diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-09-30 12:55:59 +0300 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2020-10-03 17:42:39 +0300 |
commit | 602fb3bedc50ede2054838c22371debc38a3f515 (patch) | |
tree | f81dc2caa1d0a6ab20791f98426d40c7ffb7b234 /src/api | |
parent | e9639ee7e8705516e3b4b9ba7ee19d8e210afa9a (diff) |
src: make MakeCallback() check can_call_into_js before getting method
There is a check for this in the inner `MakeCallback()` function
called by it, but since the `Get()` call here can also result in a
call into JS, we should ideally check the flag before that.
PR-URL: https://github.com/nodejs/node/pull/35424
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/callback.cc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/api/callback.cc b/src/api/callback.cc index 84664c08959..3d4f91a866e 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -223,10 +223,19 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate, int argc, Local<Value> argv[], async_context asyncContext) { - Local<Value> callback_v = - recv->Get(isolate->GetCurrentContext(), symbol).ToLocalChecked(); - if (callback_v.IsEmpty()) return Local<Value>(); - if (!callback_v->IsFunction()) return Local<Value>(); + // Check can_call_into_js() first because calling Get() might do so. + Environment* env = Environment::GetCurrent(recv->CreationContext()); + CHECK_NOT_NULL(env); + if (!env->can_call_into_js()) return Local<Value>(); + + Local<Value> callback_v; + if (!recv->Get(isolate->GetCurrentContext(), symbol).ToLocal(&callback_v)) + return Local<Value>(); + if (!callback_v->IsFunction()) { + // This used to return an empty value, but Undefined() makes more sense + // since no exception is pending here. + return Undefined(isolate); + } Local<Function> callback = callback_v.As<Function>(); return MakeCallback(isolate, recv, callback, argc, argv, asyncContext); } |