Commit 77d2ce8c authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Chromium LUCI CQ

[bindings] Create FunctionTemplate with the correct ConstructorBehavior

Instead of using the default arguments of
v8::ConstructorBehavior::kAllow and then immediately calling
FunctionTemplate::RemovePrototype, this patch changes the
FunctionTemplateInfo::New to pass in the correct value for
v8::ConstructorBehavior.

There is no change in observable behavior with this patch.

In the future, this change will allow v8 to correctly cache only the
instantiable templates (crbug.com/v8/11284) improving performance of
this template cache.

Change-Id: I674d38689201045a994ccd6b6b6feb81b95eef69
Bug: v8:11288
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543345
Commit-Queue: Sathya Gunasekaran  <gsathya@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841527}
parent 8caf3b6b
......@@ -248,9 +248,8 @@ v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(
isolate, &internal::Dispatcher<Sig>::DispatchToCallback,
ConvertToV8<v8::Local<v8::External>>(isolate,
holder->GetHandle(isolate)));
tmpl->RemovePrototype();
ConvertToV8<v8::Local<v8::External>>(isolate, holder->GetHandle(isolate)),
v8::Local<v8::Signature>(), 0, v8::ConstructorBehavior::kThrow);
return tmpl;
}
......
......@@ -29,9 +29,9 @@ void Log(const v8::FunctionCallbackInfo<v8::Value>& info) {
// static
void Console::Register(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ) {
v8::Local<v8::FunctionTemplate> log_templ =
v8::FunctionTemplate::New(isolate, Log);
log_templ->RemovePrototype();
v8::Local<v8::FunctionTemplate> log_templ = v8::FunctionTemplate::New(
isolate, Log, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
templ->Set(StringToSymbol(isolate, "log"), log_templ);
}
......
......@@ -409,8 +409,6 @@ void InstallCSSPropertyAttributes(
v8::Local<v8::FunctionTemplate> set_func = v8::FunctionTemplate::New(
isolate, CSSPropertyAttributeSet, v8_property_name, signature, 1,
v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect);
get_func->RemovePrototype();
set_func->RemovePrototype();
get_func->SetAcceptAnyReceiver(false);
set_func->SetAcceptAnyReceiver(false);
get_func->SetClassName(
......
......@@ -205,11 +205,10 @@ CreateAccessorFunctionOrTemplate<v8::FunctionTemplate>(
} else {
function_template = v8::FunctionTemplate::New(
isolate, callback, data, signature, length,
v8::ConstructorBehavior::kAllow, side_effect_type);
v8::ConstructorBehavior::kThrow, side_effect_type);
}
if (!function_template.IsEmpty()) {
function_template->RemovePrototype();
function_template->SetAcceptAnyReceiver(
access_check_configuration == V8DOMConfiguration::kDoNotCheckAccess);
......@@ -485,12 +484,10 @@ void InstallMethodInternal(v8::Isolate* isolate,
: v8::SideEffectType::kHasSideEffect;
if (method.property_location_configuration &
(V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) {
// TODO(luoe): use ConstructorBehavior::kThrow for non-constructor methods.
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(
isolate, callback, v8::Local<v8::Value>(), signature, method.length,
v8::ConstructorBehavior::kAllow, side_effect_type, v8_c_function);
function_template->RemovePrototype();
v8::ConstructorBehavior::kThrow, side_effect_type, v8_c_function);
function_template->SetAcceptAnyReceiver(
method.access_check_configuration ==
V8DOMConfiguration::kDoNotCheckAccess);
......@@ -510,13 +507,11 @@ void InstallMethodInternal(v8::Isolate* isolate,
// Operations installed on the interface object must be static methods, so
// no need to specify a signature, i.e. no need to do type check against a
// holder.
// TODO(luoe): use ConstructorBehavior::kThrow for non-constructor methods.
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), method.length,
v8::ConstructorBehavior::kAllow,
v8::ConstructorBehavior::kThrow,
side_effect_type);
function_template->RemovePrototype();
// Similarly, there is no need to do an access check for static methods, as
// there is no holder to check against.
AddMethodToTemplate(isolate, interface_template, function_template, method);
......@@ -554,12 +549,10 @@ void InstallMethodInternal(
DCHECK(location);
if (location &
(V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) {
// TODO(luoe): use ConstructorBehavior::kThrow for non-constructor methods.
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(
isolate, callback, v8::Local<v8::Value>(), signature, config.length,
v8::ConstructorBehavior::kAllow, side_effect_type);
function_template->RemovePrototype();
v8::ConstructorBehavior::kThrow, side_effect_type);
function_template->SetAcceptAnyReceiver(
config.access_check_configuration ==
V8DOMConfiguration::kDoNotCheckAccess);
......@@ -586,13 +579,11 @@ void InstallMethodInternal(
// Operations installed on the interface object must be static
// operations, so no need to specify a signature, i.e. no need to do
// type check against a holder.
// TODO(luoe): use ConstructorBehavior::kThrow for non-constructor methods.
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), config.length,
v8::ConstructorBehavior::kAllow,
v8::ConstructorBehavior::kThrow,
side_effect_type);
function_template->RemovePrototype();
v8::Local<v8::Function> function =
function_template->GetFunction(isolate->GetCurrentContext())
.ToLocalChecked();
......
......@@ -5213,8 +5213,9 @@ def make_install_interface_template(cg_context, function_name, class_name,
// https://heycam.github.io/webidl/#es-DOMException-specialness
{
v8::Local<v8::FunctionTemplate> intrinsic_error_prototype_interface_template =
v8::FunctionTemplate::New(${isolate});
intrinsic_error_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(${isolate}, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_error_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(${isolate}, "prototype"), v8::kErrorPrototype);
${interface_function_template}->Inherit(
......@@ -5230,8 +5231,9 @@ def make_install_interface_template(cg_context, function_name, class_name,
{
v8::Local<v8::FunctionTemplate>
intrinsic_iterator_prototype_interface_template =
v8::FunctionTemplate::New(${isolate});
intrinsic_iterator_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(${isolate}, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_iterator_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(${isolate}, "prototype"), v8::kAsyncIteratorPrototype);
${interface_function_template}->Inherit(
......@@ -5257,8 +5259,9 @@ ${instance_object_template}->MarkAsUndetectable();
{
v8::Local<v8::FunctionTemplate>
intrinsic_iterator_prototype_interface_template =
v8::FunctionTemplate::New(${isolate});
intrinsic_iterator_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(${isolate}, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_iterator_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(${isolate}, "prototype"), v8::kIteratorPrototype);
${interface_function_template}->Inherit(
......
......@@ -579,8 +579,9 @@ static void Install{{v8_class}}Template(
// so there is no need to reuse this FunctionTemplate and register it in
// V8PerIsolateData.
v8::Local<v8::FunctionTemplate> intrinsic_iterator_prototype_interface_template =
v8::FunctionTemplate::New(isolate);
intrinsic_iterator_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(isolate, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_iterator_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(isolate, "prototype"), v8::kIteratorPrototype);
interface_template->Inherit(intrinsic_iterator_prototype_interface_template);
......@@ -590,8 +591,9 @@ static void Install{{v8_class}}Template(
// Temporary @@asyncIterator support for FileSystemDirectoryHandle
// TODO(https://crbug.com/1087157): Replace with proper bindings support.
v8::Local<v8::FunctionTemplate> intrinsic_iterator_prototype_interface_template =
v8::FunctionTemplate::New(isolate);
intrinsic_iterator_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(isolate, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_iterator_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(isolate, "prototype"), v8::kAsyncIteratorPrototype);
interface_template->Inherit(intrinsic_iterator_prototype_interface_template);
......@@ -614,8 +616,9 @@ static void Install{{v8_class}}Template(
// |interface_template| is instantiated, its prototype.__proto__ will point to
// |intrinsic_error_prototype_interface_template|'s "prototype" property.
v8::Local<v8::FunctionTemplate> intrinsic_error_prototype_interface_template =
v8::FunctionTemplate::New(isolate);
intrinsic_error_prototype_interface_template->RemovePrototype();
v8::FunctionTemplate::New(isolate, nullptr, v8::Local<v8::Value>(),
v8::Local<v8::Signature>(), 0,
v8::ConstructorBehavior::kThrow);
intrinsic_error_prototype_interface_template->SetIntrinsicDataProperty(
V8AtomicString(isolate, "prototype"), v8::kErrorPrototype);
interface_template->Inherit(intrinsic_error_prototype_interface_template);
......
......@@ -161,10 +161,10 @@ v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
V8PrivateProperty::GetCachedAccessor(isolate, v8_cached_accessor)
.GetPrivate(),
v8::Local<v8::Value>(), signature, length, v8_side_effect);
function_template->RemovePrototype();
}
function_template->SetClassName(name);
function_template->RemovePrototype();
function_template->SetAcceptAnyReceiver(
GetConfigCrossOriginCheck<kind>(config) ==
IDLMemberInstaller::FlagCrossOriginCheck::kDoNotCheck);
......
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