[bootstrapper] Refactor CreateFunction and InstallFunction.

Move set_native(true) from InstallFunction into CreateFunction in order to
emphasize the places where we create non-native functions.

No change in semantics overall.

BUG=

Review-Url: https://codereview.chromium.org/2667993005
Cr-Commit-Position: refs/heads/master@{#42854}
This commit is contained in:
neis 2017-02-01 06:02:59 -08:00 committed by Commit bot
parent 87d309dadd
commit f555b07354

View File

@ -363,7 +363,6 @@ void InstallFunction(Handle<JSObject> target, Handle<Name> property_name,
if (target->IsJSGlobalObject()) { if (target->IsJSGlobalObject()) {
function->shared()->set_instance_class_name(*function_name); function->shared()->set_instance_class_name(*function_name);
} }
function->shared()->set_native(true);
} }
void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function,
@ -381,11 +380,14 @@ Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name,
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<Code> call_code(isolate->builtins()->builtin(call)); Handle<Code> call_code(isolate->builtins()->builtin(call));
Handle<JSObject> prototype; Handle<JSObject> prototype;
return maybe_prototype.ToHandle(&prototype) Handle<JSFunction> result =
? factory->NewFunction(name, call_code, prototype, type, maybe_prototype.ToHandle(&prototype)
instance_size, strict_function_map) ? factory->NewFunction(name, call_code, prototype, type,
: factory->NewFunctionWithoutPrototype(name, call_code, instance_size, strict_function_map)
strict_function_map); : factory->NewFunctionWithoutPrototype(name, call_code,
strict_function_map);
result->shared()->set_native(true);
return result;
} }
Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name,
@ -469,14 +471,12 @@ void SimpleInstallGetterSetter(Handle<JSObject> base, Handle<String> name,
.ToHandleChecked(); .ToHandleChecked();
Handle<JSFunction> getter = Handle<JSFunction> getter =
SimpleCreateFunction(isolate, getter_name, call_getter, 0, true); SimpleCreateFunction(isolate, getter_name, call_getter, 0, true);
getter->shared()->set_native(true);
Handle<String> setter_name = Handle<String> setter_name =
Name::ToFunctionName(name, isolate->factory()->set_string()) Name::ToFunctionName(name, isolate->factory()->set_string())
.ToHandleChecked(); .ToHandleChecked();
Handle<JSFunction> setter = Handle<JSFunction> setter =
SimpleCreateFunction(isolate, setter_name, call_setter, 1, true); SimpleCreateFunction(isolate, setter_name, call_setter, 1, true);
setter->shared()->set_native(true);
JSObject::DefineAccessor(base, name, getter, setter, attribs).Check(); JSObject::DefineAccessor(base, name, getter, setter, attribs).Check();
} }
@ -492,7 +492,6 @@ Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
.ToHandleChecked(); .ToHandleChecked();
Handle<JSFunction> getter = Handle<JSFunction> getter =
SimpleCreateFunction(isolate, getter_name, call, 0, adapt); SimpleCreateFunction(isolate, getter_name, call, 0, adapt);
getter->shared()->set_native(true);
Handle<Object> setter = isolate->factory()->undefined_value(); Handle<Object> setter = isolate->factory()->undefined_value();
@ -722,7 +721,6 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
Handle<JSFunction> iterator_prototype_iterator = SimpleCreateFunction( Handle<JSFunction> iterator_prototype_iterator = SimpleCreateFunction(
isolate(), factory()->NewStringFromAsciiChecked("[Symbol.iterator]"), isolate(), factory()->NewStringFromAsciiChecked("[Symbol.iterator]"),
Builtins::kReturnReceiver, 0, true); Builtins::kReturnReceiver, 0, true);
iterator_prototype_iterator->shared()->set_native(true);
JSObject::AddProperty(iterator_prototype, factory()->iterator_symbol(), JSObject::AddProperty(iterator_prototype, factory()->iterator_symbol(),
iterator_prototype_iterator, DONT_ENUM); iterator_prototype_iterator, DONT_ENUM);
@ -761,10 +759,12 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
SimpleInstallFunction(generator_object_prototype, "throw", SimpleInstallFunction(generator_object_prototype, "throw",
Builtins::kGeneratorPrototypeThrow, 1, true); Builtins::kGeneratorPrototypeThrow, 1, true);
// Internal version of generator_prototype_next, flagged as non-native. // Internal version of generator_prototype_next, flagged as non-native such
// that it doesn't show up in Error traces.
Handle<JSFunction> generator_next_internal = Handle<JSFunction> generator_next_internal =
SimpleCreateFunction(isolate(), factory()->next_string(), SimpleCreateFunction(isolate(), factory()->next_string(),
Builtins::kGeneratorPrototypeNext, 1, true); Builtins::kGeneratorPrototypeNext, 1, true);
generator_next_internal->shared()->set_native(false);
native_context()->set_generator_next_internal(*generator_next_internal); native_context()->set_generator_next_internal(*generator_next_internal);
// Create maps for generator functions and their prototypes. Store those // Create maps for generator functions and their prototypes. Store those
@ -1372,6 +1372,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
isolate, factory->ArrayIterator_string(), isolate, factory->ArrayIterator_string(),
JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize, JS_FAST_ARRAY_VALUE_ITERATOR_TYPE, JSArrayIterator::kSize,
array_iterator_prototype, Builtins::kIllegal); array_iterator_prototype, Builtins::kIllegal);
array_iterator_function->shared()->set_native(false);
array_iterator_function->shared()->set_instance_class_name( array_iterator_function->shared()->set_instance_class_name(
isolate->heap()->ArrayIterator_string()); isolate->heap()->ArrayIterator_string());
@ -1606,7 +1607,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> iterator = SimpleCreateFunction( Handle<JSFunction> iterator = SimpleCreateFunction(
isolate, factory->NewStringFromAsciiChecked("[Symbol.iterator]"), isolate, factory->NewStringFromAsciiChecked("[Symbol.iterator]"),
Builtins::kStringPrototypeIterator, 0, true); Builtins::kStringPrototypeIterator, 0, true);
iterator->shared()->set_native(true);
iterator->shared()->set_builtin_function_id(kStringIterator); iterator->shared()->set_builtin_function_id(kStringIterator);
JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator, JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
static_cast<PropertyAttributes>(DONT_ENUM)); static_cast<PropertyAttributes>(DONT_ENUM));
@ -1642,6 +1642,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
isolate, factory->NewStringFromAsciiChecked("StringIterator"), isolate, factory->NewStringFromAsciiChecked("StringIterator"),
JS_STRING_ITERATOR_TYPE, JSStringIterator::kSize, JS_STRING_ITERATOR_TYPE, JSStringIterator::kSize,
string_iterator_prototype, Builtins::kIllegal); string_iterator_prototype, Builtins::kIllegal);
string_iterator_function->shared()->set_native(false);
native_context()->set_string_iterator_map( native_context()->set_string_iterator_map(
string_iterator_function->initial_map()); string_iterator_function->initial_map());
} }
@ -1861,6 +1862,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> new_promise_capability = Handle<JSFunction> new_promise_capability =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kNewPromiseCapability, 2, false); Builtins::kNewPromiseCapability, 2, false);
new_promise_capability->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, new_promise_capability, InstallWithIntrinsicDefaultProto(isolate, new_promise_capability,
Context::NEW_PROMISE_CAPABILITY_INDEX); Context::NEW_PROMISE_CAPABILITY_INDEX);
} }
@ -1924,6 +1926,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kPromiseInternalConstructor, 1, true); Builtins::kPromiseInternalConstructor, 1, true);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto( InstallWithIntrinsicDefaultProto(
isolate, function, Context::PROMISE_INTERNAL_CONSTRUCTOR_INDEX); isolate, function, Context::PROMISE_INTERNAL_CONSTRUCTOR_INDEX);
} }
@ -1931,6 +1934,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // Internal: IsPromise { // Internal: IsPromise
Handle<JSFunction> function = SimpleCreateFunction( Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(), Builtins::kIsPromise, 1, false); isolate, factory->empty_string(), Builtins::kIsPromise, 1, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, function, InstallWithIntrinsicDefaultProto(isolate, function,
Context::IS_PROMISE_INDEX); Context::IS_PROMISE_INDEX);
} }
@ -1939,6 +1943,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
// Also exposed as extrasUtils.resolvePromise. // Also exposed as extrasUtils.resolvePromise.
Handle<JSFunction> function = SimpleCreateFunction( Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(), Builtins::kResolvePromise, 2, true); isolate, factory->empty_string(), Builtins::kResolvePromise, 2, true);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, function, InstallWithIntrinsicDefaultProto(isolate, function,
Context::PROMISE_RESOLVE_INDEX); Context::PROMISE_RESOLVE_INDEX);
} }
@ -1946,6 +1951,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // Internal: PromiseHandle { // Internal: PromiseHandle
Handle<JSFunction> function = SimpleCreateFunction( Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(), Builtins::kPromiseHandle, 5, false); isolate, factory->empty_string(), Builtins::kPromiseHandle, 5, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, function, InstallWithIntrinsicDefaultProto(isolate, function,
Context::PROMISE_HANDLE_INDEX); Context::PROMISE_HANDLE_INDEX);
// Set up catch prediction // Set up catch prediction
@ -1957,6 +1963,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kPromiseHandleReject, 3, false); Builtins::kPromiseHandleReject, 3, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, function, InstallWithIntrinsicDefaultProto(isolate, function,
Context::PROMISE_HANDLE_REJECT_INDEX); Context::PROMISE_HANDLE_REJECT_INDEX);
// Set up catch prediction // Set up catch prediction
@ -1968,6 +1975,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kInternalPromiseReject, 3, true); Builtins::kInternalPromiseReject, 3, true);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto(isolate, function, InstallWithIntrinsicDefaultProto(isolate, function,
Context::PROMISE_INTERNAL_REJECT_INDEX); Context::PROMISE_INTERNAL_REJECT_INDEX);
} }
@ -2434,6 +2442,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
CreateFunction(isolate, factory->InternalizeUtf8String("TypedArray"), CreateFunction(isolate, factory->InternalizeUtf8String("TypedArray"),
JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, prototype, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, prototype,
Builtins::kIllegal); Builtins::kIllegal);
typed_array_fun->shared()->set_native(false);
InstallSpeciesGetter(typed_array_fun); InstallSpeciesGetter(typed_array_fun);
// Install the "constructor" property on the {prototype}. // Install the "constructor" property on the {prototype}.
@ -3375,6 +3384,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kAsyncFunctionAwaitCaught, 3, false); Builtins::kAsyncFunctionAwaitCaught, 3, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto( InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX); isolate, function, Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX);
} }
@ -3383,6 +3393,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kAsyncFunctionAwaitUncaught, 3, false); Builtins::kAsyncFunctionAwaitUncaught, 3, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto( InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_AWAIT_UNCAUGHT_INDEX); isolate, function, Context::ASYNC_FUNCTION_AWAIT_UNCAUGHT_INDEX);
} }
@ -3411,6 +3422,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Handle<JSFunction> function = Handle<JSFunction> function =
SimpleCreateFunction(isolate, factory->empty_string(), SimpleCreateFunction(isolate, factory->empty_string(),
Builtins::kAsyncFunctionPromiseCreate, 0, false); Builtins::kAsyncFunctionPromiseCreate, 0, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto( InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX); isolate, function, Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX);
} }
@ -3419,6 +3431,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Handle<JSFunction> function = SimpleCreateFunction( Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(), isolate, factory->empty_string(),
Builtins::kAsyncFunctionPromiseRelease, 1, false); Builtins::kAsyncFunctionPromiseRelease, 1, false);
function->shared()->set_native(false);
InstallWithIntrinsicDefaultProto( InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX); isolate, function, Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX);
} }