Commit de9daff0 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

Remove Accessors::FunctionSetPrototype

It was a straight pass-through to JSFunction::SetPrototype, with the
added wrinkle that it appeared to sometimes throw (although it never did).

Also improves typing of JSFunction::SetInstancePrototype signature to
require being passed a JSReceiver.

Change-Id: Ie85b9a74955f72bf988cd902c5eec34e32b51a24
Reviewed-on: https://chromium-review.googlesource.com/482421Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44757}
parent 0cbe6454
...@@ -681,23 +681,6 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate, ...@@ -681,23 +681,6 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate,
return Handle<Object>(function->prototype(), isolate); return Handle<Object>(function->prototype(), isolate);
} }
MUST_USE_RESULT static MaybeHandle<Object> SetFunctionPrototype(
Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) {
JSFunction::SetPrototype(function, value);
DCHECK(function->prototype() == *value);
return function;
}
MaybeHandle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
Handle<Object> prototype) {
DCHECK(function->IsConstructor());
Isolate* isolate = function->GetIsolate();
return SetFunctionPrototype(isolate, function, prototype);
}
void Accessors::FunctionPrototypeGetter( void Accessors::FunctionPrototypeGetter(
v8::Local<v8::Name> name, v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
...@@ -719,11 +702,8 @@ void Accessors::FunctionPrototypeSetter( ...@@ -719,11 +702,8 @@ void Accessors::FunctionPrototypeSetter(
Handle<Object> value = Utils::OpenHandle(*val); Handle<Object> value = Utils::OpenHandle(*val);
Handle<JSFunction> object = Handle<JSFunction> object =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
if (SetFunctionPrototype(isolate, object, value).is_null()) { JSFunction::SetPrototype(object, value);
isolate->OptionalRescheduleException(false); info.GetReturnValue().Set(true);
} else {
info.GetReturnValue().Set(true);
}
} }
......
...@@ -90,8 +90,6 @@ class Accessors : public AllStatic { ...@@ -90,8 +90,6 @@ class Accessors : public AllStatic {
}; };
// Accessor functions called directly from the runtime system. // Accessor functions called directly from the runtime system.
MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
Handle<JSFunction> object, Handle<Object> value);
static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object); static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object);
// Returns true for properties that are accessors to object fields. // Returns true for properties that are accessors to object fields.
......
...@@ -573,8 +573,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { ...@@ -573,8 +573,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
// prototype, otherwise the missing initial_array_prototype will cause // prototype, otherwise the missing initial_array_prototype will cause
// assertions during startup. // assertions during startup.
native_context()->set_initial_array_prototype(*object_function_prototype); native_context()->set_initial_array_prototype(*object_function_prototype);
Accessors::FunctionSetPrototype(object_fun, object_function_prototype) JSFunction::SetPrototype(object_fun, object_function_prototype);
.Assert();
} }
// Allocate the empty function as the prototype for function - ES6 19.2.3 // Allocate the empty function as the prototype for function - ES6 19.2.3
...@@ -1188,7 +1187,7 @@ static void InstallError(Isolate* isolate, Handle<JSObject> global, ...@@ -1188,7 +1187,7 @@ static void InstallError(Isolate* isolate, Handle<JSObject> global,
.FromMaybe(false)); .FromMaybe(false));
} }
Accessors::FunctionSetPrototype(error_fun, prototype).Assert(); JSFunction::SetPrototype(error_fun, prototype);
} }
Handle<Map> initial_map(error_fun->initial_map()); Handle<Map> initial_map(error_fun->initial_map());
...@@ -1592,7 +1591,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1592,7 +1591,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSValue> prototype = Handle<JSValue> prototype =
Handle<JSValue>::cast(factory->NewJSObject(number_fun, TENURED)); Handle<JSValue>::cast(factory->NewJSObject(number_fun, TENURED));
prototype->set_value(Smi::kZero); prototype->set_value(Smi::kZero);
Accessors::FunctionSetPrototype(number_fun, prototype).Assert(); JSFunction::SetPrototype(number_fun, prototype);
// Install the "constructor" property on the {prototype}. // Install the "constructor" property on the {prototype}.
JSObject::AddProperty(prototype, factory->constructor_string(), number_fun, JSObject::AddProperty(prototype, factory->constructor_string(), number_fun,
...@@ -1709,7 +1708,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1709,7 +1708,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSValue> prototype = Handle<JSValue> prototype =
Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED)); Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED));
prototype->set_value(isolate->heap()->false_value()); prototype->set_value(isolate->heap()->false_value());
Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert(); JSFunction::SetPrototype(boolean_fun, prototype);
// Install the "constructor" property on the {prototype}. // Install the "constructor" property on the {prototype}.
JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun, JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun,
...@@ -1761,7 +1760,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1761,7 +1760,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSValue> prototype = Handle<JSValue> prototype =
Handle<JSValue>::cast(factory->NewJSObject(string_fun, TENURED)); Handle<JSValue>::cast(factory->NewJSObject(string_fun, TENURED));
prototype->set_value(isolate->heap()->empty_string()); prototype->set_value(isolate->heap()->empty_string());
Accessors::FunctionSetPrototype(string_fun, prototype).Assert(); JSFunction::SetPrototype(string_fun, prototype);
// Install the "constructor" property on the {prototype}. // Install the "constructor" property on the {prototype}.
JSObject::AddProperty(prototype, factory->constructor_string(), string_fun, JSObject::AddProperty(prototype, factory->constructor_string(), string_fun,
...@@ -2473,8 +2472,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2473,8 +2472,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- J S O N { // -- J S O N
Handle<String> name = factory->InternalizeUtf8String("JSON"); Handle<String> name = factory->InternalizeUtf8String("JSON");
Handle<JSFunction> cons = factory->NewFunction(name); Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype(cons, JSFunction::SetInstancePrototype(cons, isolate->initial_object_prototype());
Handle<Object>(native_context()->initial_object_prototype(), isolate));
Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
DCHECK(json_object->IsJSObject()); DCHECK(json_object->IsJSObject());
JSObject::AddProperty(global, name, json_object, DONT_ENUM); JSObject::AddProperty(global, name, json_object, DONT_ENUM);
...@@ -2490,9 +2488,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2490,9 +2488,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- M a t h { // -- M a t h
Handle<String> name = factory->InternalizeUtf8String("Math"); Handle<String> name = factory->InternalizeUtf8String("Math");
Handle<JSFunction> cons = factory->NewFunction(name); Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype( JSFunction::SetInstancePrototype(cons, isolate->initial_object_prototype());
cons,
Handle<Object>(native_context()->initial_object_prototype(), isolate));
Handle<JSObject> math = factory->NewJSObject(cons, TENURED); Handle<JSObject> math = factory->NewJSObject(cons, TENURED);
DCHECK(math->IsJSObject()); DCHECK(math->IsJSObject());
JSObject::AddProperty(global, name, math, DONT_ENUM); JSObject::AddProperty(global, name, math, DONT_ENUM);
...@@ -2610,9 +2606,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2610,9 +2606,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- I n t l { // -- I n t l
Handle<String> name = factory->InternalizeUtf8String("Intl"); Handle<String> name = factory->InternalizeUtf8String("Intl");
Handle<JSFunction> cons = factory->NewFunction(name); Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype( JSFunction::SetInstancePrototype(cons, isolate->initial_object_prototype());
cons,
Handle<Object>(native_context()->initial_object_prototype(), isolate));
Handle<JSObject> intl = factory->NewJSObject(cons, TENURED); Handle<JSObject> intl = factory->NewJSObject(cons, TENURED);
DCHECK(intl->IsJSObject()); DCHECK(intl->IsJSObject());
JSObject::AddProperty(global, name, intl, DONT_ENUM); JSObject::AddProperty(global, name, intl, DONT_ENUM);
...@@ -3557,7 +3551,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3557,7 +3551,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
isolate->initial_object_prototype(), Builtins::kUnsupportedThrower); isolate->initial_object_prototype(), Builtins::kUnsupportedThrower);
Handle<JSObject> prototype = Handle<JSObject> prototype =
factory->NewJSObject(isolate->object_function(), TENURED); factory->NewJSObject(isolate->object_function(), TENURED);
Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); JSFunction::SetPrototype(script_fun, prototype);
native_context->set_script_function(*script_fun); native_context->set_script_function(*script_fun);
Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
...@@ -3811,7 +3805,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3811,7 +3805,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
SimpleInstallFunction(proto, info.name, info.id, 0, true, attrs); SimpleInstallFunction(proto, info.name, info.id, 0, true, attrs);
} }
Accessors::FunctionSetPrototype(callsite_fun, proto).Assert(); JSFunction::SetPrototype(callsite_fun, proto);
} }
} }
isolate->native_context()->set_exports_container(*container); isolate->native_context()->set_exports_container(*container);
...@@ -3906,9 +3900,7 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { ...@@ -3906,9 +3900,7 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
Handle<String> name = factory->InternalizeUtf8String("Atomics"); Handle<String> name = factory->InternalizeUtf8String("Atomics");
Handle<JSFunction> cons = factory->NewFunction(name); Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype( JSFunction::SetInstancePrototype(cons, isolate->initial_object_prototype());
cons,
Handle<Object>(native_context()->initial_object_prototype(), isolate));
Handle<JSObject> atomics_object = factory->NewJSObject(cons, TENURED); Handle<JSObject> atomics_object = factory->NewJSObject(cons, TENURED);
DCHECK(atomics_object->IsJSObject()); DCHECK(atomics_object->IsJSObject());
JSObject::AddProperty(global, name, atomics_object, DONT_ENUM); JSObject::AddProperty(global, name, atomics_object, DONT_ENUM);
...@@ -4224,7 +4216,7 @@ bool Genesis::InstallNatives(GlobalContextType context_type) { ...@@ -4224,7 +4216,7 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize);
Handle<JSObject> prototype = Handle<JSObject> prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED); factory()->NewJSObject(isolate()->object_function(), TENURED);
Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); JSFunction::SetPrototype(opaque_reference_fun, prototype);
native_context()->set_opaque_reference_function(*opaque_reference_fun); native_context()->set_opaque_reference_function(*opaque_reference_fun);
} }
......
...@@ -12624,13 +12624,10 @@ Handle<Object> CacheInitialJSArrayMaps( ...@@ -12624,13 +12624,10 @@ Handle<Object> CacheInitialJSArrayMaps(
return initial_map; return initial_map;
} }
void JSFunction::SetInstancePrototype(Handle<JSFunction> function, void JSFunction::SetInstancePrototype(Handle<JSFunction> function,
Handle<Object> value) { Handle<JSReceiver> value) {
Isolate* isolate = function->GetIsolate(); Isolate* isolate = function->GetIsolate();
DCHECK(value->IsJSReceiver());
// Now some logic for the maps of the objects that are created by using this // Now some logic for the maps of the objects that are created by using this
// function as a constructor. // function as a constructor.
if (function->has_initial_map()) { if (function->has_initial_map()) {
...@@ -12686,7 +12683,7 @@ void JSFunction::SetPrototype(Handle<JSFunction> function, ...@@ -12686,7 +12683,7 @@ void JSFunction::SetPrototype(Handle<JSFunction> function,
Handle<Object> value) { Handle<Object> value) {
DCHECK(function->IsConstructor() || DCHECK(function->IsConstructor() ||
IsGeneratorFunction(function->shared()->kind())); IsGeneratorFunction(function->shared()->kind()));
Handle<Object> construct_prototype = value; Handle<JSReceiver> construct_prototype;
// If the value is not a JSReceiver, store the value in the map's // If the value is not a JSReceiver, store the value in the map's
// constructor field so it can be accessed. Also, set the prototype // constructor field so it can be accessed. Also, set the prototype
...@@ -12706,18 +12703,19 @@ void JSFunction::SetPrototype(Handle<JSFunction> function, ...@@ -12706,18 +12703,19 @@ void JSFunction::SetPrototype(Handle<JSFunction> function,
FunctionKind kind = function->shared()->kind(); FunctionKind kind = function->shared()->kind();
Handle<Context> native_context(function->context()->native_context()); Handle<Context> native_context(function->context()->native_context());
construct_prototype = construct_prototype = Handle<JSReceiver>(
handle(IsGeneratorFunction(kind) IsGeneratorFunction(kind)
? IsAsyncFunction(kind) ? IsAsyncFunction(kind)
? native_context->initial_async_generator_prototype() ? native_context->initial_async_generator_prototype()
: native_context->initial_generator_prototype() : native_context->initial_generator_prototype()
: native_context->initial_object_prototype(), : native_context->initial_object_prototype(),
isolate); isolate);
} else { } else {
construct_prototype = Handle<JSReceiver>::cast(value);
function->map()->set_non_instance_prototype(false); function->map()->set_non_instance_prototype(false);
} }
return SetInstancePrototype(function, construct_prototype); SetInstancePrototype(function, construct_prototype);
} }
......
...@@ -6945,7 +6945,7 @@ class JSFunction: public JSObject { ...@@ -6945,7 +6945,7 @@ class JSFunction: public JSObject {
static void SetPrototype(Handle<JSFunction> function, static void SetPrototype(Handle<JSFunction> function,
Handle<Object> value); Handle<Object> value);
static void SetInstancePrototype(Handle<JSFunction> function, static void SetInstancePrototype(Handle<JSFunction> function,
Handle<Object> value); Handle<JSReceiver> value);
// After prototype is removed, it will not be created when accessed, and // After prototype is removed, it will not be created when accessed, and
// [[Construct]] from this function will not be allowed. // [[Construct]] from this function will not be allowed.
......
...@@ -144,8 +144,7 @@ RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) { ...@@ -144,8 +144,7 @@ RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) {
CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
CHECK(fun->IsConstructor()); CHECK(fun->IsConstructor());
RETURN_FAILURE_ON_EXCEPTION(isolate, JSFunction::SetPrototype(fun, value);
Accessors::FunctionSetPrototype(fun, value));
return args[0]; // return TOS return args[0]; // return TOS
} }
......
...@@ -865,8 +865,7 @@ void WasmJs::Install(Isolate* isolate) { ...@@ -865,8 +865,7 @@ void WasmJs::Install(Isolate* isolate) {
// Setup WebAssembly // Setup WebAssembly
Handle<String> name = v8_str(isolate, "WebAssembly"); Handle<String> name = v8_str(isolate, "WebAssembly");
Handle<JSFunction> cons = factory->NewFunction(name); Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype( JSFunction::SetInstancePrototype(cons, isolate->initial_object_prototype());
cons, Handle<Object>(context->initial_object_prototype(), isolate));
cons->shared()->set_instance_class_name(*name); cons->shared()->set_instance_class_name(*name);
Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED);
PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
......
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