Commit 0411e2cd authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Fix the implementation of named constructors

Bug: 839389
Change-Id: I802b01943d6c6a5a178c40f516ac367d43981c82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145424
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758442}
parent 57096b0c
......@@ -255,15 +255,33 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction(
v8::SideEffectType::kHasSideEffect);
v8::Local<v8::FunctionTemplate> interface_template =
wrapper_type_info->DomTemplate(isolate, world);
function_template->SetPrototypeProviderTemplate(interface_template);
function_template->ReadOnlyPrototype();
function_template->Inherit(interface_template);
function_template->SetClassName(V8AtomicString(isolate, func_name));
function_template->InstanceTemplate()->SetInternalFieldCount(
kV8DefaultWrapperInternalFieldCount);
per_isolate_data->SetInterfaceTemplate(world, callback_key,
function_template);
}
return function_template->GetFunction(script_state->GetContext());
v8::Local<v8::Context> context = script_state->GetContext();
V8PerContextData* per_context_data = V8PerContextData::From(context);
v8::Local<v8::Function> function;
if (!function_template->GetFunction(context).ToLocal(&function)) {
return v8::MaybeLocal<v8::Function>();
}
v8::Local<v8::Object> prototype_object =
per_context_data->PrototypeForType(wrapper_type_info);
bool did_define;
if (!function
->DefineOwnProperty(
context, V8AtomicString(isolate, "prototype"), prototype_object,
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum |
v8::DontDelete))
.To(&did_define)) {
return v8::MaybeLocal<v8::Function>();
}
CHECK(did_define);
return function;
}
void InstallUnscopablePropertyNames(
......
......@@ -762,12 +762,14 @@ def make_check_constructor_call(cg_context):
"ExceptionMessages::ConstructorNotCallableAsFunction("
"${class_like_name}));\n"
"return;")),
CxxLikelyIfNode(
cond=("ConstructorMode::Current(${isolate}) == "
"ConstructorMode::kWrapExistingObject"),
body=T("bindings::V8SetReturnValue(${info}, ${v8_receiver});\n"
"return;")),
])
if not cg_context.is_named_constructor:
node.append(
CxxLikelyIfNode(
cond=("ConstructorMode::Current(${isolate}) == "
"ConstructorMode::kWrapExistingObject"),
body=T("bindings::V8SetReturnValue(${info}, ${v8_receiver});\n"
"return;")))
node.accumulate(
CodeGenAccumulator.require_include_headers([
"third_party/blink/renderer/platform/bindings/v8_object_constructor.h",
......@@ -1802,9 +1804,11 @@ static const V8PrivateProperty::SymbolKey kPrivatePropertyNamedConstructor;
auto&& v8_private_named_constructor =
V8PrivateProperty::GetSymbol(${isolate}, kPrivatePropertyNamedConstructor);
v8::Local<v8::Value> v8_named_constructor;
if (v8_private_named_constructor.GetOrUndefined(${v8_receiver})
.ToLocal(&v8_named_constructor) &&
!v8_named_constructor->IsUndefined()) {
if (!v8_private_named_constructor.GetOrUndefined(${v8_receiver})
.ToLocal(&v8_named_constructor)) {
return;
}
if (!v8_named_constructor->IsUndefined()) {
bindings::V8SetReturnValue(${info}, v8_named_constructor);
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment