mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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>
This commit is contained in:
1 parent
6e9e5c3381
commit
5a85d4f2c6
1 file changed
+13
-4
+13
-4
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user