On Mon, Sep 2, 2024 at 8:14 PM Hertz <[email protected]> wrote: > > > // argv and argc are the same as those passed to FunctionCallbackInfo: > // - argc is the number of arguments excluding the receiver > // - argv is the array arguments. The receiver is stored at argv[-1]. > template <bool is_construct> > V8_WARN_UNUSED_RESULT MaybeHandle<Object> HandleApiCallHelper( > Isolate* isolate, Handle<HeapObject> new_target, > Handle<FunctionTemplateInfo> fun_data, Handle<Object> receiver, > Address* argv, int argc) { > Handle<JSReceiver> js_receiver; > Tagged<JSReceiver> raw_holder; > if (is_construct) { > DCHECK(IsTheHole(*receiver, isolate)); > if (IsUndefined(fun_data->GetInstanceTemplate(), isolate)) { > v8::Local<ObjectTemplate> templ = > ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), > ToApiHandle<v8::FunctionTemplate>(fun_data)); > FunctionTemplateInfo::SetInstanceTemplate(isolate, fun_data, > Utils::OpenHandle(*templ)); > } > Handle<ObjectTemplateInfo> instance_template( > ObjectTemplateInfo::cast(fun_data->GetInstanceTemplate()), isolate); > ASSIGN_RETURN_ON_EXCEPTION( > isolate, js_receiver, > ApiNatives::InstantiateObject(isolate, instance_template, > Handle<JSReceiver>::cast(new_target)), > Object); > argv[BuiltinArguments::kReceiverArgsOffset] = js_receiver->ptr(); > raw_holder = *js_receiver; > } else { > DCHECK(IsJSReceiver(*receiver)); > js_receiver = Handle<JSReceiver>::cast(receiver); > > if (!fun_data->accept_any_receiver() && IsAccessCheckNeeded(*js_receiver)) { > // Proxies never need access checks. > DCHECK(IsJSObject(*js_receiver)); > Handle<JSObject> js_object = Handle<JSObject>::cast(js_receiver); > if (!isolate->MayAccess(isolate->native_context(), js_object)) { > RETURN_ON_EXCEPTION( > isolate, isolate->ReportFailedAccessCheck(js_object), Object); > UNREACHABLE(); > } > } > > raw_holder = GetCompatibleReceiver(isolate, *fun_data, *js_receiver); > > if (raw_holder.is_null()) { > // This function cannot be called with the given receiver. Abort! > THROW_NEW_ERROR( > isolate, NewTypeError(MessageTemplate::kIllegalInvocation), Object); > } > } > > if (fun_data->has_callback(isolate)) { > Tagged<Object> data_obj = fun_data->callback_data(kAcquireLoad); > FunctionCallbackArguments custom(isolate, data_obj, raw_holder, *new_target, > argv, argc); > Handle<Object> result = custom.Call(*fun_data); > > RETURN_EXCEPTION_IF_EXCEPTION(isolate, Object); > if (result.is_null()) { > if (is_construct) return js_receiver; > return isolate->factory()->undefined_value(); > } > // Rebox the result. > { > DisallowGarbageCollection no_gc; > Tagged<Object> raw_result = *result; > DCHECK(IsApiCallResultType(raw_result)); > if (!is_construct || IsJSReceiver(raw_result)) > return handle(raw_result, isolate); > } > } > > return js_receiver; > } > > }
fun_data is the function/method, receiver is the "this" object, argv are the arguments. -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAHQurc-0jbYvunM31vk1EW0OBYjeNgVTMEYSoG5s%3DpP%2BV8w26w%40mail.gmail.com.
