Skip to content

Commit 5a85d4f

Browse files
addaleaxdanielleadams
authored andcommitted
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: #35424 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 6e9e5c3 commit 5a85d4f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/api/callback.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,19 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
223223
int argc,
224224
Local<Value> argv[],
225225
async_context asyncContext) {
226-
Local<Value> callback_v =
227-
recv->Get(isolate->GetCurrentContext(), symbol).ToLocalChecked();
228-
if (callback_v.IsEmpty()) return Local<Value>();
229-
if (!callback_v->IsFunction()) return Local<Value>();
226+
// Check can_call_into_js() first because calling Get() might do so.
227+
Environment* env = Environment::GetCurrent(recv->CreationContext());
228+
CHECK_NOT_NULL(env);
229+
if (!env->can_call_into_js()) return Local<Value>();
230+
231+
Local<Value> callback_v;
232+
if (!recv->Get(isolate->GetCurrentContext(), symbol).ToLocal(&callback_v))
233+
return Local<Value>();
234+
if (!callback_v->IsFunction()) {
235+
// This used to return an empty value, but Undefined() makes more sense
236+
// since no exception is pending here.
237+
return Undefined(isolate);
238+
}
230239
Local<Function> callback = callback_v.As<Function>();
231240
return MakeCallback(isolate, recv, callback, argc, argv, asyncContext);
232241
}

0 commit comments

Comments
 (0)