diff options
Diffstat (limited to 'deps/v8/src/bootstrapper.cc')
-rw-r--r-- | deps/v8/src/bootstrapper.cc | 1064 |
1 files changed, 671 insertions, 393 deletions
diff --git a/deps/v8/src/bootstrapper.cc b/deps/v8/src/bootstrapper.cc index c609e578d4..f68a12ab14 100644 --- a/deps/v8/src/bootstrapper.cc +++ b/deps/v8/src/bootstrapper.cc @@ -16,11 +16,7 @@ #include "src/isolate-inl.h" #include "src/snapshot/natives.h" #include "src/snapshot/snapshot.h" -#include "third_party/fdlibm/fdlibm.h" - -#if defined(V8_WASM) #include "src/wasm/wasm-js.h" -#endif namespace v8 { namespace internal { @@ -59,7 +55,6 @@ template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>( int index); template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); -template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index); void Bootstrapper::Initialize(bool create_heap_objects) { @@ -130,7 +125,6 @@ void Bootstrapper::TearDown() { DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap())); DeleteNativeSources( ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); - DeleteNativeSources(CodeStubNatives::GetSourceCache(isolate_->heap())); extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical } @@ -185,13 +179,11 @@ class Genesis BASE_EMBEDDED { // Similarly, we want to use the global that has been created by the templates // passed through the API. The global from the snapshot is detached from the // other objects in the snapshot. - void HookUpGlobalObject(Handle<JSGlobalObject> global_object, - Handle<FixedArray> outdated_contexts); + void HookUpGlobalObject(Handle<JSGlobalObject> global_object); // The native context has a ScriptContextTable that store declarative bindings // made in script scopes. Add a "this" binding to that table pointing to the // global proxy. void InstallGlobalThisBinding(); - void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts); // New context initialization. Used for creating a context from scratch. void InitializeGlobal(Handle<JSGlobalObject> global_object, Handle<JSFunction> empty_function, @@ -206,8 +198,11 @@ class Genesis BASE_EMBEDDED { HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) + DECLARE_FEATURE_INITIALIZATION(promise_extra, "") #undef DECLARE_FEATURE_INITIALIZATION + Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, + const char* name); Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, const char* name, ElementsKind elements_kind); @@ -222,6 +217,7 @@ class Genesis BASE_EMBEDDED { void InstallBuiltinFunctionIds(); void InstallExperimentalBuiltinFunctionIds(); void InitializeNormalizedMapCaches(); + void InstallJSProxyMaps(); enum ExtensionTraversalState { UNVISITED, VISITED, INSTALLED @@ -271,8 +267,7 @@ class Genesis BASE_EMBEDDED { FUNCTION_WITH_WRITEABLE_PROTOTYPE, FUNCTION_WITH_READONLY_PROTOTYPE, // Without prototype. - FUNCTION_WITHOUT_PROTOTYPE, - BOUND_FUNCTION + FUNCTION_WITHOUT_PROTOTYPE }; static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { @@ -340,26 +335,6 @@ Handle<Context> Bootstrapper::CreateEnvironment( } -bool Bootstrapper::CreateCodeStubContext(Isolate* isolate) { - HandleScope scope(isolate); - SaveContext save_context(isolate); - BootstrapperActive active(this); - - v8::ExtensionConfiguration no_extensions; - Handle<Context> native_context = CreateEnvironment( - MaybeHandle<JSGlobalProxy>(), v8::Local<v8::ObjectTemplate>(), - &no_extensions, THIN_CONTEXT); - isolate->heap()->SetRootCodeStubContext(*native_context); - isolate->set_context(*native_context); - Handle<JSObject> code_stub_exports = - isolate->factory()->NewJSObject(isolate->object_function()); - JSObject::NormalizeProperties(code_stub_exports, CLEAR_INOBJECT_PROPERTIES, 2, - "container to export to extra natives"); - isolate->heap()->SetRootCodeStubExportsObject(*code_stub_exports); - return InstallCodeStubNatives(isolate); -} - - static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { // object.__proto__ = proto; Handle<Map> old_map = Handle<Map>(object->map()); @@ -386,31 +361,55 @@ void Bootstrapper::DetachGlobal(Handle<Context> env) { namespace { +void InstallFunction(Handle<JSObject> target, Handle<Name> property_name, + Handle<JSFunction> function, Handle<String> function_name, + PropertyAttributes attributes = DONT_ENUM) { + JSObject::AddProperty(target, property_name, function, attributes); + if (target->IsJSGlobalObject()) { + function->shared()->set_instance_class_name(*function_name); + } + function->shared()->set_native(true); +} + + +static void InstallFunction(Handle<JSObject> target, + Handle<JSFunction> function, Handle<Name> name, + PropertyAttributes attributes = DONT_ENUM) { + Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); + InstallFunction(target, name, function, name_string, attributes); +} + + +static Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, + InstanceType type, int instance_size, + MaybeHandle<JSObject> maybe_prototype, + Builtins::Name call, + bool strict_function_map = false) { + Factory* factory = isolate->factory(); + Handle<Code> call_code(isolate->builtins()->builtin(call)); + Handle<JSObject> prototype; + static const bool kReadOnlyPrototype = false; + static const bool kInstallConstructor = false; + return maybe_prototype.ToHandle(&prototype) + ? factory->NewFunction(name, call_code, prototype, type, + instance_size, kReadOnlyPrototype, + kInstallConstructor, strict_function_map) + : factory->NewFunctionWithoutPrototype(name, call_code, + strict_function_map); +} + + Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, InstanceType type, int instance_size, MaybeHandle<JSObject> maybe_prototype, Builtins::Name call, PropertyAttributes attributes, bool strict_function_map = false) { - Isolate* isolate = target->GetIsolate(); - Factory* factory = isolate->factory(); Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); - Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); - Handle<JSObject> prototype; - static const bool kReadOnlyPrototype = false; - static const bool kInstallConstructor = false; Handle<JSFunction> function = - maybe_prototype.ToHandle(&prototype) - ? factory->NewFunction(name_string, call_code, prototype, type, - instance_size, kReadOnlyPrototype, - kInstallConstructor, strict_function_map) - : factory->NewFunctionWithoutPrototype(name_string, call_code, - strict_function_map); - JSObject::AddProperty(target, name, function, attributes); - if (target->IsJSGlobalObject()) { - function->shared()->set_instance_class_name(*name_string); - } - function->shared()->set_native(true); + CreateFunction(target->GetIsolate(), name_string, type, instance_size, + maybe_prototype, call, strict_function_map); + InstallFunction(target, name, function, name_string, attributes); return function; } @@ -484,7 +483,7 @@ void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); SetFunctionInstanceDescriptor(map, function_mode); - map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); + if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor(); map->set_is_callable(); return map; } @@ -557,7 +556,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { } // Allocate the empty function as the prototype for function - ES6 19.2.3 - Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); + Handle<Code> code(isolate->builtins()->EmptyFunction()); Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype(factory->empty_string(), code); @@ -597,7 +596,7 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map, FunctionMode function_mode) { - int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; + int size = IsFunctionModeWithPrototype(function_mode) ? 3 : 2; Map::EnsureDescriptorSlack(map, size); PropertyAttributes rw_attribs = @@ -607,35 +606,22 @@ void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map, PropertyAttributes roc_attribs = static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); - if (function_mode == BOUND_FUNCTION) { - { // Add length. - Handle<String> length_string = isolate()->factory()->length_string(); - DataDescriptor d(length_string, 0, roc_attribs, Representation::Tagged()); - map->AppendDescriptor(&d); - } - { // Add name. - Handle<String> name_string = isolate()->factory()->name_string(); - DataDescriptor d(name_string, 1, roc_attribs, Representation::Tagged()); - map->AppendDescriptor(&d); - } - } else { - DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || - function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || - function_mode == FUNCTION_WITHOUT_PROTOTYPE); - { // Add length. - Handle<AccessorInfo> length = - Accessors::FunctionLengthInfo(isolate(), roc_attribs); - AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), - length, roc_attribs); - map->AppendDescriptor(&d); - } - { // Add name. - Handle<AccessorInfo> name = - Accessors::FunctionNameInfo(isolate(), roc_attribs); - AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, - roc_attribs); - map->AppendDescriptor(&d); - } + DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || + function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || + function_mode == FUNCTION_WITHOUT_PROTOTYPE); + { // Add length. + Handle<AccessorInfo> length = + Accessors::FunctionLengthInfo(isolate(), roc_attribs); + AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), + length, roc_attribs); + map->AppendDescriptor(&d); + } + { // Add name. + Handle<AccessorInfo> name = + Accessors::FunctionNameInfo(isolate(), roc_attribs); + AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, + roc_attribs); + map->AppendDescriptor(&d); } if (IsFunctionModeWithPrototype(function_mode)) { // Add prototype. @@ -682,11 +668,13 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic( Handle<Code> code(isolate()->builtins()->builtin(builtin_name)); Handle<JSFunction> function = factory()->NewFunctionWithoutPrototype(name, code); - function->set_map(native_context()->sloppy_function_map()); function->shared()->DontAdaptArguments(); // %ThrowTypeError% must not have a name property. - JSReceiver::DeleteProperty(function, factory()->name_string()).Assert(); + if (JSReceiver::DeleteProperty(function, factory()->name_string()) + .IsNothing()) { + DCHECK(false); + } // length needs to be non configurable. Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate()); @@ -695,8 +683,10 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic( static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY)) .Assert(); - if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR).IsNothing()) + if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR) + .IsNothing()) { DCHECK(false); + } return function; } @@ -725,7 +715,7 @@ Handle<Map> Genesis::CreateStrictFunctionMap( FunctionMode function_mode, Handle<JSFunction> empty_function) { Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); SetStrictFunctionInstanceDescriptor(map, function_mode); - map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); + if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor(); map->set_is_callable(); Map::SetPrototype(map, empty_function); return map; @@ -736,7 +726,7 @@ Handle<Map> Genesis::CreateStrongFunctionMap( Handle<JSFunction> empty_function, bool is_constructor) { Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); SetStrongFunctionInstanceDescriptor(map); - map->set_is_constructor(is_constructor); + if (is_constructor) map->set_is_constructor(); Map::SetPrototype(map, empty_function); map->set_is_callable(); map->set_is_extensible(is_constructor); @@ -763,21 +753,6 @@ void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { // This map is installed in MakeFunctionInstancePrototypeWritable. strict_function_map_writable_prototype_ = CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); - - // Special map for non-constructor bound functions. - // TODO(bmeurer): Bound functions should not be represented as JSFunctions. - Handle<Map> bound_function_without_constructor_map = - CreateStrictFunctionMap(BOUND_FUNCTION, empty); - native_context()->set_bound_function_without_constructor_map( - *bound_function_without_constructor_map); - - // Special map for constructor bound functions. - // TODO(bmeurer): Bound functions should not be represented as JSFunctions. - Handle<Map> bound_function_with_constructor_map = - Map::Copy(bound_function_without_constructor_map, "IsConstructor"); - bound_function_with_constructor_map->set_is_constructor(true); - native_context()->set_bound_function_with_constructor_map( - *bound_function_with_constructor_map); } @@ -920,23 +895,6 @@ void Genesis::InstallGlobalThisBinding() { } -void Genesis::HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts) { - // One of these contexts should be the one that declares the global "this" - // binding. - for (int i = 0; i < outdated_contexts->length(); ++i) { - Context* context = Context::cast(outdated_contexts->get(i)); - if (context->IsScriptContext()) { - ScopeInfo* scope_info = context->scope_info(); - int slot = scope_info->ReceiverContextSlotIndex(); - if (slot >= 0) { - DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); - context->set(slot, native_context()->global_proxy()); - } - } - } -} - - Handle<JSGlobalObject> Genesis::CreateNewGlobals( v8::Local<v8::ObjectTemplate> global_proxy_template, Handle<JSGlobalProxy> global_proxy) { @@ -973,8 +931,7 @@ Handle<JSGlobalObject> Genesis::CreateNewGlobals( if (js_global_object_template.is_null()) { Handle<String> name = Handle<String>(heap()->empty_string()); - Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( - Builtins::kIllegal)); + Handle<Code> code = isolate()->builtins()->Illegal(); Handle<JSObject> prototype = factory()->NewFunctionPrototype(isolate()->object_function()); js_global_object_function = factory()->NewFunction( @@ -1004,8 +961,7 @@ Handle<JSGlobalObject> Genesis::CreateNewGlobals( Handle<JSFunction> global_proxy_function; if (global_proxy_template.IsEmpty()) { Handle<String> name = Handle<String>(heap()->empty_string()); - Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( - Builtins::kIllegal)); + Handle<Code> code = isolate()->builtins()->Illegal(); global_proxy_function = factory()->NewFunction( name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); } else { @@ -1044,27 +1000,65 @@ void Genesis::HookUpGlobalProxy(Handle<JSGlobalObject> global_object, } -void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object, - Handle<FixedArray> outdated_contexts) { +void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) { Handle<JSGlobalObject> global_object_from_snapshot( JSGlobalObject::cast(native_context()->extension())); native_context()->set_extension(*global_object); native_context()->set_security_token(*global_object); - // Replace outdated global objects in deserialized contexts. - for (int i = 0; i < outdated_contexts->length(); ++i) { - Context* context = Context::cast(outdated_contexts->get(i)); - // Assert that there is only one native context. - DCHECK(!context->IsNativeContext() || context == *native_context()); - DCHECK_EQ(context->global_object(), *global_object_from_snapshot); - context->set_global_object(*global_object); - } - TransferNamedProperties(global_object_from_snapshot, global_object); TransferIndexedProperties(global_object_from_snapshot, global_object); } +static Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, + Handle<String> name, + Builtins::Name call, int len, + bool adapt) { + Handle<JSFunction> fun = + CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, + MaybeHandle<JSObject>(), call); + if (adapt) { + fun->shared()->set_internal_formal_parameter_count(len); + } else { + fun->shared()->DontAdaptArguments(); + } + fun->shared()->set_length(len); + return fun; +} + + +static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, + Handle<String> name, + Builtins::Name call, int len, + bool adapt) { + Handle<JSFunction> fun = + SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); + InstallFunction(base, fun, name, DONT_ENUM); + return fun; +} + + +static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, + const char* name, + Builtins::Name call, int len, + bool adapt) { + Factory* const factory = base->GetIsolate()->factory(); + return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, + len, adapt); +} + + +static void InstallWithIntrinsicDefaultProto(Isolate* isolate, + Handle<JSFunction> function, + int context_index) { + Handle<Smi> index(Smi::FromInt(context_index), isolate); + JSObject::AddProperty( + function, isolate->factory()->native_context_index_symbol(), index, NONE); + isolate->native_context()->set(context_index, *function); +} + + // This is only called if we are not using snapshots. The equivalent // work in the snapshot case is done in HookUpGlobalObject. void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, @@ -1076,7 +1070,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, native_context()->set_previous(NULL); // Set extension and global object. native_context()->set_extension(*global_object); - native_context()->set_global_object(*global_object); // Security setup: Set the security token of the native context to the global // object. This makes the security check between two different contexts fail // by default even in case of global object reinitialization. @@ -1090,18 +1083,71 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, native_context()->set_script_context_table(*script_context_table); InstallGlobalThisBinding(); - Handle<String> object_name = factory->Object_string(); - JSObject::AddProperty( - global_object, object_name, isolate->object_function(), DONT_ENUM); + { // --- O b j e c t --- + Handle<String> object_name = factory->Object_string(); + Handle<JSFunction> object_function = isolate->object_function(); + JSObject::AddProperty(global_object, object_name, object_function, + DONT_ENUM); + SimpleInstallFunction(object_function, factory->assign_string(), + Builtins::kObjectAssign, 2, false); + SimpleInstallFunction(object_function, factory->create_string(), + Builtins::kObjectCreate, 2, false); + Handle<JSFunction> object_freeze = SimpleInstallFunction( + object_function, "freeze", Builtins::kObjectFreeze, 1, false); + native_context()->set_object_freeze(*object_freeze); + Handle<JSFunction> object_is_extensible = + SimpleInstallFunction(object_function, "isExtensible", + Builtins::kObjectIsExtensible, 1, false); + native_context()->set_object_is_extensible(*object_is_extensible); + Handle<JSFunction> object_is_frozen = SimpleInstallFunction( + object_function, "isFrozen", Builtins::kObjectIsFrozen, 1, false); + native_context()->set_object_is_frozen(*object_is_frozen); + Handle<JSFunction> object_is_sealed = SimpleInstallFunction( + object_function, "isSealed", Builtins::kObjectIsSealed, 1, false); + native_context()->set_object_is_sealed(*object_is_sealed); + Handle<JSFunction> object_keys = SimpleInstallFunction( + object_function, "keys", Builtins::kObjectKeys, 1, false); + native_context()->set_object_keys(*object_keys); + SimpleInstallFunction(object_function, "preventExtensions", + Builtins::kObjectPreventExtensions, 1, false); + SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1, + false); + } Handle<JSObject> global(native_context()->global_object()); - // Install global Function object - Handle<JSFunction> function_function = - InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, - empty_function, Builtins::kIllegal); - function_function->initial_map()->set_is_callable(); - function_function->initial_map()->set_is_constructor(true); + { // --- F u n c t i o n --- + Handle<JSFunction> prototype = empty_function; + Handle<JSFunction> function_fun = + InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, + prototype, Builtins::kFunctionConstructor); + function_fun->set_prototype_or_initial_map( + *sloppy_function_map_writable_prototype_); + function_fun->shared()->DontAdaptArguments(); + function_fun->shared()->set_construct_stub( + *isolate->builtins()->FunctionConstructor()); + function_fun->shared()->set_length(1); + InstallWithIntrinsicDefaultProto(isolate, function_fun, + Context::FUNCTION_FUNCTION_INDEX); + + // Setup the methods on the %FunctionPrototype%. + SimpleInstallFunction(prototype, factory->apply_string(), + Builtins::kFunctionPrototypeApply, 2, false); + SimpleInstallFunction(prototype, factory->bind_string(), + Builtins::kFunctionPrototypeBind, 1, false); + SimpleInstallFunction(prototype, factory->call_string(), + Builtins::kFunctionPrototypeCall, 1, false); + SimpleInstallFunction(prototype, factory->toString_string(), + Builtins::kFunctionPrototypeToString, 0, false); + + // Install the "constructor" property on the %FunctionPrototype%. + JSObject::AddProperty(prototype, factory->constructor_string(), + function_fun, DONT_ENUM); + + sloppy_function_map_writable_prototype_->SetConstructor(*function_fun); + strict_function_map_writable_prototype_->SetConstructor(*function_fun); + native_context()->strong_function_map()->SetConstructor(*function_fun); + } { // --- A r r a y --- Handle<JSFunction> array_function = @@ -1134,11 +1180,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, initial_map->AppendDescriptor(&d); } - // array_function is used internally. JS code creating array object should - // search for the 'Array' property on the global object and use that one - // as the constructor. 'Array' property on a global object can be - // overwritten by JS code. - native_context()->set_array_function(*array_function); + InstallWithIntrinsicDefaultProto(isolate, array_function, + Context::ARRAY_FUNCTION_INDEX); // Cache the array maps, needed by ArrayConstructorStub CacheInitialJSArrayMaps(native_context(), initial_map); @@ -1150,14 +1193,23 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, Map::Copy(initial_map, "SetInstancePrototype"); initial_strong_map->set_is_strong(); CacheInitialJSArrayMaps(native_context(), initial_strong_map); + + Handle<JSFunction> is_arraylike = SimpleInstallFunction( + array_function, isolate->factory()->InternalizeUtf8String("isArray"), + Builtins::kArrayIsArray, 1, true); + native_context()->set_is_arraylike(*is_arraylike); } { // --- N u m b e r --- - Handle<JSFunction> number_fun = - InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, - isolate->initial_object_prototype(), - Builtins::kIllegal); - native_context()->set_number_function(*number_fun); + Handle<JSFunction> number_fun = InstallFunction( + global, "Number", JS_VALUE_TYPE, JSValue::kSize, + isolate->initial_object_prototype(), Builtins::kNumberConstructor); + number_fun->shared()->DontAdaptArguments(); + number_fun->shared()->set_construct_stub( + *isolate->builtins()->NumberConstructor_ConstructStub()); + number_fun->shared()->set_length(1); + InstallWithIntrinsicDefaultProto(isolate, number_fun, + Context::NUMBER_FUNCTION_INDEX); } { // --- B o o l e a n --- @@ -1165,18 +1217,20 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, isolate->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_boolean_function(*boolean_fun); + InstallWithIntrinsicDefaultProto(isolate, boolean_fun, + Context::BOOLEAN_FUNCTION_INDEX); } { // --- S t r i n g --- Handle<JSFunction> string_fun = InstallFunction( global, "String", JS_VALUE_TYPE, JSValue::kSize, isolate->initial_object_prototype(), Builtins::kStringConstructor); - string_fun->shared()->set_construct_stub(isolate->builtins()->builtin( - Builtins::kStringConstructor_ConstructStub)); + string_fun->shared()->set_construct_stub( + *isolate->builtins()->StringConstructor_ConstructStub()); string_fun->shared()->DontAdaptArguments(); string_fun->shared()->set_length(1); - native_context()->set_string_function(*string_fun); + InstallWithIntrinsicDefaultProto(isolate, string_fun, + Context::STRING_FUNCTION_INDEX); Handle<Map> string_map = Handle<Map>(native_context()->string_function()->initial_map()); @@ -1199,19 +1253,143 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, Handle<JSFunction> symbol_fun = InstallFunction( global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, isolate->initial_object_prototype(), Builtins::kSymbolConstructor); - symbol_fun->shared()->set_construct_stub(isolate->builtins()->builtin( - Builtins::kSymbolConstructor_ConstructStub)); - symbol_fun->shared()->set_internal_formal_parameter_count(1); + symbol_fun->shared()->set_construct_stub( + *isolate->builtins()->SymbolConstructor_ConstructStub()); symbol_fun->shared()->set_length(1); + symbol_fun->shared()->DontAdaptArguments(); native_context()->set_symbol_function(*symbol_fun); } { // --- D a t e --- // Builtin functions for Date.prototype. - InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, - isolate->initial_object_prototype(), Builtins::kIllegal); - } + Handle<JSObject> prototype = + factory->NewJSObject(isolate->object_function(), TENURED); + Handle<JSFunction> date_fun = + InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype, + Builtins::kDateConstructor); + InstallWithIntrinsicDefaultProto(isolate, date_fun, + Context::DATE_FUNCTION_INDEX); + date_fun->shared()->set_construct_stub( + *isolate->builtins()->DateConstructor_ConstructStub()); + date_fun->shared()->set_length(7); + date_fun->shared()->DontAdaptArguments(); + + // Install the Date.now, Date.parse and Date.UTC functions. + SimpleInstallFunction(date_fun, "now", Builtins::kDateNow, 0, false); + SimpleInstallFunction(date_fun, "parse", Builtins::kDateParse, 1, false); + SimpleInstallFunction(date_fun, "UTC", Builtins::kDateUTC, 7, false); + + // Install the "constructor" property on the {prototype}. + JSObject::AddProperty(prototype, factory->constructor_string(), date_fun, + DONT_ENUM); + + // Install the Date.prototype methods. + SimpleInstallFunction(prototype, "toString", + Builtins::kDatePrototypeToString, 0, false); + SimpleInstallFunction(prototype, "toDateString", + Builtins::kDatePrototypeToDateString, 0, false); + SimpleInstallFunction(prototype, "toTimeString", + Builtins::kDatePrototypeToTimeString, 0, false); + SimpleInstallFunction(prototype, "toGMTString", + Builtins::kDatePrototypeToUTCString, 0, false); + SimpleInstallFunction(prototype, "toISOString", + Builtins::kDatePrototypeToISOString, 0, false); + SimpleInstallFunction(prototype, "toUTCString", + Builtins::kDatePrototypeToUTCString, 0, false); + SimpleInstallFunction(prototype, "getDate", Builtins::kDatePrototypeGetDate, + 0, true); + SimpleInstallFunction(prototype, "setDate", Builtins::kDatePrototypeSetDate, + 1, false); + SimpleInstallFunction(prototype, "getDay", Builtins::kDatePrototypeGetDay, + 0, true); + SimpleInstallFunction(prototype, "getFullYear", + Builtins::kDatePrototypeGetFullYear, 0, true); + SimpleInstallFunction(prototype, "setFullYear", + Builtins::kDatePrototypeSetFullYear, 3, false); + SimpleInstallFunction(prototype, "getHours", + Builtins::kDatePrototypeGetHours, 0, true); + SimpleInstallFunction(prototype, "setHours", + Builtins::kDatePrototypeSetHours, 4, false); + SimpleInstallFunction(prototype, "getMilliseconds", + Builtins::kDatePrototypeGetMilliseconds, 0, true); + SimpleInstallFunction(prototype, "setMilliseconds", + Builtins::kDatePrototypeSetMilliseconds, 1, false); + SimpleInstallFunction(prototype, "getMinutes", + Builtins::kDatePrototypeGetMinutes, 0, true); + SimpleInstallFunction(prototype, "setMinutes", + Builtins::kDatePrototypeSetMinutes, 3, false); + SimpleInstallFunction(prototype, "getMonth", + Builtins::kDatePrototypeGetMonth, 0, true); + SimpleInstallFunction(prototype, "setMonth", + Builtins::kDatePrototypeSetMonth, 2, false); + SimpleInstallFunction(prototype, "getSeconds", + Builtins::kDatePrototypeGetSeconds, 0, true); + SimpleInstallFunction(prototype, "setSeconds", + Builtins::kDatePrototypeSetSeconds, 2, false); + SimpleInstallFunction(prototype, "getTime", Builtins::kDatePrototypeGetTime, + 0, true); + SimpleInstallFunction(prototype, "setTime", Builtins::kDatePrototypeSetTime, + 1, false); + SimpleInstallFunction(prototype, "getTimezoneOffset", + Builtins::kDatePrototypeGetTimezoneOffset, 0, true); + SimpleInstallFunction(prototype, "getUTCDate", + Builtins::kDatePrototypeGetUTCDate, 0, true); + SimpleInstallFunction(prototype, "setUTCDate", + Builtins::kDatePrototypeSetUTCDate, 1, false); + SimpleInstallFunction(prototype, "getUTCDay", + Builtins::kDatePrototypeGetUTCDay, 0, true); + SimpleInstallFunction(prototype, "getUTCFullYear", + Builtins::kDatePrototypeGetUTCFullYear, 0, true); + SimpleInstallFunction(prototype, "setUTCFullYear", + Builtins::kDatePrototypeSetUTCFullYear, 3, false); + SimpleInstallFunction(prototype, "getUTCHours", + Builtins::kDatePrototypeGetUTCHours, 0, true); + SimpleInstallFunction(prototype, "setUTCHours", + Builtins::kDatePrototypeSetUTCHours, 4, false); + SimpleInstallFunction(prototype, "getUTCMilliseconds", + Builtins::kDatePrototypeGetUTCMilliseconds, 0, true); + SimpleInstallFunction(prototype, "setUTCMilliseconds", + Builtins::kDatePrototypeSetUTCMilliseconds, 1, false); + SimpleInstallFunction(prototype, "getUTCMinutes", + Builtins::kDatePrototypeGetUTCMinutes, 0, true); + SimpleInstallFunction(prototype, "setUTCMinutes", + Builtins::kDatePrototypeSetUTCMinutes, 3, false); + SimpleInstallFunction(prototype, "getUTCMonth", + Builtins::kDatePrototypeGetUTCMonth, 0, true); + SimpleInstallFunction(prototype, "setUTCMonth", + Builtins::kDatePrototypeSetUTCMonth, 2, false); + SimpleInstallFunction(prototype, "getUTCSeconds", + Builtins::kDatePrototypeGetUTCSeconds, 0, true); + SimpleInstallFunction(prototype, "setUTCSeconds", + Builtins::kDatePrototypeSetUTCSeconds, 2, false); + SimpleInstallFunction(prototype, "valueOf", Builtins::kDatePrototypeValueOf, + 0, false); + SimpleInstallFunction(prototype, "getYear", Builtins::kDatePrototypeGetYear, + 0, true); + SimpleInstallFunction(prototype, "setYear", Builtins::kDatePrototypeSetYear, + 1, false); + + // Install i18n fallback functions. + SimpleInstallFunction(prototype, "toLocaleString", + Builtins::kDatePrototypeToString, 0, false); + SimpleInstallFunction(prototype, "toLocaleDateString", + Builtins::kDatePrototypeToDateString, 0, false); + SimpleInstallFunction(prototype, "toLocaleTimeString", + Builtins::kDatePrototypeToTimeString, 0, false); + + // Install the @@toPrimitive function. + Handle<JSFunction> to_primitive = InstallFunction( + prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE, + JSObject::kHeaderSize, MaybeHandle<JSObject>(), + Builtins::kDatePrototypeToPrimitive, + static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); + + // Set the expected parameters for @@toPrimitive to 1; required by builtin. + to_primitive->shared()->set_internal_formal_parameter_count(1); + // Set the length for the function to satisfy ECMA-262. + to_primitive->shared()->set_length(1); + } { // -- R e g E x p // Builtin functions for RegExp.prototype. @@ -1219,7 +1397,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, isolate->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_regexp_function(*regexp_fun); + InstallWithIntrinsicDefaultProto(isolate, regexp_fun, + Context::REGEXP_FUNCTION_INDEX); + regexp_fun->shared()->set_construct_stub( + *isolate->builtins()->JSBuiltinsConstructStub()); DCHECK(regexp_fun->has_initial_map()); Handle<Map> initial_map(regexp_fun->initial_map()); @@ -1243,6 +1424,62 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, num_fields * kPointerSize); } + { // -- E r r o r + Handle<JSFunction> error_fun = InstallFunction( + global, "Error", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, error_fun, + Context::ERROR_FUNCTION_INDEX); + } + + { // -- E v a l E r r o r + Handle<JSFunction> eval_error_fun = InstallFunction( + global, "EvalError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, + Context::EVAL_ERROR_FUNCTION_INDEX); + } + + { // -- R a n g e E r r o r + Handle<JSFunction> range_error_fun = InstallFunction( + global, "RangeError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, range_error_fun, + Context::RANGE_ERROR_FUNCTION_INDEX); + } + + { // -- R e f e r e n c e E r r o r + Handle<JSFunction> reference_error_fun = InstallFunction( + global, "ReferenceError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, + Context::REFERENCE_ERROR_FUNCTION_INDEX); + } + + { // -- S y n t a x E r r o r + Handle<JSFunction> syntax_error_fun = InstallFunction( + global, "SyntaxError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, + Context::SYNTAX_ERROR_FUNCTION_INDEX); + } + + { // -- T y p e E r r o r + Handle<JSFunction> type_error_fun = InstallFunction( + global, "TypeError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, type_error_fun, + Context::TYPE_ERROR_FUNCTION_INDEX); + } + + { // -- U R I E r r o r + Handle<JSFunction> uri_error_fun = InstallFunction( + global, "URIError", JS_OBJECT_TYPE, JSObject::kHeaderSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, + Context::URI_ERROR_FUNCTION_INDEX); + } + // Initialize the embedder data slot. Handle<FixedArray> embedder_data = factory->NewFixedArray(3); native_context()->set_embedder_data(*embedder_data); @@ -1274,20 +1511,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, { // -- A r r a y B u f f e r Handle<JSFunction> array_buffer_fun = - InstallFunction( - global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, - JSArrayBuffer::kSizeWithInternalFields, - isolate->initial_object_prototype(), - Builtins::kIllegal); - native_context()->set_array_buffer_fun(*array_buffer_fun); + InstallArrayBuffer(global, "ArrayBuffer"); + InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, + Context::ARRAY_BUFFER_FUN_INDEX); } { // -- T y p e d A r r a y s -#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ - { \ - Handle<JSFunction> fun; \ - InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ - native_context()->set_##type##_array_fun(*fun); \ +#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ + { \ + Handle<JSFunction> fun; \ + InstallTypedArray(#Type "Array", TYPE##_ELEMENTS, &fun); \ + InstallWithIntrinsicDefaultProto(isolate, fun, \ + Context::TYPE##_ARRAY_FUN_INDEX); \ } TYPED_ARRAYS(INSTALL_TYPED_ARRAY) #undef INSTALL_TYPED_ARRAY @@ -1298,21 +1533,26 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, JSDataView::kSizeWithInternalFields, isolate->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_data_view_fun(*data_view_fun); + InstallWithIntrinsicDefaultProto(isolate, data_view_fun, + Context::DATA_VIEW_FUN_INDEX); + data_view_fun->shared()->set_construct_stub( + *isolate->builtins()->JSBuiltinsConstructStub()); } { // -- M a p Handle<JSFunction> js_map_fun = InstallFunction( global, "Map", JS_MAP_TYPE, JSMap::kSize, isolate->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_js_map_fun(*js_map_fun); + InstallWithIntrinsicDefaultProto(isolate, js_map_fun, + Context::JS_MAP_FUN_INDEX); } { // -- S e t Handle<JSFunction> js_set_fun = InstallFunction( global, "Set", JS_SET_TYPE, JSSet::kSize, isolate->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_js_set_fun(*js_set_fun); + InstallWithIntrinsicDefaultProto(isolate, js_set_fun, + Context::JS_SET_FUN_INDEX); } { // -- I t e r a t o r R e s u l t @@ -1337,25 +1577,63 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, native_context()->set_iterator_result_map(*map); } - // -- W e a k M a p - InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, - isolate->initial_object_prototype(), Builtins::kIllegal); - // -- W e a k S e t - InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, - isolate->initial_object_prototype(), Builtins::kIllegal); + { // -- W e a k M a p + Handle<JSFunction> js_weak_map_fun = InstallFunction( + global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, js_weak_map_fun, + Context::JS_WEAK_MAP_FUN_INDEX); + } + + { // -- W e a k S e t + Handle<JSFunction> js_weak_set_fun = InstallFunction( + global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, + isolate->initial_object_prototype(), Builtins::kIllegal); + InstallWithIntrinsicDefaultProto(isolate, js_weak_set_fun, + Context::JS_WEAK_SET_FUN_INDEX); + } + + { // --- B o u n d F u n c t i o n + Handle<Map> map = + factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize); + map->set_is_callable(); + Map::SetPrototype(map, empty_function); + + PropertyAttributes roc_attribs = + static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); + Map::EnsureDescriptorSlack(map, 2); + + { // length + DataDescriptor d(factory->length_string(), JSBoundFunction::kLengthIndex, + roc_attribs, Representation::Tagged()); + map->AppendDescriptor(&d); + } + { // name + DataDescriptor d(factory->name_string(), JSBoundFunction::kNameIndex, + roc_attribs, Representation::Tagged()); + map->AppendDescriptor(&d); + } + + map->SetInObjectProperties(2); + native_context()->set_bound_function_without_constructor_map(*map); + + map = Map::Copy(map, "IsConstructor"); + map->set_is_constructor(); + native_context()->set_bound_function_with_constructor_map(*map); + } { // --- sloppy arguments map // Make sure we can recognize argument objects at runtime. // This is done by introducing an anonymous function with // class_name equals 'Arguments'. Handle<String> arguments_string = factory->Arguments_string(); - Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); + Handle<Code> code = isolate->builtins()->Illegal(); Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( arguments_string, code); function->shared()->set_instance_class_name(*arguments_string); - Handle<Map> map = - factory->NewMap(JS_OBJECT_TYPE, Heap::kSloppyArgumentsObjectSize); + Handle<Map> map = factory->NewMap( + JS_OBJECT_TYPE, Heap::kSloppyArgumentsObjectSize, FAST_ELEMENTS); // Create the descriptor array for the arguments object. Map::EnsureDescriptorSlack(map, 2); @@ -1414,8 +1692,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, caller->set_setter(*poison); // Create the map. Allocate one in-object field for length. - Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, - Heap::kStrictArgumentsObjectSize); + Handle<Map> map = factory->NewMap( + JS_OBJECT_TYPE, Heap::kStrictArgumentsObjectSize, FAST_ELEMENTS); // Create the descriptor array for the arguments object. Map::EnsureDescriptorSlack(map, 3); @@ -1454,8 +1732,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, { // --- context extension // Create a function for the context extension objects. - Handle<Code> code = Handle<Code>( - isolate->builtins()->builtin(Builtins::kIllegal)); + Handle<Code> code = isolate->builtins()->Illegal(); Handle<JSFunction> context_extension_fun = factory->NewFunction( factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE, JSObject::kHeaderSize); @@ -1469,9 +1746,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, { // Set up the call-as-function delegate. - Handle<Code> code = - Handle<Code>(isolate->builtins()->builtin( - Builtins::kHandleApiCallAsFunction)); + Handle<Code> code = isolate->builtins()->HandleApiCallAsFunction(); Handle<JSFunction> delegate = factory->NewFunction( factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); native_context()->set_call_as_function_delegate(*delegate); @@ -1480,15 +1755,13 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, { // Set up the call-as-constructor delegate. - Handle<Code> code = - Handle<Code>(isolate->builtins()->builtin( - Builtins::kHandleApiCallAsConstructor)); + Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); Handle<JSFunction> delegate = factory->NewFunction( factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); native_context()->set_call_as_constructor_delegate(*delegate); delegate->shared()->DontAdaptArguments(); } -} +} // NOLINT(readability/fn_size) void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, @@ -1514,6 +1787,7 @@ void Genesis::InitializeExperimentalGlobal() { HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) + FEATURE_INITIALIZE_GLOBAL(promise_extra, "") #undef FEATURE_INITIALIZE_GLOBAL } @@ -1577,20 +1851,6 @@ bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate, } -bool Bootstrapper::CompileCodeStubBuiltin(Isolate* isolate, int index) { - HandleScope scope(isolate); - Vector<const char> name = CodeStubNatives::GetScriptName(index); - Handle<String> source_code = - isolate->bootstrapper()->SourceLookup<CodeStubNatives>(index); - Handle<JSObject> global(isolate->global_object()); - Handle<JSObject> exports(isolate->heap()->code_stub_exports_object()); - Handle<Object> args[] = {global, exports}; - bool result = - CompileNative(isolate, name, source_code, arraysize(args), args); - return result; -} - - bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, Handle<String> source, int argc, Handle<Object> argv[]) { @@ -1616,10 +1876,9 @@ bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, DCHECK(context->IsNativeContext()); - Handle<Context> runtime_context(context->runtime_context()); Handle<JSFunction> fun = isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, - runtime_context); + context); Handle<Object> receiver = isolate->factory()->undefined_value(); // For non-extension scripts, run script to get the function wrapper. @@ -1719,24 +1978,6 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, } -template <typename Data> -Handle<JSTypedArray> CreateTypedArray(Isolate* isolate, ExternalArrayType type, - size_t num_elements, Data** data) { - size_t byte_length = num_elements * sizeof(**data); - Handle<JSArrayBuffer> buffer = - isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared, TENURED); - bool is_external = (*data != nullptr); - if (!is_external) { - *data = reinterpret_cast<Data*>( - isolate->array_buffer_allocator()->Allocate(byte_length)); - } - JSArrayBuffer::Setup(buffer, isolate, is_external, *data, byte_length, - SharedFlag::kNotShared); - return isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements, - TENURED); -} - - void Genesis::ConfigureUtilsObject(ContextType context_type) { switch (context_type) { // We still need the utils object to find debug functions. @@ -1764,12 +2005,6 @@ void Genesis::ConfigureUtilsObject(ContextType context_type) { // The utils object can be removed for cases that reach this point. native_context()->set_natives_utils_object(heap()->undefined_value()); - -#ifdef DEBUG - JSGlobalObject* dummy = native_context()->runtime_context()->global_object(); - DCHECK_EQ(0, dummy->elements()->length()); - DCHECK_EQ(0, GlobalDictionary::cast(dummy->properties())->NumberOfElements()); -#endif } @@ -1795,11 +2030,8 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, Handle<JSFunction> apply = InstallFunction( container, "reflect_apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, MaybeHandle<JSObject>(), Builtins::kReflectApply); - apply->shared()->set_internal_formal_parameter_count(3); + apply->shared()->DontAdaptArguments(); apply->shared()->set_length(3); - Handle<TypeFeedbackVector> feedback_vector = - TypeFeedbackVector::CreatePushAppliedArgumentsVector(isolate); - apply->shared()->set_feedback_vector(*feedback_vector); native_context->set_reflect_apply(*apply); } @@ -1807,14 +2039,20 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, Handle<JSFunction> construct = InstallFunction( container, "reflect_construct", JS_OBJECT_TYPE, JSObject::kHeaderSize, MaybeHandle<JSObject>(), Builtins::kReflectConstruct); - construct->shared()->set_internal_formal_parameter_count(3); + construct->shared()->DontAdaptArguments(); construct->shared()->set_length(2); - Handle<TypeFeedbackVector> feedback_vector = - TypeFeedbackVector::CreatePushAppliedArgumentsVector(isolate); - construct->shared()->set_feedback_vector(*feedback_vector); native_context->set_reflect_construct(*construct); } + { + Handle<JSFunction> to_string = InstallFunction( + container, "object_to_string", JS_OBJECT_TYPE, JSObject::kHeaderSize, + MaybeHandle<JSObject>(), Builtins::kObjectProtoToString); + to_string->shared()->DontAdaptArguments(); + to_string->shared()->set_length(0); + native_context->set_object_to_string(*to_string); + } + Handle<JSObject> iterator_prototype; { @@ -1836,12 +2074,26 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, generator_function_prototype, NONE); static const bool kUseStrictFunctionMap = true; - Handle<JSFunction> generator_function_function = - InstallFunction(container, "GeneratorFunction", JS_FUNCTION_TYPE, - JSFunction::kSize, generator_function_prototype, - Builtins::kIllegal, kUseStrictFunctionMap); - generator_function_function->initial_map()->set_is_callable(); - generator_function_function->initial_map()->set_is_constructor(true); + Handle<JSFunction> generator_function_function = InstallFunction( + container, "GeneratorFunction", JS_FUNCTION_TYPE, JSFunction::kSize, + generator_function_prototype, Builtins::kGeneratorFunctionConstructor, + kUseStrictFunctionMap); + generator_function_function->set_prototype_or_initial_map( + native_context->sloppy_generator_function_map()); + generator_function_function->shared()->DontAdaptArguments(); + generator_function_function->shared()->set_construct_stub( + *isolate->builtins()->GeneratorFunctionConstructor()); + generator_function_function->shared()->set_length(1); + InstallWithIntrinsicDefaultProto( + isolate, generator_function_function, + Context::GENERATOR_FUNCTION_FUNCTION_INDEX); + + native_context->sloppy_generator_function_map()->SetConstructor( + *generator_function_function); + native_context->strict_generator_function_map()->SetConstructor( + *generator_function_function); + native_context->strong_generator_function_map()->SetConstructor( + *generator_function_function); } { // -- S e t I t e r a t o r @@ -2028,6 +2280,7 @@ void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, INITIALIZE_FLAG(FLAG_harmony_tostring) INITIALIZE_FLAG(FLAG_harmony_tolength) + INITIALIZE_FLAG(FLAG_harmony_species) #undef INITIALIZE_FLAG } @@ -2037,34 +2290,21 @@ void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, void Genesis::InitializeGlobal_##id() {} EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) -EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes) -EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) -EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) -EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring_bind) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring_assignment) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tolength) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_do_expressions) - - -static void SimpleInstallFunction(Handle<JSObject>& base, const char* name, - Builtins::Name call, int len, bool adapt) { - Handle<JSFunction> fun = - InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, - MaybeHandle<JSObject>(), call); - if (adapt) { - fun->shared()->set_internal_formal_parameter_count(len); - } else { - fun->shared()->DontAdaptArguments(); - } - fun->shared()->set_length(len); -} +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_lookbehind) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_name) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(promise_extra) void InstallPublicSymbol(Factory* factory, Handle<Context> native_context, @@ -2109,35 +2349,50 @@ void Genesis::InitializeGlobal_harmony_regexp_subclass() { void Genesis::InitializeGlobal_harmony_reflect() { + Factory* factory = isolate()->factory(); + + // We currently use some of the Reflect functions internally, even when + // the --harmony-reflect flag is not given. + + Handle<JSFunction> define_property = + SimpleCreateFunction(isolate(), factory->defineProperty_string(), + Builtins::kReflectDefineProperty, 3, true); + native_context()->set_reflect_define_property(*define_property); + + Handle<JSFunction> delete_property = + SimpleCreateFunction(isolate(), factory->deleteProperty_string(), + Builtins::kReflectDeleteProperty, 2, true); + native_context()->set_reflect_delete_property(*delete_property); + if (!FLAG_harmony_reflect) return; Handle<JSGlobalObject> global(JSGlobalObject::cast( native_context()->global_object())); - Handle<String> reflect_string = - factory()->NewStringFromStaticChars("Reflect"); + Handle<String> reflect_string = factory->NewStringFromStaticChars("Reflect"); Handle<JSObject> reflect = - factory()->NewJSObject(isolate()->object_function(), TENURED); + factory->NewJSObject(isolate()->object_function(), TENURED); JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM); - SimpleInstallFunction(reflect, "defineProperty", - Builtins::kReflectDefineProperty, 3, true); - SimpleInstallFunction(reflect, "deleteProperty", - Builtins::kReflectDeleteProperty, 2, true); - SimpleInstallFunction(reflect, "get", - Builtins::kReflectGet, 3, false); - SimpleInstallFunction(reflect, "getOwnPropertyDescriptor", + InstallFunction(reflect, define_property, factory->defineProperty_string()); + InstallFunction(reflect, delete_property, factory->deleteProperty_string()); + + SimpleInstallFunction(reflect, factory->get_string(), + Builtins::kReflectGet, 2, false); + SimpleInstallFunction(reflect, factory->getOwnPropertyDescriptor_string(), Builtins::kReflectGetOwnPropertyDescriptor, 2, true); - SimpleInstallFunction(reflect, "getPrototypeOf", + SimpleInstallFunction(reflect, factory->getPrototypeOf_string(), Builtins::kReflectGetPrototypeOf, 1, true); - SimpleInstallFunction(reflect, "has", + SimpleInstallFunction(reflect, factory->has_string(), Builtins::kReflectHas, 2, true); - SimpleInstallFunction(reflect, "isExtensible", + SimpleInstallFunction(reflect, factory->isExtensible_string(), Builtins::kReflectIsExtensible, 1, true); - SimpleInstallFunction(reflect, "preventExtensions", + SimpleInstallFunction(reflect, factory->ownKeys_string(), + Builtins::kReflectOwnKeys, 1, true); + SimpleInstallFunction(reflect, factory->preventExtensions_string(), Builtins::kReflectPreventExtensions, 1, true); - SimpleInstallFunction(reflect, "set", + SimpleInstallFunction(reflect, factory->set_string(), Builtins::kReflectSet, 3, false); - SimpleInstallFunction(reflect, "setPrototypeOf", + SimpleInstallFunction(reflect, factory->setPrototypeOf_string(), Builtins::kReflectSetPrototypeOf, 2, true); } @@ -2145,13 +2400,9 @@ void Genesis::InitializeGlobal_harmony_reflect() { void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { if (!FLAG_harmony_sharedarraybuffer) return; - Handle<JSGlobalObject> global( - JSGlobalObject::cast(native_context()->global_object())); - - Handle<JSFunction> shared_array_buffer_fun = InstallFunction( - global, "SharedArrayBuffer", JS_ARRAY_BUFFER_TYPE, - JSArrayBuffer::kSizeWithInternalFields, - isolate()->initial_object_prototype(), Builtins::kIllegal); + Handle<JSGlobalObject> global(native_context()->global_object()); + Handle<JSFunction> shared_array_buffer_fun = + InstallArrayBuffer(global, "SharedArrayBuffer"); native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun); } @@ -2187,6 +2438,100 @@ void Genesis::InitializeGlobal_harmony_simd() { } +void Genesis::InstallJSProxyMaps() { + // Allocate the different maps for all Proxy types. + // Next to the default proxy, we need maps indicating callable and + // constructable proxies. + + Handle<Map> proxy_function_map = + Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); + proxy_function_map->set_is_constructor(); + native_context()->set_proxy_function_map(*proxy_function_map); + + Handle<Map> proxy_map = + factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); + proxy_map->set_dictionary_map(true); + native_context()->set_proxy_map(*proxy_map); + + Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); + proxy_callable_map->set_is_callable(); + native_context()->set_proxy_callable_map(*proxy_callable_map); + proxy_callable_map->SetConstructor(native_context()->function_function()); + + Handle<Map> proxy_constructor_map = + Map::Copy(proxy_callable_map, "constructor Proxy"); + proxy_constructor_map->set_is_constructor(); + native_context()->set_proxy_constructor_map(*proxy_constructor_map); +} + + +void Genesis::InitializeGlobal_harmony_proxies() { + if (!FLAG_harmony_proxies) return; + Handle<JSGlobalObject> global( + JSGlobalObject::cast(native_context()->global_object())); + Isolate* isolate = global->GetIsolate(); + Factory* factory = isolate->factory(); + + InstallJSProxyMaps(); + + // Create the Proxy object. + Handle<String> name = factory->Proxy_string(); + Handle<Code> code(isolate->builtins()->ProxyConstructor()); + + Handle<JSFunction> proxy_function = factory->NewFunction( + isolate->proxy_function_map(), factory->Proxy_string(), code); + + JSFunction::SetInitialMap(proxy_function, + Handle<Map>(native_context()->proxy_map(), isolate), + factory->null_value()); + + proxy_function->shared()->set_construct_stub( + *isolate->builtins()->ProxyConstructor_ConstructStub()); + proxy_function->shared()->set_internal_formal_parameter_count(2); + proxy_function->shared()->set_length(2); + + native_context()->set_proxy_function(*proxy_function); + InstallFunction(global, name, proxy_function, factory->Object_string()); +} + + +Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target, + const char* name) { + // Setup the {prototype} with the given {name} for @@toStringTag. + Handle<JSObject> prototype = + factory()->NewJSObject(isolate()->object_function(), TENURED); + JSObject::AddProperty(prototype, factory()->to_string_tag_symbol(), + factory()->NewStringFromAsciiChecked(name), + static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); + + // Allocate the constructor with the given {prototype}. + Handle<JSFunction> array_buffer_fun = + InstallFunction(target, name, JS_ARRAY_BUFFER_TYPE, + JSArrayBuffer::kSizeWithInternalFields, prototype, + Builtins::kArrayBufferConstructor); + array_buffer_fun->shared()->set_construct_stub( + *isolate()->builtins()->ArrayBufferConstructor_ConstructStub()); + array_buffer_fun->shared()->DontAdaptArguments(); + array_buffer_fun->shared()->set_length(1); + + // Install the "constructor" property on the {prototype}. + JSObject::AddProperty(prototype, factory()->constructor_string(), + array_buffer_fun, DONT_ENUM); + + SimpleInstallFunction(array_buffer_fun, factory()->isView_string(), + Builtins::kArrayBufferIsView, 1, true); + + return array_buffer_fun; +} + + +void Genesis::InitializeGlobal_harmony_species() { + if (!FLAG_harmony_species) return; + InstallPublicSymbol(factory(), native_context(), "species", + factory()->species_symbol()); +} + + Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, const char* name, ElementsKind elements_kind) { @@ -2233,31 +2578,6 @@ Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, bool Genesis::InstallNatives(ContextType context_type) { HandleScope scope(isolate()); - // Create a bridge function that has context in the native context. - Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); - DCHECK(bridge->context() == *isolate()->native_context()); - - // Allocate the runtime context. - { - Handle<Context> context = - factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); - native_context()->set_runtime_context(*context); - Handle<Code> code = isolate()->builtins()->Illegal(); - Handle<JSFunction> global_fun = - factory()->NewFunction(factory()->empty_string(), code, - JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); - global_fun->initial_map()->set_dictionary_map(true); - global_fun->initial_map()->set_prototype(heap()->null_value()); - Handle<JSGlobalObject> dummy_global = - Handle<JSGlobalObject>::cast(factory()->NewJSGlobalObject(global_fun)); - dummy_global->set_native_context(*native_context()); - dummy_global->set_global_proxy(native_context()->global_proxy()); - context->set_global_object(*dummy_global); - // Something went wrong if we actually need to write into the dummy global. - dummy_global->set_properties(*GlobalDictionary::New(isolate(), 0)); - dummy_global->set_elements(heap()->empty_fixed_array()); - } - // Set up the utils object as shared container between native scripts. Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, @@ -2338,27 +2658,12 @@ bool Genesis::InstallNatives(ContextType context_type) { native_context()->set_string_function_prototype_map( HeapObject::cast(string_function->initial_map()->prototype())->map()); - // Install Date.prototype[@@toPrimitive]. + // Install Global.eval. { - Handle<String> key = factory()->Date_string(); - Handle<JSFunction> date = Handle<JSFunction>::cast( - Object::GetProperty(handle(native_context()->global_object()), key) - .ToHandleChecked()); - Handle<JSObject> proto = - Handle<JSObject>(JSObject::cast(date->instance_prototype())); - - // Install the @@toPrimitive function. - Handle<JSFunction> to_primitive = - InstallFunction(proto, factory()->to_primitive_symbol(), JS_OBJECT_TYPE, - JSObject::kHeaderSize, MaybeHandle<JSObject>(), - Builtins::kDateToPrimitive, - static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); - - // Set the expected parameters for @@toPrimitive to 1; required by builtin. - to_primitive->shared()->set_internal_formal_parameter_count(1); - - // Set the length for the function to satisfy ECMA-262. - to_primitive->shared()->set_length(1); + Handle<JSFunction> eval = SimpleInstallFunction( + handle(native_context()->global_object()), factory()->eval_string(), + Builtins::kGlobalEval, 1, false); + native_context()->set_global_eval_fun(*eval); } // Install Array.prototype.concat @@ -2395,38 +2700,19 @@ bool Genesis::InstallNatives(ContextType context_type) { // Set the lengths for the functions to satisfy ECMA-262. concat->shared()->set_length(1); } - // Install Function.prototype.call and apply. - { - Handle<String> key = factory()->Function_string(); - Handle<JSFunction> function = - Handle<JSFunction>::cast(Object::GetProperty( - handle(native_context()->global_object()), key).ToHandleChecked()); - Handle<JSObject> proto = - Handle<JSObject>(JSObject::cast(function->instance_prototype())); - - // Install the call and the apply functions. - Handle<JSFunction> call = - InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, - MaybeHandle<JSObject>(), Builtins::kFunctionCall); - Handle<JSFunction> apply = - InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, - MaybeHandle<JSObject>(), Builtins::kFunctionApply); - Handle<TypeFeedbackVector> feedback_vector = - TypeFeedbackVector::CreatePushAppliedArgumentsVector(isolate()); - apply->shared()->set_feedback_vector(*feedback_vector); - - // Make sure that Function.prototype.call appears to be compiled. - // The code will never be called, but inline caching for call will - // only work if it appears to be compiled. - call->shared()->DontAdaptArguments(); - DCHECK(call->is_compiled()); - - // Set the expected parameters for apply to 2; required by builtin. - apply->shared()->set_internal_formal_parameter_count(2); - // Set the lengths for the functions to satisfy ECMA-262. - call->shared()->set_length(1); - apply->shared()->set_length(2); + // Set up the Promise constructor. + { + Handle<String> key = factory()->Promise_string(); + Handle<JSFunction> function = Handle<JSFunction>::cast( + Object::GetProperty(handle(native_context()->global_object()), key) + .ToHandleChecked()); + JSFunction::EnsureHasInitialMap(function); + function->initial_map()->set_instance_type(JS_PROMISE_TYPE); + function->shared()->set_construct_stub( + *isolate()->builtins()->JSBuiltinsConstructStub()); + InstallWithIntrinsicDefaultProto(isolate(), function, + Context::PROMISE_FUNCTION_INDEX); } InstallBuiltinFunctionIds(); @@ -2526,8 +2812,6 @@ bool Genesis::InstallNatives(ContextType context_type) { bool Genesis::InstallExperimentalNatives() { - static const char* harmony_array_includes_natives[] = { - "native harmony-array-includes.js", nullptr}; static const char* harmony_proxies_natives[] = {"native proxy.js", nullptr}; static const char* harmony_modules_natives[] = {nullptr}; static const char* harmony_regexps_natives[] = {"native harmony-regexp.js", @@ -2536,12 +2820,15 @@ bool Genesis::InstallExperimentalNatives() { static const char* harmony_sloppy_natives[] = {nullptr}; static const char* harmony_sloppy_function_natives[] = {nullptr}; static const char* harmony_sloppy_let_natives[] = {nullptr}; - static const char* harmony_unicode_regexps_natives[] = {nullptr}; - static const char* harmony_rest_parameters_natives[] = {nullptr}; + static const char* harmony_species_natives[] = {"native harmony-species.js", + nullptr}; + static const char* harmony_unicode_regexps_natives[] = { + "native harmony-unicode-regexps.js", nullptr}; static const char* harmony_default_parameters_natives[] = {nullptr}; static const char* harmony_reflect_natives[] = {"native harmony-reflect.js", nullptr}; - static const char* harmony_destructuring_natives[] = {nullptr}; + static const char* harmony_destructuring_bind_natives[] = {nullptr}; + static const char* harmony_destructuring_assignment_natives[] = {nullptr}; static const char* harmony_object_observe_natives[] = { "native harmony-object-observe.js", nullptr}; static const char* harmony_sharedarraybuffer_natives[] = { @@ -2553,6 +2840,10 @@ bool Genesis::InstallExperimentalNatives() { static const char* harmony_completion_natives[] = {nullptr}; static const char* harmony_do_expressions_natives[] = {nullptr}; static const char* harmony_regexp_subclass_natives[] = {nullptr}; + static const char* harmony_regexp_lookbehind_natives[] = {nullptr}; + static const char* harmony_function_name_natives[] = {nullptr}; + static const char* promise_extra_natives[] = {"native promise-extra.js", + nullptr}; for (int i = ExperimentalNatives::GetDebuggerCount(); i < ExperimentalNatives::GetBuiltinsCount(); i++) { @@ -2571,6 +2862,7 @@ bool Genesis::InstallExperimentalNatives() { HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES); HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); + INSTALL_EXPERIMENTAL_NATIVES(promise_extra, ""); #undef INSTALL_EXPERIMENTAL_NATIVES } @@ -2616,16 +2908,6 @@ bool Genesis::InstallDebuggerNatives() { } -bool Bootstrapper::InstallCodeStubNatives(Isolate* isolate) { - for (int i = CodeStubNatives::GetDebuggerCount(); - i < CodeStubNatives::GetBuiltinsCount(); i++) { - if (!CompileCodeStubBuiltin(isolate, i)) return false; - } - - return true; -} - - static void InstallBuiltinFunctionId(Handle<JSObject> holder, const char* function_name, BuiltinFunctionId id) { @@ -2710,8 +2992,7 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) { Handle<JSGlobalObject> global(JSGlobalObject::cast( native_context->global_object())); - Handle<JSObject> Error = Handle<JSObject>::cast( - Object::GetProperty(isolate, global, "Error").ToHandleChecked()); + Handle<JSObject> Error = isolate->error_function(); Handle<String> name = factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); @@ -2736,9 +3017,9 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) { JSObject::AddProperty(global, debug_string, global_proxy, DONT_ENUM); } -#if defined(V8_WASM) - WasmJs::Install(isolate, global); -#endif + if (FLAG_expose_wasm) { + WasmJs::Install(isolate, global); + } return true; } @@ -3123,10 +3404,8 @@ Genesis::Genesis(Isolate* isolate, // We can only de-serialize a context if the isolate was initialized from // a snapshot. Otherwise we have to build the context from scratch. // Also create a context from scratch to expose natives, if required by flag. - Handle<FixedArray> outdated_contexts; if (!isolate->initialized_from_snapshot() || - !Snapshot::NewContextFromSnapshot(isolate, global_proxy, - &outdated_contexts) + !Snapshot::NewContextFromSnapshot(isolate, global_proxy) .ToHandle(&native_context_)) { native_context_ = Handle<Context>(); } @@ -3148,8 +3427,7 @@ Genesis::Genesis(Isolate* isolate, CreateNewGlobals(global_proxy_template, global_proxy); HookUpGlobalProxy(global_object, global_proxy); - HookUpGlobalObject(global_object, outdated_contexts); - HookUpGlobalThisBinding(outdated_contexts); + HookUpGlobalObject(global_object); if (!ConfigureGlobalObjects(global_proxy_template)) return; } else { |