Skip to content

Commit

Permalink
Calling denoSub twice should fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 11, 2018
1 parent f89f576 commit 356fd18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deno2/deno.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ void Sub(const v8::FunctionCallbackInfo<v8::Value>& args) {

v8::HandleScope handle_scope(isolate);

if (!d->sub.IsEmpty()) {
isolate->ThrowException(v8_str("denoSub already called."));
return;
}

v8::Local<v8::Value> v = args[0];
assert(v->IsFunction());
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);
Expand Down
7 changes: 7 additions & 0 deletions deno2/js/mock_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ function SubReturnBar() {
const rstr = String.fromCharCode(...rui8);
assert(rstr === "bar");
}

function DoubleSubFails() {
// denoSub is an internal function and should only be called once from the
// runtime.
denoSub((channel, msg) => assert(false));
denoSub((channel, msg) => assert(false));
}
6 changes: 6 additions & 0 deletions deno2/mock_runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ TEST(MockRuntimeTest, SubReturnBar) {
deno_delete(d);
}

TEST(MockRuntimeTest, DoubleSubFails) {
Deno* d = deno_new(NULL, NULL);
EXPECT_FALSE(deno_execute(d, "a.js", "DoubleSubFails()"));
deno_delete(d);
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
deno_init();
Expand Down

0 comments on commit 356fd18

Please sign in to comment.