Skip to content

Commit cd80195

Browse files
addaleaxMylesBorins
authored andcommittedNov 16, 2020
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 <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>
1 parent edf3fbb commit cd80195

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎src/api/callback.cc

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

0 commit comments

Comments
 (0)
Please sign in to comment.