Commit 30715157 authored by yangguo's avatar yangguo Committed by Commit bot

Install iterator meta objects via utils object.

R=cbruni@chromium.org, hpayer@chromium.org

Review URL: https://codereview.chromium.org/1411653002

Cr-Commit-Position: refs/heads/master@{#31331}
parent f2bfa126
This diff is collapsed.
......@@ -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") \
......
......@@ -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, [
......
......@@ -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
......
......@@ -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
......
......@@ -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;
});
// -------------------------------------------------------------------
......
......@@ -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");
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
})
......@@ -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));
......
......@@ -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);
......
......@@ -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;
});
......
......@@ -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([
......
......@@ -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, [
......
......@@ -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,
......
......@@ -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<v8::Object> 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<v8::String> name = v8_str("utils");
utils.Reset(isolate, CcTest::global()->Get(name)->ToObject(isolate));
CcTest::global()->Delete(name);
}
utils.SetWeak(&utils, UtilsHasBeenCollected,
......
// 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);
}
}
// 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();
......@@ -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) {
......
......@@ -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);
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment