diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index ae24675263..6d54793a28 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -164,6 +164,7 @@ class Genesis BASE_EMBEDDED { void CreateStrictModeFunctionMaps(Handle empty); void CreateStrongModeFunctionMaps(Handle empty); + void CreateIteratorMaps(); // Make the "arguments" and "caller" properties throw a TypeError on access. void AddRestrictedFunctionProperties(Handle map); @@ -199,6 +200,8 @@ class Genesis BASE_EMBEDDED { void InitializeExperimentalGlobal(); // Typed arrays are not serializable and have to initialized afterwards. void InitializeBuiltinTypedArrays(); + // Depending on the situation, expose and/or get rid of the utils object. + void ConfigureUtilsObject(ContextType context_type); #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ void InitializeGlobal_##id(); @@ -793,6 +796,57 @@ void Genesis::CreateStrongModeFunctionMaps(Handle empty) { } +void Genesis::CreateIteratorMaps() { + // Create iterator-related meta-objects. + Handle iterator_prototype = + factory()->NewJSObject(isolate()->object_function(), TENURED); + Handle generator_object_prototype = + factory()->NewJSObject(isolate()->object_function(), TENURED); + Handle generator_function_prototype = + factory()->NewJSObject(isolate()->object_function(), TENURED); + SetObjectPrototype(generator_object_prototype, iterator_prototype); + + JSObject::AddProperty(generator_function_prototype, + factory()->InternalizeUtf8String("prototype"), + generator_object_prototype, + static_cast(DONT_ENUM | READ_ONLY)); + + // Create maps for generator functions and their prototypes. Store those + // maps in the native context. The "prototype" property descriptor is + // writable, non-enumerable, and non-configurable (as per ES6 draft + // 04-14-15, section 25.2.4.3). + Handle strict_function_map(strict_function_map_writable_prototype_); + // Generator functions do not have "caller" or "arguments" accessors. + Handle sloppy_generator_function_map = + Map::Copy(strict_function_map, "SloppyGeneratorFunction"); + Map::SetPrototype(sloppy_generator_function_map, + generator_function_prototype); + native_context()->set_sloppy_generator_function_map( + *sloppy_generator_function_map); + + Handle strict_generator_function_map = + Map::Copy(strict_function_map, "StrictGeneratorFunction"); + Map::SetPrototype(strict_generator_function_map, + generator_function_prototype); + native_context()->set_strict_generator_function_map( + *strict_generator_function_map); + + Handle strong_function_map(native_context()->strong_function_map()); + Handle strong_generator_function_map = + Map::Copy(strong_function_map, "StrongGeneratorFunction"); + Map::SetPrototype(strong_generator_function_map, + generator_function_prototype); + native_context()->set_strong_generator_function_map( + *strong_generator_function_map); + + Handle object_function(native_context()->object_function()); + Handle generator_object_prototype_map = Map::Create(isolate(), 0); + Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); + native_context()->set_generator_object_prototype_map( + *generator_object_prototype_map); +} + + static void ReplaceAccessors(Handle map, Handle name, PropertyAttributes attributes, @@ -1794,6 +1848,36 @@ void Genesis::InitializeBuiltinTypedArrays() { } +void Genesis::ConfigureUtilsObject(ContextType context_type) { + switch (context_type) { + // We still need the utils object to find debug functions. + case DEBUG_CONTEXT: + return; + // Expose the natives in global if a valid name for it is specified. + case FULL_CONTEXT: { + // We still need the utils object after deserialization. + if (isolate()->serializer_enabled()) return; + if (FLAG_expose_natives_as == NULL) break; + if (strlen(FLAG_expose_natives_as) == 0) break; + HandleScope scope(isolate()); + Handle natives_key = + factory()->InternalizeUtf8String(FLAG_expose_natives_as); + uint32_t dummy_index; + if (natives_key->AsArrayIndex(&dummy_index)) break; + Handle utils = isolate()->natives_utils_object(); + Handle global = isolate()->global_object(); + JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); + break; + } + case THIN_CONTEXT: + break; + } + + // The utils object can be removed for cases that reach this point. + native_context()->set_natives_utils_object(heap()->undefined_value()); +} + + void Bootstrapper::ExportFromRuntime(Isolate* isolate, Handle container) { HandleScope scope(isolate); @@ -1837,6 +1921,58 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, construct->shared()->set_feedback_vector(*feedback_vector); isolate->native_context()->set_reflect_construct(*construct); } + + Handle iterator_prototype; + + { + PrototypeIterator iter( + isolate->native_context()->generator_object_prototype_map()); + iter.Advance(); // Advance to the prototype of generator_object_prototype. + iterator_prototype = Handle(iter.GetCurrent()); + + JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String( + "IteratorPrototype"), + iterator_prototype, NONE); + } + + { + PrototypeIterator iter( + isolate->native_context()->sloppy_generator_function_map()); + Handle generator_function_prototype(iter.GetCurrent()); + + JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String( + "GeneratorFunctionPrototype"), + generator_function_prototype, NONE); + + static const bool kUseStrictFunctionMap = true; + Handle 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(); + } + + { // -- S e t I t e r a t o r + Handle set_iterator_prototype = + isolate->factory()->NewJSObject(isolate->object_function(), TENURED); + SetObjectPrototype(set_iterator_prototype, iterator_prototype); + Handle set_iterator_function = InstallFunction( + container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, + set_iterator_prototype, Builtins::kIllegal); + isolate->native_context()->set_set_iterator_map( + set_iterator_function->initial_map()); + } + + { // -- M a p I t e r a t o r + Handle map_iterator_prototype = + isolate->factory()->NewJSObject(isolate->object_function(), TENURED); + SetObjectPrototype(map_iterator_prototype, iterator_prototype); + Handle map_iterator_function = InstallFunction( + container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, + map_iterator_prototype, Builtins::kIllegal); + isolate->native_context()->set_map_iterator_map( + map_iterator_function->initial_map()); + } } @@ -1855,6 +1991,7 @@ void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, INITIALIZE_FLAG(FLAG_harmony_regexps) INITIALIZE_FLAG(FLAG_harmony_unicode_regexps) INITIALIZE_FLAG(FLAG_harmony_tostring) + INITIALIZE_FLAG(FLAG_harmony_tolength) #undef INITIALIZE_FLAG } @@ -1881,15 +2018,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion) - - -void Genesis::InitializeGlobal_harmony_tolength() { - Handle builtins(native_context()->builtins()); - Handle flag(factory()->ToBoolean(FLAG_harmony_tolength)); - Runtime::SetObjectProperty(isolate(), builtins, - factory()->harmony_tolength_string(), flag, - STRICT).Assert(); -} +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tolength) static void SimpleInstallFunction(Handle& base, const char* name, @@ -2080,11 +2209,6 @@ bool Genesis::InstallNatives(ContextType context_type) { // A thin context is ready at this point. if (context_type == THIN_CONTEXT) return true; - if (FLAG_expose_natives_as != NULL) { - Handle utils_key = factory()->NewStringFromAsciiChecked("utils"); - JSObject::AddProperty(builtins, utils_key, utils, NONE); - } - { // -- S c r i p t // Builtin functions for Script. Handle script_fun = InstallFunction( @@ -2261,96 +2385,6 @@ bool Genesis::InstallNatives(ContextType context_type) { InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); } - { // -- S e t I t e r a t o r - Handle set_iterator_function = InstallFunction( - builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, - isolate()->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_set_iterator_map( - set_iterator_function->initial_map()); - } - - { // -- M a p I t e r a t o r - Handle map_iterator_function = InstallFunction( - builtins, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, - isolate()->initial_object_prototype(), Builtins::kIllegal); - native_context()->set_map_iterator_map( - map_iterator_function->initial_map()); - } - - { - // Create generator meta-objects and install them on the builtins object. - Handle builtins(native_context()->builtins()); - Handle iterator_prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); - Handle generator_object_prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); - Handle generator_function_prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); - SetObjectPrototype(generator_object_prototype, iterator_prototype); - JSObject::AddProperty( - builtins, factory()->InternalizeUtf8String("$iteratorPrototype"), - iterator_prototype, - static_cast(DONT_ENUM | DONT_DELETE | READ_ONLY)); - JSObject::AddProperty( - builtins, - factory()->InternalizeUtf8String("GeneratorFunctionPrototype"), - generator_function_prototype, - static_cast(DONT_ENUM | DONT_DELETE | READ_ONLY)); - - JSObject::AddProperty( - generator_function_prototype, - factory()->InternalizeUtf8String("prototype"), - generator_object_prototype, - static_cast(DONT_ENUM | READ_ONLY)); - - static const bool kUseStrictFunctionMap = true; - Handle generator_function_function = - InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE, - JSFunction::kSize, generator_function_prototype, - Builtins::kIllegal, kUseStrictFunctionMap); - generator_function_function->initial_map()->set_is_callable(); - - // Create maps for generator functions and their prototypes. Store those - // maps in the native context. The "prototype" property descriptor is - // writable, non-enumerable, and non-configurable (as per ES6 draft - // 04-14-15, section 25.2.4.3). - Handle strict_function_map(strict_function_map_writable_prototype_); - // Generator functions do not have "caller" or "arguments" accessors. - Handle sloppy_generator_function_map = - Map::Copy(strict_function_map, "SloppyGeneratorFunction"); - Map::SetPrototype(sloppy_generator_function_map, - generator_function_prototype); - native_context()->set_sloppy_generator_function_map( - *sloppy_generator_function_map); - - Handle strict_generator_function_map = - Map::Copy(strict_function_map, "StrictGeneratorFunction"); - Map::SetPrototype(strict_generator_function_map, - generator_function_prototype); - native_context()->set_strict_generator_function_map( - *strict_generator_function_map); - - Handle strong_function_map(native_context()->strong_function_map()); - Handle strong_generator_function_map = - Map::Copy(strong_function_map, "StrongGeneratorFunction"); - Map::SetPrototype(strong_generator_function_map, - generator_function_prototype); - native_context()->set_strong_generator_function_map( - *strong_generator_function_map); - - Handle object_function(native_context()->object_function()); - Handle generator_object_prototype_map = Map::Create(isolate(), 0); - Map::SetPrototype(generator_object_prototype_map, - generator_object_prototype); - native_context()->set_generator_object_prototype_map( - *generator_object_prototype_map); - } - - if (FLAG_disable_native_files) { - PrintF("Warning: Running without installed natives!\n"); - return true; - } - // Run the rest of the native scripts. while (builtin_index < Natives::GetBuiltinsCount()) { if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; @@ -2768,16 +2802,6 @@ bool Genesis::InstallSpecialObjects(Handle native_context) { Handle stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); JSObject::AddProperty(Error, name, stack_trace_limit, NONE); - // Expose the natives in global if a name for it is specified. - if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { - Handle natives_key = - factory->InternalizeUtf8String(FLAG_expose_natives_as); - uint32_t dummy_index; - if (natives_key->AsArrayIndex(&dummy_index)) return true; - Handle natives(global->builtins()); - JSObject::AddProperty(global, natives_key, natives, DONT_ENUM); - } - // Expose the debug global object in global if a name for it is specified. if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { // If loading fails we just bail out without installing the @@ -3221,6 +3245,7 @@ Genesis::Genesis(Isolate* isolate, Handle empty_function = CreateEmptyFunction(isolate); CreateStrictModeFunctionMaps(empty_function); CreateStrongModeFunctionMaps(empty_function); + CreateIteratorMaps(); Handle global_object = CreateNewGlobals(global_proxy_template, global_proxy); HookUpGlobalProxy(global_object, global_proxy); @@ -3249,10 +3274,6 @@ Genesis::Genesis(Isolate* isolate, if (FLAG_experimental_extras) { if (!InstallExperimentalExtraNatives()) return; } - - // By now the utils object is useless and can be removed. - native_context()->set_natives_utils_object( - isolate->heap()->undefined_value()); } // The serializer cannot serialize typed arrays. Reset those typed arrays // for each new context. @@ -3263,6 +3284,8 @@ Genesis::Genesis(Isolate* isolate, if (!InstallDebuggerNatives()) return; } + ConfigureUtilsObject(context_type); + // Check that the script context table is empty except for the 'this' binding. // We do not need script contexts for native scripts. if (!FLAG_global_var_shortcuts) { diff --git a/src/heap/heap.h b/src/heap/heap.h index 193323f30e..3c725c3b36 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -263,7 +263,6 @@ namespace internal { V(multiline_string, "multiline") \ V(sticky_string, "sticky") \ V(unicode_string, "unicode") \ - V(harmony_tolength_string, "harmony_tolength") \ V(input_string, "input") \ V(index_string, "index") \ V(last_index_string, "lastIndex") \ diff --git a/src/js/array-iterator.js b/src/js/array-iterator.js index 11b07db806..03ef3b2870 100644 --- a/src/js/array-iterator.js +++ b/src/js/array-iterator.js @@ -18,6 +18,7 @@ var arrayIteratorNextIndexSymbol = var arrayIteratorObjectSymbol = utils.ImportNow("array_iterator_object_symbol"); var GlobalArray = global.Array; +var IteratorPrototype = utils.ImportNow("IteratorPrototype"); var iteratorSymbol = utils.ImportNow("iterator_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); @@ -121,7 +122,7 @@ function ArrayKeys() { } -%FunctionSetPrototype(ArrayIterator, {__proto__: $iteratorPrototype}); +%FunctionSetPrototype(ArrayIterator, {__proto__: IteratorPrototype}); %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); utils.InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [ diff --git a/src/js/array.js b/src/js/array.js index e8e5197d66..4b994e272a 100644 --- a/src/js/array.js +++ b/src/js/array.js @@ -12,6 +12,7 @@ // Imports var Delete; +var FLAG_harmony_tolength; var GlobalArray = global.Array; var InternalArray = utils.InternalArray; var InternalPackedArray = utils.InternalPackedArray; @@ -37,6 +38,10 @@ utils.Import(function(from) { ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; }); +utils.ImportFromExperimental(function(from) { + FLAG_harmony_tolength = from.FLAG_harmony_tolength; +}); + // ------------------------------------------------------------------- // Global list of arrays visited during toString, toLocaleString and diff --git a/src/js/collection-iterator.js b/src/js/collection-iterator.js index 133219d4a5..4367c66aa1 100644 --- a/src/js/collection-iterator.js +++ b/src/js/collection-iterator.js @@ -11,7 +11,9 @@ var GlobalMap = global.Map; var GlobalSet = global.Set; var iteratorSymbol = utils.ImportNow("iterator_symbol"); +var MapIterator = utils.ImportNow("MapIterator"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); +var SetIterator = utils.ImportNow("SetIterator"); // ------------------------------------------------------------------- @@ -65,7 +67,6 @@ function SetValues() { // ------------------------------------------------------------------- %SetCode(SetIterator, SetIteratorConstructor); -%FunctionSetPrototype(SetIterator, {__proto__: $iteratorPrototype}); %FunctionSetInstanceClassName(SetIterator, 'Set Iterator'); utils.InstallFunctions(SetIterator.prototype, DONT_ENUM, [ 'next', SetIteratorNextJS @@ -144,7 +145,6 @@ function MapValues() { // ------------------------------------------------------------------- %SetCode(MapIterator, MapIteratorConstructor); -%FunctionSetPrototype(MapIterator, {__proto__: $iteratorPrototype}); %FunctionSetInstanceClassName(MapIterator, 'Map Iterator'); utils.InstallFunctions(MapIterator.prototype, DONT_ENUM, [ 'next', MapIteratorNextJS diff --git a/src/js/collection.js b/src/js/collection.js index 6c867e4a16..8cf37f7f9d 100644 --- a/src/js/collection.js +++ b/src/js/collection.js @@ -15,16 +15,16 @@ var GlobalObject = global.Object; var GlobalSet = global.Set; var hashCodeSymbol = utils.ImportNow("hash_code_symbol"); var IntRandom; +var MapIterator; +var NumberIsNaN; +var SetIterator; var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); utils.Import(function(from) { IntRandom = from.IntRandom; -}); - -var NumberIsNaN; - -utils.Import(function(from) { + MapIterator = from.MapIterator; NumberIsNaN = from.NumberIsNaN; + SetIterator = from.SetIterator; }); // ------------------------------------------------------------------- diff --git a/src/js/generator.js b/src/js/generator.js index 6e5a533c1b..17e4b23e81 100644 --- a/src/js/generator.js +++ b/src/js/generator.js @@ -11,6 +11,8 @@ // ------------------------------------------------------------------- // Imports +var GeneratorFunctionPrototype = utils.ImportNow("GeneratorFunctionPrototype"); +var GeneratorFunction = utils.ImportNow("GeneratorFunction"); var GlobalFunction = global.Function; var NewFunctionString; var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); diff --git a/src/js/harmony-array-includes.js b/src/js/harmony-array-includes.js index a6b59137d2..54f68a7ce3 100644 --- a/src/js/harmony-array-includes.js +++ b/src/js/harmony-array-includes.js @@ -9,6 +9,11 @@ %CheckIsBootstrapping(); var GlobalArray = global.Array; +var SameValueZero; + +utils.Import(function(from) { + SameValueZero = from.SameValueZero; +}); // ------------------------------------------------------------------- @@ -34,7 +39,7 @@ function InnerArrayIncludes(searchElement, fromIndex, array, length) { while (k < length) { var elementK = array[k]; - if ($sameValueZero(searchElement, elementK)) { + if (SameValueZero(searchElement, elementK)) { return true; } diff --git a/src/js/harmony-array.js b/src/js/harmony-array.js index 61bdbb689e..6705691486 100644 --- a/src/js/harmony-array.js +++ b/src/js/harmony-array.js @@ -11,6 +11,7 @@ // ------------------------------------------------------------------- // Imports +var FLAG_harmony_tolength; var GetIterator; var GetMethod; var GlobalArray = global.Array; @@ -21,6 +22,7 @@ var ObjectIsFrozen; var ObjectDefineProperty; utils.Import(function(from) { + FLAG_harmony_tolength = from.FLAG_harmony_tolength; GetIterator = from.GetIterator; GetMethod = from.GetMethod; MathMax = from.MathMax; diff --git a/src/js/iterator-prototype.js b/src/js/iterator-prototype.js index 2f49d90b1c..6f2501979d 100644 --- a/src/js/iterator-prototype.js +++ b/src/js/iterator-prototype.js @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var $iteratorPrototype; - (function(global, utils) { "use strict"; %CheckIsBootstrapping(); var GlobalObject = global.Object; + var IteratorPrototype = utils.ImportNow("IteratorPrototype"); var iteratorSymbol = utils.ImportNow("iterator_symbol"); // 25.1.2.1 %IteratorPrototype% [ @@iterator ] ( ) @@ -17,6 +16,6 @@ var $iteratorPrototype; } utils.SetFunctionName(IteratorPrototypeIterator, iteratorSymbol); - %AddNamedProperty($iteratorPrototype, iteratorSymbol, + %AddNamedProperty(IteratorPrototype, iteratorSymbol, IteratorPrototypeIterator, DONT_ENUM); }) diff --git a/src/js/macros.py b/src/js/macros.py index 926942e905..8259ee8da5 100644 --- a/src/js/macros.py +++ b/src/js/macros.py @@ -147,8 +147,8 @@ macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToI macro TO_INT32(arg) = ((arg) | 0); macro TO_UINT32(arg) = ((arg) >>> 0); macro TO_LENGTH(arg) = (%ToLength(arg)); -macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg)); -macro TO_LENGTH_OR_INTEGER(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_INTEGER(arg)); +macro TO_LENGTH_OR_UINT32(arg) = (FLAG_harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg)); +macro TO_LENGTH_OR_INTEGER(arg) = (FLAG_harmony_tolength ? TO_LENGTH(arg) : TO_INTEGER(arg)); macro TO_STRING(arg) = (%_ToString(arg)); macro TO_NUMBER(arg) = (%_ToNumber(arg)); macro TO_OBJECT(arg) = (%_ToObject(arg)); diff --git a/src/js/prologue.js b/src/js/prologue.js index e169018910..0b94e2b654 100644 --- a/src/js/prologue.js +++ b/src/js/prologue.js @@ -182,6 +182,7 @@ function PostNatives(utils) { "InnerArrayToLocaleString", "IsNaN", "MapEntries", + "MapIterator", "MapIteratorNext", "MathMax", "MathMin", @@ -190,6 +191,8 @@ function PostNatives(utils) { "ObserveArrayMethods", "ObserveObjectMethods", "OwnPropertyKeys", + "SameValueZero", + "SetIterator", "SetIteratorNext", "SetValues", "SymbolToString", @@ -230,12 +233,9 @@ function PostExperimentals(utils) { imports_from_experimental(exports_container); } - exports_container = UNDEFINED; - - utils.PostExperimentals = UNDEFINED; - utils.PostDebug = UNDEFINED; - utils.Import = UNDEFINED; utils.Export = UNDEFINED; + utils.PostDebug = UNDEFINED; + utils.PostExperimentals = UNDEFINED; } @@ -246,12 +246,14 @@ function PostDebug(utils) { exports_container = UNDEFINED; + utils.Export = UNDEFINED; + utils.Import = UNDEFINED; + utils.ImportNow = UNDEFINED; utils.PostDebug = UNDEFINED; utils.PostExperimentals = UNDEFINED; - utils.Import = UNDEFINED; - utils.Export = UNDEFINED; } + // ----------------------------------------------------------------------- %OptimizeObjectForAddingMultipleProperties(utils, 13); diff --git a/src/js/regexp.js b/src/js/regexp.js index 3536fe17eb..34219d9c94 100644 --- a/src/js/regexp.js +++ b/src/js/regexp.js @@ -12,12 +12,14 @@ var $regexpLastMatchInfoOverride; // Imports var FLAG_harmony_regexps; +var FLAG_harmony_tolength; var FLAG_harmony_unicode_regexps; var GlobalRegExp = global.RegExp; var InternalPackedArray = utils.InternalPackedArray; utils.ImportFromExperimental(function(from) { FLAG_harmony_regexps = from.FLAG_harmony_regexps; + FLAG_harmony_tolength = from.FLAG_harmony_tolength; FLAG_harmony_unicode_regexps = from.FLAG_harmony_unicode_regexps; }); diff --git a/src/js/runtime.js b/src/js/runtime.js index 6de87d5076..d584100beb 100644 --- a/src/js/runtime.js +++ b/src/js/runtime.js @@ -11,10 +11,6 @@ // The following declarations are shared with other native JS files. // They are all declared at this one spot to avoid redeclaration errors. -var $sameValue; -var $sameValueZero; - -var harmony_tolength = false; (function(global, utils) { @@ -232,11 +228,10 @@ function ToPositiveInteger(x, rangeErrorIndex) { // ---------------------------------------------------------------------------- // Exports -$sameValue = SameValue; -$sameValueZero = SameValueZero; - utils.Export(function(to) { to.ToPositiveInteger = ToPositiveInteger; + to.SameValue = SameValue; + to.SameValueZero = SameValueZero; }); %InstallToContext([ diff --git a/src/js/string-iterator.js b/src/js/string-iterator.js index 660dc7c98b..214f95d9ba 100644 --- a/src/js/string-iterator.js +++ b/src/js/string-iterator.js @@ -12,6 +12,7 @@ // Imports var GlobalString = global.String; +var IteratorPrototype = utils.ImportNow("IteratorPrototype"); var iteratorSymbol = utils.ImportNow("iterator_symbol"); var stringIteratorIteratedStringSymbol = utils.ImportNow("string_iterator_iterated_string_symbol"); @@ -80,7 +81,7 @@ function StringPrototypeIterator() { //------------------------------------------------------------------- -%FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype}); +%FunctionSetPrototype(StringIterator, {__proto__: IteratorPrototype}); %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); utils.InstallFunctions(StringIterator.prototype, DONT_ENUM, [ diff --git a/src/js/v8natives.js b/src/js/v8natives.js index 2aeca95128..d2cbf9675a 100644 --- a/src/js/v8natives.js +++ b/src/js/v8natives.js @@ -25,6 +25,7 @@ var ObserveEnqueueSpliceRecord; var ProxyDelegateCallAndConstruct; var ProxyDerivedHasOwnTrap; var ProxyDerivedKeysTrap; +var SameValue = utils.ImportNow("SameValue"); var StringIndexOf; var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); @@ -653,17 +654,17 @@ function DefineObjectProperty(obj, p, desc, should_throw) { if ((IsGenericDescriptor(desc) || IsDataDescriptor(desc) == IsDataDescriptor(current)) && (!desc.hasEnumerable() || - $sameValue(desc.isEnumerable(), current.isEnumerable())) && + SameValue(desc.isEnumerable(), current.isEnumerable())) && (!desc.hasConfigurable() || - $sameValue(desc.isConfigurable(), current.isConfigurable())) && + SameValue(desc.isConfigurable(), current.isConfigurable())) && (!desc.hasWritable() || - $sameValue(desc.isWritable(), current.isWritable())) && + SameValue(desc.isWritable(), current.isWritable())) && (!desc.hasValue() || - $sameValue(desc.getValue(), current.getValue())) && + SameValue(desc.getValue(), current.getValue())) && (!desc.hasGetter() || - $sameValue(desc.getGet(), current.getGet())) && + SameValue(desc.getGet(), current.getGet())) && (!desc.hasSetter() || - $sameValue(desc.getSet(), current.getSet()))) { + SameValue(desc.getSet(), current.getSet()))) { return true; } if (!current.isConfigurable()) { @@ -702,7 +703,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { } } if (!currentIsWritable && desc.hasValue() && - !$sameValue(desc.getValue(), current.getValue())) { + !SameValue(desc.getValue(), current.getValue())) { if (should_throw) { throw MakeTypeError(kRedefineDisallowed, p); } else { @@ -713,14 +714,14 @@ function DefineObjectProperty(obj, p, desc, should_throw) { // Step 11 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { if (desc.hasSetter() && - !$sameValue(desc.getSet(), current.getSet())) { + !SameValue(desc.getSet(), current.getSet())) { if (should_throw) { throw MakeTypeError(kRedefineDisallowed, p); } else { return false; } } - if (desc.hasGetter() && !$sameValue(desc.getGet(),current.getGet())) { + if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { if (should_throw) { throw MakeTypeError(kRedefineDisallowed, p); } else { @@ -1259,12 +1260,6 @@ function ObjectIsExtensible(obj) { } -// ECMA-262, Edition 6, section 19.1.2.10 -function ObjectIs(obj1, obj2) { - return $sameValue(obj1, obj2); -} - - // ECMA-262, Edition 6, section 19.1.2.1 function ObjectAssign(target, sources) { // TODO(bmeurer): Move this to toplevel. @@ -1360,7 +1355,7 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [ "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, "getOwnPropertyNames", ObjectGetOwnPropertyNames, // getOwnPropertySymbols is added in symbol.js. - "is", ObjectIs, + "is", SameValue, // ECMA-262, Edition 6, section 19.1.2.10 "isExtensible", ObjectIsExtensible, "isFrozen", ObjectIsFrozen, "isSealed", ObjectIsSealed, diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 8b86544ccb..cef8c3f250 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -5884,7 +5884,9 @@ static void UtilsHasBeenCollected( TEST(BootstrappingExports) { - FLAG_expose_natives_as = "natives"; + // Expose utils object and delete it to observe that it is indeed + // being garbage-collected. + FLAG_expose_natives_as = "utils"; CcTest::InitializeVM(); v8::Isolate* isolate = CcTest::isolate(); @@ -5896,10 +5898,9 @@ TEST(BootstrappingExports) { { v8::HandleScope scope(isolate); - v8::Handle natives = - CcTest::global()->Get(v8_str("natives"))->ToObject(isolate); - utils.Reset(isolate, natives->Get(v8_str("utils"))->ToObject(isolate)); - natives->Delete(v8_str("utils")); + v8::Local name = v8_str("utils"); + utils.Reset(isolate, CcTest::global()->Get(name)->ToObject(isolate)); + CcTest::global()->Delete(name); } utils.SetWeak(&utils, UtilsHasBeenCollected, diff --git a/test/mjsunit/builtins.js b/test/mjsunit/builtins.js deleted file mode 100644 index 62989399de..0000000000 --- a/test/mjsunit/builtins.js +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2011 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Flags: --allow-natives-syntax --expose-natives-as=builtins - -// Verify that the builtin typed arrays have been pretenured. -assertFalse(%InNewSpace(builtins.kMath)); -assertFalse(%InNewSpace(builtins.rempio2result)); -assertFalse(%InNewSpace(builtins.rngstate)); - -// Checks that all function properties of the builtin object that are actually -// constructors (recognized by having properties on their .prototype object), -// have only unconfigurable properties on the prototype, and the methods -// are also non-writable. - -var names = Object.getOwnPropertyNames(builtins); - -function isFunction(obj) { - return typeof obj == "function"; -} - -function isV8Native(name) { - return name == "GeneratorFunction" || - name == "GeneratorFunctionPrototype" || - name == "SetIterator" || - name == "MapIterator" || - name == "ArrayIterator" || - name == "StringIterator"; -} -var V8NativePrototypes = { - GeneratorFunction: Function.prototype, - // TODO(jugglinmike): Update the following values to the %IteratorPrototype% - // intrinsic once it is implemented. - // Issue 3568: Generator Prototype should have an object between itself - // and Object.prototype - // https://code.google.com/p/v8/issues/detail?id=3568 - GeneratorFunctionPrototype: Object.prototype, - SetIterator: Object.prototype, - MapIterator: Object.prototype, - ArrayIterator: Object.prototype, - StringIterator: Object.prototype -}; - -function checkConstructor(func, name) { - // A constructor is a function with a prototype and properties on the - // prototype object besides "constructor"; - if (name.charAt(0) == "$") return; - if (typeof func.prototype != "object") return; - var propNames = Object.getOwnPropertyNames(func.prototype); - if (propNames.length == 0 || - (propNames.length == 1 && propNames[0] == "constructor")) { - // Not a constructor. - return; - } - var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype"); - assertTrue(proto_desc.hasOwnProperty("value"), name); - assertFalse(proto_desc.writable, name); - assertFalse(proto_desc.configurable, name); - var prototype = proto_desc.value; - assertEquals(V8NativePrototypes[name] || null, - Object.getPrototypeOf(prototype), - name); - for (var i = 0; i < propNames.length; i++) { - var propName = propNames[i]; - if (propName == "constructor") continue; - if (isV8Native(name)) continue; - var testName = name + "-" + propName; - var propDesc = Object.getOwnPropertyDescriptor(prototype, propName); - assertTrue(propDesc.hasOwnProperty("value"), testName); - assertFalse(propDesc.configurable, testName); - if (isFunction(propDesc.value)) { - assertFalse(propDesc.writable, testName); - } - } -} - -for (var i = 0; i < names.length; i++) { - var name = names[i]; - var desc = Object.getOwnPropertyDescriptor(builtins, name); - assertTrue(desc.hasOwnProperty("value")); - var value = desc.value; - if (isFunction(value)) { - checkConstructor(value, name); - } -} diff --git a/test/mjsunit/global-deleted-property-keyed.js b/test/mjsunit/global-deleted-property-keyed.js deleted file mode 100644 index a0e48ffdeb..0000000000 --- a/test/mjsunit/global-deleted-property-keyed.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2009 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Flags: --expose-natives-as natives -// Test keyed access to deleted property in a global object w/o access checks. -// Regression test that exposed the_hole value from Runtime_KeyedGetProperty. - -var name = "fisk"; -natives[name] = name; -function foo() { natives[name] + 12; } -for(var i = 0; i < 3; i++) foo(); -delete natives[name]; -for(var i = 0; i < 3; i++) foo(); diff --git a/test/mjsunit/harmony/simd.js b/test/mjsunit/harmony/simd.js index fe4b0358f9..d1106d1fef 100644 --- a/test/mjsunit/harmony/simd.js +++ b/test/mjsunit/harmony/simd.js @@ -406,8 +406,8 @@ function TestEquality(type, lanes) { function TestSameValue(type, lanes) { var simdFn = SIMD[type]; var instance = createInstance(type); - var sameValue = natives.$sameValue; - var sameValueZero = natives.$sameValueZero; + var sameValue = Object.is + var sameValueZero = natives.ImportNow("SameValueZero"); // SIMD values should not be the same as instances of different types. checkTypeMatrix(type, function(other) { diff --git a/test/mjsunit/regress/regress-3281.js b/test/mjsunit/regress/regress-3281.js index 7d42c026b6..f7b167e3b8 100644 --- a/test/mjsunit/regress/regress-3281.js +++ b/test/mjsunit/regress/regress-3281.js @@ -5,8 +5,10 @@ // Flags: --expose-natives-as=builtins // Should not crash or raise an exception. +var SetIterator = builtins.ImportNow("SetIterator"); var s = new Set(); -var setIterator = new builtins.SetIterator(s, 2); +var setIterator = new SetIterator(s, 2); +var MapIterator = builtins.ImportNow("MapIterator"); var m = new Map(); -var mapIterator = new builtins.MapIterator(m, 2); +var mapIterator = new MapIterator(m, 2); diff --git a/test/mjsunit/regress/regress-403292.js b/test/mjsunit/regress/regress-403292.js index 4e7ba283f7..2e24d48ac4 100644 --- a/test/mjsunit/regress/regress-403292.js +++ b/test/mjsunit/regress/regress-403292.js @@ -4,6 +4,8 @@ // Flags: --allow-natives-syntax --expose-natives-as=builtins --expose-gc +var SetIterator = builtins.ImportNow("SetIterator"); +var MapIterator = builtins.ImportNow("MapIterator"); var __v_7 = []; var __v_8 = {}; var __v_10 = {}; @@ -21,9 +23,9 @@ assertEquals("good", __f_1()); } catch(e) { print("Caught: " + e); } try { __v_3 = new Set(); -__v_5 = new builtins.SetIterator(__v_3, -12); +__v_5 = new SetIterator(__v_3, -12); __v_4 = new Map(); -__v_6 = new builtins.MapIterator(__v_4, 2); +__v_6 = new MapIterator(__v_4, 2); __f_3(Array); } catch(e) { print("Caught: " + e); } function __f_4(__v_8, filter) { diff --git a/test/mjsunit/samevalue.js b/test/mjsunit/samevalue.js index 174afd2372..038fd68eb9 100644 --- a/test/mjsunit/samevalue.js +++ b/test/mjsunit/samevalue.js @@ -32,8 +32,8 @@ var obj1 = {x: 10, y: 11, z: "test"}; var obj2 = {x: 10, y: 11, z: "test"}; -var sameValue = natives.$sameValue; -var sameValueZero = natives.$sameValueZero; +var sameValue = Object.is; +var sameValueZero = natives.ImportNow("SameValueZero"); // Calls SameValue and SameValueZero and checks that their results match. function sameValueBoth(a, b) {