diff options
Diffstat (limited to 'deps/v8/test/mjsunit')
179 files changed, 6807 insertions, 629 deletions
diff --git a/deps/v8/test/mjsunit/arguments-indirect.js b/deps/v8/test/mjsunit/arguments-indirect.js index 2d37027f41..12cd5b4b35 100644 --- a/deps/v8/test/mjsunit/arguments-indirect.js +++ b/deps/v8/test/mjsunit/arguments-indirect.js @@ -35,8 +35,15 @@ function f2(x) { g(f2); } +function f3(x) { + var a = arguments; + (function() { x++ })(); + g(f3); +} function g(f) { + assertEquals("object", typeof f.arguments); + assertFalse(f.arguments === f.arguments); assertEquals(3, f.arguments.length); assertEquals(1, f.arguments[0]); assertEquals(2, f.arguments[1]); @@ -44,4 +51,5 @@ function g(f) { } f1(1,2,3); -f2(0,2,3); +f2(1,2,3); +f3(1,2,3); diff --git a/deps/v8/test/mjsunit/array-indexing.js b/deps/v8/test/mjsunit/array-indexing.js index 7276742234..d100038243 100644 --- a/deps/v8/test/mjsunit/array-indexing.js +++ b/deps/v8/test/mjsunit/array-indexing.js @@ -111,7 +111,7 @@ assertEquals(10, Array.prototype.indexOf.call(funky_object, 42)); assertEquals(-1, Array.prototype.indexOf.call(funky_object, 42, 15)); assertEquals(-1, Array.prototype.indexOf.call(funky_object, 37)); -assertEquals(-1, Array.prototype.indexOf.call(infinite_object, 42)); +assertEquals(10, Array.prototype.indexOf.call(infinite_object, 42)); // ---------------------------------------------------------------------- // Array.prototype.lastIndexOf. @@ -183,4 +183,5 @@ assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42, 15)); assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42)); assertEquals(-1, Array.prototype.lastIndexOf.call(funky_object, 37)); -assertEquals(-1, Array.prototype.lastIndexOf.call(infinite_object, 42)); +// This call would take too long because it would search backwards from 2**53-1 +// assertEquals(-1, Array.prototype.lastIndexOf.call(infinite_object, 42)); diff --git a/deps/v8/test/mjsunit/array-iteration.js b/deps/v8/test/mjsunit/array-iteration.js index 13240740fc..9d03ed13ce 100644 --- a/deps/v8/test/mjsunit/array-iteration.js +++ b/deps/v8/test/mjsunit/array-iteration.js @@ -45,17 +45,22 @@ // Use specified object as this object when calling the function. var o = { value: 42 } a = [1,42,3,42,4]; - assertArrayEquals([42,42], a.filter(function(n) { return this.value == n }, o)) + assertArrayEquals([42,42], + a.filter(function(n) { return this.value == n }, o)) // Modify original array. a = [1,42,3,42,4]; - assertArrayEquals([42,42], a.filter(function(n, index, array) { array[index] = 43; return 42 == n; })); + assertArrayEquals([42,42], + a.filter(function(n, index, array) { + array[index] = 43; return 42 == n; + })); assertArrayEquals([43,43,43,43,43], a); // Only loop through initial part of array eventhough elements are // added. a = [1,1]; - assertArrayEquals([], a.filter(function(n, index, array) { array.push(n+1); return n == 2; })); + assertArrayEquals([], + a.filter(function(n, index, array) { array.push(n+1); return n == 2; })); assertArrayEquals([1,1,2,2], a); // Respect holes. @@ -166,13 +171,19 @@ // Modify original array. a = [0,1]; - assertFalse(a.every(function(n, index, array) { array[index] = n + 1; return n == 1;})); + assertFalse( + a.every(function(n, index, array) { + array[index] = n + 1; return n == 1; + })); assertArrayEquals([1,1], a); // Only loop through initial part of array eventhough elements are // added. a = [1,1]; - assertTrue(a.every(function(n, index, array) { array.push(n + 1); return n == 1;})); + assertTrue( + a.every(function(n, index, array) { + array.push(n + 1); return n == 1; + })); assertArrayEquals([1,1,2,2], a); // Respect holes. @@ -221,14 +232,18 @@ // Modify original array. a = [0,1,2,3,4]; result = [1,2,3,4,5]; - assertArrayEquals(result, a.map(function(n, index, array) { array[index] = n + 1; return n + 1;})); + assertArrayEquals(result, + a.map(function(n, index, array) { + array[index] = n + 1; return n + 1; + })); assertArrayEquals(result, a); // Only loop through initial part of array eventhough elements are // added. a = [0,1,2,3,4]; result = [1,2,3,4,5]; - assertArrayEquals(result, a.map(function(n, index, array) { array.push(n); return n + 1;})); + assertArrayEquals(result, + a.map(function(n, index, array) { array.push(n); return n + 1; })); assertArrayEquals([0,1,2,3,4,0,1,2,3,4], a); // Respect holes. @@ -275,12 +290,15 @@ // Modify original array. a = [0,1,2,3]; - assertTrue(a.some(function(n, index, array) { array[index] = n + 1; return n == 2; })); + assertTrue( + a.some(function(n, index, array) { + array[index] = n + 1; return n == 2; })); assertArrayEquals([1,2,3,3], a); // Only loop through initial part when elements are added. a = [0,1,2]; - assertFalse(a.some(function(n, index, array) { array.push(42); return n == 42; })); + assertFalse( + a.some(function(n, index, array) { array.push(42); return n == 42; })); assertArrayEquals([0,1,2,42,42,42], a); // Respect holes. diff --git a/deps/v8/test/mjsunit/array-length.js b/deps/v8/test/mjsunit/array-length.js index c2b325061b..02103fa371 100644 --- a/deps/v8/test/mjsunit/array-length.js +++ b/deps/v8/test/mjsunit/array-length.js @@ -115,7 +115,7 @@ assertEquals(20, a.length); var o = { length: -23 }; Array.prototype.pop.apply(o); -assertEquals(4294967272, o.length); +assertEquals(0, o.length); // Check case of compiled stubs. var a = []; diff --git a/deps/v8/test/mjsunit/builtins.js b/deps/v8/test/mjsunit/builtins.js deleted file mode 100644 index 62989399de..0000000000 --- a/deps/v8/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/deps/v8/test/mjsunit/call-counts.js b/deps/v8/test/mjsunit/call-counts.js index d1488245f1..1ad62ba5e7 100644 --- a/deps/v8/test/mjsunit/call-counts.js +++ b/deps/v8/test/mjsunit/call-counts.js @@ -4,6 +4,9 @@ // Flags: --allow-natives-syntax --noalways-opt +// We disable vector store ICs because slot indices change when this option +// is enabled. + // Locations in the type feedback vector where call counts are maintained for // the two calls made from bar(); diff --git a/deps/v8/test/mjsunit/call-cross-realm.js b/deps/v8/test/mjsunit/call-cross-realm.js new file mode 100644 index 0000000000..68e5b1682b --- /dev/null +++ b/deps/v8/test/mjsunit/call-cross-realm.js @@ -0,0 +1,13 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +Realm.create(); +var object = Realm.eval(1, "Object"); +var f = Realm.eval(1, "function f() { return this }; f"); + +Number.prototype.f = f; +var number = 1; +assertEquals(object.prototype, f.call(number).__proto__.__proto__); +assertEquals(object.prototype, number.f().__proto__.__proto__); +assertEquals(Realm.global(1), f()); diff --git a/deps/v8/test/mjsunit/call-runtime-tail.js b/deps/v8/test/mjsunit/call-runtime-tail.js index 6ad107dcb2..9f404a8089 100644 --- a/deps/v8/test/mjsunit/call-runtime-tail.js +++ b/deps/v8/test/mjsunit/call-runtime-tail.js @@ -3,6 +3,7 @@ // found in the LICENSE file. // Flags: --allow-natives-syntax --nostress-opt --turbo +// Flags: --nonative-context-specialization var p0 = new Object(); var p1 = new Object(); @@ -15,7 +16,7 @@ tailee1 = function() { if (count1-- == 0) { return this; } - return %_CallFunction(this, tailee1); + return %_Call(tailee1, this); }; %OptimizeFunctionOnNextCall(tailee1); @@ -32,7 +33,7 @@ tailee2 = function(px) { if ((count2 | 0) === 0) { return this; } - return %_CallFunction(this, px, tailee2); + return %_Call(tailee2, this, px); }; %OptimizeFunctionOnNextCall(tailee2); @@ -46,7 +47,7 @@ tailee3 = function(px) { if (count3-- == 0) { return this; } - return %_CallFunction(px, this, tailee3); + return %_Call(tailee3, px, this); }; %OptimizeFunctionOnNextCall(tailee3); @@ -60,7 +61,7 @@ tailee4 = function(px) { if (count4-- == 0) { return this; } - return %_CallFunction(this, px, undefined, tailee4); + return %_Call(tailee4, this, px, undefined); }; %OptimizeFunctionOnNextCall(tailee4); @@ -74,7 +75,7 @@ tailee5 = function(px) { if (count5-- == 0) { return this; } - return %_CallFunction(this, tailee5); + return %_Call(tailee5, this); }; %OptimizeFunctionOnNextCall(tailee5); diff --git a/deps/v8/test/mjsunit/compiler/boolean-protototype.js b/deps/v8/test/mjsunit/compiler/boolean-protototype.js new file mode 100644 index 0000000000..5e940d75ae --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/boolean-protototype.js @@ -0,0 +1,43 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function test1(s) { + return s.toString; +} +assertSame(test1(false), Boolean.prototype.toString); +assertSame(test1(true), Boolean.prototype.toString); +%OptimizeFunctionOnNextCall(test1); +assertSame(test1(false), Boolean.prototype.toString); +assertSame(test1(true), Boolean.prototype.toString); + +function test2(s) { + return s.valueOf; +} +assertSame(test2(false), Boolean.prototype.valueOf); +assertSame(test2(true), Boolean.prototype.valueOf); +%OptimizeFunctionOnNextCall(test2); +assertSame(test2(false), Boolean.prototype.valueOf); +assertSame(test2(true), Boolean.prototype.valueOf); + +Boolean.prototype.foo = 42; +function test3(s) { + return s["foo"]; +} +assertEquals(test3(false), 42); +assertEquals(test3(true), 42); +%OptimizeFunctionOnNextCall(test3); +assertEquals(test3(false), 42); +assertEquals(test3(true), 42); + +Boolean.prototype.bar = function bar() { "use strict"; return this; } +function test4(s) { + return s.bar(); +} +assertEquals(test4(false), false); +assertEquals(test4(true), true); +%OptimizeFunctionOnNextCall(test4); +assertEquals(test4(false), false); +assertEquals(test4(true), true); diff --git a/deps/v8/test/mjsunit/compiler/receiver-conversion.js b/deps/v8/test/mjsunit/compiler/receiver-conversion.js new file mode 100644 index 0000000000..c3f807a422 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/receiver-conversion.js @@ -0,0 +1,128 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +// This test suite checks that the receiver value (i.e. the 'this' binding) is +// correctly converted even when the callee function is inlined. This behavior +// is specified by ES6, section 9.2.1.2 "OrdinaryCallBindThis". + +var global = this; +function test(outer, inner, check) { + check(outer()); + check(outer()); + %OptimizeFunctionOnNextCall(outer); + check(outer()); +} + + +// ----------------------------------------------------------------------------- +// Test undefined in sloppy mode. +(function UndefinedSloppy() { + function check(x) { + assertEquals("object", typeof x); + assertSame(global, x); + } + function inner(x) { + return this; + } + function outer() { + return sloppy(); + } + global.sloppy = inner; + test(outer, inner, check); +})(); + + +// ----------------------------------------------------------------------------- +// Test undefined in strict mode. +(function UndefinedStrict() { + function check(x) { + assertEquals("undefined", typeof x); + assertSame(undefined, x); + } + function inner(x) { + "use strict"; + return this; + } + function outer() { + return strict(); + } + global.strict = inner; + test(outer, inner, check); +})(); + + +// ----------------------------------------------------------------------------- +// Test primitive number in sloppy mode. +(function NumberSloppy() { + function check(x) { + assertEquals("object", typeof x); + assertInstanceof(x, Number); + } + function inner(x) { + return this; + } + function outer() { + return (0).sloppy(); + } + Number.prototype.sloppy = inner; + test(outer, inner, check); +})(); + + +// ----------------------------------------------------------------------------- +// Test primitive number in strict mode. +(function NumberStrict() { + function check(x) { + assertEquals("number", typeof x); + assertSame(0, x); + } + function inner(x) { + "use strict"; + return this; + } + function outer() { + return (0).strict(); + } + Number.prototype.strict = inner; + test(outer, inner, check); +})(); + + +// ----------------------------------------------------------------------------- +// Test primitive string in sloppy mode. +(function StringSloppy() { + function check(x) { + assertEquals("object", typeof x); + assertInstanceof(x, String); + } + function inner(x) { + return this; + } + function outer() { + return ("s").sloppy(); + } + String.prototype.sloppy = inner; + test(outer, inner, check); +})(); + + +// ----------------------------------------------------------------------------- +// Test primitive string in strict mode. +(function StringStrict() { + function check(x) { + assertEquals("string", typeof x); + assertSame("s", x); + } + function inner(x) { + "use strict"; + return this; + } + function outer() { + return ("s").strict(); + } + String.prototype.strict = inner; + test(outer, inner, check); +})(); diff --git a/deps/v8/test/mjsunit/compiler/regress-4413-1.js b/deps/v8/test/mjsunit/compiler/regress-4413-1.js new file mode 100644 index 0000000000..6f5371127d --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-4413-1.js @@ -0,0 +1,15 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --turbo-asm + +var foo = (function(stdlib) { + "use asm"; + var bar = stdlib.Symbol; + function foo() { return bar("lala"); } + return foo; +})(this); + +%OptimizeFunctionOnNextCall(foo); +foo(); diff --git a/deps/v8/test/mjsunit/compiler/regress-4470-1.js b/deps/v8/test/mjsunit/compiler/regress-4470-1.js new file mode 100644 index 0000000000..91d26b7212 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-4470-1.js @@ -0,0 +1,16 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function Foo() {} +Foo.prototype.x = 0; +function foo(f) { + f.x = 1; +} +foo(new Foo); +foo(new Foo); +%OptimizeFunctionOnNextCall(foo); +foo(new Foo); +assertEquals(Foo.prototype.x, 0); diff --git a/deps/v8/test/mjsunit/compiler/regress-447567.js b/deps/v8/test/mjsunit/compiler/regress-447567.js index c348debee2..7aaada02c7 100644 --- a/deps/v8/test/mjsunit/compiler/regress-447567.js +++ b/deps/v8/test/mjsunit/compiler/regress-447567.js @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -assertThrows(function() { - [0].every(function(){ Object.seal((new Int8Array())); }); -}) +assertThrows(function () { + Object.freeze(new Int8Array(1)) +}); assertThrows(function() { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/regress-crbug-540593.js b/deps/v8/test/mjsunit/compiler/regress-crbug-540593.js new file mode 100644 index 0000000000..ec68e85771 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-crbug-540593.js @@ -0,0 +1,14 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --enable-slow-asserts --turbo-inlining + +var __f_2 = (function(stdlib) { + "use asm"; + var __v_3 = stdlib.Symbol; + function __f_2() { return __v_3(); } + return __f_2; +})(this); +%OptimizeFunctionOnNextCall(__f_2); +__f_2(); diff --git a/deps/v8/test/mjsunit/compiler/regress-lazy-deopt.js b/deps/v8/test/mjsunit/compiler/regress-lazy-deopt.js index d1c3d01dc6..766220763b 100644 --- a/deps/v8/test/mjsunit/compiler/regress-lazy-deopt.js +++ b/deps/v8/test/mjsunit/compiler/regress-lazy-deopt.js @@ -27,7 +27,7 @@ // Flags: --allow-natives-syntax -// Test lazy deoptimization after CallFunctionStub. +// Test lazy deoptimization after Call builtin. function foo() { return 1; } @@ -37,7 +37,7 @@ function f(x, y) { %DeoptimizeFunction(f); return 1; } - a[0] = %_CallFunction(null, x - 1, f); + a[0] = %_Call(f, null, x - 1); return x >> a[0]; } diff --git a/deps/v8/test/mjsunit/regress/regress-460937.js b/deps/v8/test/mjsunit/compiler/regress-variable-liveness-let.js index cd57f93328..4c6b6936e5 100644 --- a/deps/v8/test/mjsunit/regress/regress-460937.js +++ b/deps/v8/test/mjsunit/compiler/regress-variable-liveness-let.js @@ -2,18 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --allow-natives-syntax +// Flags: --allow-natives-syntax --turbo-filter=f + +"use strict"; function f() { - var a = new Array(100000); - var i = 0; - while (!%HasFastDoubleElements(a)) { - a[i] = i; - i += 0.1; - } - a[1] = 1.5; + %DeoptimizeNow(); + let x = 23; } -f(); %OptimizeFunctionOnNextCall(f); f(); diff --git a/deps/v8/test/mjsunit/compiler/symbol-protototype.js b/deps/v8/test/mjsunit/compiler/symbol-protototype.js new file mode 100644 index 0000000000..9a707e8a08 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/symbol-protototype.js @@ -0,0 +1,40 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function test1(s) { + return s.toString; +} +assertSame(test1(Symbol()), Symbol.prototype.toString); +assertSame(test1(Symbol()), Symbol.prototype.toString); +%OptimizeFunctionOnNextCall(test1); +assertSame(test1(Symbol()), Symbol.prototype.toString); + +function test2(s) { + return s.valueOf; +} +assertSame(test2(Symbol()), Symbol.prototype.valueOf); +assertSame(test2(Symbol()), Symbol.prototype.valueOf); +%OptimizeFunctionOnNextCall(test2); +assertSame(test2(Symbol()), Symbol.prototype.valueOf); + +Symbol.prototype.foo = 1; +function test3(s) { + return s["foo"]; +} +assertEquals(test3(Symbol()), 1); +assertEquals(test3(Symbol()), 1); +%OptimizeFunctionOnNextCall(test3); +assertEquals(test3(Symbol()), 1); + +Symbol.prototype.bar = function() { "use strict"; return this; } +function test4(s) { + return s.bar(); +} +var s = Symbol("foo"); +assertEquals(test4(s), s); +assertEquals(test4(s), s); +%OptimizeFunctionOnNextCall(test4); +assertEquals(test4(s), s); diff --git a/deps/v8/test/mjsunit/cross-realm-filtering.js b/deps/v8/test/mjsunit/cross-realm-filtering.js index 9523e8cc1a..47c0d19229 100644 --- a/deps/v8/test/mjsunit/cross-realm-filtering.js +++ b/deps/v8/test/mjsunit/cross-realm-filtering.js @@ -70,3 +70,21 @@ assertSame(Realm.shared.caller_1, Realm.shared.result_1); Realm.eval(realms[0], script); assertSame(Realm.shared.caller_0, Realm.shared.result_0); assertSame(null, Realm.shared.result_1); + + +// test that do not pollute / leak a function prototype v8/4217 +var realmIndex = Realm.create(); +var otherObject = Realm.eval(realmIndex, "Object"); + +var f = Realm.eval(realmIndex, "function f(){}; f"); +f.prototype = null; + +var o = new f(); +var proto = Object.getPrototypeOf(o); +assertFalse(proto === Object.prototype); +assertTrue(proto === otherObject.prototype); + +o = Realm.eval(realmIndex, "new f()"); +proto = Object.getPrototypeOf(o); +assertFalse(proto === Object.prototype); +assertTrue(proto === otherObject.prototype); diff --git a/deps/v8/test/mjsunit/debug-scopes.js b/deps/v8/test/mjsunit/debug-scopes.js index c388a67196..8cde95194a 100644 --- a/deps/v8/test/mjsunit/debug-scopes.js +++ b/deps/v8/test/mjsunit/debug-scopes.js @@ -145,6 +145,18 @@ function CheckScopeChain(scopes, exec_state) { } +// Check that the scope chain contains the expected names of scopes. +function CheckScopeChainNames(names, exec_state) { + var all_scopes = exec_state.frame().allScopes(); + assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); + for (var i = 0; i < names.length; i++) { + var scope = exec_state.frame().scope(i); + assertTrue(scope.isScope()); + assertEquals(scope.details().name(), names[i]) + } +} + + // Check that the content of the scope is as expected. For functions just check // that there is a function. function CheckScopeContent(content, number, exec_state) { @@ -517,6 +529,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1}, 1, exec_state); + CheckScopeChainNames([undefined, "closure_1", undefined, undefined], exec_state) }; closure_1(1)(); EndTest(); @@ -543,6 +556,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,x:3}, 1, exec_state); + CheckScopeChainNames([undefined, "closure_2", undefined, undefined], exec_state) }; closure_2(1, 2)(); EndTest(); @@ -570,6 +584,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); + CheckScopeChainNames([undefined, "closure_3", undefined, undefined], exec_state) }; closure_3(1, 2)(); EndTest(); @@ -600,6 +615,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); + CheckScopeChainNames([undefined, "closure_4", undefined, undefined], exec_state) }; closure_4(1, 2)(); EndTest(); @@ -629,6 +645,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); + CheckScopeChainNames(["f", "closure_5", undefined, undefined], exec_state) }; closure_5(1, 2)(); EndTest(); @@ -660,6 +677,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({a:1}, 1, exec_state); CheckScopeContent({f:function(){}}, 2, exec_state); + CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined], exec_state) }; closure_6(1, 2)(); EndTest(); @@ -696,6 +714,7 @@ listener_delegate = function(exec_state) { CheckScopeContent({}, 0, exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 1, exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 2, exec_state); + CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined], exec_state) }; closure_7(1, 2)(); EndTest(); @@ -714,6 +733,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({x: 2}, 0, exec_state); + CheckScopeChainNames([undefined, undefined, undefined], exec_state) }; closure_8(); EndTest(); @@ -735,6 +755,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Closure, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); + CheckScopeChainNames([undefined, "closure_9", undefined, undefined], exec_state) }; closure_9(); EndTest(); @@ -783,6 +804,7 @@ listener_delegate = function(exec_state) { CheckScopeContent({j:13}, 3, exec_state); CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state); + CheckScopeChainNames([undefined, undefined, undefined, "f", "f", "the_full_monty", undefined, undefined], exec_state) }; the_full_monty(1, 2)(); EndTest(); @@ -830,6 +852,7 @@ listener_delegate = function(exec_state) { CheckScopeContent({x: 3}, 0, exec_state); CheckScopeContent({x: 2}, 1, exec_state); CheckScopeContent({x: 1}, 2, exec_state); + CheckScopeChainNames(["inner", "inner", "closure_in_with_2", "closure_in_with_2", undefined, undefined], exec_state) }; closure_in_with_2(); EndTest(); @@ -860,6 +883,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Closure, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); + CheckScopeChainNames(["inner", "inner", "closure", "createClosure", undefined, undefined], exec_state) } closure_in_with_3(); EndTest(); @@ -873,6 +897,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({x: 2}, 0, exec_state); CheckScopeContent({x: 1}, 1, exec_state); + CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) }; with({x:1}) { @@ -887,6 +912,7 @@ EndTest(); BeginTest("Global"); listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Script, debug.ScopeType.Global], exec_state); + CheckScopeChainNames([undefined, undefined], exec_state) }; debugger; EndTest(); @@ -908,6 +934,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({e:'Exception'}, 0, exec_state); + CheckScopeChainNames(["catch_block_1", undefined, undefined, undefined], exec_state) }; catch_block_1(); EndTest(); @@ -933,6 +960,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({n:10}, 0, exec_state); CheckScopeContent({e:'Exception'}, 1, exec_state); + CheckScopeChainNames(["catch_block_2", "catch_block_2", "catch_block_2", undefined, undefined], exec_state) }; catch_block_2(); EndTest(); @@ -958,6 +986,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({e:'Exception'}, 0, exec_state); CheckScopeContent({y:78}, 1, exec_state); + CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined], exec_state) }; catch_block_3(); EndTest(); @@ -986,6 +1015,7 @@ listener_delegate = function(exec_state) { CheckScopeContent({n:10}, 0, exec_state); CheckScopeContent({e:'Exception'}, 1, exec_state); CheckScopeContent({y:98}, 2, exec_state); + CheckScopeChainNames(["catch_block_4", "catch_block_4", "catch_block_4", undefined, undefined], exec_state) }; catch_block_4(); EndTest(); @@ -998,6 +1028,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({e:'Exception'}, 0, exec_state); + CheckScopeChainNames([undefined, undefined, undefined], exec_state) }; try { @@ -1018,6 +1049,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({x: 2}, 0, exec_state); CheckScopeContent({e:'Exception'}, 1, exec_state); + CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) }; try { @@ -1048,6 +1080,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({e:'Exception'}, 0, exec_state); + CheckScopeChainNames(["catch_block_7", undefined, undefined, undefined], exec_state) }; catch_block_7(); EndTest(); @@ -1061,6 +1094,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({}, 1, exec_state); + CheckScopeChainNames([undefined, undefined, undefined], exec_state) }; (function() { diff --git a/deps/v8/test/mjsunit/debug-script.js b/deps/v8/test/mjsunit/debug-script.js index 32415c2428..276fd55e90 100644 --- a/deps/v8/test/mjsunit/debug-script.js +++ b/deps/v8/test/mjsunit/debug-script.js @@ -28,6 +28,11 @@ // Flags: --expose-debug-as debug --expose-gc --send-idle-notification // Flags: --allow-natives-syntax --expose-natives-as natives // Flags: --noharmony-shipping +// Flags: --nostress-opt + +// --nostress-opt is specified because in stress mode the compilation cache +// may hold on to old copies of scripts (see bug 1641). + // Note: this test checks that that the number of scripts reported as native // by Debug.scripts() is the same as a number of core native scripts. // Native scripts that are added by --harmony-shipping are classified diff --git a/deps/v8/test/mjsunit/debug-scripts-throw.js b/deps/v8/test/mjsunit/debug-scripts-throw.js new file mode 100644 index 0000000000..ee7cbd335b --- /dev/null +++ b/deps/v8/test/mjsunit/debug-scripts-throw.js @@ -0,0 +1,14 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug + +// Get the Debug object exposed from the debug context global object. +Debug = debug.Debug; + +assertThrows("Debug.scripts()"); +Debug.setListener(function(){}); + +assertDoesNotThrow("Debug.scripts()"); +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/double-equals.js b/deps/v8/test/mjsunit/double-equals.js index 5ebf92ca7b..40d9a76b48 100644 --- a/deps/v8/test/mjsunit/double-equals.js +++ b/deps/v8/test/mjsunit/double-equals.js @@ -25,6 +25,8 @@ // (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: --harmony-simd + /** * This test uses assert{True,False}(... == ...) instead of * assertEquals(..., ...) to not rely on the details of the @@ -234,3 +236,15 @@ function testBadConversion(value) { testBadConversion(0); testBadConversion("string"); testBadConversion(true); + +var s = Symbol(); +testEqual(s, s); +testEqual(Object(s), s); +testEqual(new Wrapper(s), s); +testNotEqual(Object(s), Object(s)); + +var simd = SIMD.Float32x4(1, 2, 3, 4); +testEqual(simd, simd); +testEqual(Object(simd), simd); +testEqual(new Wrapper(simd), simd); +testNotEqual(Object(simd), Object(simd)); diff --git a/deps/v8/test/mjsunit/harmony/array-copywithin.js b/deps/v8/test/mjsunit/es6/array-copywithin.js index c3a0c14663..ed52b7d5fa 100644 --- a/deps/v8/test/mjsunit/harmony/array-copywithin.js +++ b/deps/v8/test/mjsunit/es6/array-copywithin.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrays - (function copyWithinArity() { assertEquals(Array.prototype.copyWithin.length, 2); })(); diff --git a/deps/v8/test/mjsunit/harmony/array-fill.js b/deps/v8/test/mjsunit/es6/array-fill.js index eae18d113b..ef316e8146 100644 --- a/deps/v8/test/mjsunit/harmony/array-fill.js +++ b/deps/v8/test/mjsunit/es6/array-fill.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrays - assertEquals(1, Array.prototype.fill.length); assertArrayEquals([].fill(8), []); diff --git a/deps/v8/test/mjsunit/harmony/array-find.js b/deps/v8/test/mjsunit/es6/array-find.js index 44fc78292a..5f6ba4226b 100644 --- a/deps/v8/test/mjsunit/harmony/array-find.js +++ b/deps/v8/test/mjsunit/es6/array-find.js @@ -25,8 +25,6 @@ // (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: --harmony-arrays - assertEquals(1, Array.prototype.find.length); var a = [21, 22, 23, 24]; diff --git a/deps/v8/test/mjsunit/harmony/array-findindex.js b/deps/v8/test/mjsunit/es6/array-findindex.js index 7068a9cb40..716eb4e0db 100644 --- a/deps/v8/test/mjsunit/harmony/array-findindex.js +++ b/deps/v8/test/mjsunit/es6/array-findindex.js @@ -25,8 +25,6 @@ // (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: --harmony-arrays - assertEquals(1, Array.prototype.findIndex.length); var a = [21, 22, 23, 24]; diff --git a/deps/v8/test/mjsunit/harmony/array-from.js b/deps/v8/test/mjsunit/es6/array-from.js index 2b7f2902f8..c483d3deb6 100644 --- a/deps/v8/test/mjsunit/harmony/array-from.js +++ b/deps/v8/test/mjsunit/es6/array-from.js @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrays (function() { assertEquals(1, Array.from.length); diff --git a/deps/v8/test/mjsunit/harmony/array-length.js b/deps/v8/test/mjsunit/es6/array-length.js index df488196ff..cc3b88105c 100644 --- a/deps/v8/test/mjsunit/harmony/array-length.js +++ b/deps/v8/test/mjsunit/es6/array-length.js @@ -33,13 +33,7 @@ assertEquals(1, o.length); assertEquals(1, o[0]); var o = { length: Number.MAX_VALUE }; -Array.prototype.push.call(o, 1); -assertEquals(o.length, Number.MAX_SAFE_INTEGER + 1); -assertEquals(1, o[Number.MAX_SAFE_INTEGER]); - -Array.prototype.push.call(o, 2); -assertEquals(o.length, Number.MAX_SAFE_INTEGER + 1); -assertEquals(2, o[Number.MAX_SAFE_INTEGER]); +assertThrows(() => Array.prototype.push.call(o, 1), TypeError); // ArrayPop diff --git a/deps/v8/test/mjsunit/harmony/array-of.js b/deps/v8/test/mjsunit/es6/array-of.js index 7fd5eeaf61..40bc890da7 100644 --- a/deps/v8/test/mjsunit/harmony/array-of.js +++ b/deps/v8/test/mjsunit/es6/array-of.js @@ -4,8 +4,6 @@ // Based on Mozilla Array.of() tests at http://dxr.mozilla.org/mozilla-central/source/js/src/jit-test/tests/collections -// Flags: --harmony-arrays - // Array.of makes real arrays. diff --git a/deps/v8/test/mjsunit/harmony/arrow-functions-lexical-arguments.js b/deps/v8/test/mjsunit/es6/arrow-functions-lexical-arguments.js index b2498d78dc..2d06552ed2 100644 --- a/deps/v8/test/mjsunit/harmony/arrow-functions-lexical-arguments.js +++ b/deps/v8/test/mjsunit/es6/arrow-functions-lexical-arguments.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - (function testInFunctionDeclaration() { var calls = 0; diff --git a/deps/v8/test/mjsunit/harmony/arrow-functions-this.js b/deps/v8/test/mjsunit/es6/arrow-functions-this.js index 2c2ad075d2..dea105f296 100644 --- a/deps/v8/test/mjsunit/harmony/arrow-functions-this.js +++ b/deps/v8/test/mjsunit/es6/arrow-functions-this.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - var object = {}; var global = this; var call = Function.call.bind(Function.call); diff --git a/deps/v8/test/mjsunit/harmony/arrow-functions.js b/deps/v8/test/mjsunit/es6/arrow-functions.js index 6b84c3a6b4..c1b375a411 100644 --- a/deps/v8/test/mjsunit/harmony/arrow-functions.js +++ b/deps/v8/test/mjsunit/es6/arrow-functions.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - // Arrow functions are like functions, except they throw when using the // "new" operator on them. assertEquals("function", typeof (() => {})); @@ -70,3 +68,16 @@ assertEquals([5, 10], fives); assertThrows(function() { return arrowFn.caller; }, TypeError); assertThrows(function() { arrowFn.caller = {}; }, TypeError); })(); + + +// v8:4474 +(function testConciseBodyReturnsRegexp() { + var arrow1 = () => /foo/ + var arrow2 = () => /foo/; + var arrow3 = () => /foo/i + var arrow4 = () => /foo/i; + assertEquals(arrow1.toString(), "() => /foo/"); + assertEquals(arrow2.toString(), "() => /foo/"); + assertEquals(arrow3.toString(), "() => /foo/i"); + assertEquals(arrow4.toString(), "() => /foo/i"); +}); diff --git a/deps/v8/test/mjsunit/es6/block-for.js b/deps/v8/test/mjsunit/es6/block-for.js index 420c41e610..c7a23e8d32 100644 --- a/deps/v8/test/mjsunit/es6/block-for.js +++ b/deps/v8/test/mjsunit/es6/block-for.js @@ -24,6 +24,9 @@ // 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: --harmony-completion + "use strict"; function props(x) { @@ -189,10 +192,18 @@ assertEquals(undefined, eval("for (let i = 0; i < 10; i++) { continue; i; }")); assertEquals(0, eval("for (let i = 0; true;) { i; break; }")); assertEquals(0, eval("for (const i = 0; true;) { i; break; }")); assertEquals(9, eval("for (let i = 0; i < 10; i++) { i; continue; }")); -assertEquals(3, eval("for (let i = 0; true; i++) { i; if (i >= 3) break; }")); -assertEquals(2, eval("for (let i = 0; true; i++) { if (i >= 3) break; i; }")); -assertEquals( - 2, eval("for (let i = 0; i < 10; i++) { if (i >= 3) continue; i; }")); +assertEquals(undefined, + eval("for (let i = 0; true; i++) { i; if (i >= 3) break; }")); +assertEquals(3, + eval("for (let i = 0; true; i++) { i; if (i >= 3) { i; break; } }")); +assertEquals(undefined, + eval("for (let i = 0; true; i++) { if (i >= 3) break; i; }")); +assertEquals(3, + eval("for (let i = 0; true; i++) { if (i >= 3) { i; break; }; i; }")); +assertEquals(undefined, + eval("for (let i = 0; i < 10; i++) { if (i >= 3) continue; i; }")); +assertEquals(9, + eval("for (let i = 0; i < 10; i++) { if (i >= 3) {i; continue; }; i; }")); assertEquals(undefined, eval("foo: for (let i = 0; true;) { break foo; }")); assertEquals(undefined, eval("foo: for (const i = 0; true;) { break foo; }")); assertEquals(3, eval("foo: for (let i = 3; true;) { i; break foo; }")); diff --git a/deps/v8/test/mjsunit/es6/block-scoping.js b/deps/v8/test/mjsunit/es6/block-scoping.js index 719f5231ce..0308edde96 100644 --- a/deps/v8/test/mjsunit/es6/block-scoping.js +++ b/deps/v8/test/mjsunit/es6/block-scoping.js @@ -90,7 +90,6 @@ function f3(one) { for (var j = 0; j < 5; ++j) f3(1); %OptimizeFunctionOnNextCall(f3); f3(1); -assertTrue(%GetOptimizationStatus(f3) != 2); diff --git a/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js b/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js new file mode 100644 index 0000000000..74dd489cb8 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js @@ -0,0 +1,606 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +"use strict"; + + +function checkPrototypeChain(object, constructors) { + var proto = object.__proto__; + for (var i = 0; i < constructors.length; i++) { + assertEquals(constructors[i].prototype, proto); + assertEquals(constructors[i], proto.constructor); + proto = proto.__proto__; + } +} + + +(function() { + class A extends Object { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var s = new A("foo"); + assertTrue(s instanceof Object); + assertTrue(s instanceof A); + assertEquals("object", typeof s); + checkPrototypeChain(s, [A, Object]); + assertEquals(42, s.a); + assertEquals(4.2, s.d); + + var s1 = new A("bar"); + assertTrue(%HaveSameMap(s, s1)); + + + var n = new A(153); + assertTrue(n instanceof Object); + assertTrue(n instanceof A); + assertEquals("object", typeof s); + checkPrototypeChain(s, [A, Object]); + assertEquals(42, n.a); + assertEquals(4.2, n.d); + + var n1 = new A(312); + assertTrue(%HaveSameMap(n, n1)); + assertTrue(%HaveSameMap(n, s)); + + + var b = new A(true); + assertTrue(b instanceof Object); + assertTrue(b instanceof A); + assertEquals("object", typeof s); + checkPrototypeChain(s, [A, Object]); + assertEquals(42, b.a); + assertEquals(4.2, b.d); + + var b1 = new A(true); + assertTrue(%HaveSameMap(b, b1)); + assertTrue(%HaveSameMap(b, s)); +})(); + + +(function() { + class A extends Function { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A("this.foo = 153;"); + assertTrue(o instanceof Object); + assertTrue(o instanceof Function); + assertTrue(o instanceof A); + assertEquals("function", typeof o); + checkPrototypeChain(o, [A, Function, Object]); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + var oo = new o(); + assertEquals(153, oo.foo); + + var o1 = new A("return 312;"); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +(function() { + class A extends Boolean { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A(true); + assertTrue(o instanceof Object); + assertTrue(o instanceof Boolean); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, Boolean]); + assertTrue(o.valueOf()); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(false); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +function TestErrorSubclassing(error) { + class A extends error { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A("message"); + assertTrue(o instanceof Object); + assertTrue(o instanceof error); + assertTrue(o instanceof Error); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + if (error == Error) { + checkPrototypeChain(o, [A, Error, Object]); + } else { + checkPrototypeChain(o, [A, error, Error, Object]); + } + assertEquals("message", o.message); + assertEquals(error.name + ": message", o.toString()); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A("achtung!"); + assertTrue(%HaveSameMap(o, o1)); +} + + +(function() { + TestErrorSubclassing(Error); + TestErrorSubclassing(EvalError); + TestErrorSubclassing(RangeError); + TestErrorSubclassing(ReferenceError); + TestErrorSubclassing(SyntaxError); + TestErrorSubclassing(TypeError); + TestErrorSubclassing(URIError); +})(); + + +(function() { + class A extends Number { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A(153); + assertTrue(o instanceof Object); + assertTrue(o instanceof Number); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, Number, Object]); + assertEquals(153, o.valueOf()); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(312); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +(function() { + class A extends Date { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A(1234567890); + assertTrue(o instanceof Object); + assertTrue(o instanceof Date); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, Date, Object]); + assertEquals(1234567890, o.getTime()); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(2015, 10, 29); + assertEquals(2015, o1.getFullYear()); + assertEquals(10, o1.getMonth()); + assertEquals(29, o1.getDate()); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +(function() { + class A extends String { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A("foo"); + assertTrue(o instanceof Object); + assertTrue(o instanceof String); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, String, Object]); + + assertEquals("foo", o.valueOf()); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A("bar"); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +(function() { + class A extends RegExp { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A("o(..)h", "g"); + assertTrue(o instanceof Object); + assertTrue(o instanceof RegExp); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, RegExp, Object]); + assertTrue(o.test("ouch")); + assertArrayEquals(["ouch", "uc"], o.exec("boom! ouch! bam!")); + assertEquals("o(..)h", o.source); + assertTrue(o.global); + assertFalse(o.ignoreCase); + assertFalse(o.multiline); + assertEquals(10, o.lastIndex); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(7); + assertTrue(%HaveSameMap(o, o1)); +})(); + + +function TestArraySubclassing(array) { + class A extends array { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new array(13); + assertTrue(o instanceof Object); + assertTrue(o instanceof array); + assertEquals("object", typeof o); + checkPrototypeChain(o, [array, Object]); + assertEquals(13, o.length); + + var o = new A(10); + assertTrue(o instanceof Object); + assertTrue(o instanceof array); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, array, Object]); + assertEquals(10, o.length); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(7); + assertTrue(%HaveSameMap(o, o1)); +} + + +(function() { + TestArraySubclassing(Array); + TestArraySubclassing(Int8Array); + TestArraySubclassing(Uint8Array); + TestArraySubclassing(Uint8ClampedArray); + TestArraySubclassing(Int16Array); + TestArraySubclassing(Uint16Array); + TestArraySubclassing(Int32Array); + TestArraySubclassing(Uint32Array); + TestArraySubclassing(Float32Array); + TestArraySubclassing(Float64Array); +})(); + + +function TestMapSetSubclassing(container, is_map) { + var keys = [{name: "banana"}, {name: "cow"}, {name: "orange"}, {name: "chicken"}, {name: "apple"}]; + + class A extends container { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A(); + assertTrue(o instanceof Object); + assertTrue(o instanceof container); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, container, Object]); + + for (var i = 0; i < keys.length; i++) { + if (is_map) { + o.set(keys[i], (i + 1) * 11); + } else { + o.add(keys[i]); + } + } + o.delete(keys[1]); + o.delete(keys[3]); + + assertTrue(o.has(keys[0])); + assertFalse(o.has(keys[1])); + assertTrue(o.has(keys[2])); + assertFalse(o.has(keys[1])); + assertTrue(o.has(keys[4])); + if (is_map) { + assertEquals(11, o.get(keys[0])); + assertEquals(undefined, o.get(keys[1])); + assertEquals(33, o.get(keys[2])); + assertEquals(undefined, o.get(keys[3])); + assertEquals(55, o.get(keys[4])); + } + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(); + assertTrue(%HaveSameMap(o, o1)); +} + + +(function() { + TestMapSetSubclassing(Map, true); + TestMapSetSubclassing(WeakMap, true); + TestMapSetSubclassing(Set, false); + TestMapSetSubclassing(WeakSet, false); +})(); + + +(function() { + class A extends ArrayBuffer { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var o = new A(16); + assertTrue(o instanceof Object); + assertTrue(o instanceof ArrayBuffer); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, ArrayBuffer, Object]); + + assertEquals(16, o.byteLength); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A("bar"); + assertTrue(%HaveSameMap(o, o1)); + + + class MyInt32Array extends Int32Array { + constructor(v, name) { + super(v); + this.name = name; + } + } + + class MyUint32Array extends Uint32Array { + constructor(v, name) { + super(v); + this.name = name; + } + } + + var int32view = new MyInt32Array(o, "cats"); + var uint32view = new MyUint32Array(o, "dogs"); + + int32view[0] = -2; + uint32view[1] = 0xffffffff; + + assertEquals("cats", int32view.name); + assertEquals("dogs", uint32view.name); + assertEquals(-2, int32view[0]); + assertEquals(-1, int32view[1]); + assertEquals(0xfffffffe, uint32view[0]); + assertEquals(0xffffffff, uint32view[1]); +})(); + + +(function() { + class A extends DataView { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + + var buffer = new ArrayBuffer(16); + var o = new A(buffer); + assertTrue(o instanceof Object); + assertTrue(o instanceof DataView); + assertTrue(o instanceof A); + assertEquals("object", typeof o); + checkPrototypeChain(o, [A, DataView, Object]); + + o.setUint32(0, 0xcafebabe, false); + assertEquals(0xcafebabe, o.getUint32(0, false)); + assertEquals(0xbebafeca, o.getUint32(0, true)); + assertEquals(42, o.a); + assertEquals(4.2, o.d); + + var o1 = new A(buffer); + assertTrue(%HaveSameMap(o, o1)); + +})(); + + +(function() { + // TODO(ishell): remove once GeneratorFunction is available. + var GeneratorFunction = (function*() {}).__proto__.constructor; + class A extends GeneratorFunction { + constructor(...args) { + assertTrue(%IsConstructCall()); + super(...args); + this.a = 42; + this.d = 4.2; + } + } + var generator_func = new A("var index = 0; while (index < 5) { yield ++index; }"); + assertTrue(generator_func instanceof Object); + assertTrue(generator_func instanceof Function); + assertTrue(generator_func instanceof GeneratorFunction); + assertTrue(generator_func instanceof A); + assertEquals("function", typeof generator_func); + checkPrototypeChain(generator_func, [A, GeneratorFunction, Function, Object]); + assertEquals(42, generator_func.a); + assertEquals(4.2, generator_func.d); + + var o = new generator_func(); + assertTrue(o instanceof Object); + assertTrue(o instanceof generator_func); + assertEquals("object", typeof o); + + assertPropertiesEqual({done: false, value: 1}, o.next()); + assertPropertiesEqual({done: false, value: 2}, o.next()); + assertPropertiesEqual({done: false, value: 3}, o.next()); + assertPropertiesEqual({done: false, value: 4}, o.next()); + assertPropertiesEqual({done: false, value: 5}, o.next()); + assertPropertiesEqual({done: true, value: undefined}, o.next()); + + var generator_func1 = new A("return 0;"); + assertTrue(%HaveSameMap(generator_func, generator_func1)); +})(); + + +(function() { + class A extends Boolean { + constructor() { + assertTrue(%IsConstructCall()); + super(true); + this.a00 = 0 + this.a01 = 0 + this.a02 = 0 + this.a03 = 0 + this.a04 = 0 + this.a05 = 0 + this.a06 = 0 + this.a07 = 0 + this.a08 = 0 + this.a09 = 0 + this.a10 = 0 + this.a11 = 0 + this.a12 = 0 + this.a13 = 0 + this.a14 = 0 + this.a15 = 0 + this.a16 = 0 + this.a17 = 0 + this.a18 = 0 + this.a19 = 0 + } + } + + class B extends A { + constructor() { + assertTrue(%IsConstructCall()); + super(); + this.b00 = 0 + this.b01 = 0 + this.b02 = 0 + this.b03 = 0 + this.b04 = 0 + this.b05 = 0 + this.b06 = 0 + this.b07 = 0 + this.b08 = 0 + this.b09 = 0 + this.b10 = 0 + this.b11 = 0 + this.b12 = 0 + this.b13 = 0 + this.b14 = 0 + this.b15 = 0 + this.b16 = 0 + this.b17 = 0 + this.b18 = 0 + this.b19 = 0 + } + } + + class C extends B { + constructor() { + assertTrue(%IsConstructCall()); + super(); + this.c00 = 0 + this.c01 = 0 + this.c02 = 0 + this.c03 = 0 + this.c04 = 0 + this.c05 = 0 + this.c06 = 0 + this.c07 = 0 + this.c08 = 0 + this.c09 = 0 + this.c10 = 0 + this.c11 = 0 + this.c12 = 0 + this.c13 = 0 + this.c14 = 0 + this.c15 = 0 + this.c16 = 0 + this.c17 = 0 + this.c18 = 0 + this.c19 = 0 + } + } + + var o = new C(); + assertTrue(o instanceof Object); + assertTrue(o instanceof Boolean); + assertTrue(o instanceof A); + assertTrue(o instanceof B); + assertTrue(o instanceof C); + assertEquals("object", typeof o); + checkPrototypeChain(o, [C, B, A, Boolean, Object]); +})(); + + +(function() { + assertThrows("class A extends undefined {}"); + assertThrows("class B extends NaN {}"); + assertThrows("class C extends Infinity {}"); +})(); + + +(function() { + class A extends null {} + assertThrows("new A"); +})(); + + +(function() { + class A extends Symbol {} + assertThrows("new A"); +})(); diff --git a/deps/v8/test/mjsunit/es6/classes.js b/deps/v8/test/mjsunit/es6/classes.js index a1420be1c2..ac10f0e033 100644 --- a/deps/v8/test/mjsunit/es6/classes.js +++ b/deps/v8/test/mjsunit/es6/classes.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-sloppy +// Flags: --harmony-sloppy --allow-natives-syntax (function TestBasics() { var C = class C {} @@ -626,6 +626,56 @@ function assertAccessorDescriptor(object, name) { })(); +(function TestConstructorCall(){ + var realmIndex = Realm.create(); + var otherTypeError = Realm.eval(realmIndex, "TypeError"); + var A = Realm.eval(realmIndex, '"use strict"; class A {}'); + var instance = new A(); + var constructor = instance.constructor; + var otherTypeError = Realm.eval(realmIndex, 'TypeError'); + if (otherTypeError === TypeError) { + throw Error('Should not happen!'); + } + + // ES6 9.2.1[[Call]] throws a TypeError in the caller context/Realm when the + // called function is a classConstructor + assertThrows(function() { Realm.eval(realmIndex, "A()") }, otherTypeError); + assertThrows(function() { instance.constructor() }, TypeError); + assertThrows(function() { A() }, TypeError); + + // ES6 9.3.1 call() first activates the callee context before invoking the + // method. The TypeError from the constructor is thus thrown in the other + // Realm. + assertThrows(function() { Realm.eval(realmIndex, "A.call()") }, + otherTypeError); + assertThrows(function() { constructor.call() }, otherTypeError); + assertThrows(function() { A.call() }, otherTypeError); +})(); + + +(function TestConstructorCallOptimized() { + class A { }; + + function invoke_constructor() { A() } + function call_constructor() { A.call() } + function apply_constructor() { A.apply() } + + for (var i=0; i<3; i++) { + assertThrows(invoke_constructor); + assertThrows(call_constructor); + assertThrows(apply_constructor); + } + // Make sure we still check for class constructors when calling optimized + // code. + %OptimizeFunctionOnNextCall(invoke_constructor); + assertThrows(invoke_constructor); + %OptimizeFunctionOnNextCall(call_constructor); + assertThrows(call_constructor); + %OptimizeFunctionOnNextCall(apply_constructor); + assertThrows(apply_constructor); +})(); + + (function TestDefaultConstructor() { var calls = 0; class Base { diff --git a/deps/v8/test/mjsunit/es6/debug-break-default-constructor.js b/deps/v8/test/mjsunit/es6/debug-break-default-constructor.js new file mode 100644 index 0000000000..a06c3b52de --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-break-default-constructor.js @@ -0,0 +1,42 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug + +"use strict"; + +var Debug = debug.Debug; +var exception = null; +var super_called = false; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + execState.prepareStep(Debug.StepAction.StepInto); + var s = execState.frame().sourceLineText(); + step_count++; + assertTrue(s.indexOf('// ' + step_count + '.') >= 0); + } catch (e) { + exception = e; + } +} + +class Base { + constructor() { + var x = 1; // 2. + } // 3. +} + +class Derived extends Base {} // 1. // 4. + +Debug.setListener(listener); +var bp = Debug.setBreakPoint(Derived, 0); + +new Derived(); + +Debug.setListener(null); // 5. + +assertNull(exception); +assertEquals(5, step_count); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/promise-all-caught.js b/deps/v8/test/mjsunit/es6/debug-promises/promise-all-caught.js new file mode 100644 index 0000000000..2c940ce217 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/promise-all-caught.js @@ -0,0 +1,40 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug --allow-natives-syntax + +// Test debug events when we only listen to uncaught exceptions and a +// Promise p3 created by Promise.all has a catch handler, and is rejected +// because one of the Promises p2 passed to Promise.all is rejected. We +// expect no Exception debug event to be triggered, since p3 and by +// extension p2 have a catch handler. + +var Debug = debug.Debug; + +var expected_events = 2; + +var p1 = Promise.resolve(); +p1.name = "p1"; + +var p2 = p1.then(function() { + throw new Error("caught"); +}); + +p2.name = "p2"; + +var p3 = Promise.all([p2]); +p3.name = "p3"; + +p3.catch(function(e) {}); + +function listener(event, exec_state, event_data, data) { + try { + assertTrue(event != Debug.DebugEvent.Exception) + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } +} + +Debug.setBreakOnUncaughtException(); +Debug.setListener(listener); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/promise-all-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/promise-all-uncaught.js new file mode 100644 index 0000000000..d183c5cf2d --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/promise-all-uncaught.js @@ -0,0 +1,73 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug --allow-natives-syntax + +// Test debug events when we only listen to uncaught exceptions and a +// Promise p3 created by Promise.all has no catch handler, and is rejected +// because one of the Promises p2 passed to Promise.all is rejected. We +// expect two Exception debug events to be triggered, for p2 and p3 each, +// because neither has an user-defined catch handler. + +var Debug = debug.Debug; + +var expected_events = 2; +var log = []; + +var p1 = Promise.resolve(); +p1.name = "p1"; + +var p2 = p1.then(function() { + log.push("throw"); + throw new Error("uncaught"); // event +}); + +p2.name = "p2"; + +var p3 = Promise.all([p2]); +p3.name = "p3"; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + expected_events--; + assertTrue(expected_events >= 0); + assertEquals("uncaught", event_data.exception().message); + assertTrue(event_data.promise() instanceof Promise); + if (expected_events === 1) { + // Assert that the debug event is triggered at the throw site. + assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); + assertEquals("p2", event_data.promise().name); + } else { + assertEquals("p3", event_data.promise().name); + } + assertTrue(event_data.uncaught()); + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } +} + +Debug.setBreakOnUncaughtException(); +Debug.setListener(listener); + +log.push("end main"); + +function testDone(iteration) { + function checkResult() { + try { + assertTrue(iteration < 10); + if (expected_events === 0) { + assertEquals(["end main", "throw"], log); + } else { + testDone(iteration + 1); + } + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } + } + + %EnqueueMicrotask(checkResult); +} + +testDone(0); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/promise-race-caught.js b/deps/v8/test/mjsunit/es6/debug-promises/promise-race-caught.js new file mode 100644 index 0000000000..dd3ca83ee8 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/promise-race-caught.js @@ -0,0 +1,40 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug --allow-natives-syntax + +// Test debug events when we only listen to uncaught exceptions and a +// Promise p3 created by Promise.race has a catch handler, and is rejected +// because one of the Promises p2 passed to Promise.all is rejected. We +// expect no Exception debug event to be triggered, since p3 and by +// extension p2 have a catch handler. + +var Debug = debug.Debug; + +var expected_events = 2; + +var p1 = Promise.resolve(); +p1.name = "p1"; + +var p2 = p1.then(function() { + throw new Error("caught"); +}); + +p2.name = "p2"; + +var p3 = Promise.all([p2]); +p3.name = "p3"; + +p3.catch(function(e) {}); + +function listener(event, exec_state, event_data, data) { + try { + assertTrue(event != Debug.DebugEvent.Exception) + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } +} + +Debug.setBreakOnUncaughtException(); +Debug.setListener(listener); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/promise-race-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/promise-race-uncaught.js new file mode 100644 index 0000000000..57955c01ef --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/promise-race-uncaught.js @@ -0,0 +1,73 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug --allow-natives-syntax + +// Test debug events when we only listen to uncaught exceptions and a +// Promise p3 created by Promise.race has no catch handler, and is rejected +// because one of the Promises p2 passed to Promise.all is rejected. We +// expect two Exception debug events to be triggered, for p2 and p3 each, +// because neither has an user-defined catch handler. + +var Debug = debug.Debug; + +var expected_events = 2; +var log = []; + +var p1 = Promise.resolve(); +p1.name = "p1"; + +var p2 = p1.then(function() { + log.push("throw"); + throw new Error("uncaught"); // event +}); + +p2.name = "p2"; + +var p3 = Promise.race([p2]); +p3.name = "p3"; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + expected_events--; + assertTrue(expected_events >= 0); + assertEquals("uncaught", event_data.exception().message); + assertTrue(event_data.promise() instanceof Promise); + if (expected_events === 1) { + // Assert that the debug event is triggered at the throw site. + assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); + assertEquals("p2", event_data.promise().name); + } else { + assertEquals("p3", event_data.promise().name); + } + assertTrue(event_data.uncaught()); + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } +} + +Debug.setBreakOnUncaughtException(); +Debug.setListener(listener); + +log.push("end main"); + +function testDone(iteration) { + function checkResult() { + try { + assertTrue(iteration < 10); + if (expected_events === 0) { + assertEquals(["end main", "throw"], log); + } else { + testDone(iteration + 1); + } + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } + } + + %EnqueueMicrotask(checkResult); +} + +testDone(0); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js b/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js new file mode 100644 index 0000000000..4f3891b187 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js @@ -0,0 +1,47 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug + +var Debug = debug.Debug; +var exception = null; +var breaks = []; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + breaks.push(exec_state.frame(0).sourceLineText().trimLeft()); + exec_state.prepareStep(Debug.StepAction.StepIn, 1); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +function resolver(resolve, reject) { + 1; + 2; + 3; + resolve(); +} + +debugger; +var p = new Promise(resolver); + +Debug.setListener(null); + +var expected_breaks = [ + "debugger;", + "var p = new Promise(resolver);", + "1;", + "2;", + "3;", + "resolve();", + "}", + "Debug.setListener(null);" +]; + +assertEquals(expected_breaks, breaks); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/es6/debug-stepin-promises.js b/deps/v8/test/mjsunit/es6/debug-promises/stepin-handler.js index 8548a2badd..8548a2badd 100644 --- a/deps/v8/test/mjsunit/es6/debug-stepin-promises.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/stepin-handler.js diff --git a/deps/v8/test/mjsunit/es6/debug-step-into-constructor.js b/deps/v8/test/mjsunit/es6/debug-step-into-constructor.js index 66fc0b99d0..1e903256fd 100644 --- a/deps/v8/test/mjsunit/es6/debug-step-into-constructor.js +++ b/deps/v8/test/mjsunit/es6/debug-step-into-constructor.js @@ -14,7 +14,6 @@ function listener(event, execState, eventData, data) { if (!done) { execState.prepareStep(Debug.StepAction.StepInto); var s = execState.frame().sourceLineText(); - print(s); assertTrue(s.indexOf('// ' + stepCount + '.') !== -1); stepCount++; } @@ -41,7 +40,7 @@ class Derived extends Base {} var bp = Debug.setBreakPoint(Base, 0); new Base(); - assertEquals(5, stepCount); + assertEquals(1, stepCount); Debug.clearBreakPoint(bp); })(); @@ -53,7 +52,7 @@ class Derived extends Base {} var bp = Debug.setBreakPoint(Base, 0); new Derived(); - assertEquals(5, stepCount); + assertEquals(1, stepCount); Debug.clearBreakPoint(bp); })(); @@ -69,7 +68,7 @@ class Derived extends Base {} var bp = Debug.setBreakPoint(f, 0); f(); - assertEquals(5, stepCount); + assertEquals(1, stepCount); Debug.clearBreakPoint(bp); })(); @@ -87,7 +86,7 @@ class Derived extends Base {} var bp = Debug.setBreakPoint(f, 0); f(); - assertEquals(5, stepCount); + assertEquals(1, stepCount); Debug.clearBreakPoint(bp); })(); @@ -105,7 +104,7 @@ class Derived extends Base {} var bp = Debug.setBreakPoint(f, 0); f(); - assertEquals(5, stepCount); + assertEquals(1, stepCount); Debug.clearBreakPoint(bp); })(); diff --git a/deps/v8/test/mjsunit/es6/for-of.js b/deps/v8/test/mjsunit/es6/for-of.js new file mode 100644 index 0000000000..b123bba5f6 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/for-of.js @@ -0,0 +1,24 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function TestForOfName() { + var result = 0; + var index; + + for (index of [1, 2, 3, 4, 5]) result += index; + + assertEquals(result, 15); + assertEquals(index, 5); +})(); + + +(function TestForOfProperty() { + var O = {}; + var result = 0; + + for (O.index of [1, 2, 3, 4, 5]) result += O.index; + + assertEquals(result, 15); + assertEquals(O.index, 5); +})(); diff --git a/deps/v8/test/mjsunit/es6/math-hyperbolic.js b/deps/v8/test/mjsunit/es6/math-hyperbolic.js index 8970f6ef65..29a419d1bd 100644 --- a/deps/v8/test/mjsunit/es6/math-hyperbolic.js +++ b/deps/v8/test/mjsunit/es6/math-hyperbolic.js @@ -186,3 +186,21 @@ assertEquals(1.7976931348621744e308, Math.cosh(-710.4758600739439)); // Overflow. assertEquals(Infinity, Math.cosh(710.475860073944)); assertEquals(Infinity, Math.cosh(-710.475860073944)); + +// Implementation-specific tests for tanh. +// Case |x| < 2^-55 +var two_56 = Math.pow(2, -56); +assertEquals(two_56, Math.tanh(two_56)); +assertEquals(-two_56, Math.tanh(-two_56)); +// Case |x| < 1 +assertEquals(0.6, Math.tanh(Math.LN2)); +assertEquals(-0.6, Math.tanh(-Math.LN2)); +// Case 1 < |x| < 22 +assertEquals(15/17, Math.tanh(2 * Math.LN2)); +assertEquals(-15/17, Math.tanh(-2 * Math.LN2)); +// Case |x| > 22 +assertEquals(1, Math.tanh(100)); +assertEquals(-1, Math.tanh(-100)); +// Test against overflow +assertEquals(1, Math.tanh(1e300)); +assertEquals(-1, Math.tanh(-1e300)); diff --git a/deps/v8/test/mjsunit/harmony/new-target.js b/deps/v8/test/mjsunit/es6/new-target.js index d98f5f8098..9ecff815fa 100644 --- a/deps/v8/test/mjsunit/harmony/new-target.js +++ b/deps/v8/test/mjsunit/es6/new-target.js @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-new-target --harmony-reflect --harmony-destructuring -// Flags: --harmony-rest-parameters --harmony-arrow-functions +// Flags: --harmony-reflect --harmony-destructuring --harmony-rest-parameters (function TestClass() { @@ -386,6 +385,23 @@ })(); +// Has to be top-level to be inlined. +function get_new_target() { return new.target; } +(function TestInlining() { + "use strict"; + new function() { assertEquals(undefined, get_new_target()); } + new function() { assertEquals(get_new_target, new get_new_target()); } + + class A extends get_new_target { + constructor() { + var new_target = super(); + this.new_target = new_target; + } + } + assertEquals(A, new A().new_target); +})(); + + (function TestEarlyErrors() { assertThrows(function() { Function("new.target = 42"); }, ReferenceError); assertThrows(function() { Function("var foo = 1; new.target = foo = 42"); }, ReferenceError); diff --git a/deps/v8/test/mjsunit/harmony/object-literals-super.js b/deps/v8/test/mjsunit/es6/object-literals-super.js index c6fb6334de..b31a498767 100644 --- a/deps/v8/test/mjsunit/harmony/object-literals-super.js +++ b/deps/v8/test/mjsunit/es6/object-literals-super.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions --allow-natives-syntax +// Flags: --allow-natives-syntax (function TestHomeObject() { diff --git a/deps/v8/test/mjsunit/es6/promises.js b/deps/v8/test/mjsunit/es6/promises.js index 405da02b53..341242f8d9 100644 --- a/deps/v8/test/mjsunit/es6/promises.js +++ b/deps/v8/test/mjsunit/es6/promises.js @@ -1011,9 +1011,9 @@ function assertAsyncDone(iteration) { log = "" var p4 = MyPromise.resolve(4) var p5 = MyPromise.reject(5) - assertTrue(p4 instanceof Promise, "subclass/instance4") + assertTrue(p4 instanceof MyPromise, "subclass/instance4") assertTrue(p4 instanceof MyPromise, "subclass/instance-my4") - assertTrue(p5 instanceof Promise, "subclass/instance5") + assertTrue(p5 instanceof MyPromise, "subclass/instance5") assertTrue(p5 instanceof MyPromise, "subclass/instance-my5") d3.resolve(3) assertTrue(log === "nx4nr5x3", "subclass/resolve") @@ -1028,12 +1028,35 @@ function assertAsyncDone(iteration) { log = "" Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) - assertTrue(log === "nx14n", "subclass/all/arg") + + assertTrue(log === "nx14", "subclass/all/arg") log = "" MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) - assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") + assertTrue(log === "nx24nnx21nnnnx23nnnx25nnx26n", "subclass/all/self") })(); +(function() { + 'use strict'; + + class Pact extends Promise { } + class Vow extends Pact { } + class Oath extends Vow { } + + Oath.constructor = Vow; + + assertTrue(Pact.resolve(Pact.resolve()).constructor === Pact, + "subclass/resolve/own"); + + assertTrue(Pact.resolve(Promise.resolve()).constructor === Pact, + "subclass/resolve/ancestor"); + + assertTrue(Pact.resolve(Vow.resolve()).constructor === Pact, + "subclass/resolve/descendant"); var vow = Vow.resolve(); + + vow.constructor = Oath; + assertTrue(Oath.resolve(vow) === vow, + "subclass/resolve/descendant with transplanted own constructor"); +}()); assertAsyncDone() diff --git a/deps/v8/test/mjsunit/es6/regexp-flags.js b/deps/v8/test/mjsunit/es6/regexp-flags.js new file mode 100644 index 0000000000..98070fb735 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regexp-flags.js @@ -0,0 +1,64 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-regexps --harmony-unicode-regexps + +var r1 = /abc/gi; +assertEquals("abc", r1.source); +assertTrue(r1.global); +assertTrue(r1.ignoreCase); +assertFalse(r1.multiline); +assertFalse(r1.sticky); +assertFalse(r1.unicode); + +// Internal slot of prototype is not read. +var r2 = { __proto__: r1 }; +assertThrows(function() { r2.source; }, TypeError); +assertThrows(function() { r2.global; }, TypeError); +assertThrows(function() { r2.ignoreCase; }, TypeError); +assertThrows(function() { r2.multiline; }, TypeError); +assertThrows(function() { r2.sticky; }, TypeError); +assertThrows(function() { r2.unicode; }, TypeError); + +var r3 = /I/; +var string = "iIiIi"; +var expected = "iXiIi"; +assertFalse(r3.global); +assertFalse(r3.ignoreCase); +assertEquals("", r3.flags); +assertEquals(expected, string.replace(r3, "X")); + +var get_count = 0; +Object.defineProperty(r3, "global", { + get: function() { get_count++; return true; } +}); +Object.defineProperty(r3, "ignoreCase", { + get: function() { get_count++; return true; } +}); + +assertTrue(r3.global); +assertEquals(1, get_count); +assertTrue(r3.ignoreCase); +assertEquals(2, get_count); +// Overridden flag getters affects the flags getter. +assertEquals("gi", r3.flags); +assertEquals(4, get_count); +// Overridden flag getters do not affect the internal flags. +assertEquals(expected, string.replace(r3, "X")); +assertEquals(4, get_count); + + +function testName(name) { + assertThrows(() => RegExp.prototype[name], TypeError); + assertEquals( + "get " + name, + Object.getOwnPropertyDescriptor(RegExp.prototype, name).get.name); +} + +testName("global"); +testName("ignoreCase"); +testName("multiline"); +testName("source"); +testName("sticky"); +testName("unicode"); diff --git a/deps/v8/test/mjsunit/es6/regexp-match-lastindex.js b/deps/v8/test/mjsunit/es6/regexp-match-lastindex.js new file mode 100644 index 0000000000..71cf90df66 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regexp-match-lastindex.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Tests that lastIndex of a global RegExp is overwritten as per +// ECMA-262 6.0 21.2.5.6 step 8.c. + +var global = /./g; +global.lastIndex = { valueOf: function() { assertUnreachable(); } }; +"x".match(global); +assertEquals(0, global.lastIndex); diff --git a/deps/v8/test/mjsunit/es6/regexp-prototype.js b/deps/v8/test/mjsunit/es6/regexp-prototype.js new file mode 100644 index 0000000000..673be4b97e --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regexp-prototype.js @@ -0,0 +1,17 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// ES6 21.2.4.1 +var proto_desc = Object.getOwnPropertyDescriptor(RegExp, "prototype"); +assertFalse(proto_desc.writable); +assertFalse(proto_desc.enumerable); +assertFalse(proto_desc.configurable); + +// ES6 21.2.5.1 +var proto = proto_desc.value; +assertFalse(proto instanceof RegExp); +assertEquals(undefined, Object.getOwnPropertyDescriptor(proto, "valueOf")); +assertEquals(proto.valueOf, Object.prototype.valueOf); +var proto_constr = Object.getOwnPropertyDescriptor(proto, "constructor"); +assertEquals(RegExp, proto_constr.value); diff --git a/deps/v8/test/mjsunit/es6/regexp-replace-lastindex.js b/deps/v8/test/mjsunit/es6/regexp-replace-lastindex.js new file mode 100644 index 0000000000..08217e6389 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regexp-replace-lastindex.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Tests that lastIndex of a global RegExp is overwritten as per +// ECMA-262 6.0 21.2.5.8 step 10.c. + +var global = /./g; +global.lastIndex = { valueOf: function() { assertUnreachable(); } }; +assertEquals("X", "x".replace(global, function(a) { return "X"; })); +assertEquals(0, global.lastIndex); diff --git a/deps/v8/test/mjsunit/es6/regexp-tolength.js b/deps/v8/test/mjsunit/es6/regexp-tolength.js new file mode 100644 index 0000000000..d9e967ba27 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regexp-tolength.js @@ -0,0 +1,19 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-tolength + +'use strict'; + +let regexp = /x/g; + +regexp.lastIndex = -1; + +assertTrue(regexp.test("axb")); +assertEquals(2, regexp.lastIndex); + +regexp.lastIndex = -1; + +assertEquals("x", regexp.exec("axb")[0]); +assertEquals(2, regexp.lastIndex); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-3501.js b/deps/v8/test/mjsunit/es6/regress/regress-3501.js index 4b449e458f..82920e0d0e 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-3501.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-3501.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - // See: http://code.google.com/p/v8/issues/detail?id=3501 "use strict"; diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4056.js b/deps/v8/test/mjsunit/es6/regress/regress-4056.js index d938df0be0..f80aa9fe71 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4056.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-4056.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - function strictFunctionArrowEval(s) { "use strict"; return (()=>eval(s))(); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4160.js b/deps/v8/test/mjsunit/es6/regress/regress-4160.js index b02daeed40..d5dd27022d 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4160.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-4160.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions --allow-natives-syntax +// Flags: --allow-natives-syntax (function(x) { (function(x) { diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4298.js b/deps/v8/test/mjsunit/es6/regress/regress-4298.js index 98e69d1acf..c4fe519138 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4298.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-4298.js @@ -1,8 +1,6 @@ // Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// Flags: --harmony-spread-arrays var arr = [1, 2, ...[3]]; assertEquals([1, 2, 3], arr); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4417.js b/deps/v8/test/mjsunit/es6/regress/regress-4417.js index fb773f5fac..b98c5b9b77 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4417.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-4417.js @@ -1,8 +1,6 @@ // Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// Flags: --harmony-spread-arrays var arr = [1, 2, 3]; assertEquals({arr: [1, 2, 3]}, {arr: [...arr]}); diff --git a/deps/v8/test/mjsunit/es6/regress/regress-4466.js b/deps/v8/test/mjsunit/es6/regress/regress-4466.js new file mode 100644 index 0000000000..144eef11d6 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regress/regress-4466.js @@ -0,0 +1,26 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +"use strict"; + +class Parent { + parentMethod(x, y) { + assertEquals(42, x); + assertEquals('hello world', y); + } +} + +class Child extends Parent { + method(x) { + let outer = (y) => { + let inner = () => { + super.parentMethod(x, y); + }; + inner(); + }; + outer('hello world'); + } +} + +new Child().method(42); diff --git a/deps/v8/test/mjsunit/es6/regress/regress-4522.js b/deps/v8/test/mjsunit/es6/regress/regress-4522.js new file mode 100644 index 0000000000..b71797c943 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/regress/regress-4522.js @@ -0,0 +1,19 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +"use strict"; + +class C { + foo() { + return 42; + } +} + +class D extends C { + foo() { + return (() => eval("super.foo()"))(); + } +} + +assertEquals(42, new D().foo()); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-arrow-duplicate-params.js b/deps/v8/test/mjsunit/es6/regress/regress-arrow-duplicate-params.js index a43f022c02..725832a8c4 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-arrow-duplicate-params.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-arrow-duplicate-params.js @@ -2,6 +2,4 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - assertThrows("(x, x, y) => 10;", SyntaxError); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-465671-null.js b/deps/v8/test/mjsunit/es6/regress/regress-crbug-465671-null.js index d24599c385..28fc56605a 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-465671-null.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-crbug-465671-null.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - // This used to trigger a segfault because of NULL being accessed. function f() { var a = [10]; diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-465671.js b/deps/v8/test/mjsunit/es6/regress/regress-crbug-465671.js index 24f4d05475..287df0d41e 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-465671.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-crbug-465671.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions - // This used to trigger crash because of an unhandled stack overflow. function f() { var a = [10]; diff --git a/deps/v8/test/mjsunit/harmony/spread-array.js b/deps/v8/test/mjsunit/es6/spread-array.js index 18b72a28c5..d112422b78 100644 --- a/deps/v8/test/mjsunit/harmony/spread-array.js +++ b/deps/v8/test/mjsunit/es6/spread-array.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-spread-arrays --allow-natives-syntax +// Flags: --allow-natives-syntax (function TestBasics() { var a = [1, 2]; diff --git a/deps/v8/test/mjsunit/harmony/spread-call-new-class.js b/deps/v8/test/mjsunit/es6/spread-call-new-class.js index ed95e6cad7..fc4770de7c 100644 --- a/deps/v8/test/mjsunit/harmony/spread-call-new-class.js +++ b/deps/v8/test/mjsunit/es6/spread-call-new-class.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-spread-calls --harmony-sloppy --harmony-rest-parameters +// Flags: --harmony-sloppy --harmony-rest-parameters (function testConstructClassStrict() { diff --git a/deps/v8/test/mjsunit/harmony/spread-call-new.js b/deps/v8/test/mjsunit/es6/spread-call-new.js index 4ae115e791..bb14dbdabb 100644 --- a/deps/v8/test/mjsunit/harmony/spread-call-new.js +++ b/deps/v8/test/mjsunit/es6/spread-call-new.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-spread-calls - (function testNonConstructorStrict() { "use strict"; assertThrows(function() { diff --git a/deps/v8/test/mjsunit/harmony/spread-call-super-property.js b/deps/v8/test/mjsunit/es6/spread-call-super-property.js index cc6cf849bd..b7326294fe 100644 --- a/deps/v8/test/mjsunit/harmony/spread-call-super-property.js +++ b/deps/v8/test/mjsunit/es6/spread-call-super-property.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-spread-calls --harmony-sloppy --harmony-rest-parameters +// Flags: --harmony-sloppy --harmony-rest-parameters (function testCallSuperPropertyStrict() { "use strict"; diff --git a/deps/v8/test/mjsunit/harmony/spread-call.js b/deps/v8/test/mjsunit/es6/spread-call.js index 7c19ec1ef1..05e17741d6 100644 --- a/deps/v8/test/mjsunit/harmony/spread-call.js +++ b/deps/v8/test/mjsunit/es6/spread-call.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-spread-calls - (function testSpreadCallsStrict() { "use strict" function countArgs() { return arguments.length; } diff --git a/deps/v8/test/mjsunit/harmony/super.js b/deps/v8/test/mjsunit/es6/super.js index d74484ea04..f93b259fd2 100644 --- a/deps/v8/test/mjsunit/harmony/super.js +++ b/deps/v8/test/mjsunit/es6/super.js @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions --allow-natives-syntax -// Flags: --harmony-spread-calls --harmony-destructuring -// Flags: --harmony-rest-parameters --harmony-sloppy +// Flags: --allow-natives-syntax +// Flags: --harmony-destructuring --harmony-rest-parameters --harmony-sloppy (function TestSuperNamedLoads() { function Base() { } @@ -940,62 +939,40 @@ mSloppy() { assertEquals(42, this.ownReadOnly); super.ownReadOnly = 55; - assertEquals(55, this.ownReadOnly); - var descr = Object.getOwnPropertyDescriptor(this, 'ownReadOnly'); - assertEquals(55, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertFalse(descr.writable); + assertSame(undefined, super.ownReadOnly); + assertEquals(42, this.ownReadOnly); assertFalse(Base.prototype.hasOwnProperty('ownReadOnly')); assertEquals(15, this.ownReadonlyAccessor); super.ownReadonlyAccessor = 25; - assertEquals(25, this.ownReadonlyAccessor); - var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); - assertEquals(25, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertSame(undefined, super.ownReadonlyAccessor); + assertEquals(15, this.ownReadonlyAccessor); assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); super.ownSetter = 35; - assertEquals(35, this.ownSetter); + assertSame(undefined, super.ownSetter); var descr = Object.getOwnPropertyDescriptor(this, 'ownSetter'); - assertEquals(35, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertTrue('set' in descr); assertFalse(Base.prototype.hasOwnProperty('ownSetter')); }, mStrict() { 'use strict'; assertEquals(42, this.ownReadOnly); - super.ownReadOnly = 55; - assertEquals(55, this.ownReadOnly); - var descr = Object.getOwnPropertyDescriptor(this, 'ownReadOnly'); - assertEquals(55, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertFalse(descr.writable); + assertThrows(() => {super.ownReadOnly = 55}, TypeError); + assertSame(undefined, super.ownReadOnly); + assertEquals(42, this.ownReadOnly); assertFalse(Base.prototype.hasOwnProperty('ownReadOnly')); assertEquals(15, this.ownReadonlyAccessor); - super.ownReadonlyAccessor = 25; - assertEquals(25, this.ownReadonlyAccessor); - var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); - assertEquals(25, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertThrows(() => {super.ownReadonlyAccessor = 25}, TypeError); + assertSame(undefined, super.ownReadonlyAccessor); + assertEquals(15, this.ownReadonlyAccessor); assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); - super.ownSetter = 35; - assertEquals(35, this.ownSetter); + assertThrows(() => {super.ownSetter = 35}, TypeError); + assertSame(undefined, super.ownSetter); var descr = Object.getOwnPropertyDescriptor(this, 'ownSetter'); - assertEquals(35, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertTrue('set' in descr); assertFalse(Base.prototype.hasOwnProperty('ownSetter')); }, }; @@ -1053,6 +1030,7 @@ assertEquals(15, this.ownReadonlyAccessor); super.ownReadonlyAccessor = 25; + assertSame(undefined, super.ownReadonlyAccessor); assertEquals(15, this.ownReadonlyAccessor); var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); assertFalse(descr.configurable); @@ -1076,7 +1054,7 @@ } assertInstanceof(ex, TypeError); assertEquals( - "Cannot assign to read only property 'ownReadOnly' of #<Base>", + "Cannot assign to read only property 'ownReadOnly' of object '#<Base>'", ex.message); assertEquals(42, this.ownReadOnly); @@ -1181,62 +1159,40 @@ function TestKeyedSetterCreatingOwnPropertiesReconfigurable(ownReadOnly, mSloppy() { assertEquals(42, this[ownReadOnly]); super[ownReadOnly] = 55; - assertEquals(55, this[ownReadOnly]); - var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); - assertEquals(55, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertFalse(descr.writable); + assertSame(undefined, super[ownReadOnly]); + assertEquals(42, this[ownReadOnly]); assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); assertEquals(15, this[ownReadonlyAccessor]); super[ownReadonlyAccessor] = 25; - assertEquals(25, this[ownReadonlyAccessor]); - var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); - assertEquals(25, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertSame(undefined, super[ownReadonlyAccessor]); + assertEquals(15, this[ownReadonlyAccessor]); assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); super[ownSetter] = 35; - assertEquals(35, this[ownSetter]); + assertSame(undefined, super[ownSetter]); var descr = Object.getOwnPropertyDescriptor(this, ownSetter); - assertEquals(35, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertTrue('set' in descr); assertFalse(Base.prototype.hasOwnProperty(ownSetter)); }, mStrict() { 'use strict'; assertEquals(42, this[ownReadOnly]); - super[ownReadOnly] = 55; - assertEquals(55, this[ownReadOnly]); - var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); - assertEquals(55, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertFalse(descr.writable); + assertThrows(() => {super[ownReadOnly] = 55}, TypeError); + assertSame(undefined, super[ownReadOnly]); + assertEquals(42, this[ownReadOnly]); assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); assertEquals(15, this[ownReadonlyAccessor]); - super[ownReadonlyAccessor] = 25; - assertEquals(25, this[ownReadonlyAccessor]); - var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); - assertEquals(25, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertThrows(() => {super[ownReadonlyAccessor] = 25}, TypeError); + assertSame(undefined, super[ownReadonlyAccessor]); + assertEquals(15, this[ownReadonlyAccessor]); assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); - super[ownSetter] = 35; - assertEquals(35, this[ownSetter]); + assertThrows(() => {super[ownSetter] = 35}, TypeError); + assertSame(undefined, super[ownSetter]); var descr = Object.getOwnPropertyDescriptor(this, ownSetter); - assertEquals(35, descr.value); - assertTrue(descr.configurable); - assertFalse(descr.enumerable); - assertTrue(descr.writable); + assertTrue('set' in descr); assertFalse(Base.prototype.hasOwnProperty(ownSetter)); }, }; @@ -1299,6 +1255,7 @@ function TestKeyedSetterCreatingOwnPropertiesNonConfigurable( assertEquals(15, this[ownReadonlyAccessor]); super[ownReadonlyAccessor] = 25; + assertSame(undefined, super[ownReadonlyAccessor]); assertEquals(15, this[ownReadonlyAccessor]); var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); assertFalse(descr.configurable); @@ -1323,7 +1280,7 @@ function TestKeyedSetterCreatingOwnPropertiesNonConfigurable( assertInstanceof(ex, TypeError); assertEquals( "Cannot assign to read only property '" + ownReadOnly + - "' of #<Base>", + "' of object '#<Base>'", ex.message); assertEquals(42, this[ownReadOnly]); @@ -2021,8 +1978,8 @@ TestKeyedSetterCreatingOwnPropertiesNonConfigurable(42, 43, 44); class F extends Object { } var f = new F(42); - // TODO(dslomov,arv): Fix this. BUG=v8:3886. - assertInstanceof(f, Number); + assertInstanceof(f, F); + assertInstanceof(f, Object); }()); diff --git a/deps/v8/test/mjsunit/es6/symbols.js b/deps/v8/test/mjsunit/es6/symbols.js index 05601bd75e..58142cf27f 100644 --- a/deps/v8/test/mjsunit/es6/symbols.js +++ b/deps/v8/test/mjsunit/es6/symbols.js @@ -167,8 +167,8 @@ function TestEquality() { assertTrue(symbols[i] == symbols[i]) assertFalse(symbols[i] === Object(symbols[i])) assertFalse(Object(symbols[i]) === symbols[i]) - assertFalse(symbols[i] == Object(symbols[i])) - assertFalse(Object(symbols[i]) == symbols[i]) + assertTrue(symbols[i] == Object(symbols[i])) + assertTrue(Object(symbols[i]) == symbols[i]) assertTrue(symbols[i] === symbols[i].valueOf()) assertTrue(symbols[i].valueOf() === symbols[i]) assertTrue(symbols[i] == symbols[i].valueOf()) diff --git a/deps/v8/test/mjsunit/es6/typedarray.js b/deps/v8/test/mjsunit/es6/typedarray.js index 7b1cc06e1c..a45b6308f3 100644 --- a/deps/v8/test/mjsunit/es6/typedarray.js +++ b/deps/v8/test/mjsunit/es6/typedarray.js @@ -563,10 +563,9 @@ function TestTypedArraysWithIllegalIndices() { assertEquals(255, a[s2]); assertEquals(0, a[-0]); - /* Chromium bug: 424619 - * a[-Infinity] = 50; - * assertEquals(undefined, a[-Infinity]); - */ + a[-Infinity] = 50; + assertEquals(undefined, a[-Infinity]); + a[1.5] = 10; assertEquals(undefined, a[1.5]); var nan = Math.sqrt(-1); diff --git a/deps/v8/test/mjsunit/for-in-opt.js b/deps/v8/test/mjsunit/for-in-opt.js index 67ef2d870e..a6ee0ec81e 100644 --- a/deps/v8/test/mjsunit/for-in-opt.js +++ b/deps/v8/test/mjsunit/for-in-opt.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-proxies --allow-natives-syntax +// Flags: --harmony-proxies --allow-natives-syntax --expose-debug-as debug "use strict"; @@ -84,3 +84,77 @@ f3({__proto__:{x:1}}); %OptimizeFunctionOnNextCall(f3); f3(undefined); f3(null); + +// Reliable repro for an issue previously flushed out by GC stress. +var handler2 = { + getPropertyDescriptor: function(k) { + has_keys.push(k); + return {value: 10, configurable: true, writable: false, enumerable: true}; + } +} +var proxy2 = Proxy.create(handler2); +var o2 = {__proto__: proxy2}; +var p = {x: "x"} + +function f4(o, p) { + var result = []; + for (var i in o) { + var j = p.x + "str"; + result.push(i); + } + return result; +} +function check_f4() { + assertEquals(keys, f4(o, p)); + assertEquals(keys, has_keys); + has_keys.length = 0; +} +check_f4(); +check_f4(); +%OptimizeFunctionOnNextCall(f4); +p.y = "y"; // Change map, cause eager deopt. +check_f4(); + +// Repro for Turbofan equivalent. +var x; +var count = 0; + +var Debug = debug.Debug; + +function listener(event, exec_state, event_data, data) { + if (event == Debug.DebugEvent.Break) { + %DeoptimizeFunction(f5); + } +} + +var handler3 = { + enumerate: function(target) { + return ["a", "b"]; + }, + + getPropertyDescriptor: function(k) { + if (k == "a") count++; + if (x) %ScheduleBreak(); + return {value: 10, configurable: true, writable: false, enumerable: true}; + } +}; + +var proxy3 = Proxy.create(handler3); +var o3 = {__proto__: proxy3}; + +function f5() { + for (var p in o3) { + print(p); + } +} + +x = false; + +f5(); f5(); f5(); +%OptimizeFunctionOnNextCall(f5); +x = true; +count = 0; +Debug.setListener(listener); +f5(); +Debug.setListener(null); +assertEquals(1, count); diff --git a/deps/v8/test/mjsunit/regress/regress-1217.js b/deps/v8/test/mjsunit/global-properties.js index e00d5371ad..28e3e8f9cb 100644 --- a/deps/v8/test/mjsunit/regress/regress-1217.js +++ b/deps/v8/test/mjsunit/global-properties.js @@ -1,4 +1,4 @@ -// Copyright 2011 the V8 project authors. All rights reserved. +// Copyright 2010 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: @@ -25,26 +25,44 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Check that RegExp.prototype is itself a RegExp object. +var global = this; -var proto = RegExp.prototype; -assertEquals("[object RegExp]", Object.prototype.toString.call(proto)); +function testNamedProperty(key, value) { + global[key] = value; + assertTrue(global.hasOwnProperty(key)); + assertTrue(-1 < Object.keys(global).indexOf(key)); + assertTrue(-1 < Object.getOwnPropertyNames(global).indexOf(key)); + assertTrue(-1 == Object.getOwnPropertySymbols(global).indexOf(key)); +} -assertEquals("(?:)", proto.source); -assertEquals(false, proto.global); -assertEquals(false, proto.multiline); -assertEquals(false, proto.ignoreCase); -assertEquals(0, proto.lastIndex); +testNamedProperty('property0', 'value'); +testNamedProperty('0property', 'value'); +testNamedProperty('42', 'value'); -assertEquals("/(?:)/", proto.toString()); +function testNamedNonEnumerableProperty(key, value) { + Object.defineProperty(global, key, { + enumerable: false, + value: value + }); + assertTrue(global.hasOwnProperty(key)); + assertTrue(-1 == Object.keys(global).indexOf(key)); + assertTrue(-1 < Object.getOwnPropertyNames(global).indexOf(key)); + assertTrue(-1 == Object.getOwnPropertySymbols(global).indexOf(key)); +} -var execResult = proto.exec("argle"); -assertEquals(1, execResult.length); -assertEquals("", execResult[0]); -assertEquals("argle", execResult.input); -assertEquals(0, execResult.index); +testNamedNonEnumerableProperty('property1', 'value'); +testNamedNonEnumerableProperty('1property', 'value'); +testNamedNonEnumerableProperty('43', 'value'); -assertTrue(proto.test("argle")); +function testSymbolProperty(key, value) { + key = Symbol(key); + global[key] = value; + assertTrue(global.hasOwnProperty(key)); + assertTrue(-1 == Object.keys(global).indexOf(key)); + assertTrue(-1 == Object.getOwnPropertyNames(global).indexOf(key)); + assertTrue(-1 < Object.getOwnPropertySymbols(global).indexOf(key)); +} -// We disallow re-compiling the RegExp.prototype object. -assertThrows(function(){ proto.compile("something"); }, TypeError); +testSymbolProperty('property2', 'value'); +testSymbolProperty('2property', 'value'); +testSymbolProperty('43', 'value'); diff --git a/deps/v8/test/mjsunit/harmony/arrow-rest-params-lazy-parsing.js b/deps/v8/test/mjsunit/harmony/arrow-rest-params-lazy-parsing.js index 6e760fcb17..478603e746 100644 --- a/deps/v8/test/mjsunit/harmony/arrow-rest-params-lazy-parsing.js +++ b/deps/v8/test/mjsunit/harmony/arrow-rest-params-lazy-parsing.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-rest-parameters --harmony-arrow-functions +// Flags: --harmony-rest-parameters // Flags: --min-preparse-length=0 (function testRestIndex() { diff --git a/deps/v8/test/mjsunit/harmony/arrow-rest-params.js b/deps/v8/test/mjsunit/harmony/arrow-rest-params.js index 0ee77390ed..3cb7adf92c 100644 --- a/deps/v8/test/mjsunit/harmony/arrow-rest-params.js +++ b/deps/v8/test/mjsunit/harmony/arrow-rest-params.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-rest-parameters --harmony-arrow-functions +// Flags: --harmony-rest-parameters (function testRestIndex() { assertEquals(5, ((...args) => args.length)(1,2,3,4,5)); diff --git a/deps/v8/test/mjsunit/harmony/block-eval-var-over-legacy-const.js b/deps/v8/test/mjsunit/harmony/block-eval-var-over-legacy-const.js new file mode 100644 index 0000000000..0eb8456433 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/block-eval-var-over-legacy-const.js @@ -0,0 +1,109 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function + +// Var-let conflict in a function throws, even if the var is in an eval + +let caught = false; + +// Throws at the top level of a function +try { + (function() { + let x = 1; + eval('const x = 2'); + })() +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the eval is in its own block scope, throws +caught = false; +try { + (function() { + let y = 1; + { eval('const y = 2'); } + })() +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the let is in its own block scope, with the eval, throws +caught = false +try { + (function() { + { + let x = 1; + eval('const x = 2'); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Legal if the let is no longer visible +caught = false +try { + (function() { + { + let x = 1; + } + eval('const x = 2'); + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// In global scope +caught = false; +try { + let z = 1; + eval('const z = 2'); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Let declarations beyond a function boundary don't conflict +caught = false; +try { + let a = 1; + (function() { + eval('const a'); + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// var across with doesn't conflict +caught = false; +try { + (function() { + with ({x: 1}) { + eval("const x = 2;"); + } + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// var can still conflict with let across a with +caught = false; +try { + (function() { + let x; + with ({x: 1}) { + eval("const x = 2;"); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); diff --git a/deps/v8/test/mjsunit/harmony/block-eval-var-over-let.js b/deps/v8/test/mjsunit/harmony/block-eval-var-over-let.js new file mode 100644 index 0000000000..292d073c81 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/block-eval-var-over-let.js @@ -0,0 +1,191 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function --no-legacy-const + +// Var-let conflict in a function throws, even if the var is in an eval + +let caught = false; + +// Throws at the top level of a function +try { + (function() { + let x = 1; + eval('var x = 2'); + })() +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the eval is in its own block scope, throws +caught = false; +try { + (function() { + let y = 1; + { eval('var y = 2'); } + })() +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the let is in its own block scope, with the eval, throws +caught = false +try { + (function() { + { + let x = 1; + eval('var x = 2'); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Legal if the let is no longer visible +caught = false +try { + (function() { + { + let x = 1; + } + eval('var x = 2'); + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// All the same works for const: +// Throws at the top level of a function +try { + (function() { + const x = 1; + eval('var x = 2'); + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the eval is in its own block scope, throws +caught = false; +try { + (function() { + const y = 1; + { eval('var y = 2'); } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// If the const is in its own block scope, with the eval, throws +caught = false +try { + (function() { + { + const x = 1; + eval('var x = 2'); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Legal if the const is no longer visible +caught = false +try { + (function() { + { + const x = 1; + } + eval('var x = 2'); + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// In global scope +caught = false; +try { + let z = 1; + eval('var z = 2'); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Let declarations beyond a function boundary don't conflict +caught = false; +try { + let a = 1; + (function() { + eval('var a'); + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// var across with doesn't conflict +caught = false; +try { + (function() { + with ({x: 1}) { + eval("var x = 2;"); + } + })(); +} catch (e) { + caught = true; +} +assertFalse(caught); + +// var can still conflict with let across a with +caught = false; +try { + (function() { + let x; + with ({x: 1}) { + eval("var x = 2;"); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// Functions declared in eval also conflict +caught = false +try { + (function() { + { + let x = 1; + eval('function x() {}'); + } + })(); +} catch (e) { + caught = true; +} +assertTrue(caught); + +// TODO(littledan): Hoisting x out of the block should be +// prevented in this case BUG(v8:4479) +caught = false +try { + (function() { + { + let x = 1; + eval('{ function x() {} }'); + } + })(); +} catch (e) { + caught = true; +} +// TODO(littledan): switch to assertTrue when bug is fixed +assertTrue(caught); diff --git a/deps/v8/test/mjsunit/harmony/block-for-sloppy.js b/deps/v8/test/mjsunit/harmony/block-for-sloppy.js index eee8e0b5cd..e9e960504b 100644 --- a/deps/v8/test/mjsunit/harmony/block-for-sloppy.js +++ b/deps/v8/test/mjsunit/harmony/block-for-sloppy.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --no-legacy-const --harmony-sloppy --harmony-sloppy-let +// Flags: --harmony-completion function props(x) { var array = []; @@ -190,10 +191,12 @@ assertEquals(undefined, eval("for (let i = 0; i < 10; i++) { continue; i; }")); assertEquals(0, eval("for (let i = 0; true;) { i; break; }")); assertEquals(0, eval("for (const i = 0; true;) { i; break; }")); assertEquals(9, eval("for (let i = 0; i < 10; i++) { i; continue; }")); -assertEquals(3, eval("for (let i = 0; true; i++) { i; if (i >= 3) break; }")); -assertEquals(2, eval("for (let i = 0; true; i++) { if (i >= 3) break; i; }")); assertEquals( - 2, eval("for (let i = 0; i < 10; i++) { if (i >= 3) continue; i; }")); + undefined, eval("for (let i = 0; true; i++) { i; if (i >= 3) break; }")); +assertEquals( + undefined, eval("for (let i = 0; true; i++) { if (i >= 3) break; i; }")); +assertEquals( + undefined, eval("for (let i = 0; i < 10; i++) { if (i >= 3) continue; i; }")); assertEquals(undefined, eval("foo: for (let i = 0; true;) { break foo; }")); assertEquals(undefined, eval("foo: for (const i = 0; true;) { break foo; }")); assertEquals(3, eval("foo: for (let i = 3; true;) { i; break foo; }")); diff --git a/deps/v8/test/mjsunit/harmony/block-let-contextual-sloppy.js b/deps/v8/test/mjsunit/harmony/block-let-contextual-sloppy.js index 9b3cc44c0d..a4c5aeb211 100644 --- a/deps/v8/test/mjsunit/harmony/block-let-contextual-sloppy.js +++ b/deps/v8/test/mjsunit/harmony/block-let-contextual-sloppy.js @@ -4,17 +4,19 @@ // Flags: --harmony-sloppy --harmony-sloppy-let --harmony-destructuring +// let is usable as a variable with var or legacy const, not let or ES6 const -{ - assertThrows(function() { return let; }, ReferenceError); - let let; +(function (){ + assertEquals(undefined, let); + + var let; let = 5; assertEquals(5, let); - { let let = 1; assertEquals(1, let); } + (function() { var let = 1; assertEquals(1, let); })(); assertEquals(5, let); -} +})(); assertThrows(function() { return let; }, ReferenceError); @@ -23,36 +25,36 @@ assertThrows(function() { return let; }, ReferenceError); for (let in [1, 2, 3, 4]) sum += Number(let); assertEquals(6, sum); - for (let let of [4, 5]) sum += let; + (function() { for (var let of [4, 5]) sum += let; })(); assertEquals(15, sum); - for (let let in [6]) sum += Number([6][let]); + (function() { for (var let in [6]) sum += Number([6][let]); })(); assertEquals(21, sum); for (let = 7; let < 8; let++) sum += let; assertEquals(28, sum); assertEquals(8, let); - for (let let = 8; let < 9; let++) sum += let; + (function() { for (var let = 8; let < 9; let++) sum += let; })(); assertEquals(36, sum); assertEquals(8, let); -})() +})(); assertThrows(function() { return let; }, ReferenceError); -{ +(function () { let obj = {}; - let {let} = {let() { return obj; }}; + var {let} = {let() { return obj; }}; let().x = 1; assertEquals(1, obj.x); -} +})(); -{ +(function () { let obj = {}; - let [let] = [function() { return obj; }]; + const [let] = [function() { return obj; }]; let().x = 1; assertEquals(1, obj.x); -} +})(); (function() { function let() { diff --git a/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js b/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js index c91a9fbf1c..36a07f111e 100644 --- a/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js +++ b/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js @@ -88,7 +88,6 @@ function f3(one) { for (var j = 0; j < 5; ++j) f3(1); %OptimizeFunctionOnNextCall(f3); f3(1); -assertTrue(%GetOptimizationStatus(f3) != 2); diff --git a/deps/v8/test/mjsunit/harmony/block-sloppy-function.js b/deps/v8/test/mjsunit/harmony/block-sloppy-function.js index a17a4c0799..ff895d5b8a 100644 --- a/deps/v8/test/mjsunit/harmony/block-sloppy-function.js +++ b/deps/v8/test/mjsunit/harmony/block-sloppy-function.js @@ -146,13 +146,6 @@ assertEquals(2, f()); })(); -// Test that hoisting from blocks doesn't happen in global scope -function globalUnhoisted() { return 0; } -{ - function globalUnhoisted() { return 1; } -} -assertEquals(0, globalUnhoisted()); - // Test that shadowing arguments is fine (function shadowArguments(x) { assertArrayEquals([1], arguments); @@ -201,3 +194,109 @@ assertThrows(function notInDefaultScope(x = y) { assertEquals('function', typeof y); assertEquals(x, undefined); }, ReferenceError); + +// Test that hoisting from blocks does happen in global scope +function globalHoisted() { return 0; } +{ + function globalHoisted() { return 1; } +} +assertEquals(1, globalHoisted()); + +// Also happens when not previously defined +assertEquals(undefined, globalUndefinedHoisted); +{ + function globalUndefinedHoisted() { return 1; } +} +assertEquals(1, globalUndefinedHoisted()); +var globalUndefinedHoistedDescriptor = + Object.getOwnPropertyDescriptor(this, "globalUndefinedHoisted"); +assertFalse(globalUndefinedHoistedDescriptor.configurable); +assertTrue(globalUndefinedHoistedDescriptor.writable); +assertTrue(globalUndefinedHoistedDescriptor.enumerable); +assertEquals(1, globalUndefinedHoistedDescriptor.value()); + +// When a function property is hoisted, it should be +// made enumerable. +// BUG(v8:4451) +Object.defineProperty(this, "globalNonEnumerable", { + value: false, + configurable: true, + writable: true, + enumerable: false +}); +eval("{function globalNonEnumerable() { return 1; }}"); +var globalNonEnumerableDescriptor + = Object.getOwnPropertyDescriptor(this, "globalNonEnumerable"); +// BUG(v8:4451): Should be made non-configurable +assertTrue(globalNonEnumerableDescriptor.configurable); +assertTrue(globalNonEnumerableDescriptor.writable); +// BUG(v8:4451): Should be made enumerable +assertFalse(globalNonEnumerableDescriptor.enumerable); +assertEquals(1, globalNonEnumerableDescriptor.value()); + +// When a function property is hoisted, it should be overwritten and +// made writable and overwritten, even if the property was non-writable. +Object.defineProperty(this, "globalNonWritable", { + value: false, + configurable: true, + writable: false, + enumerable: true +}); +eval("{function globalNonWritable() { return 1; }}"); +var globalNonWritableDescriptor + = Object.getOwnPropertyDescriptor(this, "globalNonWritable"); +// BUG(v8:4451): Should be made non-configurable +assertTrue(globalNonWritableDescriptor.configurable); +// BUG(v8:4451): Should be made writable +assertFalse(globalNonWritableDescriptor.writable); +assertFalse(globalNonEnumerableDescriptor.enumerable); +// BUG(v8:4451): Should be overwritten +assertEquals(false, globalNonWritableDescriptor.value); + +// Test that hoisting from blocks does happen in an eval +eval(` + function evalHoisted() { return 0; } + { + function evalHoisted() { return 1; } + } + assertEquals(1, evalHoisted()); +`); + +// Test that hoisting from blocks happens from eval in a function +!function() { + eval(` + function evalInFunctionHoisted() { return 0; } + { + function evalInFunctionHoisted() { return 1; } + } + assertEquals(1, evalInFunctionHoisted()); + `); +}(); + +let dontHoistGlobal; +{ function dontHoistGlobal() {} } +assertEquals(undefined, dontHoistGlobal); + +let dontHoistEval; +// BUG(v8:) This shouldn't hoist and shouldn't throw +var throws = false; +try { + eval("{ function dontHoistEval() {} }"); +} catch (e) { + throws = true; +} +assertTrue(throws); + +// When the global object is frozen, silently don't hoist +// Currently this actually throws BUG(v8:4452) +Object.freeze(this); +throws = false; +try { + eval('{ function hoistWhenFrozen() {} }'); +} catch (e) { + throws = true; +} +assertFalse(this.hasOwnProperty("hoistWhenFrozen")); +assertThrows(() => hoistWhenFrozen, ReferenceError); +// Should be assertFalse BUG(v8:4452) +assertTrue(throws); diff --git a/deps/v8/test/mjsunit/harmony/completion.js b/deps/v8/test/mjsunit/harmony/completion.js new file mode 100644 index 0000000000..ceeafb2b3d --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/completion.js @@ -0,0 +1,150 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-completion --harmony-sloppy-let --no-legacy-const + + +function assertUndef(x) { + assertEquals(undefined, x); +} + + +// IfStatement [13.6.7] + +assertUndef(eval('42; if (true) ; else 0;')); // ES5: 42 +assertUndef(eval('42; if (true) ;')); // ES5: 42 +assertUndef(eval('42; if (false) 0;')); // ES5: 42 + +assertEquals(1, eval('42; if (true) 1;')); +assertEquals(1, eval('42; if (true) 1; else 0;')); +assertEquals(0, eval('42; if (false) 1; else 0;')); + + +// IterationStatement [13.7] + +assertUndef(eval('42; do ; while (false);')); // ES5: 42 +assertUndef(eval('42; var x = 1; do ; while (x--);')); // ES5: 42 +assertUndef(eval('42; while (false) 0;')); // ES5: 42 +assertUndef(eval('42; while (true) break;')); // ES5: 42 +assertUndef(eval('42; bla: while (true) break bla;')); // ES5: 42 +assertUndef(eval('42; var x = 1; while (x--) ;')); // ES5: 42 +assertUndef(eval('42; for (; false; ) 0;')); // ES5: 42 +assertUndef(eval('42; for (var x = 1; x; x--) ;')); // ES5: 42 +assertUndef(eval('42; for (var x in ["foo", "bar"]) ;')); +assertUndef(eval('42; for (var x of ["foo", "bar"]) ;')); +assertUndef(eval('42; for (let x = 1; x; x--) ;')); +assertUndef(eval('42; for (let x in ["foo", "bar"]) ;')); +assertUndef(eval('42; for (let x of ["foo", "bar"]) ;')); +assertUndef(eval('42; for (const x in ["foo", "bar"]) ;')); +assertUndef(eval('42; for (const x of ["foo", "bar"]) ;')); + +assertEquals(1, eval('42; var x = 10; do x--; while (x);')); +assertEquals(1, eval('42; var x = 10; while (x) x--;')); +assertEquals(1, eval('42; for (var x = 10; x; x--) x;')); +assertEquals(1, eval('42; for (var x = 10; x; --x) x;')); +assertEquals(1, eval('42; for (let x = 10; x; --x) x;')); +assertEquals(1, eval('42; var y = 2; for (var x in ["foo", "bar"]) y--;')); +assertEquals(1, eval('42; var y = 2; for (const x in ["foo", "bar"]) y--;')); +assertEquals(1, eval('42; var y = 2; for (let x in ["foo", "bar"]) y--;')); +assertEquals(1, eval('42; var y = 2; for (var x of ["foo", "bar"]) y--;')); +assertEquals(1, eval('42; var y = 2; for (const x of ["foo", "bar"]) y--;')); +assertEquals(1, eval('42; var y = 2; for (let x of ["foo", "bar"]) y--;')); + + +// WithStatement [13.11.7] + +assertUndef(eval('42; with ({}) ;')); // ES5: 42 + +assertEquals(1, eval('42; with ({}) 1;')); + + +// SwitchStatement [13.12.11] + +assertUndef(eval('42; switch (0) {};')); // ES5: 42 +assertUndef(eval('42; switch (0) { case 1: 1; };')); // ES5: 42 +assertUndef(eval('42; switch (0) { case 0: ; };')); // ES5: 42 +assertUndef(eval('42; switch (0) { default: ; };')); // ES5: 42 +assertUndef(eval('42; switch (0) { case 0: break; }')); // ES5: 42 + +assertEquals(1, eval('42; switch (0) { case 0: 1; }')); +assertEquals(1, eval('42; switch (0) { case 0: 1; break; }')); +assertEquals(1, eval('42; switch (0) { case 0: 1; case 666: break; }')); +assertEquals(2, eval('42; switch (0) { case 0: 1; case 666: 2; break; }')); + + +// TryStatement [13.15.8] + +assertUndef(eval('42; try { } catch(e) { };')); // ES5: 42 +assertUndef(eval('42; try { } catch(e) { 0; };')); // ES5: 42 +assertUndef(eval('42; try { throw "" } catch(e) { };')); // ES5: 42 +assertUndef(eval('42; try { throw "" } catch(e) { } finally { };')); // ES5: 42 +assertUndef(eval('42; try { } finally { 666 };')); // ES5: 42 + + +// Some combinations + +assertUndef(eval('42; switch (0) { case 0: if (true) break; }')); // ES5: 42 +assertUndef(eval('42; switch (0) { case 0: 1; if (true) ; }')); // ES5: 1 +assertUndef(eval('42; switch (0) { case 0: 1; try { break } catch(e) { }; }')); // ES5: 1 + +assertEquals(0, eval('42; switch (0) { case 0: 0; case 1: break; }')); +assertEquals(0, eval('42; while (1) { 0; break; }')) +assertEquals(0, eval('42; bla: while (1) { 0; break bla; }')) +assertEquals(0, eval('42; while (1) { with ({}) { 0; break; } }')) +assertEquals(0, eval('42; while (1) { try { 0; break } catch(e) {666} }')) +assertEquals(0, eval( + '42; while (1) { try { 0; break } catch(e) {666} finally {666} }')) +assertEquals(0, eval( + '42; while (1) { try { throw "" } catch(e) {666} finally {0; break} }')) +assertEquals(0, eval( + '42; while (1) { try { throw "" } catch(e) {0; break} finally {666} }')) +assertEquals(0, eval( + '42; while (1) { try { 666 } finally {0; break} }')); +assertEquals(0, eval( + '42; while (1) { try { 666; break } finally {0; break} }')); +assertEquals(0, eval( + '42; lab: try { 666; break lab } finally {0; break lab}')); +assertEquals(undefined, eval( + 'var b = 1; ' + + 'outer: while (1) { while (1) { if (b--) 42; else break outer; }; 666 }')); + +// The following is not what ES6 says, but see ES bug 4540. +assertUndef(eval('42; switch (0) { case 0: 1; if (true) break; }')); // ES5: 1 + + + +//////////////////////////////////////////////////////////////////////////////// +// +// The following are copied from webkit/eval-throw-return and adapted. + +function throwFunc() { + throw ""; +} + +function throwOnReturn(){ + 1; + return throwFunc(); +} + +function twoFunc() { + 2; +} + +assertEquals(1, eval("1;")); +assertUndef(eval("1; try { foo = [2,3,throwFunc(), 4]; } catch (e){}")); +assertUndef(eval("1; try { 2; throw ''; } catch (e){}")); +assertUndef(eval("1; try { 2; throwFunc(); } catch (e){}")); +assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {}")); +assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {4;}")); +assertUndef(eval("function blah() { 1; }; blah();")); +assertUndef(eval("var x = 1;")); +assertEquals(1, eval("if (true) { 1; } else { 2; }")); +assertEquals(2, eval("if (false) { 1; } else { 2; }")); +assertUndef(eval("try{1; if (true) { 2; throw ''; } else { 2; }} catch(e){}")); +assertEquals(2, eval("1; var i = 0; do { ++i; 2; } while(i!=1);")); +assertUndef(eval( + "try{1; var i = 0; do { ++i; 2; throw ''; } while (i!=1);} catch(e){}")); +assertUndef(eval("1; try{2; throwOnReturn();} catch(e){}")); +assertUndef(eval("1; twoFunc();")); +assertEquals(2, eval("1; with ( { a: 0 } ) { 2; }")); diff --git a/deps/v8/test/mjsunit/harmony/default-parameters-destructuring.js b/deps/v8/test/mjsunit/harmony/default-parameters-destructuring.js new file mode 100644 index 0000000000..526ab44c9c --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/default-parameters-destructuring.js @@ -0,0 +1,112 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-default-parameters --harmony-destructuring + + +(function TestSloppyEvalScoping() { + var x = 1; + + function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; } + assertEquals(1, f41({})); + assertEquals(1, f41({a: 0})); + function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } + assertEquals(1, f42({})); + assertEquals(1, f42({a: 0})); + function f43({a: w = eval("var x = 2")}, z = x) { return z; } + assertEquals(1, f43({})); + assertEquals(1, f43({a: 0})); + function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } + assertEquals(1, f44({})); + assertEquals(1, f44({a: 0})); + + function f5({a = eval("var x = 2"), b = x}) { return b; } + assertEquals(2, f5({})); + assertEquals(1, f5({a: 0})); + function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } + assertEquals(2, f6({})); + assertEquals(1, f6({a: 0})); + function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } + assertEquals(2, f71({})); + assertEquals(2, f71({a: 0})); + function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; } + assertEquals(2, f72({})); + assertEquals(2, f72({a: 0})); + function f73({a: w = eval("var x = 2"), b = x}) { return b; } + assertEquals(2, f73({})); + assertEquals(1, f73({a: 0})); + function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; } + assertEquals(2, f74({})); + assertEquals(1, f74({a: 0})); + + var g41 = ({[eval("var x = 2; 'a'")]: w}, z = x) => { return z; }; + assertEquals(1, g41({})); + assertEquals(1, g41({a: 0})); + var g42 = ({[eval("var x = 2; 'a'")]: w}, z = eval("x")) => { return z; }; + assertEquals(1, g42({})); + assertEquals(1, g42({a: 0})); + var g43 = ({a: w = eval("var x = 2")}, z = x) => { return z; }; + assertEquals(1, g43({})); + assertEquals(1, g43({a: 0})); + var g44 = ({a: w = eval("var x = 2")}, z = eval("x")) => { return z; }; + assertEquals(1, g44({})); + assertEquals(1, g44({a: 0})); + + var g5 = ({a = eval("var x = 2"), b = x}) => { return b; }; + assertEquals(2, g5({})); + assertEquals(1, g5({a: 0})); + var g6 = ({a = eval("var x = 2"), b = eval("x")}) => { return b; }; + assertEquals(2, g6({})); + assertEquals(1, g6({a: 0})); + var g71 = ({[eval("var x = 2; 'a'")]: w, b = x}) => { return b; }; + assertEquals(2, g71({})); + assertEquals(2, g71({a: 0})); + var g72 = ({[eval("var x = 2; 'a'")]: w, b = eval("x")}) => { return b; }; + assertEquals(2, g72({})); + assertEquals(2, g72({a: 0})); + var g73 = ({a: w = eval("var x = 2"), b = x}) => { return b; }; + assertEquals(2, g73({})); + assertEquals(1, g73({a: 0})); + var g74 = ({a: w = eval("var x = 2"), b = eval("x")}) => { return b; }; + assertEquals(2, g74({})); + assertEquals(1, g74({a: 0})); +})(); + + +(function TestStrictEvalScoping() { + 'use strict'; + var x = 1; + + function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; } + assertEquals(1, f41({})); + assertEquals(1, f41({a: 0})); + function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } + assertEquals(1, f42({})); + assertEquals(1, f42({a: 0})); + function f43({a: w = eval("var x = 2")}, z = x) { return z; } + assertEquals(1, f43({})); + assertEquals(1, f43({a: 0})); + function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } + assertEquals(1, f44({})); + assertEquals(1, f44({a: 0})); + + function f5({a = eval("var x = 2"), b = x}) { return b; } + assertEquals(1, f5({})); + assertEquals(1, f5({a: 0})); + function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } + assertEquals(1, f6({})); + assertEquals(1, f6({a: 0})); + function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } + assertEquals(1, f71({})); + assertEquals(1, f71({a: 0})); + function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; } + assertEquals(1, f72({})); + assertEquals(1, f72({a: 0})); + function f73({a: w = eval("var x = 2"), b = x}) { return b; } + assertEquals(1, f73({})); + assertEquals(1, f73({a: 0})); + function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; } + assertEquals(1, f74({})); + assertEquals(1, f74({a: 0})); +})(); diff --git a/deps/v8/test/mjsunit/harmony/default-parameters.js b/deps/v8/test/mjsunit/harmony/default-parameters.js index b3a79a49a4..106cf8cde5 100644 --- a/deps/v8/test/mjsunit/harmony/default-parameters.js +++ b/deps/v8/test/mjsunit/harmony/default-parameters.js @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-default-parameters --harmony-arrow-functions -// Flags: --harmony-rest-parameters --harmony-destructuring +// Flags: --harmony-default-parameters --harmony-rest-parameters (function TestDefaults() { @@ -179,37 +178,6 @@ function f3(y = eval("var x = 2"), z = eval("x")) { return z; } assertEquals(1, f3()); assertEquals(1, f3(0)); - function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; } - assertEquals(1, f41({})); - assertEquals(1, f41({a: 0})); - function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } - assertEquals(1, f42({})); - assertEquals(1, f42({a: 0})); - function f43({a: w = eval("var x = 2")}, z = x) { return z; } - assertEquals(1, f43({})); - assertEquals(1, f43({a: 0})); - function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } - assertEquals(1, f44({})); - assertEquals(1, f44({a: 0})); - - function f5({a = eval("var x = 2"), b = x}) { return b; } - assertEquals(2, f5({})); - assertEquals(1, f5({a: 0})); - function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } - assertEquals(2, f6({})); - assertEquals(1, f6({a: 0})); - function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } - assertEquals(2, f71({})); - assertEquals(2, f71({a: 0})); - function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; } - assertEquals(2, f72({})); - assertEquals(2, f72({a: 0})); - function f73({a: w = eval("var x = 2"), b = x}) { return b; } - assertEquals(2, f73({})); - assertEquals(1, f73({a: 0})); - function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; } - assertEquals(2, f74({})); - assertEquals(1, f74({a: 0})); function f8(y = (eval("var x = 2"), x)) { return y; } assertEquals(2, f8()); assertEquals(0, f8(0)); @@ -236,37 +204,6 @@ var g3 = (y = eval("var x = 2"), z = eval("x")) => { return z; }; assertEquals(1, g3()); assertEquals(1, g3(0)); - var g41 = ({[eval("var x = 2; 'a'")]: w}, z = x) => { return z; }; - assertEquals(1, g41({})); - assertEquals(1, g41({a: 0})); - var g42 = ({[eval("var x = 2; 'a'")]: w}, z = eval("x")) => { return z; }; - assertEquals(1, g42({})); - assertEquals(1, g42({a: 0})); - var g43 = ({a: w = eval("var x = 2")}, z = x) => { return z; }; - assertEquals(1, g43({})); - assertEquals(1, g43({a: 0})); - var g44 = ({a: w = eval("var x = 2")}, z = eval("x")) => { return z; }; - assertEquals(1, g44({})); - assertEquals(1, g44({a: 0})); - - var g5 = ({a = eval("var x = 2"), b = x}) => { return b; }; - assertEquals(2, g5({})); - assertEquals(1, g5({a: 0})); - var g6 = ({a = eval("var x = 2"), b = eval("x")}) => { return b; }; - assertEquals(2, g6({})); - assertEquals(1, g6({a: 0})); - var g71 = ({[eval("var x = 2; 'a'")]: w, b = x}) => { return b; }; - assertEquals(2, g71({})); - assertEquals(2, g71({a: 0})); - var g72 = ({[eval("var x = 2; 'a'")]: w, b = eval("x")}) => { return b; }; - assertEquals(2, g72({})); - assertEquals(2, g72({a: 0})); - var g73 = ({a: w = eval("var x = 2"), b = x}) => { return b; }; - assertEquals(2, g73({})); - assertEquals(1, g73({a: 0})); - var g74 = ({a: w = eval("var x = 2"), b = eval("x")}) => { return b; }; - assertEquals(2, g74({})); - assertEquals(1, g74({a: 0})); var g8 = (y = (eval("var x = 2"), x)) => { return y; }; assertEquals(2, g8()); assertEquals(0, g8(0)); @@ -299,37 +236,6 @@ function f3(y = eval("var x = 2"), z = eval("x")) { return z; } assertEquals(1, f3()); assertEquals(1, f3(0)); - function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; } - assertEquals(1, f41({})); - assertEquals(1, f41({a: 0})); - function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; } - assertEquals(1, f42({})); - assertEquals(1, f42({a: 0})); - function f43({a: w = eval("var x = 2")}, z = x) { return z; } - assertEquals(1, f43({})); - assertEquals(1, f43({a: 0})); - function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; } - assertEquals(1, f44({})); - assertEquals(1, f44({a: 0})); - - function f5({a = eval("var x = 2"), b = x}) { return b; } - assertEquals(1, f5({})); - assertEquals(1, f5({a: 0})); - function f6({a = eval("var x = 2"), b = eval("x")}) { return b; } - assertEquals(1, f6({})); - assertEquals(1, f6({a: 0})); - function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; } - assertEquals(1, f71({})); - assertEquals(1, f71({a: 0})); - function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; } - assertEquals(1, f72({})); - assertEquals(1, f72({a: 0})); - function f73({a: w = eval("var x = 2"), b = x}) { return b; } - assertEquals(1, f73({})); - assertEquals(1, f73({a: 0})); - function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; } - assertEquals(1, f74({})); - assertEquals(1, f74({a: 0})); function f8(y = (eval("var x = 2"), x)) { return y; } assertEquals(1, f8()); assertEquals(0, f8(0)); diff --git a/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount-nolazy.js b/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount-nolazy.js index 52d7ca06d9..82158438b4 100644 --- a/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount-nolazy.js +++ b/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount-nolazy.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // // Flags: --harmony-destructuring -// Flags: --harmony-arrow-functions --no-lazy --allow-natives-syntax +// Flags: --no-lazy --allow-natives-syntax var t1 = [1]; diff --git a/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount.js b/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount.js index 64c1793673..cc0e278acb 100644 --- a/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount.js +++ b/deps/v8/test/mjsunit/harmony/destructuring-parameters-literalcount.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // // Flags: --harmony-destructuring -// Flags: --harmony-arrow-functions --allow-natives-syntax +// Flags: --allow-natives-syntax var t1 = [1]; diff --git a/deps/v8/test/mjsunit/harmony/destructuring.js b/deps/v8/test/mjsunit/harmony/destructuring.js index f1e2210a2a..7192d7aa5b 100644 --- a/deps/v8/test/mjsunit/harmony/destructuring.js +++ b/deps/v8/test/mjsunit/harmony/destructuring.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Flags: --harmony-destructuring --harmony-arrow-functions +// Flags: --harmony-destructuring // Flags: --harmony-default-parameters --harmony-rest-parameters (function TestObjectLiteralPattern() { @@ -957,11 +957,85 @@ assertEquals(1, ok1(1)); function ok2(x) { 'use strict'; { let x = 2; return x; } }; assertEquals(2, ok2(1)); +}()); + + +(function TestShadowingOfParameters() { + function f1({x}) { var x = 2; return x } + assertEquals(2, f1({x: 1})); + function f2({x}) { { var x = 2; } return x; } + assertEquals(2, f2({x: 1})); + function f3({x}) { var y = x; var x = 2; return y; } + assertEquals(1, f3({x: 1})); + function f4({x}) { { var y = x; var x = 2; } return y; } + assertEquals(1, f4({x: 1})); + function f5({x}, g = () => x) { var x = 2; return g(); } + assertEquals(1, f5({x: 1})); + function f6({x}, g = () => x) { { var x = 2; } return g(); } + assertEquals(1, f6({x: 1})); + function f7({x}) { var g = () => x; var x = 2; return g(); } + assertEquals(2, f7({x: 1})); + function f8({x}) { { var g = () => x; var x = 2; } return g(); } + assertEquals(2, f8({x: 1})); + function f9({x}, g = () => eval("x")) { var x = 2; return g(); } + assertEquals(1, f9({x: 1})); + + function f10({x}, y) { var y; return y } + assertEquals(2, f10({x: 6}, 2)); + function f11({x}, y) { var z = y; var y = 2; return z; } + assertEquals(1, f11({x: 6}, 1)); + function f12(y, g = () => y) { var y = 2; return g(); } + assertEquals(1, f12(1)); + function f13({x}, y, [z], v) { var x, y, z; return x*y*z*v } + assertEquals(210, f13({x: 2}, 3, [5], 7)); + + function f20({x}) { function x() { return 2 }; return x(); } + assertEquals(2, f20({x: 1})); + function f21({x}) { { function x() { return 2 } } return x(); } + assertEquals(2, f21({x: 1})); + + var g1 = ({x}) => { var x = 2; return x }; + assertEquals(2, g1({x: 1})); + var g2 = ({x}) => { { var x = 2; } return x; }; + assertEquals(2, g2({x: 1})); + var g3 = ({x}) => { var y = x; var x = 2; return y; }; + assertEquals(1, g3({x: 1})); + var g4 = ({x}) => { { var y = x; var x = 2; } return y; }; + assertEquals(1, g4({x: 1})); + var g5 = ({x}, g = () => x) => { var x = 2; return g(); }; + assertEquals(1, g5({x: 1})); + var g6 = ({x}, g = () => x) => { { var x = 2; } return g(); }; + assertEquals(1, g6({x: 1})); + var g7 = ({x}) => { var g = () => x; var x = 2; return g(); }; + assertEquals(2, g7({x: 1})); + var g8 = ({x}) => { { var g = () => x; var x = 2; } return g(); }; + assertEquals(2, g8({x: 1})); + var g9 = ({x}, g = () => eval("x")) => { var x = 2; return g(); }; + assertEquals(1, g9({x: 1})); + + var g10 = ({x}, y) => { var y; return y }; + assertEquals(2, g10({x: 6}, 2)); + var g11 = ({x}, y) => { var z = y; var y = 2; return z; }; + assertEquals(1, g11({x: 6}, 1)); + var g12 = (y, g = () => y) => { var y = 2; return g(); }; + assertEquals(1, g12(1)); + var g13 = ({x}, y, [z], v) => { var x, y, z; return x*y*z*v }; + assertEquals(210, g13({x: 2}, 3, [5], 7)); + + var g20 = ({x}) => { function x() { return 2 }; return x(); } + assertEquals(2, g20({x: 1})); + var g21 = ({x}) => { { function x() { return 2 } } return x(); } + assertEquals(2, g21({x: 1})); - assertThrows("function f({x}) { var x; }; f({});", SyntaxError); - assertThrows("function f({x}) { { var x; } }; f({});", SyntaxError); assertThrows("'use strict'; function f(x) { let x = 0; }; f({});", SyntaxError); assertThrows("'use strict'; function f({x}) { let x = 0; }; f({});", SyntaxError); + assertThrows("'use strict'; function f(x) { const x = 0; }; f({});", SyntaxError); + assertThrows("'use strict'; function f({x}) { const x = 0; }; f({});", SyntaxError); + + assertThrows("'use strict'; let g = (x) => { let x = 0; }; f({});", SyntaxError); + assertThrows("'use strict'; let g = ({x}) => { let x = 0; }; f({});", SyntaxError); + assertThrows("'use strict'; let g = (x) => { const x = 0; }; f({});", SyntaxError); + assertThrows("'use strict'; let g = ({x}) => { const x = 0; }; f({});", SyntaxError); }()); @@ -1023,3 +1097,37 @@ assertThrows( function(){ eval("(class{foo(a, {}) {'use strict';}});") }, SyntaxError); })(); + + +(function TestLegacyConstDestructuringInForLoop() { + var result; + for (const {foo} of [{foo: 1}]) { result = foo; } + assertEquals(1, result); +})(); + + +(function TestCatch() { + "use strict"; + + // For testing proper scoping. + var foo = "hello", bar = "world", baz = 42; + + try { + throw {foo: 1, bar: 2}; + } catch ({foo, bar, baz = 3}) { + assertEquals(1, foo); + assertEquals(2, bar); + assertEquals(3, baz); + } + + try { + throw [1, 2, 3]; + } catch ([foo, ...bar]) { + assertEquals(1, foo); + assertEquals([2, 3], bar); + } + + assertEquals("hello", foo); + assertEquals("world", bar); + assertEquals(42, baz); +})(); diff --git a/deps/v8/test/mjsunit/harmony/do-expressions.js b/deps/v8/test/mjsunit/harmony/do-expressions.js new file mode 100644 index 0000000000..c3f9e0cd86 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/do-expressions.js @@ -0,0 +1,277 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-do-expressions --harmony-sloppy-let --allow-natives-syntax +// Flags: --harmony-default-parameters --harmony-destructuring +// Flags: --harmony-completion + +function returnValue(v) { return v; } +function MyError() {} +var global = this; + +function TestBasic() { + // Looping and lexical declarations + assertEquals(512, returnValue(do { + let n = 2; + for (let i = 0; i < 4; i++) n <<= 2; + })); + + // Strings do the right thing + assertEquals("spooky halloween", returnValue(do { + "happy halloween".replace('happy', 'spooky'); + })); + + // Do expressions with no completion produce an undefined value + assertEquals(undefined, returnValue(do {})); + assertEquals(undefined, returnValue(do { var x = 99; })); + assertEquals(undefined, returnValue(do { function f() {}; })); + assertEquals(undefined, returnValue(do { let z = 33; })); + + // Propagation of exception + assertThrows(function() { + (do { + throw new MyError(); + "potatoes"; + }); + }, MyError); + + assertThrows(function() { + return do { + throw new MyError(); + "potatoes"; + }; + }, MyError); + + // Return value within do-block overrides `return |do-expression|` + assertEquals("inner-return", (function() { + return "outer-return" + do { + return "inner-return"; + ""; + }; + })()); + + var count = 0, n = 1; + // Breaking out |do-expression| + assertEquals(3, (function() { + for (var i = 0; i < 10; ++i) (count += 2 * do { if (i === 3) break; ++n }); + return i; + })()); + // (2 * 2) + (2 * 3) + (2 * 4) + assertEquals(18, count); + + // Continue in |do-expression| + count = 0, n = 1; + assertEquals([1, 3, 5, 7, 9], (function() { + var values = []; + for (var i = 0; i < 10; ++i) { + count += 2 * (do { + if ((i & 1) === 0) continue; + values.push(i); + ++n; + }) + 1; + } + // (2*2) + 1 + (2*3) + 1 + (2*4) + 1 + (2*5) + 1 + (2*6) + 1 + return values; + })()); + assertEquals(count, 45); + + assertThrows("(do { break; });", SyntaxError); + assertThrows("(do { continue; });", SyntaxError); + + // Real-world use case for desugaring + var array = [1, 2, 3, 4, 5], iterable = [6, 7, 8,9]; + assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], do { + for (var element of iterable) array.push(element); + array; + }); + + // Nested do-expressions + assertEquals(125, do { (do { (do { 5 * 5 * 5 }) }) }); + + // Directives are not honoured + (do { + "use strict"; + foo = 80; + assertEquals(foo, 80); + }); + + // Non-empty operand stack testing + var O = { + method1() { + let x = 256; + return x + do { + for (var i = 0; i < 4; ++i) x += i; + } + 17; + }, + method2() { + let x = 256; + this.reset(); + return x + do { + for (var i = 0; i < this.length(); ++i) x += this.index() * 2; + }; + }, + _index: 0, + index() { + return ++this._index; + }, + _length: 4, + length() { return this._length; }, + reset() { this._index = 0; } + }; + assertEquals(535, O["method" + do { 1 } + ""]()); + assertEquals(532, O["method" + do { ({ valueOf() { return "2"; } }); }]()); + assertEquals(532, O[ + do { let s = ""; for (let c of "method") s += c; } + "2"]()); +} +TestBasic(); + + +function TestDeoptimization1() { + function f(v) { + return 88 + do { + v.a * v.b + v.c; + }; + } + + var o1 = {}; + o1.a = 10; + o1.b = 5; + o1.c = 50; + + var o2 = {}; + o2.c = 100; + o2.a = 10; + o2.b = 10; + + assertEquals(188, f(o1)); + assertEquals(188, f(o1)); + %OptimizeFunctionOnNextCall(f); + assertEquals(188, f(o1)); + assertOptimized(f); + assertEquals(288, f(o2)); + assertUnoptimized(f); + assertEquals(288, f(o2)); +} +TestDeoptimization1(); + + +function TestInParameterInitializers() { + var first_name = "George"; + var last_name = "Jetson"; + function fn1(name = do { first_name + " " + last_name }) { + return name; + } + assertEquals("George Jetson", fn1()); + + var _items = [1, 2, 3, NaN, 4, 5]; + function fn2(items = do { + let items = []; + for (var el of _items) { + if (el !== el) { + items; + break; + } + items.push(el), items; + } + }) { + return items; + } + assertEquals([1, 2, 3], fn2()); + + function thrower() { throw new MyError(); } + function fn3(exception = do { try { thrower(); } catch (e) { e } }) { + return exception; + } + assertDoesNotThrow(fn3); + assertInstanceof(fn3(), MyError); + + function fn4(exception = do { throw new MyError() }) {} + function catcher(fn) { + try { + fn(); + assertUnreachable("fn() initializer should throw"); + } catch (e) { + assertInstanceof(e, MyError); + } + } + catcher(fn4); +} +TestInParameterInitializers(); + + +function TestWithEval() { + (function sloppy1() { + assertEquals(do { eval("var x = 5"), x }, 5); + assertEquals(x, 5); + })(); + + assertThrows(function strict1() { + "use strict"; + (do { eval("var x = 5"), x }, 5); + }, ReferenceError); + + assertThrows(function strict2() { + (do { eval("'use strict'; var x = 5"), x }, 5); + }, ReferenceError); +} +TestWithEval(); + + +function TestHoisting() { + (do { var a = 1; }); + assertEquals(a, 1); + assertEquals(global.a, undefined); + + (do { + for (let it of [1, 2, 3, 4, 5]) { + var b = it; + } + }); + assertEquals(b, 5); + assertEquals(global.b, undefined); + + { + let x = 1 + + // TODO(caitp): ensure VariableStatements in |do-expressions| in parameter + // initializers, are evaluated in the same VariableEnvironment as they would + // be for eval(). + // function f1(a = do { var x = 2 }, b = x) { return b } + // assertEquals(1, f1()) + + // function f2(a = x, b = do { var x = 2 }) { return a } + // assertEquals(1, f2()) + + function f3({a = do { var x = 2 }, b = x}) { return b } + assertEquals(2, f3({})) + + function f4({a = x, b = do { var x = 2 }}) { return b } + assertEquals(undefined, f4({})) + + function f5(a = do { var y = 0 }) {} + assertThrows(() => y, ReferenceError) + } + + // TODO(caitp): Always block-scope function declarations in |do| expressions + //(do { + // assertEquals(true, inner_func()); + // function inner_func() { return true; } + //}); + //assertThrows(function() { return innerFunc(); }, ReferenceError); +} +TestHoisting(); + + +function TestOSR() { + var numbers = do { + let nums = []; + for (let i = 0; i < 1000; ++i) { + let value = (Math.random() * 100) | 0; + nums.push(value === 0 ? 1 : value), nums; + } + }; + assertEquals(numbers.length, 1000); +} + +for (var i = 0; i < 64; ++i) TestOSR(); diff --git a/deps/v8/test/mjsunit/harmony/private.js b/deps/v8/test/mjsunit/harmony/private.js index 0adbb13b21..d44ff33aca 100644 --- a/deps/v8/test/mjsunit/harmony/private.js +++ b/deps/v8/test/mjsunit/harmony/private.js @@ -132,8 +132,8 @@ function TestEquality() { assertTrue(symbols[i] == symbols[i]) assertFalse(symbols[i] === Object(symbols[i])) assertFalse(Object(symbols[i]) === symbols[i]) - assertFalse(symbols[i] == Object(symbols[i])) - assertFalse(Object(symbols[i]) == symbols[i]) + assertTrue(symbols[i] == Object(symbols[i])) + assertTrue(Object(symbols[i]) == symbols[i]) assertTrue(symbols[i] === symbols[i].valueOf()) assertTrue(symbols[i].valueOf() === symbols[i]) assertTrue(symbols[i] == symbols[i].valueOf()) diff --git a/deps/v8/test/mjsunit/harmony/proxies-function.js b/deps/v8/test/mjsunit/harmony/proxies-function.js index 3c36a4f204..113ea79f46 100644 --- a/deps/v8/test/mjsunit/harmony/proxies-function.js +++ b/deps/v8/test/mjsunit/harmony/proxies-function.js @@ -118,10 +118,10 @@ function TestCall(isStrict, callTrap) { assertEquals(42, %Apply(f, null, [11, 31], 0, 2)) assertSame(isStrict ? null : global_object, receiver) receiver = 333 - assertEquals(42, %_CallFunction(o, 11, 31, f)) + assertEquals(42, %_Call(f, o, 11, 31)) assertSame(o, receiver) receiver = 333 - assertEquals(42, %_CallFunction(null, 11, 31, f)) + assertEquals(42, %_Call(f, null, 11, 31)) assertSame(isStrict ? null : global_object, receiver) var ff = Function.prototype.bind.call(f, o, 12) @@ -148,10 +148,10 @@ function TestCall(isStrict, callTrap) { assertEquals(24, %Apply(ff, {}, [12, 13], 0, 2)) assertSame(o, receiver) receiver = 333 - assertEquals(34, %_CallFunction({}, 22, ff)) + assertEquals(34, %_Call(ff, {}, 22)) assertSame(o, receiver) receiver = 333 - assertEquals(34, %_CallFunction({}, 22, 3, ff)) + assertEquals(34, %_Call(ff, {}, 22, 3)) assertSame(o, receiver) var fff = Function.prototype.bind.call(ff, o, 30) @@ -181,10 +181,10 @@ function TestCall(isStrict, callTrap) { assertEquals(42, %Apply(fff, {}, [12, 13], 0, 2)) assertSame(o, receiver) receiver = 333 - assertEquals(42, %_CallFunction({}, fff)) + assertEquals(42, %_Call(fff, {})) assertSame(o, receiver) receiver = 333 - assertEquals(42, %_CallFunction({}, 3, 4, 5, fff)) + assertEquals(42, %_Call(fff, {}, 3, 4, 5)) assertSame(o, receiver) var f = CreateFrozen({}, callTrap) @@ -217,7 +217,7 @@ function TestCall(isStrict, callTrap) { assertEquals(27, %Apply(f, o, [12, 13, 14], 1, 2)) assertSame(o, receiver) receiver = 333 - assertEquals(42, %_CallFunction(o, 18, 24, f)) + assertEquals(42, %_Call(f, o, 18, 24)) assertSame(o, receiver) } @@ -284,8 +284,8 @@ function TestCallThrow(callTrap) { assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn") assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") - assertThrows(function(){ %_CallFunction({}, f) }, "myexn") - assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") + assertThrows(function(){ %_Call(f, {}) }, "myexn") + assertThrows(function(){ %_Call(f, {}, 1, 2) }, "myexn") var f = CreateFrozen({}, callTrap) assertThrows(function(){ f(11) }, "myexn") @@ -297,8 +297,8 @@ function TestCallThrow(callTrap) { assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn") assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") - assertThrows(function(){ %_CallFunction({}, f) }, "myexn") - assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") + assertThrows(function(){ %_Call(f, {}) }, "myexn") + assertThrows(function(){ %_Call(f, {}, 1, 2) }, "myexn") } TestCallThrow(function() { throw "myexn" }) @@ -697,7 +697,7 @@ function TestCalls() { function(f, x, y, o) { return f.apply(o, [x, y]) }, function(f, x, y, o) { return Function.prototype.call.call(f, o, x, y) }, function(f, x, y, o) { return Function.prototype.apply.call(f, o, [x, y]) }, - function(f, x, y, o) { return %_CallFunction(o, x, y, f) }, + function(f, x, y, o) { return %_Call(f, o, x, y) }, function(f, x, y, o) { return %Call(f, o, x, y) }, function(f, x, y, o) { return %Apply(f, o, [null, x, y, null], 1, 2) }, function(f, x, y, o) { return %Apply(f, o, arguments, 2, 2) }, diff --git a/deps/v8/test/mjsunit/harmony/proxies.js b/deps/v8/test/mjsunit/harmony/proxies.js index f1d37b445a..e49ea7fab8 100644 --- a/deps/v8/test/mjsunit/harmony/proxies.js +++ b/deps/v8/test/mjsunit/harmony/proxies.js @@ -1310,7 +1310,7 @@ function TestDescriptorGetOrder(handler) { TestDescriptorGetOrder2(function(n) { return p[n] }, "vV") TestDescriptorGetOrder2(function(n) { return n in p }, "") TestDescriptorGetOrder2(function(n) { return o[n] }, "vV") - TestDescriptorGetOrder2(function(n) { return n in o }, "eEcCvVwWgs") + TestDescriptorGetOrder2(function(n) { return n in o }, "") } function TestDescriptorGetOrder2(f, access) { diff --git a/deps/v8/test/mjsunit/harmony/reflect-define-property.js b/deps/v8/test/mjsunit/harmony/reflect-define-property.js new file mode 100644 index 0000000000..afd3ff6595 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-define-property.js @@ -0,0 +1,1115 @@ +// Copyright 2012-2015 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. + +// Tests the Reflect.defineProperty method - ES6 26.1.3 +// This is adapted from mjsunit/object-define-property.js. + +// Flags: --allow-natives-syntax --harmony-reflect + + +// Check that an exception is thrown when null is passed as object. +var exception = false; +try { + Reflect.defineProperty(null, null, null); +} catch (e) { + exception = true; + assertTrue(/called on non-object/.test(e)); +} +assertTrue(exception); + +// Check that an exception is thrown when undefined is passed as object. +exception = false; +try { + Reflect.defineProperty(undefined, undefined, undefined); +} catch (e) { + exception = true; + assertTrue(/called on non-object/.test(e)); +} +assertTrue(exception); + +// Check that an exception is thrown when non-object is passed as object. +exception = false; +try { + Reflect.defineProperty(0, "foo", undefined); +} catch (e) { + exception = true; + assertTrue(/called on non-object/.test(e)); +} +assertTrue(exception); + +// Object. +var obj1 = {}; + +// Values. +var val1 = 0; +var val2 = 0; +var val3 = 0; + +function setter1() {val1++; } +function getter1() {return val1; } + +function setter2() {val2++; } +function getter2() {return val2; } + +function setter3() {val3++; } +function getter3() {return val3; } + + +// Descriptors. +var emptyDesc = {}; + +var accessorConfigurable = { + set: setter1, + get: getter1, + configurable: true +}; + +var accessorNoConfigurable = { + set: setter2, + get: getter2, + configurable: false +}; + +var accessorOnlySet = { + set: setter3, + configurable: true +}; + +var accessorOnlyGet = { + get: getter3, + configurable: true +}; + +var accessorDefault = {set: function(){} }; + +var dataConfigurable = { value: 1000, configurable: true }; + +var dataNoConfigurable = { value: 2000, configurable: false }; + +var dataWritable = { value: 3000, writable: true}; + + +// Check that we can't add property with undefined attributes. +assertThrows(function() { Reflect.defineProperty(obj1, "foo", undefined) }, + TypeError); + +// Make sure that we can add a property with an empty descriptor and +// that it has the default descriptor values. +assertTrue(Reflect.defineProperty(obj1, "foo", emptyDesc)); + +// foo should be undefined as it has no get, set or value +assertEquals(undefined, obj1.foo); + +// We should, however, be able to retrieve the propertydescriptor which should +// have all default values (according to 8.6.1). +var desc = Object.getOwnPropertyDescriptor(obj1, "foo"); +assertFalse(desc.configurable); +assertFalse(desc.enumerable); +assertFalse(desc.writable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); +assertEquals(desc.value, undefined); + +// Make sure that getOwnPropertyDescriptor does not return a descriptor +// with default values if called with non existing property (otherwise +// the test above is invalid). +desc = Object.getOwnPropertyDescriptor(obj1, "bar"); +assertEquals(desc, undefined); + +// Make sure that foo can't be reset (as configurable is false). +assertFalse(Reflect.defineProperty(obj1, "foo", accessorConfigurable)); + + +// Accessor properties + +assertTrue(Reflect.defineProperty(obj1, "bar", accessorConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "bar"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorConfigurable.get); +assertEquals(desc.set, accessorConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj1.bar = 1); +assertEquals(1, val1); +assertEquals(1, obj1.bar = 1); +assertEquals(2, val1); +assertEquals(2, obj1.bar); + +// Redefine bar with non configurable test +assertTrue(Reflect.defineProperty(obj1, "bar", accessorNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "bar"); +assertFalse(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorNoConfigurable.get); +assertEquals(desc.set, accessorNoConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj1.bar = 1); +assertEquals(2, val1); +assertEquals(1, val2); +assertEquals(1, obj1.bar = 1) +assertEquals(2, val1); +assertEquals(2, val2); +assertEquals(2, obj1.bar); + +// Try to redefine bar again - should fail as configurable is false. +assertFalse(Reflect.defineProperty(obj1, "bar", accessorConfigurable)); + +// Try to redefine bar again using the data descriptor - should fail. +assertFalse(Reflect.defineProperty(obj1, "bar", dataConfigurable)); + +// Redefine using same descriptor - should succeed. +assertTrue(Reflect.defineProperty(obj1, "bar", accessorNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "bar"); +assertFalse(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorNoConfigurable.get); +assertEquals(desc.set, accessorNoConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj1.bar = 1); +assertEquals(2, val1); +assertEquals(3, val2); +assertEquals(1, obj1.bar = 1) +assertEquals(2, val1); +assertEquals(4, val2); +assertEquals(4, obj1.bar); + +// Define an accessor that has only a setter. +assertTrue(Reflect.defineProperty(obj1, "setOnly", accessorOnlySet)); +desc = Object.getOwnPropertyDescriptor(obj1, "setOnly"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.set, accessorOnlySet.set); +assertEquals(desc.writable, undefined); +assertEquals(desc.value, undefined); +assertEquals(desc.get, undefined); +assertEquals(1, obj1.setOnly = 1); +assertEquals(1, val3); + +// Add a getter - should not touch the setter. +assertTrue(Reflect.defineProperty(obj1, "setOnly", accessorOnlyGet)); +desc = Object.getOwnPropertyDescriptor(obj1, "setOnly"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.get, accessorOnlyGet.get); +assertEquals(desc.set, accessorOnlySet.set); +assertEquals(desc.writable, undefined); +assertEquals(desc.value, undefined); +assertEquals(1, obj1.setOnly = 1); +assertEquals(2, val3); + +// The above should also work if redefining just a getter or setter on +// an existing property with both a getter and a setter. +assertTrue(Reflect.defineProperty(obj1, "both", accessorConfigurable)); + +assertTrue(Reflect.defineProperty(obj1, "both", accessorOnlySet)); +desc = Object.getOwnPropertyDescriptor(obj1, "both"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.set, accessorOnlySet.set); +assertEquals(desc.get, accessorConfigurable.get); +assertEquals(desc.writable, undefined); +assertEquals(desc.value, undefined); +assertEquals(1, obj1.both = 1); +assertEquals(3, val3); + + +// Data properties + +assertTrue(Reflect.defineProperty(obj1, "foobar", dataConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); +assertEquals(obj1.foobar, 1000); +assertEquals(desc.value, 1000); +assertTrue(desc.configurable); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); +//Try writing to non writable attribute - should remain 1000 +obj1.foobar = 1001; +assertEquals(obj1.foobar, 1000); + + +// Redefine to writable descriptor - now writing to foobar should be allowed. +assertTrue(Reflect.defineProperty(obj1, "foobar", dataWritable)); +desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); +assertEquals(obj1.foobar, 3000); +assertEquals(desc.value, 3000); +// Note that since dataWritable does not define configurable the configurable +// setting from the redefined property (in this case true) is used. +assertTrue(desc.configurable); +assertTrue(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); +// Writing to the property should now be allowed +obj1.foobar = 1001; +assertEquals(obj1.foobar, 1001); + + +// Redefine with non configurable data property. +assertTrue(Reflect.defineProperty(obj1, "foobar", dataNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); +assertEquals(obj1.foobar, 2000); +assertEquals(desc.value, 2000); +assertFalse(desc.configurable); +assertTrue(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); + +// Try redefine again - shold fail because configurable is now false. +assertFalse(Reflect.defineProperty(obj1, "foobar", dataConfigurable)); + +// Try redefine again with accessor property - shold also fail. +assertFalse(Reflect.defineProperty(obj1, "foobar", dataConfigurable)); + + +// Redifine with the same descriptor - should succeed (step 6). +assertTrue(Reflect.defineProperty(obj1, "foobar", dataNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj1, "foobar"); +assertEquals(obj1.foobar, 2000); +assertEquals(desc.value, 2000); +assertFalse(desc.configurable); +assertTrue(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); + + +// New object +var obj2 = {}; + +// Make accessor - redefine to data +assertTrue(Reflect.defineProperty(obj2, "foo", accessorConfigurable)); + +// Redefine to data property +assertTrue(Reflect.defineProperty(obj2, "foo", dataConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj2, "foo"); +assertEquals(obj2.foo, 1000); +assertEquals(desc.value, 1000); +assertTrue(desc.configurable); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); + + +// Redefine back to accessor +assertTrue(Reflect.defineProperty(obj2, "foo", accessorConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj2, "foo"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorConfigurable.get); +assertEquals(desc.set, accessorConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj2.foo = 1); +assertEquals(3, val1); +assertEquals(4, val2); +assertEquals(3, obj2.foo); + +// Make data - redefine to accessor +assertTrue(Reflect.defineProperty(obj2, "bar", dataConfigurable)) + +// Redefine to accessor property +assertTrue(Reflect.defineProperty(obj2, "bar", accessorConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj2, "bar"); +assertTrue(desc.configurable); +assertFalse(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorConfigurable.get); +assertEquals(desc.set, accessorConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj2.bar = 1); +assertEquals(4, val1); +assertEquals(4, val2); +assertEquals(4, obj2.foo); + +// Redefine back to data property +assertTrue(Reflect.defineProperty(obj2, "bar", dataConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj2, "bar"); +assertEquals(obj2.bar, 1000); +assertEquals(desc.value, 1000); +assertTrue(desc.configurable); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); + + +// Redefinition of an accessor defined using __defineGetter__ and +// __defineSetter__. +function get(){return this.x} +function set(x){this.x=x}; + +var obj3 = {x:1000}; +obj3.__defineGetter__("foo", get); +obj3.__defineSetter__("foo", set); + +desc = Object.getOwnPropertyDescriptor(obj3, "foo"); +assertTrue(desc.configurable); +assertTrue(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, get); +assertEquals(desc.set, set); +assertEquals(desc.value, undefined); +assertEquals(1, obj3.foo = 1); +assertEquals(1, obj3.x); +assertEquals(1, obj3.foo); + +// Redefine to accessor property (non configurable) - note that enumerable +// which we do not redefine should remain the same (true). +assertTrue(Reflect.defineProperty(obj3, "foo", accessorNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj3, "foo"); +assertFalse(desc.configurable); +assertTrue(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorNoConfigurable.get); +assertEquals(desc.set, accessorNoConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj3.foo = 1); +assertEquals(5, val2); +assertEquals(5, obj3.foo); + + +obj3.__defineGetter__("bar", get); +obj3.__defineSetter__("bar", set); + + +// Redefine back to data property +assertTrue(Reflect.defineProperty(obj3, "bar", dataConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj3, "bar"); +assertEquals(obj3.bar, 1000); +assertEquals(desc.value, 1000); +assertTrue(desc.configurable); +assertFalse(desc.writable); +assertTrue(desc.enumerable); +assertEquals(desc.get, undefined); +assertEquals(desc.set, undefined); + + +var obj4 = {}; +var func = function (){return 42;}; +obj4.bar = func; +assertEquals(42, obj4.bar()); + +assertTrue(Reflect.defineProperty(obj4, "bar", accessorConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj4, "bar"); +assertTrue(desc.configurable); +assertTrue(desc.enumerable); +assertEquals(desc.writable, undefined); +assertEquals(desc.get, accessorConfigurable.get); +assertEquals(desc.set, accessorConfigurable.set); +assertEquals(desc.value, undefined); +assertEquals(1, obj4.bar = 1); +assertEquals(5, val1); +assertEquals(5, obj4.bar); + +// Make sure an error is thrown when trying to access to redefined function. +try { + obj4.bar(); + assertTrue(false); +} catch (e) { + assertTrue(/is not a function/.test(e)); +} + + +// Test runtime calls to DefineDataPropertyUnchecked and +// DefineAccessorPropertyUnchecked - make sure we don't +// crash. +try { + %DefineAccessorPropertyUnchecked(0, 0, 0, 0, 0); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +try { + %DefineDataPropertyUnchecked(0, 0, 0, 0); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +try { + %DefineDataPropertyUnchecked(null, null, null, null); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +try { + %DefineAccessorPropertyUnchecked(null, null, null, null, null); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +try { + %DefineDataPropertyUnchecked({}, null, null, null); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +// Defining properties null should fail even when we have +// other allowed values +try { + %DefineAccessorPropertyUnchecked(null, 'foo', func, null, 0); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +try { + %DefineDataPropertyUnchecked(null, 'foo', 0, 0); +} catch (e) { + assertTrue(/illegal access/.test(e)); +} + +// Test that all possible differences in step 6 in DefineOwnProperty are +// exercised, i.e., any difference in the given property descriptor and the +// existing properties should not return true, but throw an error if the +// existing configurable property is false. + +var obj5 = {}; +// Enumerable will default to false. +assertTrue(Reflect.defineProperty(obj5, 'foo', accessorNoConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj5, 'foo'); +// First, test that we are actually allowed to set the accessor if all +// values are of the descriptor are the same as the existing one. +assertTrue(Reflect.defineProperty(obj5, 'foo', accessorNoConfigurable)); + +// Different setter. +var descDifferent = { + configurable:false, + enumerable:false, + set: setter1, + get: getter2 +}; + +assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent)); + +// Different getter. +descDifferent = { + configurable:false, + enumerable:false, + set: setter2, + get: getter1 +}; + +assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent)); + +// Different enumerable. +descDifferent = { + configurable:false, + enumerable:true, + set: setter2, + get: getter2 +}; + +assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent)); + +// Different configurable. +descDifferent = { + configurable:false, + enumerable:true, + set: setter2, + get: getter2 +}; + +assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent)); + +// No difference. +descDifferent = { + configurable:false, + enumerable:false, + set: setter2, + get: getter2 +}; +// Make sure we can still redefine if all properties are the same. +assertTrue(Reflect.defineProperty(obj5, 'foo', descDifferent)); + +// Make sure that obj5 still holds the original values. +desc = Object.getOwnPropertyDescriptor(obj5, 'foo'); +assertEquals(desc.get, getter2); +assertEquals(desc.set, setter2); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + + +// Also exercise step 6 on data property, writable and enumerable +// defaults to false. +assertTrue(Reflect.defineProperty(obj5, 'bar', dataNoConfigurable)); + +// Test that redefinition with the same property descriptor is possible +assertTrue(Reflect.defineProperty(obj5, 'bar', dataNoConfigurable)); + +// Different value. +descDifferent = { + configurable:false, + enumerable:false, + writable: false, + value: 1999 +}; + +assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent)); + +// Different writable. +descDifferent = { + configurable:false, + enumerable:false, + writable: true, + value: 2000 +}; + +assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent)); + + +// Different enumerable. +descDifferent = { + configurable:false, + enumerable:true , + writable:false, + value: 2000 +}; + +assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent)); + + +// Different configurable. +descDifferent = { + configurable:true, + enumerable:false, + writable:false, + value: 2000 +}; + +assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent)); + +// No difference. +descDifferent = { + configurable:false, + enumerable:false, + writable:false, + value:2000 +}; +// Make sure we can still redefine if all properties are the same. +assertTrue(Reflect.defineProperty(obj5, 'bar', descDifferent)); + +// Make sure that obj5 still holds the original values. +desc = Object.getOwnPropertyDescriptor(obj5, 'bar'); +assertEquals(desc.value, 2000); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + + +// Make sure that we can't overwrite +0 with -0 and vice versa. +var descMinusZero = {value: -0, configurable: false}; +var descPlusZero = {value: +0, configurable: false}; + +assertTrue(Reflect.defineProperty(obj5, 'minuszero', descMinusZero)); + +// Make sure we can redefine with -0. +assertTrue(Reflect.defineProperty(obj5, 'minuszero', descMinusZero)); + +assertFalse(Reflect.defineProperty(obj5, 'minuszero', descPlusZero)); + + +assertTrue(Reflect.defineProperty(obj5, 'pluszero', descPlusZero)); + +// Make sure we can redefine with +0. +assertTrue(Reflect.defineProperty(obj5, 'pluszero', descPlusZero)); + +assertFalse(Reflect.defineProperty(obj5, 'pluszero', descMinusZero)); + + +var obj6 = {}; +obj6[1] = 'foo'; +obj6[2] = 'bar'; +obj6[3] = '42'; +obj6[4] = '43'; +obj6[5] = '44'; + +var descElement = { value: 'foobar' }; +var descElementNonConfigurable = { value: 'barfoo', configurable: false }; +var descElementNonWritable = { value: 'foofoo', writable: false }; +var descElementNonEnumerable = { value: 'barbar', enumerable: false }; +var descElementAllFalse = { value: 'foofalse', + configurable: false, + writable: false, + enumerable: false }; + + +// Redefine existing property. +assertTrue(Reflect.defineProperty(obj6, '1', descElement)); +desc = Object.getOwnPropertyDescriptor(obj6, '1'); +assertEquals(desc.value, 'foobar'); +assertTrue(desc.writable); +assertTrue(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(obj6, '2', descElementNonConfigurable)); +desc = Object.getOwnPropertyDescriptor(obj6, '2'); +assertEquals(desc.value, 'barfoo'); +assertTrue(desc.writable); +assertTrue(desc.enumerable); +assertFalse(desc.configurable); + +// Can use defineProperty to change the value of a non +// configurable property. +try { + assertTrue(Reflect.defineProperty(obj6, '2', descElement)); + desc = Object.getOwnPropertyDescriptor(obj6, '2'); + assertEquals(desc.value, 'foobar'); +} catch (e) { + assertUnreachable(); +} + +// Ensure that we can't change the descriptor of a +// non configurable property. +var descAccessor = { get: function() { return 0; } }; +assertFalse(Reflect.defineProperty(obj6, '2', descAccessor)); + +assertTrue(Reflect.defineProperty(obj6, '2', descElementNonWritable)); +desc = Object.getOwnPropertyDescriptor(obj6, '2'); +assertEquals(desc.value, 'foofoo'); +assertFalse(desc.writable); +assertTrue(desc.enumerable); +assertFalse(desc.configurable); + +assertTrue(Reflect.defineProperty(obj6, '3', descElementNonWritable)); +desc = Object.getOwnPropertyDescriptor(obj6, '3'); +assertEquals(desc.value, 'foofoo'); +assertFalse(desc.writable); +assertTrue(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(obj6, '4', descElementNonEnumerable)); +desc = Object.getOwnPropertyDescriptor(obj6, '4'); +assertEquals(desc.value, 'barbar'); +assertTrue(desc.writable); +assertFalse(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(obj6, '5', descElementAllFalse)); +desc = Object.getOwnPropertyDescriptor(obj6, '5'); +assertEquals(desc.value, 'foofalse'); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + +// Define non existing property - all attributes should default to false. +assertTrue(Reflect.defineProperty(obj6, '15', descElement)); +desc = Object.getOwnPropertyDescriptor(obj6, '15'); +assertEquals(desc.value, 'foobar'); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + +// Make sure that we can't redefine using direct access. +obj6[15] ='overwrite'; +assertEquals(obj6[15],'foobar'); + + +// Repeat the above tests on an array. +var arr = new Array(); +arr[1] = 'foo'; +arr[2] = 'bar'; +arr[3] = '42'; +arr[4] = '43'; +arr[5] = '44'; + +var descElement = { value: 'foobar' }; +var descElementNonConfigurable = { value: 'barfoo', configurable: false }; +var descElementNonWritable = { value: 'foofoo', writable: false }; +var descElementNonEnumerable = { value: 'barbar', enumerable: false }; +var descElementAllFalse = { value: 'foofalse', + configurable: false, + writable: false, + enumerable: false }; + + +// Redefine existing property. +assertTrue(Reflect.defineProperty(arr, '1', descElement)); +desc = Object.getOwnPropertyDescriptor(arr, '1'); +assertEquals(desc.value, 'foobar'); +assertTrue(desc.writable); +assertTrue(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(arr, '2', descElementNonConfigurable)); +desc = Object.getOwnPropertyDescriptor(arr, '2'); +assertEquals(desc.value, 'barfoo'); +assertTrue(desc.writable); +assertTrue(desc.enumerable); +assertFalse(desc.configurable); + +// Can use defineProperty to change the value of a non +// configurable property of an array. +try { + assertTrue(Reflect.defineProperty(arr, '2', descElement)); + desc = Object.getOwnPropertyDescriptor(arr, '2'); + assertEquals(desc.value, 'foobar'); +} catch (e) { + assertUnreachable(); +} + +// Ensure that we can't change the descriptor of a +// non configurable property. +var descAccessor = { get: function() { return 0; } }; +assertFalse(Reflect.defineProperty(arr, '2', descAccessor)); + +assertTrue(Reflect.defineProperty(arr, '2', descElementNonWritable)); +desc = Object.getOwnPropertyDescriptor(arr, '2'); +assertEquals(desc.value, 'foofoo'); +assertFalse(desc.writable); +assertTrue(desc.enumerable); +assertFalse(desc.configurable); + +assertTrue(Reflect.defineProperty(arr, '3', descElementNonWritable)); +desc = Object.getOwnPropertyDescriptor(arr, '3'); +assertEquals(desc.value, 'foofoo'); +assertFalse(desc.writable); +assertTrue(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(arr, '4', descElementNonEnumerable)); +desc = Object.getOwnPropertyDescriptor(arr, '4'); +assertEquals(desc.value, 'barbar'); +assertTrue(desc.writable); +assertFalse(desc.enumerable); +assertTrue(desc.configurable); + +// Redefine existing property with configurable: false. +assertTrue(Reflect.defineProperty(arr, '5', descElementAllFalse)); +desc = Object.getOwnPropertyDescriptor(arr, '5'); +assertEquals(desc.value, 'foofalse'); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + +// Define non existing property - all attributes should default to false. +assertTrue(Reflect.defineProperty(arr, '15', descElement)); +desc = Object.getOwnPropertyDescriptor(arr, '15'); +assertEquals(desc.value, 'foobar'); +assertFalse(desc.writable); +assertFalse(desc.enumerable); +assertFalse(desc.configurable); + +// Define non-array property, check that .length is unaffected. +assertEquals(16, arr.length); +assertTrue(Reflect.defineProperty(arr, '0x20', descElement)); +assertEquals(16, arr.length); + +// See issue 968: http://code.google.com/p/v8/issues/detail?id=968 +var o = { x : 42 }; +assertTrue(Reflect.defineProperty(o, "x", { writable: false })); +assertEquals(42, o.x); +o.x = 37; +assertEquals(42, o.x); + +o = { x : 42 }; +assertTrue(Reflect.defineProperty(o, "x", {})); +assertEquals(42, o.x); +o.x = 37; +// Writability is preserved. +assertEquals(37, o.x); + +var o = { }; +assertTrue(Reflect.defineProperty(o, "x", { writable: false })); +assertEquals(undefined, o.x); +o.x = 37; +assertEquals(undefined, o.x); + +o = { get x() { return 87; } }; +assertTrue(Reflect.defineProperty(o, "x", { writable: false })); +assertEquals(undefined, o.x); +o.x = 37; +assertEquals(undefined, o.x); + +// Ignore inherited properties. +o = { __proto__ : { x : 87 } }; +assertTrue(Reflect.defineProperty(o, "x", { writable: false })); +assertEquals(undefined, o.x); +o.x = 37; +assertEquals(undefined, o.x); + +function testDefineProperty(obj, propertyName, desc, resultDesc) { + assertTrue(Reflect.defineProperty(obj, propertyName, desc)); + var actualDesc = Object.getOwnPropertyDescriptor(obj, propertyName); + assertEquals(resultDesc.enumerable, actualDesc.enumerable); + assertEquals(resultDesc.configurable, actualDesc.configurable); + if (resultDesc.hasOwnProperty('value')) { + assertEquals(resultDesc.value, actualDesc.value); + assertEquals(resultDesc.writable, actualDesc.writable); + assertFalse(resultDesc.hasOwnProperty('get')); + assertFalse(resultDesc.hasOwnProperty('set')); + } else { + assertEquals(resultDesc.get, actualDesc.get); + assertEquals(resultDesc.set, actualDesc.set); + assertFalse(resultDesc.hasOwnProperty('value')); + assertFalse(resultDesc.hasOwnProperty('writable')); + } +} + +// tests redefining existing property with a generic descriptor +o = { p : 42 }; +testDefineProperty(o, 'p', + { }, + { value : 42, writable : true, enumerable : true, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : true }, + { value : 42, writable : true, enumerable : true, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { configurable : true }, + { value : 42, writable : true, enumerable : true, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : false }, + { value : 42, writable : true, enumerable : false, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { configurable : false }, + { value : 42, writable : true, enumerable : true, configurable : false }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : true, configurable : true }, + { value : 42, writable : true, enumerable : true, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : false, configurable : true }, + { value : 42, writable : true, enumerable : false, configurable : true }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : true, configurable : false }, + { value : 42, writable : true, enumerable : true, configurable : false }); + +o = { p : 42 }; +testDefineProperty(o, 'p', + { enumerable : false, configurable : false }, + { value : 42, writable : true, enumerable : false, configurable : false }); + +// can make a writable, non-configurable field non-writable +o = { p : 42 }; +assertTrue(Reflect.defineProperty(o, 'p', { configurable: false })); +testDefineProperty(o, 'p', + { writable: false }, + { value : 42, writable : false, enumerable : true, configurable : false }); + +// redefine of get only property with generic descriptor +o = {}; +assertTrue(Reflect.defineProperty(o, 'p', + { get : getter1, enumerable: true, configurable: true })); +testDefineProperty(o, 'p', + { enumerable : false, configurable : false }, + { get: getter1, set: undefined, enumerable : false, configurable : false }); + +// redefine of get/set only property with generic descriptor +o = {}; +assertTrue(Reflect.defineProperty(o, 'p', + { get: getter1, set: setter1, enumerable: true, configurable: true })); +testDefineProperty(o, 'p', + { enumerable : false, configurable : false }, + { get: getter1, set: setter1, enumerable : false, configurable : false }); + +// redefine of set only property with generic descriptor +o = {}; +assertTrue(Reflect.defineProperty(o, 'p', + { set : setter1, enumerable: true, configurable: true })); +testDefineProperty(o, 'p', + { enumerable : false, configurable : false }, + { get: undefined, set: setter1, enumerable : false, configurable : false }); + + +// Regression test: Ensure that growing dictionaries are not ignored. +o = {}; +for (var i = 0; i < 1000; i++) { + // Non-enumerable property forces dictionary mode. + assertTrue(Reflect.defineProperty(o, i, {value: i, enumerable: false})); +} +assertEquals(999, o[999]); + + +// Regression test: Bizzare behavior on non-strict arguments object. +// TODO(yangguo): Tests disabled, needs investigation! +/* +(function test(arg0) { + // Here arguments[0] is a fast alias on arg0. + Reflect.defineProperty(arguments, "0", { + value:1, + enumerable:false + }); + // Here arguments[0] is a slow alias on arg0. + Reflect.defineProperty(arguments, "0", { + value:2, + writable:false + }); + // Here arguments[0] is no alias at all. + Reflect.defineProperty(arguments, "0", { + value:3 + }); + assertEquals(2, arg0); + assertEquals(3, arguments[0]); +})(0); +*/ + +// Regression test: We should never observe the hole value. +var objectWithGetter = {}; +objectWithGetter.__defineGetter__('foo', function() {}); +assertEquals(undefined, objectWithGetter.__lookupSetter__('foo')); + +var objectWithSetter = {}; +objectWithSetter.__defineSetter__('foo', function(x) {}); +assertEquals(undefined, objectWithSetter.__lookupGetter__('foo')); + +// An object with a getter on the prototype chain. +function getter() { return 111; } +function anotherGetter() { return 222; } + +function testGetterOnProto(expected, o) { + assertEquals(expected, o.quebec); +} + +obj1 = {}; +assertTrue( + Reflect.defineProperty(obj1, "quebec", { get: getter, configurable: true })); +obj2 = Object.create(obj1); +obj3 = Object.create(obj2); + +testGetterOnProto(111, obj3); +testGetterOnProto(111, obj3); +%OptimizeFunctionOnNextCall(testGetterOnProto); +testGetterOnProto(111, obj3); +testGetterOnProto(111, obj3); + +assertTrue(Reflect.defineProperty(obj1, "quebec", { get: anotherGetter })); + +testGetterOnProto(222, obj3); +testGetterOnProto(222, obj3); +%OptimizeFunctionOnNextCall(testGetterOnProto); +testGetterOnProto(222, obj3); +testGetterOnProto(222, obj3); + +// An object with a setter on the prototype chain. +var modifyMe; +function setter(x) { modifyMe = x+1; } +function anotherSetter(x) { modifyMe = x+2; } + +function testSetterOnProto(expected, o) { + modifyMe = 333; + o.romeo = 444; + assertEquals(expected, modifyMe); +} + +obj1 = {}; +assertTrue( + Reflect.defineProperty(obj1, "romeo", { set: setter, configurable: true })); +obj2 = Object.create(obj1); +obj3 = Object.create(obj2); + +testSetterOnProto(445, obj3); +testSetterOnProto(445, obj3); +%OptimizeFunctionOnNextCall(testSetterOnProto); +testSetterOnProto(445, obj3); +testSetterOnProto(445, obj3); + +assertTrue(Reflect.defineProperty(obj1, "romeo", { set: anotherSetter })); + +testSetterOnProto(446, obj3); +testSetterOnProto(446, obj3); +%OptimizeFunctionOnNextCall(testSetterOnProto); +testSetterOnProto(446, obj3); +testSetterOnProto(446, obj3); + +// Removing a setter on the prototype chain. +function testSetterOnProtoStrict(o) { + "use strict"; + o.sierra = 12345; +} + +obj1 = {}; +assertTrue(Reflect.defineProperty(obj1, "sierra", + { get: getter, set: setter, configurable: true })); +obj2 = Object.create(obj1); +obj3 = Object.create(obj2); + +testSetterOnProtoStrict(obj3); +testSetterOnProtoStrict(obj3); +%OptimizeFunctionOnNextCall(testSetterOnProtoStrict); +testSetterOnProtoStrict(obj3); +testSetterOnProtoStrict(obj3); + +assertTrue(Reflect.defineProperty(obj1, "sierra", + { get: getter, set: undefined, configurable: true })); + +exception = false; +try { + testSetterOnProtoStrict(obj3); +} catch (e) { + exception = true; + assertTrue(/which has only a getter/.test(e)); +} +assertTrue(exception); + +// Test assignment to a getter-only property on the prototype chain. This makes +// sure that crankshaft re-checks its assumptions and doesn't rely only on type +// feedback (which would be monomorphic here). + +function Assign(o) { + o.blubb = 123; +} + +function C() {} + +Assign(new C); +Assign(new C); +%OptimizeFunctionOnNextCall(Assign); +assertTrue( + Reflect.defineProperty(C.prototype, "blubb", {get: function() {return -42}})); +Assign(new C); + +// Test that changes to the prototype of a simple constructor are not ignored, +// even after creating initial instances. +function C() { + this.x = 23; +} +assertEquals(23, new C().x); +C.prototype.__defineSetter__('x', function(value) { this.y = 23; }); +assertEquals(void 0, new C().x); diff --git a/deps/v8/test/mjsunit/regress/regress-2285.js b/deps/v8/test/mjsunit/harmony/reflect-enumerate-delete.js index a0d628df93..1137d8a0a4 100644 --- a/deps/v8/test/mjsunit/regress/regress-2285.js +++ b/deps/v8/test/mjsunit/harmony/reflect-enumerate-delete.js @@ -1,4 +1,4 @@ -// Copyright 2012 the V8 project authors. All rights reserved. +// Copyright 2010-2015 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: @@ -25,7 +25,29 @@ // (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 +// Test that properties deleted during an enumeration do not show up in +// the enumeration. This is adapted from mjsunit/for-in-delete.js. -assertThrows(function() { %_CallFunction(null, 0, ""); }); -assertThrows(function() { %_CallFunction(null, 0, 1); }); +// Flags: --harmony-reflect + + +function f(o, expected, del) { + var index = 0; + for (p of Reflect.enumerate(o)) { + if (del) delete o[del]; + assertEquals(expected[index], p); + index++; + } + assertEquals(expected.length, index); +} + +var o = {} +o.a = 1; +o.b = 2; +o.c = 3; +o.d = 3; + +f(o, ['a', 'b', 'c', 'd']); +f(o, ['a', 'b', 'c', 'd']); +f(o, ['a', 'c', 'd'], 'b'); +f(o, ['a', 'c'], 'd'); diff --git a/deps/v8/test/mjsunit/harmony/reflect-enumerate-opt.js b/deps/v8/test/mjsunit/harmony/reflect-enumerate-opt.js new file mode 100644 index 0000000000..34cd660c8f --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-enumerate-opt.js @@ -0,0 +1,77 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This is adapted from mjsunit/for-in-opt.js. + +// Flags: --harmony-proxies --harmony-reflect --allow-natives-syntax + + +"use strict"; + +function f(o) { + var result = []; + for (var i of Reflect.enumerate(Object(o))) { + result.push(i); + } + return result; +} + +assertEquals(["0"], f("a")); +assertEquals(["0"], f("a")); +%OptimizeFunctionOnNextCall(f); +assertEquals(["0","1","2"], f("bla")); + +// Test the lazy deopt points. +var keys = ["a", "b", "c", "d"]; +var has_keys = []; +var deopt_has = false; +var deopt_enum = false; + +var handler = { + enumerate: function(target) { + if (deopt_enum) { + %DeoptimizeFunction(f2); + deopt_enum = false; + } + return keys; + }, + + getPropertyDescriptor: function(k) { + if (deopt_has) { + %DeoptimizeFunction(f2); + deopt_has = false; + } + has_keys.push(k); + return {value: 10, configurable: true, writable: false, enumerable: true}; + } +}; + + +var proxy = Proxy.create(handler); +var o = {__proto__: proxy}; + +function f2(o) { + var result = []; + for (var i of Reflect.enumerate(o)) { + result.push(i); + } + return result; +} + +function check_f2() { + assertEquals(keys, f2(o)); + assertEquals(keys, has_keys); + has_keys.length = 0; +} + +check_f2(); +check_f2(); +// Test lazy deopt after GetPropertyNamesFast +%OptimizeFunctionOnNextCall(f2); +deopt_enum = true; +check_f2(); +// Test lazy deopt after FILTER_KEY +%OptimizeFunctionOnNextCall(f2); +deopt_has = true; +check_f2(); diff --git a/deps/v8/test/mjsunit/harmony/reflect-enumerate-special-cases.js b/deps/v8/test/mjsunit/harmony/reflect-enumerate-special-cases.js new file mode 100644 index 0000000000..234a3e3e0d --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-enumerate-special-cases.js @@ -0,0 +1,88 @@ +// Copyright 2008-2015 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. + +// This is adapted from mjsunit/for-in-special-cases.js. + +// Flags: --harmony-reflect + + +function Accumulate(x) { + var accumulator = ""; + for (var i of Reflect.enumerate(Object(x))) { + accumulator += i; + } + return accumulator; +} + +for (var i = 0; i < 3; ++i) { + var elements = Accumulate("abcd"); + // We do not assume that enumerate enumerates elements in order. + assertTrue(-1 != elements.indexOf("0")); + assertTrue(-1 != elements.indexOf("1")); + assertTrue(-1 != elements.indexOf("2")); + assertTrue(-1 != elements.indexOf("3")); + assertEquals(4, elements.length); +} + +function for_in_string_prototype() { + + var x = new String("abc"); + x.foo = 19; + function B() { + this.bar = 5; + this[7] = 4; + } + B.prototype = x; + + var y = new B(); + y.gub = 13; + + var elements = Accumulate(y); + var elements1 = Accumulate(y); + // If enumerate returns elements in a different order on multiple calls, this + // assert will fail. If that happens, consider if that behavior is OK. + assertEquals(elements, elements1, "Enumeration not the same both times."); + // We do not assume that enumerate enumerates elements in order. + assertTrue(-1 != elements.indexOf("0")); + assertTrue(-1 != elements.indexOf("1")); + assertTrue(-1 != elements.indexOf("2")); + assertTrue(-1 != elements.indexOf("7")); + assertTrue(-1 != elements.indexOf("foo")); + assertTrue(-1 != elements.indexOf("bar")); + assertTrue(-1 != elements.indexOf("gub")); + assertEquals(13, elements.length); + + elements = Accumulate(x); + assertTrue(-1 != elements.indexOf("0")); + assertTrue(-1 != elements.indexOf("1")); + assertTrue(-1 != elements.indexOf("2")); + assertTrue(-1 != elements.indexOf("foo")); + assertEquals(6, elements.length); +} + +for_in_string_prototype(); +for_in_string_prototype(); diff --git a/deps/v8/test/mjsunit/harmony/reflect-enumerate.js b/deps/v8/test/mjsunit/harmony/reflect-enumerate.js new file mode 100644 index 0000000000..bbc364e7b9 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-enumerate.js @@ -0,0 +1,101 @@ +// Copyright 2008-2015 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. + +// This is adapted from mjsunit/for-in.js. + +// Flags: --harmony-reflect + + +function props(x) { + var array = []; + for (var p of Reflect.enumerate(x)) array.push(p); + return array.sort(); +} + +assertEquals(0, props({}).length, "olen0"); +assertEquals(1, props({x:1}).length, "olen1"); +assertEquals(2, props({x:1, y:2}).length, "olen2"); + +assertArrayEquals(["x"], props({x:1}), "x"); +assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); +assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); + +assertEquals(0, props([]).length, "alen0"); +assertEquals(1, props([1]).length, "alen1"); +assertEquals(2, props([1,2]).length, "alen2"); + +assertArrayEquals(["0"], props([1]), "0"); +assertArrayEquals(["0", "1"], props([1,2]), "01"); +assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012"); + +var o = {}; +var a = []; +for (var i = 0x0020; i < 0x01ff; i+=2) { + var s = 'char:' + String.fromCharCode(i); + a.push(s); + o[s] = i; +} +assertArrayEquals(a, props(o), "charcodes"); + +var a = []; +assertEquals(0, props(a).length, "proplen0"); +a[Math.pow(2,30)-1] = 0; +assertEquals(1, props(a).length, "proplen1"); +a[Math.pow(2,31)-1] = 0; +assertEquals(2, props(a).length, "proplen2"); +a[1] = 0; +assertEquals(3, props(a).length, "proplen3"); + +var result = ''; +for (var p of Reflect.enumerate({a : [0], b : 1})) { result += p; } +assertEquals('ab', result, "ab"); + +var result = ''; +for (var p of Reflect.enumerate({a : {v:1}, b : 1})) { result += p; } +assertEquals('ab', result, "ab-nodeep"); + +var result = ''; +for (var p of Reflect.enumerate({ get a() {}, b : 1})) { result += p; } +assertEquals('ab', result, "abget"); + +var result = ''; +for (var p of Reflect.enumerate({ get a() {}, set a(x) {}, b : 1})) { + result += p; +} +assertEquals('ab', result, "abgetset"); + +(function() { + var large_key = 2147483650; + var o = {__proto__: {}}; + o[large_key] = 1; + o.__proto__[large_key] = 1; + var keys = []; + for (var k of Reflect.enumerate(o)) { + keys.push(k); + } + assertEquals(["2147483650"], keys); +})(); diff --git a/deps/v8/test/mjsunit/harmony/reflect-get-own-property-descriptor.js b/deps/v8/test/mjsunit/harmony/reflect-get-own-property-descriptor.js new file mode 100644 index 0000000000..3cbffea78b --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-get-own-property-descriptor.js @@ -0,0 +1,123 @@ +// Copyright 2015 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. + +// This file only tests very simple descriptors that always have +// configurable, enumerable, and writable set to true. + +// This is adapted from mjsunit/get-own-property-descriptor.js. + +// Flags: --harmony-reflect + +function get() { return x; } +function set(x) { this.x = x; } + +var obj = {x: 1}; +obj.__defineGetter__("accessor", get); +obj.__defineSetter__("accessor", set); +var a = new Array(); +a[1] = 42; +obj[1] = 42; + +var descIsData = Reflect.getOwnPropertyDescriptor(obj, 'x'); +assertTrue(descIsData.enumerable); +assertTrue(descIsData.writable); +assertTrue(descIsData.configurable); + +var descIsAccessor = Reflect.getOwnPropertyDescriptor(obj, 'accessor'); +assertTrue(descIsAccessor.enumerable); +assertTrue(descIsAccessor.configurable); +assertTrue(descIsAccessor.get == get); +assertTrue(descIsAccessor.set == set); + +var descIsNotData = Reflect.getOwnPropertyDescriptor(obj, 'not-x'); +assertTrue(descIsNotData == undefined); + +var descIsNotAccessor = Reflect.getOwnPropertyDescriptor(obj, 'not-accessor'); +assertTrue(descIsNotAccessor == undefined); + +var descArray = Reflect.getOwnPropertyDescriptor(a, '1'); +assertTrue(descArray.enumerable); +assertTrue(descArray.configurable); +assertTrue(descArray.writable); +assertEquals(descArray.value, 42); + +var descObjectElement = Reflect.getOwnPropertyDescriptor(obj, '1'); +assertTrue(descObjectElement.enumerable); +assertTrue(descObjectElement.configurable); +assertTrue(descObjectElement.writable); +assertEquals(descObjectElement.value, 42); + +// String objects. +var a = new String('foobar'); +for (var i = 0; i < a.length; i++) { + var descStringObject = Reflect.getOwnPropertyDescriptor(a, i); + assertTrue(descStringObject.enumerable); + assertFalse(descStringObject.configurable); + assertFalse(descStringObject.writable); + assertEquals(descStringObject.value, a.substring(i, i+1)); +} + +// Support for additional attributes on string objects. +a.x = 42; +a[10] = 'foo'; +var descStringProperty = Reflect.getOwnPropertyDescriptor(a, 'x'); +assertTrue(descStringProperty.enumerable); +assertTrue(descStringProperty.configurable); +assertTrue(descStringProperty.writable); +assertEquals(descStringProperty.value, 42); + +var descStringElement = Reflect.getOwnPropertyDescriptor(a, '10'); +assertTrue(descStringElement.enumerable); +assertTrue(descStringElement.configurable); +assertTrue(descStringElement.writable); +assertEquals(descStringElement.value, 'foo'); + +// Test that elements in the prototype chain is not returned. +var proto = {}; +proto[10] = 42; + +var objWithProto = new Array(); +objWithProto.prototype = proto; +objWithProto[0] = 'bar'; +var descWithProto = Reflect.getOwnPropertyDescriptor(objWithProto, '10'); +assertEquals(undefined, descWithProto); + +// Test elements on global proxy object. +var global = (function() { return this; })(); + +global[42] = 42; + +function el_getter() { return 239; }; +function el_setter() {}; +Object.defineProperty(global, '239', {get: el_getter, set: el_setter}); + +var descRegularElement = Reflect.getOwnPropertyDescriptor(global, '42'); +assertEquals(42, descRegularElement.value); + +var descAccessorElement = Reflect.getOwnPropertyDescriptor(global, '239'); +assertEquals(el_getter, descAccessorElement.get); +assertEquals(el_setter, descAccessorElement.set); diff --git a/deps/v8/test/mjsunit/harmony/reflect-get-prototype-of.js b/deps/v8/test/mjsunit/harmony/reflect-get-prototype-of.js new file mode 100644 index 0000000000..1ce86347df --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-get-prototype-of.js @@ -0,0 +1,139 @@ +// Copyright 2010-2015 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. + +// Tests the Reflect.getPrototypeOf - ES6 26.1.8. +// This is adapted from mjsunit/get-prototype-of.js. + +// Flags: --harmony-reflect + + + +function assertPrototypeOf(func, expected) { + assertEquals(expected, Reflect.getPrototypeOf(func)); +} + + +assertThrows(function() { + Reflect.getPrototypeOf(undefined); +}, TypeError); + + +assertThrows(function() { + Reflect.getPrototypeOf(null); +}, TypeError); + + +function F(){}; +var y = new F(); + +assertPrototypeOf(y, F.prototype); +assertPrototypeOf(F, Function.prototype); + +assertPrototypeOf({x: 5}, Object.prototype); +assertPrototypeOf({x: 5, __proto__: null}, null); + +assertPrototypeOf([1, 2], Array.prototype); + + +assertThrows(function () { + Reflect.getPrototypeOf(1); +}, TypeError); +assertThrows(function () { + Reflect.getPrototypeOf(true); +}, TypeError); +assertThrows(function () { + Reflect.getPrototypeOf(false); +}, TypeError); +assertThrows(function () { + Reflect.getPrototypeOf('str'); +}, TypeError); +assertThrows(function () { + Reflect.getPrototypeOf(Symbol()); +}, TypeError); + +assertPrototypeOf(Object(1), Number.prototype); +assertPrototypeOf(Object(true), Boolean.prototype); +assertPrototypeOf(Object(false), Boolean.prototype); +assertPrototypeOf(Object('str'), String.prototype); +assertPrototypeOf(Object(Symbol()), Symbol.prototype); + + +var errorFunctions = [ + EvalError, + RangeError, + ReferenceError, + SyntaxError, + TypeError, + URIError, +]; + +for (var f of errorFunctions) { + assertPrototypeOf(f, Error); + assertPrototypeOf(new f(), f.prototype); +} + + +// Builtin constructors. +var functions = [ + Array, + ArrayBuffer, + Boolean, + // DataView, + Date, + Error, + Float32Array, + Float64Array, + Function, + Int16Array, + Int32Array, + Int8Array, + Map, + Number, + Object, + // Promise, + RegExp, + Set, + String, + // Symbol, not constructible + Uint16Array, + Uint32Array, + Uint8Array, + Uint8ClampedArray, + WeakMap, + WeakSet, +]; + +for (var f of functions) { + assertPrototypeOf(f, Function.prototype); + assertPrototypeOf(new f(), f.prototype); +} + +var p = new Promise(function() {}); +assertPrototypeOf(p, Promise.prototype); + +var dv = new DataView(new ArrayBuffer()); +assertPrototypeOf(dv, DataView.prototype); diff --git a/deps/v8/test/mjsunit/harmony/reflect-prevent-extensions.js b/deps/v8/test/mjsunit/harmony/reflect-prevent-extensions.js new file mode 100644 index 0000000000..a964ed7b2d --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-prevent-extensions.js @@ -0,0 +1,164 @@ +// Copyright 2010-2015 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. + +// Tests the Reflect.preventExtensions method - ES6 26.1.12. +// This is adapted from object-prevent-extensions.js. + +// Flags: --allow-natives-syntax --harmony-reflect + + +var obj1 = {}; +// Extensible defaults to true. +assertTrue(Object.isExtensible(obj1)); +assertTrue(Reflect.preventExtensions(obj1)); + +// Make sure the is_extensible flag is set. +assertFalse(Object.isExtensible(obj1)); +obj1.x = 42; +assertEquals(undefined, obj1.x); + +// Try adding a new element. +obj1[1] = 42; +assertEquals(undefined, obj1[1]); + + +// Try when the object has an existing property. +var obj2 = {}; +assertTrue(Object.isExtensible(obj2)); +obj2.x = 42; +assertEquals(42, obj2.x); +assertTrue(Object.isExtensible(obj2)); + +assertTrue(Reflect.preventExtensions(obj2)); +assertEquals(42, obj2.x); + +obj2.y = 42; +// obj2.y should still be undefined. +assertEquals(undefined, obj2.y); +// Make sure we can still write values to obj.x. +obj2.x = 43; +assertEquals(43, obj2.x) + +obj2.y = new function() { return 42; }; +// obj2.y should still be undefined. +assertEquals(undefined, obj2.y); +assertEquals(43, obj2.x) + +try { + Object.defineProperty(obj2, "y", {value: 42}); +} catch (e) { + assertTrue(/object is not extensible/.test(e)); +} + +// obj2.y should still be undefined. +assertEquals(undefined, obj2.y); +assertEquals(43, obj2.x); + +obj2[1] = 42; +assertEquals(undefined, obj2[1]); + +var arr = new Array(); +arr[1] = 10; + +assertTrue(Reflect.preventExtensions(arr)); + +arr[2] = 42; +assertEquals(10, arr[1]); + +// We should still be able to change existing elements. +arr[1]= 42; +assertEquals(42, arr[1]); + + +// Test the the extensible flag is not inherited. +var parent = {}; +parent.x = 42; +assertTrue(Reflect.preventExtensions(parent)); + +var child = Object.create(parent); + +// We should be able to add new properties to the child object. +child.y = 42; + +// This should have no influence on the parent class. +parent.y = 29; + + +// Test that attributes on functions are also handled correctly. +function foo() { + return 42; +} + +assertTrue(Reflect.preventExtensions(foo)); + +foo.x = 29; +assertEquals(undefined, foo.x); + +// when Object.isExtensible(o) === false +// assignment should return right hand side value +var o = {}; +assertTrue(Reflect.preventExtensions(o)); +var v = o.v = 50; +assertEquals(undefined, o.v); +assertEquals(50, v); + +// test same behavior as above, but for integer properties +var n = o[0] = 100; +assertEquals(undefined, o[0]); +assertEquals(100, n); + +// Fast properties should remain fast +obj = { x: 42, y: 'foo' }; +assertTrue(%HasFastProperties(obj)); +assertTrue(Reflect.preventExtensions(obj)); +assertFalse(Object.isExtensible(obj)); +assertFalse(Object.isSealed(obj)); +assertTrue(%HasFastProperties(obj)); + +// Non-extensible objects should share maps where possible +obj = { prop1: 1, prop2: 2 }; +obj2 = { prop1: 3, prop2: 4 }; +assertTrue(%HaveSameMap(obj, obj2)); +assertTrue(Reflect.preventExtensions(obj)); +assertTrue(Reflect.preventExtensions(obj2)); +assertFalse(Object.isExtensible(obj)); +assertFalse(Object.isExtensible(obj2)); +assertFalse(Object.isSealed(obj)); +assertFalse(Object.isSealed(obj2)); +assertTrue(%HaveSameMap(obj, obj2)); + +// Non-extensible objects should share maps even when they have elements +obj = { prop1: 1, prop2: 2, 75: 'foo' }; +obj2 = { prop1: 3, prop2: 4, 150: 'bar' }; +assertTrue(%HaveSameMap(obj, obj2)); +assertTrue(Reflect.preventExtensions(obj)); +assertTrue(Reflect.preventExtensions(obj2)); +assertFalse(Object.isExtensible(obj)); +assertFalse(Object.isExtensible(obj2)); +assertFalse(Object.isSealed(obj)); +assertFalse(Object.isSealed(obj2)); +assertTrue(%HaveSameMap(obj, obj2)); diff --git a/deps/v8/test/mjsunit/harmony/reflect-set-prototype-of.js b/deps/v8/test/mjsunit/harmony/reflect-set-prototype-of.js new file mode 100644 index 0000000000..0e5554e907 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect-set-prototype-of.js @@ -0,0 +1,184 @@ +// Copyright 2014-2015 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. + +// This is adapted from mjsunit/harmony/set-prototype-of.js. + +// Flags: --harmony-reflect + + + +function getObjects() { + function func() {} + return [ + func, + new func(), + {x: 5}, + /regexp/, + ['array'], + // new Error(), + new Date(), + new Number(1), + new Boolean(true), + new String('str'), + Object(Symbol()) + ]; +} + + +var coercibleValues = [ + 1, + true, + 'string', + Symbol() +]; + + +var nonCoercibleValues = [ + undefined, + null +]; + + +var valuesWithoutNull = coercibleValues.concat(undefined); + + +function TestSetPrototypeOfCoercibleValues() { + for (var i = 0; i < coercibleValues.length; i++) { + var value = coercibleValues[i]; + var proto = Object.getPrototypeOf(value); + assertThrows(function() { Reflect.setPrototypeOf(value, {}) }, TypeError); + assertSame(proto, Object.getPrototypeOf(value)); + } +} +TestSetPrototypeOfCoercibleValues(); + + +function TestSetPrototypeOfNonCoercibleValues() { + for (var i = 0; i < nonCoercibleValues.length; i++) { + var value = nonCoercibleValues[i]; + assertThrows(function() { + Reflect.setPrototypeOf(value, {}); + }, TypeError); + } +} +TestSetPrototypeOfNonCoercibleValues(); + + +function TestSetPrototypeToNonObject(proto) { + var objects = getObjects(); + for (var i = 0; i < objects.length; i++) { + var object = objects[i]; + for (var j = 0; j < valuesWithoutNull.length; j++) { + var proto = valuesWithoutNull[j]; + assertThrows(function() { + Reflect.setPrototypeOf(object, proto); + }, TypeError); + } + } +} +TestSetPrototypeToNonObject(); + + +function TestSetPrototypeOf(object, proto) { + assertTrue(Reflect.setPrototypeOf(object, proto)); + assertEquals(Object.getPrototypeOf(object), proto); +} + + +function TestSetPrototypeOfForObjects() { + var objects1 = getObjects(); + var objects2 = getObjects(); + for (var i = 0; i < objects1.length; i++) { + for (var j = 0; j < objects2.length; j++) { + TestSetPrototypeOf(objects1[i], objects2[j]); + } + } +} +TestSetPrototypeOfForObjects(); + + +function TestSetPrototypeToNull() { + var objects = getObjects(); + for (var i = 0; i < objects.length; i++) { + TestSetPrototypeOf(objects[i], null); + } +} +TestSetPrototypeToNull(); + + +function TestSetPrototypeOfNonExtensibleObject() { + var objects = getObjects(); + var proto = {}; + for (var i = 0; i < objects.length; i++) { + var object = objects[i]; + Object.preventExtensions(object); + // Setting the current prototype must succeed. + assertTrue(Reflect.setPrototypeOf(object, Object.getPrototypeOf(object))); + // Setting any other must fail. + assertFalse(Reflect.setPrototypeOf(object, proto)); + } +} +TestSetPrototypeOfNonExtensibleObject(); + + +function TestSetPrototypeCyclic() { + var objects = [ + Object.prototype, {}, + Array.prototype, [], + Error.prototype, new TypeError, + // etc ... + ]; + for (var i = 0; i < objects.length; i += 2) { + var object = objects[i]; + var value = objects[i + 1]; + assertFalse(Reflect.setPrototypeOf(object, value)); + } +} +TestSetPrototypeCyclic(); + + +function TestLookup() { + var object = {}; + assertFalse('x' in object); + assertFalse('y' in object); + + var oldProto = { + x: 'old x', + y: 'old y' + }; + assertTrue(Reflect.setPrototypeOf(object, oldProto)); + assertEquals(object.x, 'old x'); + assertEquals(object.y, 'old y'); + + var newProto = { + x: 'new x' + }; + assertTrue(Reflect.setPrototypeOf(object, newProto)); + assertEquals(object.x, 'new x'); + assertFalse('y' in object); +} +TestLookup(); diff --git a/deps/v8/test/mjsunit/harmony/reflect.js b/deps/v8/test/mjsunit/harmony/reflect.js new file mode 100644 index 0000000000..a3d44b8916 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/reflect.js @@ -0,0 +1,561 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-reflect + +// TODO(neis): Test with proxies. + + + +//////////////////////////////////////////////////////////////////////////////// +// (Auxiliaries) + + +"use strict"; + +var global = this; + +var sym = Symbol("gaga"); + +var objects = [ + {}, + [], + function() {}, + function() { + return arguments; + }(), + function() { + 'use strict'; + return arguments; + }(), + Object(1), + Object(true), + Object('bla'), + new Date, + new RegExp, + new Set, + new Map, + new WeakMap, + new WeakSet, + new ArrayBuffer(10), + new Int32Array(5), + Object, + Function, + Date, + RegExp, + global +]; + +function prepare(target) { + target["bla"] = true; + target[4] = 42; + target[sym] = "foo"; + target["noconf"] = 43; + Object.defineProperty(target, "noconf", + { configurable: false }); + Object.defineProperty(target, "nowrite", + { writable: false, configurable: true, value: 44 }); + Object.defineProperty(target, "getter", + { get: function () {return this.bla}, configurable: true }); + Object.defineProperty(target, "setter", + { set: function (x) {this.gaga = x}, configurable: true }); + Object.defineProperty(target, "setter2", + { set: function (x) {}, configurable: true }); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.get + + +(function testReflectGetArity() { + assertEquals(3, Reflect.get.length); +})(); + + +(function testReflectGetOnNonObject() { + assertThrows(function() { Reflect.get(); }, TypeError); + assertThrows(function() { Reflect.get(42, "bla"); }, TypeError); + assertThrows(function() { Reflect.get(null, "bla"); }, TypeError); +})(); + + +(function testReflectGetKeyConversion() { + var target = {bla: 42}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertEquals(42, Reflect.get(target, a)); + assertThrows(function() { Reflect.get(target, b); }, "gaga"); +})(); + + +(function testReflectGetOnObject() { + var receiver = {bla: false}; + for (let target of objects) { + prepare(target); + assertEquals(true, Reflect.get(target, "bla")); + assertEquals(true, Reflect.get(target, "bla", target)); + assertEquals(true, Reflect.get(target, "bla", receiver)); + assertEquals(42, Reflect.get(target, 4)); + assertEquals(42, Reflect.get(target, 4, target)); + assertEquals(42, Reflect.get(target, 4, receiver)); + assertEquals(42, Reflect.get(target, "4")); + assertEquals(42, Reflect.get(target, "4", target)); + assertEquals(42, Reflect.get(target, "4", receiver)); + assertEquals("foo", Reflect.get(target, sym)); + assertEquals("foo", Reflect.get(target, sym, target)); + assertEquals("foo", Reflect.get(target, sym, receiver)); + assertEquals(43, Reflect.get(target, "noconf")); + assertEquals(43, Reflect.get(target, "noconf", target)); + assertEquals(43, Reflect.get(target, "noconf", receiver)); + assertEquals(true, Reflect.get(target, "getter")); + assertEquals(true, Reflect.get(target, "getter", target)); + assertEquals(false, Reflect.get(target, "getter", receiver)); + assertEquals(undefined, Reflect.get(target, "setter")); + assertEquals(undefined, Reflect.get(target, "setter", target)); + assertEquals(undefined, Reflect.get(target, "setter", receiver)); + assertEquals(undefined, Reflect.get(target, "foo")); + assertEquals(undefined, Reflect.get(target, "foo", target)); + assertEquals(undefined, Reflect.get(target, "foo", receiver)); + assertEquals(undefined, Reflect.get(target, 666)); + assertEquals(undefined, Reflect.get(target, 666, target)); + assertEquals(undefined, Reflect.get(target, 666, receiver)); + + let proto = target.__proto__; + target.__proto__ = { get foo() {return this.bla} }; + assertEquals(true, Reflect.get(target, "foo")); + assertEquals(true, Reflect.get(target, "foo", target)); + assertEquals(false, Reflect.get(target, "foo", receiver)); + target.__proto__ = proto; + } +})(); + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.set + + +(function testReflectSetArity() { + assertEquals(3, Reflect.set.length); +})(); + + +(function testReflectSetOnNonObject() { + assertThrows(function() { Reflect.set(); }, TypeError); + assertThrows(function() { Reflect.set(42, "bla"); }, TypeError); + assertThrows(function() { Reflect.set(null, "bla"); }, TypeError); +})(); + + +(function testReflectSetKeyConversion() { + var target = {}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertTrue(Reflect.set(target, a, 42)); + assertEquals(42, target.bla); + assertThrows(function() { Reflect.set(target, b, 42); }, "gaga"); +})(); + + +(function testReflectSetOnObject() { + var receiver = {bla: false}; + var value = 34234; + for (let target of objects) { + prepare(target); + assertTrue(Reflect.set(target, "bla", value)); + assertEquals(value, target.bla); + + prepare(target); + assertTrue(Reflect.set(target, "bla", value, target)); + assertEquals(value, target.bla); + + prepare(target); + assertTrue(Reflect.set(target, "bla", value, receiver)); + assertEquals(true, target.bla); + assertEquals(value, receiver.bla); + receiver.bla = false; + + prepare(target); + assertTrue(Reflect.set(target, 4, value)); + assertEquals(value, target[4]); + + prepare(target); + assertTrue(Reflect.set(target, 4, value, target)); + assertEquals(value, target[4]); + + prepare(target); + assertTrue(Reflect.set(target, 4, value, receiver)); + assertEquals(42, target[4]); + assertEquals(value, receiver[4]); + delete receiver[4]; + + prepare(target); + assertTrue(Reflect.set(target, sym, value)); + assertEquals(value, target[sym]); + + prepare(target); + assertTrue(Reflect.set(target, sym, value, target)); + assertEquals(value, target[sym]); + + prepare(target); + assertTrue(Reflect.set(target, sym, value, receiver)); + assertEquals("foo", target[sym]); + assertEquals(value, receiver[sym]); + delete receiver[sym]; + + prepare(target); + assertTrue(Reflect.set(target, "noconf", value)); + assertEquals(value, target.noconf); + + prepare(target); + assertTrue(Reflect.set(target, "noconf", value, target)); + assertEquals(value, target.noconf); + + prepare(target); + assertTrue(Reflect.set(target, "noconf", value, receiver)); + assertEquals(43, target.noconf); + assertEquals(value, receiver.noconf); + delete receiver.noconf; + + assertTrue(Reflect.set(target, "setter", value)); + assertEquals(value, target.gaga) + delete target.gaga; + + assertTrue(Reflect.set(target, "setter", value, target)); + assertEquals(value, target.gaga) + delete target.gaga; + + assertTrue(Reflect.set(target, "setter", value, receiver)); + assertFalse("gaga" in target); + assertEquals(value, receiver.gaga); + delete receiver.gaga; + + assertFalse(Reflect.set(target, "nowrite", value)); + assertEquals(44, target.nowrite); + + assertFalse(Reflect.set(target, "nowrite", value, target)); + assertEquals(44, target.nowrite); + + assertFalse(Reflect.set(target, "nowrite", value, receiver)); + assertEquals(44, target.nowrite); + assertFalse("nowrite" in receiver); + + // Data vs Non-Writable + assertFalse(Reflect.set({}, "nowrite", value, target)); + + // Data vs Accessor + assertFalse(Reflect.set({}, "unknown", 0, {set unknown(x) {}})); + assertFalse(Reflect.set(target, "unknown", value, {set unknown(x) {}})); + assertFalse(Reflect.set(target, "bla", value, {set bla(x) {}})); + assertFalse(Reflect.set(target, "bla", value, {get bla() {}})); + + // Accessor vs Data + assertTrue(Reflect.set({set bla(x) {}}), "bla", value, target); + assertFalse(Reflect.set({get bla() {}}, "bla", value, target)); + + // Data vs Non-Object + assertFalse(Reflect.set({}, "bla", value, null)); + assertFalse(Reflect.set({bla: 42}, "bla", value, null)); + + // Accessor vs Non-Object + assertTrue(Reflect.set(target, "setter2", value, null)); + assertFalse(Reflect.set(target, "getter", value, null)); + + let receiver2 = {}; + Object.defineProperty(receiver2, "bla", + {configurable: false, writable: true, value: true}); + Object.defineProperty(receiver2, "not_in_target", + {configurable: false, writable: true, value: true}); + assertTrue(Reflect.set(target, "bla", value, receiver2)); + assertTrue(Reflect.set(target, "not_in_target", value, receiver2)); + } +})(); + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.has + + +(function testReflectHasArity() { + assertEquals(2, Reflect.has.length); +})(); + + +(function testReflectHasOnNonObject() { + assertThrows(function() { Reflect.has(); }, TypeError); + assertThrows(function() { Reflect.has(42, "bla"); }, TypeError); + assertThrows(function() { Reflect.has(null, "bla"); }, TypeError); +})(); + + +(function testReflectHasKeyConversion() { + var target = {bla: 42}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertTrue(Reflect.has(target, a)); + assertThrows(function() { Reflect.has(target, b); }, "gaga"); +})(); + + +(function testReflectHasOnObject() { + for (let target of objects) { + prepare(target); + assertTrue(Reflect.has(target, "bla")); + assertTrue(Reflect.has(target, 4)); + assertTrue(Reflect.has(target, "4")); + assertTrue(Reflect.has(target, sym)); + assertTrue(Reflect.has(target, "noconf")); + assertTrue(Reflect.has(target, "getter")); + assertTrue(Reflect.has(target, "setter")); + assertFalse(Reflect.has(target, "foo")); + assertFalse(Reflect.has(target, 666)); + + let proto = target.__proto__; + target.__proto__ = { get foo() {return this.bla} }; + assertEquals(true, Reflect.has(target, "foo")); + target.__proto__ = proto; + } +})(); + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.defineProperty + + +(function testReflectDefinePropertyArity() { + assertEquals(3, Reflect.defineProperty.length); +})(); + + +(function testReflectDefinePropertyOnNonObject() { + assertThrows(function() { Reflect.defineProperty(); }, TypeError); + assertThrows(function() { Reflect.defineProperty(42, "bla"); }, TypeError); + assertThrows(function() { Reflect.defineProperty(null, "bla"); }, TypeError); + assertThrows(function() { Reflect.defineProperty({}, "bla"); }, TypeError); + assertThrows(function() { Reflect.defineProperty({}, "bla", 42); }, + TypeError); + assertThrows(function() { Reflect.defineProperty({}, "bla", null); }, + TypeError); +})(); + + +(function testReflectDefinePropertyKeyConversion() { + var target = {}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertTrue(Reflect.defineProperty(target, a, {value: 42})); + assertEquals(target.bla, 42); + assertThrows(function() { Reflect.defineProperty(target, b); }, "gaga"); +})(); + + +// See reflect-define-property.js for further tests. + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.deleteProperty + + +(function testReflectDeletePropertyArity() { + assertEquals(2, Reflect.deleteProperty.length); +})(); + + +(function testReflectDeletePropertyOnNonObject() { + assertThrows(function() { Reflect.deleteProperty(); }, TypeError); + assertThrows(function() { Reflect.deleteProperty(42, "bla"); }, TypeError); + assertThrows(function() { Reflect.deleteProperty(null, "bla"); }, TypeError); +})(); + + +(function testReflectDeletePropertyKeyConversion() { + var target = {bla: 42}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertTrue(Reflect.deleteProperty(target, a)); + assertThrows(function() { Reflect.deleteProperty(target, b); }, "gaga"); +})(); + + +(function testReflectDeletePropertyOnObject() { + for (let target of objects) { + prepare(target); + assertTrue(Reflect.deleteProperty(target, "bla")); + assertEquals(undefined, Object.getOwnPropertyDescriptor(target, "bla")); + if (target instanceof Int32Array) { + assertFalse(Reflect.deleteProperty(target, 4)); + } else { + assertTrue(Reflect.deleteProperty(target, 4)); + assertEquals(undefined, Object.getOwnPropertyDescriptor(target, 4)); + } + assertTrue(Reflect.deleteProperty(target, sym)); + assertEquals(undefined, Object.getOwnPropertyDescriptor(target, sym)); + assertFalse(Reflect.deleteProperty(target, "noconf")); + assertEquals(43, target.noconf); + assertTrue(Reflect.deleteProperty(target, "getter")); + assertTrue(Reflect.deleteProperty(target, "setter")); + assertTrue(Reflect.deleteProperty(target, "foo")); + assertTrue(Reflect.deleteProperty(target, 666)); + + let proto = target.__proto__; + target.__proto__ = { get foo() {return this.bla} }; + assertEquals(true, Reflect.deleteProperty(target, "foo")); + target.__proto__ = proto; + } +})(); + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.getPrototypeOf + + +(function testReflectGetPrototypeOfArity() { + assertEquals(1, Reflect.getPrototypeOf.length); +})(); + + +(function testReflectGetPrototypeOnNonObject() { + assertThrows(function() { Reflect.getPrototypeOf(); }, TypeError); + assertThrows(function() { Reflect.getPrototypeOf(42); }, TypeError); + assertThrows(function() { Reflect.getPrototypeOf(null); }, TypeError); +})(); + + +// See reflect-get-prototype-of.js for further tests. + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.setPrototypeOf + + +(function testReflectSetPrototypeOfArity() { + assertEquals(2, Reflect.setPrototypeOf.length); +})(); + + +(function testReflectSetPrototypeOfOnNonObject() { + assertThrows(function() { Reflect.setPrototypeOf(undefined, {}); }, + TypeError); + assertThrows(function() { Reflect.setPrototypeOf(42, {}); }, TypeError); + assertThrows(function() { Reflect.setPrototypeOf(null, {}); }, TypeError); + + assertThrows(function() { Reflect.setPrototypeOf({}, undefined); }, + TypeError); + assertThrows(function() { Reflect.setPrototypeOf({}, 42); }, TypeError); + assertTrue(Reflect.setPrototypeOf({}, null)); +})(); + + +// See reflect-set-prototype-of.js for further tests. + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.isExtensible + + +(function testReflectIsExtensibleArity() { + assertEquals(1, Reflect.isExtensible.length); +})(); + + +(function testReflectIsExtensibleOnNonObject() { + assertThrows(function() { Reflect.isExtensible(); }, TypeError); + assertThrows(function() { Reflect.isExtensible(42); }, TypeError); + assertThrows(function() { Reflect.isExtensible(null); }, TypeError); +})(); + + +(function testReflectIsExtensibleOnObject() { + // This should be the last test on [objects] as it modifies them irreversibly. + for (let target of objects) { + prepare(target); + if (target instanceof Int32Array) continue; // issue v8:4460 + assertTrue(Reflect.isExtensible(target)); + Object.preventExtensions(target); + assertFalse(Reflect.isExtensible(target)); + } +})(); + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.enumerate + + +(function testReflectEnumerateArity() { + assertEquals(1, Reflect.enumerate.length); +})(); + + +(function testReflectEnumerateOnNonObject() { + assertThrows(function() { Reflect.enumerate(); }, TypeError); + assertThrows(function() { Reflect.enumerate(42); }, TypeError); + assertThrows(function() { Reflect.enumerate(null); }, TypeError); +})(); + + +// See reflect-enumerate*.js for further tests. + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.getOwnPropertyDescriptor + + +(function testReflectGetOwnPropertyDescriptorArity() { + assertEquals(2, Reflect.getOwnPropertyDescriptor.length); +})(); + + +(function testReflectGetOwnPropertyDescriptorOnNonObject() { + assertThrows(function() { Reflect.getOwnPropertyDescriptor(); }, TypeError); + assertThrows(function() { Reflect.getOwnPropertyDescriptor(42); }, + TypeError); + assertThrows(function() { Reflect.getOwnPropertyDescriptor(null); }, + TypeError); +})(); + + +(function testReflectGetOwnPropertyDescriptorKeyConversion() { + var target = {bla: 42}; + var a = { [Symbol.toPrimitive]: function() { return "bla" } }; + var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; + assertEquals(42, Reflect.getOwnPropertyDescriptor(target, a).value); + assertThrows(function() { Reflect.getOwnPropertyDescriptor(target, b); }, + "gaga"); +})(); + + +// See reflect-get-own-property-descriptor.js for further tests. + + + +//////////////////////////////////////////////////////////////////////////////// +// Reflect.preventExtensions + + +(function testReflectPreventExtensionsArity() { + assertEquals(1, Reflect.preventExtensions.length); +})(); + + +(function testReflectPreventExtensionsOnNonObject() { + assertThrows(function() { Reflect.preventExtensions(); }, TypeError); + assertThrows(function() { Reflect.preventExtensions(42); }, TypeError); + assertThrows(function() { Reflect.preventExtensions(null); }, TypeError); +})(); + + +// See reflect-prevent-extensions.js for further tests. + +// TODO(neis): Need proxies to test the situation where +// [[preventExtensions]] returns false. diff --git a/deps/v8/test/mjsunit/harmony/regexp-sticky.js b/deps/v8/test/mjsunit/harmony/regexp-sticky.js index bd7f646d00..971adb7fed 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-sticky.js +++ b/deps/v8/test/mjsunit/harmony/regexp-sticky.js @@ -40,13 +40,13 @@ assertTrue(!!"..foobar".match(plain)); var sticky = /foo.bar/y; assertTrue(!!"foo*bar".match(sticky)); -assertEquals(0, sticky.lastIndex); +assertEquals(7, sticky.lastIndex); assertFalse(!!"..foo*bar".match(sticky)); var stickyplain = /foobar/y; assertTrue(!!"foobar".match(stickyplain)); -assertEquals(0, stickyplain.lastIndex); +assertEquals(6, stickyplain.lastIndex); assertFalse(!!"..foobar".match(stickyplain)); var global = /foo.bar/g; diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4211.js b/deps/v8/test/mjsunit/harmony/regress/regress-4211.js index 8affc7344a..d83c1a71f9 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4211.js +++ b/deps/v8/test/mjsunit/harmony/regress/regress-4211.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Flags: --harmony-arrow-functions --harmony-rest-parameters +// Flags: --harmony-rest-parameters assertThrows("()=>{}()", SyntaxError); assertThrows("x=>{}()", SyntaxError); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4395-global-eval.js b/deps/v8/test/mjsunit/harmony/regress/regress-4395-global-eval.js new file mode 100644 index 0000000000..6cc6f0e747 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-4395-global-eval.js @@ -0,0 +1,8 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --harmony-default-parameters --harmony-destructuring + +((x, y = eval('x')) => assertEquals(42, y))(42); +((x, {y = eval('x')}) => assertEquals(42, y))(42, {}); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4395.js b/deps/v8/test/mjsunit/harmony/regress/regress-4395.js new file mode 100644 index 0000000000..a003856715 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-4395.js @@ -0,0 +1,104 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --harmony-destructuring --harmony-default-parameters + +(function testExpressionTypes() { + "use strict"; + ((x, y = x) => assertEquals(42, y))(42); + + ((x, y = (x)) => assertEquals(42, y))(42); + ((x, y = `${x}`) => assertEquals("42", y))(42); + ((x, y = x = x + 1) => assertEquals(43, y))(42); + ((x, y = x()) => assertEquals(42, y))(() => 42); + ((x, y = new x()) => assertEquals(42, y.z))(function() { this.z = 42 }); + ((x, y = -x) => assertEquals(-42, y))(42); + ((x, y = ++x) => assertEquals(43, y))(42); + ((x, y = x === 42) => assertTrue(y))(42); + ((x, y = (x == 42 ? x : 0)) => assertEquals(42, y))(42); + + ((x, y = function() { return x }) => assertEquals(42, y()))(42); + ((x, y = () => x) => assertEquals(42, y()))(42); + + // Literals + ((x, y = {z: x}) => assertEquals(42, y.z))(42); + ((x, y = {[x]: x}) => assertEquals(42, y[42]))(42); + ((x, y = [x]) => assertEquals(42, y[0]))(42); + ((x, y = [...x]) => assertEquals(42, y[0]))([42]); + + ((x, y = class { + static [x]() { return x } + }) => assertEquals(42, y[42]()))(42); + ((x, y = (new class { + z() { return x } + })) => assertEquals(42, y.z()))(42); + + ((x, y = (new class Y { + static [x]() { return x } + z() { return Y[42]() } + })) => assertEquals(42, y.z()))(42); + + ((x, y = (new class { + constructor() { this.z = x } + })) => assertEquals(42, y.z))(42); + ((x, y = (new class Y { + constructor() { this.z = x } + })) => assertEquals(42, y.z))(42); + + ((x, y = (new class extends x { + })) => assertEquals(42, y.z()))(class { z() { return 42 } }); + + // Defaults inside destructuring + ((x, {y = x}) => assertEquals(42, y))(42, {}); + ((x, [y = x]) => assertEquals(42, y))(42, []); +})(); + + +(function testMultiScopeCapture() { + "use strict"; + var x = 1; + { + let y = 2; + ((x, y, a = x, b = y) => { + assertEquals(3, x); + assertEquals(3, a); + assertEquals(4, y); + assertEquals(4, b); + })(3, 4); + } +})(); + + +(function testSuper() { + "use strict"; + class A { + x() { return 42; } + } + + class B extends A { + y() { + ((q = super.x()) => assertEquals(42, q))(); + } + } + + new B().y(); + + class C { + constructor() { return { prop: 42 } } + } + + class D extends C{ + constructor() { + ((q = super()) => assertEquals(42, q.prop))(); + } + } + + new D(); +})(); + + +(function testScopeFlags() { + ((x, y = eval('x')) => assertEquals(42, y))(42); + ((x, {y = eval('x')}) => assertEquals(42, y))(42, {}); +})(); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4482.js b/deps/v8/test/mjsunit/harmony/regress/regress-4482.js new file mode 100644 index 0000000000..bffca42ecc --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-4482.js @@ -0,0 +1,9 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --harmony-sloppy --nolegacy-const + +assertEquals("function", (function f() { f = 42; return typeof f })()); +assertEquals("function", + (function* g() { g = 42; yield typeof g })().next().value); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-508074.js b/deps/v8/test/mjsunit/harmony/regress/regress-508074.js index d2864bb956..93f82cfd0c 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-508074.js +++ b/deps/v8/test/mjsunit/harmony/regress/regress-508074.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-rest-parameters --harmony-arrow-functions +// Flags: --harmony-rest-parameters // Flags: --allow-natives-syntax var f = (a, b, ...c) => { diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-546967.js b/deps/v8/test/mjsunit/harmony/regress/regress-546967.js new file mode 100644 index 0000000000..0315c43634 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-546967.js @@ -0,0 +1,16 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --harmony-do-expressions --allow-natives-syntax + +function func1() { + for (var i = 0; i < 64; ++i) func2(); +} + +%OptimizeFunctionOnNextCall(func1); +func1(); + +function func2() { + var v = do {}; +} diff --git a/deps/v8/test/mjsunit/harmony/rest-params-lazy-parsing.js b/deps/v8/test/mjsunit/harmony/rest-params-lazy-parsing.js index b50a990f5c..2042a27f6b 100644 --- a/deps/v8/test/mjsunit/harmony/rest-params-lazy-parsing.js +++ b/deps/v8/test/mjsunit/harmony/rest-params-lazy-parsing.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-rest-parameters --harmony-arrow-functions +// Flags: --harmony-rest-parameters // Flags: --min-preparse-length=0 function variadic(co, ...values) { diff --git a/deps/v8/test/mjsunit/harmony/set-prototype-of.js b/deps/v8/test/mjsunit/harmony/set-prototype-of.js index e92a0c37bc..7406fb54bf 100644 --- a/deps/v8/test/mjsunit/harmony/set-prototype-of.js +++ b/deps/v8/test/mjsunit/harmony/set-prototype-of.js @@ -131,6 +131,9 @@ function TestSetPrototypeOfNonExtensibleObject() { for (var i = 0; i < objects.length; i++) { var object = objects[i]; Object.preventExtensions(object); + // Setting the current prototype must succeed. + Object.setPrototypeOf(object, Object.getPrototypeOf(object)); + // Setting any other must fail. assertThrows(function() { Object.setPrototypeOf(object, proto); }, TypeError); diff --git a/deps/v8/test/mjsunit/harmony/simd.js b/deps/v8/test/mjsunit/harmony/simd.js index fe4b0358f9..2c07eefb59 100644 --- a/deps/v8/test/mjsunit/harmony/simd.js +++ b/deps/v8/test/mjsunit/harmony/simd.js @@ -337,8 +337,8 @@ function TestEquality(type, lanes) { assertTrue(instance == instance) assertFalse(instance === Object(instance)) assertFalse(Object(instance) === instance) - assertFalse(instance == Object(instance)) - assertFalse(Object(instance) == instance) + assertTrue(instance == Object(instance)) + assertTrue(Object(instance) == instance) assertTrue(instance === instance.valueOf()) assertTrue(instance.valueOf() === instance) assertTrue(instance == instance.valueOf()) @@ -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/deps/v8/test/mjsunit/harmony/string-split.js b/deps/v8/test/mjsunit/harmony/string-split.js new file mode 100644 index 0000000000..1240d84bc1 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/string-split.js @@ -0,0 +1,21 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-regexp-subclass + +var pattern = {}; +var limit = { value: 3 }; +pattern[Symbol.split] = function(string, limit) { + return string.length * limit.value; +}; +// Check object coercible fails. +assertThrows(() => String.prototype.split.call(null, pattern, limit), + TypeError); +// Override is called. +assertEquals(15, "abcde".split(pattern, limit)); +// Non-callable override. +pattern[Symbol.split] = "dumdidum"; +assertThrows(() => "abcde".split(pattern, limit), TypeError); + +assertEquals("[Symbol.split]", RegExp.prototype[Symbol.split].name); diff --git a/deps/v8/test/mjsunit/harmony/to-length.js b/deps/v8/test/mjsunit/harmony/to-length.js new file mode 100644 index 0000000000..b805e5cffe --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/to-length.js @@ -0,0 +1,76 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +assertEquals(0, %ToLength(NaN)); +assertEquals(0, %_ToLength(NaN)); + +assertEquals(0, %ToLength(-Infinity)); +assertEquals(0, %_ToLength(-Infinity)); + +assertEquals(0, %ToLength(0)); +assertEquals(0, %_ToLength(0)); + +assertEquals(0, %ToLength(.5)); +assertEquals(0, %_ToLength(.5)); + +assertEquals(42, %ToLength(42.99999)); +assertEquals(42, %_ToLength(42.99999)); + +assertEquals(9007199254740991, %ToLength(9007199254740991)); +assertEquals(9007199254740991, %_ToLength(9007199254740991)); + +assertEquals(9007199254740991, %ToLength(Infinity)); +assertEquals(9007199254740991, %_ToLength(Infinity)); + +assertEquals(0, %ToLength(null)); +assertEquals(0, %_ToLength(null)); + +assertEquals(1, %ToLength(true)); +assertEquals(1, %_ToLength(true)); + +assertEquals(0, %ToLength(false)); +assertEquals(0, %_ToLength(false)); + +assertEquals(0, %ToLength(undefined)); +assertEquals(0, %_ToLength(undefined)); + +assertEquals(0, %ToLength("-1")); +assertEquals(0, %_ToLength("-1")); +assertEquals(123, %ToLength("123")); +assertEquals(123, %_ToLength("123")); +assertEquals(0, %ToLength("random text")); +assertEquals(0, %_ToLength("random text")); + +assertThrows(function() { %ToLength(Symbol.toPrimitive) }, TypeError); +assertThrows(function() { %_ToLength(Symbol.toPrimitive) }, TypeError); + +var a = { toString: function() { return 54321 }}; +assertEquals(54321, %ToLength(a)); +assertEquals(54321, %_ToLength(a)); + +var b = { valueOf: function() { return 42 }}; +assertEquals(42, %ToLength(b)); +assertEquals(42, %_ToLength(b)); + +var c = { + toString: function() { return "x"}, + valueOf: function() { return 123 } +}; +assertEquals(123, %ToLength(c)); +assertEquals(123, %_ToLength(c)); + +var d = { + [Symbol.toPrimitive]: function(hint) { + assertEquals("number", hint); + return 987654321; + } +}; +assertEquals(987654321, %ToLength(d)); +assertEquals(987654321, %_ToLength(d)); + +var e = new Date(0); +assertEquals(0, %ToLength(e)); +assertEquals(0, %_ToLength(e)); diff --git a/deps/v8/test/mjsunit/compiler/jsnatives.js b/deps/v8/test/mjsunit/keyed-load-with-symbol-key.js index 74d88ba3a6..15562be6bd 100644 --- a/deps/v8/test/mjsunit/compiler/jsnatives.js +++ b/deps/v8/test/mjsunit/keyed-load-with-symbol-key.js @@ -1,4 +1,4 @@ -// Copyright 2009 the V8 project authors. All rights reserved. +// Copyright 2014 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: @@ -26,7 +26,24 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax +var s = Symbol("foo"); -// Test call of JS runtime functions. +var o = { + [s]: "bar", +} -assertEquals(1, %to_number_fun("1")); +function get(obj, key) { + return obj[key]; +} + +assertEquals("bar", get(o, s)); +get(o, s); +get(o, s); + +%OptimizeFunctionOnNextCall(get); +assertEquals("bar", get(o, s)); + +assertOptimized(get); + +get(o, "funny"); +assertUnoptimized(get); diff --git a/deps/v8/test/mjsunit/math-floor-of-div-nosudiv.js b/deps/v8/test/mjsunit/math-floor-of-div-nosudiv.js index bf7a4ce38a..f5b1f299b7 100644 --- a/deps/v8/test/mjsunit/math-floor-of-div-nosudiv.js +++ b/deps/v8/test/mjsunit/math-floor-of-div-nosudiv.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --nouse-inlining --noenable-sudiv +// Flags: --noenable-armv8 // Use this function as reference. Make sure it is not inlined. function div(a, b) { diff --git a/deps/v8/test/mjsunit/messages.js b/deps/v8/test/mjsunit/messages.js index b8c3114d36..f55bad3dbb 100644 --- a/deps/v8/test/mjsunit/messages.js +++ b/deps/v8/test/mjsunit/messages.js @@ -62,10 +62,10 @@ test(function() { Array.prototype.shift.call(null); }, "Array.prototype.shift called on null or undefined", TypeError); -// kCannotPreventExtExternalArray +// kCannotFreezeArrayBufferView test(function() { - Object.preventExtensions(new Uint16Array(1)); -}, "Cannot prevent extension of an object with external array elements", TypeError); + Object.freeze(new Uint16Array(1)); +}, "Cannot freeze array buffer views with elements", TypeError); // kConstAssign test(function() { @@ -136,9 +136,9 @@ test(function() { // kIncompatibleMethodReceiver test(function() { - RegExp.prototype.compile.call(RegExp.prototype); -}, "Method RegExp.prototype.compile called on incompatible receiver " + - "[object RegExp]", TypeError); + Set.prototype.add.call([]); +}, "Method Set.prototype.add called on incompatible receiver [object Array]", +TypeError); // kInstanceofFunctionExpected test(function() { @@ -301,7 +301,7 @@ test(function() { test(function() { "use strict"; (1).a = 1; -}, "Cannot assign to read only property 'a' of 1", TypeError); +}, "Cannot create property 'a' on number '1'", TypeError); // kStrongImplicitCast test(function() { @@ -332,8 +332,8 @@ test(function() { // kValueAndAccessor test(function() { Object.defineProperty({}, "x", { get: function(){}, value: 1}); -}, "Invalid property. A property cannot both have accessors and be " + - "writable or have a value, #<Object>", TypeError); +}, "Invalid property descriptor. Cannot both specify accessors " + + "and a value or writable attribute, #<Object>", TypeError); // kWithExpression test(function() { diff --git a/deps/v8/test/mjsunit/minmax-simple.js b/deps/v8/test/mjsunit/minmax-simple.js new file mode 100644 index 0000000000..a65f995435 --- /dev/null +++ b/deps/v8/test/mjsunit/minmax-simple.js @@ -0,0 +1,27 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-natives-as natives +// Test the MaxSimple and MinSimple internal methods in runtime.js + +var MaxSimple = natives.ImportNow("MaxSimple"); +var MinSimple = natives.ImportNow("MinSimple"); + +function checkEvaluations(target) { + var evaluations = 0; + var observedNumber = { + valueOf: function() { + evaluations++; + return 0; + } + }; + target(observedNumber, observedNumber); + return evaluations; +} + +assertEquals(1, MaxSimple(-1, 1)); +assertEquals(2, checkEvaluations(MaxSimple)); + +assertEquals(-1, MinSimple(-1, 1)); +assertEquals(2, checkEvaluations(MinSimple)); diff --git a/deps/v8/test/mjsunit/mirror-regexp.js b/deps/v8/test/mjsunit/mirror-regexp.js index 6c251d4ff6..882af8dd6e 100644 --- a/deps/v8/test/mjsunit/mirror-regexp.js +++ b/deps/v8/test/mjsunit/mirror-regexp.js @@ -25,19 +25,17 @@ // (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-debug-as debug --harmony-unicode-regexps +// Flags: --expose-debug-as debug --harmony-regexps --harmony-unicode-regexps // Test the mirror object for regular expression values -var all_attributes = debug.PropertyAttribute.ReadOnly | - debug.PropertyAttribute.DontEnum | - debug.PropertyAttribute.DontDelete; -var expected_attributes = { - 'source': all_attributes, - 'global': all_attributes, - 'ignoreCase': all_attributes, - 'multiline': all_attributes, - 'unicode' : all_attributes, - 'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDelete +var dont_enum = debug.PropertyAttribute.DontEnum; +var dont_delete = debug.PropertyAttribute.DontDelete; +var expected_prototype_attributes = { + 'source': dont_enum, + 'global': dont_enum, + 'ignoreCase': dont_enum, + 'multiline': dont_enum, + 'unicode' : dont_enum, }; function MirrorRefCache(json_refs) { @@ -70,9 +68,12 @@ function testRegExpMirror(r) { assertTrue(mirror.isRegExp()); assertEquals('regexp', mirror.type()); assertFalse(mirror.isPrimitive()); - for (var p in expected_attributes) { - assertEquals(expected_attributes[p], - mirror.property(p).attributes(), + assertEquals(dont_enum | dont_delete, + mirror.property('lastIndex').attributes()); + var proto_mirror = mirror.protoObject(); + for (var p in expected_prototype_attributes) { + assertEquals(expected_prototype_attributes[p], + proto_mirror.property(p).attributes(), p + ' attributes'); } @@ -83,24 +84,12 @@ function testRegExpMirror(r) { var fromJSON = eval('(' + json + ')'); assertEquals('regexp', fromJSON.type); assertEquals('RegExp', fromJSON.className); - for (var p in expected_attributes) { - for (var i = 0; i < fromJSON.properties.length; i++) { - if (fromJSON.properties[i].name == p) { - assertEquals(expected_attributes[p], - fromJSON.properties[i].attributes, - 'Unexpected value for ' + p + ' attributes'); - assertEquals(mirror.property(p).propertyType(), - fromJSON.properties[i].propertyType, - 'Unexpected value for ' + p + ' propertyType'); - assertEquals(mirror.property(p).value().handle(), - fromJSON.properties[i].ref, - 'Unexpected handle for ' + p); - assertEquals(mirror.property(p).value().value(), - refs.lookup(fromJSON.properties[i].ref).value, - 'Unexpected value for ' + p); - } - } - } + assertEquals('lastIndex', fromJSON.properties[0].name); + assertEquals(dont_enum | dont_delete, fromJSON.properties[0].attributes); + assertEquals(mirror.property('lastIndex').propertyType(), + fromJSON.properties[0].propertyType); + assertEquals(mirror.property('lastIndex').value().value(), + refs.lookup(fromJSON.properties[0].ref).value); } diff --git a/deps/v8/test/mjsunit/mjsunit.gyp b/deps/v8/test/mjsunit/mjsunit.gyp new file mode 100644 index 0000000000..35ce2ffdee --- /dev/null +++ b/deps/v8/test/mjsunit/mjsunit.gyp @@ -0,0 +1,26 @@ +# Copyright 2015 the V8 project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'conditions': [ + ['test_isolation_mode != "noop"', { + 'targets': [ + { + 'target_name': 'mjsunit_run', + 'type': 'none', + 'dependencies': [ + '../../src/d8.gyp:d8_run', + ], + 'includes': [ + '../../build/features.gypi', + '../../build/isolate.gypi', + ], + 'sources': [ + 'mjsunit.isolate', + ], + }, + ], + }], + ], +} diff --git a/deps/v8/test/mjsunit/mjsunit.isolate b/deps/v8/test/mjsunit/mjsunit.isolate new file mode 100644 index 0000000000..18b73c2a14 --- /dev/null +++ b/deps/v8/test/mjsunit/mjsunit.isolate @@ -0,0 +1,23 @@ +# Copyright 2015 the V8 project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +{ + 'variables': { + 'files': [ + './', + '../../tools/codemap.js', + '../../tools/consarray.js', + '../../tools/csvparser.js', + '../../tools/logreader.js', + '../../tools/profile.js', + '../../tools/profile_view.js', + '../../tools/profviz/composer.js', + '../../tools/splaytree.js', + '../../tools/tickprocessor.js' + ], + }, + 'includes': [ + '../../src/d8.isolate', + '../../tools/testrunner/testrunner.isolate', + ], +}
\ No newline at end of file diff --git a/deps/v8/test/mjsunit/mjsunit.js b/deps/v8/test/mjsunit/mjsunit.js index f50319d6aa..f08c29339a 100644 --- a/deps/v8/test/mjsunit/mjsunit.js +++ b/deps/v8/test/mjsunit/mjsunit.js @@ -39,7 +39,7 @@ function MjsUnitAssertionError(message) { MjsUnitAssertionError.prototype.toString = function () { - return this.message; + return this.message + "\n\nStack: " + this.stack; }; @@ -131,6 +131,7 @@ var assertUnoptimized; case "boolean": case "undefined": case "function": + case "symbol": return String(value); case "object": if (value === null) return "null"; diff --git a/deps/v8/test/mjsunit/mjsunit.status b/deps/v8/test/mjsunit/mjsunit.status index edc08a84b5..47aa91f808 100644 --- a/deps/v8/test/mjsunit/mjsunit.status +++ b/deps/v8/test/mjsunit/mjsunit.status @@ -57,11 +57,6 @@ ############################################################################## # TurboFan compiler failures. - # TODO(mstarzinger): An arguments object materialized in the prologue can't - # be accessed indirectly. Either we drop that requirement or wait for support - # from the deoptimizer to do that. - 'arguments-indirect': [PASS, NO_VARIANTS], - # TODO(verwaest): Some tests are over-restrictive about object layout. 'array-constructor-feedback': [PASS, NO_VARIANTS], 'array-feedback': [PASS, NO_VARIANTS], @@ -110,6 +105,7 @@ 'debug-step-3': [PASS, NO_VARIANTS], # flaky in no-snap mode. 'debug-stepframe-clearing': [PASS, NO_VARIANTS], # only in no-snap debug. 'debug-stepin-call-function-stub': [PASS, NO_VARIANTS], # only in no-snap debug. + 'debug-stepin-positions': [PASS, NO_VARIANTS], # only due to inlining. 'regress/regress-3717': [PASS, NO_VARIANTS], # only in no-snap mode. 'regress/regress-2451': [PASS, NO_VARIANTS], # with custom snapshot and gc-stress. 'debug-multiple-breakpoints': [PASS, NO_VARIANTS], # with custom snapshot and gc-stress. @@ -151,6 +147,9 @@ # TODO(titzer): too slow in --turbo mode due to O(n^2) graph verification. 'regress/regress-1122': [PASS, NO_VARIANTS], + # Assumptions about optimization need investigation in TurboFan. + 'regress-sync-optimized-lists': [PASS, NO_VARIANTS], + # issue 4078: 'allocation-site-info': [PASS, NO_VARIANTS], @@ -200,7 +199,7 @@ # Skip long running tests that time out in debug mode. 'generated-transition-stub': [PASS, ['mode == debug', SKIP]], 'migrations': [SKIP], - 'array-functions-prototype-misc': [PASS, ['mode == debug', SKIP]], + 'array-functions-prototype-misc': [PASS, SLOW, ['mode == debug', SKIP]], ############################################################################## # This test sets the umask on a per-process basis and hence cannot be @@ -251,9 +250,24 @@ # BUG(v8:3838). 'regress/regress-3116': [PASS, ['isolates', FLAKY]], + # BUG(v8:4458). TODO(mvstanton): reenable the test once --vector-stores is + # prermanently enabled. + 'call-counts': [SKIP], + # BUG(chromium:508074). Remove this once the issue is fixed. 'harmony/arrow-rest-params': [PASS, NO_VARIANTS], 'harmony/rest-params': [PASS, ['no_snap == True', NO_VARIANTS]], + + # Slow tests. + 'copy-on-write-assert': [PASS, SLOW], + 'debug-scopes': [PASS, SLOW], + 'es7/object-observe': [PASS, ['mode == debug', SLOW]], + 'numops-fuzz-part*': [PASS, ['mode == debug', SLOW]], + 'readonly': [PASS, SLOW], + 'regress/regress-1200351': [PASS, ['mode == debug', SLOW]], + 'regress/regress-crbug-474297': [PASS, ['mode == debug', SLOW]], + 'strong/implicit-conversions': [PASS, SLOW], + 'strong/load-element-mutate-backing-store': [PASS, SLOW], }], # ALWAYS ['novfp3 == True', { @@ -284,6 +298,7 @@ 'regress/regress-165637': [SKIP], 'regress/regress-2249': [SKIP], 'regress/regress-4121': [SKIP], + 'compare-known-objects-slow': [SKIP], # Tests taking too long 'debug-stepout-scope-part8': [SKIP], 'mirror-object': [SKIP], @@ -322,8 +337,14 @@ # BUG(v8:4359) 'strong/load-proxy': [SKIP], - # BUG(v8:4381) - 'for-in-opt': [PASS, FAIL], + # Slow tests. + 'array-constructor': [PASS, SLOW], + 'json': [PASS, SLOW], + 'regress/regress-446389': [PASS, SLOW], + 'regress/regress-inline-getter-near-stack-limit': [PASS, SLOW], + + # BUG(v8:3097) + 'debug-references': [SKIP], }], # 'gc_stress == True' ############################################################################## @@ -546,6 +567,12 @@ }], # 'arch == mips' ############################################################################## +['arch == x87', { + # Turbofan will hit the known issue that x87 changes sNaN to qNaN by default. + 'regress/regress-undefined-nan': [SKIP], +}], # 'arch == x87' + +############################################################################## ['arch == mips64el or arch == mips64', { # Slow tests which times out in debug mode. @@ -607,6 +634,9 @@ # BUG(v8:3435) 'debug-script-breakpoints': [PASS, FAIL], + + # BUG(v8:4495). + 'es6/collections': [PASS, ['arch == ia32', FAST_VARIANTS]], }], # 'system == windows' ############################################################################## @@ -674,6 +704,9 @@ 'readonly': [SKIP], 'array-feedback': [SKIP], + # Bounds check triggers forced deopt for array constructors. + 'array-constructor-feedback': [SKIP], + # Deopting uses just enough memory to make this one OOM. 'regress/regress-3976': [SKIP], @@ -694,4 +727,318 @@ # take too long with the simulator. 'regress/regress-1132': [SKIP], }], # 'arch == ppc and simulator_run == True' + +['ignition == True', { + 'asm/*': [SKIP], + 'compiler/*': [SKIP], + 'const*': [SKIP], + 'debug-*': [SKIP], + 'es6/*': [SKIP], + 'es7/*': [SKIP], + 'strong/*': [SKIP], + 'harmony/*': [SKIP], + 'regress/debug*': [SKIP], + 'regress/regress-debug*': [SKIP], + + 'allocation-folding': [SKIP], + 'api-call-after-bypassed-exception': [SKIP], + 'apply-arguments-gc-safepoint': [SKIP], + 'arguments-load-across-eval': [SKIP], + 'arguments-read-and-assignment': [SKIP], + 'array-bounds-check-removal': [SKIP], + 'array-constructor': [SKIP], + 'array-elements-from-array-prototype-chain': [SKIP], + 'array-functions-prototype-misc': [SKIP], + 'array-join': [SKIP], + 'array-length-number-conversion': [SKIP], + 'array-literal-feedback': [SKIP], + 'array-literal-transitions': [SKIP], + 'array-reduce': [SKIP], + 'array-tostring': [SKIP], + 'assert-opt-and-deopt': [SKIP], + 'big-array-literal': [SKIP], + 'break': [SKIP], + 'call-runtime-tail': [SKIP], + 'context-calls-maintained': [SKIP], + 'contextual-calls': [SKIP], + 'cross-realm-filtering': [SKIP], + 'cyclic-array-to-string': [SKIP], + 'd8-worker-sharedarraybuffer': [SKIP], + 'deopt-minus-zero': [SKIP], + 'deopt-with-fp-regs': [SKIP], + 'deserialize-script-id': [SKIP], + 'div-mul-minus-one': [SKIP], + 'double-equals': [SKIP], + 'double-intrinsics': [SKIP], + 'elements-transition-hoisting': [SKIP], + 'error-constructors': [SKIP], + 'eval-enclosing-function-name': [SKIP], + 'eval-stack-trace': [SKIP], + 'fast-prototype': [SKIP], + 'for-in-special-cases': [SKIP], + 'function-call': [SKIP], + 'get-caller-js-function': [SKIP], + 'get-prototype-of': [SKIP], + 'getter-in-prototype': [SKIP], + 'getters-on-elements': [SKIP], + 'global-hash': [SKIP], + 'global-load-from-eval-in-with': [SKIP], + 'global-vars-with': [SKIP], + 'instanceof-2': [SKIP], + 'math-floor-of-div-minus-zero': [SKIP], + 'math-min-max': [SKIP], + 'messages': [SKIP], + 'mirror-object': [SKIP], + 'numops-fuzz-part1': [SKIP], + 'numops-fuzz-part2': [SKIP], + 'numops-fuzz-part3': [SKIP], + 'numops-fuzz-part4': [SKIP], + 'object-literal-gc': [SKIP], + 'osr-elements-kind': [SKIP], + 'property-load-across-eval': [SKIP], + 'proto-accessor': [SKIP], + 'readonly': [SKIP], + 'regress-3225': [SKIP], + 'regress/clear-keyed-call': [SKIP], + 'regress/regress-102153': [SKIP], + 'regress/regress-1079': [SKIP], + 'regress/regress-109195': [SKIP], + 'regress/regress-1114040': [SKIP], + 'regress/regress-1125': [SKIP], + 'regress/regress-1129': [SKIP], + 'regress/regress-117409': [SKIP], + 'regress/regress-1177809': [SKIP], + 'regress/regress-119609': [SKIP], + 'regress/regress-1209': [SKIP], + 'regress/regress-124594': [SKIP], + 'regress/regress-124': [SKIP], + 'regress/regress-125515': [SKIP], + 'regress/regress-128018': [SKIP], + 'regress/regress-131994': [SKIP], + 'regress/regress-133211b': [SKIP], + 'regress/regress-1365': [SKIP], + 'regress/regress-1369': [SKIP], + 'regress/regress-1403': [SKIP], + 'regress/regress-1412': [SKIP], + 'regress/regress-1415': [SKIP], + 'regress/regress-1436': [SKIP], + 'regress/regress-1493017': [SKIP], + 'regress/regress-1523': [SKIP], + 'regress/regress-1560': [SKIP], + 'regress/regress-1586': [SKIP], + 'regress/regress-1639-2': [SKIP], + 'regress/regress-1639': [SKIP], + 'regress/regress-166553': [SKIP], + 'regress/regress-1708': [SKIP], + 'regress/regress-1757': [SKIP], + 'regress/regress-1790': [SKIP], + 'regress/regress-1980': [SKIP], + 'regress/regress-2054': [SKIP], + 'regress/regress-2071': [SKIP], + 'regress/regress-2132': [SKIP], + 'regress/regress-2163': [SKIP], + 'regress/regress-2318': [SKIP], + 'regress/regress-2339': [SKIP], + 'regress/regress-2444': [SKIP], + 'regress/regress-244': [SKIP], + 'regress/regress-2593': [SKIP], + 'regress/regress-2594': [SKIP], + 'regress/regress-2618': [SKIP], + 'regress/regress-263': [SKIP], + 'regress/regress-265': [SKIP], + 'regress/regress-269': [SKIP], + 'regress/regress-2790': [SKIP], + 'regress/regress-2825': [SKIP], + 'regress/regress-286': [SKIP], + 'regress/regress-298269': [SKIP], + 'regress/regress-3176': [SKIP], + 'regress/regress-318420': [SKIP], + 'regress/regress-320532': [SKIP], + 'regress/regress-3281': [SKIP], + 'regress/regress-331444': [SKIP], + 'regress/regress-343609': [SKIP], + 'regress/regress-347530': [SKIP], + 'regress/regress-352982': [SKIP], + 'regress/regress-354357': [SKIP], + 'regress/regress-356053': [SKIP], + 'regress/regress-357105': [SKIP], + 'regress/regress-361025': [SKIP], + 'regress/regress-3621': [SKIP], + 'regress/regress-365172-3': [SKIP], + 'regress/regress-370827': [SKIP], + 'regress/regress-3709': [SKIP], + 'regress/regress-377290': [SKIP], + 'regress/regress-385565': [SKIP], + 'regress/regress-3859': [SKIP], + 'regress/regress-3884': [SKIP], + 'regress/regress-3926': [SKIP], + 'regress/regress-3960': [SKIP], + 'regress/regress-3969': [SKIP], + 'regress/regress-4023': [SKIP], + 'regress/regress-4027': [SKIP], + 'regress/regress-403292': [SKIP], + 'regress/regress-410912': [SKIP], + 'regress/regress-4121': [SKIP], + 'regress/regress-419663': [SKIP], + 'regress/regress-4255-4': [SKIP], + 'regress/regress-430201': [SKIP], + 'regress/regress-430201b': [SKIP], + 'regress/regress-4309-3': [SKIP], + 'regress/regress-4320': [SKIP], + 'regress/regress-4325': [SKIP], + 'regress/regress-436893': [SKIP], + 'regress/regress-4374': [SKIP], + 'regress/regress-4388': [SKIP], + 'regress/regress-444805': [SKIP], + 'regress/regress-446389': [SKIP], + 'regress/regress-4515': [SKIP], + 'regress/regress-4521': [SKIP], + 'regress/regress-4525': [SKIP], + 'regress/regress-453481': [SKIP], + 'regress/regress-4534': [SKIP], + 'regress/regress-454725': [SKIP], + 'regress/regress-470804': [SKIP], + 'regress/regress-476488': [SKIP], + 'regress/regress-491536': [SKIP], + 'regress/regress-514362': [SKIP], + 'regress/regress-520029': [SKIP], + 'regress/regress-542099': [SKIP], + 'regress/regress-542100': [SKIP], + 'regress/regress-580': [SKIP], + 'regress/regress-618': [SKIP], + 'regress/regress-643': [SKIP], + 'regress/regress-69': [SKIP], + 'regress/regress-70066': [SKIP], + 'regress/regress-747': [SKIP], + 'regress/regress-806473': [SKIP], + 'regress/regress-842017': [SKIP], + 'regress/regress-84234': [SKIP], + 'regress/regress-88858': [SKIP], + 'regress/regress-94425': [SKIP], + 'regress/regress-94873': [SKIP], + 'regress/regress-95485': [SKIP], + 'regress/regress-97116b': [SKIP], + 'regress/regress-97116': [SKIP], + 'regress/regress-974': [SKIP], + 'regress/regress-99167': [SKIP], + 'regress/regress-998565': [SKIP], + 'regress/regress-arguments-gc': [SKIP], + 'regress/regress-assignment-in-test-context': [SKIP], + 'regress/regress-cnlt-elements': [SKIP], + 'regress/regress-cnlt-enum-indices': [SKIP], + 'regress/regress-cntl-descriptors-enum': [SKIP], + 'regress/regress-conditional-position': [SKIP], + 'regress/regress-convert-enum': [SKIP], + 'regress/regress-crbug-119800': [SKIP], + 'regress/regress-crbug-135008': [SKIP], + 'regress/regress-crbug-229923': [SKIP], + 'regress/regress-crbug-242502': [SKIP], + 'regress/regress-crbug-242924': [SKIP], + 'regress/regress-crbug-245480': [SKIP], + 'regress/regress-crbug-349079': [SKIP], + 'regress/regress-crbug-350864': [SKIP], + 'regress/regress-crbug-352058': [SKIP], + 'regress/regress-crbug-357137': [SKIP], + 'regress/regress-crbug-385002': [SKIP], + 'regress/regress-crbug-387599': [SKIP], + 'regress/regress-crbug-405922': [SKIP], + 'regress/regress-crbug-409614': [SKIP], + 'regress/regress-crbug-410033': [SKIP], + 'regress/regress-crbug-412208': [SKIP], + 'regress/regress-crbug-416558': [SKIP], + 'regress/regress-crbug-424142': [SKIP], + 'regress/regress-crbug-431602': [SKIP], + 'regress/regress-crbug-432493': [SKIP], + 'regress/regress-crbug-450642': [SKIP], + 'regress/regress-crbug-465298': [SKIP], + 'regress/regress-crbug-467180': [SKIP], + 'regress/regress-crbug-467531': [SKIP], + 'regress/regress-crbug-474297': [SKIP], + 'regress/regress-crbug-480819': [SKIP], + 'regress/regress-crbug-481896': [SKIP], + 'regress/regress-crbug-485548-1': [SKIP], + 'regress/regress-crbug-485548-2': [SKIP], + 'regress/regress-crbug-487289': [SKIP], + 'regress/regress-crbug-489293': [SKIP], + 'regress/regress-crbug-489597': [SKIP], + 'regress/regress-crbug-498142': [SKIP], + 'regress/regress-crbug-500824': [SKIP], + 'regress/regress-crbug-501809': [SKIP], + 'regress/regress-crbug-506443': [SKIP], + 'regress/regress-crbug-507070': [SKIP], + 'regress/regress-crbug-527364': [SKIP], + 'regress/regress-crbug-530598': [SKIP], + 'regress/regress-crbug-546968': [SKIP], + 'regress/regress-deopt-gcb': [SKIP], + 'regress/regress-deopt-gc': [SKIP], + 'regress/regress-embedded-cons-string': [SKIP], + 'regress/regress-existing-shared-function-info': [SKIP], + 'regress/regress-fast-literal-transition': [SKIP], + 'regress/regress-force-representation': [SKIP], + 'regress/regress-function-constructor-receiver': [SKIP], + 'regress/regress-handle-illegal-redeclaration': [SKIP], + 'regress/regress-inline-class-constructor': [SKIP], + 'regress/regress-inlining-function-literal-context': [SKIP], + 'regress/regress-lazy-deopt-reloc': [SKIP], + 'regress/regress-map-invalidation-2': [SKIP], + 'regress/regress-opt-after-debug-deopt': [SKIP], + 'regress/regress-param-local-type': [SKIP], + 'regress/regress-prepare-break-while-recompile': [SKIP], + 'regress/regress-put-prototype-transition': [SKIP], + 'regress/regress-sliced-external-cons-regexp': [SKIP], + 'regress/regress-transcendental': [SKIP], + 'regress/regress-typedarray-length': [SKIP], + 'regress/splice-missing-wb': [SKIP], + 'shift-for-integer-div': [SKIP], + 'simple-constructor': [SKIP], + 'sin-cos': [SKIP], + 'smi-mul-const': [SKIP], + 'smi-mul': [SKIP], + 'sparse-array-reverse': [SKIP], + 'stack-traces': [SKIP], + 'strict-mode': [SKIP], + 'string-case': [SKIP], + 'string-external-cached': [SKIP], + 'string-externalize': [SKIP], + 'string-natives': [SKIP], + 'string-replace-with-empty': [SKIP], + 'string-slices': [SKIP], + 'switch-opt': [SKIP], + 'tools/profile': [SKIP], + 'tools/profviz': [SKIP], + 'try-finally-continue': [SKIP], + 'try': [SKIP], + 'unary-minus-deopt': [SKIP], + 'undetectable-compare': [SKIP], + 'unused-context-in-with': [SKIP], + 'uri': [SKIP], + 'value-wrapper': [SKIP], + 'with-parameter-access': [SKIP], + 'with-prototype': [SKIP], + 'with-readonly': [SKIP], +}], # ignition == True + +['ignition == True and (arch == arm or arch == arm64)', { + 'array-sort': [SKIP], + 'date-parse': [SKIP], + 'math-floor-part1': [SKIP], + 'math-floor-part2': [SKIP], + 'math-floor-part3': [SKIP], + 'mul-exhaustive-part*': [SKIP], + 'regress/regress-1167': [SKIP], + 'regress/regress-165637': [SKIP], + 'regress/regress-2249': [SKIP], + 'regress/regress-319722-ArrayBuffer': [SKIP], + 'regress/regress-542823': [SKIP], + 'regress/regress-634-debug': [SKIP], + 'regress/regress-78270': [SKIP], + 'regress/regress-crbug-347903': [SKIP], + 'regress/regress-crbug-505007-1': [SKIP], + 'regress/regress-crbug-505007-2': [SKIP], + 'regress/short-circuit': [SKIP], + 'stack-traces-overflow': [SKIP], + 'unicodelctest': [SKIP], + 'unicodelctest-no-optimization': [SKIP], +}], # ignition == True and (arch == arm or arch == arm64) + ] diff --git a/deps/v8/test/mjsunit/object-prevent-extensions.js b/deps/v8/test/mjsunit/object-prevent-extensions.js index bde3161c60..9f3091ebb4 100644 --- a/deps/v8/test/mjsunit/object-prevent-extensions.js +++ b/deps/v8/test/mjsunit/object-prevent-extensions.js @@ -88,7 +88,7 @@ Object.preventExtensions(arr); arr[2] = 42; assertEquals(10, arr[1]); -// We should still be able to change exiting elements. +// We should still be able to change existing elements. arr[1]= 42; assertEquals(42, arr[1]); diff --git a/deps/v8/test/mjsunit/regexp-static.js b/deps/v8/test/mjsunit/regexp-static.js index 8f283f6cee..0d6d85c660 100644 --- a/deps/v8/test/mjsunit/regexp-static.js +++ b/deps/v8/test/mjsunit/regexp-static.js @@ -119,7 +119,7 @@ for (var i = 4; i < 10; ++i) { // case the function uses the static properties of the regexp constructor. re = /(.)/g; function f() { return RegExp.$1; }; -assertEquals('abcd', 'abcd'.replace(re, f)); +assertEquals('dddd', 'abcd'.replace(re, f)); // lastParen where the last parenthesis didn't match. assertEquals(["foo",undefined], /foo(?:a(x))?/.exec("foobx"), @@ -144,8 +144,6 @@ for (var i = 1; i <= 9; i++) { assertEquals("", RegExp['$' + (i)], "$" + i); } -RegExp.multiline = "foo"; -assertTrue(typeof RegExp.multiline == typeof Boolean(), "RegExp.multiline coerces values to booleans"); RegExp.input = Number(); assertTrue(typeof RegExp.input == typeof String(), "RegExp.input coerces values to booleans"); diff --git a/deps/v8/test/mjsunit/regexp.js b/deps/v8/test/mjsunit/regexp.js index c2d92823bc..6374296210 100644 --- a/deps/v8/test/mjsunit/regexp.js +++ b/deps/v8/test/mjsunit/regexp.js @@ -605,23 +605,29 @@ assertEquals(["ts", "li"], log); // Check that properties of RegExp have the correct permissions. var re = /x/g; -var desc = Object.getOwnPropertyDescriptor(re, "global"); -assertEquals(true, desc.value); -assertEquals(false, desc.configurable); +var desc = Object.getOwnPropertyDescriptor(re.__proto__, "global"); +assertInstanceof(desc.get, Function); +assertEquals(true, desc.configurable); assertEquals(false, desc.enumerable); -assertEquals(false, desc.writable); -desc = Object.getOwnPropertyDescriptor(re, "multiline"); -assertEquals(false, desc.value); -assertEquals(false, desc.configurable); +desc = Object.getOwnPropertyDescriptor(re.__proto__, "multiline"); +assertInstanceof(desc.get, Function); +assertEquals(true, desc.configurable); assertEquals(false, desc.enumerable); -assertEquals(false, desc.writable); -desc = Object.getOwnPropertyDescriptor(re, "ignoreCase"); -assertEquals(false, desc.value); -assertEquals(false, desc.configurable); +desc = Object.getOwnPropertyDescriptor(re.__proto__, "ignoreCase"); +assertInstanceof(desc.get, Function); +assertEquals(true, desc.configurable); assertEquals(false, desc.enumerable); -assertEquals(false, desc.writable); + +desc = Object.getOwnPropertyDescriptor(re, "global"); +assertEquals(undefined, desc); + +desc = Object.getOwnPropertyDescriptor(re, "multiline"); +assertEquals(undefined, desc); + +desc = Object.getOwnPropertyDescriptor(re, "ignoreCase"); +assertEquals(undefined, desc); desc = Object.getOwnPropertyDescriptor(re, "lastIndex"); assertEquals(0, desc.value); diff --git a/deps/v8/test/mjsunit/regress-crbug-528379.js b/deps/v8/test/mjsunit/regress-crbug-528379.js new file mode 100644 index 0000000000..f335f6a104 --- /dev/null +++ b/deps/v8/test/mjsunit/regress-crbug-528379.js @@ -0,0 +1,8 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --enable-slow-asserts + +Error.prepareStackTrace = function(e, frames) { return frames; } +assertThrows(function() { new Error().stack[0].getMethodName.call({}); }); diff --git a/deps/v8/test/mjsunit/regress/call-function-in-effect-context-deopt.js b/deps/v8/test/mjsunit/regress/call-function-in-effect-context-deopt.js index 704af744d2..72d3938511 100644 --- a/deps/v8/test/mjsunit/regress/call-function-in-effect-context-deopt.js +++ b/deps/v8/test/mjsunit/regress/call-function-in-effect-context-deopt.js @@ -29,7 +29,7 @@ function f(deopt, osr) { var result = "result"; - %_CallFunction(0, 0, function() {}); + %_Call(function() {}, 0, 0); var dummy = deopt + 0; for (var i = 0; osr && i < 2; i++) %OptimizeOsr(); return result; diff --git a/deps/v8/test/mjsunit/regress/regress-2193.js b/deps/v8/test/mjsunit/regress/regress-2193.js index 50509bfcbd..4ec050e10a 100644 --- a/deps/v8/test/mjsunit/regress/regress-2193.js +++ b/deps/v8/test/mjsunit/regress/regress-2193.js @@ -25,7 +25,7 @@ // (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 --cache-optimized-code +// Flags: --allow-natives-syntax function bozo() {}; function MakeClosure() { diff --git a/deps/v8/test/mjsunit/regress/regress-2438.js b/deps/v8/test/mjsunit/regress/regress-2438.js index 7be7e71687..f694ff8e19 100644 --- a/deps/v8/test/mjsunit/regress/regress-2438.js +++ b/deps/v8/test/mjsunit/regress/regress-2438.js @@ -35,14 +35,6 @@ function testSideEffects(subject, re) { re.lastIndex = side_effect_object; re.test(subject); assertEquals(2, counter); - - re.lastIndex = side_effect_object; - subject.match(re); - assertEquals(3, counter); - - re.lastIndex = side_effect_object; - subject.replace(re, ""); - assertEquals(4, counter); } testSideEffects("zzzz", /a/); diff --git a/deps/v8/test/mjsunit/global-deleted-property-keyed.js b/deps/v8/test/mjsunit/regress/regress-2529.js index a0e48ffdeb..cec56a60f5 100644 --- a/deps/v8/test/mjsunit/global-deleted-property-keyed.js +++ b/deps/v8/test/mjsunit/regress/regress-2529.js @@ -1,4 +1,4 @@ -// Copyright 2009 the V8 project authors. All rights reserved. +// Copyright 2015 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: @@ -26,13 +26,18 @@ // 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. +// Regression test for v8 bug 2529. -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(); +function makeScript(s) { + return 'while(true) { try { "try"; break } finally { "finally" }; ' + s + ' }'; +} + +var s1 = makeScript(''); +var s2 = makeScript('y = "done"'); +var s3 = makeScript('if (true) 2; else var x = 3;'); +var s4 = makeScript('if (true) 2; else 3;'); + +assertEquals("try", eval(s1)); +assertEquals("try", eval(s2)); +assertEquals("try", eval(s3)); +assertEquals("try", eval(s4)); diff --git a/deps/v8/test/mjsunit/regress/regress-3183.js b/deps/v8/test/mjsunit/regress/regress-3183.js index 0c915b0aec..4551621e65 100644 --- a/deps/v8/test/mjsunit/regress/regress-3183.js +++ b/deps/v8/test/mjsunit/regress/regress-3183.js @@ -83,7 +83,7 @@ } function bar(x, deopt) { - %_CallFunction(null, 'push', [x][0], ((deopt + 0), 1), f1); + %_Call(f1, null, 'push', [x][0], ((deopt + 0), 1)); } function foo() { return bar(arguments[0], arguments[1]); } diff --git a/deps/v8/test/mjsunit/regress/regress-3229.js b/deps/v8/test/mjsunit/regress/regress-3229.js index 1a0ed64412..419cade8cd 100644 --- a/deps/v8/test/mjsunit/regress/regress-3229.js +++ b/deps/v8/test/mjsunit/regress/regress-3229.js @@ -17,7 +17,6 @@ testEscapes("\\/\\/", new RegExp("\\/\\/")); testEscapes("\\/\\/\\/\\/", new RegExp("////")); testEscapes("\\/\\/\\/\\/", new RegExp("\\//\\//")); testEscapes("(?:)", new RegExp("")); -testEscapes("(?:)", RegExp.prototype); // Read-only property. var r = /\/\//; diff --git a/deps/v8/test/mjsunit/regress/regress-3281.js b/deps/v8/test/mjsunit/regress/regress-3281.js index 7d42c026b6..f7b167e3b8 100644 --- a/deps/v8/test/mjsunit/regress/regress-3281.js +++ b/deps/v8/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/deps/v8/test/mjsunit/regress/regress-403292.js b/deps/v8/test/mjsunit/regress/regress-403292.js index 4e7ba283f7..2e24d48ac4 100644 --- a/deps/v8/test/mjsunit/regress/regress-403292.js +++ b/deps/v8/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/deps/v8/test/mjsunit/regress/regress-447561.js b/deps/v8/test/mjsunit/regress/regress-447561.js index 0d7a321de0..e1a5ba5aa5 100644 --- a/deps/v8/test/mjsunit/regress/regress-447561.js +++ b/deps/v8/test/mjsunit/regress/regress-447561.js @@ -3,8 +3,8 @@ // found in the LICENSE file. __proto__ = /foo/gi; -assertEquals("foo", source); -assertTrue(global); -assertTrue(ignoreCase); -assertFalse(multiline); +assertThrows(function() { source }); +assertThrows(function() { global }); +assertThrows(function() { ignoreCase }); +assertThrows(function() { multiline }); assertEquals(0, lastIndex); diff --git a/deps/v8/test/mjsunit/regress/regress-4493-1.js b/deps/v8/test/mjsunit/regress/regress-4493-1.js new file mode 100644 index 0000000000..a24c8b07dc --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4493-1.js @@ -0,0 +1,16 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function baz(x, f) { return x.length; }; + +function bar(x, y) { + if (y) {} + baz(x, function() { return x; }); +}; + +function foo(x) { bar(x, ''); } +%OptimizeFunctionOnNextCall(foo); +foo(['a']); diff --git a/deps/v8/test/mjsunit/regress/regress-4495.js b/deps/v8/test/mjsunit/regress/regress-4495.js new file mode 100644 index 0000000000..2af5bc2445 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4495.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +function foo(a, s) { a[s] = 35; } +var x = { bilbo: 3 }; +var y = { frodo: 3, bilbo: 'hi' }; +foo(x, "bilbo"); +foo(x, "bilbo"); +// Without the fix for 4495, this will crash on ia32: +foo(y, "bilbo"); diff --git a/deps/v8/test/mjsunit/regress/regress-4507.js b/deps/v8/test/mjsunit/regress/regress-4507.js new file mode 100644 index 0000000000..a3fe5107be --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4507.js @@ -0,0 +1,19 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function broken(value) { + return Math.floor(value/65536); +} +function toUnsigned(i) { + return i >>> 0; +} +function outer(i) { + return broken(toUnsigned(i)); +} +for (var i = 0; i < 5; i++) outer(0); +broken(0x80000000); // Spice things up with a sprinkling of type feedback. +%OptimizeFunctionOnNextCall(outer); +assertEquals(32768, outer(0x80000000)); diff --git a/deps/v8/test/mjsunit/regress/regress-4515.js b/deps/v8/test/mjsunit/regress/regress-4515.js new file mode 100644 index 0000000000..81610f08a5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4515.js @@ -0,0 +1,17 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --turbo-filter=f + +function f(array) { + return array.length >>> 0; +} + +var a = new Array(); +a[4000000000] = "A"; + +assertEquals(4000000001, f(a)); +assertEquals(4000000001, f(a)); +%OptimizeFunctionOnNextCall(f); +assertEquals(4000000001, f(a)); diff --git a/deps/v8/test/mjsunit/regress/regress-4521.js b/deps/v8/test/mjsunit/regress/regress-4521.js new file mode 100644 index 0000000000..f9bdafcea8 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4521.js @@ -0,0 +1,20 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +"use strict"; + +class B { + foo() { return 23 } +} + +class C extends B { + bar() { return super[%DeoptimizeFunction(C.prototype.bar), "foo"]() } +} + +assertEquals(23, new C().bar()); +assertEquals(23, new C().bar()); +%OptimizeFunctionOnNextCall(C.prototype.bar); +assertEquals(23, new C().bar()); diff --git a/deps/v8/test/mjsunit/regress/regress-4525.js b/deps/v8/test/mjsunit/regress/regress-4525.js new file mode 100644 index 0000000000..b962dc07ca --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4525.js @@ -0,0 +1,37 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function receiver() { + return this; +} + +function construct(f) { + "use strict"; + class B {} + class C extends B { + bar() { return super.foo() } + } + B.prototype.foo = f; + return new C(); +} + +function check(x, value, type) { + assertEquals("object", typeof x); + assertInstanceof(x, type); + assertEquals(value, x); +} + +var o = construct(receiver); +check(o.bar.call(123), Object(123), Number); +check(o.bar.call("a"), Object("a"), String); +check(o.bar.call(undefined), this, Object); +check(o.bar.call(null), this, Object); + +%OptimizeFunctionOnNextCall(o.bar); +check(o.bar.call(456), Object(456), Number); +check(o.bar.call("b"), Object("b"), String); +check(o.bar.call(undefined), this, Object); +check(o.bar.call(null), this, Object); diff --git a/deps/v8/test/mjsunit/regress/regress-4534.js b/deps/v8/test/mjsunit/regress/regress-4534.js new file mode 100644 index 0000000000..7042958ad2 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4534.js @@ -0,0 +1,17 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --expose-gc + +var dp = Object.defineProperty; +function getter() { return 111; } +function setter(x) { print(222); } +obj1 = {}; +dp(obj1, "golf", { get: getter, configurable: true }); +dp(obj1, "golf", { set: setter, configurable: true }); +gc(); +obj2 = {}; +dp(obj2, "golf", { get: getter, configurable: true }); +dp(obj2, "golf", { set: setter, configurable: true }); +assertTrue(%HaveSameMap(obj1, obj2)); diff --git a/deps/v8/test/mjsunit/regress/regress-536751.js b/deps/v8/test/mjsunit/regress/regress-536751.js new file mode 100644 index 0000000000..b2d19e422a --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-536751.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-sloppy --harmony-sloppy-function --harmony-sloppy-let + +// At some point, this code led to DCHECK errors in debug mode + +for (; false;) function foo() {}; + +for (x in []) function foo() {}; diff --git a/deps/v8/test/mjsunit/regress/regress-542099.js b/deps/v8/test/mjsunit/regress/regress-542099.js new file mode 100644 index 0000000000..f3655da53c --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-542099.js @@ -0,0 +1,18 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-sloppy --harmony-sloppy-function + +// Previously, this caused a CHECK fail in debug mode +// https://code.google.com/p/chromium/issues/detail?id=542099 + +var foo = {}; +var bar = foo; +for (foo.x in {a: 1}) function foo() { return foo; } +assertEquals("object", typeof bar); +assertEquals("a", bar.x); +assertEquals("function", typeof foo); +assertEquals("function", typeof foo()); +assertSame(foo, foo()); +assertEquals(undefined, foo.x); diff --git a/deps/v8/test/mjsunit/regress/regress-542100.js b/deps/v8/test/mjsunit/regress/regress-542100.js new file mode 100644 index 0000000000..bc03e6f9e2 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-542100.js @@ -0,0 +1,25 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-sloppy --harmony-sloppy-function + +(function() { + var x = {a: 1} + assertEquals("undefined", typeof f); + with (x) + function f() { return a; } + assertEquals("function", typeof f); + assertEquals(1, f()); + x.a = 2; + assertEquals(2, f()); +})(); + +var y = {b: 1} +assertEquals("undefined", typeof g); +with (y) + function g() { return b; } +assertEquals("function", typeof g); +assertEquals(1, g()); +y.b = 2; +assertEquals(2, g()); diff --git a/deps/v8/test/mjsunit/regress/regress-542823.js b/deps/v8/test/mjsunit/regress/regress-542823.js new file mode 100644 index 0000000000..d9c23396d4 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-542823.js @@ -0,0 +1,12 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +__v_0 = 100000; +__v_1 = new Array(); +for (var __v_2 = 0; __v_2 < __v_0; __v_2++) { + __v_1[__v_2] = 0.5; +} +for (var __v_2 = 0; __v_2 < 10; __v_2++) { + var __v_0 = __v_1 + 0.5; +} diff --git a/deps/v8/test/mjsunit/regress/regress-543994.js b/deps/v8/test/mjsunit/regress/regress-543994.js new file mode 100644 index 0000000000..e0d6010287 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-543994.js @@ -0,0 +1,19 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flass: --allow-natives-syntax --always-opt --gc-interval=163 --stress-compaction + +try { a = f(); +} catch(e) { +} +var i = 0; +function f() { + try { + f(); + } catch(e) { + i++; + []; + } +} +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-552302.js b/deps/v8/test/mjsunit/regress/regress-552302.js new file mode 100644 index 0000000000..d4a1f2448e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-552302.js @@ -0,0 +1,7 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --harmony-destructuring --allow-natives-syntax + +assertThrows('var %OptimizeFunctionOnNextCall()', SyntaxError); diff --git a/deps/v8/test/mjsunit/regress/regress-95113.js b/deps/v8/test/mjsunit/regress/regress-95113.js index 468bff84c2..aa526ae0b9 100644 --- a/deps/v8/test/mjsunit/regress/regress-95113.js +++ b/deps/v8/test/mjsunit/regress/regress-95113.js @@ -31,8 +31,8 @@ function get_double_array() { var a = new Array(100000); var i = 0; while (!%HasFastDoubleElements(a)) { - a[i] = i; - i += 0.5; + a[i] = i + 0.1; + i += 1; } assertTrue(%HasFastDoubleElements(a)); a.length = 1; diff --git a/deps/v8/test/mjsunit/regress/regress-95920.js b/deps/v8/test/mjsunit/regress/regress-95920.js index 20e73fbc40..5584965561 100644 --- a/deps/v8/test/mjsunit/regress/regress-95920.js +++ b/deps/v8/test/mjsunit/regress/regress-95920.js @@ -28,31 +28,23 @@ // Tests that objects with external arrays cannot be sealed or have their // properties redefined. -(function() { - assertThrows(function() { - [0].every(function(){ Object.seal((new Int8Array(42))); }); - assertUnreable(); - }, TypeError) -})(); +Object.preventExtensions(new Int8Array(42)); +Object.seal(new Int8Array(42)); -(function() { - assertThrows(function() { - [0].every(function(){ Object.freeze((new Int8Array(42))); }); - assertUnreable(); - }, TypeError) -})(); +// No elements, so should succeed. +Object.freeze(new Int8Array(0)); -(function() { - assertThrows(function() { - [0].every(function(){ Object.preventExtensions((new Int8Array(42))); }); - assertUnreable(); - }, TypeError) -})(); +var o = new Int8Array(42); +assertThrows(function() { + Object.freeze(o); + assertUnreable(); + }, TypeError); -(function() { - assertThrows(function() { - Object.defineProperty(new Int8Array(42), "1", - { writable: false, value: "1" }); - assertUnreable(); - }) -})(); +// Freeze should still have managed to preventExtensions o. +assertFalse(Object.isExtensible(o)); + +assertThrows(function() { + Object.defineProperty(new Int8Array(42), "1", + { writable: false, value: "1" }); + assertUnreable(); + }); diff --git a/deps/v8/test/mjsunit/regress/regress-arguments-slice.js b/deps/v8/test/mjsunit/regress/regress-arguments-slice.js new file mode 100644 index 0000000000..f7cd8c6ec8 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-arguments-slice.js @@ -0,0 +1,8 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +function f() { return arguments; } +var o = f(); +o.length = -100; +Array.prototype.slice.call(o); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-119800.js b/deps/v8/test/mjsunit/regress/regress-crbug-119800.js new file mode 100644 index 0000000000..1641cac686 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-119800.js @@ -0,0 +1,37 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug + +function f() { + 1; + 2; + 3; +} + +var Debug = debug.Debug; +var exception = null; +var breaks = []; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + Debug.debuggerFlags().breakPointsActive.setValue(false); + breaks.push(exec_state.frame().sourceLineText().trimLeft()); + exec_state.prepareStep(Debug.StepAction.StepIn, 1); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); +Debug.setBreakPoint(f, 0, 0); + +f(); + +Debug.setListener(null); +Debug.debuggerFlags().breakPointsActive.setValue(true); + +assertNull(exception); +assertEquals(breaks, ["1;", "2;", "3;", "}", "Debug.setListener(null);"]); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-401915.js b/deps/v8/test/mjsunit/regress/regress-crbug-401915.js index 67ea19158e..9786313227 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-401915.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-401915.js @@ -10,7 +10,7 @@ Debug.setBreakOnException(); try { try { - %DebugPushPromise(new Promise(function() {}), function() {}); + %DebugPushPromise(new Promise(function() {}), function() {}, function() {}); } catch (e) { } throw new Error(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-405922.js b/deps/v8/test/mjsunit/regress/regress-crbug-405922.js index 9f76a862db..a38ac86912 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-405922.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-405922.js @@ -18,7 +18,7 @@ function listener(event, exec_state, event_data, data) { Debug.setListener(listener); function f(x) { - if (x > 0) %_CallFunction(null, x-1, f); + if (x > 0) %_Call(f, null, x-1); } debugger; diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-465298.js b/deps/v8/test/mjsunit/regress/regress-crbug-465298.js index 0b2827b0d2..0c5ab56c7a 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-465298.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-465298.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --noturbo-osr --expose-debug-as debug +// Flags: --noturbo-osr --noturbo-inlining --expose-debug-as debug var stdlib = this; var buffer = new ArrayBuffer(64 * 1024); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-485410.js b/deps/v8/test/mjsunit/regress/regress-crbug-485410.js index 55c9c43dbf..bb11c82908 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-485410.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-485410.js @@ -11,7 +11,7 @@ function ToHeapNumber(i) { } for (var i = 0; i < 3; i++) ToHeapNumber(i); %OptimizeFunctionOnNextCall(ToHeapNumber); -assertFalse(%IsSmi(ToHeapNumber(1))); +ToHeapNumber(1); function Fail(a, i, v) { a[i] = v; diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-538086.js b/deps/v8/test/mjsunit/regress/regress-crbug-538086.js new file mode 100644 index 0000000000..537cbda5fc --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-538086.js @@ -0,0 +1,6 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +this[1]++; +for (var x in this) {}; diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-542101.js b/deps/v8/test/mjsunit/regress/regress-crbug-542101.js new file mode 100644 index 0000000000..1a4c2b37ce --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-542101.js @@ -0,0 +1,10 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function() { + Error.prototype.toString.call({ + get name() { return { __proto__: this }; }, + get message() { } + }); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-545364.js b/deps/v8/test/mjsunit/regress/regress-crbug-545364.js new file mode 100644 index 0000000000..4fe99d0133 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-545364.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function() { + "use asm"; + return function(x) { + for (var i = 0; i < 100000; ++i) {} + return x; + } +})()(this + "i"); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-546968.js b/deps/v8/test/mjsunit/regress/regress-crbug-546968.js new file mode 100644 index 0000000000..51f20c4204 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-546968.js @@ -0,0 +1,14 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --harmony-do-expressions + +function f() { + print( + do { + for (var i = 0; i < 10; i++) { if (i == 5) %OptimizeOsr(); } + } + ); +} +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-548580.js b/deps/v8/test/mjsunit/regress/regress-crbug-548580.js new file mode 100644 index 0000000000..4a2f5e152f --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-548580.js @@ -0,0 +1,17 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-regexps + +function store(v) { + var re = /(?=[d#.])/; + re.a = v; + return re; +} + +var re1 = store(undefined); +var re2 = store(42); + +assertEquals(re1.a, undefined); +assertEquals(re2.a, 42); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-549162.js b/deps/v8/test/mjsunit/regress/regress-crbug-549162.js new file mode 100644 index 0000000000..072bdd52d9 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-549162.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var s = Symbol("foo"); +var __v_13 = {} +Object.defineProperty( __v_13, s, {value: {}, enumerable: true}); +for (var __v_14 in __v_13) {} +__v_13 = {} +Object.defineProperty( __v_13, s, {value: {}, enumerable: true}); +var __v_14 = Object.create(Object.prototype, __v_13) diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-552304.js b/deps/v8/test/mjsunit/regress/regress-crbug-552304.js new file mode 100644 index 0000000000..fa3baa34c1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-552304.js @@ -0,0 +1,11 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function() { + "use asm"; + return function() { + for (var i = 0; i < 100000; delete unresolved_name) {++i} + return 0; + } +})()(this + "i"); diff --git a/deps/v8/test/mjsunit/regress/regress-function-constructor-receiver.js b/deps/v8/test/mjsunit/regress/regress-function-constructor-receiver.js index f345435ade..5d713803be 100644 --- a/deps/v8/test/mjsunit/regress/regress-function-constructor-receiver.js +++ b/deps/v8/test/mjsunit/regress/regress-function-constructor-receiver.js @@ -10,8 +10,8 @@ try { new Function({toString:0,valueOf:0}); } catch (e) { threw = true; - // Ensure that the receiver during "new Function" is the global proxy. - assertEquals(this, e.stack[0].getThis()); + // Ensure that the receiver during "new Function" is the undefined value. + assertEquals(undefined, e.stack[0].getThis()); } assertTrue(threw); diff --git a/deps/v8/test/mjsunit/regress/regress-inline-class-constructor.js b/deps/v8/test/mjsunit/regress/regress-inline-class-constructor.js new file mode 100644 index 0000000000..1d77176758 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-inline-class-constructor.js @@ -0,0 +1,28 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +"use strict"; + +var B = class extends Int32Array { } + +function f(b) { + if (b) { + null instanceof B; + } +} + +f(); +f(); +f(); +%OptimizeFunctionOnNextCall(f); +f(); + +function f2() { + return new B(); +} + +%OptimizeFunctionOnNextCall(f2); +f2(); diff --git a/deps/v8/test/mjsunit/regress/string-fromcharcode-sideeffect.js b/deps/v8/test/mjsunit/regress/string-fromcharcode-sideeffect.js new file mode 100644 index 0000000000..432ba2c38d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/string-fromcharcode-sideeffect.js @@ -0,0 +1,8 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var counter = 0; +var a = { valueOf: function() { counter++; return 0x100; } }; +assertEquals("A\u0100\u0100\u0100", String.fromCharCode(65, a, a, a)); +assertEquals(3, counter); diff --git a/deps/v8/test/mjsunit/regress/typed-array-lifetime.js b/deps/v8/test/mjsunit/regress/typed-array-lifetime.js new file mode 100644 index 0000000000..db9a216531 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/typed-array-lifetime.js @@ -0,0 +1,26 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Flags: --allow-natives-syntax --typed-array-max-size-in-heap=1 + +var foo = (function () { + var y = 0; + return function foo(x) { + // Needs to be an external array. + var a = new Float64Array(32); + a[0] = 42; + y = x + 0.1; // This has to allocate. + return a[0]; + } +})(); + +foo(1); +foo(1); +%OptimizeFunctionOnNextCall(foo); +foo(1); +// Try to force a GC during allocation in above marked line. +for (var i = 0; i < 20; ++i) { + %SetAllocationTimeout(i, i, false); + assertEquals(42, foo(2)); +} diff --git a/deps/v8/test/mjsunit/samevalue.js b/deps/v8/test/mjsunit/samevalue.js index 174afd2372..038fd68eb9 100644 --- a/deps/v8/test/mjsunit/samevalue.js +++ b/deps/v8/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) { diff --git a/deps/v8/test/mjsunit/string-replace.js b/deps/v8/test/mjsunit/string-replace.js index de92115575..e8392ae2bf 100644 --- a/deps/v8/test/mjsunit/string-replace.js +++ b/deps/v8/test/mjsunit/string-replace.js @@ -163,6 +163,30 @@ replaceTest("0a1b2cx", short, /(x)(?=(.))/g, function r(m, c1, c2, i, s) { assertEquals(3, ctr, "replace(/x/g,func) num-match"); +replaceTest("ABCD", "abcd", /(.)/g, function r(m, c1, i, s) { + assertEquals("d", RegExp.lastMatch); + assertEquals("d", RegExp.$1); + assertEquals("abc", RegExp.leftContext); + return m.toUpperCase(); +}); + + +var long = ""; +while (long.length < 0x2000) { + long += String.fromCharCode(65 + Math.random() * 26); +} + +for (var i = 0; i < 3; i++) { + replaceTest(long.toLowerCase(), long, /(..)/g, function r(m, c1, i, s) { + var expected = long.substring(0x1ffe, 0x2000); + assertEquals(expected, RegExp.lastMatch); + assertEquals(expected, RegExp.$1); + assertEquals(long.substring(0, 0x1ffe), RegExp.leftContext); + return m.toLowerCase(); + }); +} + + // Test special cases of replacement parts longer than 1<<11. var longstring = "xyzzy"; longstring = longstring + longstring; @@ -194,20 +218,6 @@ replaceTest("aundefinedbundefinedcundefined", // Test nested calls to replace, including that it sets RegExp.$& correctly. -function replacer(m,i,s) { - assertEquals(m,RegExp['$&']); - return "[" + RegExp['$&'] + "-" - + m.replace(/./g,"$&$&") + "-" - + m.replace(/./g,function() { return RegExp['$&']; }) - + "-" + RegExp['$&'] + "]"; -} - -replaceTest("[ab-aabb-ab-b][az-aazz-az-z]", - "abaz", /a./g, replacer); - -replaceTest("[ab-aabb-ab-b][az-aazz-az-z]", - "abaz", /a(.)/g, replacer); - var str = 'She sells seashells by the seashore.'; var re = /sh/g; assertEquals('She sells sea$schells by the sea$schore.', diff --git a/deps/v8/test/mjsunit/strong/classes.js b/deps/v8/test/mjsunit/strong/classes.js index c8d261760d..92dea0f2a9 100644 --- a/deps/v8/test/mjsunit/strong/classes.js +++ b/deps/v8/test/mjsunit/strong/classes.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --strong-mode --harmony-arrow-functions +// Flags: --strong-mode 'use strong'; diff --git a/deps/v8/test/mjsunit/strong/declaration-after-use.js b/deps/v8/test/mjsunit/strong/declaration-after-use.js index e6caccfcca..ee44983329 100644 --- a/deps/v8/test/mjsunit/strong/declaration-after-use.js +++ b/deps/v8/test/mjsunit/strong/declaration-after-use.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --strong-mode --harmony-rest-parameters --harmony-arrow-functions +// Flags: --strong-mode --harmony-rest-parameters // Note that it's essential for these tests that the reference is inside dead // code (because we already produce ReferenceErrors for run-time unresolved diff --git a/deps/v8/test/mjsunit/strong/destructuring.js b/deps/v8/test/mjsunit/strong/destructuring.js index 3145dcfb4d..b3971b3b09 100644 --- a/deps/v8/test/mjsunit/strong/destructuring.js +++ b/deps/v8/test/mjsunit/strong/destructuring.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // // Flags: --harmony-destructuring -// Flags: --harmony-arrow-functions --strong-mode --allow-natives-syntax +// Flags: --strong-mode --allow-natives-syntax (function() { var f = (function() { diff --git a/deps/v8/test/mjsunit/strong/function-arity.js b/deps/v8/test/mjsunit/strong/function-arity.js index 67c0d1f195..5ead236171 100644 --- a/deps/v8/test/mjsunit/strong/function-arity.js +++ b/deps/v8/test/mjsunit/strong/function-arity.js @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --strong-mode --harmony-arrow-functions --harmony-reflect -// Flags: --harmony-spread-calls --harmony-rest-parameters --allow-natives-syntax +// Flags: --strong-mode --harmony-reflect +// Flags: --harmony-rest-parameters --allow-natives-syntax 'use strict'; @@ -70,8 +70,7 @@ function generateSpread(n) { `f.call(undefined, ${generateSpread(argumentCount)})`, `f.apply(undefined, [${generateArguments(argumentCount)}])`, `f.bind(undefined)(${generateArguments(argumentCount)})`, - `%_CallFunction(${generateArguments(argumentCount, 'undefined')}, - f)`, + `%_Call(f, ${generateArguments(argumentCount, 'undefined')})`, `%Call(f, ${generateArguments(argumentCount, 'undefined')})`, `%Apply(f, undefined, [${generateArguments(argumentCount)}], 0, ${argumentCount})`, @@ -134,7 +133,7 @@ function generateSpread(n) { `o.m.call(o, ${generateSpread(argumentCount)})`, `o.m.apply(o, [${generateArguments(argumentCount)}])`, `o.m.bind(o)(${generateArguments(argumentCount)})`, - `%_CallFunction(${generateArguments(argumentCount, 'o')}, o.m)`, + `%_Call(o.m, ${generateArguments(argumentCount, 'o')})`, `%Call(o.m, ${generateArguments(argumentCount, 'o')})`, `%Apply(o.m, o, [${generateArguments(argumentCount)}], 0, ${argumentCount})`, diff --git a/deps/v8/test/mjsunit/strong/literals.js b/deps/v8/test/mjsunit/strong/literals.js index a78f793a02..c9457ffbec 100644 --- a/deps/v8/test/mjsunit/strong/literals.js +++ b/deps/v8/test/mjsunit/strong/literals.js @@ -3,8 +3,8 @@ // found in the LICENSE file. // Flags: --strong-mode --allow-natives-syntax -// Flags: --harmony-arrow-functions --harmony-rest-parameters -// Flags: --harmony-destructuring --harmony-spread-arrays +// Flags: --harmony-rest-parameters +// Flags: --harmony-destructuring 'use strict'; diff --git a/deps/v8/test/mjsunit/strong/mutually-recursive-classes.js b/deps/v8/test/mjsunit/strong/mutually-recursive-classes.js index c8cf9788ba..204c3964de 100644 --- a/deps/v8/test/mjsunit/strong/mutually-recursive-classes.js +++ b/deps/v8/test/mjsunit/strong/mutually-recursive-classes.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --strong-mode --harmony-arrow-functions +// Flags: --strong-mode "use strict" let prologue_dead = "(function outer() { if (false) { "; diff --git a/deps/v8/test/mjsunit/strong/undefined.js b/deps/v8/test/mjsunit/strong/undefined.js index f324106b30..218547a192 100644 --- a/deps/v8/test/mjsunit/strong/undefined.js +++ b/deps/v8/test/mjsunit/strong/undefined.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --strong-mode --harmony-sloppy --harmony-arrow-functions +// Flags: --strong-mode --harmony-sloppy // Repurposing the strict mode 'eval' and 'arguments' tests to test for correct // behaviour of 'undefined' as an identifier in strong mode. diff --git a/deps/v8/test/mjsunit/third_party/object-keys/object-keys.js b/deps/v8/test/mjsunit/third_party/object-keys/object-keys.js index c8003745c4..39336090ea 100644 --- a/deps/v8/test/mjsunit/third_party/object-keys/object-keys.js +++ b/deps/v8/test/mjsunit/third_party/object-keys/object-keys.js @@ -42,6 +42,7 @@ assertEquals(Object.keys({a:null, b:null}), ['a', 'b']); assertEquals(Object.keys({b:null, a:null}), ['b', 'a']); assertEquals(Object.keys([]), []); assertEquals(Object.keys([null]), ['0']); +assertEquals(Object.keys([undefined]), ['0']); assertEquals(Object.keys([null,null]), ['0', '1']); assertEquals(Object.keys([null,null,,,,null]), ['0', '1', '5']); assertEquals(Object.keys({__proto__:{a:null}}), []); @@ -66,3 +67,34 @@ keysBefore[0] = 'x'; var keysAfter = Object.keys(literal); assertEquals(['a', 'b', 'c'], keysAfter); assertEquals(['x', 'b', 'c'], keysBefore); + + +var o = [1, 2, 3]; +assertEquals(['0', '1', '2'], Object.keys(o)); +Object.defineProperty(o, '0', { + enumerable: false, +}); +assertEquals(['1', '2'], Object.keys(o)); + + +(function(){ + assertEquals(['0', '1', '2'], Object.keys(arguments)); + Object.defineProperty(arguments, '0', { + enumerable: false, + }); + assertEquals(['1', '2'], Object.keys(arguments)); +})(0,1,2); + + +(function(a, b){ + assertEquals(['0', '1', '2'], Object.keys(arguments)); + Object.defineProperty(arguments, '0', { + enumerable: false, + }); + assertEquals(['1', '2'], Object.keys(arguments)); +})(0,1,2); + +var b = []; +assertEquals(0, Object.keys(b).length); +b[0] = undefined; +assertEquals(1, Object.keys(b).length); diff --git a/deps/v8/test/mjsunit/this-dynamic-lookup.js b/deps/v8/test/mjsunit/this-dynamic-lookup.js index c5fa7a2c79..eedda6000b 100644 --- a/deps/v8/test/mjsunit/this-dynamic-lookup.js +++ b/deps/v8/test/mjsunit/this-dynamic-lookup.js @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrow-functions // NO HARNESS var globalEval = eval; |