From 8fce4f1e0c2529bfb0f2a8b552c03d5d5a87e131 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 20 Oct 2023 13:52:44 +0100 Subject: [PATCH] [*] Fix crash under Aurora API Last aurora commit: 9480aab0 --- src/api/api.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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 {}; }