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:
parent
f89f576f6d
commit
356fd18c73
3 changed files with 18 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue