1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Calling denoSub twice should fail.

This commit is contained in:
Ryan Dahl 2018-06-11 22:51:11 +02:00
parent f89f576f6d
commit 356fd18c73
3 changed files with 18 additions and 0 deletions

View file

@ -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);

View file

@ -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));
}

View file

@ -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();