diff --git a/src/api/api.cc b/src/api/api.cc index 3b07a86a2b..a69ec6a49f 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -5487,6 +5487,7 @@ MaybeLocal Function::Bind(v8::Local that, i::Handle self; i::Handle that_obj; v8::Isolate* isolate = this->GetIsolate(); + i::MaybeHandle bound_function; i::Isolate* i_isolate = reinterpret_cast(isolate); if (that.IsEmpty()) { @@ -5505,18 +5506,24 @@ MaybeLocal Function::Bind(v8::Local that, self = Utils::OpenHandle(this); // derive a base vector of internal object handles by unwrapping an optional v8::Array - base::ScopedVector> argv(bound_args.IsEmpty() ? 0 : bound_args->Length()); - if (!bound_args.IsEmpty()) { - for (int i = 0; i < bound_args->Length(); ++i) { - MaybeLocal arg = bound_args->Get(isolate->GetCurrentContext(), i); - CHECK(!arg.IsEmpty()); - argv[i] = Utils::OpenHandle(*arg.ToLocalChecked()); + if (!bound_args.IsEmpty() && bound_args->Length()) { + base::ScopedVector> argv( + bound_args.IsEmpty() ? 0 : bound_args->Length()); + if (!bound_args.IsEmpty()) { + for (int i = 0; i < bound_args->Length(); ++i) { + MaybeLocal arg = + bound_args->Get(isolate->GetCurrentContext(), i); + CHECK(!arg.IsEmpty()); + argv[i] = Utils::OpenHandle(*arg.ToLocalChecked()); + } } + bound_function = + i_isolate->factory()->NewJSBoundFunction(self, that_obj, argv); + } else { + bound_function = + i_isolate->factory()->NewJSBoundFunction(self, that_obj, {}); } - i::MaybeHandle bound_function = - i_isolate->factory()->NewJSBoundFunction(self, that_obj, argv); - if (bound_function.is_null()) { return {}; }