diff options
Diffstat (limited to 'deps/v8/test/mjsunit')
652 files changed, 22599 insertions, 6839 deletions
diff --git a/deps/v8/test/mjsunit/arguments.js b/deps/v8/test/mjsunit/arguments.js index 26eb38912a..97ec7cca6d 100644 --- a/deps/v8/test/mjsunit/arguments.js +++ b/deps/v8/test/mjsunit/arguments.js @@ -204,3 +204,70 @@ assertEquals(117, arg_set(0xFFFFFFFF)); } assertTrue(%HasSloppyArgumentsElements(a)); })(); + +(function testDeleteArguments() { + function f() { return arguments }; + var args = f(1, 2); + assertEquals(1, args[0]); + assertEquals(2, args[1]); + assertEquals(2, args.length); + + delete args[0]; + assertEquals(undefined, args[0]); + assertEquals(2, args[1]); + assertEquals(2, args.length); + + delete args[1]; + assertEquals(undefined, args[0]); + assertEquals(undefined, args[1]); + assertEquals(2, args.length); +})(); + +(function testDeleteFastSloppyArguments() { + function f(a) { return arguments }; + var args = f(1, 2); + assertEquals(1, args[0]); + assertEquals(2, args[1]); + assertEquals(2, args.length); + + delete args[0]; + assertEquals(undefined, args[0]); + assertEquals(2, args[1]); + assertEquals(2, args.length); + + delete args[1]; + assertEquals(undefined, args[0]); + assertEquals(undefined, args[1]); + assertEquals(2, args.length); +})(); + +(function testDeleteSlowSloppyArguments() { + var key = 10000; + function f(a) { + arguments[key] = key; + return arguments + }; + var args = f(1, 2); + assertEquals(1, args[0]); + assertEquals(2, args[1]); + assertEquals(key, args[key]); + assertEquals(2, args.length); + + delete args[0]; + assertEquals(undefined, args[0]); + assertEquals(2, args[1]); + assertEquals(key, args[key]); + assertEquals(2, args.length); + + delete args[1]; + assertEquals(undefined, args[0]); + assertEquals(undefined, args[1]); + assertEquals(key, args[key]); + assertEquals(2, args.length); + + delete args[key]; + assertEquals(undefined, args[0]); + assertEquals(undefined, args[1]); + assertEquals(undefined, args[key]); + assertEquals(2, args.length); +})(); diff --git a/deps/v8/test/mjsunit/array-constructor-feedback.js b/deps/v8/test/mjsunit/array-constructor-feedback.js index 4c3a28f17a..865b8ba44f 100644 --- a/deps/v8/test/mjsunit/array-constructor-feedback.js +++ b/deps/v8/test/mjsunit/array-constructor-feedback.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --expose-gc +// Flags: --noalways-opt // Test element kind of objects. @@ -61,26 +62,6 @@ function assertKind(expected, obj, name_opt) { assertEquals(expected, getKind(obj), name_opt); } -// Test: If a call site goes megamorphic, it retains the ability to -// use allocation site feedback (if FLAG_allocation_site_pretenuring -// is on). -(function() { - function bar(t, len) { - return new t(len); - } - - a = bar(Array, 10); - a[0] = 3.5; - b = bar(Array, 1); - assertKind(elements_kind.fast_double, b); - c = bar(Object, 3); - b = bar(Array, 10); - // TODO(mvstanton): re-enable when FLAG_allocation_site_pretenuring - // is on in the build. - // assertKind(elements_kind.fast_double, b); -})(); - - // Test: ensure that crankshafted array constructor sites are deopted // if another function is used. (function() { diff --git a/deps/v8/test/mjsunit/array-feedback.js b/deps/v8/test/mjsunit/array-feedback.js index f0a859e67c..4eb922c2f7 100644 --- a/deps/v8/test/mjsunit/array-feedback.js +++ b/deps/v8/test/mjsunit/array-feedback.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --expose-gc +// Flags: --noalways-opt var elements_kind = { fast_smi_only : 'fast smi only elements', diff --git a/deps/v8/test/mjsunit/array-indexing-receiver.js b/deps/v8/test/mjsunit/array-indexing-receiver.js new file mode 100644 index 0000000000..d5f5a7692d --- /dev/null +++ b/deps/v8/test/mjsunit/array-indexing-receiver.js @@ -0,0 +1,632 @@ +// Copyright 2016 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 + +// Ensure `Array.prototype.indexOf` functions correctly for numerous elements +// kinds, and various exotic receiver types, + +var kIterCount = 1; +var kTests = { + Array: { + FAST_ELEMENTS() { + var r = /foo/; + var s = new String("bar"); + var p = new Proxy({}, {}); + var o = {}; + + var array = [r, s, p]; + assertTrue(%HasFastObjectElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(p), 2); + assertEquals(array.indexOf(o), -1); + } + }, + + FAST_HOLEY_ELEMENTS() { + var r = /foo/; + var p = new Proxy({}, {}); + var o = {}; + + var array = [r, , p]; + assertTrue(%HasFastObjectElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(p), 2); + assertEquals(array.indexOf(o), -1); + } + }, + + FAST_SMI_ELEMENTS() { + var array = [0, 88, 9999, 1, -5, 7]; + assertTrue(%HasFastSmiElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(9999), 2); + assertEquals(array.indexOf(-5), 4); + assertEquals(array.indexOf(-5.00001), -1); + assertEquals(array.indexOf(undefined), -1); + assertEquals(array.indexOf(NaN), -1); + } + }, + + FAST_HOLEY_SMI_ELEMENTS() { + var array = [49, , , 72, , , 67, -48]; + assertTrue(%HasFastSmiElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(72), 3); + assertEquals(array.indexOf(-48), 7); + assertEquals(array.indexOf(72, 4), -1); + assertEquals(array.indexOf(undefined), -1); + assertEquals(array.indexOf(undefined, -2), -1); + assertEquals(array.indexOf(NaN), -1); + } + }, + + FAST_DOUBLE_ELEMENTS() { + var array = [7.00000001, -13000.89412, 73451.4124, + 5824.48, 6.0000495, 48.3488, 44.0, 76.35, NaN, 78.4]; + assertTrue(%HasFastDoubleElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(7.00000001), 0); + assertEquals(array.indexOf(7.00000001, 2), -1); + assertEquals(array.indexOf(NaN), -1); + assertEquals(array.indexOf(NaN, -1), -1); + assertEquals(array.indexOf(-13000.89412), 1); + assertEquals(array.indexOf(-13000.89412, -2), -1); + assertEquals(array.indexOf(undefined), -1); + } + }, + + FAST_HOLEY_DOUBLE_ELEMENTS() { + var array = [7.00000001, -13000.89412, , + 5824.48, , 48.3488, , NaN, , 78.4]; + assertTrue(%HasFastDoubleElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(7.00000001), 0); + assertEquals(array.indexOf(7.00000001, 2), -1); + assertEquals(array.indexOf(NaN), -1); + assertEquals(array.indexOf(NaN, -2), -1); + assertEquals(array.indexOf(-13000.89412), 1); + assertEquals(array.indexOf(-13000.89412, -2), -1); + assertEquals(array.indexOf(undefined, -2), -1); + assertEquals(array.indexOf(undefined, -1), -1); + } + }, + + DICTIONARY_ELEMENTS() { + var array = []; + Object.defineProperty(array, 4, { get() { return NaN; } }); + Object.defineProperty(array, 7, { value: Function }); + + assertTrue(%HasDictionaryElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(array.indexOf(NaN), -1); + assertEquals(array.indexOf(NaN, -3), -1); + assertEquals(array.indexOf(Function), 7); + assertEquals(array.indexOf(undefined), -1); + assertEquals(array.indexOf(undefined, 7), -1); + } + }, + }, + + Object: { + FAST_ELEMENTS() { + var r = /foo/; + var s = new String("bar"); + var p = new Proxy({}, {}); + var o = {}; + + var object = { 0: r, 1: s, 2: p, length: 3 }; + assertTrue(%HasFastObjectElements(object)); + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, p), 2); + assertEquals(Array.prototype.indexOf.call(object, o), -1); + } + }, + + FAST_HOLEY_ELEMENTS() { + var r = /foo/; + var p = new Proxy({}, {}); + var o = {}; + + var object = { 0: r, 2: p, length: 3 }; + assertTrue(%HasFastObjectElements(object)); + assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, p), 2); + assertEquals(Array.prototype.indexOf.call(object, o), -1); + } + }, + + FAST_SMI_ELEMENTS() { + var object = { 0: 0, 1: 88, 2: 9999, 3: 1, 4: -5, 5: 7, length: 6 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastSmiElements(object)); + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, 9999), 2); + assertEquals(Array.prototype.indexOf.call(object, -5), 4); + assertEquals(Array.prototype.indexOf.call(object, -5.00001), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN), -1); + } + }, + + FAST_HOLEY_SMI_ELEMENTS() { + var object = { 0: 49, 3: 72, 6: 67, 7: -48, length: 8 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastSmiElements(object)); + // assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, 72), 3); + assertEquals(Array.prototype.indexOf.call(object, -48), 7); + assertEquals(Array.prototype.indexOf.call(object, 72, 4), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined, -2), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN), -1); + } + }, + + FAST_DOUBLE_ELEMENTS() { + var object = { 0: 7.00000001, 1: -13000.89412, 2: 73451.4124, + 3: 5824.48, 4: 6.0000495, 5: 48.3488, 6: 44.0, 7: 76.35, + 8: NaN, 9: 78.4, length: 10 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastDoubleElements(object)); + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, 7.00000001), 0); + assertEquals(Array.prototype.indexOf.call(object, 7.00000001, 2), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN, -1), -1); + assertEquals(Array.prototype.indexOf.call(object, -13000.89412), 1); + assertEquals(Array.prototype.indexOf.call(object, -13000.89412, -2), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined), -1); + } + }, + + FAST_HOLEY_DOUBLE_ELEMENTS() { + var object = { 0: 7.00000001, 1: -13000.89412, 3: 5824.48, 5: 48.3488, + 7: NaN, 9: 78.4, length: 10 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastDoubleElements(object)); + // assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, 7.00000001), 0); + assertEquals(Array.prototype.indexOf.call(object, 7.00000001, 2), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN, -2), -1); + assertEquals(Array.prototype.indexOf.call(object, -13000.89412), 1); + assertEquals(Array.prototype.indexOf.call(object, -13000.89412, -2), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined, -2), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined, -1), -1); + } + }, + + DICTIONARY_ELEMENTS() { + var object = { length: 8 }; + Object.defineProperty(object, 4, { get() { return NaN; } }); + Object.defineProperty(object, 7, { value: Function }); + + assertTrue(%HasDictionaryElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(object, NaN), -1); + assertEquals(Array.prototype.indexOf.call(object, NaN, -3), -1); + assertEquals(Array.prototype.indexOf.call(object, Function), 7); + assertEquals(Array.prototype.indexOf.call(object, undefined), -1); + assertEquals(Array.prototype.indexOf.call(object, undefined, 7), -1); + } + + (function prototypeModifiedDuringAccessor() { + function O() { + return { + __proto__: {}, + get 0() { + this.__proto__.__proto__ = { + get 1() { + this[2] = "c"; + return "b"; + } + }; + return "a"; + }, + length: 3 + }; + } + + // Switch to slow path when first accessor modifies the prototype + assertEquals(Array.prototype.indexOf.call(O(), "a"), 0); + assertEquals(Array.prototype.indexOf.call(O(), "b"), 1); + assertEquals(Array.prototype.indexOf.call(O(), "c"), 2); + + // Avoid switching to slow path due to avoiding the accessor + assertEquals(Array.prototype.indexOf.call(O(), "c", 2), -1); + assertEquals(Array.prototype.indexOf.call(O(), "b", 1), -1); + assertEquals(Array.prototype.indexOf.call(O(), undefined, 1), 1); + }); + }, + }, + + String: { + FAST_STRING_ELEMENTS() { + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call("froyo", "y"), 3); + assertEquals(Array.prototype.indexOf.call("froyo", "y", -1), -1); + assertEquals(Array.prototype.indexOf.call("froyo", "y", -2), 3); + assertEquals(Array.prototype.indexOf.call("froyo", NaN), -1); + assertEquals(Array.prototype.indexOf.call("froyo", undefined), -1); + } + }, + + SLOW_STRING_ELEMENTS() { + var string = new String("froyo"); + + // Never accessible from A.p.indexOf as 'length' is not configurable + Object.defineProperty(string, 34, { value: NaN }); + Object.defineProperty(string, 12, { get() { return "nope" } }); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call("froyo", "y"), 3); + assertEquals(Array.prototype.indexOf.call("froyo", "y", -1), -1); + assertEquals(Array.prototype.indexOf.call("froyo", "y", -2), 3); + assertEquals(Array.prototype.indexOf.call(string, NaN), -1); + assertEquals(Array.prototype.indexOf.call(string, undefined), -1); + assertEquals(Array.prototype.indexOf.call(string, "nope"), -1); + } + }, + }, + + Arguments: { + FAST_SLOPPY_ARGUMENTS_ELEMENTS() { + var args = (function(a, b) { return arguments; })("foo", NaN, "bar"); + assertTrue(%HasSloppyArgumentsElements(args)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(args, undefined), -1); + assertEquals(Array.prototype.indexOf.call(args, NaN), -1); + assertEquals(Array.prototype.indexOf.call(args, NaN, -1), -1); + assertEquals(Array.prototype.indexOf.call(args, "bar", -1), 2); + } + }, + + SLOW_SLOPPY_ARGUMENTS_ELEMENTS() { + var args = (function(a, a) { return arguments; })("foo", NaN, "bar"); + Object.defineProperty(args, 3, { get() { return "silver"; } }); + Object.defineProperty(args, "length", { value: 4 }); + assertTrue(%HasSloppyArgumentsElements(args)); + + for (var i = 0; i < kIterCount; ++i) { + assertEquals(Array.prototype.indexOf.call(args, undefined), -1); + assertEquals(Array.prototype.indexOf.call(args, NaN), -1); + assertEquals(Array.prototype.indexOf.call(args, NaN, -2), -1); + assertEquals(Array.prototype.indexOf.call(args, "bar", -2), 2); + assertEquals(Array.prototype.indexOf.call(args, "silver", -1), 3); + } + } + }, + + TypedArray: { + Int8Array() { + var array = new Int8Array([-129, 128, + NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, + +Infinity /* 0 */, -Infinity /* 0 */, + 255 /* -1 */, 127 /* 127 */, -255 /* 1 */]); + assertEquals(Array.prototype.indexOf.call(array, -129), -1); + assertEquals(Array.prototype.indexOf.call(array, 128), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, -1, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, -1, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 127, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 127, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 1, 9), 9); + }, + + Detached_Int8Array() { + var array = new Int8Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Uint8Array() { + var array = new Uint8Array([-1, 256, + NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, + +Infinity /* 0 */, -Infinity /* 0 */, + 255 /* 255 */, 257 /* 1 */, -128 /* 128 */, + -2 /* 254 */]); + assertEquals(Array.prototype.indexOf.call(array, -1), -1); + assertEquals(Array.prototype.indexOf.call(array, 256), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, 255, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, 255, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 1, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 1, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 128, 9), 9); + assertEquals(Array.prototype.indexOf.call(array, 128, 10), -1); + + assertEquals(Array.prototype.indexOf.call(array, 254, 10), 10); + }, + + Detached_Uint8Array() { + var array = new Uint8Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Uint8ClampedArray() { + var array = new Uint8ClampedArray([-1 /* 0 */, NaN /* 0 */, 256 /* 255 */, + 127.6 /* 128 */, 127.4 /* 127 */, + 121.5 /* 122 */, 124.5 /* 124 */]); + assertEquals(Array.prototype.indexOf.call(array, -1), -1); + assertEquals(Array.prototype.indexOf.call(array, 256), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0), 0); + assertEquals(Array.prototype.indexOf.call(array, 0, 1), 1); + assertEquals(Array.prototype.indexOf.call(array, 255, 2), 2); + + assertEquals(Array.prototype.indexOf.call(array, 128, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 128, 4), -1); + + assertEquals(Array.prototype.indexOf.call(array, 127, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 127, 5), -1); + + assertEquals(Array.prototype.indexOf.call(array, 122, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 122, 6), -1); + + assertEquals(Array.prototype.indexOf.call(array, 124, 6), 6); + }, + + Detached_Uint8ClampedArray() { + var array = new Uint8ClampedArray(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Int16Array() { + var array = new Int16Array([-32769, 32768, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFF /* -1 */, 30000 /* 30000 */, + 300000 /* -27680 */]); + assertEquals(Array.prototype.indexOf.call(array, -32769), -1); + assertEquals(Array.prototype.indexOf.call(array, 32768), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, -1, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, -1, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 30000, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 30000, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, -27680, 9), 9); + }, + + Detached_Int16Array() { + var array = new Int16Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Uint16Array() { + var array = new Uint16Array([-1, 65536, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFF /* 65535 */, 300000 /* 37856 */, + 3000000 /* 50880 */]); + assertEquals(Array.prototype.indexOf.call(array, -1), -1); + assertEquals(Array.prototype.indexOf.call(array, 65536), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, 65535, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, 65535, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 37856, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 37856, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 50880, 9), 9); + }, + + Detached_Uint16Array() { + var array = new Uint16Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Int32Array() { + var array = new Int32Array([-2147483649, 2147483648, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* -1 */, 4294968064 /* 768 */, + 4294959447 /* -7849 */]); + assertEquals(Array.prototype.indexOf.call(array, -2147483649), -1); + assertEquals(Array.prototype.indexOf.call(array, 2147483648), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0.0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, -1, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, -1, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 768, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 768, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, -7849, 9), 9); + }, + + Detached_Int32Array() { + var array = new Int32Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Uint32Array() { + var array = new Uint32Array([-1, 4294967296, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 4294967295 */, + 4294968064 /* 768 */, + 4295079447 /* 112151 */]); + assertEquals(Array.prototype.indexOf.call(array, -1), -1); + assertEquals(Array.prototype.indexOf.call(array, 4294967296), -1); + + assertEquals(Array.prototype.indexOf.call(array, 0.0, 2), 2); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, 0, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, 4294967295, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, 4294967295, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, 768, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, 768, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 112151, 9), 9); + }, + + Detached_Uint32Array() { + var array = new Uint32Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Float32Array() { + var array = new Float32Array([-1, 4294967296, + NaN, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 34359738368.0 */, + -4294968064 /* -4294968320.0 */, + 4295079447 /* 4295079424.0 */]); + assertEquals(Array.prototype.indexOf.call(array, -1.0), 0); + assertEquals(Array.prototype.indexOf.call(array, 4294967296), 1); + + assertEquals(Array.prototype.indexOf.call(array, NaN, 2), -1); + assertEquals(Array.prototype.indexOf.call(array, Infinity, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, -Infinity, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, 34359738368.0, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, 34359738368.0, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, -4294968320.0, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, -4294968320.0, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 4295079424.0, 9), 9); + }, + + Detached_Float32Array() { + var array = new Float32Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + + Float64Array() { + var array = new Float64Array([-1, 4294967296, + NaN, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 34359738367.0 */, + -4294968064 /* -4294968064.0 */, + 4295079447 /* 4295079447.0 */]); + assertEquals(Array.prototype.indexOf.call(array, -1.0), 0); + assertEquals(Array.prototype.indexOf.call(array, 4294967296), 1); + + assertEquals(Array.prototype.indexOf.call(array, NaN, 2), -1); + assertEquals(Array.prototype.indexOf.call(array, Infinity, 3), 3); + assertEquals(Array.prototype.indexOf.call(array, -Infinity, 4), 4); + assertEquals(Array.prototype.indexOf.call(array, 0, 5), 5); + assertEquals(Array.prototype.indexOf.call(array, 0, 6), 6); + assertEquals(Array.prototype.indexOf.call(array, 0.0, 7), -1); + + assertEquals(Array.prototype.indexOf.call(array, 34359738367.0, 7), 7); + assertEquals(Array.prototype.indexOf.call(array, 34359738367.0, 8), -1); + + assertEquals(Array.prototype.indexOf.call(array, -4294968064.0, 8), 8); + assertEquals(Array.prototype.indexOf.call(array, -4294968064.0, 9), -1); + + assertEquals(Array.prototype.indexOf.call(array, 4295079447.0, 9), 9); + }, + + Detached_Float64Array() { + var array = new Float32Array(10); + %ArrayBufferNeuter(array.buffer); + assertEquals(Array.prototype.indexOf.call(array, 0), -1); + assertEquals(Array.prototype.indexOf.call(array, 0, 10), -1); + }, + } +}; + +function runSuites(suites) { + Object.keys(suites).forEach(suite => runSuite(suites[suite])); + + function runSuite(suite) { + Object.keys(suite).forEach(test => suite[test]()); + } +} + +runSuites(kTests); diff --git a/deps/v8/test/mjsunit/array-literal-transitions.js b/deps/v8/test/mjsunit/array-literal-transitions.js index e1624553f4..cd9d96bcf4 100644 --- a/deps/v8/test/mjsunit/array-literal-transitions.js +++ b/deps/v8/test/mjsunit/array-literal-transitions.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --expose-gc +// Flags: --ignition-osr --turbo-from-bytecode // IC and Crankshaft support for smi-only elements in dynamic array literals. function get(foo) { return foo; } // Used to generate dynamic values. diff --git a/deps/v8/test/mjsunit/array-push.js b/deps/v8/test/mjsunit/array-push.js index c87fd128e4..ece3319bc1 100644 --- a/deps/v8/test/mjsunit/array-push.js +++ b/deps/v8/test/mjsunit/array-push.js @@ -146,3 +146,16 @@ f(a, {}); assertEquals(10, a.f()); })(); + + +(function testDoubleArrayPush() { + var a = []; + var max = 1000; + for (var i = 0; i < max; i++) { + a.push(i + 0.1); + } + assertEquals(max, a.length); + for (var i = 0; i < max; i++) { + assertEquals(i+0.1, a[i]); + } +})(); diff --git a/deps/v8/test/mjsunit/array-push7.js b/deps/v8/test/mjsunit/array-push7.js deleted file mode 100644 index 68c3a2a76e..0000000000 --- a/deps/v8/test/mjsunit/array-push7.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2014 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-object-observe -// Flags: --allow-natives-syntax - -var v = 0; - -function push_wrapper(array, value) { - array.push(value); -} -function pop_wrapper(array) { - return array.pop(); -} - -// Test that Object.observe() notification events are properly sent from -// Array.push() and Array.pop() both from optimized and un-optimized code. -var array = []; - -function somethingChanged(changes) { - v++; -} - -Object.observe(array, somethingChanged); -push_wrapper(array, 1); -%RunMicrotasks(); -assertEquals(1, array.length); -assertEquals(1, v); -push_wrapper(array, 1); -%RunMicrotasks(); -assertEquals(2, array.length); -assertEquals(2, v); -%OptimizeFunctionOnNextCall(push_wrapper); -push_wrapper(array, 1); -%RunMicrotasks(); -assertEquals(3, array.length); -assertEquals(3, v); -push_wrapper(array, 1); -%RunMicrotasks(); -assertEquals(4, array.length); -assertEquals(4, v); - -pop_wrapper(array); -%RunMicrotasks(); -assertEquals(3, array.length); -assertEquals(5, v); -pop_wrapper(array); -%RunMicrotasks(); -assertEquals(2, array.length); -assertEquals(6, v); -%OptimizeFunctionOnNextCall(pop_wrapper); -pop_wrapper(array); -%RunMicrotasks(); -assertEquals(1, array.length); -assertEquals(7, v); -pop_wrapper(array); -%RunMicrotasks(); -assertEquals(0, array.length); -assertEquals(8, v); diff --git a/deps/v8/test/mjsunit/array-slice.js b/deps/v8/test/mjsunit/array-slice.js index ae0e3bc1ef..b017dd506a 100644 --- a/deps/v8/test/mjsunit/array-slice.js +++ b/deps/v8/test/mjsunit/array-slice.js @@ -228,6 +228,7 @@ func([]); func(['a'], 'a'); func(['a', 1], 'a', 1); + func(['a', 1, 2, 3, 4, 5], 'a', 1, 2, 3, 4, 5); func(['a', 1, undefined], 'a', 1, undefined); func(['a', 1, undefined, void(0)], 'a', 1, undefined, void(0)); })(); diff --git a/deps/v8/test/mjsunit/array-sort.js b/deps/v8/test/mjsunit/array-sort.js index ae9f6efa66..fdd2333d7c 100644 --- a/deps/v8/test/mjsunit/array-sort.js +++ b/deps/v8/test/mjsunit/array-sort.js @@ -479,3 +479,68 @@ function TestSortOnProxy() { } } TestSortOnProxy(); + + +// Test special prototypes +(function testSortSpecialPrototypes() { + function test(proto, length, expected) { + var result = { + length: length, + __proto__: proto, + }; + Array.prototype.sort.call(result); + assertEquals(expected.length, result.length, "result.length"); + for (var i = 0; i<expected.length; i++) { + assertEquals(expected[i], result[i], "result["+i+"]"); + } + } + + (function fast() { + // Fast elements, non-empty + test(arguments, 0, []); + test(arguments, 1, [2]); + test(arguments, 2, [1, 2]); + test(arguments, 4, [1, 2, 3, 4]); + delete arguments[0] + // sort copies down the properties to the receiver, hence result[1] + // is read on the arguments through the hole on the receiver. + test(arguments, 2, [1, 1]); + arguments[0] = undefined; + test(arguments, 2, [1, undefined]); + })(2, 1, 4, 3); + + (function fastSloppy(a) { + // Fast sloppy + test(arguments, 0, []); + test(arguments, 1, [2]); + test(arguments, 2, [1, 2]); + delete arguments[0] + test(arguments, 2, [1, 1]); + arguments[0] = undefined; + test(arguments, 2, [1, undefined]); + })(2, 1); + + (function fastEmpty() { + test(arguments, 0, []); + test(arguments, 1, [undefined]); + test(arguments, 2, [undefined, undefined]); + })(); + + (function stringWrapper() { + // cannot redefine string wrapper properties + assertThrows(() => test(new String('cba'), 3, []), TypeError); + })(); + + (function typedArrys() { + test(new Int32Array(0), 0, []); + test(new Int32Array(1), 1, [0]); + var array = new Int32Array(3); + array[0] = 2; + array[1] = 1; + array[2] = 3; + test(array, 1, [2]); + test(array, 2, [1, 2]); + test(array, 3, [1, 2, 3]); + })() + +})(); diff --git a/deps/v8/test/mjsunit/array-splice.js b/deps/v8/test/mjsunit/array-splice.js index 744e95454b..75ff2d174b 100644 --- a/deps/v8/test/mjsunit/array-splice.js +++ b/deps/v8/test/mjsunit/array-splice.js @@ -300,6 +300,55 @@ } })(); +// Check the behaviour when approaching maximal values for length. +(function() { + for (var i = 0; i < 7; i++) { + try { + new Array(Math.pow(2, 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); + throw 'Should have thrown RangeError'; + } catch (e) { + assertTrue(e instanceof RangeError); + } + + // Check smi boundary + var bigNum = (1 << 30) - 3; + var array = new Array(bigNum); + array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); + assertEquals(bigNum + 7, array.length); + } +})(); + +(function() { + for (var i = 0; i < 7; i++) { + var a = [7, 8, 9]; + a.splice(0, 0, 1, 2, 3, 4, 5, 6); + assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); + assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); + assertEquals(undefined, a[10]); + } +})(); + +(function testSpliceDeleteDouble() { + var a = [1.1, 1.2, 1.3, 1.4]; + a.splice(2, 1) + assertEquals([1.1, 1.2, 1.4], a); +})(); + +// Past this point the ArrayProtector is invalidated since we modify the +// Array.prototype. + +// Check the case of JS builtin .splice() +(function() { + for (var i = 0; i < 7; i++) { + var array = [1, 2, 3, 4]; + Array.prototype[3] = 'foo'; // To force JS builtin. + + var spliced = array.splice(); + + assertEquals([], spliced); + assertEquals([1, 2, 3, 4], array); + } +})(); // Now check the case with array of holes and some elements on prototype. (function() { @@ -350,7 +399,6 @@ } })(); - // Now check the case with array of holes and some elements on prototype. (function() { var len = 9; @@ -397,46 +445,3 @@ "array.hasOwnProperty(Math.pow(2, 32) - 2)"); } })(); - - -// Check the case of JS builtin .splice() -(function() { - for (var i = 0; i < 7; i++) { - var array = [1, 2, 3, 4]; - Array.prototype[3] = 'foo'; // To force JS builtin. - - var spliced = array.splice(); - - assertEquals([], spliced); - assertEquals([1, 2, 3, 4], array); - } -})(); - - -// Check the behaviour when approaching maximal values for length. -(function() { - for (var i = 0; i < 7; i++) { - try { - new Array(Math.pow(2, 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); - throw 'Should have thrown RangeError'; - } catch (e) { - assertTrue(e instanceof RangeError); - } - - // Check smi boundary - var bigNum = (1 << 30) - 3; - var array = new Array(bigNum); - array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); - assertEquals(bigNum + 7, array.length); - } -})(); - -(function() { - for (var i = 0; i < 7; i++) { - var a = [7, 8, 9]; - a.splice(0, 0, 1, 2, 3, 4, 5, 6); - assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); - assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); - assertEquals(undefined, a[10]); - } -})(); diff --git a/deps/v8/test/mjsunit/array-tostring.js b/deps/v8/test/mjsunit/array-tostring.js index 5be3d5045c..382bf8d7a0 100644 --- a/deps/v8/test/mjsunit/array-tostring.js +++ b/deps/v8/test/mjsunit/array-tostring.js @@ -125,7 +125,9 @@ var la1 = [1, [2, 3], 4]; assertEquals("1,2,3,4", la1.toLocaleString()); // Used on a string (which looks like an array of characters). -String.prototype.toLocaleString = Array.prototype.toLocaleString; +String.prototype.toLocaleString = function() { + return (this.length == 1) ? this : Array.prototype.toLocaleString.call(this); +} assertEquals("1,2,3,4", "1234".toLocaleString()); // If toLocaleString of element is not callable, throw a TypeError. @@ -157,3 +159,23 @@ for (var i = 0; i < 3; i++) { } Number.prototype.arrayToLocaleString = Array.prototype.toLocaleString; assertEquals("42,42,42", (42).arrayToLocaleString()); + + +(function TestToLocaleStringCalls() { + let log = []; + let pushArgs = (label) => (...args) => log.push(label, args); + + let NumberToLocaleString = Number.prototype.toLocaleString; + let StringToLocaleString = String.prototype.toLocaleString; + let ObjectToLocaleString = Object.prototype.toLocaleString; + Number.prototype.toLocaleString = pushArgs("Number"); + String.prototype.toLocaleString = pushArgs("String"); + Object.prototype.toLocaleString = pushArgs("Object"); + + [42, "foo", {}].toLocaleString(); + assertEquals(["Number", [], "String", [], "Object", []], log); + + Number.prototype.toLocaleString = NumberToLocaleString; + String.prototype.toLocaleString = StringToLocaleString; + Object.prototype.toLocaleString = ObjectToLocaleString; +})(); diff --git a/deps/v8/test/mjsunit/asm-directive.js b/deps/v8/test/mjsunit/asm-directive.js new file mode 100644 index 0000000000..a308f43f6f --- /dev/null +++ b/deps/v8/test/mjsunit/asm-directive.js @@ -0,0 +1,11 @@ +// Copyright 2016 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.eval(Realm.current(), '"use asm"'); +function f() { "use asm" } +() => "use asm" +if (true) "use asm" +with ({}) "use asm" +try { } catch (e) { "use asm" } +Realm.eval(Realm.current(), 'eval(\'"use asm"\')'); diff --git a/deps/v8/test/mjsunit/asm/asm-validation.js b/deps/v8/test/mjsunit/asm/asm-validation.js new file mode 100644 index 0000000000..eae282ca57 --- /dev/null +++ b/deps/v8/test/mjsunit/asm/asm-validation.js @@ -0,0 +1,215 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function assertValidAsm(func) { + assertTrue(%IsAsmWasmCode(func)); +} + +(function TestModuleArgs() { + function Module1(stdlib) { + "use asm"; + function foo() { } + return { foo: foo }; + } + function Module2(stdlib, ffi) { + "use asm"; + function foo() { } + return { foo: foo }; + } + function Module3(stdlib, ffi, heap) { + "use asm"; + function foo() { } + return { foo: foo }; + } + var modules = [Module1, Module2, Module3]; + var heap = new ArrayBuffer(1024 * 1024); + for (var i = 0; i < modules.length; ++i) { + print('Module' + (i + 1)); + var module = modules[i]; + var m = module(); + assertValidAsm(module); + var m = module({}); + assertValidAsm(module); + var m = module({}, {}); + assertValidAsm(module); + var m = module({}, {}, heap); + assertValidAsm(module); + var m = module({}, {}, heap, {}); + assertValidAsm(module); + } +})(); + +(function TestBadModule() { + function Module(stdlib, ffi, heap) { + "use asm"; + function foo() { var y = 3; var x = 1 + y; return 123; } + return { foo: foo }; + } + var m = Module({}); + assertTrue(%IsNotAsmWasmCode(Module)); + assertEquals(123, m.foo()); +})(); + +(function TestBadArgTypes() { + function Module(a, b, c) { + "use asm"; + var NaN = a.NaN; + return {}; + } + var m = Module(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module)); + assertEquals({}, m); +})(); + +(function TestBadArgTypesMismatch() { + function Module(a, b, c) { + "use asm"; + var NaN = a.NaN; + return {}; + } + var m = Module(1, 2); + assertTrue(%IsNotAsmWasmCode(Module)); + assertEquals({}, m); +})(); + +(function TestModuleNoStdlib() { + function Module() { + "use asm"; + function foo() { return 123; } + return { foo: foo }; + } + var m = Module({}); + assertValidAsm(Module); + assertEquals(123, m.foo()); +})(); + +(function TestModuleWith5() { + function Module(a, b, c, d, e) { + "use asm"; + function foo() { return 123; } + return { foo: foo }; + } + var heap = new ArrayBuffer(1024 * 1024); + var m = Module({}, {}, heap); + assertTrue(%IsNotAsmWasmCode(Module)); + assertEquals(123, m.foo()); +})(); + +(function TestModuleNoStdlibCall() { + function Module(stdlib, ffi, heap) { + "use asm"; + function foo() { return 123; } + return { foo: foo }; + } + var m = Module(); + assertValidAsm(Module); + assertEquals(123, m.foo()); +})(); + +(function TestModuleNew() { + function Module(stdlib, ffi, heap) { + "use asm"; + function foo() { return 123; } + return { foo: foo }; + } + var m = new Module({}, {}); + assertValidAsm(Module); + assertEquals(123, m.foo()); +})(); + +(function TestMultipleFailures() { + function Module(stdlib) { + "use asm"; + var NaN = stdlib.NaN; + function foo() { return 123; } + return { foo: foo }; + } + var m1 = Module(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module)); + var m2 = Module(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module)); + assertEquals(123, m1.foo()); + assertEquals(123, m2.foo()); +})(); + +(function TestFailureThenSuccess() { + function MkModule() { + function Module(stdlib, ffi, heap) { + "use asm"; + var NaN = stdlib.NaN; + function foo() { return 123; } + return { foo: foo }; + } + return Module; + } + var Module1 = MkModule(); + var Module2 = MkModule(); + var heap = new ArrayBuffer(1024 * 1024); + var m1 = Module1(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module1)); + var m2 = Module2({}, {}, heap); + assertTrue(%IsNotAsmWasmCode(Module2)); + assertEquals(123, m1.foo()); + assertEquals(123, m2.foo()); +})(); + +(function TestSuccessThenFailure() { + function MkModule() { + function Module(stdlib, ffi, heap) { + "use asm"; + var NaN = stdlib.NaN; + function foo() { return 123; } + return { foo: foo }; + } + return Module; + } + var Module1 = MkModule(); + var Module2 = MkModule(); + var heap = new ArrayBuffer(1024 * 1024); + var m1 = Module1({NaN: NaN}, {}, heap); + assertValidAsm(Module1); + var m2 = Module2(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module2)); + assertEquals(123, m1.foo()); + assertEquals(123, m2.foo()); +})(); + +(function TestSuccessThenFailureThenRetry() { + function MkModule() { + function Module(stdlib, ffi, heap) { + "use asm"; + var NaN = stdlib.NaN; + function foo() { return 123; } + return { foo: foo }; + } + return Module; + } + var Module1 = MkModule(); + var Module2 = MkModule(); + var heap = new ArrayBuffer(1024 * 1024); + var m1a = Module1({NaN: NaN}, {}, heap); + assertValidAsm(Module1); + var m2 = Module2(1, 2, 3); + assertTrue(%IsNotAsmWasmCode(Module2)); + var m1b = Module1({NaN: NaN}, {}, heap); + assertTrue(%IsNotAsmWasmCode(Module1)); + assertEquals(123, m1a.foo()); + assertEquals(123, m1b.foo()); + assertEquals(123, m2.foo()); +})(); + +(function TestBoundFunction() { + function Module(stdlib, ffi, heap) { + "use asm"; + function foo() { return 123; } + return { foo: foo }; + } + var heap = new ArrayBuffer(1024 * 1024); + var ModuleBound = Module.bind(this, {}, {}, heap); + var m = ModuleBound(); + assertValidAsm(Module); + assertEquals(123, m.foo()); +})(); diff --git a/deps/v8/test/mjsunit/asm/construct-double.js b/deps/v8/test/mjsunit/asm/construct-double.js deleted file mode 100644 index 8bb5000082..0000000000 --- a/deps/v8/test/mjsunit/asm/construct-double.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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 - -var stdlib = this; -var foreign = {}; -var heap = new ArrayBuffer(64 * 1024); - - -var m = (function(stdlib, foreign, heap) { - "use asm"; - function cd1(i, j) { - i = i|0; - j = j|0; - return +%_ConstructDouble(i, j); - } - function cd2(i) { - i = i|0; - return +%_ConstructDouble(0, i); - } - return { cd1: cd1, cd2: cd2 }; -})(stdlib, foreign, heap); - -assertEquals(0.0, m.cd1(0, 0)); -assertEquals(%ConstructDouble(0, 1), m.cd2(1)); -for (var i = -2147483648; i < 2147483648; i += 3999773) { - assertEquals(%ConstructDouble(0, i), m.cd2(i)); - for (var j = -2147483648; j < 2147483648; j += 3999773) { - assertEquals(%ConstructDouble(i, j), m.cd1(i, j)); - } -} diff --git a/deps/v8/test/mjsunit/asm/double-hi.js b/deps/v8/test/mjsunit/asm/double-hi.js deleted file mode 100644 index 5a5f942f7b..0000000000 --- a/deps/v8/test/mjsunit/asm/double-hi.js +++ /dev/null @@ -1,40 +0,0 @@ -// 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 - -var stdlib = this; -var foreign = {}; -var heap = new ArrayBuffer(64 * 1024); - - -var m = (function(stdlib, foreign, heap) { - "use asm"; - function hi1(i) { - i = +i; - return %_DoubleHi(i)|0; - } - function hi2(i, j) { - i = +i; - j = +j; - return %_DoubleHi(i)+%_DoubleHi(j)|0; - } - return { hi1: hi1, hi2: hi2 }; -})(stdlib, foreign, heap); - -assertEquals(0, m.hi1(0.0)); -assertEquals(-2147483648, m.hi1(-0.0)); -assertEquals(2146435072, m.hi1(Infinity)); -assertEquals(-1048576, m.hi1(-Infinity)); -assertEquals(0, m.hi2(0.0, 0.0)); -assertEquals(-2147483648, m.hi2(0.0, -0.0)); -assertEquals(-2147483648, m.hi2(-0.0, 0.0)); -assertEquals(0, m.hi2(-0.0, -0.0)); -for (var i = -2147483648; i < 2147483648; i += 3999773) { - assertEquals(%_DoubleHi(i), m.hi1(i)); - assertEquals(i, m.hi1(%ConstructDouble(i, 0))); - assertEquals(i, m.hi1(%ConstructDouble(i, i))); - assertEquals(i+i|0, m.hi2(%ConstructDouble(i, 0), %ConstructDouble(i, 0))); - assertEquals(i+i|0, m.hi2(%ConstructDouble(i, i), %ConstructDouble(i, i))); -} diff --git a/deps/v8/test/mjsunit/asm/double-lo.js b/deps/v8/test/mjsunit/asm/double-lo.js deleted file mode 100644 index 39d5b5268f..0000000000 --- a/deps/v8/test/mjsunit/asm/double-lo.js +++ /dev/null @@ -1,40 +0,0 @@ -// 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 - -var stdlib = this; -var foreign = {}; -var heap = new ArrayBuffer(64 * 1024); - - -var m = (function(stdlib, foreign, heap) { - "use asm"; - function lo1(i) { - i = +i; - return %_DoubleLo(i)|0; - } - function lo2(i, j) { - i = +i; - j = +j; - return %_DoubleLo(i)+%_DoubleLo(j)|0; - } - return { lo1: lo1, lo2: lo2 }; -})(stdlib, foreign, heap); - -assertEquals(0, m.lo1(0.0)); -assertEquals(0, m.lo1(-0.0)); -assertEquals(0, m.lo1(Infinity)); -assertEquals(0, m.lo1(-Infinity)); -assertEquals(0, m.lo2(0.0, 0.0)); -assertEquals(0, m.lo2(0.0, -0.0)); -assertEquals(0, m.lo2(-0.0, 0.0)); -assertEquals(0, m.lo2(-0.0, -0.0)); -for (var i = -2147483648; i < 2147483648; i += 3999773) { - assertEquals(%_DoubleLo(i), m.lo1(i)); - assertEquals(i, m.lo1(%ConstructDouble(0, i))); - assertEquals(i, m.lo1(%ConstructDouble(i, i))); - assertEquals(i+i|0, m.lo2(%ConstructDouble(0, i), %ConstructDouble(0, i))); - assertEquals(i+i|0, m.lo2(%ConstructDouble(i, i), %ConstructDouble(i, i))); -} diff --git a/deps/v8/test/mjsunit/asm/load-elimination.js b/deps/v8/test/mjsunit/asm/load-elimination.js new file mode 100644 index 0000000000..cdc996222e --- /dev/null +++ b/deps/v8/test/mjsunit/asm/load-elimination.js @@ -0,0 +1,26 @@ +// Copyright 2016 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 + +var stdlib = this; +var foreign = {}; +var heap = new ArrayBuffer(64 * 1024 * 1024); + +var foo = (function(stdlib, foreign, heap) { + "use asm"; + var M16 = new Int16Array(heap); + var M32 = new Int32Array(heap); + function foo() { + M32[0] = 0x12341234; + var i = M32[0]; + return M16[0]; + } + return foo; +})(stdlib, foreign, heap); + +assertEquals(0x1234, foo()); +assertEquals(0x1234, foo()); +%OptimizeFunctionOnNextCall(foo); +assertEquals(0x1234, foo()); diff --git a/deps/v8/test/mjsunit/call-counts.js b/deps/v8/test/mjsunit/call-counts.js deleted file mode 100644 index 1ad62ba5e7..0000000000 --- a/deps/v8/test/mjsunit/call-counts.js +++ /dev/null @@ -1,46 +0,0 @@ -// 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 --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(); - -(function() { - const kFooCallExtraIndex = 5; - const kArrayCallExtraIndex = 7; - - function GetCallCount(func, slot) { - var vector = %GetTypeFeedbackVector(func); - // Call counts are recorded doubled. - var value = %FixedArrayGet(vector, slot); - return Math.floor(value / 2); - } - - function foo(a) { return a[3] * 16; } - - function bar(a) { - var result = 0; - for (var i = 0; i < 10; i++) { - result = foo(a); - if (i % 2 === 0) { - var r = Array(); - r[0] = 1; - result += r[0]; - } - } - return result; - } - - var a = [1, 2, 3]; - bar(a); - assertEquals(10, GetCallCount(bar, kFooCallExtraIndex)); - assertEquals(5, GetCallCount(bar, kArrayCallExtraIndex)); - - %OptimizeFunctionOnNextCall(bar); - bar(a); -})(); diff --git a/deps/v8/test/mjsunit/callsite.js b/deps/v8/test/mjsunit/callsite.js deleted file mode 100644 index a4d9455b32..0000000000 --- a/deps/v8/test/mjsunit/callsite.js +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -Error.prepareStackTrace = (e,s) => s; -var constructor = Error().stack[0].constructor; - -// Second argument needs to be a function. -assertThrows(()=>constructor({}, {}, 1, false), TypeError); - -var receiver = {}; -function f() {} - -var site = constructor.call(null, receiver, f, {valueOf() { return 0 }}, false); -assertEquals(receiver, site.getThis()); -assertEquals(1, site.getLineNumber()); -assertEquals(1, site.getColumnNumber()); diff --git a/deps/v8/test/mjsunit/compiler/accessor-exceptions1.js b/deps/v8/test/mjsunit/compiler/accessor-exceptions1.js new file mode 100644 index 0000000000..716d229aba --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/accessor-exceptions1.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 + +var o = {} +Object.defineProperty(o, "x", { + get: function() { throw 7; } +}); + +function foo(o) { + var x = 1; + try { o.x; } catch (e) { x = e; } + return x; +} + +assertEquals(7, foo(o)); +assertEquals(7, foo(o)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(7, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/accessor-exceptions2.js b/deps/v8/test/mjsunit/compiler/accessor-exceptions2.js new file mode 100644 index 0000000000..ed6e3e21c0 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/accessor-exceptions2.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 + +var o = {} +Object.defineProperty(o, "x", { + set: function(v) { throw 7; } +}); + +function foo(o) { + var x = 1; + try { o.x = 2; } catch (e) { x = e; } + return x; +} + +assertEquals(7, foo(o)); +assertEquals(7, foo(o)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(7, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors1.js b/deps/v8/test/mjsunit/compiler/deopt-accessors1.js new file mode 100644 index 0000000000..3589258656 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors1.js @@ -0,0 +1,28 @@ +// Copyright 2016 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 + +var o = {v:1}; +var deopt = false; + +Object.defineProperty(o, "x", { + get: function() { return this.v; }, + set: function(v) { + this.v = v; + if (deopt) { + %DeoptimizeFunction(foo); + } + } +}); + +function foo(o) { + return o.x++; +} + +assertEquals(1, foo(o)); +assertEquals(2, foo(o)); +%OptimizeFunctionOnNextCall(foo); +deopt = true; +assertEquals(3, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors2.js b/deps/v8/test/mjsunit/compiler/deopt-accessors2.js new file mode 100644 index 0000000000..74d41397bf --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors2.js @@ -0,0 +1,28 @@ +// Copyright 2016 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 + +var o = {v:1}; +var deopt = false; + +Object.defineProperty(o, "x", { + get: function() { return this.v; }, + set: function(v) { + this.v = v; + if (deopt) { + %DeoptimizeFunction(foo); + } + } +}); + +function foo(o) { + return ++o.x; +} + +assertEquals(2, foo(o)); +assertEquals(3, foo(o)); +%OptimizeFunctionOnNextCall(foo); +deopt = true; +assertEquals(4, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors3.js b/deps/v8/test/mjsunit/compiler/deopt-accessors3.js new file mode 100644 index 0000000000..035cf2b359 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors3.js @@ -0,0 +1,29 @@ +// Copyright 2016 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 + +var o = {v:1}; +var deopt = false; + +Object.defineProperty(o, "x", { + get: function() { return this.v; }, + set: function(v) { + this.v = v; + if (deopt) { + %DeoptimizeFunction(foo); + } + } +}); + +function foo(o) { + var x = "x"; + return o[x]++; +} + +assertEquals(1, foo(o)); +assertEquals(2, foo(o)); +%OptimizeFunctionOnNextCall(foo); +deopt = true; +assertEquals(3, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors4.js b/deps/v8/test/mjsunit/compiler/deopt-accessors4.js new file mode 100644 index 0000000000..5a8453f237 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors4.js @@ -0,0 +1,29 @@ +// Copyright 2016 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 + +var o = {v:1}; +var deopt = false; + +Object.defineProperty(o, "x", { + get: function() { return this.v; }, + set: function(v) { + this.v = v; + if (deopt) { + %DeoptimizeFunction(foo); + } + } +}); + +function foo(o) { + var x = "x"; + return ++o[x]; +} + +assertEquals(2, foo(o)); +assertEquals(3, foo(o)); +%OptimizeFunctionOnNextCall(foo); +deopt = true; +assertEquals(4, foo(o)); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors5.js b/deps/v8/test/mjsunit/compiler/deopt-accessors5.js new file mode 100644 index 0000000000..1b23c532dc --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors5.js @@ -0,0 +1,23 @@ +// Copyright 2016 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-tailcalls + +"use strict"; + +function f(v) { + %DeoptimizeFunction(test); + return 153; +} + +function test() { + var o = {}; + o.__defineSetter__('q', f); + assertEquals(1, o.q = 1); +} + +test(); +test(); +%OptimizeFunctionOnNextCall(test); +test(); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors6.js b/deps/v8/test/mjsunit/compiler/deopt-accessors6.js new file mode 100644 index 0000000000..16fb4ddf64 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors6.js @@ -0,0 +1,24 @@ +// Copyright 2016 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-tailcalls + +"use strict"; + +function f(v) { + %DeoptimizeFunction(test); + return 153; +} + +function test() { + var o = {}; + var q = "q"; + o.__defineSetter__(q, f); + assertEquals(1, o[q] = 1); +} + +test(); +test(); +%OptimizeFunctionOnNextCall(test); +test(); diff --git a/deps/v8/test/mjsunit/compiler/deopt-accessors7.js b/deps/v8/test/mjsunit/compiler/deopt-accessors7.js new file mode 100644 index 0000000000..8c7d7a1e3c --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/deopt-accessors7.js @@ -0,0 +1,30 @@ +// Copyright 2016 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 + +var o = {v:1}; +var deopt = false; +Object.defineProperty(o, "x", { + get: function() { + if (deopt) %DeoptimizeFunction(foo); + return 1; + } +}); + +function bar(x, y, z) { + return x + z; +} + +function foo(o, x) { + return bar(1, (o[x], 2), 3); +} + +assertEquals(4, foo(o, "v")); +assertEquals(4, foo(o, "v")); +assertEquals(4, foo(o, "x")); +assertEquals(4, foo(o, "x")); +%OptimizeFunctionOnNextCall(foo); +deopt = true; +assertEquals(4, foo(o, "x")); diff --git a/deps/v8/test/mjsunit/compiler/deopt-materialize-accumulator.js b/deps/v8/test/mjsunit/compiler/deopt-materialize-accumulator.js index 217de769d3..0b19df8a1c 100644 --- a/deps/v8/test/mjsunit/compiler/deopt-materialize-accumulator.js +++ b/deps/v8/test/mjsunit/compiler/deopt-materialize-accumulator.js @@ -34,7 +34,7 @@ var global = 3; function f(a) { // This will trigger a deopt since global was previously a SMI, with the // accumulator holding an unboxed double which needs materialized. - global = %math_sqrt(a); + global = Math.sqrt(a); } %OptimizeFunctionOnNextCall(f); f(0.25); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-610228.js b/deps/v8/test/mjsunit/compiler/dont-constant-fold-deopting-checks.js index ca077d5631..02bd8d9a25 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-610228.js +++ b/deps/v8/test/mjsunit/compiler/dont-constant-fold-deopting-checks.js @@ -4,8 +4,7 @@ // Flags: --allow-natives-syntax -function foo() { return JSON.stringify({a: 0.1}); } -assertEquals('{"a":0.1}', foo()); -assertEquals('{"a":0.1}', foo()); +function bar(a) { a[0](true); } +function foo(a) { return bar(1); } %OptimizeFunctionOnNextCall(foo); -assertEquals('{"a":0.1}', foo()); +assertThrows(function() {bar([foo])}, TypeError); diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-1.js b/deps/v8/test/mjsunit/compiler/escape-analysis-1.js index b8c66448dc..f05040bd02 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-1.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-1.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-10.js b/deps/v8/test/mjsunit/compiler/escape-analysis-10.js index c53cf4d989..4f06d57dcf 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-10.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-10.js @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape + (function() { "use strict"; function f() { diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-2.js b/deps/v8/test/mjsunit/compiler/escape-analysis-2.js index d116e9a364..49f440e856 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-2.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-2.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-3.js b/deps/v8/test/mjsunit/compiler/escape-analysis-3.js index d1ebc9b1f8..b92d1c3876 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-3.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-3.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-4.js b/deps/v8/test/mjsunit/compiler/escape-analysis-4.js index d9fdccc143..ef9f95fd36 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-4.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-4.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-5.js b/deps/v8/test/mjsunit/compiler/escape-analysis-5.js index cfaf81dbc3..54b5e82958 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-5.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-5.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(h) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-6.js b/deps/v8/test/mjsunit/compiler/escape-analysis-6.js index 6143cfbc1f..c36e7d956e 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-6.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-6.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-7.js b/deps/v8/test/mjsunit/compiler/escape-analysis-7.js index 16bc71c017..cfa30cbeb4 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-7.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-7.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f() { this.x=0; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-8.js b/deps/v8/test/mjsunit/compiler/escape-analysis-8.js index bc5b1d963e..d9c6d254ef 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-8.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-8.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f(a) { this.x=a; diff --git a/deps/v8/test/mjsunit/compiler/escape-analysis-9.js b/deps/v8/test/mjsunit/compiler/escape-analysis-9.js index a19786b360..0b8f75c576 100644 --- a/deps/v8/test/mjsunit/compiler/escape-analysis-9.js +++ b/deps/v8/test/mjsunit/compiler/escape-analysis-9.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax --turbo-escape -// function f() { return arguments; diff --git a/deps/v8/test/mjsunit/compiler/inline-dead-jscreate.js b/deps/v8/test/mjsunit/compiler/inline-dead-jscreate.js new file mode 100644 index 0000000000..a9778758c4 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/inline-dead-jscreate.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 bar = 0; + +function baz() { return this; } + +function foo() { + bar += 1; + if (bar === 2) throw new baz(); +} + +foo(); diff --git a/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter1.js b/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter1.js new file mode 100644 index 0000000000..8eb1c308a3 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter1.js @@ -0,0 +1,18 @@ +// Copyright 2016 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(a) { + return a.pop(); +} + +var a = new Array(4); + +assertEquals(undefined, foo(a)); +assertEquals(undefined, foo(a)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(undefined, foo(a)); +Object.prototype.__defineGetter__(0, function() { return 1; }); +assertEquals(1, foo(a)); diff --git a/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter2.js b/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter2.js new file mode 100644 index 0000000000..8ae642619e --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/inlined-array-pop-getter2.js @@ -0,0 +1,23 @@ +// Copyright 2016 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 + +var pop = Array.prototype.pop; + +function foo(a) { + a.length; + return pop.call(a); +} + +var a = new Array(4); +var o = {} +o.__defineGetter__(0, function() { return 1; }); + +assertEquals(undefined, foo(a)); +assertEquals(undefined, foo(a)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(undefined, foo(a)); +Array.prototype.__proto__ = o; +assertEquals(1, foo(a)); diff --git a/deps/v8/test/mjsunit/compiler/inlined-array-pop-opt.js b/deps/v8/test/mjsunit/compiler/inlined-array-pop-opt.js new file mode 100644 index 0000000000..c1301489e7 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/inlined-array-pop-opt.js @@ -0,0 +1,83 @@ +// Copyright 2016 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() { + function foo(a) { return a.pop(); } + + var x = {}; + var a = [x,x,]; + + assertEquals(x, foo(a)); + assertEquals(x, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(undefined, foo(a)); + assertOptimized(foo); +})(); + +(function() { + function foo(a) { return a.pop(); } + + var x = 0; + var a = [x,x,]; + + assertEquals(x, foo(a)); + assertEquals(x, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(undefined, foo(a)); + assertOptimized(foo); +})(); + +(function() { + function foo(a) { return a.pop(); } + + var x = 0; + var a = [x,x,x]; + + assertEquals(x, foo(a)); + assertEquals(x, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(x, foo(a)); + assertOptimized(foo); +})(); + +(function() { + function foo(a) { return a.pop(); } + + var x = {}; + var a = [x,x,x]; + + assertEquals(x, foo(a)); + assertEquals(x, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(x, foo(a)); + assertOptimized(foo); +})(); + +(function() { + function foo(a) { return a.pop(); } + + var a = [,,]; + + assertEquals(undefined, foo(a)); + assertEquals(undefined, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(undefined, foo(a)); + assertOptimized(foo); +})(); + +(function() { + var pop = Array.prototype.pop; + + function foo(a) { return a.pop(); } + + var a = [1, 2, 3]; + + assertEquals(3, foo(a)); + assertEquals(2, foo(a)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(1, foo(a)); + assertOptimized(foo); +})(); diff --git a/deps/v8/test/mjsunit/compiler/integral32-add-sub.js b/deps/v8/test/mjsunit/compiler/integral32-add-sub.js new file mode 100644 index 0000000000..2dd370c9dd --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/integral32-add-sub.js @@ -0,0 +1,131 @@ +// Copyright 2016 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() { + function foo(x) { + x = x >>> 0; + var y = 0 - 2147483648; + return x + y; + } + + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + %BaselineFunctionOnNextCall(foo); + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + assertOptimized(foo); +})(); + +(function() { + function foo(x) { + x = x >>> 0; + var y = 2147483648; + return x - y; + } + + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + %BaselineFunctionOnNextCall(foo); + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-2147483648, foo(0)); + assertEquals(0, foo(2147483648)); + assertEquals(2147483647, foo(4294967295)); + assertOptimized(foo); +})(); + +(function() { + function foo(x) { + x = x | 0; + var y = 2147483648; + return x + y; + } + + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + %BaselineFunctionOnNextCall(foo); + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + assertOptimized(foo); +})(); + +(function() { + function foo(x) { + x = x | 0; + var y = 0 - 2147483648; + return x - y; + } + + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + %BaselineFunctionOnNextCall(foo); + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(2147483648, foo(0)); + assertEquals(0, foo(-2147483648)); + assertEquals(4294967295, foo(2147483647)); + assertOptimized(foo); +})(); + +(function() { + function foo(x) { + x = x | 0; + var y = -0; + return x + y; + } + + assertEquals(2147483647, foo(2147483647)); + assertEquals(-2147483648, foo(-2147483648)); + assertEquals(0, foo(0)); + %BaselineFunctionOnNextCall(foo); + assertEquals(2147483647, foo(2147483647)); + assertEquals(-2147483648, foo(-2147483648)); + assertEquals(0, foo(0)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(2147483647, foo(2147483647)); + assertEquals(-2147483648, foo(-2147483648)); + assertEquals(0, foo(0)); + assertOptimized(foo); +})(); + +(function() { + function foo(x) { + var y = (x < 0) ? 4294967295 : 4294967296; + var z = (x > 0) ? 2147483647 : 2147483648; + return y - z; + } + + assertEquals(2147483647, foo(-1)); + assertEquals(2147483648, foo(0)); + assertEquals(2147483649, foo(1)); + %BaselineFunctionOnNextCall(foo); + assertEquals(2147483647, foo(-1)); + assertEquals(2147483648, foo(0)); + assertEquals(2147483649, foo(1)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(2147483647, foo(-1)); + assertEquals(2147483648, foo(0)); + assertEquals(2147483649, foo(1)); + assertOptimized(foo); +})(); diff --git a/deps/v8/test/mjsunit/compiler/math-mul.js b/deps/v8/test/mjsunit/compiler/math-mul.js new file mode 100644 index 0000000000..a391b445fe --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/math-mul.js @@ -0,0 +1,45 @@ +// Copyright 2016 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 + +// For TurboFan, make sure we can eliminate the -0 return value check +// by recognizing a constant value. +function gotaconstant(y) { return 15 * y; } +assertEquals(45, gotaconstant(3)); +gotaconstant(3); +%OptimizeFunctionOnNextCall(gotaconstant); +gotaconstant(3); + +function gotaconstant_truncated(x, y) { return x * y | 0; } +assertEquals(45, gotaconstant_truncated(3, 15)); +gotaconstant_truncated(3, 15); +%OptimizeFunctionOnNextCall(gotaconstant_truncated); +gotaconstant_truncated(3, 15); + +function test(x, y) { return x * y; } + +assertEquals(12, test(3, 4)); +assertEquals(16, test(4, 4)); + +%OptimizeFunctionOnNextCall(test); +assertEquals(27, test(9, 3)); + +assertEquals(-0, test(-3, 0)); +assertEquals(-0, test(0, -0)); + + +const SMI_MAX = (1 << 29) - 1 + (1 << 29); // Create without overflowing. +const SMI_MIN = -SMI_MAX - 1; // Create without overflowing. + +// multiply by 3 to avoid compiler optimizations that convert 2*x to x + x. +assertEquals(SMI_MAX + SMI_MAX + SMI_MAX, test(SMI_MAX, 3)); + +// Verify that strength reduction will reduce the -0 check quite a bit +// if we have a negative integer constant. +function negtest(y) { return -3 * y; } +assertEquals(-12, negtest(4)); +assertEquals(-12, negtest(4)); +%OptimizeFunctionOnNextCall(negtest); +negtest(4); diff --git a/deps/v8/test/mjsunit/compiler/optimized-float32array-length.js b/deps/v8/test/mjsunit/compiler/optimized-float32array-length.js new file mode 100644 index 0000000000..eed8922c07 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-float32array-length.js @@ -0,0 +1,13 @@ +// Copyright 2016 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 + +var a = new Float32Array(1); +function len(a) { return a.length; } +assertEquals(1, len(a)); +assertEquals(1, len(a)); +%OptimizeFunctionOnNextCall(len); +assertEquals(1, len(a)); +assertOptimized(len); diff --git a/deps/v8/test/mjsunit/compiler/optimized-float64array-length.js b/deps/v8/test/mjsunit/compiler/optimized-float64array-length.js new file mode 100644 index 0000000000..f6a3d77677 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-float64array-length.js @@ -0,0 +1,13 @@ +// Copyright 2016 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 + +var a = new Float64Array(1); +function len(a) { return a.length; } +assertEquals(1, len(a)); +assertEquals(1, len(a)); +%OptimizeFunctionOnNextCall(len); +assertEquals(1, len(a)); +assertOptimized(len); diff --git a/deps/v8/test/mjsunit/compiler/optimized-for-in.js b/deps/v8/test/mjsunit/compiler/optimized-for-in.js index 9f5e4e7f83..ca17ee6a75 100644 --- a/deps/v8/test/mjsunit/compiler/optimized-for-in.js +++ b/deps/v8/test/mjsunit/compiler/optimized-for-in.js @@ -35,28 +35,28 @@ function a(t) { var result = []; for (var i in t) { - result.push(i + t[i]); + result.push([i, t[i]]); } - return result.join(''); + return result; } // Check that we correctly deoptimize on map check. function b(t) { var result = []; for (var i in t) { - result.push(i + t[i]); + result.push([i, t[i]]); delete t[i]; } - return result.join(''); + return result; } // Check that we correctly deoptimize during preparation step. function c(t) { var result = []; for (var i in t) { - result.push(i + t[i]); + result.push([i, t[i]]); } - return result.join(''); + return result; } // Check that we deoptimize to the place after side effect in the right state. @@ -64,9 +64,9 @@ function d(t) { var result = []; var o; for (var i in (o = t())) { - result.push(i + o[i]); + result.push([i, o[i]]); } - return result.join(''); + return result; } // Check that we correctly deoptimize on map check inserted for fused load. @@ -75,9 +75,9 @@ function e(t) { for (var i in t) { delete t[i]; t[i] = i; - result.push(i + t[i]); + result.push([i, t[i]]); } - return result.join(''); + return result; } // Nested for-in loops. @@ -85,10 +85,10 @@ function f(t) { var result = []; for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); } } - return result.join(''); + return result; } // Deoptimization from the inner for-in loop. @@ -96,13 +96,13 @@ function g(t) { var result = []; for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); var v = t[i]; delete t[i]; t[i] = v; } } - return result.join(''); + return result; } @@ -111,12 +111,12 @@ function h(t, deopt) { var result = []; for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); break; } } deopt.deopt; - return result.join(''); + return result; } // Continue in the inner loop. @@ -124,12 +124,12 @@ function j(t, deopt) { var result = []; for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); continue; } } deopt.deopt; - return result.join(''); + return result; } // Continue of the outer loop. @@ -137,12 +137,12 @@ function k(t, deopt) { var result = []; outer: for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); continue outer; } } deopt.deopt; - return result.join(''); + return result; } // Break of the outer loop. @@ -150,12 +150,12 @@ function l(t, deopt) { var result = []; outer: for (var i in t) { for (var j in t) { - result.push(i + j + t[i] + t[j]); + result.push([i, j, t[i], t[j]]); break outer; } } deopt.deopt; - return result.join(''); + return result; } // Test deoptimization from inlined frame (currently it is not inlined). @@ -163,7 +163,7 @@ function m0(t, deopt) { for (var i in t) { for (var j in t) { deopt.deopt; - return i + j + t[i] + t[j]; + return [i, j, t[i], t[j]]; } } } @@ -173,42 +173,53 @@ function m(t, deopt) { } -function tryFunction(s, mkT, f) { +function tryFunction(result, mkT, f) { var d = {deopt: false}; - assertEquals(s, f(mkT(), d)); - assertEquals(s, f(mkT(), d)); - assertEquals(s, f(mkT(), d)); + assertEquals(result, f(mkT(), d)); + assertEquals(result, f(mkT(), d)); + assertEquals(result, f(mkT(), d)); %OptimizeFunctionOnNextCall(f); - assertEquals(s, f(mkT(), d)); - assertEquals(s, f(mkT(), {})); + assertEquals(result, f(mkT(), d)); + assertEquals(result, f(mkT(), {})); } -var s = "a1b2c3d4"; +var expectedResult = [["a","1"],["b","2"],["c","3"],["d","4"]]; function mkTable() { return { a: "1", b: "2", c: "3", d: "4" }; } -tryFunction(s, mkTable, a); -tryFunction(s, mkTable, b); -tryFunction("0a1b2c3d", function () { return "abcd"; }, c); -tryFunction("0a1b2c3d", function () { +tryFunction(expectedResult, mkTable, a); +tryFunction(expectedResult, mkTable, b); + +expectedResult = [["0","a"],["1","b"],["2","c"],["3","d"]]; +tryFunction(expectedResult, function () { return "abcd"; }, c); +tryFunction(expectedResult, function () { var cnt = false; return function () { cnt = true; return "abcd"; } }, d); -tryFunction("aabbccdd", mkTable, e); +tryFunction([["a","a"],["b","b"],["c","c"],["d","d"]], mkTable, e); function mkSmallTable() { return { a: "1", b: "2" }; } -tryFunction("aa11ab12ba21bb22", mkSmallTable, f); -tryFunction("aa11ab12bb22ba21", mkSmallTable, g); -tryFunction("aa11ba21", mkSmallTable, h); -tryFunction("aa11ab12ba21bb22", mkSmallTable, j); -tryFunction("aa11ba21", mkSmallTable, h); -tryFunction("aa11ba21", mkSmallTable, k); -tryFunction("aa11", mkSmallTable, l); -tryFunction("aa11", mkSmallTable, m); +tryFunction([ + ["a","a","1","1"],["a","b","1","2"], + ["b","a","2","1"],["b","b","2","2"]], + mkSmallTable, f); +tryFunction([ + ["a","a","1","1"],["a","b","1","2"], + ["b","b","2","2"],["b","a","2","1"]], + mkSmallTable, g); +tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, h); +tryFunction([ + ["a","a","1","1"],["a","b","1","2"], + ["b","a","2","1"],["b","b","2","2"]], + mkSmallTable, j); +tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, h); +tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, k); +tryFunction([["a","a","1","1"]], mkSmallTable, l); +tryFunction(["a","a","1","1"], mkSmallTable, m); // Test handling of null. tryFunction("", function () { @@ -229,7 +240,7 @@ tryFunction("", function () { // Test LoadFieldByIndex for out of object properties. function O() { this.a = 1; } for (var i = 0; i < 10; i++) new O(); -tryFunction("a1b2c3d4e5f6", function () { +tryFunction([["a",1],["b",2],["c",3],["d",4],["e",5],["f",6]], function () { var o = new O(); o.b = 2; o.c = 3; @@ -239,8 +250,8 @@ tryFunction("a1b2c3d4e5f6", function () { return o; }, function (t) { var r = []; - for (var i in t) r.push(i + t[i]); - return r.join(''); + for (var i in t) r.push([i, t[i]]); + return r; }); // Test OSR inside for-in. diff --git a/deps/v8/test/mjsunit/compiler/optimized-instanceof-1.js b/deps/v8/test/mjsunit/compiler/optimized-instanceof-1.js new file mode 100644 index 0000000000..242b4be772 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-instanceof-1.js @@ -0,0 +1,17 @@ +// Copyright 2016 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 F() {} +var f = new F + +var proto = Object.getPrototypeOf(F); +Object.setPrototypeOf(F, null); +F[Symbol.hasInstance] = function(v) { return true }; +Object.setPrototypeOf(F, proto); + +function foo(x) { return x instanceof F }; +%OptimizeFunctionOnNextCall(foo); +assertTrue(foo(1)); diff --git a/deps/v8/test/mjsunit/compiler/optimized-instanceof-2.js b/deps/v8/test/mjsunit/compiler/optimized-instanceof-2.js new file mode 100644 index 0000000000..38a35b73f1 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-instanceof-2.js @@ -0,0 +1,19 @@ +// Copyright 2016 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 F() {} +var f = new F + +function foo(x) { return x instanceof F }; +%OptimizeFunctionOnNextCall(foo); +assertFalse(foo(1)); + +var proto = Object.getPrototypeOf(F); +Object.setPrototypeOf(F, null); +F[Symbol.hasInstance] = function(v) { return true }; +Object.setPrototypeOf(F, proto); + +assertTrue(foo(1)); diff --git a/deps/v8/test/mjsunit/compiler/optimized-int32array-length.js b/deps/v8/test/mjsunit/compiler/optimized-int32array-length.js new file mode 100644 index 0000000000..250d523cc9 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-int32array-length.js @@ -0,0 +1,13 @@ +// Copyright 2016 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 + +var a = new Int32Array(1); +function len(a) { return a.length; } +assertEquals(1, len(a)); +assertEquals(1, len(a)); +%OptimizeFunctionOnNextCall(len); +assertEquals(1, len(a)); +assertOptimized(len); diff --git a/deps/v8/test/mjsunit/compiler/optimized-uint32array-length.js b/deps/v8/test/mjsunit/compiler/optimized-uint32array-length.js new file mode 100644 index 0000000000..d389370a4f --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/optimized-uint32array-length.js @@ -0,0 +1,13 @@ +// Copyright 2016 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 + +var a = new Uint32Array(1); +function len(a) { return a.length; } +assertEquals(1, len(a)); +assertEquals(1, len(a)); +%OptimizeFunctionOnNextCall(len); +assertEquals(1, len(a)); +assertOptimized(len); diff --git a/deps/v8/test/mjsunit/compiler/osr-alignment.js b/deps/v8/test/mjsunit/compiler/osr-alignment.js index 085d6c4d68..f815e712ee 100644 --- a/deps/v8/test/mjsunit/compiler/osr-alignment.js +++ b/deps/v8/test/mjsunit/compiler/osr-alignment.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 --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function f1() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-backedges1.js b/deps/v8/test/mjsunit/compiler/osr-backedges1.js index d415f4a107..18a7e0469e 100644 --- a/deps/v8/test/mjsunit/compiler/osr-backedges1.js +++ b/deps/v8/test/mjsunit/compiler/osr-backedges1.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function foo(a) { var i = a | 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-block-scope-func.js b/deps/v8/test/mjsunit/compiler/osr-block-scope-func.js index df4076c411..7c41f54074 100644 --- a/deps/v8/test/mjsunit/compiler/osr-block-scope-func.js +++ b/deps/v8/test/mjsunit/compiler/osr-block-scope-func.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/osr-block-scope-id.js b/deps/v8/test/mjsunit/compiler/osr-block-scope-id.js index 923c72f422..bcc7cdd47d 100644 --- a/deps/v8/test/mjsunit/compiler/osr-block-scope-id.js +++ b/deps/v8/test/mjsunit/compiler/osr-block-scope-id.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/osr-block-scope.js b/deps/v8/test/mjsunit/compiler/osr-block-scope.js index 0d78cdcb64..c60f8af6c9 100644 --- a/deps/v8/test/mjsunit/compiler/osr-block-scope.js +++ b/deps/v8/test/mjsunit/compiler/osr-block-scope.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/osr-follow.js b/deps/v8/test/mjsunit/compiler/osr-follow.js index b6a2e8e4be..46581a8e5a 100644 --- a/deps/v8/test/mjsunit/compiler/osr-follow.js +++ b/deps/v8/test/mjsunit/compiler/osr-follow.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: --use-osr --turbo-osr +// Flags: --use-osr function foo(a) { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-for-let.js b/deps/v8/test/mjsunit/compiler/osr-for-let.js index 4b2fa3e532..b8cef780b5 100644 --- a/deps/v8/test/mjsunit/compiler/osr-for-let.js +++ b/deps/v8/test/mjsunit/compiler/osr-for-let.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/osr-forin-nested.js b/deps/v8/test/mjsunit/compiler/osr-forin-nested.js index ad55b30bd8..dd810897e0 100644 --- a/deps/v8/test/mjsunit/compiler/osr-forin-nested.js +++ b/deps/v8/test/mjsunit/compiler/osr-forin-nested.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: --turbo-osr --allow-natives-syntax +// Flags: --allow-natives-syntax function test(e, f, v) { assertEquals(e, f(v)); diff --git a/deps/v8/test/mjsunit/compiler/osr-forin.js b/deps/v8/test/mjsunit/compiler/osr-forin.js index 8d1678224c..b45d200d1b 100644 --- a/deps/v8/test/mjsunit/compiler/osr-forin.js +++ b/deps/v8/test/mjsunit/compiler/osr-forin.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: --use-osr --turbo-osr +// Flags: --use-osr function f(a) { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-forof.js b/deps/v8/test/mjsunit/compiler/osr-forof.js index 36bff09c58..ce7b24de13 100644 --- a/deps/v8/test/mjsunit/compiler/osr-forof.js +++ b/deps/v8/test/mjsunit/compiler/osr-forof.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: --use-osr --turbo-osr +// Flags: --use-osr function f(a) { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-function-id.js b/deps/v8/test/mjsunit/compiler/osr-function-id.js index c506ae8282..8761e8517e 100644 --- a/deps/v8/test/mjsunit/compiler/osr-function-id.js +++ b/deps/v8/test/mjsunit/compiler/osr-function-id.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: --use-osr --turbo-osr +// Flags: --use-osr function id(f) { return f; } diff --git a/deps/v8/test/mjsunit/compiler/osr-function-id2.js b/deps/v8/test/mjsunit/compiler/osr-function-id2.js index 561c62e1bc..e25ec31480 100644 --- a/deps/v8/test/mjsunit/compiler/osr-function-id2.js +++ b/deps/v8/test/mjsunit/compiler/osr-function-id2.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: --use-osr --turbo-osr +// Flags: --use-osr function id(f) { return f; } diff --git a/deps/v8/test/mjsunit/compiler/osr-function.js b/deps/v8/test/mjsunit/compiler/osr-function.js index 06d137b62c..cee7e9d3d0 100644 --- a/deps/v8/test/mjsunit/compiler/osr-function.js +++ b/deps/v8/test/mjsunit/compiler/osr-function.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: --use-osr --turbo-osr +// Flags: --use-osr function foo() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-infinite.js b/deps/v8/test/mjsunit/compiler/osr-infinite.js index aa74c877d5..24c7add272 100644 --- a/deps/v8/test/mjsunit/compiler/osr-infinite.js +++ b/deps/v8/test/mjsunit/compiler/osr-infinite.js @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --use-osr --allow-natives-syntax --turbo-osr +// Flags: --use-osr --allow-natives-syntax var global_counter = 0; function thrower() { var x = global_counter++; - if (x == 5) %OptimizeOsr(thrower.caller); + if (x == 5) %OptimizeOsr(1); if (x == 10) throw "terminate"; } diff --git a/deps/v8/test/mjsunit/compiler/osr-labeled.js b/deps/v8/test/mjsunit/compiler/osr-labeled.js index 1a9709285e..1384e9a715 100644 --- a/deps/v8/test/mjsunit/compiler/osr-labeled.js +++ b/deps/v8/test/mjsunit/compiler/osr-labeled.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function foo() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-literals-adapted.js b/deps/v8/test/mjsunit/compiler/osr-literals-adapted.js index 950d8b0762..4d1798c929 100644 --- a/deps/v8/test/mjsunit/compiler/osr-literals-adapted.js +++ b/deps/v8/test/mjsunit/compiler/osr-literals-adapted.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function mod() { function f0() { diff --git a/deps/v8/test/mjsunit/compiler/osr-literals.js b/deps/v8/test/mjsunit/compiler/osr-literals.js index d9f68a0b37..f2051dced7 100644 --- a/deps/v8/test/mjsunit/compiler/osr-literals.js +++ b/deps/v8/test/mjsunit/compiler/osr-literals.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function mod() { function f0() { diff --git a/deps/v8/test/mjsunit/compiler/osr-manual1.js b/deps/v8/test/mjsunit/compiler/osr-manual1.js index 29a4948a65..c3db796f11 100644 --- a/deps/v8/test/mjsunit/compiler/osr-manual1.js +++ b/deps/v8/test/mjsunit/compiler/osr-manual1.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr var counter = 111; diff --git a/deps/v8/test/mjsunit/compiler/osr-manual2.js b/deps/v8/test/mjsunit/compiler/osr-manual2.js index 8aa5d69db3..de7ec243fe 100644 --- a/deps/v8/test/mjsunit/compiler/osr-manual2.js +++ b/deps/v8/test/mjsunit/compiler/osr-manual2.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr var counter = 188; diff --git a/deps/v8/test/mjsunit/compiler/osr-multiple.js b/deps/v8/test/mjsunit/compiler/osr-multiple.js index c318645d32..72fff8546c 100644 --- a/deps/v8/test/mjsunit/compiler/osr-multiple.js +++ b/deps/v8/test/mjsunit/compiler/osr-multiple.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: --use-osr --turbo-osr +// Flags: --use-osr function f1(a,b,c) { var x = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-multiple2.js b/deps/v8/test/mjsunit/compiler/osr-multiple2.js index 9a81bfb658..edb627a57b 100644 --- a/deps/v8/test/mjsunit/compiler/osr-multiple2.js +++ b/deps/v8/test/mjsunit/compiler/osr-multiple2.js @@ -3,7 +3,6 @@ // found in the LICENSE file. // Flags: --use-osr -// TODO(titzer): enable --turbo-osr when nested OSR works. function f1(a,b,c) { var x = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-multiple3.js b/deps/v8/test/mjsunit/compiler/osr-multiple3.js index 0fb1ac73a3..fa703eaeac 100644 --- a/deps/v8/test/mjsunit/compiler/osr-multiple3.js +++ b/deps/v8/test/mjsunit/compiler/osr-multiple3.js @@ -3,7 +3,6 @@ // found in the LICENSE file. // Flags: --use-osr -// TODO(titzer): enable --turbo-osr when nested OSR works. function f1(a,b,c) { var x = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-nested2.js b/deps/v8/test/mjsunit/compiler/osr-nested2.js index 41bd9b247b..efe31f1177 100644 --- a/deps/v8/test/mjsunit/compiler/osr-nested2.js +++ b/deps/v8/test/mjsunit/compiler/osr-nested2.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function f() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-nested2b.js b/deps/v8/test/mjsunit/compiler/osr-nested2b.js index e64c10ccb4..18088114a4 100644 --- a/deps/v8/test/mjsunit/compiler/osr-nested2b.js +++ b/deps/v8/test/mjsunit/compiler/osr-nested2b.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function f() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-nested3.js b/deps/v8/test/mjsunit/compiler/osr-nested3.js index f5d09ba166..d7c144b9e6 100644 --- a/deps/v8/test/mjsunit/compiler/osr-nested3.js +++ b/deps/v8/test/mjsunit/compiler/osr-nested3.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function f() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-nested3b.js b/deps/v8/test/mjsunit/compiler/osr-nested3b.js index 32ac2a7058..a10d328e03 100644 --- a/deps/v8/test/mjsunit/compiler/osr-nested3b.js +++ b/deps/v8/test/mjsunit/compiler/osr-nested3b.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function f() { var sum = 0; diff --git a/deps/v8/test/mjsunit/compiler/osr-regex-id.js b/deps/v8/test/mjsunit/compiler/osr-regex-id.js index 7831b14840..e0b4dad1dc 100644 --- a/deps/v8/test/mjsunit/compiler/osr-regex-id.js +++ b/deps/v8/test/mjsunit/compiler/osr-regex-id.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function id(f) { return f; } diff --git a/deps/v8/test/mjsunit/compiler/osr-sar.js b/deps/v8/test/mjsunit/compiler/osr-sar.js index cc04adca8a..02684f088c 100644 --- a/deps/v8/test/mjsunit/compiler/osr-sar.js +++ b/deps/v8/test/mjsunit/compiler/osr-sar.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 --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr function test() { // Loop to force OSR. diff --git a/deps/v8/test/mjsunit/compiler/osr-warm.js b/deps/v8/test/mjsunit/compiler/osr-warm.js index 7c30c07f20..73e1fd5cd2 100644 --- a/deps/v8/test/mjsunit/compiler/osr-warm.js +++ b/deps/v8/test/mjsunit/compiler/osr-warm.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: --use-osr --turbo-osr +// Flags: --use-osr function f1(x) { while (x > 0) { diff --git a/deps/v8/test/mjsunit/compiler/osr-while-let.js b/deps/v8/test/mjsunit/compiler/osr-while-let.js index c19cf6cb24..11ebc4bb35 100644 --- a/deps/v8/test/mjsunit/compiler/osr-while-let.js +++ b/deps/v8/test/mjsunit/compiler/osr-while-let.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: --allow-natives-syntax --use-osr --turbo-osr +// Flags: --allow-natives-syntax --use-osr "use strict"; diff --git a/deps/v8/test/mjsunit/compiler/regress-5074.js b/deps/v8/test/mjsunit/compiler/regress-5074.js new file mode 100644 index 0000000000..903b54ad98 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-5074.js @@ -0,0 +1,18 @@ +// Copyright 2016 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 + +var s = [,0.1]; + +function foo(a, b) { + var x = s[a]; + s[1] = 0.1; + return x + b; +} + +assertEquals(2.1, foo(1, 2)); +assertEquals(2.1, foo(1, 2)); +%OptimizeFunctionOnNextCall(foo); +assertEquals("undefined2", foo(0, "2")); diff --git a/deps/v8/test/mjsunit/compiler/regress-5100.js b/deps/v8/test/mjsunit/compiler/regress-5100.js new file mode 100644 index 0000000000..694cd8a75b --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-5100.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 + +var a = [0, 1]; +a["true"] = "true"; +a["false"] = "false"; +a["null"] = "null"; +a["undefined"] = "undefined"; + +// Ensure we don't accidentially truncate true when used to index arrays. +(function() { + function f(x) { return a[x]; } + + assertEquals(0, f(0)); + assertEquals(0, f(0)); + %OptimizeFunctionOnNextCall(f); + assertEquals("true", f(true)); +})(); + +// Ensure we don't accidentially truncate false when used to index arrays. +(function() { + function f( x) { return a[x]; } + + assertEquals(0, f(0)); + assertEquals(0, f(0)); + %OptimizeFunctionOnNextCall(f); + assertEquals("false", f(false)); +})(); + +// Ensure we don't accidentially truncate null when used to index arrays. +(function() { + function f( x) { return a[x]; } + + assertEquals(0, f(0)); + assertEquals(0, f(0)); + %OptimizeFunctionOnNextCall(f); + assertEquals("null", f(null)); +})(); + +// Ensure we don't accidentially truncate undefined when used to index arrays. +(function() { + function f( x) { return a[x]; } + + assertEquals(0, f(0)); + assertEquals(0, f(0)); + %OptimizeFunctionOnNextCall(f); + assertEquals("undefined", f(undefined)); +})(); diff --git a/deps/v8/test/mjsunit/compiler/regress-5129.js b/deps/v8/test/mjsunit/compiler/regress-5129.js new file mode 100644 index 0000000000..1d100ab34c --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-5129.js @@ -0,0 +1,15 @@ +// Copyright 2016 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($a,$b) { + $a = $a|0; + $b = $b|0; + var $sub = $a - $b; + return ($sub|0) < 0; +} + +%OptimizeFunctionOnNextCall(foo); +assertTrue(foo(0x7fffffff,-1)); diff --git a/deps/v8/test/mjsunit/compiler/regress-5158.js b/deps/v8/test/mjsunit/compiler/regress-5158.js new file mode 100644 index 0000000000..ead5f4ed9d --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-5158.js @@ -0,0 +1,16 @@ +// Copyright 2016 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(x) { + x = +x; + return (x > 0) ? x : 0 - x; +} + +foo(1); +foo(-1); +foo(0); +%OptimizeFunctionOnNextCall(foo); +assertEquals(2147483648, foo(-2147483648)); diff --git a/deps/v8/test/mjsunit/compiler/regress-5278.js b/deps/v8/test/mjsunit/compiler/regress-5278.js new file mode 100644 index 0000000000..25b1fb03d5 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-5278.js @@ -0,0 +1,13 @@ +// Copyright 2016 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(a, b) { + return a % b; +} +foo(2, 1); +foo(2, 1); +%OptimizeFunctionOnNextCall(foo); +assertEquals(-0, foo(-2, 1)); diff --git a/deps/v8/test/mjsunit/compiler/regress-607493.js b/deps/v8/test/mjsunit/compiler/regress-607493.js new file mode 100644 index 0000000000..540b47e2d2 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-607493.js @@ -0,0 +1,37 @@ +// Copyright 2016 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 ForInTryCatchContrinueOsr() { + var a = [1]; + + function g() { + for (var x in a) { + try { + for (var i = 0; i < 10; i++) { %OptimizeOsr(); } + return; + } catch(e) { + continue; + } + } + } + + g(); +})(); + +(function ForInContinueNestedOsr() { + var a = [1]; + + function g() { + for (var x in a) { + if (x) { + for (var i = 0; i < 10; i++) { %OptimizeOsr(); } + } + continue; + } + } + + g(); +})(); diff --git a/deps/v8/test/mjsunit/compiler/regress-621423.js b/deps/v8/test/mjsunit/compiler/regress-621423.js new file mode 100644 index 0000000000..962176ffbf --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-621423.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 + +var a = [0, ""]; +a[0] = 0; + +function g(array) { + array[1] = undefined; +} + +function f() { + g(function() {}); + g(a); +} + +f(); +%OptimizeFunctionOnNextCall(f); +f(); diff --git a/deps/v8/test/mjsunit/compiler/regress-625558.js b/deps/v8/test/mjsunit/compiler/regress-625558.js new file mode 100644 index 0000000000..5d6b372632 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-625558.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 + +for (var global = 0; global <= 256; global++) { } + +function f() { + global = "luft"; + global += ++global; +} + +f(); diff --git a/deps/v8/test/mjsunit/compiler/regress-628403.js b/deps/v8/test/mjsunit/compiler/regress-628403.js new file mode 100644 index 0000000000..4096ac32ae --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-628403.js @@ -0,0 +1,27 @@ +// Copyright 2016 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 + +var dothrow = false; + +function g() { + if (dothrow) throw 1; +} + +function f(a) { + try { + g(); + } catch(e) { + if (typeof e !== 'number' && e !== 1) throw e; + return a[0]; + } +} + +%NeverOptimizeFunction(g); +f(); +f(); +%OptimizeFunctionOnNextCall(f); +dothrow = true; +assertEquals(42, f([42])); diff --git a/deps/v8/test/mjsunit/compiler/regress-628516.js b/deps/v8/test/mjsunit/compiler/regress-628516.js new file mode 100644 index 0000000000..8cb43b4bea --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-628516.js @@ -0,0 +1,13 @@ +// Copyright 2016 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() { + var i = 0; + while (1) { + if ({}) i = expected[0] == x[0]; + i++; + } +} + +assertThrows(f); diff --git a/deps/v8/test/mjsunit/compiler/regress-628773.js b/deps/v8/test/mjsunit/compiler/regress-628773.js new file mode 100644 index 0000000000..3c315b3828 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-628773.js @@ -0,0 +1,21 @@ +// Copyright 2016 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-tailcalls + +"use strict"; + +function foo() { + for (var i = 0; i < 10000; i++) { + try { + for (var j = 0; j < 2; j++) { + } + throw 1; + } catch(e) { + if (typeof a == "number") return a && isNaN(b); + } + } +} + +foo(); diff --git a/deps/v8/test/mjsunit/compiler/regress-630611.js b/deps/v8/test/mjsunit/compiler/regress-630611.js new file mode 100644 index 0000000000..be75777ba7 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-630611.js @@ -0,0 +1,16 @@ +// Copyright 2016 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 global = 1; +global = 2; + +function f() { + var o = { a : 1 }; + global = "a"; + for (var i = global; i < 2; i++) { + delete o[i]; + } +} + +f(); diff --git a/deps/v8/test/mjsunit/compiler/regress-633497.js b/deps/v8/test/mjsunit/compiler/regress-633497.js new file mode 100644 index 0000000000..8bf358af00 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-633497.js @@ -0,0 +1,29 @@ +// Copyright 2016 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 f(a) { + var x; + a = a|0; + var dummy; + if (a === 1) { + x = 277.5; + } else if (a === 2) { + x = 0; + } else { + dummy = 527.5; + dummy = 958.5; + dummy = 1143.5; + dummy = 1368.5; + dummy = 1558.5; + x = 277.5; + } + return +x; +} + +f(); +f(); +%OptimizeFunctionOnNextCall(f); +assertEquals(277.5, f()); diff --git a/deps/v8/test/mjsunit/compiler/regress-loop-variable-if.js b/deps/v8/test/mjsunit/compiler/regress-loop-variable-if.js new file mode 100644 index 0000000000..ec284e9222 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-loop-variable-if.js @@ -0,0 +1,13 @@ +// Copyright 2016 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: --turbo-loop-variable + +function f() { + for (var i = 0; i != 10; i++) { + if (i < 8) print("x"); + } +} + +f(); diff --git a/deps/v8/test/mjsunit/compiler/regress-loop-variable-unsigned.js b/deps/v8/test/mjsunit/compiler/regress-loop-variable-unsigned.js new file mode 100644 index 0000000000..751136eb13 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-loop-variable-unsigned.js @@ -0,0 +1,23 @@ +// Copyright 2016 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: --turbo-loop-variable + +(function() { + function f() { + for (var i = 0; i < 4294967295; i += 2) { + if (i === 10) break; + } + } + f(); +})(); + +(function() { + function f() { + for (var i = 0; i < 4294967293; i += 2) { + if (i === 10) break; + } + } + f(); +})(); diff --git a/deps/v8/test/mjsunit/compiler/regress-number-is-hole-nan.js b/deps/v8/test/mjsunit/compiler/regress-number-is-hole-nan.js new file mode 100644 index 0000000000..368c837163 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-number-is-hole-nan.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 + +var a = [, 2.121736758e-314]; + +function foo() { return a[1]; } + +assertEquals(2.121736758e-314, foo()); +assertEquals(2.121736758e-314, foo()); +%OptimizeFunctionOnNextCall(foo); +assertEquals(2.121736758e-314, foo()); diff --git a/deps/v8/test/mjsunit/compiler/regress-store-holey-double-array.js b/deps/v8/test/mjsunit/compiler/regress-store-holey-double-array.js new file mode 100644 index 0000000000..81231984e0 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-store-holey-double-array.js @@ -0,0 +1,43 @@ +// Copyright 2016 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 StoreHoleBitPattern() { + function g(src, dst, i) { + dst[i] = src[i]; + } + + var b = new ArrayBuffer(16); + var i32 = new Int32Array(b); + i32[0] = 0xFFF7FFFF; + i32[1] = 0xFFF7FFFF; + i32[3] = 0xFFF7FFFF; + i32[4] = 0xFFF7FFFF; + var f64 = new Float64Array(b); + + var a = [,0.1]; + + g(f64, a, 1); + g(f64, a, 1); + %OptimizeFunctionOnNextCall(g); + g(f64, a, 0); + + assertTrue(Number.isNaN(a[0])); +})(); + + +(function ConvertHoleToNumberAndStore() { + function g(a, i) { + var x = a[i]; + a[i] = +x; + } + + var a=[,0.1]; + g(a, 1); + g(a, 1); + %OptimizeFunctionOnNextCall(g); + g(a, 0); + assertTrue(Number.isNaN(a[0])); +})(); diff --git a/deps/v8/test/mjsunit/compiler/regress-string-to-number-add.js b/deps/v8/test/mjsunit/compiler/regress-string-to-number-add.js new file mode 100644 index 0000000000..e872401c0b --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-string-to-number-add.js @@ -0,0 +1,15 @@ +// Copyright 2016 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-type-feedback + +function f(x) { + var s = x ? "0" : "1"; + return 1 + Number(s); +} + +f(0); +f(0); +%OptimizeFunctionOnNextCall(f); +assertEquals(2, f(0)); diff --git a/deps/v8/test/mjsunit/compiler/regress-truncate-number-or-undefined-to-float64.js b/deps/v8/test/mjsunit/compiler/regress-truncate-number-or-undefined-to-float64.js new file mode 100644 index 0000000000..1dc3042ea7 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/regress-truncate-number-or-undefined-to-float64.js @@ -0,0 +1,19 @@ +// Copyright 2016 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 g(a, b) { + a = +a; + if (b) { + a = undefined; + } + print(a); + return +a; +} + +g(0); +g(0); +%OptimizeFunctionOnNextCall(g); +assertTrue(Number.isNaN(g(0, true))); diff --git a/deps/v8/test/mjsunit/compiler/regress-valueof.js b/deps/v8/test/mjsunit/compiler/regress-valueof.js deleted file mode 100644 index 7b29b46a66..0000000000 --- a/deps/v8/test/mjsunit/compiler/regress-valueof.js +++ /dev/null @@ -1,35 +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 - -// Test valueof with integer input. -function f(x) { var y = x + 1; return %_ValueOf(y); } - -for (var i=0; i<100000; i++) f(42); - -assertEquals(43, f(42)); diff --git a/deps/v8/test/mjsunit/compiler/try-osr.js b/deps/v8/test/mjsunit/compiler/try-osr.js index e4eb8dd9fa..c0ef27add3 100644 --- a/deps/v8/test/mjsunit/compiler/try-osr.js +++ b/deps/v8/test/mjsunit/compiler/try-osr.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: --allow-natives-syntax --turbo-osr +// Flags: --allow-natives-syntax function OSRInsideTry(x) { try { diff --git a/deps/v8/test/mjsunit/compiler/turbo-number-feedback.js b/deps/v8/test/mjsunit/compiler/turbo-number-feedback.js new file mode 100644 index 0000000000..8dcc42c8a1 --- /dev/null +++ b/deps/v8/test/mjsunit/compiler/turbo-number-feedback.js @@ -0,0 +1,102 @@ +// Copyright 2016 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-type-feedback + +(function AddSubtractSmis() { + function f0(a, b, c) { + return a + b - c; + } + + assertEquals(4, f0(3, 2, 1)); + assertEquals(4, f0(3, 2, 1)); + %OptimizeFunctionOnNextCall(f0); + assertEquals(4, f0(3, 2, 1)); +})(); + +(function AddSubtractDoubles() { + function f1(a, b, c) { + return a + b - c; + } + + assertEquals(4.5, f1(3.5, 2.5, 1.5)); + assertEquals(4.5, f1(3.5, 2.5, 1.5)); + %OptimizeFunctionOnNextCall(f1); + assertEquals(4.5, f1(3.5, 2.5, 1.5)); + assertEquals(4, f1(3, 2, 1)); + assertTrue(isNaN(f1(3, 2, undefined))); + assertTrue(isNaN(f1(3, undefined, 1))); +})(); + +(function CheckUint32ToInt32Conv() { + function f2(a) { + return (a >>> 0) + 1; + } + + assertEquals(1, f2(0)); + assertEquals(1, f2(0)); + %OptimizeFunctionOnNextCall(f2); + assertEquals(1, f2(0)); + assertEquals(4294967295, f2(-2)); +})(); + +(function CheckFloat64ToInt32Conv() { + function f3(a, b) { + var x = 0; + if (a) { + x = 0.5; + } + return x + b; + } + + assertEquals(1, f3(0, 1)); + assertEquals(1, f3(0, 1)); + %OptimizeFunctionOnNextCall(f3); + assertEquals(1, f3(0, 1)); + assertEquals(1.5, f3(1, 1)); +})(); + +(function ShiftLeftSmis() { + function f4(a, b) { + return a << b; + } + + assertEquals(24, f4(3, 3)); + assertEquals(40, f4(5, 3)); + %OptimizeFunctionOnNextCall(f4); + assertEquals(64, f4(4, 4)); +})(); + +(function ShiftLeftNumbers() { + function f5(a, b) { + return a << b; + } + + assertEquals(24, f5(3.3, 3.4)); + assertEquals(40, f5(5.1, 3.9)); + %OptimizeFunctionOnNextCall(f5); + assertEquals(64, f5(4.9, 4.1)); +})(); + +(function ShiftRightNumbers() { + function f6(a, b) { + return a >> b; + } + + assertEquals(1, f6(8.3, 3.4)); + assertEquals(-2, f6(-16.1, 3.9)); + %OptimizeFunctionOnNextCall(f6); + assertEquals(0, f6(16.2, 5.1)); +})(); + +(function ShiftRightLogicalNumbers() { + function f7(a, b) { + return a >>> b; + } + + assertEquals(1, f7(8.3, 3.4)); + assertEquals(536870910, f7(-16.1, 3.9)); + %OptimizeFunctionOnNextCall(f7); + assertEquals(0, f7(16.2, 5.1)); +})(); diff --git a/deps/v8/test/mjsunit/cross-realm-filtering.js b/deps/v8/test/mjsunit/cross-realm-filtering.js index 47c0d19229..8ac5b8a646 100644 --- a/deps/v8/test/mjsunit/cross-realm-filtering.js +++ b/deps/v8/test/mjsunit/cross-realm-filtering.js @@ -33,18 +33,18 @@ function assertNotIn(thrower, error) { } Realm.eval(realms[1], script); -assertSame(3, Realm.shared.error_0.length); -assertSame(4, Realm.shared.error_1.length); +assertSame(2, Realm.shared.error_0.length); +assertSame(3, Realm.shared.error_1.length); -assertTrue(Realm.shared.thrower_1 === Realm.shared.error_1[2].getFunction()); +assertTrue(Realm.shared.thrower_1 === Realm.shared.error_1[1].getFunction()); assertNotIn(Realm.shared.thrower_0, Realm.shared.error_0); assertNotIn(Realm.shared.thrower_0, Realm.shared.error_1); Realm.eval(realms[0], script); -assertSame(5, Realm.shared.error_0.length); -assertSame(4, Realm.shared.error_1.length); +assertSame(4, Realm.shared.error_0.length); +assertSame(3, Realm.shared.error_1.length); -assertTrue(Realm.shared.thrower_0 === Realm.shared.error_0[2].getFunction()); +assertTrue(Realm.shared.thrower_0 === Realm.shared.error_0[1].getFunction()); assertNotIn(Realm.shared.thrower_1, Realm.shared.error_0); assertNotIn(Realm.shared.thrower_1, Realm.shared.error_1); @@ -88,3 +88,77 @@ o = Realm.eval(realmIndex, "new f()"); proto = Object.getPrototypeOf(o); assertFalse(proto === Object.prototype); assertTrue(proto === otherObject.prototype); + +// Check function constructor. +var ctor_script = "Function"; +var ctor_a_script = + "(function() { return Function.apply(this, ['return 1;']); })"; +var ctor_b_script = "Function.bind(this, 'return 1;')"; +var ctor_c_script = + "(function() { return Function.call(this, 'return 1;'); })"; +Realm.shared = { + ctor_0 : Realm.eval(realms[0], ctor_script), + ctor_1 : Realm.eval(realms[1], ctor_script), + ctor_a_0 : Realm.eval(realms[0], ctor_a_script), + ctor_a_1 : Realm.eval(realms[1], ctor_a_script), + ctor_b_0 : Realm.eval(realms[0], ctor_b_script), + ctor_b_1 : Realm.eval(realms[1], ctor_b_script), + ctor_c_0 : Realm.eval(realms[0], ctor_c_script), + ctor_c_1 : Realm.eval(realms[1], ctor_c_script), +} +var script_0 = " \ + var ctor_0 = Realm.shared.ctor_0; \ + Realm.shared.direct_0 = ctor_0('return 1'); \ + Realm.shared.indirect_0 = (function() { return ctor_0('return 1;'); })(); \ + Realm.shared.apply_0 = ctor_0.apply(this, ['return 1']); \ + Realm.shared.bind_0 = ctor_0.bind(this, 'return 1')(); \ + Realm.shared.call_0 = ctor_0.call(this, 'return 1'); \ + Realm.shared.proxy_0 = new Proxy(ctor_0, {})('return 1'); \ + Realm.shared.reflect_0 = Reflect.apply(ctor_0, this, ['return 1']); \ + Realm.shared.a_0 = Realm.shared.ctor_a_0(); \ + Realm.shared.b_0 = Realm.shared.ctor_b_0(); \ + Realm.shared.c_0 = Realm.shared.ctor_c_0(); \ +"; +script = script_0 + script_0.replace(/_0/g, "_1"); +Realm.eval(realms[0], script); +assertSame(1, Realm.shared.direct_0()); +assertSame(1, Realm.shared.indirect_0()); +assertSame(1, Realm.shared.apply_0()); +assertSame(1, Realm.shared.bind_0()); +assertSame(1, Realm.shared.call_0()); +assertSame(1, Realm.shared.proxy_0()); +assertSame(1, Realm.shared.reflect_0()); +assertSame(1, Realm.shared.a_0()); +assertSame(1, Realm.shared.b_0()); +assertSame(1, Realm.shared.c_0()); +assertSame(undefined, Realm.shared.direct_1); +assertSame(undefined, Realm.shared.indirect_1); +assertSame(undefined, Realm.shared.apply_1); +assertSame(undefined, Realm.shared.bind_1); +assertSame(undefined, Realm.shared.call_1); +assertSame(undefined, Realm.shared.proxy_1); +assertSame(undefined, Realm.shared.reflect_1); +assertSame(undefined, Realm.shared.a_1); +assertSame(undefined, Realm.shared.b_1); +assertSame(undefined, Realm.shared.c_1); +Realm.eval(realms[1], script); +assertSame(undefined, Realm.shared.direct_0); +assertSame(undefined, Realm.shared.indirect_0); +assertSame(undefined, Realm.shared.apply_0); +assertSame(undefined, Realm.shared.bind_0); +assertSame(undefined, Realm.shared.call_0); +assertSame(undefined, Realm.shared.proxy_0); +assertSame(undefined, Realm.shared.reflect_0); +assertSame(undefined, Realm.shared.a_0); +assertSame(undefined, Realm.shared.b_0); +assertSame(undefined, Realm.shared.c_0); +assertSame(1, Realm.shared.direct_1()); +assertSame(1, Realm.shared.indirect_1()); +assertSame(1, Realm.shared.apply_1()); +assertSame(1, Realm.shared.bind_1()); +assertSame(1, Realm.shared.call_1()); +assertSame(1, Realm.shared.proxy_1()); +assertSame(1, Realm.shared.reflect_1()); +assertSame(1, Realm.shared.a_1()); +assertSame(1, Realm.shared.b_1()); +assertSame(1, Realm.shared.c_1()); diff --git a/deps/v8/test/mjsunit/debug-allscopes-on-debugger.js b/deps/v8/test/mjsunit/debug-allscopes-on-debugger.js index b7a8dff1ba..17668cfc24 100644 --- a/deps/v8/test/mjsunit/debug-allscopes-on-debugger.js +++ b/deps/v8/test/mjsunit/debug-allscopes-on-debugger.js @@ -49,10 +49,11 @@ var sum = 0; var i = 0; // Break 1. i++; // Break 2. i++; // Break 3. - return i; // Break 4. -}()); // Break 5. + debugger; // Break 4. + return i; // Break 5. +}()); // Break 6. -assertNull(exception); // Break 6. +assertNull(exception); // Break 7. assertEquals(expected_breaks, break_count); Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/debug-eval-scope.js b/deps/v8/test/mjsunit/debug-eval-scope.js new file mode 100644 index 0000000000..2b97bf65f2 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-eval-scope.js @@ -0,0 +1,144 @@ +// Copyright 2016 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 --no-always-opt + +// Test that the (strict) eval scope is visible to the debugger. + +var Debug = debug.Debug; +var exception = null; +var delegate = null; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + delegate(exec_state); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +// Current function is the top-level eval. +// We can access stack- and context-allocated values in the eval-scope. +delegate = function(exec_state) { + assertEquals([ debug.ScopeType.Eval, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + var scope = exec_state.frame(0).scope(0); + assertEquals(1, scope.scopeObject().property("a").value().value()); + assertEquals(1, exec_state.frame(0).evaluate("a").value()); + scope.setVariableValue("a", 2); + assertEquals(2, exec_state.frame(0).evaluate("a++").value()); +} + +eval("'use strict'; \n" + + "var a = 1; \n" + + "debugger; \n" + + "assertEquals(3, a);\n"); + +eval("'use strict'; \n" + + "var a = 1; \n" + + "(x=>a); \n" + // Force context-allocation. + "debugger; \n" + + "assertEquals(3, a);\n"); + +// Current function is an inner function. +// We cannot access stack-allocated values in the eval-scope. +delegate = function(exec_state) { + assertEquals([ debug.ScopeType.Local, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + assertEquals([ debug.ScopeType.Eval, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(1).allScopes().map(s => s.scopeType())); + var scope = exec_state.frame(0).scope(0); + assertThrows(() => exec_state.frame(0).evaluate("a"), ReferenceError); + assertTrue(scope.scopeObject().property("a").isUndefined()); +} + +eval("'use strict'; \n" + + "var a = 1; \n" + + "(() => {debugger})()\n"); + +// Current function is an escaped inner function. +delegate = function(exec_state) { + assertEquals([ debug.ScopeType.Local, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + assertEquals([ debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(1).allScopes().map(s => s.scopeType())); + var scope = exec_state.frame(0).scope(0); + assertThrows(() => exec_state.frame(0).evaluate("a"), ReferenceError); + assertTrue(scope.scopeObject().property("a").isUndefined()); +} + +var f = eval("'use strict'; \n" + + "var a = 1; \n" + + "() => {debugger}\n"); +f(); + +// Current function is an inner function. +// We can access context-allocated values in the eval-scope. +delegate = function(exec_state) { + assertEquals([ debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + assertEquals([ debug.ScopeType.Eval, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(1).allScopes().map(s => s.scopeType())); + var scope = exec_state.frame(1).scope(0); + assertEquals(1, scope.scopeObject().property("a").value().value()); + assertEquals(1, exec_state.frame(1).evaluate("a").value()); + assertEquals(1, exec_state.frame(0).evaluate("a").value()); + scope.setVariableValue("a", 2); + assertEquals(2, exec_state.frame(0).evaluate("a++").value()); + assertEquals(3, exec_state.frame(1).evaluate("a++").value()); +} + +eval("'use strict'; \n" + + "var a = 1; \n" + + "(() => { a; \n" + // Force context-allocation. + " debugger; \n" + + " assertEquals(4, a);\n" + + " })(); \n" + ); + +// Current function is an escaped inner function. +// We can access context-allocated values in the eval-scope. +delegate = function(exec_state) { + assertEquals([ debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + assertEquals([ debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(1).allScopes().map(s => s.scopeType())); + var scope = exec_state.frame(0).scope(1); + assertEquals(1, scope.scopeObject().property("a").value().value()); + assertEquals(1, exec_state.frame(0).evaluate("a").value()); + scope.setVariableValue("a", 2); + assertEquals(2, exec_state.frame(0).evaluate("a++").value()); +} + +var g = eval("'use strict'; \n" + + "var a = 1; \n" + + "() => { a; \n" + + " debugger; \n" + + " assertEquals(3, a);\n" + + " } \n"); +g(); + +Debug.setListener(null); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/debug-evaluate-nested.js b/deps/v8/test/mjsunit/debug-evaluate-nested.js index da11b9001c..965b5a7aa5 100644 --- a/deps/v8/test/mjsunit/debug-evaluate-nested.js +++ b/deps/v8/test/mjsunit/debug-evaluate-nested.js @@ -34,7 +34,7 @@ function listener(event, exec_state, event_data, data) { exec_state.frame(0).evaluate("debugger;"); } else { checkScopes(exec_state.frame(0).allScopes(), - [ ScopeType.With, ScopeType.Closure, + [ ScopeType.Eval, ScopeType.With, ScopeType.Closure, ScopeType.Script, ScopeType.Global ]); } } catch (e) { diff --git a/deps/v8/test/mjsunit/debug-evaluate-shadowed-context-2.js b/deps/v8/test/mjsunit/debug-evaluate-shadowed-context-2.js new file mode 100644 index 0000000000..59352e06a5 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-evaluate-shadowed-context-2.js @@ -0,0 +1,41 @@ +// Copyright 2016 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 --no-analyze-environment-liveness + +// Test that debug-evaluate correctly collects free outer variables +// and does not get confused by variables in nested scopes. + +Debug = debug.Debug + +var exception = null; +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertThrows(() => exec_state.frame(0).evaluate("x").value()); + } catch (e) { + exception = e; + print(e + e.stack); + } +} + +Debug.setListener(listener); + +(function() { + var x = 1; // context allocate x + (() => x); + (function() { + var x = 2; // stack allocate shadowing x + (function() { + { // context allocate x in a nested scope + let x = 3; + (() => x); + } + debugger; + })(); + })(); +})(); + +Debug.setListener(null); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/debug-exceptions.js b/deps/v8/test/mjsunit/debug-exceptions.js new file mode 100644 index 0000000000..1a0e222d51 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-exceptions.js @@ -0,0 +1,88 @@ +// Copyright 2016 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 + + +Debug = debug.Debug + +let error = false; +let uncaught; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + uncaught = event_data.uncaught(); + } catch (e) { + error = true; + } +} + +Debug.setBreakOnException(); +Debug.setListener(listener); + + +function assertCaught(f) { + try {f()} finally { + assertFalse(uncaught); + return; + } +} + +function assertUncaught(f) { + try {f()} finally { + assertTrue(uncaught); + return; + } +} + + +assertUncaught(() => { + for (var a of [1, 2, 3]) { + throw a + } +}); + +assertUncaught(() => { + for (var a of [1, 2, 3]) { + try {throw a} finally {} + } +}); + +assertCaught(() => { + for (var a of [1, 2, 3]) { + try { + try {throw a} finally {} + } catch(_) {} + } +}); + +assertCaught(() => { + try { + for (var a of [1, 2, 3]) { + try {throw a} finally {} + } + } catch(_) {} +}); + + +// Check that an internal exception in our yield* desugaring is not observable. +{ + uncaught = null; + + let iter = { + next() {return {value:42, done:false}}, + throw() {return {done:true}} + }; + let iterable = {[Symbol.iterator]() {return iter}}; + function* f() { yield* iterable } + + let g = f(); + g.next(); + assertEquals({value: undefined, done: true}, g.throw()); + assertNull(uncaught); // No exception event was generated. +} + + +assertFalse(error); diff --git a/deps/v8/test/mjsunit/debug-function-scopes.js b/deps/v8/test/mjsunit/debug-function-scopes.js index f63d7b26c8..ae95f9b97d 100644 --- a/deps/v8/test/mjsunit/debug-function-scopes.js +++ b/deps/v8/test/mjsunit/debug-function-scopes.js @@ -42,14 +42,7 @@ function CheckScope(scope_mirror, scope_expectations, expected_scope_type) { } } -// A copy of the scope types from debug/mirrors.js. -var ScopeType = { Global: 0, - Local: 1, - With: 2, - Closure: 3, - Catch: 4, - Block: 5, - Script: 6}; +var ScopeType = debug.ScopeType; var f1 = (function F1(x) { function F2(y) { @@ -162,6 +155,3 @@ function CheckNoScopeVisible(f) { CheckNoScopeVisible(Number); CheckNoScopeVisible(Function.toString); - -// This getter is known to be implemented as closure. -CheckNoScopeVisible(new Error().__lookupGetter__("stack")); diff --git a/deps/v8/test/mjsunit/debug-generator-break-on-stack.js b/deps/v8/test/mjsunit/debug-generator-break-on-stack.js new file mode 100644 index 0000000000..5a1a9c56c1 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-generator-break-on-stack.js @@ -0,0 +1,46 @@ +// Copyright 2016 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 break_count = 0; +var exception = null; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + break_count++; + var line = exec_state.frame(0).sourceLineText(); + print(line); + assertTrue(line.indexOf(`B${break_count}`) > 0); + } catch (e) { + exception = e; + } +} + + +function* g() { + setbreaks(); + yield 1; // B1 +} + +function* f() { + yield* g(); + return 2; // B2 +} + +function setbreaks() { + Debug.setListener(listener); + Debug.setBreakPoint(g, 2); + Debug.setBreakPoint(f, 2); +} + +for (let _ of f()) { } + +assertEquals(2, break_count); +assertNull(exception); + +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/debug-generator-break.js b/deps/v8/test/mjsunit/debug-generator-break.js new file mode 100644 index 0000000000..34ed82c376 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-generator-break.js @@ -0,0 +1,44 @@ +// Copyright 2016 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 break_count = 0; +var exception = null; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + break_count++; + var line = exec_state.frame(0).sourceLineText(); + assertTrue(line.indexOf(`B${break_count}`) > 0); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +function* g() { + yield 1; +} + +function* f() { + yield* g(); // B1 + assertEquals(2, break_count); // B2 + return 1; // B3 +} + +Debug.setBreakPoint(f, 1); +Debug.setBreakPoint(f, 2); +Debug.setBreakPoint(f, 3); + +for (let _ of f()) { } + +assertEquals(3, break_count); +assertNull(exception); + +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/debug-handle.js b/deps/v8/test/mjsunit/debug-handle.js index 1582b9f121..ca02592542 100644 --- a/deps/v8/test/mjsunit/debug-handle.js +++ b/deps/v8/test/mjsunit/debug-handle.js @@ -108,7 +108,7 @@ function listener(event, exec_state, event_data, data) { var handle_a = evaluateRequest(exec_state, '{"expression":"b","frame":1}'); assertEquals(handle_o, handle_a); assertEquals(handle_a, handle_b); - assertFalse(handle_o == handle_p, "o and p have he same handle"); + assertFalse(handle_o == handle_p, "o and p have the same handle"); var response; var count; @@ -140,7 +140,7 @@ function listener(event, exec_state, event_data, data) { var handle_g = evaluateRequest(exec_state, '{"expression":"g"}'); var handle_caller = evaluateRequest(exec_state, '{"expression":"f.caller"}'); - assertFalse(handle_f == handle_g, "f and g have he same handle"); + assertFalse(handle_f == handle_g, "f and g have the same handle"); assertEquals(handle_g, handle_caller, "caller for f should be g"); response = lookupRequest(exec_state, '{"handles":[' + handle_f + ']}', true); diff --git a/deps/v8/test/mjsunit/debug-liveedit-exceptions.js b/deps/v8/test/mjsunit/debug-liveedit-exceptions.js new file mode 100644 index 0000000000..28ec01dbad --- /dev/null +++ b/deps/v8/test/mjsunit/debug-liveedit-exceptions.js @@ -0,0 +1,67 @@ +// Copyright 2016 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 + +Debug = debug.Debug + +function BestEditor() { + throw 'Emacs'; +} + +var exception = null; +var results = []; +var log = [] + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + var source_line = event_data.sourceLineText(); + print(source_line); + log.push(source_line); + switch (results.length) { + case 0: + Replace(BestEditor, "Emacs", "Eclipse"); + break; + case 1: + Replace(BestEditor, "Eclipse", "Vim"); + break; + case 2: + break; + default: + assertUnreachable(); + } + } catch (e) { + exception = e; + } +}; + +function Replace(fun, original, patch) { + var script = Debug.findScript(fun); + if (fun.toString().indexOf(original) < 0) return; + var patch_pos = script.source.indexOf(original); + var change_log = []; + Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, original.length, patch, change_log); +} + +Debug.setListener(listener); +Debug.setBreakOnException(); + +for (var i = 0; i < 3; i++) { + try { + BestEditor(); + } catch (e) { + results.push(e); + } +} +Debug.setListener(null); + +assertNull(exception); +assertEquals(["Emacs", "Eclipse", "Vim"], results); +print(JSON.stringify(log, 1)); +assertEquals([ + " throw 'Emacs';", + " throw 'Eclipse';", + " throw 'Vim';", +], log); diff --git a/deps/v8/test/mjsunit/debug-liveedit-patch-positions.js b/deps/v8/test/mjsunit/debug-liveedit-patch-positions.js deleted file mode 100644 index c669b5e862..0000000000 --- a/deps/v8/test/mjsunit/debug-liveedit-patch-positions.js +++ /dev/null @@ -1,129 +0,0 @@ -// 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: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Flags: --expose-debug-as debug -// Get the Debug object exposed from the debug context global object. - -// Scenario: some function is being edited; the outer function has to have its -// positions patched. Accoring to a special markup of function text -// corresponding byte-code PCs should coincide before change and after it. - -Debug = debug.Debug -Debug.setListener(function() {}); - -eval( - "function F1() { return 5; }\n" + - "function ChooseAnimal(/*$*/ ) {\n" + - "/*$*/ var x = F1(/*$*/ );\n" + - "/*$*/ var res/*$*/ =/*$*/ (function() { return 'Cat'; } )();\n" + - "/*$*/ var y/*$*/ = F2(/*$*/ F1()/*$*/ , F1(/*$*/ )/*$*/ );\n" + - "/*$*/ if (/*$*/ x.toString(/*$*/ )) { /*$*/ y = 3;/*$*/ } else {/*$*/ y = 8;/*$*/ }\n" + - "/*$*/ var z = /*$*/ x * y;\n" + - "/*$*/ return/*$*/ res/*$*/ + z;/*$*/ }\n" + - "function F2(x, y) { return x + y; }" -); - -// Find all *$* markers in text of the function and read corresponding statement -// PCs. -function ReadMarkerPositions(func) { - var text = func.toString(); - var positions = new Array(); - var match; - var pattern = /\/\*\$\*\//g; - while ((match = pattern.exec(text)) != null) { - positions.push(match.index); - } - return positions; -} - -function ReadPCMap(func, positions) { - var res = new Array(); - for (var i = 0; i < positions.length; i++) { - var pc = Debug.LiveEdit.GetPcFromSourcePos(func, positions[i]); - - if (typeof pc === 'undefined') { - // Function was marked for recompilation and it's code was replaced with a - // stub. This can happen at any time especially if we are running with - // --stress-opt. There is no way to get PCs now. - return; - } - - res.push(pc); - } - - return res; -} - -function ApplyPatch(orig_animal, new_animal) { - var res = ChooseAnimal(); - assertEquals(orig_animal + "15", res); - - var script = Debug.findScript(ChooseAnimal); - - var orig_string = "'" + orig_animal + "'"; - var patch_string = "'" + new_animal + "'"; - var patch_pos = script.source.indexOf(orig_string); - - var change_log = new Array(); - - Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, - patch_pos, - orig_string.length, - patch_string, - change_log); - - print("Change log: " + JSON.stringify(change_log) + "\n"); - - var markerPositions = ReadMarkerPositions(ChooseAnimal); - var pcArray = ReadPCMap(ChooseAnimal, markerPositions); - - var res = ChooseAnimal(); - assertEquals(new_animal + "15", res); - - return pcArray; -} - -var pcArray1 = ApplyPatch('Cat', 'Dog'); - -// When we patched function for the first time it was deoptimized. -// Check that after the second patch maping between sources position and -// pcs will not change. - -var pcArray2 = ApplyPatch('Dog', 'Capybara'); - -print(pcArray1); -print(pcArray2); - -// Function can be marked for recompilation at any point (especially if we are -// running with --stress-opt). When we mark function for recompilation we -// replace it's code with stub. So there is no reliable way to get PCs for -// function. -if (pcArray1 && pcArray2) { - assertArrayEquals(pcArray1, pcArray2); -} - -Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/debug-liveedit-stepin.js b/deps/v8/test/mjsunit/debug-liveedit-stepin.js index 601a66f93d..c6070ce284 100644 --- a/deps/v8/test/mjsunit/debug-liveedit-stepin.js +++ b/deps/v8/test/mjsunit/debug-liveedit-stepin.js @@ -7,8 +7,7 @@ Debug = debug.Debug function BestEditor() { - var best_editor = "Emacs"; - return best_editor; + return 'Emacs'; } var exception = null; @@ -62,20 +61,15 @@ print(JSON.stringify(log, 1)); assertEquals([ "debugger;", "results.push(BestEditor());", - " var best_editor = \"Emacs\";", - " return best_editor;","}", + " return 'Emacs';","}", "results.push(BestEditor());", "results.push(BestEditor());", - " var best_editor = \"Emacs\";", - " return best_editor;", - " var best_editor = \"Eclipse\";", - " return best_editor;","}", + " return 'Emacs';", + " return 'Eclipse';","}", "results.push(BestEditor());", "results.push(BestEditor());", - " var best_editor = \"Eclipse\";", - " return best_editor;", - " var best_editor = \"Vim\";", - " return best_editor;", + " return 'Eclipse';", + " return 'Vim';", "}","results.push(BestEditor());", "Debug.setListener(null);" ], log); diff --git a/deps/v8/test/mjsunit/debug-scopes-suspended-generators.js b/deps/v8/test/mjsunit/debug-scopes-suspended-generators.js new file mode 100644 index 0000000000..f4750b7f76 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-scopes-suspended-generators.js @@ -0,0 +1,470 @@ +// Copyright 2016 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 --ignition +// The functions used for testing backtraces. They are at the top to make the +// testing of source line/column easier. + +// Get the Debug object exposed from the debug context global object. +var Debug = debug.Debug; + +var test_name; +var exception; +var begin_test_count = 0; +var end_test_count = 0; + +// Initialize for a new test. +function BeginTest(name) { + test_name = name; + exception = null; + begin_test_count++; +} + +// Check result of a test. +function EndTest() { + assertNull(exception, test_name + " / " + exception); + end_test_count++; +} + +// Check that two scope are the same. +function assertScopeMirrorEquals(scope1, scope2) { + assertEquals(scope1.scopeType(), scope2.scopeType()); + assertEquals(scope1.frameIndex(), scope2.frameIndex()); + assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); + assertPropertiesEqual(scope1.scopeObject().value(), + scope2.scopeObject().value()); +} + +// Check that the scope chain contains the expected types of scopes. +function CheckScopeChain(scopes, gen_mirror) { + var all_scopes = gen_mirror.allScopes(); + assertEquals(scopes.length, gen_mirror.scopeCount()); + assertEquals(scopes.length, all_scopes.length, + "FrameMirror.allScopes length"); + for (var i = 0; i < scopes.length; i++) { + var scope = gen_mirror.scope(i); + assertTrue(scope.isScope()); + assertEquals(scopes[i], scope.scopeType(), + `Scope ${i} has unexpected type`); + assertScopeMirrorEquals(all_scopes[i], scope); + + // Check the global object when hitting the global scope. + if (scopes[i] == debug.ScopeType.Global) { + // Objects don't have same class (one is "global", other is "Object", + // so just check the properties directly. + assertPropertiesEqual(this, scope.scopeObject().value()); + } + } +} + +// Check that the content of the scope is as expected. For functions just check +// that there is a function. +function CheckScopeContent(content, number, gen_mirror) { + var scope = gen_mirror.scope(number); + var count = 0; + for (var p in content) { + var property_mirror = scope.scopeObject().property(p); + assertFalse(property_mirror.isUndefined(), + 'property ' + p + ' not found in scope'); + if (typeof(content[p]) === 'function') { + assertTrue(property_mirror.value().isFunction()); + } else { + assertEquals(content[p], property_mirror.value().value(), + 'property ' + p + ' has unexpected value'); + } + count++; + } + + // 'arguments' and might be exposed in the local and closure scope. Just + // ignore this. + var scope_size = scope.scopeObject().properties().length; + if (!scope.scopeObject().property('arguments').isUndefined()) { + scope_size--; + } + // Ditto for 'this'. + if (!scope.scopeObject().property('this').isUndefined()) { + scope_size--; + } + // Temporary variables introduced by the parser have not been materialized. + assertTrue(scope.scopeObject().property('').isUndefined()); + + if (count != scope_size) { + print('Names found in scope:'); + var names = scope.scopeObject().propertyNames(); + for (var i = 0; i < names.length; i++) { + print(names[i]); + } + } + assertEquals(count, scope_size); +} + +// Simple empty closure scope. + +function *gen1() { + yield 1; + return 2; +} + +var g = gen1(); +var gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({}, 0, gm); + +// Closure scope with a parameter. + +function *gen2(a) { + yield a; + return 2; +} + +g = gen2(42); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 42}, 0, gm); + +// Closure scope with a parameter. + +function *gen3(a) { + var b = 1 + yield a; + return b; +} + +g = gen3(0); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 0, b: undefined}, 0, gm); + +g.next(); // Create b. +CheckScopeContent({a: 0, b: 1}, 0, gm); + +// Closure scope with a parameter. + +function *gen4(a, b) { + var x = 2; + yield a; + var y = 3; + return b; +} + +g = gen4(0, 1); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 0, b: 1, x: undefined, y: undefined}, 0, gm); + +g.next(); // Create x. +CheckScopeContent({a: 0, b: 1, x: 2, y: undefined}, 0, gm); + +g.next(); // Create y. +CheckScopeContent({a: 0, b: 1, x: 2, y: 3}, 0, gm); + +// Closure introducing local variable using eval. + +function *gen5(a) { + eval('var b = 2'); + return b; +} + +g = gen5(1); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 1, b: 2}, 0, gm); + +// Single empty with block. + +function *gen6() { + with({}) { + yield 1; + } + yield 2; + return 3; +} + +g = gen6(); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.With, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({}, 0, gm); + +g.next(); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); + +// Nested empty with blocks. + +function *gen7() { + with({}) { + with({}) { + yield 1; + } + yield 2; + } + return 3; +} + +g = gen7(); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.With, + debug.ScopeType.With, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({}, 0, gm); + +// Nested with blocks using in-place object literals. + +function *gen8() { + with({a: 1,b: 2}) { + with({a: 2,b: 1}) { + yield a; + } + yield a; + } + return 3; +} + +g = gen8(); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.With, + debug.ScopeType.With, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 2, b: 1}, 0, gm); + +g.next(); +CheckScopeContent({a: 1, b: 2}, 0, gm); + +// Catch block. + +function *gen9() { + try { + throw 42; + } catch (e) { + yield e; + } + return 3; +} + +g = gen9(); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({e: 42}, 0, gm); + +// For statement with block scope. + +function *gen10() { + for (let i = 0; i < 42; i++) yield i; + return 3; +} + +g = gen10(); +g.next(); +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Block, + debug.ScopeType.Block, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({i: 0}, 0, gm); + +g.next(); +CheckScopeContent({i: 1}, 0, gm); +CheckScopeContent({i: 0}, 1, gm); // Additional block scope with i = 0; + +// Nested generators. + +var gen12; +function *gen11() { + gen12 = function*() { + var a = 1; + yield 1; + return 2; + }(); + + var a = 0; + yield* gen12; +} + +g = gen11(); +g.next(); + +gm = debug.MakeMirror(gen12); +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 1}, 0, gm); +CheckScopeContent({a: 0}, 1, gm); + +// Set a variable in an empty scope. + +function *gen13() { + yield 1; + return 2; +} + +var g = gen13(); +var gm = debug.MakeMirror(g); +assertThrows(() => gm.scope(0).setVariableValue("a", 42)); +CheckScopeContent({}, 0, gm); + +// Set a variable in a simple scope. + +function *gen14() { + var a = 0; + yield 1; + yield a; + return 2; +} + +var g = gen14(); +assertEquals(1, g.next().value); + +var gm = debug.MakeMirror(g); +CheckScopeContent({a: 0}, 0, gm); + +gm.scope(0).setVariableValue("a", 1); +CheckScopeContent({a: 1}, 0, gm); + +assertEquals(1, g.next().value); + +// Set a variable in nested with blocks using in-place object literals. + +function *gen15() { + var c = 3; + with({a: 1,b: 2}) { + var d = 4; + yield a; + var e = 5; + } + yield e; + return e; +} + +var g = gen15(); +assertEquals(1, g.next().value); + +var gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.With, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({a: 1, b: 2}, 0, gm); +CheckScopeContent({c: 3, d: 4, e: undefined}, 1, gm); + +// Variables don't exist in given scope. +assertThrows(() => gm.scope(0).setVariableValue("c", 42)); +assertThrows(() => gm.scope(1).setVariableValue("a", 42)); + +// Variables in with scope are immutable. +assertThrows(() => gm.scope(0).setVariableValue("a", 3)); +assertThrows(() => gm.scope(0).setVariableValue("b", 3)); + +gm.scope(1).setVariableValue("c", 1); +gm.scope(1).setVariableValue("e", 42); + +CheckScopeContent({a: 1, b: 2}, 0, gm); +CheckScopeContent({c: 1, d: 4, e: 42}, 1, gm); +assertEquals(5, g.next().value); // Initialized after set. + +CheckScopeChain([debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); + +gm.scope(0).setVariableValue("e", 42); + +CheckScopeContent({c: 1, d: 4, e: 42}, 0, gm); +assertEquals(42, g.next().value); + +// Set a variable in nested with blocks using in-place object literals plus a +// nested block scope. + +function *gen16() { + var c = 3; + with({a: 1,b: 2}) { + let d = 4; + yield a; + let e = 5; + yield d; + } + return 3; +} + +var g = gen16(); +g.next(); + +var gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Block, + debug.ScopeType.With, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({d: 4}, 0, gm); +CheckScopeContent({a: 1, b: 2}, 1, gm); +CheckScopeContent({c: 3}, 2, gm); + +gm.scope(0).setVariableValue("d", 1); +CheckScopeContent({d: 1}, 0, gm); + +assertEquals(1, g.next().value); + +// Set variable in catch block. + +var yyzyzzyz = 4829; +let xxxyyxxyx = 42284; +function *gen17() { + try { + throw 42; + } catch (e) { + yield e; + yield e; + } + return 3; +} + +g = gen17(); +g.next(); + +gm = debug.MakeMirror(g); +CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], gm); +CheckScopeContent({e: 42}, 0, gm); +CheckScopeContent({xxxyyxxyx: 42284}, 2, gm); + +gm.scope(0).setVariableValue("e", 1); +CheckScopeContent({e: 1}, 0, gm); + +assertEquals(1, g.next().value); + +// Script scope. +gm.scope(2).setVariableValue("xxxyyxxyx", 42); +assertEquals(42, xxxyyxxyx); + +// Global scope. +assertThrows(() => gm.scope(3).setVariableValue("yyzyzzyz", 42)); +assertEquals(4829, yyzyzzyz); diff --git a/deps/v8/test/mjsunit/debug-scopes.js b/deps/v8/test/mjsunit/debug-scopes.js index 3659d4e129..935de9cc98 100644 --- a/deps/v8/test/mjsunit/debug-scopes.js +++ b/deps/v8/test/mjsunit/debug-scopes.js @@ -183,10 +183,8 @@ function CheckScopeContent(content, number, exec_state) { if (!scope.scopeObject().property('this').isUndefined()) { scope_size--; } - // Skip property with empty name. - if (!scope.scopeObject().property('').isUndefined()) { - scope_size--; - } + // Temporary variables introduced by the parser have not been materialized. + assertTrue(scope.scopeObject().property('').isUndefined()); if (count != scope_size) { print('Names found in scope:'); @@ -1179,11 +1177,10 @@ var code3 = "function for_statement() { \n" + listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); - CheckScopeChainPositions([{start: 52, end: 111}, {start: 42, end: 111}, {start: 22, end: 145}, {}, {}], exec_state); + CheckScopeChainPositions([{start: 52, end: 111}, {start: 22, end: 145}, {}, {}], exec_state); } eval(code3); EndTest(); diff --git a/deps/v8/test/mjsunit/debug-script.js b/deps/v8/test/mjsunit/debug-script.js index 5396415087..3bedb74a35 100644 --- a/deps/v8/test/mjsunit/debug-script.js +++ b/deps/v8/test/mjsunit/debug-script.js @@ -84,11 +84,6 @@ var math_script = Debug.findScript('native math.js'); assertEquals('native math.js', math_script.name); assertEquals(Debug.ScriptType.Native, math_script.type); -// Test a builtins delay loaded script. -var date_delay_script = Debug.findScript('native json.js'); -assertEquals('native json.js', date_delay_script.name); -assertEquals(Debug.ScriptType.Native, date_delay_script.type); - // Test a debugger script. var debug_delay_script = Debug.findScript('native debug.js'); assertEquals('native debug.js', debug_delay_script.name); diff --git a/deps/v8/test/mjsunit/debug-sourceinfo.js b/deps/v8/test/mjsunit/debug-sourceinfo.js index cb41107c60..b79fb8e3ec 100644 --- a/deps/v8/test/mjsunit/debug-sourceinfo.js +++ b/deps/v8/test/mjsunit/debug-sourceinfo.js @@ -63,12 +63,11 @@ var comment_lines = 28; // This is the last position in the entire file (note: this equals // file size of <debug-sourceinfo.js> - 1, since starting at 0). -var last_position = 11519; +var last_position = 8126; // This is the last line of entire file (note: starting at 0). -var last_line = 269; -// This is the last column of last line (note: starting at 0 and +1, due -// to trailing <LF>). -var last_column = 1; +var last_line = 200; +// This is the last column of last line (note: starting at 0). +var last_column = 71; // This magic number is the length or the first line comment (actually number // of characters before 'function a(...'. @@ -168,66 +167,6 @@ assertEquals(start_d, script.locationFromPosition(start_d).position); assertEquals(11, script.locationFromPosition(start_d).line - comment_lines); assertEquals(10, script.locationFromPosition(start_d).column); -// Test first line. -assertEquals(0, script.locationFromLine().position); -assertEquals(0, script.locationFromLine().line); -assertEquals(0, script.locationFromLine().column); -assertEquals(0, script.locationFromLine(0).position); -assertEquals(0, script.locationFromLine(0).line); -assertEquals(0, script.locationFromLine(0).column); - -// Test first line column 1. -assertEquals(1, script.locationFromLine(0, 1).position); -assertEquals(0, script.locationFromLine(0, 1).line); -assertEquals(1, script.locationFromLine(0, 1).column); - -// Test first line offset 1. -assertEquals(1, script.locationFromLine(0, 0, 1).position); -assertEquals(0, script.locationFromLine(0, 0, 1).line); -assertEquals(1, script.locationFromLine(0, 0, 1).column); - -// Test offset function a(). -assertEquals(start_a, script.locationFromLine(void 0, void 0, start_a).position); -assertEquals(0, script.locationFromLine(void 0, void 0, start_a).line - comment_lines); -assertEquals(10, script.locationFromLine(void 0, void 0, start_a).column); -assertEquals(start_a, script.locationFromLine(0, void 0, start_a).position); -assertEquals(0, script.locationFromLine(0, void 0, start_a).line - comment_lines); -assertEquals(10, script.locationFromLine(0, void 0, start_a).column); -assertEquals(start_a, script.locationFromLine(0, 0, start_a).position); -assertEquals(0, script.locationFromLine(0, 0, start_a).line - comment_lines); -assertEquals(10, script.locationFromLine(0, 0, start_a).column); - -// Test second line offset function a(). -assertEquals(start_a + 13, script.locationFromLine(1, 0, start_a).position); -assertEquals(1, script.locationFromLine(1, 0, start_a).line - comment_lines); -assertEquals(0, script.locationFromLine(1, 0, start_a).column); - -// Test second line column 2 offset function a(). -assertEquals(start_a + 13 + 1, script.locationFromLine(1, 1, start_a).position); -assertEquals(1, script.locationFromLine(1, 2, start_a).line - comment_lines); -assertEquals(2, script.locationFromLine(1, 2, start_a).column); - -// Test offset function b(). -assertEquals(start_b, script.locationFromLine(0, 0, start_b).position); -assertEquals(1, script.locationFromLine(0, 0, start_b).line - comment_lines); -assertEquals(13, script.locationFromLine(0, 0, start_b).column); - -// Test second line offset function b(). -assertEquals(start_b + 5, script.locationFromLine(1, 0, start_b).position); -assertEquals(2, script.locationFromLine(1, 0, start_b).line - comment_lines); -assertEquals(0, script.locationFromLine(1, 0, start_b).column); - -// Test second line column 10 offset function b(). -assertEquals(start_b + 5 + 10, script.locationFromLine(1, 10, start_b).position); -assertEquals(2, script.locationFromLine(1, 10, start_b).line - comment_lines); -assertEquals(10, script.locationFromLine(1, 10, start_b).column); - -// Test second line column 11 offset function b. Second line in b is 10 long -// using column 11 wraps to next line. -assertEquals(start_b + 5 + 11, script.locationFromLine(1, 11, start_b).position); -assertEquals(3, script.locationFromLine(1, 11, start_b).line - comment_lines); -assertEquals(0, script.locationFromLine(1, 11, start_b).column); - // Test the Debug.findSourcePosition which wraps SourceManager. assertEquals(0 + start_a, Debug.findFunctionSourceLocation(a, 0, 0).position); assertEquals(0 + start_b, Debug.findFunctionSourceLocation(b, 0, 0).position); @@ -260,11 +199,3 @@ assertEquals(last_column, script.locationFromPosition(last_position).column); assertEquals(last_line + 1, script.locationFromPosition(last_position + 1).line); assertEquals(0, script.locationFromPosition(last_position + 1).column); - -// Test that script.sourceLine(line) works. -var location; - -for (line = 0; line < num_lines_d; line++) { - var line_content_regexp = new RegExp(" x = " + (line + 1)); - assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); -} diff --git a/deps/v8/test/mjsunit/debug-sourceslice.js b/deps/v8/test/mjsunit/debug-sourceslice.js deleted file mode 100644 index db9a3e7da8..0000000000 --- a/deps/v8/test/mjsunit/debug-sourceslice.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Flags: --expose-debug-as debug -// Source lines for test. -var lines = [ 'function a() { b(); };\n', - 'function b() {\n', - ' c(true);\n', - '};\n', - ' function c(x) {\n', - ' if (x) {\n', - ' return 1;\n', - ' } else {\n', - ' return 1;\n', - ' }\n', - ' };\n' ]; - -// Build source by putting all lines together -var source = ''; -for (var i = 0; i < lines.length; i++) { - source += lines[i]; -} -eval(source); - -// Flags: --expose-debug-as debug -// Get the Debug object exposed from the debug context global object. -Debug = debug.Debug - -// Get the script object from one of the functions in the source. -var script = Debug.findScript(a); - -// Make sure that the source is as expected. -assertEquals(source, script.source); -assertEquals(source, script.sourceSlice().sourceText()); - -// Try all possible line interval slices. -for (var slice_size = 0; slice_size < lines.length; slice_size++) { - for (var n = 0; n < lines.length - slice_size; n++) { - var slice = script.sourceSlice(n, n + slice_size); - assertEquals(n, slice.from_line); - assertEquals(n + slice_size, slice.to_line); - - var text = slice.sourceText(); - var expected = ''; - for (var i = 0; i < slice_size; i++) { - expected += lines[n + i]; - } - assertEquals(expected, text); - } -} diff --git a/deps/v8/test/mjsunit/debug-stack-check-position.js b/deps/v8/test/mjsunit/debug-stack-check-position.js new file mode 100644 index 0000000000..a5570ce904 --- /dev/null +++ b/deps/v8/test/mjsunit/debug-stack-check-position.js @@ -0,0 +1,30 @@ +// Copyright 2016 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 + +var Debug = debug.Debug; +var exception = null; +var loop = true; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertTrue(exec_state.frame(0).sourceLineText().indexOf("BREAK") > 0); + } catch (e) { + exception = e; + } +} + +function f() { // BREAK + return 1; +} + +Debug.setListener(listener); + +%ScheduleBreak(); // Break on function entry. +f(); + +Debug.setListener(null); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/delete.js b/deps/v8/test/mjsunit/delete.js index 8d4636af45..20fa6bfb67 100644 --- a/deps/v8/test/mjsunit/delete.js +++ b/deps/v8/test/mjsunit/delete.js @@ -178,3 +178,17 @@ function load_a(x) { } load_deleted_property_using_IC(); + + +(function deleteLargeDoubleArrayAtEnd() { + var o = {}; + var max = 100000; + for (var i = 0; i <= max; i++) { + o[i] = 1.1; + } + delete o[max]; + for (var i = 0; i < max; i++) { + assertEquals(1.1, o[i]); + } + assertEquals(undefined, o[max]); +})(); diff --git a/deps/v8/test/mjsunit/dictionary-properties.js b/deps/v8/test/mjsunit/dictionary-properties.js index 0659268bac..33360d7f52 100644 --- a/deps/v8/test/mjsunit/dictionary-properties.js +++ b/deps/v8/test/mjsunit/dictionary-properties.js @@ -39,7 +39,13 @@ function SlowPrototype() { SlowPrototype.prototype.bar = 2; SlowPrototype.prototype.baz = 3; delete SlowPrototype.prototype.baz; -new SlowPrototype; +assertFalse(%HasFastProperties(SlowPrototype.prototype)); +var slow_proto = new SlowPrototype; +// ICs make prototypes fast. +function ic() { return slow_proto.bar; } +ic(); +ic(); +assertTrue(%HasFastProperties(slow_proto.__proto__)); // Prototypes stay fast even after deleting properties. assertTrue(%HasFastProperties(SlowPrototype.prototype)); diff --git a/deps/v8/test/mjsunit/double-intrinsics.js b/deps/v8/test/mjsunit/double-intrinsics.js deleted file mode 100644 index 16d6538937..0000000000 --- a/deps/v8/test/mjsunit/double-intrinsics.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 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 assertDoubleBits(hi, lo, x) { - hi = hi | 0; - lo = lo | 0; - assertEquals(x, %_ConstructDouble(hi, lo)); - assertEquals(hi, %_DoubleHi(x)); - assertEquals(lo, %_DoubleLo(x)); - assertEquals(x, %_ConstructDouble(%_DoubleHi(x), %_DoubleLo(x))); -} - - -var tests = [0x7ff00000, 0x00000000, Infinity, - 0xfff00000, 0x00000000, -Infinity, - 0x80000000, 0x00000000, -0, - 0x400921fb, 0x54442d18, Math.PI, - 0xc00921fb, 0x54442d18, -Math.PI, - 0x4005bf0a, 0x8b145769, Math.E, - 0xc005bf0a, 0x8b145769, -Math.E, - 0xbfe80000, 0x00000000, -0.75]; - - -for (var i = 0; i < tests.length; i += 3) { - assertDoubleBits(tests[i], tests[i + 1], tests[i + 2]); -} - -%OptimizeFunctionOnNextCall(assertDoubleBits); - -for (var i = 0; i < tests.length; i += 3) { - assertDoubleBits(tests[i], tests[i + 1], tests[i + 2]); - assertOptimized(assertDoubleBits); -} diff --git a/deps/v8/test/mjsunit/eagerly-parsed-lazily-compiled-functions.js b/deps/v8/test/mjsunit/eagerly-parsed-lazily-compiled-functions.js new file mode 100644 index 0000000000..edc14430ea --- /dev/null +++ b/deps/v8/test/mjsunit/eagerly-parsed-lazily-compiled-functions.js @@ -0,0 +1,33 @@ +// Copyright 2016 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: --min-preparse-length=0 + +// The test functions in this file will be eagerly compiled. The functions +// inside will be eagerly parsed but lazily compiled. + +(function TestLengths() { + function inner(p1, p2, p3) { } + assertEquals(3, inner.length); +})(); + +(function TestAccessingContextVariables() { + var in_context = 8; + function inner() { return in_context; } + assertEquals(8, inner()); +})(); + +(function TestAccessingContextVariablesFromDeeper() { + var in_context = 8; + function inner() { + function inner_inner() { + function inner_inner_inner() { + return in_context; + } + return inner_inner_inner; + } + return inner_inner; + } + assertEquals(8, inner()()()); +})(); diff --git a/deps/v8/test/mjsunit/error-tostring-omit.js b/deps/v8/test/mjsunit/error-tostring-omit.js index 9ff43fa9b2..48e1399d7a 100644 --- a/deps/v8/test/mjsunit/error-tostring-omit.js +++ b/deps/v8/test/mjsunit/error-tostring-omit.js @@ -42,7 +42,7 @@ assertTrue(veryLongString().length > 256); var re = /...<omitted>.../; try { - Number.prototype.toFixed.call(veryLongString); + Date.prototype.setDate.call(veryLongString); } catch (e) { assertTrue(e.message.length < 256); assertTrue(re.test(e.message)); diff --git a/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-1.js b/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-1.js new file mode 100644 index 0000000000..2dfddc3504 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-1.js @@ -0,0 +1,19 @@ +// Copyright 2016 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 testConcatRevokedProxyToArrayInPrototype() { + "use strict"; + var handler = { + get(_, name) { + if (name === Symbol.isConcatSpreadable) { + p.revoke(); + } + return target[name]; + } + } + + var p = Proxy.revocable([], handler); + var target = { __proto__: p.proxy }; + assertThrows(function() { [].concat(target); }, TypeError); +})(); diff --git a/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-2.js b/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-2.js new file mode 100644 index 0000000000..f91eb655bf --- /dev/null +++ b/deps/v8/test/mjsunit/es6/array-concat-revoked-proxy-2.js @@ -0,0 +1,19 @@ +// Copyright 2016 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 testConcatRevokedProxyToArray() { + "use strict"; + var handler = { + get(_, name) { + if (name === Symbol.isConcatSpreadable) { + p.revoke(); + } + return target[name]; + } + } + + var target = []; + var p = Proxy.revocable(target, handler); + assertThrows(function() { [].concat(p.proxy); }, TypeError); +})(); diff --git a/deps/v8/test/mjsunit/es6/array-concat.js b/deps/v8/test/mjsunit/es6/array-concat.js index fe320d6858..f57c10e03e 100644 --- a/deps/v8/test/mjsunit/es6/array-concat.js +++ b/deps/v8/test/mjsunit/es6/array-concat.js @@ -1,7 +1,6 @@ // Copyright 2014 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 testArrayConcatArity() { "use strict"; assertEquals(1, Array.prototype.concat.length); @@ -20,6 +19,15 @@ assertEquals(false, desc.enumerable); })(); +(function testNonConcatSpreadableArray() { + "use strict" + var array = [1, 2, 3]; + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + array[Symbol.isConcatSpreadable] = false; + assertEquals([[1,2,3]], [].concat(array)); + assertEquals([[1,2,3]], array.concat([])); +})(); (function testConcatArrayLike() { "use strict"; @@ -864,3 +872,25 @@ logger.get = function(t, trap, r) { assertThrows(() => [].concat(obj), TypeError); assertThrows(() => Array.prototype.concat.apply(obj), TypeError); })(); + +(function testConcatRevokedProxy() { + "use strict"; + var target = []; + var handler = { + get(_, name) { + if (name === Symbol.isConcatSpreadable) { + p.revoke(); + } + return target[name]; + } + } + + p = Proxy.revocable(target, handler); + target = {}; + target.__proto__ = p.proxy; + assertThrows(function() { [].concat({ __proto__: p.proxy }); }, TypeError); + + target = []; + var p = Proxy.revocable(target, handler); + assertThrows(function() { [].concat(p.proxy); }, TypeError); +})(); diff --git a/deps/v8/test/mjsunit/es6/array-prototype-values.js b/deps/v8/test/mjsunit/es6/array-prototype-values.js index 64162c47c8..b7c4e78e33 100644 --- a/deps/v8/test/mjsunit/es6/array-prototype-values.js +++ b/deps/v8/test/mjsunit/es6/array-prototype-values.js @@ -13,3 +13,4 @@ assertTrue(valuesDesc.configurable); assertTrue(valuesDesc.writable); assertFalse(valuesDesc.enumerable); assertTrue(Array.prototype[Symbol.unscopables].values); +assertThrows(() => new Array.prototype[Symbol.iterator], TypeError); diff --git a/deps/v8/test/mjsunit/harmony/array-species-constructor-accessor.js b/deps/v8/test/mjsunit/es6/array-species-constructor-accessor.js index 4c852f06f0..7ebf328a8a 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-constructor-accessor.js +++ b/deps/v8/test/mjsunit/es6/array-species-constructor-accessor.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting the constructor of an instance updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species-constructor-delete.js b/deps/v8/test/mjsunit/es6/array-species-constructor-delete.js index f341282dd9..fff22a2a8c 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-constructor-delete.js +++ b/deps/v8/test/mjsunit/es6/array-species-constructor-delete.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting the constructor of an instance updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species-constructor.js b/deps/v8/test/mjsunit/es6/array-species-constructor.js index d766e09eee..0d888f46ee 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-constructor.js +++ b/deps/v8/test/mjsunit/es6/array-species-constructor.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting the constructor of an instance updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species-delete.js b/deps/v8/test/mjsunit/es6/array-species-delete.js index ba49414069..16a2fa26f9 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-delete.js +++ b/deps/v8/test/mjsunit/es6/array-species-delete.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting the constructor of an instance updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species-modified.js b/deps/v8/test/mjsunit/es6/array-species-modified.js index 73c52b91a4..58feb31669 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-modified.js +++ b/deps/v8/test/mjsunit/es6/array-species-modified.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting Array[Symbol.species] updates the protector diff --git a/deps/v8/test/mjsunit/es6/array-species-neg-zero.js b/deps/v8/test/mjsunit/es6/array-species-neg-zero.js new file mode 100644 index 0000000000..d60b8ba00f --- /dev/null +++ b/deps/v8/test/mjsunit/es6/array-species-neg-zero.js @@ -0,0 +1,23 @@ +// Copyright 2016 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. + +/** + * 9.4.2.3 ArraySpeciesCreate(originalArray, length) + * + * 1. Assert: length is an integer Number ≥ 0. + * 2. If length is −0, let length be +0. + * [...] + */ + +var x = []; +var deleteCount; + +x.constructor = function() {}; +x.constructor[Symbol.species] = function(param) { + deleteCount = param; +}; + +x.splice(0, -0); + +assertEquals(0, deleteCount); diff --git a/deps/v8/test/mjsunit/harmony/array-species-parent-constructor.js b/deps/v8/test/mjsunit/es6/array-species-parent-constructor.js index 347732e1de..b4fb1d56e3 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-parent-constructor.js +++ b/deps/v8/test/mjsunit/es6/array-species-parent-constructor.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting Array.prototype.constructor updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species-proto.js b/deps/v8/test/mjsunit/es6/array-species-proto.js index 70db751519..6b55881cd6 100644 --- a/deps/v8/test/mjsunit/harmony/array-species-proto.js +++ b/deps/v8/test/mjsunit/es6/array-species-proto.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Overwriting an array instance's __proto__ updates the protector diff --git a/deps/v8/test/mjsunit/harmony/array-species.js b/deps/v8/test/mjsunit/es6/array-species.js index 19ed1d8185..25edf55104 100644 --- a/deps/v8/test/mjsunit/harmony/array-species.js +++ b/deps/v8/test/mjsunit/es6/array-species.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-species - // Test the ES2015 @@species feature 'use strict'; diff --git a/deps/v8/test/mjsunit/harmony/arraybuffer-species.js b/deps/v8/test/mjsunit/es6/arraybuffer-species.js index 0445a4b648..1ac6efbe26 100644 --- a/deps/v8/test/mjsunit/harmony/arraybuffer-species.js +++ b/deps/v8/test/mjsunit/es6/arraybuffer-species.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-species - // ArrayBuffer.prototype.slice makes subclass and checks length class MyArrayBuffer extends ArrayBuffer { } diff --git a/deps/v8/test/mjsunit/harmony/block-conflicts-sloppy.js b/deps/v8/test/mjsunit/es6/block-conflicts-sloppy.js index 8908ce4e56..b2ebfce6c9 100644 --- a/deps/v8/test/mjsunit/harmony/block-conflicts-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-conflicts-sloppy.js @@ -4,8 +4,6 @@ // Test for conflicting variable bindings. -// Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function - function CheckException(e) { var string = e.toString(); assertTrue(string.indexOf("has already been declared") >= 0 || @@ -172,8 +170,5 @@ for (var v = 0; v < varbinds.length; ++v) { TestNoConflict('(function (x) {' + varbinds[v] + '})();'); } -// Test conflicting catch/function bindings. -TestNoConflict('try {} catch(x) {' + funbind + '}'); - // Test conflicting parameter/function bindings. TestNoConflict('(function (x) {' + funbind + '})();'); diff --git a/deps/v8/test/mjsunit/es6/block-conflicts.js b/deps/v8/test/mjsunit/es6/block-conflicts.js index 0e3d4e5a2a..bca3cb4ea5 100644 --- a/deps/v8/test/mjsunit/es6/block-conflicts.js +++ b/deps/v8/test/mjsunit/es6/block-conflicts.js @@ -170,8 +170,5 @@ for (var v = 0; v < varbinds.length; ++v) { TestNoConflict('(function (x) {' + varbinds[v] + '})();'); } -// Test conflicting catch/function bindings. -TestNoConflict('try {} catch(x) {' + funbind + '}'); - // Test conflicting parameter/function bindings. TestNoConflict('(function (x) {' + funbind + '})();'); diff --git a/deps/v8/test/mjsunit/harmony/block-const-assign-sloppy.js b/deps/v8/test/mjsunit/es6/block-const-assign-sloppy.js index 5dde82cbf2..99024ef7cb 100644 --- a/deps/v8/test/mjsunit/harmony/block-const-assign-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-const-assign-sloppy.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-sloppy --harmony-sloppy-let - // Test that we throw early syntax errors in harmony mode // when using an immutable binding in an assigment or with // prefix/postfix decrement/increment operators. diff --git a/deps/v8/test/mjsunit/es6/block-early-errors.js b/deps/v8/test/mjsunit/es6/block-early-errors.js deleted file mode 100644 index 4af6521f64..0000000000 --- a/deps/v8/test/mjsunit/es6/block-early-errors.js +++ /dev/null @@ -1,54 +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: --no-harmony-sloppy-let - -function CheckException(e) { - var string = e.toString(); - assertInstanceof(e, SyntaxError); -} - -function Check(str) { - try { - eval("(function () { " + str + " })"); - assertUnreachable(); - } catch (e) { - CheckException(e); - } - try { - eval("(function () { { " + str + " } })"); - assertUnreachable(); - } catch (e) { - CheckException(e); - } -} - -// Check for early syntax errors when using let -// declarations outside of strict mode. -Check("let x;"); -Check("let x = 1;"); -Check("let x, y;"); diff --git a/deps/v8/test/mjsunit/harmony/block-eval-var-over-let.js b/deps/v8/test/mjsunit/es6/block-eval-var-over-let.js index 98091b4218..e16d7a02a6 100644 --- a/deps/v8/test/mjsunit/harmony/block-eval-var-over-let.js +++ b/deps/v8/test/mjsunit/es6/block-eval-var-over-let.js @@ -2,21 +2,19 @@ // 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 // Throws at the top level of a function assertThrows(function() { let x = 1; eval('var x'); -}, TypeError); +}, SyntaxError); // If the eval is in its own block scope, throws assertThrows(function() { let y = 1; { eval('var y'); } -}, TypeError); +}, SyntaxError); // If the let is in its own block scope, with the eval, throws assertThrows(function() { @@ -24,7 +22,7 @@ assertThrows(function() { let x = 1; eval('var x'); } -}, TypeError); +}, SyntaxError); // Legal if the let is no longer visible assertDoesNotThrow(function() { @@ -39,13 +37,13 @@ assertDoesNotThrow(function() { assertThrows(function() { const x = 1; eval('var x'); -}, TypeError); +}, SyntaxError); // If the eval is in its own block scope, throws assertThrows(function() { const y = 1; { eval('var y'); } -}, TypeError); +}, SyntaxError); // If the const is in its own block scope, with the eval, throws assertThrows(function() { @@ -53,7 +51,7 @@ assertThrows(function() { const x = 1; eval('var x'); } -}, TypeError); +}, SyntaxError); // Legal if the const is no longer visible assertDoesNotThrow(function() { @@ -63,6 +61,23 @@ assertDoesNotThrow(function() { eval('var x'); }); +// The same should work for lexical function declarations: +// If the const is in its own block scope, with the eval, throws +assertThrows(function() { + { + function x() {} + eval('var x'); + } +}, SyntaxError); + +// If the eval is in its own block scope, throws +assertThrows(function() { + { + function y() {} + { eval('var y'); } + } +}, SyntaxError); + // In global scope let caught = false; try { @@ -126,8 +141,6 @@ try { } assertTrue(caught); -// TODO(littledan): Hoisting x out of the block should be -// prevented in this case BUG(v8:4479) caught = false try { (function() { @@ -139,5 +152,4 @@ try { } catch (e) { caught = true; } -// TODO(littledan): switch to assertTrue when bug is fixed -assertTrue(caught); +assertFalse(caught); diff --git a/deps/v8/test/mjsunit/harmony/block-for-sloppy.js b/deps/v8/test/mjsunit/es6/block-for-sloppy.js index 261c46a166..4f0f63faa3 100644 --- a/deps/v8/test/mjsunit/harmony/block-for-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-for-sloppy.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-sloppy --harmony-sloppy-let - function props(x) { var array = []; for (let p in x) array.push(p); diff --git a/deps/v8/test/mjsunit/harmony/block-leave-sloppy.js b/deps/v8/test/mjsunit/es6/block-leave-sloppy.js index 0023fa08f3..1313026bf8 100644 --- a/deps/v8/test/mjsunit/harmony/block-leave-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-leave-sloppy.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-sloppy --harmony-sloppy-let - // We want to test the context chain shape. In each of the tests cases // below, the outer with is to force a runtime lookup of the identifier 'x' // to actually verify that the inner context has been discarded. A static diff --git a/deps/v8/test/mjsunit/es6/block-let-contextual-sloppy.js b/deps/v8/test/mjsunit/es6/block-let-contextual-sloppy.js index ac7bca107e..8282d779a1 100644 --- a/deps/v8/test/mjsunit/es6/block-let-contextual-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-let-contextual-sloppy.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-sloppy --harmony-sloppy-let - // let is usable as a variable with var, but not let or ES6 const (function (){ diff --git a/deps/v8/test/mjsunit/harmony/block-let-crankshaft-sloppy.js b/deps/v8/test/mjsunit/es6/block-let-crankshaft-sloppy.js index 4f29c05693..b5e81f7850 100644 --- a/deps/v8/test/mjsunit/harmony/block-let-crankshaft-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-let-crankshaft-sloppy.js @@ -26,7 +26,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Flags: --allow-natives-syntax -// Flags: --harmony-sloppy --harmony-sloppy-let // Check that the following functions are optimizable. var functions = [ f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, diff --git a/deps/v8/test/mjsunit/harmony/block-let-declaration-sloppy.js b/deps/v8/test/mjsunit/es6/block-let-declaration-sloppy.js index af95553bd0..ea0e39bd07 100644 --- a/deps/v8/test/mjsunit/harmony/block-let-declaration-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-let-declaration-sloppy.js @@ -27,8 +27,6 @@ // Test let declarations in various settings. -// Flags: --harmony-sloppy --harmony-sloppy-let - // Global let x; let y = 2; diff --git a/deps/v8/test/mjsunit/harmony/block-let-semantics-sloppy.js b/deps/v8/test/mjsunit/es6/block-let-semantics-sloppy.js index a55ff8fe49..4102ec8f5f 100644 --- a/deps/v8/test/mjsunit/harmony/block-let-semantics-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-let-semantics-sloppy.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-sloppy --harmony-sloppy-let --harmony-sloppy-function - // Test temporal dead zone semantics of let bound variables in // function and block scopes. diff --git a/deps/v8/test/mjsunit/es6/block-non-strict-errors.js b/deps/v8/test/mjsunit/es6/block-non-strict-errors.js deleted file mode 100644 index db7f558905..0000000000 --- a/deps/v8/test/mjsunit/es6/block-non-strict-errors.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 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: --no-harmony-sloppy-let --no-harmony-sloppy-function -// Flags: --no-harmony-sloppy - -function CheckError(source) { - var exception = null; - try { - eval(source); - } catch (e) { - exception = e; - } - assertNotNull(exception); - assertEquals( - "Block-scoped declarations (let, const, function, class) not yet supported outside strict mode", - exception.message); -} - - -function CheckOk(source) { - eval(source); -} - -CheckError("let x = 1;"); -CheckError("{ let x = 1; }"); -CheckError("function f() { let x = 1; }"); -CheckError("for (let x = 1; x < 1; x++) {}"); -CheckError("for (let x of []) {}"); -CheckError("for (let x in []) {}"); -CheckError("class C {}"); -CheckError("class C extends Array {}"); -CheckError("(class {});"); -CheckError("(class extends Array {});"); -CheckError("(class C {});"); -CheckError("(class C exends Array {});"); - -CheckOk("let = 1;"); -CheckOk("{ let = 1; }"); -CheckOk("function f() { let = 1; }"); -CheckOk("for (let = 1; let < 1; let++) {}"); diff --git a/deps/v8/test/mjsunit/es6/block-scope-class.js b/deps/v8/test/mjsunit/es6/block-scope-class.js index 351feaa90e..7bbd49d338 100644 --- a/deps/v8/test/mjsunit/es6/block-scope-class.js +++ b/deps/v8/test/mjsunit/es6/block-scope-class.js @@ -4,8 +4,6 @@ // Test for conflicting variable bindings. -// Flags: --harmony-sloppy --harmony-sloppy-function - function AssertEqualsStrictAndSloppy(value, code) { assertEquals(value, eval("(function() {" + code + "})()")); assertEquals(value, eval("(function() { 'use strict'; " + code + "})()")); diff --git a/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js b/deps/v8/test/mjsunit/es6/block-scoping-sloppy.js index 1785901276..f5c5a6326b 100644 --- a/deps/v8/test/mjsunit/harmony/block-scoping-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-scoping-sloppy.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 --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function +// Flags: --allow-natives-syntax // Test functionality of block scopes. // Hoisting of var declarations. diff --git a/deps/v8/test/mjsunit/harmony/block-scoping-top-level-sloppy.js b/deps/v8/test/mjsunit/es6/block-scoping-top-level-sloppy.js index 6f6a8fe06d..2a3b903f9e 100644 --- a/deps/v8/test/mjsunit/harmony/block-scoping-top-level-sloppy.js +++ b/deps/v8/test/mjsunit/es6/block-scoping-top-level-sloppy.js @@ -3,7 +3,6 @@ // found in the LICENSE file. // Flags: --min-preparse-length=0 -// Flags: --harmony-sloppy --harmony-sloppy-let let xxx = 1; let f = undefined; diff --git a/deps/v8/test/mjsunit/es6/block-sloppy-function.js b/deps/v8/test/mjsunit/es6/block-sloppy-function.js new file mode 100644 index 0000000000..8cb9a4deda --- /dev/null +++ b/deps/v8/test/mjsunit/es6/block-sloppy-function.js @@ -0,0 +1,656 @@ +// 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. + +// Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. +// http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-declarations-web-legacy-compatibility-semantics + +(function overridingLocalFunction() { + var x = []; + assertEquals('function', typeof f); + function f() { + x.push(1); + } + f(); + { + f(); + function f() { + x.push(2); + } + f(); + } + f(); + { + f(); + function f() { + x.push(3); + } + f(); + } + f(); + assertArrayEquals([1, 2, 2, 2, 3, 3, 3], x); +})(); + +(function newFunctionBinding() { + var x = []; + assertEquals('undefined', typeof f); + { + f(); + function f() { + x.push(2); + } + f(); + } + f(); + { + f(); + function f() { + x.push(3); + } + f(); + } + f(); + assertArrayEquals([2, 2, 2, 3, 3, 3], x); +})(); + +(function shadowingLetDoesntBind() { + let f = 1; + assertEquals(1, f); + { + let y = 3; + function f() { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals(1, f); +})(); + +(function shadowingClassDoesntBind() { + class f { } + assertEquals('class f { }', f.toString()); + { + let y = 3; + function f() { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals('class f { }', f.toString()); +})(); + +(function shadowingConstDoesntBind() { + const f = 1; + assertEquals(1, f); + { + let y = 3; + function f() { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals(1, f); +})(); + +(function shadowingVarBinds() { + var f = 1; + assertEquals(1, f); + { + let y = 3; + function f() { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals('function', typeof f); +})(); + +(function complexParams(a = 0) { + { + let y = 3; + function f(b = 0) { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals('function', typeof f); +})(); + +(function complexVarParams(a = 0) { + var f; + { + let y = 3; + function f(b = 0) { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals('function', typeof f); +})(); + +(function conditional() { + if (true) { + function f() { return 1; } + } else { + function f() { return 2; } + } + assertEquals(1, f()); + + if (false) { + function g() { return 1; } + } else { + function g() { return 2; } + } + assertEquals(2, g()); +})(); + +(function skipExecution() { + { + function f() { return 1; } + } + assertEquals(1, f()); + { + function f() { return 2; } + } + assertEquals(2, f()); + L: { + assertEquals(3, f()); + break L; + function f() { return 3; } + } + assertEquals(2, f()); +})(); + +(function executionOrder() { + function getOuter() { + return f; + } + assertEquals('undefined', typeof getOuter()); + + { + assertEquals('function', typeof f); + assertEquals('undefined', typeof getOuter()); + function f () {} + assertEquals('function', typeof f); + assertEquals('function', typeof getOuter()); + } + + assertEquals('function', typeof getOuter()); +})(); + +(function reassignBindings() { + function getOuter() { + return f; + } + assertEquals('undefined', typeof getOuter()); + + { + assertEquals('function', typeof f); + assertEquals('undefined', typeof getOuter()); + f = 1; + assertEquals('number', typeof f); + assertEquals('undefined', typeof getOuter()); + function f () {} + assertEquals('number', typeof f); + assertEquals('number', typeof getOuter()); + f = ''; + assertEquals('string', typeof f); + assertEquals('number', typeof getOuter()); + } + + assertEquals('number', typeof getOuter()); +})(); + +// Test that shadowing arguments is fine +(function shadowArguments(x) { + assertArrayEquals([1], arguments); + { + assertEquals('function', typeof arguments); + function arguments() {} + assertEquals('function', typeof arguments); + } + assertEquals('function', typeof arguments); +})(1); + + +// Don't shadow simple parameter +(function shadowingParameterDoesntBind(x) { + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})(1); + +// Don't shadow complex parameter +(function shadowingDefaultParameterDoesntBind(x = 0) { + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})(1); + +// Don't shadow nested complex parameter +(function shadowingNestedParameterDoesntBind([[x]]) { + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})([[1]]); + +// Don't shadow rest parameter +(function shadowingRestParameterDoesntBind(...x) { + assertArrayEquals([1], x); + { + function x() {} + } + assertArrayEquals([1], x); +})(1); + +// Don't shadow complex rest parameter +(function shadowingComplexRestParameterDoesntBind(...[x]) { + assertArrayEquals(1, x); + { + function x() {} + } + assertArrayEquals(1, x); +})(1); + +// Previous tests with a var declaration thrown in. +// Don't shadow simple parameter +(function shadowingVarParameterDoesntBind(x) { + var x; + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})(1); + +// Don't shadow complex parameter +(function shadowingVarDefaultParameterDoesntBind(x = 0) { + var x; + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})(1); + +// Don't shadow nested complex parameter +(function shadowingVarNestedParameterDoesntBind([[x]]) { + var x; + assertEquals(1, x); + { + function x() {} + } + assertEquals(1, x); +})([[1]]); + +// Don't shadow rest parameter +(function shadowingVarRestParameterDoesntBind(...x) { + var x; + assertArrayEquals([1], x); + { + function x() {} + } + assertArrayEquals([1], x); +})(1); + +// Don't shadow complex rest parameter +(function shadowingVarComplexRestParameterDoesntBind(...[x]) { + var x; + assertArrayEquals(1, x); + { + function x() {} + } + assertArrayEquals(1, x); +})(1); + + +// Hoisting is not affected by other simple parameters +(function irrelevantParameterBinds(y, z) { + assertEquals(undefined, x); + { + function x() {} + } + assertEquals('function', typeof x); +})(1); + +// Hoisting is not affected by other complex parameters +(function irrelevantComplexParameterBinds([y] = [], z) { + assertEquals(undefined, x); + { + function x() {} + } + assertEquals('function', typeof x); +})(); + +// Hoisting is not affected by rest parameters +(function irrelevantRestParameterBinds(y, ...z) { + assertEquals(undefined, x); + { + function x() {} + } + assertEquals('function', typeof x); +})(); + +// Hoisting is not affected by complex rest parameters +(function irrelevantRestParameterBinds(y, ...[z]) { + assertEquals(undefined, x); + { + function x() {} + } + assertEquals('function', typeof x); +})(); + + +// Test that shadowing function name is fine +{ + let called = false; + (function shadowFunctionName() { + if (called) assertUnreachable(); + called = true; + { + function shadowFunctionName() { + return 0; + } + assertEquals(0, shadowFunctionName()); + } + assertEquals(0, shadowFunctionName()); + })(); +} + +{ + let called = false; + (function shadowFunctionNameWithComplexParameter(...r) { + if (called) assertUnreachable(); + called = true; + { + function shadowFunctionNameWithComplexParameter() { + return 0; + } + assertEquals(0, shadowFunctionNameWithComplexParameter()); + } + assertEquals(0, shadowFunctionNameWithComplexParameter()); + })(); +} + +(function shadowOuterVariable() { + { + let f = 0; + (function () { + assertEquals(undefined, f); + { + assertEquals(1, f()); + function f() { return 1; } + assertEquals(1, f()); + } + assertEquals(1, f()); + })(); + assertEquals(0, f); + } +})(); + +(function notInDefaultScope() { + var y = 1; + (function innerNotInDefaultScope(x = y) { + assertEquals('undefined', typeof y); + { + function y() {} + } + assertEquals('function', typeof y); + assertEquals(1, x); + })(); +})(); + +(function noHoistingThroughNestedLexical() { + { + let f = 2; + { + let y = 3; + function f() { + y = 2; + } + f(); + assertEquals(2, y); + } + assertEquals(2, f); + } + assertThrows(()=>f, ReferenceError); +})(); + +// Only the first function is hoisted; the second is blocked by the first. +// Contrast overridingLocalFunction, in which the outer function declaration +// is not lexical and so the inner declaration is hoisted. +(function noHoistingThroughNestedFunctions() { + assertEquals(undefined, f); // Also checks that the var-binding exists + + { + assertEquals(4, f()); + + function f() { + return 4; + } + + { + assertEquals(5, f()); + function f() { + return 5; + } + assertEquals(5, f()); + } + + assertEquals(4, f()); + } + + assertEquals(4, f()); +})(); + +// B.3.5 interacts with B.3.3 to allow this. +(function hoistingThroughSimpleCatch() { + assertEquals(undefined, f); + + try { + throw 0; + } catch (f) { + { + assertEquals(4, f()); + + function f() { + return 4; + } + + assertEquals(4, f()); + } + + assertEquals(0, f); + } + + assertEquals(4, f()); +})(); + +(function noHoistingThroughComplexCatch() { + try { + throw 0; + } catch ({f}) { + { + assertEquals(4, f()); + + function f() { + return 4; + } + + assertEquals(4, f()); + } + } + + assertThrows(()=>f, ReferenceError); +})(); + +(function hoistingThroughWith() { + with ({f: 0}) { + assertEquals(0, f); + + { + assertEquals(4, f()); + + function f() { + return 4; + } + + assertEquals(4, f()); + } + + assertEquals(0, f); + } + + assertEquals(4, f()); +})(); + +// 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()); + `); +}(); + +// This test is incorrect BUG(v8:5168). The commented assertions are correct. +(function evalHoistingThroughSimpleCatch() { + try { + throw 0; + } catch (f) { + eval(`{ function f() { + return 4; + } }`); + + // assertEquals(0, f); + assertEquals(4, f()); + } + + // assertEquals(4, f()); + assertEquals(undefined, f); +})(); + +// This test is incorrect BUG(v8:5168). The commented assertions are correct. +(function evalHoistingThroughWith() { + with ({f: 0}) { + eval(`{ function f() { + return 4; + } }`); + + // assertEquals(0, f); + assertEquals(4, f()); + } + + // assertEquals(4, f()); + assertEquals(undefined, f); +})(); + +let dontHoistGlobal; +{ function dontHoistGlobal() {} } +assertEquals(undefined, dontHoistGlobal); + +let dontHoistEval; +var throws = false; +try { + eval("{ function dontHoistEval() {} }"); +} catch (e) { + throws = true; +} +assertFalse(throws); + +// When the global object is frozen, silently don't hoist +// Currently this actually throws BUG(v8:4452) +Object.freeze(this); +{ + let 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/es6/catch-parameter-redeclaration.js b/deps/v8/test/mjsunit/es6/catch-parameter-redeclaration.js new file mode 100644 index 0000000000..0f8f9c86e7 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/catch-parameter-redeclaration.js @@ -0,0 +1,112 @@ +// Copyright 2016 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 checkIsRedeclarationError(code) { + try { + eval(` +checkIsRedeclarationError : { + break checkIsRedeclarationError; +${code} +} +`); + assertUnreachable(); + } catch(e) { + assertInstanceof(e, SyntaxError ); + assertTrue( e.toString().indexOf("has already been declared") >= 0 ); + } +} + +function checkIsNotRedeclarationError(code) { + assertDoesNotThrow(()=>eval(` +checkIsNotRedeclarationError_label : { + break checkIsNotRedeclarationError_label; +${code} +} +`)); +} + + +let lexical_e = [ + 'let e', + 'let f, g, e', + 'let [f] = [], [] = [], e = e, h', + 'let {e} = 0', + 'let {f, e} = 0', + 'let {f, g} = 0, {e} = 0', + 'let {f = 0, e = 1} = 0', + 'let [e] = 0', + 'let [f, e] = 0', + 'let {f:e} = 0', + 'let [[[], e]] = 0', + 'const e = 0', + 'const f = 0, g = 0, e = 0', + 'const {e} = 0', + 'const [e] = 0', + 'const {f:e} = 0', + 'const [[[], e]] = 0', + 'function e(){}', + 'function* e(){}', +]; + +let not_lexical_e = [ + 'var e', + 'var f, e', + 'var {e} = 0', + 'let {} = 0', + 'let {e:f} = 0', + '{ function e(){} }' +]; + +// Check that lexical declarations cannot override a simple catch parameter +for (let declaration of lexical_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch(e) { + ${declaration} +} +`); +} + +// Check that lexical declarations cannot override a complex catch parameter +for (let declaration of lexical_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch({e}) { + ${declaration} +} +`); +} + +// Check that non-lexical declarations can override a simple catch parameter +for (let declaration of not_lexical_e) { + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + ${declaration} +} +`); +} + +// Check that the above error does not occur if a declaration scope is between +// the catch and the loop. +for (let declaration of lexical_e) { + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + (()=>{${declaration}})(); +} +`); + + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + (function(){${declaration}})(); +} +`); +} diff --git a/deps/v8/test/mjsunit/es6/class-computed-property-names-super.js b/deps/v8/test/mjsunit/es6/class-computed-property-names-super.js index cb9f25157c..b5a2ac995e 100644 --- a/deps/v8/test/mjsunit/es6/class-computed-property-names-super.js +++ b/deps/v8/test/mjsunit/es6/class-computed-property-names-super.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-sloppy // Flags: --allow-natives-syntax diff --git a/deps/v8/test/mjsunit/es6/class-property-name-eval-arguments.js b/deps/v8/test/mjsunit/es6/class-property-name-eval-arguments.js index 72ff60fd3e..bbd05cc355 100644 --- a/deps/v8/test/mjsunit/es6/class-property-name-eval-arguments.js +++ b/deps/v8/test/mjsunit/es6/class-property-name-eval-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-sloppy - (function Method() { class C { diff --git a/deps/v8/test/mjsunit/es6/classes-derived-return-type.js b/deps/v8/test/mjsunit/es6/classes-derived-return-type.js index 8283bcb227..3f81a340ff 100644 --- a/deps/v8/test/mjsunit/es6/classes-derived-return-type.js +++ b/deps/v8/test/mjsunit/es6/classes-derived-return-type.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-sloppy - class Base {} diff --git a/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js b/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js index 7669ef3a8a..dca514c294 100644 --- a/deps/v8/test/mjsunit/es6/classes-subclass-builtins.js +++ b/deps/v8/test/mjsunit/es6/classes-subclass-builtins.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: --allow-natives-syntax --harmony-regexp-subclass -// Flags: --expose-gc +// Flags: --allow-natives-syntax --expose-gc "use strict"; diff --git a/deps/v8/test/mjsunit/es6/classes.js b/deps/v8/test/mjsunit/es6/classes.js index 4dabda8e44..fb77dbb8e4 100644 --- a/deps/v8/test/mjsunit/es6/classes.js +++ b/deps/v8/test/mjsunit/es6/classes.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-sloppy --harmony-function-name --allow-natives-syntax -// Flags: --harmony-do-expressions +// Flags: --allow-natives-syntax --harmony-do-expressions (function TestBasics() { var C = class C {} diff --git a/deps/v8/test/mjsunit/es6/completion.js b/deps/v8/test/mjsunit/es6/completion.js index 7559514421..988e9709bb 100644 --- a/deps/v8/test/mjsunit/es6/completion.js +++ b/deps/v8/test/mjsunit/es6/completion.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-sloppy-let - function assertUndef(x) { assertEquals(undefined, x); diff --git a/deps/v8/test/mjsunit/es6/debug-blockscopes.js b/deps/v8/test/mjsunit/es6/debug-blockscopes.js index 193ad705cb..bf04a0a4aa 100644 --- a/deps/v8/test/mjsunit/es6/debug-blockscopes.js +++ b/deps/v8/test/mjsunit/es6/debug-blockscopes.js @@ -52,6 +52,7 @@ function listener(event, exec_state, event_data, data) { listener_delegate(exec_state); } } catch (e) { + print(e, e.stack); exception = e; } } @@ -147,10 +148,8 @@ function CheckScopeContent(content, number, exec_state) { if (!scope.scopeObject().property('arguments').isUndefined()) { scope_size--; } - // Skip property with empty name. - if (!scope.scopeObject().property('').isUndefined()) { - scope_size--; - } + // Temporary variables introduced by the parser have not been materialized. + assertTrue(scope.scopeObject().property('').isUndefined()); if (count != scope_size) { print('Names found in scope:'); @@ -380,16 +379,12 @@ function for_loop_1() { listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({x:'y'}, 0, exec_state); // The function scope contains a temporary iteration variable, but it is // hidden to the debugger. - // TODO(adamk): This variable is only used to provide a TDZ for the enumerable - // expression and should not be visible to the debugger. - CheckScopeContent({x:undefined}, 1, exec_state); }; for_loop_1(); EndTest(); @@ -409,7 +404,6 @@ function for_loop_2() { listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); @@ -417,9 +411,6 @@ listener_delegate = function(exec_state) { CheckScopeContent({x:'y'}, 1, exec_state); // The function scope contains a temporary iteration variable, hidden to the // debugger. - // TODO(adamk): This variable is only used to provide a TDZ for the enumerable - // expression and should not be visible to the debugger. - CheckScopeContent({x:undefined}, 2, exec_state); }; for_loop_2(); EndTest(); @@ -436,13 +427,11 @@ function for_loop_3() { listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({x:3}, 0, exec_state); - CheckScopeContent({x:3}, 1, exec_state); - CheckScopeContent({}, 2, exec_state); + CheckScopeContent({}, 1, exec_state); }; for_loop_3(); EndTest(); @@ -461,14 +450,12 @@ function for_loop_4() { listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({x:5}, 0, exec_state); CheckScopeContent({x:3}, 1, exec_state); - CheckScopeContent({x:3}, 2, exec_state); - CheckScopeContent({}, 3, exec_state); + CheckScopeContent({}, 2, exec_state); }; for_loop_4(); EndTest(); @@ -485,13 +472,11 @@ function for_loop_5() { listener_delegate = function(exec_state) { CheckScopeChain([debug.ScopeType.Block, - debug.ScopeType.Block, debug.ScopeType.Local, debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({x:3,y:5}, 0, exec_state); - CheckScopeContent({x:3,y:5}, 1, exec_state); - CheckScopeContent({}, 2, exec_state); + CheckScopeContent({}, 1, exec_state); }; for_loop_5(); EndTest(); diff --git a/deps/v8/test/mjsunit/es6/debug-exception-generators.js b/deps/v8/test/mjsunit/es6/debug-exception-generators.js new file mode 100644 index 0000000000..b2e7e82964 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-exception-generators.js @@ -0,0 +1,49 @@ +// Copyright 2016 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 + +Debug = debug.Debug + +var exception = null; +var log = []; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + var line = exec_state.frame(0).sourceLineText(); + var match = /Exception (\w)/.exec(line); + assertNotNull(match); + assertEquals(match[1], event_data.exception()); + log.push(match[1]); + } catch (e) { + exception = e; + } +} + + +function* g() { + try { + throw "a"; // Ordinary throw. Exception a + } catch (e) {} + try { + yield 1; // Caught internally. Exception b + } catch (e) {} + yield 2; + yield 3; // Caught externally. Exception c + yield 4; +} + +Debug.setListener(listener); +Debug.setBreakOnException(); +var g_obj = g(); +assertEquals(1, g_obj.next().value); +assertEquals(2, g_obj.throw("b").value); +assertEquals(3, g_obj.next().value); +assertThrows(() => g_obj.throw("c")); +assertThrows(() => g_obj.throw("d")); // Closed generator. Exception d +Debug.setListener(null); +Debug.clearBreakOnException(); +assertEquals(["a", "b", "c", "d"], log); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/async-task-event.js b/deps/v8/test/mjsunit/es6/debug-promises/async-task-event.js index 88030a2e73..0b0fa1e64f 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/async-task-event.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/async-task-event.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: --expose-debug-as debug +// Flags: --expose-debug-as debug --allow-natives-syntax Debug = debug.Debug; @@ -16,8 +16,8 @@ var expected = [ "didHandle #1", "willHandle #2", "then #2", - "enqueue #3", "didHandle #2", + "enqueue #3", "willHandle #3", "didHandle #3" ]; @@ -58,4 +58,6 @@ p.then(function() { }); resolver(); +%RunMicrotasks(); + assertNull(exception); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/evaluate-across-microtasks.js b/deps/v8/test/mjsunit/es6/debug-promises/evaluate-across-microtasks.js new file mode 100644 index 0000000000..73718eec7b --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/evaluate-across-microtasks.js @@ -0,0 +1,66 @@ +// Copyright 2014 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 + +var Debug = debug.Debug; +var listenerComplete = false; +var exception = null; +var count = 0; +var log = []; +var done = false; + +function LogX(x) { + var stored_count = count; + return function() { + log.push(`[${stored_count}] ${x}`); + }; +} + +function DebuggerStatement() { + log.push(`[${count}] debugger`); + if (count++ < 3) { + debugger; + } +} + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var p = Promise.resolve(); + var q = p.then(LogX("then 1")); + p.then(LogX("then 2")); + q.then(LogX("then 3")); + q.then(DebuggerStatement); + var r = q.then(() => { throw 1; }); + r.catch(LogX("catch")); + listenerComplete = true; + } catch (e) { + exception = e; + print(e, e.stack); + quit(1); + }; +}; + +// Add the debug event listener. +Debug.setListener(listener); + +DebuggerStatement(); +LogX("start")(); + +// Make sure that the debug event listener was invoked. +assertTrue(listenerComplete); + +%RunMicrotasks(); + +var expectation = + [ "[0] debugger", "[1] start", "[1] then 1", + "[1] then 2", "[1] then 3", "[1] debugger", + "[2] then 1", "[2] then 2", "[1] catch", + "[2] then 3", "[2] debugger", "[3] then 1", + "[3] then 2", "[2] catch", "[3] then 3", + "[3] debugger", "[3] catch", + ]; + +assertEquals(expectation, log); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/events.js b/deps/v8/test/mjsunit/es6/debug-promises/events.js deleted file mode 100644 index 3fcb22ff27..0000000000 --- a/deps/v8/test/mjsunit/es6/debug-promises/events.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2014 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-debug-as debug - -Debug = debug.Debug; - -var eventsExpected = 16; -var exception = null; -var result = []; - -function updatePromise(promise, parentPromise, status, value) { - var i; - for (i = 0; i < result.length; ++i) { - if (result[i].promise === promise) { - result[i].parentPromise = parentPromise || result[i].parentPromise; - result[i].status = status || result[i].status; - result[i].value = value || result[i].value; - break; - } - } - assertTrue(i < result.length); -} - -function listener(event, exec_state, event_data, data) { - if (event != Debug.DebugEvent.PromiseEvent) return; - try { - eventsExpected--; - assertTrue(event_data.promise().isPromise()); - if (event_data.status() === 0) { - // New promise. - assertEquals("pending", event_data.promise().status()); - result.push({ promise: event_data.promise().value(), status: 0 }); - assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); - } else if (event_data.status() !== undefined) { - // Resolve/reject promise. - updatePromise(event_data.promise().value(), - undefined, - event_data.status(), - event_data.value().value()); - } else { - // Chain promises. - assertTrue(event_data.parentPromise().isPromise()); - updatePromise(event_data.promise().value(), - event_data.parentPromise().value()); - assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); - } - } catch (e) { - print(e + e.stack) - exception = e; - } -} - -Debug.setListener(listener); - -function resolver(resolve, reject) { resolve(); } - -var p1 = new Promise(resolver); // event -var p2 = p1.then().then(); // event -var p3 = new Promise(function(resolve, reject) { // event - reject("rejected"); -}); -var p4 = p3.then(); // event -var p5 = p1.then(); // event - -function assertAsync(b, s) { - if (b) { - print(s, "succeeded"); - } else { - %AbortJS(s + " FAILED!"); - } -} - -function testDone(iteration) { - function checkResult() { - if (eventsExpected === 0) { - assertAsync(result.length === 6, "result.length"); - - assertAsync(result[0].promise === p1, "result[0].promise"); - assertAsync(result[0].parentPromise === undefined, - "result[0].parentPromise"); - assertAsync(result[0].status === 1, "result[0].status"); - assertAsync(result[0].value === undefined, "result[0].value"); - - assertAsync(result[1].parentPromise === p1, - "result[1].parentPromise"); - assertAsync(result[1].status === 1, "result[1].status"); - - assertAsync(result[2].promise === p2, "result[2].promise"); - - assertAsync(result[3].promise === p3, "result[3].promise"); - assertAsync(result[3].parentPromise === undefined, - "result[3].parentPromise"); - assertAsync(result[3].status === -1, "result[3].status"); - assertAsync(result[3].value === "rejected", "result[3].value"); - - assertAsync(result[4].promise === p4, "result[4].promise"); - assertAsync(result[4].parentPromise === p3, - "result[4].parentPromise"); - assertAsync(result[4].status === -1, "result[4].status"); - assertAsync(result[4].value === "rejected", "result[4].value"); - - assertAsync(result[5].promise === p5, "result[5].promise"); - assertAsync(result[5].parentPromise === p1, - "result[5].parentPromise"); - assertAsync(result[5].status === 1, "result[5].status"); - - assertAsync(exception === null, "exception === null"); - Debug.setListener(null); - } else if (iteration > 10) { - %AbortJS("Not all events were received!"); - } else { - testDone(iteration + 1); - } - } - - var iteration = iteration || 0; - %EnqueueMicrotask(checkResult); -} - -testDone(); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reentry.js b/deps/v8/test/mjsunit/es6/debug-promises/reentry.js index a97ce81012..cc98ed9efd 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reentry.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reentry.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: --expose-debug-as debug --promise-extra +// Flags: --expose-debug-as debug // Test reentry of special try catch for Promises. @@ -12,6 +12,6 @@ Debug.setBreakOnUncaughtException(); Debug.setListener(function(event, exec_state, event_data, data) { }); var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain(function() { +var q = p.then(function() { new Promise(function(resolve, reject) { resolve(); }); }); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-after-resolve.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-after-resolve.js index ed4b2c435e..5ec2da50e9 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-after-resolve.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-after-resolve.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we listen to uncaught exceptions and // the Promise is rejected in a chained closure after it has been resolved. @@ -17,7 +17,7 @@ var p = new Promise(function(resolve, reject) { resolve(reject); }); -var q = p.chain( +var q = p.then( function(value) { assertEquals(["resolve", "end main"], log); value(new Error("reject")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-all.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-all.js index e1a653889d..8d348ce6b6 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-all.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-all.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we listen to all exceptions and // there is a catch handler for the to-be-rejected Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function(value) { log.push("reject"); return Promise.reject(new Error("reject")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-late.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-late.js index 922449261b..44eb76728f 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-late.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-late.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions, the Promise // is rejected, and a catch handler is installed right before the rejection. @@ -14,7 +14,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { q.catch(function(e) { assertEquals("caught", e.message); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js index afb46fea8f..b2fe8b0a45 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-caught-uncaught.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions and // there is a catch handler for the to-be-rejected Promise. @@ -14,7 +14,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { return Promise.reject(Error("caught reject")); }); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-all.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-all.js index 63e3b8678d..0c5ecc5f3a 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-all.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-all.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we listen to all exceptions and // there is a catch handler for the to-be-rejected Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { log.push("reject"); return Promise.reject(new Error("uncaught reject")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js index b542bc69dd..e5e560b3db 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions and // there is no catch handler for the to-be-rejected Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { log.push("reject"); return Promise.reject(Error("uncaught reject")); // event diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js index 8775df687d..6aaf882ce8 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when a Promise is rejected, which is caught by a custom // promise, which has a number for reject closure. We expect an Exception debug @@ -28,7 +28,7 @@ function MyPromise(resolver) { MyPromise.prototype = new Promise(function() {}); p.constructor = MyPromise; -var q = p.chain( +var q = p.then( function() { log.push("reject caught"); return Promise.reject(new Error("caught")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js index b6c06df49e..47e335d968 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when a Promise is rejected, which is caught by a // custom promise, which throws a new exception in its reject handler. @@ -33,7 +33,7 @@ function MyPromise(resolver) { MyPromise.prototype = new Promise(function() {}); p.constructor = MyPromise; -var q = p.chain( +var q = p.then( function() { log.push("reject caught"); return Promise.reject(new Error("caught")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js index d058d41b96..1595372396 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when a Promise is rejected, which is caught by a custom // promise, which has undefined for reject closure. We expect an Exception @@ -28,7 +28,7 @@ function MyPromise(resolver) { MyPromise.prototype = new Promise(function() {}); p.constructor = MyPromise; -var q = p.chain( +var q = p.then( function() { log.push("reject caught"); return Promise.reject(new Error("caught")); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js b/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js deleted file mode 100644 index 918ae2a2e8..0000000000 --- a/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 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 listen to all exceptions and -// there is a catch handler for the exception thrown in a Promise. -// We expect a normal Exception debug event to be triggered. - -Debug = debug.Debug; - -var events = []; - -function listener(event, exec_state, event_data, data) { - if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); -} - -Debug.setListener(listener); - -var p = new Promise(function(resolve, reject) { - do { - try { - throw new Error("reject"); - } finally { - break; // No rethrow. - } - } while (false); - resolve(); -}); - -assertEquals([0 /* create */, 1 /* resolve */], events); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js b/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js deleted file mode 100644 index 298201f103..0000000000 --- a/deps/v8/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 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 listen to all exceptions and -// there is a catch handler for the exception thrown in a Promise. -// We expect a normal Exception debug event to be triggered. - -Debug = debug.Debug; - -var events = []; - -function listener(event, exec_state, event_data, data) { - if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); -} - -Debug.setListener(listener); - -var p = new Promise(function (resolve, reject) { - try { - throw new Error("reject"); - } catch (e) { - } - resolve(); -}); - -assertEquals([0 /* create */, 1 /* resolve */], events); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js b/deps/v8/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js deleted file mode 100644 index b1e2ff98e1..0000000000 --- a/deps/v8/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 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 listen to all exceptions and -// there is a catch handler for the exception thrown in a Promise. -// We expect a normal Exception debug event to be triggered. - -Debug = debug.Debug; - -var events = []; - -function listener(event, exec_state, event_data, data) { - if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); -} - -Debug.setListener(listener); - -var p = new Promise(function(resolve, reject) { - try { - throw new Error("reject"); - } finally { - // Implicit rethrow. - } - resolve(); -}); - -assertEquals([0 /* create */, -1 /* rethrown */], events); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js b/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js index 906969e105..6914ae0036 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/stepin-constructor.js @@ -21,9 +21,9 @@ function listener(event, exec_state, event_data, data) { Debug.setListener(listener); function resolver(resolve, reject) { - 1; - 2; - 3; + print(1); + print(2); + print(3); resolve(); } @@ -35,9 +35,9 @@ Debug.setListener(null); var expected_breaks = [ "debugger;", "var p = new Promise(resolver);", - "1;", - "2;", - "3;", + "print(1);", + "print(2);", + "print(3);", "resolve();", "}", "Debug.setListener(null);" diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-all.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-all.js index 3b7c48c1cf..8b932490b2 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-all.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-all.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we listen to all exceptions and // there is a catch handler for the exception thrown in a Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { log.push("throw"); throw new Error("caught"); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-late.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-late.js index aa7e584320..0399e5cc34 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-late.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-late.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions, the Promise // throws, and a catch handler is installed right before throwing. @@ -14,7 +14,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { q.catch(function(e) { assertEquals("caught", e.message); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js index a424ccc9f7..8e1524d519 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-caught-uncaught.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions and // there is a catch handler for the exception thrown in a Promise. @@ -14,7 +14,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { throw new Error("caught throw"); }); diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-finally-caught-all.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-finally-caught-all.js new file mode 100644 index 0000000000..eb823f518f --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-finally-caught-all.js @@ -0,0 +1,72 @@ +// Copyright 2016 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 listen to all exceptions and +// there is a catch handler for the exception thrown in a Promise, first +// caught by a try-finally, and immediately rethrown. +// We expect a normal Exception debug event to be triggered. + +Debug = debug.Debug; + +var expected_events = 1; +var log = []; + +var p = new Promise(function(resolve, reject) { + log.push("resolve"); + resolve(); +}); + +var q = p.then( + function() { + log.push("throw"); + try { + throw new Error("caught"); + } finally { + } + }); + +q.catch( + function(e) { + assertEquals("caught", e.message); + }); + +function listener(event, exec_state, event_data, data) { + try { + if (event == Debug.DebugEvent.Exception) { + expected_events--; + assertTrue(expected_events >= 0); + assertEquals("caught", event_data.exception().message); + assertSame(q, event_data.promise()); + assertFalse(event_data.uncaught()); + } + } catch (e) { + %AbortJS(e + "\n" + e.stack); + } +} + +Debug.setBreakOnException(); +Debug.setListener(listener); + +log.push("end main"); + +function testDone(iteration) { + function checkResult() { + try { + assertTrue(iteration < 10); + if (expected_events === 0) { + assertEquals(["resolve", "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/throw-uncaught-all.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-all.js index bfe0bedbac..3a73ac9fff 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-all.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-all.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we listen to all exceptions and // there is no catch handler for the exception thrown in a Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { log.push("throw"); throw new Error("uncaught"); // event diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js index 8dff592f33..24239f26f3 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when we only listen to uncaught exceptions and // there is a catch handler for the exception thrown in a Promise. @@ -18,7 +18,7 @@ var p = new Promise(function(resolve, reject) { resolve(); }); -var q = p.chain( +var q = p.then( function() { log.push("throw"); throw new Error("uncaught"); // event diff --git a/deps/v8/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js b/deps/v8/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js index 5cf49f2fae..622dd2573e 100644 --- a/deps/v8/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js +++ b/deps/v8/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.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: --expose-debug-as debug --allow-natives-syntax --promise-extra +// Flags: --expose-debug-as debug --allow-natives-syntax // Test debug events when an exception is thrown inside a Promise, which is // caught by a custom promise, which throws a new exception in its reject @@ -12,7 +12,7 @@ Debug = debug.Debug; -var expected_events = 2; +var expected_events = 1; var log = []; var p = new Promise(function(resolve, reject) { @@ -34,7 +34,7 @@ MyPromise.prototype = new Promise(function() {}); MyPromise.__proto__ = Promise; p.constructor = MyPromise; -var q = p.chain( +var q = p.then( function() { log.push("throw caught"); throw new Error("caught"); // event @@ -45,12 +45,10 @@ function listener(event, exec_state, event_data, data) { if (event == Debug.DebugEvent.Exception) { expected_events--; assertTrue(expected_events >= 0); - if (expected_events == 1) { + if (expected_events == 0) { assertEquals(["resolve", "construct", "end main", "throw caught"], log); assertEquals("caught", event_data.exception().message); - } else if (expected_events == 0) { - assertEquals("reject", event_data.exception().message); } else { assertUnreachable(); } diff --git a/deps/v8/test/mjsunit/es6/debug-scope-default-param-with-eval.js b/deps/v8/test/mjsunit/es6/debug-scope-default-param-with-eval.js new file mode 100644 index 0000000000..d4dc93f2c5 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-scope-default-param-with-eval.js @@ -0,0 +1,61 @@ +// Copyright 2016 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 + +// Test that the parameter initialization block scope set up for +// sloppy eval is visible to the debugger. + +var Debug = debug.Debug; +var exception = null; +var break_count = 0; + +function call_for_break() { + return 5; +} + +function test(x = eval("var y = 7; debugger; y") + call_for_break()) { + return x; +} + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var frame = exec_state.frame(0); + var block_scope; + if (break_count++ == 0) { + // Inside eval. + assertEquals([ debug.ScopeType.Eval, + debug.ScopeType.Block, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global ], + frame.allScopes().map(s => s.scopeType())); + exec_state.prepareStep(Debug.StepAction.StepOut); + block_scope = frame.scope(1); + } else { + // Outside of eval. + assertEquals([ debug.ScopeType.Block, + debug.ScopeType.Local, + debug.ScopeType.Script, + debug.ScopeType.Global ], + frame.allScopes().map(s => s.scopeType())); + block_scope = frame.scope(0); + } + assertTrue(block_scope.scopeObject().propertyNames().includes('y')); + assertEquals(7, block_scope.scopeObject().property('y').value().value()); + } catch (e) { + print(e); + exception = e; + } +} + +Debug.setListener(listener); + +assertEquals(12, test()); + +Debug.setListener(null); + +assertNull(exception); +assertEquals(2, break_count); diff --git a/deps/v8/test/mjsunit/es6/debug-step-into-regexp-subclass.js b/deps/v8/test/mjsunit/es6/debug-step-into-regexp-subclass.js index 599fe05715..5e5eb47d7f 100644 --- a/deps/v8/test/mjsunit/es6/debug-step-into-regexp-subclass.js +++ b/deps/v8/test/mjsunit/es6/debug-step-into-regexp-subclass.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: --expose-debug-as debug --harmony-regexp-subclass +// Flags: --expose-debug-as debug Debug = debug.Debug diff --git a/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js b/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js index 6a7c5536dc..e541f0f4b4 100644 --- a/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js +++ b/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.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-object-observe // Flags: --allow-natives-syntax --expose-debug-as debug Debug = debug.Debug @@ -46,6 +45,7 @@ Promise.resolve(42) .then(Boolean) // Should skip stepping into native. .then(promise2) .catch(promise3) + .then(promise4) .catch(function(e) { %AbortJS("FAIL: uncaught exception " + e); }); @@ -60,36 +60,16 @@ function promise2() { } function promise3() { - installObservers(); // Break 4. StepOver. - return break_count; // Break 5. -} // Break 6. - -function installObservers() { - var dummy = {}; - Object.observe(dummy, observer1); - Object.observe(dummy, Object); // Should skip stepping into native. - Object.observe(dummy, Boolean); // Should skip stepping into native. - Object.observe(dummy, observer2); - dummy.foo = 1; -} - -function observer1() { - return exception || 3; // Break 7. -} // Break 8. - -function observer2() { - Promise.resolve().then(promise4); // Break 9. StepOver. - return break_count + 1; // Break 10. -} // Break 11. + return break_count; // Break 4. +} // Break 5. function promise4() { - finalize(); // Break 12. StepOver. - return 0; // Break 13. -} // Break 14. StepOver. + finalize(); // Break 6. StepOver. + return 0; // Break 7. +} // Break 8. StepOver. function finalize() { - var dummy = {}; - Object.observe(dummy, function() { + Promise.resolve().then(function() { if (expected_breaks !== break_count) { %AbortJS("FAIL: expected <" + expected_breaks + "> breaks instead of <" + break_count + ">"); @@ -98,5 +78,4 @@ function finalize() { %AbortJS("FAIL: exception: " + exception); } }); - dummy.foo = 1; } diff --git a/deps/v8/test/mjsunit/es6/debug-stepin-proxies.js b/deps/v8/test/mjsunit/es6/debug-stepin-proxies.js index 4e71c79198..72c01f0c43 100644 --- a/deps/v8/test/mjsunit/es6/debug-stepin-proxies.js +++ b/deps/v8/test/mjsunit/es6/debug-stepin-proxies.js @@ -54,7 +54,7 @@ assertEquals(42, get); assertEquals([ "a0", - "b17", "h4b20", "i2b20", // [[Has]] + "b17", "h4b17", "i2b17", // [[Has]] "c15", "j4c15", "k2c15", // [[Get]] "d0", "l4d11", "m2d11", // [[Set]] "g0" diff --git a/deps/v8/test/mjsunit/es6/debug-stepnext-for.js b/deps/v8/test/mjsunit/es6/debug-stepnext-for.js index 9d5641a4a3..d425a46b84 100644 --- a/deps/v8/test/mjsunit/es6/debug-stepnext-for.js +++ b/deps/v8/test/mjsunit/es6/debug-stepnext-for.js @@ -11,6 +11,8 @@ var log = [] var s = 0; var a = [1, 2, 3]; +var b = [1, 2, 3, 4]; +var null_value = null; var i = 0; function f() { @@ -18,11 +20,11 @@ function f() { debugger; // Break a var j; // Break b - for (var i in null) { // Break c + for (var i in null_value) { // Break c s += a[i]; } - for (j in null) { // Break d + for (j in null_value) { // Break d s += a[j]; } @@ -46,7 +48,7 @@ function f() { s += j; // Break I } - for (let i of a) { // Break j + for (let i of a) { // Break j s += i; // Break J } @@ -61,6 +63,11 @@ function f() { for (let i = 0; i < 3; i++) { // Break m s += a[i]; // Break M } + + for (let i of a) {} // Break n + + [1, ...a] // Break o + } // Break y function listener(event, exec_state, event_data, data) { @@ -103,17 +110,21 @@ var expected = [ // For-in-let: get enumerable, next, body, next, ... "g16","g11","G4","g11","G4","g11","G4","g11", // For-of-var: [Symbol.iterator](), next(), body, next(), body, ... - "h16","h14","h15","H4","h15","H4","h15","H4","h15", + "h16","h13","H4","h13","H4","h13","H4","h13", // For-of: [Symbol.iterator](), next(), body, next(), body, ... - "i12","i10","i11","I4","i11","I4","i11","I4","i11", + "i12","i9","I4","i9","I4","i9","I4","i9", // For-of-let: [Symbol.iterator](), next(), body, next(), ... - "j16","j14","j15","J4","j15","J4","j15","J4","j15", + "j18","j14","J4","j14","J4","j14","J4","j14", // For-var: init, condition, body, next, condition, body, ... "k15","k20","K4","k26","k20","K4","k26","k20","K4","k26","k20", // For: init, condition, body, next, condition, body, ... "l7","l16","L4","l22","l16","L4","l22","l16","L4","l22","l16", // For-let: init, condition, body, next, condition, body, ... "m15","m20","M4","m26","m20","M4","m26","m20","M4","m26","m20", + // For-of, empty: [Symbol.iterator](), next() once + "n16", "n13", + // Spread: expression statement, spread + "o2", "o9", // Exit. "y0","z0", ] diff --git a/deps/v8/test/mjsunit/es6/default-parameters.js b/deps/v8/test/mjsunit/es6/default-parameters.js index 4e0bf542ef..c0fe031c03 100644 --- a/deps/v8/test/mjsunit/es6/default-parameters.js +++ b/deps/v8/test/mjsunit/es6/default-parameters.js @@ -350,14 +350,15 @@ (function TestDirectiveThrows() { "use strict"; - assertThrows(function(){ eval("function(x=1){'use strict';}") }, SyntaxError); - assertThrows(function(){ eval("(x=1) => {'use strict';}") }, SyntaxError); - assertThrows( - function(){ eval("(class{foo(x=1) {'use strict';}});") }, SyntaxError); - - assertThrows( - function(){ eval("function(a, x=1){'use strict';}") }, SyntaxError); - assertThrows(function(){ eval("(a, x=1) => {'use strict';}") }, SyntaxError); - assertThrows( - function(){ eval("(class{foo(a, x=1) {'use strict';}});") }, SyntaxError); + assertThrows("(function(x=1){'use strict';})", SyntaxError); + assertThrows("(x=1) => {'use strict';}", SyntaxError); + assertThrows("(class{foo(x=1) {'use strict';}});", SyntaxError); + + assertThrows("(function(a, x=1){'use strict';})", SyntaxError); + assertThrows("(a, x=1) => {'use strict';}", SyntaxError); + assertThrows("(class{foo(a, x=1) {'use strict';}});", SyntaxError); + + assertThrows("(function({x}){'use strict';})", SyntaxError); + assertThrows("({x}) => {'use strict';}", SyntaxError); + assertThrows("(class{foo({x}) {'use strict';}});", SyntaxError); })(); diff --git a/deps/v8/test/mjsunit/es6/destructuring.js b/deps/v8/test/mjsunit/es6/destructuring.js index 1f16c45270..a4f88844d4 100644 --- a/deps/v8/test/mjsunit/es6/destructuring.js +++ b/deps/v8/test/mjsunit/es6/destructuring.js @@ -1045,9 +1045,9 @@ function f20({x}) { function x() { return 2 }; return x(); } assertEquals(2, f20({x: 1})); - // Function hoisting is blocked by the conflicting x declaration - function f21({x}) { { function x() { return 2 } } return x(); } - assertThrows(() => f21({x: 1}), TypeError); + // Annex B 3.3 function hoisting is blocked by the conflicting x declaration + function f21({x}) { { function x() { return 2 } } return x; } + assertEquals(1, f21({x: 1})); var g1 = ({x}) => { var x = 2; return x }; assertEquals(2, g1({x: 1})); @@ -1082,15 +1082,15 @@ var g21 = ({x}) => { { function x() { return 2 } } return x(); } assertThrows(() => g21({x: 1}), TypeError); - 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'; function f(x) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; function f({x}) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; function f(x) { const x = 0; }", SyntaxError); + assertThrows("'use strict'; function f({x}) { const x = 0; }", 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); + assertThrows("'use strict'; let g = (x) => { let x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = ({x}) => { let x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = (x) => { const x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = ({x}) => { const x = 0; }", SyntaxError); }()); diff --git a/deps/v8/test/mjsunit/es6/for-each-in-catch.js b/deps/v8/test/mjsunit/es6/for-each-in-catch.js new file mode 100644 index 0000000000..674cddd047 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/for-each-in-catch.js @@ -0,0 +1,194 @@ +// Copyright 2016 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 checkIsRedeclarationError(code) { + try { + eval(` +checkIsRedeclarationError : { + break checkIsRedeclarationError; +${code} +} +`); + assertUnreachable(); + } catch(e) { + assertInstanceof(e, SyntaxError ); + assertTrue( e.toString().indexOf("has already been declared") >= 0 ); + } +} + +function checkIsNotRedeclarationError(code) { + assertDoesNotThrow(()=>eval(` +checkIsNotRedeclarationError_label : { + break checkIsNotRedeclarationError_label; +${code} +} +`)); +} + + +let var_e = [ + 'var e', + 'var {e}', + 'var {f, e}', + 'var [e]', + 'var {f:e}', + 'var [[[], e]]' +]; + +let not_var_e = [ + 'var f', + 'var {}', + 'var {e:f}', + 'e', + '{e}', + 'let e', + 'const e', + 'let {e}', + 'const {e}', + 'let [e]', + 'const [e]', + 'let {f:e}', + 'const {f:e}' +]; + +// Check that `for (var ... of ...)` cannot redeclare a simple catch variable +// but `for (var ... in ...)` can. +for (let binding of var_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch(e) { + for (${binding} of []); +} +`); + + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + for (${binding} in []); +} +`); +} + +// Check that the above error occurs even for nested catches. +for (let binding of var_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch(e) { + try { + throw 1; + } catch(f) { + try { + throw 2; + } catch({}) { + for (${binding} of []); + } + } +} +`); + + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + try { + throw 1; + } catch(f) { + try { + throw 2; + } catch({}) { + for (${binding} in []); + } + } +} +`); +} + +// Check that the above error does not occur if a declaration scope is between +// the catch and the loop. +for (let binding of var_e) { + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + (()=>{for (${binding} of []);})(); +} +`); + + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + (function(){for (${binding} of []);})(); +} +`); +} + +// Check that there is no error when not declaring a var named e. +for (let binding of not_var_e) { + checkIsNotRedeclarationError(` +try { + throw 0; +} catch(e) { + for (${binding} of []); +} +`); +} + +// Check that there is an error for both for-in and for-of when redeclaring +// a non-simple catch parameter +for (let binding of var_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch({e}) { + for (${binding} of []); +} +`); + + checkIsRedeclarationError(` +try { + throw 0; +} catch({e}) { + for (${binding} in []); +} +`); +} + +// Check that the above error occurs even for nested catches. +for (let binding of var_e) { + checkIsRedeclarationError(` +try { + throw 0; +} catch({e}) { + try { + throw 1; + } catch(f) { + try { + throw 2; + } catch({}) { + for (${binding} of []); + } + } +} +`); + + checkIsRedeclarationError(` +try { + throw 0; +} catch({e}) { + try { + throw 1; + } catch(f) { + try { + throw 2; + } catch({}) { + for (${binding} in []); + } + } +} +`); +} diff --git a/deps/v8/test/mjsunit/harmony/function-name.js b/deps/v8/test/mjsunit/es6/function-name.js index 66a69e0f16..0fcab441ed 100644 --- a/deps/v8/test/mjsunit/harmony/function-name.js +++ b/deps/v8/test/mjsunit/es6/function-name.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-function-name (function testVariableDeclarationsFunction() { 'use strict'; @@ -359,10 +357,10 @@ (function testNameNotReflectedInToString() { - var f = function() {}; - var g = function*() {}; + var f = function () {}; + var g = function* () {}; var obj = { - ['h']: function() {}, + ['h']: function () {}, i: () => {} }; assertEquals('function () {}', f.toString()); diff --git a/deps/v8/test/mjsunit/es6/generator-destructuring.js b/deps/v8/test/mjsunit/es6/generator-destructuring.js new file mode 100644 index 0000000000..7228782c09 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/generator-destructuring.js @@ -0,0 +1,317 @@ +// Copyright 2016 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 TestDefaultBeforeInitializingYield() { + var y = 0; + var z = 0; + function* f1(x = (y = 1)) { z = 1 }; + assertEquals(0, y); + assertEquals(0, z); + var gen = f1(); + assertEquals(1, y); + assertEquals(0, z); + gen.next(); + assertEquals(1, y); + assertEquals(1, z); +})(); + +(function TestShadowingOfParameters() { + function* f1({x}) { var x = 2; return x } + assertEquals(2, f1({x: 1}).next().value); + function* f2({x}) { { var x = 2; } return x; } + assertEquals(2, f2({x: 1}).next().value); + function* f3({x}) { var y = x; var x = 2; return y; } + assertEquals(1, f3({x: 1}).next().value); + function* f4({x}) { { var y = x; var x = 2; } return y; } + assertEquals(1, f4({x: 1}).next().value); + function* f5({x}, g = () => x) { var x = 2; return g(); } + assertEquals(1, f5({x: 1}).next().value); + function* f6({x}, g = () => x) { { var x = 2; } return g(); } + assertEquals(1, f6({x: 1}).next().value); + function* f7({x}) { var g = () => x; var x = 2; return g(); } + assertEquals(2, f7({x: 1}).next().value); + function* f8({x}) { { var g = () => x; var x = 2; } return g(); } + assertEquals(2, f8({x: 1}).next().value); + function* f9({x}, g = () => eval("x")) { var x = 2; return g(); } + assertEquals(1, f9({x: 1}).next().value); + + function* f10({x}, y) { var y; return y } + assertEquals(2, f10({x: 6}, 2).next().value); + function* f11({x}, y) { var z = y; var y = 2; return z; } + assertEquals(1, f11({x: 6}, 1).next().value); + function* f12(y, g = () => y) { var y = 2; return g(); } + assertEquals(1, f12(1).next().value); + function* f13({x}, y, [z], v) { var x, y, z; return x*y*z*v } + assertEquals(210, f13({x: 2}, 3, [5], 7).next().value); + + function* f20({x}) { function x() { return 2 }; return x(); } + assertEquals(2, f20({x: 1}).next().value); + // Annex B 3.3 function hoisting is blocked by the conflicting x declaration + function* f21({x}) { { function x() { return 2 } } return x; } + assertEquals(1, f21({x: 1}).next().value); + + assertThrows("'use strict'; function* f(x) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; function* f({x}) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; function* f(x) { const x = 0; }", SyntaxError); + assertThrows("'use strict'; function* f({x}) { const x = 0; }", SyntaxError); +}()); + +(function TestDefaults() { + function* f1(x = 1) { return x } + assertEquals(1, f1().next().value); + assertEquals(1, f1(undefined).next().value); + assertEquals(2, f1(2).next().value); + assertEquals(null, f1(null).next().value); + + function* f2(x, y = x) { return x + y; } + assertEquals(8, f2(4).next().value); + assertEquals(8, f2(4, undefined).next().value); + assertEquals(6, f2(4, 2).next().value); + + function* f3(x = 1, y) { return x + y; } + assertEquals(8, f3(5, 3).next().value); + assertEquals(3, f3(undefined, 2).next().value); + assertEquals(6, f3(4, 2).next().value); + + function* f4(x = () => 1) { return x() } + assertEquals(1, f4().next().value); + assertEquals(1, f4(undefined).next().value); + assertEquals(2, f4(() => 2).next().value); + assertThrows(() => f4(null).next(), TypeError); + + function* f5(x, y = () => x) { return x + y(); } + assertEquals(8, f5(4).next().value); + assertEquals(8, f5(4, undefined).next().value); + assertEquals(6, f5(4, () => 2).next().value); + + function* f6(x = {a: 1, m() { return 2 }}) { return x.a + x.m(); } + assertEquals(3, f6().next().value); + assertEquals(3, f6(undefined).next().value); + assertEquals(5, f6({a: 2, m() { return 3 }}).next().value); +}()); + + +(function TestEvalInParameters() { + function* f1(x = eval(0)) { return x } + assertEquals(0, f1().next().value); + function* f2(x = () => eval(1)) { return x() } + assertEquals(1, f2().next().value); +})(); + + +(function TestParameterScopingSloppy() { + var x = 1; + + function* f1(a = x) { var x = 2; return a; } + assertEquals(1, f1().next().value); + function* f2(a = x) { function x() {}; return a; } + assertEquals(1, f2().next().value); + function* f3(a = eval("x")) { var x; return a; } + assertEquals(1, f3().next().value); + function* f31(a = eval("'use strict'; x")) { var x; return a; } + assertEquals(1, f31().next().value); + function* f4(a = function() { return x }) { var x; return a(); } + assertEquals(1, f4().next().value); + function* f5(a = () => x) { var x; return a(); } + assertEquals(1, f5().next().value); + function* f6(a = () => eval("x")) { var x; return a(); } + assertEquals(1, f6().next().value); + function* f61(a = () => { 'use strict'; return eval("x") }) { var x; return a(); } + assertEquals(1, f61().next().value); + function* f62(a = () => eval("'use strict'; x")) { var x; return a(); } + assertEquals(1, f62().next().value); + + var f11 = function* f(x = f) { var f; return x; } + assertSame(f11, f11().next().value); + var f12 = function* f(x = f) { function f() {}; return x; } + assertSame(f12, f12().next().value); + var f13 = function* f(f = 7, x = f) { return x; } + assertSame(7, f13().next().value); + + var o1 = {f: function*(x = this) { return x; }}; + assertSame(o1, o1.f().next().value); + assertSame(1, o1.f(1).next().value); +})(); + +(function TestParameterScopingStrict() { + "use strict"; + var x = 1; + + function* f1(a = x) { let x = 2; return a; } + assertEquals(1, f1().next().value); + function* f2(a = x) { const x = 2; return a; } + assertEquals(1, f2().next().value); + function* f3(a = x) { function x() {}; return a; } + assertEquals(1, f3().next().value); + function* f4(a = eval("x")) { var x; return a; } + assertEquals(1, f4().next().value); + function* f5(a = () => eval("x")) { var x; return a(); } + assertEquals(1, f5().next().value); + + var f11 = function* f(x = f) { let f; return x; } + assertSame(f11, f11().next().value); + var f12 = function* f(x = f) { const f = 0; return x; } + assertSame(f12, f12().next().value); + var f13 = function* f(x = f) { function f() {}; return x; } + assertSame(f13, f13().next().value); +})(); + +(function TestSloppyEvalScoping() { + var x = 1; + + function* f1(y = eval("var x = 2")) { with ({}) { return x; } } + assertEquals(1, f1().next().value); + function* f2(y = eval("var x = 2"), z = x) { return z; } + assertEquals(1, f2().next().value); + assertEquals(1, f2(0).next().value); + function* f3(y = eval("var x = 2"), z = eval("x")) { return z; } + assertEquals(1, f3().next().value); + assertEquals(1, f3(0).next().value); + function* f8(y = (eval("var x = 2"), x)) { return y; } + assertEquals(2, f8().next().value); + assertEquals(0, f8(0).next().value); + + function* f11(z = eval("var y = 2")) { return y; } + assertThrows(() => f11().next(), ReferenceError); + function* f12(z = eval("var y = 2"), b = y) {} + assertThrows(() => f12().next(), ReferenceError); + function* f13(z = eval("var y = 2"), b = eval("y")) {} + assertThrows(() => f13().next(), ReferenceError); + + function* f21(f = () => x) { eval("var x = 2"); return f() } + assertEquals(1, f21().next().value); + assertEquals(3, f21(() => 3).next().value); + function* f22(f = () => eval("x")) { eval("var x = 2"); return f() } + assertEquals(1, f22().next().value); + assertEquals(3, f22(() => 3).next().value); +})(); + + +(function TestStrictEvalScoping() { + 'use strict'; + var x = 1; + + function* f1(y = eval("var x = 2")) { return x; } + assertEquals(1, f1().next().value); + function* f2(y = eval("var x = 2"), z = x) { return z; } + assertEquals(1, f2().next().value); + assertEquals(1, f2(0).next().value); + function* f3(y = eval("var x = 2"), z = eval("x")) { return z; } + assertEquals(1, f3().next().value); + assertEquals(1, f3(0).next().value); + function* f8(y = (eval("var x = 2"), x)) { return y; } + assertEquals(1, f8().next().value); + assertEquals(0, f8(0).next().value); + + function* f11(z = eval("var y = 2")) { return y; } + assertThrows(() => f11().next().value, ReferenceError); + function* f12(z = eval("var y = 2"), b = y) {} + assertThrows(() => f12().next().value, ReferenceError); + function* f13(z = eval("var y = 2"), b = eval("y")) {} + assertThrows(() => f13().next().value, ReferenceError); + + function* f21(f = () => x) { eval("var x = 2"); return f() } + assertEquals(1, f21().next().value); + assertEquals(3, f21(() => 3).next().value); + function* f22(f = () => eval("x")) { eval("var x = 2"); return f() } + assertEquals(1, f22().next().value); + assertEquals(3, f22(() => 3).next().value); +})(); + +(function TestParameterTDZSloppy() { + function* f1(a = x, x) { return a } + assertThrows(() => f1(undefined, 4), ReferenceError); + assertEquals(4, f1(4, 5).next().value); + function* f2(a = eval("x"), x) { return a } + assertThrows(() => f2(undefined, 4), ReferenceError); + assertEquals(4, f2(4, 5).next().value); + function* f3(a = eval("'use strict'; x"), x) { return a } + assertThrows(() => f3(undefined, 4), ReferenceError); + assertEquals(4, f3(4, 5).next().value); + function* f4(a = () => x, x) { return a() } + assertEquals(4, f4(() => 4, 5).next().value); + function* f5(a = () => eval("x"), x) { return a() } + assertEquals(4, f5(() => 4, 5).next().value); + function* f6(a = () => eval("'use strict'; x"), x) { return a() } + assertEquals(4, f6(() => 4, 5).next().value); + + function* f11(a = x, x = 2) { return a } + assertThrows(() => f11(), ReferenceError); + assertThrows(() => f11(undefined), ReferenceError); + assertThrows(() => f11(undefined, 4), ReferenceError); + assertEquals(4, f1(4, 5).next().value); + function* f12(a = eval("x"), x = 2) { return a } + assertThrows(() => f12(), ReferenceError); + assertThrows(() => f12(undefined), ReferenceError); + assertThrows(() => f12(undefined, 4), ReferenceError); + assertEquals(4, f12(4, 5).next().value); + function* f13(a = eval("'use strict'; x"), x = 2) { return a } + assertThrows(() => f13(), ReferenceError); + assertThrows(() => f13(undefined), ReferenceError); + assertThrows(() => f13(undefined, 4), ReferenceError); + assertEquals(4, f13(4, 5).next().value); + + function* f21(x = function() { return a }, ...a) { return x()[0] } + assertEquals(4, f21(undefined, 4).next().value); + function* f22(x = () => a, ...a) { return x()[0] } + assertEquals(4, f22(undefined, 4).next().value); + function* f23(x = () => eval("a"), ...a) { return x()[0] } + assertEquals(4, f23(undefined, 4).next().value); + function* f24(x = () => {'use strict'; return eval("a") }, ...a) { + return x()[0] + } + assertEquals(4, f24(undefined, 4).next().value); + function* f25(x = () => eval("'use strict'; a"), ...a) { return x()[0] } + assertEquals(4, f25(undefined, 4).next().value); +})(); + +(function TestParameterTDZStrict() { + "use strict"; + + function* f1(a = eval("x"), x) { return a } + assertThrows(() => f1(undefined, 4), ReferenceError); + assertEquals(4, f1(4, 5).next().value); + function* f2(a = () => eval("x"), x) { return a() } + assertEquals(4, f2(() => 4, 5).next().value); + + function* f11(a = eval("x"), x = 2) { return a } + assertThrows(() => f11(), ReferenceError); + assertThrows(() => f11(undefined), ReferenceError); + assertThrows(() => f11(undefined, 4), ReferenceError); + assertEquals(4, f11(4, 5).next().value); + + function* f21(x = () => eval("a"), ...a) { return x()[0] } + assertEquals(4, f21(undefined, 4).next().value); +})(); + +(function TestArgumentsForNonSimpleParameters() { + function* f1(x = 900) { arguments[0] = 1; return x } + assertEquals(9, f1(9).next().value); + assertEquals(900, f1().next().value); + function* f2(x = 1001) { x = 2; return arguments[0] } + assertEquals(10, f2(10).next().value); + assertEquals(undefined, f2().next().value); +}()); + + +(function TestFunctionLength() { + assertEquals(0, (function*(x = 1) {}).length); + assertEquals(0, (function*(x = 1, ...a) {}).length); + assertEquals(1, (function*(x, y = 1) {}).length); + assertEquals(1, (function*(x, y = 1, ...a) {}).length); + assertEquals(2, (function*(x, y, z = 1) {}).length); + assertEquals(2, (function*(x, y, z = 1, ...a) {}).length); + assertEquals(1, (function*(x, y = 1, z) {}).length); + assertEquals(1, (function*(x, y = 1, z, ...a) {}).length); + assertEquals(1, (function*(x, y = 1, z, v = 2) {}).length); + assertEquals(1, (function*(x, y = 1, z, v = 2, ...a) {}).length); +})(); + +(function TestDirectiveThrows() { + "use strict"; + + assertThrows("(function*(x=1){'use strict';})", SyntaxError); + assertThrows("(function*(a, x=1){'use strict';})", SyntaxError); + assertThrows("(function*({x}){'use strict';})", SyntaxError); +})(); diff --git a/deps/v8/test/mjsunit/es6/generators-objects.js b/deps/v8/test/mjsunit/es6/generators-objects.js index a0c3b809be..2cc359f911 100644 --- a/deps/v8/test/mjsunit/es6/generators-objects.js +++ b/deps/v8/test/mjsunit/es6/generators-objects.js @@ -87,3 +87,43 @@ function TestGeneratorObjectMethods() { TestNonGenerator(g.prototype); } TestGeneratorObjectMethods(); + + +function TestPrototype() { + function* g() { } + + let g_prototype = g.prototype; + assertEquals([], Reflect.ownKeys(g_prototype)); + + let generator_prototype = Object.getPrototypeOf(g_prototype); + assertSame(generator_prototype, Object.getPrototypeOf(g).prototype); + + // Unchanged .prototype + assertSame(g_prototype, Object.getPrototypeOf(g())); + + // Custom object as .prototype + { + let proto = {}; + g.prototype = proto; + assertSame(proto, Object.getPrototypeOf(g())); + } + + // Custom non-object as .prototype + g.prototype = null; + assertSame(generator_prototype, Object.getPrototypeOf(g())); +} +TestPrototype(); + + +function TestComputedPropertyNames() { + function* f1() { return {[yield]: 42} } + var g1 = f1(); + g1.next(); + assertEquals(42, g1.next('a').value.a); + + function* f2() { return {['a']: yield} } + var g2 = f2(); + g2.next(); + assertEquals(42, g2.next(42).value.a); +} +TestComputedPropertyNames(); diff --git a/deps/v8/test/mjsunit/harmony/instanceof-es6.js b/deps/v8/test/mjsunit/es6/instanceof.js index 60e7ee2c39..6bf225953f 100644 --- a/deps/v8/test/mjsunit/harmony/instanceof-es6.js +++ b/deps/v8/test/mjsunit/es6/instanceof.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-instanceof - // Make sure it's an error if @@hasInstance isn't a function. (function() { var F = {}; @@ -48,3 +46,22 @@ assertEquals(Function.prototype[Symbol.hasInstance].call({}, {}), false); // OrdinaryHasInstance passed a non-object argument returns false. assertEquals(Function.prototype[Symbol.hasInstance].call(Array, 0), false); + +// Cannot assign to @@hasInstance with %FunctionPrototype%. +(function() { + "use strict"; + function F() {} + assertThrows(function() { F[Symbol.hasInstance] = (v) => v }, TypeError); +})(); + +// Check correct invocation of @@hasInstance handler on function instance. +(function() { + function F() {} + var counter = 0; + var proto = Object.getPrototypeOf(F); + Object.setPrototypeOf(F, null); + F[Symbol.hasInstance] = function(v) { ++counter; return true }; + Object.setPrototypeOf(F, proto); + assertTrue(1 instanceof F); + assertEquals(1, counter); +})(); diff --git a/deps/v8/test/mjsunit/harmony/iterator-close.js b/deps/v8/test/mjsunit/es6/iterator-close.js index b719c17c04..fd8f361e5e 100644 --- a/deps/v8/test/mjsunit/harmony/iterator-close.js +++ b/deps/v8/test/mjsunit/es6/iterator-close.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-iterator-close - function* g() { yield 42; return 88 }; @@ -968,8 +966,9 @@ function* g() { yield 42; return 88 }; // Next method throws. { + let closed = false; g.prototype.next = () => { throw 666; }; - g.prototype.return = () => { assertUnreachable() }; + g.prototype.return = () => { closed = true; }; assertThrowsEquals(() => { @@ -1007,13 +1006,37 @@ function* g() { yield 42; return 88 }; assertThrowsEquals(() => { (([x]) => x)(g()); }, 666); + + assertThrowsEquals(() => { + var [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + let [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + const [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + (([...x]) => x)(g()); + }, 666); + + + assertFalse(closed); } // Value throws. { + let closed = false; g.prototype.next = () => ({get value() {throw 666}}); - g.prototype.return = () => { assertUnreachable() }; + g.prototype.return = () => { closed = true; }; assertThrowsEquals(() => { @@ -1051,13 +1074,37 @@ function* g() { yield 42; return 88 }; assertThrowsEquals(() => { (([x]) => x)(g()); }, 666); + + assertThrowsEquals(() => { + var [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + let [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + const [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + (([...x]) => x)(g()); + }, 666); + + + assertFalse(closed); } // Done throws. { + let closed = false; g.prototype.next = () => ({get done() {throw 666}}); - g.prototype.return = () => { assertUnreachable() }; + g.prototype.return = () => { closed = true; }; assertThrowsEquals(() => { @@ -1095,6 +1142,29 @@ function* g() { yield 42; return 88 }; assertThrowsEquals(() => { (([x]) => x)(g()); }, 666); + + assertThrowsEquals(() => { + var [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + let [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + const [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + [...x] = g(); + }, 666); + + assertThrowsEquals(() => { + (([...x]) => x)(g()); + }, 666); + + + assertFalse(closed); } diff --git a/deps/v8/test/mjsunit/es6/json.js b/deps/v8/test/mjsunit/es6/json.js index 4c1ada8a86..c049a25ddd 100644 --- a/deps/v8/test/mjsunit/es6/json.js +++ b/deps/v8/test/mjsunit/es6/json.js @@ -9,5 +9,7 @@ function testJSONToString() { assertTrue(desc.configurable); assertFalse(desc.writable); assertEquals("JSON", desc.value); + delete JSON[Symbol.toStringTag]; + assertEquals('[object Object]', "" + JSON); } testJSONToString(); diff --git a/deps/v8/test/mjsunit/es6/legacy-subclassing.js b/deps/v8/test/mjsunit/es6/legacy-subclassing.js deleted file mode 100644 index dbf666d07c..0000000000 --- a/deps/v8/test/mjsunit/es6/legacy-subclassing.js +++ /dev/null @@ -1,38 +0,0 @@ -// 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: --noharmony-species - -// Before Symbol.species was added, ArrayBuffer subclasses constructed -// ArrayBuffers, and Array subclasses constructed Arrays, but TypedArray and -// Promise subclasses constructed an instance of the subclass. - -'use strict'; - -assertEquals(undefined, Symbol.species); - -class MyArray extends Array { } -let myArray = new MyArray(); -assertEquals(MyArray, myArray.constructor); -assertEquals(Array, myArray.map(x => x + 1).constructor); -assertEquals(Array, myArray.concat().constructor); - -class MyUint8Array extends Uint8Array { } -Object.defineProperty(MyUint8Array.prototype, "BYTES_PER_ELEMENT", {value: 1}); -let myTypedArray = new MyUint8Array(3); -assertEquals(MyUint8Array, myTypedArray.constructor); -assertEquals(MyUint8Array, myTypedArray.map(x => x + 1).constructor); - -class MyArrayBuffer extends ArrayBuffer { } -let myBuffer = new MyArrayBuffer(0); -assertEquals(MyArrayBuffer, myBuffer.constructor); -assertEquals(ArrayBuffer, myBuffer.slice().constructor); - -class MyPromise extends Promise { } -let myPromise = new MyPromise(() => {}); -assertEquals(MyPromise, myPromise.constructor); -assertEquals(MyPromise, myPromise.then().constructor); - -// However, subarray instantiates members of the parent class -assertEquals(Uint8Array, myTypedArray.subarray(1).constructor); diff --git a/deps/v8/test/mjsunit/es6/math-log2-log10.js b/deps/v8/test/mjsunit/es6/math-log2-log10.js index b1a7736d71..ea17a79daf 100644 --- a/deps/v8/test/mjsunit/es6/math-log2-log10.js +++ b/deps/v8/test/mjsunit/es6/math-log2-log10.js @@ -57,13 +57,13 @@ assertEqualsDelta(-9.643274665532873e-17, Math.log10(1-Number.EPSILON), 3e-32); var n = -1074; // This loop covers n from -1074 to -1043 for (var lowbits = 1; lowbits <= 0x80000000; lowbits *= 2) { - var x = %_ConstructDouble(0, lowbits); + var x = %ConstructDouble(0, lowbits); assertEquals(n, Math.log2(x)); n++; } // This loop covers n from -1042 to -1023 for (var hibits = 1; hibits <= 0x80000; hibits *= 2) { - var x = %_ConstructDouble(hibits, 0); + var x = %ConstructDouble(hibits, 0); assertEquals(n, Math.log2(x)); n++; } diff --git a/deps/v8/test/mjsunit/es6/math.js b/deps/v8/test/mjsunit/es6/math.js index cb43bd5bd1..dc761d687d 100644 --- a/deps/v8/test/mjsunit/es6/math.js +++ b/deps/v8/test/mjsunit/es6/math.js @@ -9,5 +9,7 @@ function testMathToString() { assertTrue(desc.configurable); assertFalse(desc.writable); assertEquals("Math", desc.value); + delete Math[Symbol.toStringTag]; + assertEquals('[object Object]', "" + Math); } testMathToString(); diff --git a/deps/v8/test/mjsunit/es6/microtask-delivery.js b/deps/v8/test/mjsunit/es6/microtask-delivery.js index 01b971ddc0..6b239bea47 100644 --- a/deps/v8/test/mjsunit/es6/microtask-delivery.js +++ b/deps/v8/test/mjsunit/es6/microtask-delivery.js @@ -25,7 +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-object-observe // Flags: --allow-natives-syntax var ordering = []; @@ -71,22 +70,6 @@ function newPromise(id, fn) { }; } -function newObserver(id, fn, obj) { - var observer = { - value: 1, - recordCounts: [] - }; - - Object.observe(observer, function(records) { - ordering.push('o' + id); - observer.recordCounts.push(records.length); - if (fn) fn(); - }); - - return observer; -} - - (function PromiseThens() { reset(); @@ -98,72 +81,3 @@ function newObserver(id, fn, obj) { assertOrdering(['p1', 'p2', 'p1:1', 'p2:1']); })(); - - -(function ObserversBatch() { - reset(); - - var p1 = newPromise(1); - var p2 = newPromise(2); - var p3 = newPromise(3); - - var ob1 = newObserver(1); - var ob2 = newObserver(2, function() { - ob3.value++; - p3.resolve(); - ob1.value++; - }); - var ob3 = newObserver(3); - - p1.resolve(); - ob1.value++; - p2.resolve(); - ob2.value++; - - assertOrdering(['p1', 'o1', 'o2', 'p2', 'o1', 'o3', 'p3']); - assertArrayValues([1, 1], ob1.recordCounts); - assertArrayValues([1], ob2.recordCounts); - assertArrayValues([1], ob3.recordCounts); -})(); - - -(function ObserversGetAllRecords() { - reset(); - - var p1 = newPromise(1); - var p2 = newPromise(2); - var ob1 = newObserver(1, function() { - ob2.value++; - }); - var ob2 = newObserver(2); - - p1.resolve(); - ob1.value++; - p2.resolve(); - ob2.value++; - - assertOrdering(['p1', 'o1', 'o2', 'p2']); - assertArrayValues([1], ob1.recordCounts); - assertArrayValues([2], ob2.recordCounts); -})(); - - -(function NewObserverDeliveryGetsNewMicrotask() { - reset(); - - var p1 = newPromise(1); - var p2 = newPromise(2); - var ob1 = newObserver(1); - var ob2 = newObserver(2, function() { - ob1.value++; - }); - - p1.resolve(); - ob1.value++; - p2.resolve(); - ob2.value++; - - assertOrdering(['p1', 'o1', 'o2', 'p2', 'o1']); - assertArrayValues([1, 1], ob1.recordCounts); - assertArrayValues([1], ob2.recordCounts); -})(); diff --git a/deps/v8/test/mjsunit/es6/mirror-collections.js b/deps/v8/test/mjsunit/es6/mirror-collections.js index 81a98b8a58..4232ef91cb 100644 --- a/deps/v8/test/mjsunit/es6/mirror-collections.js +++ b/deps/v8/test/mjsunit/es6/mirror-collections.js @@ -88,16 +88,21 @@ assertEquals(1, setMirror.values(1).length); assertSame(o2, values[0]); assertEquals(undefined, values[1]); +function initWeakMap(weakMap) { + weakMap.set(o1, 11); + weakMap.set(new Object(), 22); + weakMap.set(o3, 33); + weakMap.set(new Object(), 44); + var weakMapMirror = debug.MakeMirror(weakMap); + testMapMirror(weakMapMirror); + weakMap.set(new Object(), 55); + assertTrue(weakMapMirror.entries().length <= 5); + return weakMapMirror; +} + // Test the mirror object for WeakMaps var weakMap = new WeakMap(); -weakMap.set(o1, 11); -weakMap.set(new Object(), 22); -weakMap.set(o3, 33); -weakMap.set(new Object(), 44); -var weakMapMirror = debug.MakeMirror(weakMap); -testMapMirror(weakMapMirror); -weakMap.set(new Object(), 55); -assertTrue(weakMapMirror.entries().length <= 5); +var weakMapMirror = initWeakMap(weakMap); gc(); function testWeakMapEntries(weakMapMirror) { @@ -121,18 +126,23 @@ function testWeakMapEntries(weakMapMirror) { testWeakMapEntries(weakMapMirror); +function initWeakSet(weakSet) { + weakSet.add(o1); + weakSet.add(new Object()); + weakSet.add(o2); + weakSet.add(new Object()); + weakSet.add(new Object()); + weakSet.add(o3); + weakSet.delete(o2); + var weakSetMirror = debug.MakeMirror(weakSet); + testSetMirror(weakSetMirror); + assertTrue(weakSetMirror.values().length <= 5); + return weakSetMirror; +} + // Test the mirror object for WeakSets var weakSet = new WeakSet(); -weakSet.add(o1); -weakSet.add(new Object()); -weakSet.add(o2); -weakSet.add(new Object()); -weakSet.add(new Object()); -weakSet.add(o3); -weakSet.delete(o2); -var weakSetMirror = debug.MakeMirror(weakSet); -testSetMirror(weakSetMirror); -assertTrue(weakSetMirror.values().length <= 5); +var weakSetMirror = initWeakSet(weakSet); gc(); function testWeakSetValues(weakSetMirror) { diff --git a/deps/v8/test/mjsunit/es6/no-unicode-regexp-flag.js b/deps/v8/test/mjsunit/es6/no-unicode-regexp-flag.js deleted file mode 100644 index 82d070e92d..0000000000 --- a/deps/v8/test/mjsunit/es6/no-unicode-regexp-flag.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -// Before Unicode RegExps are shipped, we shouldn't have the 'unicode' -// property on RegExp.prototype, or read it from 'flags'. -// mjsunit/es6/regexp-flags tests that the property is there when the -// flag is on. - -// Flags: --no-harmony-unicode-regexps - -'use strict'; - -assertFalse(RegExp.prototype.hasOwnProperty('unicode')); - -// If we were going to be really strict, we could have a test like this, -// with the assertTrue replaced by assertFalse, since flags shouldn't -// Get the 'unicode' property. However, it is probably OK to omit this -// detailed fix. -var x = /a/; -var y = false; -Object.defineProperty(x, 'unicode', { get() { y = true; } }); -assertEquals("", x.flags); -assertTrue(y); diff --git a/deps/v8/test/mjsunit/es6/object-tostring.js b/deps/v8/test/mjsunit/es6/object-tostring.js index 29d07f263a..bc7d9681f8 100644 --- a/deps/v8/test/mjsunit/es6/object-tostring.js +++ b/deps/v8/test/mjsunit/es6/object-tostring.js @@ -15,15 +15,16 @@ var funs = { RegExp: [ RegExp ], Error: [ Error, TypeError, RangeError, SyntaxError, ReferenceError, EvalError, URIError ] -} -for (f in funs) { - for (i in funs[f]) { +}; +for (var f in funs) { + for (var i in funs[f]) { + assertEquals("[object " + f + "]", - Object.prototype.toString.call(new funs[f][i]), - funs[f][i]); + Object.prototype.toString.call(new funs[f][i]), + funs[f][i]); assertEquals("[object Function]", - Object.prototype.toString.call(funs[f][i]), - funs[f][i]); + Object.prototype.toString.call(funs[f][i]), + funs[f][i]); } } @@ -130,11 +131,11 @@ function testObjectToStringPropertyDesc() { } testObjectToStringPropertyDesc(); -function testObjectToStringOwnNonStringValue() { - var obj = Object.defineProperty({}, Symbol.toStringTag, { value: 1 }); +function testObjectToStringOnNonStringValue(obj) { + Object.defineProperty(obj, Symbol.toStringTag, { value: 1 }); assertEquals("[object Object]", ({}).toString.call(obj)); } -testObjectToStringOwnNonStringValue(); +testObjectToStringOnNonStringValue({}); // Proxies @@ -149,11 +150,77 @@ assertTag("Function", new Proxy(() => 42, {})); assertTag("Foo", new Proxy(() => 42, {get() {return "Foo"}})); assertTag("Function", new Proxy(() => 42, {get() {return 666}})); -revocable = Proxy.revocable([], {}); +var revocable = Proxy.revocable([], {}); revocable.revoke(); assertThrows(() => Object.prototype.toString.call(revocable.proxy), TypeError); -handler = {}; +var handler = {}; revocable = Proxy.revocable([], handler); +// The first get() call, i.e., toString() revokes the proxy handler.get = () => revocable.revoke(); +assertEquals("[object Array]", Object.prototype.toString.call(revocable.proxy)); assertThrows(() => Object.prototype.toString.call(revocable.proxy), TypeError); + +revocable = Proxy.revocable([], handler); +handler.get = () => {revocable.revoke(); return "value";}; +assertEquals("[object value]", Object.prototype.toString.call(revocable.proxy)); +assertThrows(() => Object.prototype.toString.call(revocable.proxy), TypeError); + + +revocable = Proxy.revocable(function() {}, handler); +handler.get = () => revocable.revoke(); +assertEquals("[object Function]", Object.prototype.toString.call(revocable.proxy)); +assertThrows(() => Object.prototype.toString.call(revocable.proxy), TypeError); + +function* gen() { yield 1; } + +assertTag("GeneratorFunction", gen); +Object.defineProperty(gen, Symbol.toStringTag, {writable: true}); +gen[Symbol.toStringTag] = "different string"; +assertTag("different string", gen); +gen[Symbol.toStringTag] = 1; +assertTag("Function", gen); + +function overwriteToStringTagWithNonStringValue(tag, obj) { + assertTag(tag, obj); + + Object.defineProperty(obj, Symbol.toStringTag, { + configurable: true, + value: "different string" + }); + assertTag("different string", obj); + + testObjectToStringOnNonStringValue(obj); +} + +overwriteToStringTagWithNonStringValue("global", global); +overwriteToStringTagWithNonStringValue("Generator", gen()); + +var arrayBuffer = new ArrayBuffer(); +overwriteToStringTagWithNonStringValue("ArrayBuffer", arrayBuffer); +overwriteToStringTagWithNonStringValue("DataView", new DataView(arrayBuffer)); + +overwriteToStringTagWithNonStringValue("Int8Array", new Int8Array()); +overwriteToStringTagWithNonStringValue("Uint8Array", new Uint8Array()); +overwriteToStringTagWithNonStringValue("Uint8ClampedArray", + new Uint8ClampedArray()); +overwriteToStringTagWithNonStringValue("Int16Array", new Int16Array()); +overwriteToStringTagWithNonStringValue("Uint16Array", new Uint16Array()); +overwriteToStringTagWithNonStringValue("Int32Array", new Int32Array()); +overwriteToStringTagWithNonStringValue("Uint32Array", new Uint32Array()); +overwriteToStringTagWithNonStringValue("Float32Array", new Float32Array()); +overwriteToStringTagWithNonStringValue("Float64Array", new Float64Array()); + +var set = new Set(); +var map = new Map(); + +overwriteToStringTagWithNonStringValue("Set", set); +overwriteToStringTagWithNonStringValue("Map", map); + +overwriteToStringTagWithNonStringValue("Set Iterator", set[Symbol.iterator]()); +overwriteToStringTagWithNonStringValue("Map Iterator", map[Symbol.iterator]()); + +overwriteToStringTagWithNonStringValue("WeakSet", new WeakSet()); +overwriteToStringTagWithNonStringValue("WeakMap", new WeakMap()); + +overwriteToStringTagWithNonStringValue("Promise", new Promise(function() {})); diff --git a/deps/v8/test/mjsunit/es6/pattern-brand-check.js b/deps/v8/test/mjsunit/es6/pattern-brand-check.js index 9b0c0111ef..2e3229481f 100644 --- a/deps/v8/test/mjsunit/es6/pattern-brand-check.js +++ b/deps/v8/test/mjsunit/es6/pattern-brand-check.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-regexp-subclass - function createNonRegExp(calls) { return { get [Symbol.match]() { diff --git a/deps/v8/test/mjsunit/es6/promise-internal-setter.js b/deps/v8/test/mjsunit/es6/promise-internal-setter.js index 20d361f623..bf0045a98b 100644 --- a/deps/v8/test/mjsunit/es6/promise-internal-setter.js +++ b/deps/v8/test/mjsunit/es6/promise-internal-setter.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: --promise-extra - 'use strict'; Object.defineProperties(Object.prototype, { @@ -16,4 +14,3 @@ class P extends Promise {} P.all([Promise.resolve('ok')]); P.race([Promise.resolve('ok')]); -P.defer(); diff --git a/deps/v8/test/mjsunit/harmony/promise-species.js b/deps/v8/test/mjsunit/es6/promise-species.js index 12244f291a..f6f2e7a1b5 100644 --- a/deps/v8/test/mjsunit/harmony/promise-species.js +++ b/deps/v8/test/mjsunit/es6/promise-species.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-species --allow-natives-syntax +// Flags: --allow-natives-syntax // Test that Promises use @@species appropriately diff --git a/deps/v8/test/mjsunit/es6/promises.js b/deps/v8/test/mjsunit/es6/promises.js index 4eb539cbd5..0af7a882e7 100644 --- a/deps/v8/test/mjsunit/es6/promises.js +++ b/deps/v8/test/mjsunit/es6/promises.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 --promise-extra +// Flags: --allow-natives-syntax // Make sure we don't rely on functions patchable by monkeys. var call = Function.prototype.call.call.bind(Function.prototype.call) @@ -82,6 +82,12 @@ for (var i in globals) { } +function defer(constructor) { + var resolve, reject; + var promise = new constructor((res, rej) => { resolve = res; reject = rej }); + return { promise, resolve, reject }; +} + var asyncAssertsExpected = 0; function assertAsyncRan() { ++asyncAssertsExpected } @@ -141,7 +147,7 @@ function assertAsyncDone(iteration) { })(); (function() { - (new Promise(function() { throw 5 })).chain( + (new Promise(function() { throw 5 })).then( assertUnreachable, function(r) { assertAsync(r === 5, "new-throw") } ) @@ -149,29 +155,21 @@ function assertAsyncDone(iteration) { })(); (function() { - Promise.accept(5); - Promise.accept(5).chain(undefined, assertUnreachable).chain( - function(x) { assertAsync(x === 5, "resolved/chain-nohandler") }, + Promise.resolve(5); + Promise.resolve(5).then(undefined, assertUnreachable).then( + function(x) { assertAsync(x === 5, "resolved/then-nohandler") }, assertUnreachable ) assertAsyncRan() })(); (function() { - Promise.reject(5).chain(assertUnreachable, undefined).chain( - assertUnreachable, - function(r) { assertAsync(r === 5, "rejected/chain-nohandler") } - ) - assertAsyncRan() -})(); - -(function() { - Promise.accept(5).then(undefined, assertUnreachable).chain( + Promise.resolve(5).then(undefined, assertUnreachable).then( function(x) { assertAsync(x === 5, "resolved/then-nohandler-undefined") }, assertUnreachable ) assertAsyncRan() - Promise.accept(6).then(null, assertUnreachable).chain( + Promise.resolve(6).then(null, assertUnreachable).then( function(x) { assertAsync(x === 6, "resolved/then-nohandler-null") }, assertUnreachable ) @@ -179,34 +177,9 @@ function assertAsyncDone(iteration) { })(); (function() { - Promise.reject(5).then(assertUnreachable, undefined).chain( - assertUnreachable, - function(r) { assertAsync(r === 5, "rejected/then-nohandler-undefined") } - ) - assertAsyncRan() - Promise.reject(6).then(assertUnreachable, null).chain( - assertUnreachable, - function(r) { assertAsync(r === 6, "rejected/then-nohandler-null") } - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - // Note: Chain now has then-style semantics, here and in future tests. - p3.chain( - function(x) { assertAsync(x === 5, "resolved/chain") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) p3.then( function(x) { assertAsync(x === 5, "resolved/then") }, assertUnreachable @@ -216,19 +189,8 @@ function assertAsyncDone(iteration) { (function() { var p1 = Promise.reject(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain( - assertUnreachable, - function(x) { assertAsync(x === 5, "rejected/chain") } - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.reject(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) p3.then( assertUnreachable, function(x) { assertAsync(x === 5, "rejected/then") } @@ -237,87 +199,21 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { return x }, assertUnreachable).chain( - function(x) { assertAsync(x === 5, "resolved/chain/chain") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { return x }, assertUnreachable).then( - function(x) { assertAsync(x === 5, "resolved/chain/then") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { return 6 }, assertUnreachable).chain( - function(x) { assertAsync(x === 6, "resolved/chain/chain2") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { return 6 }, assertUnreachable).then( - function(x) { assertAsync(x === 6, "resolved/chain/then2") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.then(function(x) { return x + 1 }, assertUnreachable).chain( - function(x) { assertAsync(x === 6, "resolved/then/chain") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.then(function(x) { return x + 1 }, assertUnreachable).then( - function(x) { assertAsync(x === 6, "resolved/then/then") }, - assertUnreachable - ) - assertAsyncRan() -})(); - -(function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.then(function(x){ return Promise.accept(x+1) }, assertUnreachable).chain( - function(x) { assertAsync(x === 6, "resolved/then/chain2") }, + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then(function(x) { return x }, assertUnreachable).then( + function(x) { assertAsync(x === 5, "resolved/then/then") }, assertUnreachable ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.then(function(x) { return Promise.accept(x+1) }, assertUnreachable).then( + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then(function(x){ return Promise.resolve(x+1) }, assertUnreachable).then( function(x) { assertAsync(x === 6, "resolved/then/then2") }, assertUnreachable ) @@ -325,42 +221,42 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { throw 6 }, assertUnreachable).chain( + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then(function(x) { throw 6 }, assertUnreachable).then( assertUnreachable, - function(x) { assertAsync(x === 6, "resolved/chain-throw/chain") } + function(x) { assertAsync(x === 6, "resolved/then-throw/then") } ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain(function(x) { throw 6 }, assertUnreachable).then( + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then(function(x) { throw 6 }, assertUnreachable).then( assertUnreachable, - function(x) { assertAsync(x === 6, "resolved/chain-throw/then") } + function(x) { assertAsync(x === 6, "resolved/then-throw/then") } ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.then(function(x) { throw 6 }, assertUnreachable).chain( + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then(function(x) { throw 6 }, assertUnreachable).then( assertUnreachable, - function(x) { assertAsync(x === 6, "resolved/then-throw/chain") } + function(x) { assertAsync(x === 6, "resolved/then-throw/then") } ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) p3.then(function(x) { throw 6 }, assertUnreachable).then( assertUnreachable, function(x) { assertAsync(x === 6, "resolved/then-throw/then") } @@ -369,20 +265,20 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) + var p1 = Promise.resolve(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) - p3.chain( - function(x) { assertAsync(x === 5, "resolved/thenable/chain") }, + var p3 = Promise.resolve(p2) + p3.then( + function(x) { assertAsync(x === 5, "resolved/thenable/then") }, assertUnreachable ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) + var p1 = Promise.resolve(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) + var p3 = Promise.resolve(p2) p3.then( function(x) { assertAsync(x === 5, "resolved/thenable/then") }, assertUnreachable @@ -393,10 +289,10 @@ function assertAsyncDone(iteration) { (function() { var p1 = Promise.reject(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) - p3.chain( + var p3 = Promise.resolve(p2) + p3.then( assertUnreachable, - function(x) { assertAsync(x === 5, "rejected/thenable/chain") } + function(x) { assertAsync(x === 5, "rejected/thenable/then") } ) assertAsyncRan() })(); @@ -404,7 +300,7 @@ function assertAsyncDone(iteration) { (function() { var p1 = Promise.reject(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) + var p3 = Promise.resolve(p2) p3.then( assertUnreachable, function(x) { assertAsync(x === 5, "rejected/thenable/then") } @@ -413,12 +309,12 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain( - function(x) { assertAsync(x === 5, "chain/resolve") }, + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then( + function(x) { assertAsync(x === 5, "then/resolve") }, assertUnreachable ) deferred.resolve(5) @@ -426,7 +322,7 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = Promise.resolve(p1) var p3 = Promise.resolve(p2) @@ -439,23 +335,23 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) - p3.chain( + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) + p3.then( assertUnreachable, - function(x) { assertAsync(x === 5, "chain/reject") } + function(x) { assertAsync(x === 5, "then/reject") } ) deferred.reject(5) assertAsyncRan() })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise - var p2 = Promise.accept(p1) - var p3 = Promise.accept(p2) + var p2 = Promise.resolve(p1) + var p3 = Promise.resolve(p2) p3.then( assertUnreachable, function(x) { assertAsync(x === 5, "then/reject") } @@ -465,7 +361,7 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = p1.then(1, 2) p2.then( @@ -477,7 +373,7 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = p1.then(1, 2) p2.then( @@ -489,12 +385,12 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) - p3.chain( - function(x) { assertAsync(x === 5, "chain/resolve/thenable") }, + var p3 = Promise.resolve(p2) + p3.then( + function(x) { assertAsync(x === 5, "then/resolve/thenable") }, assertUnreachable ) deferred.resolve(5) @@ -502,10 +398,10 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) + var p3 = Promise.resolve(p2) p3.then( function(x) { assertAsync(x === 5, "then/resolve/thenable") }, assertUnreachable @@ -515,23 +411,23 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) - p3.chain( + var p3 = Promise.resolve(p2) + p3.then( assertUnreachable, - function(x) { assertAsync(x === 5, "chain/reject/thenable") } + function(x) { assertAsync(x === 5, "then/reject/thenable") } ) deferred.reject(5) assertAsyncRan() })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var p3 = Promise.accept(p2) + var p3 = Promise.resolve(p2) p3.then( assertUnreachable, function(x) { assertAsync(x === 5, "then/reject/thenable") } @@ -541,12 +437,12 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var deferred = Promise.defer() + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var deferred = defer(Promise) var p3 = deferred.promise - p3.chain( - function(x) { assertAsync(x === 5, "chain/resolve2") }, + p3.then( + function(x) { assertAsync(x === 5, "then/resolve2") }, assertUnreachable ) deferred.resolve(p2) @@ -554,9 +450,9 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var deferred = Promise.defer() + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var deferred = defer(Promise) var p3 = deferred.promise p3.then( function(x) { assertAsync(x === 5, "then/resolve2") }, @@ -567,22 +463,22 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var deferred = Promise.defer() + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var deferred = defer(Promise) var p3 = deferred.promise - p3.chain( + p3.then( assertUnreachable, - function(x) { assertAsync(x === 5, "chain/reject2") } + function(x) { assertAsync(x === 5, "then/reject2") } ) deferred.reject(5) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(5) - var p2 = Promise.accept(p1) - var deferred = Promise.defer() + var p1 = Promise.resolve(5) + var p2 = Promise.resolve(p1) + var deferred = defer(Promise) var p3 = deferred.promise p3.then( assertUnreachable, @@ -593,12 +489,12 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) + var p1 = Promise.resolve(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var deferred = Promise.defer() + var deferred = defer(Promise) var p3 = deferred.promise - p3.chain( - function(x) { assertAsync(x === 5, "chain/resolve/thenable2") }, + p3.then( + function(x) { assertAsync(x === 5, "then/resolve/thenable2") }, assertUnreachable ) deferred.resolve(p2) @@ -606,9 +502,9 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(5) + var p1 = Promise.resolve(5) var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} - var deferred = Promise.defer() + var deferred = defer(Promise) var p3 = deferred.promise p3.then( function(x) { assertAsync(x === 5, "then/resolve/thenable2") }, @@ -619,19 +515,19 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(0) - var p2 = p1.chain(function(x) { return p2 }, assertUnreachable) - p2.chain( + var p1 = Promise.resolve(0) + var p2 = p1.then(function(x) { return p2 }, assertUnreachable) + p2.then( assertUnreachable, - function(r) { assertAsync(r instanceof TypeError, "cyclic/chain") } + function(r) { assertAsync(r instanceof TypeError, "cyclic/then") } ) assertAsyncRan() })(); (function() { - var p1 = Promise.accept(0) + var p1 = Promise.resolve(0) var p2 = p1.then(function(x) { return p2 }, assertUnreachable) - p2.chain( + p2.then( assertUnreachable, function(r) { assertAsync(r instanceof TypeError, "cyclic/then") } ) @@ -639,10 +535,10 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p = deferred.promise deferred.resolve(p) - p.chain( + p.then( assertUnreachable, function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") } ) @@ -650,7 +546,7 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p = deferred.promise deferred.resolve(p) p.then( @@ -661,7 +557,7 @@ function assertAsyncDone(iteration) { })(); (function() { - Promise.all([]).chain( + Promise.all([]).then( function(x) { assertAsync(x.length === 0, "all/resolve/empty") }, assertUnreachable ) @@ -670,7 +566,7 @@ function assertAsyncDone(iteration) { (function() { function testPromiseAllNonIterable(value) { - Promise.all(value).chain( + Promise.all(value).then( assertUnreachable, function(r) { assertAsync(r instanceof TypeError, 'all/non iterable'); @@ -684,14 +580,14 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer(); + var deferred = defer(Promise); var p = deferred.promise; function* f() { yield 1; yield p; yield 3; } - Promise.all(f()).chain( + Promise.all(f()).then( function(x) { assertAsync(x.length === 3, "all/resolve/iterable"); assertAsync(x[0] === 1, "all/resolve/iterable/0"); @@ -708,13 +604,13 @@ function assertAsyncDone(iteration) { (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise - Promise.all([p1, p2, p3]).chain( + Promise.all([p1, p2, p3]).then( function(x) { assertAsync(x.length === 3, "all/resolve") assertAsync(x[0] === 1, "all/resolve/0") @@ -733,11 +629,11 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise - var p2 = Promise.accept(2) - var p3 = Promise.defer().promise - Promise.all([p1, p2, p3]).chain( + var p2 = Promise.resolve(2) + var p3 = defer(Promise).promise + Promise.all([p1, p2, p3]).then( assertUnreachable, assertUnreachable ) @@ -745,13 +641,13 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise - Promise.all([p1, p2, p3]).chain( + Promise.all([p1, p2, p3]).then( assertUnreachable, function(x) { assertAsync(x === 2, "all/reject") } ) @@ -786,7 +682,7 @@ function assertAsyncDone(iteration) { configurable: true }); - Promise.all(3).chain( + Promise.all(3).then( function(x) { assertAsync(x.length === 3, "all/iterable/number/length"); assertAsync(x[0] === 0, "all/iterable/number/0"); @@ -807,17 +703,17 @@ function assertAsyncDone(iteration) { (function() { - Promise.race([]).chain( + Promise.race([]).then( assertUnreachable, assertUnreachable ) })(); (function() { - var p1 = Promise.accept(1) - var p2 = Promise.accept(2) - var p3 = Promise.accept(3) - Promise.race([p1, p2, p3]).chain( + var p1 = Promise.resolve(1) + var p2 = Promise.resolve(2) + var p3 = Promise.resolve(3) + Promise.race([p1, p2, p3]).then( function(x) { assertAsync(x === 1, "resolved/one") }, assertUnreachable ) @@ -825,10 +721,10 @@ function assertAsyncDone(iteration) { })(); (function() { - var p1 = Promise.accept(1) - var p2 = Promise.accept(2) - var p3 = Promise.accept(3) - Promise.race([0, p1, p2, p3]).chain( + var p1 = Promise.resolve(1) + var p2 = Promise.resolve(2) + var p3 = Promise.resolve(3) + Promise.race([0, p1, p2, p3]).then( function(x) { assertAsync(x === 0, "resolved-const/one") }, assertUnreachable ) @@ -836,13 +732,13 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise - Promise.race([p1, p2, p3]).chain( + Promise.race([p1, p2, p3]).then( function(x) { assertAsync(x === 3, "one/resolve") }, assertUnreachable ) @@ -852,11 +748,11 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred = Promise.defer() + var deferred = defer(Promise) var p1 = deferred.promise - var p2 = Promise.accept(2) - var p3 = Promise.defer().promise - Promise.race([p1, p2, p3]).chain( + var p2 = Promise.resolve(2) + var p3 = defer(Promise).promise + Promise.race([p1, p2, p3]).then( function(x) { assertAsync(x === 2, "resolved/one") }, assertUnreachable ) @@ -865,13 +761,13 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise - Promise.race([p1, p2, p3]).chain( + Promise.race([p1, p2, p3]).then( function(x) { assertAsync(x === 3, "one/resolve/reject") }, assertUnreachable ) @@ -881,13 +777,13 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise - Promise.race([p1, p2, p3]).chain( + Promise.race([p1, p2, p3]).then( assertUnreachable, function(x) { assertAsync(x === 3, "one/reject/resolve") } ) @@ -899,7 +795,7 @@ function assertAsyncDone(iteration) { (function() { function testPromiseRaceNonIterable(value) { - Promise.race(value).chain( + Promise.race(value).then( assertUnreachable, function(r) { assertAsync(r instanceof TypeError, 'race/non iterable'); @@ -914,18 +810,18 @@ function assertAsyncDone(iteration) { (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise function* f() { yield p1; yield p2; yield p3; } - Promise.race(f()).chain( + Promise.race(f()).then( function(x) { assertAsync(x === 3, "race/iterable/resolve/reject") }, assertUnreachable ) @@ -935,18 +831,18 @@ function assertAsyncDone(iteration) { })(); (function() { - var deferred1 = Promise.defer() + var deferred1 = defer(Promise) var p1 = deferred1.promise - var deferred2 = Promise.defer() + var deferred2 = defer(Promise) var p2 = deferred2.promise - var deferred3 = Promise.defer() + var deferred3 = defer(Promise) var p3 = deferred3.promise function* f() { yield p1; yield p2; yield p3; } - Promise.race(f()).chain( + Promise.race(f()).then( assertUnreachable, function(x) { assertAsync(x === 3, "race/iterable/reject/resolve") } ) @@ -980,7 +876,7 @@ function assertAsyncDone(iteration) { configurable: true }); - Promise.race(3).chain( + Promise.race(3).then( function(x) { assertAsync(x === 0, "race/iterable/number"); }, @@ -1014,18 +910,18 @@ function assertAsyncDone(iteration) { } MyPromise.prototype.__proto__ = Promise.prototype - MyPromise.prototype.chain = function(resolve, reject) { + MyPromise.prototype.then = function(resolve, reject) { log += "c" - return call(this.__proto__.__proto__.chain, this, resolve, reject) + return call(this.__proto__.__proto__.then, this, resolve, reject) } log = "" var p1 = new MyPromise(function(resolve, reject) { resolve(1) }) var p2 = new MyPromise(function(resolve, reject) { reject(2) }) - var d3 = MyPromise.defer() + var d3 = defer(MyPromise) assertTrue(d3.promise instanceof Promise, "subclass/instance") assertTrue(d3.promise instanceof MyPromise, "subclass/instance-my3") - assertTrue(log === "nx1nr2dn", "subclass/create") + assertTrue(log === "nx1nr2n", "subclass/create") log = "" var p4 = MyPromise.resolve(4) @@ -1038,21 +934,21 @@ function assertAsyncDone(iteration) { assertTrue(log === "nx4nr5x3", "subclass/resolve") log = "" - var d6 = MyPromise.defer() - d6.promise.chain(function(x) { + var d6 = defer(MyPromise) + d6.promise.then(function(x) { return new Promise(function(resolve) { resolve(x) }) - }).chain(function() {}) + }).then(function() {}) d6.resolve(6) - assertTrue(log === "dncncnx6", "subclass/chain") + assertTrue(log === "ncncnx6", "subclass/then") log = "" - Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) + Promise.all([11, Promise.resolve(12), 13, MyPromise.resolve(14), 15, 16]) assertTrue(log === "nx14", "subclass/all/arg") log = "" - MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) - assertTrue(log === "nx24nnx21nnx[object Promise]nnx23nnnx25nnx26n", + MyPromise.all([21, Promise.resolve(22), 23, MyPromise.resolve(24), 25, 26]) + assertTrue(log === "nx24nnx21cnnx[object Promise]cnnx23cncnnx25cnnx26cn", "subclass/all/self") })(); diff --git a/deps/v8/test/mjsunit/es6/proxies-for.js b/deps/v8/test/mjsunit/es6/proxies-for.js index 5b818453a9..2b3060b17e 100644 --- a/deps/v8/test/mjsunit/es6/proxies-for.js +++ b/deps/v8/test/mjsunit/es6/proxies-for.js @@ -151,7 +151,7 @@ function keys(object) { object.__proto__ = proxy; assertEquals(["0"], keys(object)); - // The Proxy doesn't set his ownKeys enumerable. + // The Proxy doesn't set its ownKeys enumerable. delete object[0]; assertEquals([], keys(object)); @@ -209,10 +209,15 @@ function keys(object) { assertThrowsEquals(() => {keys(proxy)}, "error"); })(); - -(function () { - var symbol = Symbol(); - var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }}); - assertEquals(["1","2"], Object.getOwnPropertyNames(p)); - assertEquals([symbol], Object.getOwnPropertySymbols(p)); +(function testNestedProxy() { + var handler = { + ownKeys() { + return ['c']; + }, + getOwnPropertyDescriptor() { return {configurable: true, enumerable: true } } + } + var proxy = new Proxy({}, handler); + var proxy2 = new Proxy(proxy, {}); + assertEquals(['c'], keys(proxy)); + assertEquals(['c'], keys(proxy2)); })(); diff --git a/deps/v8/test/mjsunit/es6/proxies-global-reference.js b/deps/v8/test/mjsunit/es6/proxies-global-reference.js index 975d7f75fb..1e3d3beb86 100644 --- a/deps/v8/test/mjsunit/es6/proxies-global-reference.js +++ b/deps/v8/test/mjsunit/es6/proxies-global-reference.js @@ -5,8 +5,5 @@ var failing_proxy = new Proxy({}, new Proxy({}, { get() { throw "No trap should fire" }})); -Object.setPrototypeOf(Object.prototype, failing_proxy); -assertThrows(()=>a, TypeError); - -Object.setPrototypeOf(this, failing_proxy); -assertThrows(()=>a, TypeError); +assertThrows(() => Object.setPrototypeOf(Object.prototype, failing_proxy), TypeError); +assertThrows(()=>a, ReferenceError); diff --git a/deps/v8/test/mjsunit/es6/proxies-json.js b/deps/v8/test/mjsunit/es6/proxies-json.js index d48d5390f6..6b40e3ee7d 100644 --- a/deps/v8/test/mjsunit/es6/proxies-json.js +++ b/deps/v8/test/mjsunit/es6/proxies-json.js @@ -35,7 +35,10 @@ function testStringify(expected, object) { // Test fast case that bails out to slow case. assertEquals(expected, JSON.stringify(object)); // Test slow case. - assertEquals(expected, JSON.stringify(object, undefined, 0)); + assertEquals(expected, JSON.stringify(object, (key, value) => value)); + // Test gap. + assertEquals(JSON.stringify(object, null, "="), + JSON.stringify(object, (key, value) => value, "=")); } @@ -67,6 +70,7 @@ testStringify('[1,null]', [1, proxy_fun]); var parent1a = { b: proxy1 }; testStringify('{"b":{"a":"A","b":"B","c":"C"}}', parent1a); +testStringify('{"b":{"a":"A","b":"B","c":"C"}}', parent1a); var parent1b = { a: 123, b: proxy1, c: true }; testStringify('{"a":123,"b":{"a":"A","b":"B","c":"C"},"c":true}', parent1b); @@ -503,3 +507,56 @@ for (var i in log) assertSame(target, log[i][1]); assertEquals(["get", target, "length", proxy], log[0]); assertEquals(["get", target, "0", proxy], log[1]); assertEquals(["deleteProperty", target, "0"], log[2]); + +proxy = new Proxy([], { + get: function(target, property) { + if (property == "length") return 7; + return 0; + }, +}); +assertEquals('[[0,0,0,0,0,0,0]]', JSON.stringify([proxy])); + +proxy = new Proxy([], { + get: function(target, property) { + if (property == "length") return 1E40; + return 0; + }, +}); +assertThrows(() => JSON.stringify([proxy]), RangeError); + +log = []; +proxy = new Proxy({}, { + ownKeys: function() { + log.push("ownKeys"); + return ["0", "a", "b"]; + }, + get: function(target, property) { + log.push("get " + property); + return property.toUpperCase(); + }, + getOwnPropertyDescriptor: function(target, property) { + log.push("descriptor " + property); + return {enumerable: true, configurable: true}; + }, + isExtensible: assertUnreachable, + has: assertUnreachable, + getPrototypeOf: assertUnreachable, + setPrototypeOf: assertUnreachable, + preventExtensions: assertUnreachable, + setPrototypeOf: assertUnreachable, + defineProperty: assertUnreachable, + set: assertUnreachable, + deleteProperty: assertUnreachable, + apply: assertUnreachable, + construct: assertUnreachable, +}); + +assertEquals('[{"0":"0","a":"A","b":"B"}]', JSON.stringify([proxy])); +assertEquals(['get toJSON', + 'ownKeys', + 'descriptor 0', + 'descriptor a', + 'descriptor b', + 'get 0', + 'get a', + 'get b'], log); diff --git a/deps/v8/test/mjsunit/es6/proxies-keys.js b/deps/v8/test/mjsunit/es6/proxies-keys.js index 7344032aaf..4781ae37f4 100644 --- a/deps/v8/test/mjsunit/es6/proxies-keys.js +++ b/deps/v8/test/mjsunit/es6/proxies-keys.js @@ -2,38 +2,82 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var target = { - target: 1 -}; -target.__proto__ = { - target_proto: 2 -}; - -var handler = { - ownKeys: function(target) { - return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"]; - }, - getOwnPropertyDescriptor: function(target, name) { - if (name == "non-enum") return {configurable: true}; - if (name == "not-found") return undefined; - return {enumerable: true, configurable: true}; +(function testObjectKeys() { + var target = { + target: 1 + }; + target.__proto__ = { + target_proto: 2 + }; + + var handler = { + ownKeys: function(target) { + return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"]; + }, + getOwnPropertyDescriptor: function(target, name) { + if (name == "non-enum") return {configurable: true}; + if (name == "not-found") return undefined; + return {enumerable: true, configurable: true}; + } } -} -var proxy = new Proxy(target, handler); + var proxy = new Proxy(target, handler); + + // Object.keys() ignores symbols and non-enumerable keys. + assertEquals(["foo", "bar"], Object.keys(proxy)); + + // Edge case: no properties left after filtering. + handler.getOwnPropertyDescriptor = undefined; + assertEquals([], Object.keys(proxy)); + + // Throwing shouldn't crash. + handler.getOwnPropertyDescriptor = function() { throw new Number(1); }; + assertThrows(() => Object.keys(proxy), Number); + + // Fall through to getOwnPropertyDescriptor if there is no trap. + handler.ownKeys = undefined; + assertThrows(() => Object.keys(proxy), Number); + + // Fall through to target if there is no trap. + handler.getOwnPropertyDescriptor = undefined; + assertEquals(["target"], Object.keys(proxy)); + assertEquals(["target"], Object.keys(target)); -// Object.keys() ignores symbols and non-enumerable keys. -assertEquals(["foo", "bar"], Object.keys(proxy)); + var proxy2 = new Proxy(proxy, {}); + assertEquals(["target"], Object.keys(proxy2)); +})(); -// Edge case: no properties left after filtering. -handler.getOwnPropertyDescriptor = undefined; -assertEquals([], Object.keys(proxy)); +(function testForSymbols() { + var symbol = Symbol(); + var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }}); + assertEquals(["1","2"], Object.getOwnPropertyNames(p)); + assertEquals([symbol], Object.getOwnPropertySymbols(p)); +})(); -// Throwing shouldn't crash. -handler.getOwnPropertyDescriptor = function() { throw new Number(1); }; -assertThrows("Object.keys(proxy)", Number); +(function testNoProxyTraps() { + var test_sym = Symbol("sym1"); + var test_sym2 = Symbol("sym2"); + var target = { + one: 1, + two: 2, + [test_sym]: 4, + 0: 0, + }; + Object.defineProperty( + target, "non-enum", + { enumerable: false, value: "nope", configurable: true, writable: true }); + target.__proto__ = { + target_proto: 3, + 1: 1, + [test_sym2]: 5 + }; + Object.defineProperty( + target.__proto__, "non-enum2", + { enumerable: false, value: "nope", configurable: true, writable: true }); + var proxy = new Proxy(target, {}); -// Fall through to target if there is no trap. -handler.ownKeys = undefined; -assertEquals(["target"], Object.keys(proxy)); -assertEquals(["target"], Object.keys(target)); + assertEquals(["0", "one", "two"], Object.keys(proxy)); + assertEquals(["0", "one", "two", "non-enum"], + Object.getOwnPropertyNames(proxy)); + assertEquals([test_sym], Object.getOwnPropertySymbols(proxy)); +})(); diff --git a/deps/v8/test/mjsunit/es6/reflect-construct.js b/deps/v8/test/mjsunit/es6/reflect-construct.js index b37f876e94..4661b4093b 100644 --- a/deps/v8/test/mjsunit/es6/reflect-construct.js +++ b/deps/v8/test/mjsunit/es6/reflect-construct.js @@ -1,6 +1,8 @@ // Copyright 2014 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-unsafe-function-constructor (function testReflectConstructArity() { diff --git a/deps/v8/test/mjsunit/es6/reflect-define-property.js b/deps/v8/test/mjsunit/es6/reflect-define-property.js index b19c5aa6ff..8eb3f6580e 100644 --- a/deps/v8/test/mjsunit/es6/reflect-define-property.js +++ b/deps/v8/test/mjsunit/es6/reflect-define-property.js @@ -441,53 +441,6 @@ try { } -// 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 diff --git a/deps/v8/test/mjsunit/es6/reflect.js b/deps/v8/test/mjsunit/es6/reflect.js index ee272b0fc7..d597a78901 100644 --- a/deps/v8/test/mjsunit/es6/reflect.js +++ b/deps/v8/test/mjsunit/es6/reflect.js @@ -541,6 +541,13 @@ function prepare(target) { [s2]: 0, "-1": 0, "88": 0, "aaa": 0 }; assertEquals(["0", "42", "88", "bla", "-1", "aaa", s1, s2], Reflect.ownKeys(obj)); + // Force dict-mode elements. + delete obj[0]; + assertEquals(["42", "88", "bla", "-1", "aaa", s1, s2], + Reflect.ownKeys(obj)); + // Force dict-mode properties. + delete obj["bla"]; + assertEquals(["42", "88", "-1", "aaa", s1, s2], Reflect.ownKeys(obj)); })(); diff --git a/deps/v8/test/mjsunit/es6/regexp-constructor.js b/deps/v8/test/mjsunit/es6/regexp-constructor.js index 559ac00cd0..b685ff2991 100644 --- a/deps/v8/test/mjsunit/es6/regexp-constructor.js +++ b/deps/v8/test/mjsunit/es6/regexp-constructor.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-regexp-subclass - "use strict"; function should_not_be_called() { diff --git a/deps/v8/test/mjsunit/es6/regexp-flags.js b/deps/v8/test/mjsunit/es6/regexp-flags.js index 480222d95a..2bcccfa760 100644 --- a/deps/v8/test/mjsunit/es6/regexp-flags.js +++ b/deps/v8/test/mjsunit/es6/regexp-flags.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-unicode-regexps - var r1 = /abc/gi; assertEquals("abc", r1.source); assertTrue(r1.global); diff --git a/deps/v8/test/mjsunit/es6/regress/regress-3750.js b/deps/v8/test/mjsunit/es6/regress/regress-3750.js deleted file mode 100644 index 10509bff51..0000000000 --- a/deps/v8/test/mjsunit/es6/regress/regress-3750.js +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2014 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-object-observe - -'use strict'; -class Example { } -Object.observe(Example.prototype, function(){}); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4482.js b/deps/v8/test/mjsunit/es6/regress/regress-4482.js index 2472b466ab..d813d21300 100644 --- a/deps/v8/test/mjsunit/harmony/regress/regress-4482.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-4482.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-sloppy assertEquals("function", (function f() { f = 42; return typeof f })()); assertEquals("function", diff --git a/deps/v8/test/mjsunit/es6/regress/regress-468661.js b/deps/v8/test/mjsunit/es6/regress/regress-468661.js index 4a42350930..4a58a71d30 100644 --- a/deps/v8/test/mjsunit/es6/regress/regress-468661.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-468661.js @@ -9,7 +9,8 @@ var exception = null; var break_count = 0; var expected_values = - [ReferenceError, undefined, 0, 0, 0, 0, 1, ReferenceError, ReferenceError]; + [ReferenceError, undefined, 0, 0, 0, 0, 1, + ReferenceError, ReferenceError]; function listener(event, exec_state, event_data, data) { try { @@ -39,7 +40,6 @@ function listener(event, exec_state, event_data, data) { assertTrue(v instanceof ReferenceError); } else { assertSame(expected_values[break_count], v); - } ++break_count; diff --git a/deps/v8/test/mjsunit/es6/regress/regress-cr372788.js b/deps/v8/test/mjsunit/es6/regress/regress-cr372788.js index 3144b39830..c157a7e79f 100644 --- a/deps/v8/test/mjsunit/es6/regress/regress-cr372788.js +++ b/deps/v8/test/mjsunit/es6/regress/regress-cr372788.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 --promise-extra +// Flags: --allow-natives-syntax var x = 0; var y = 0; @@ -38,7 +38,7 @@ for (var i = 0; i < 3; ++i) { assertEquals(0, x); (function check() { - Promise.resolve().chain(function() { + Promise.resolve().then(function() { // Delay check until all handlers have run. if (y < 3) check(); else assertEquals(6, x); }).catch(function(e) { %AbortJS("FAILURE: " + e) }); diff --git a/deps/v8/test/mjsunit/harmony/species.js b/deps/v8/test/mjsunit/es6/species.js index da1df4331f..39156a4a2e 100644 --- a/deps/v8/test/mjsunit/harmony/species.js +++ b/deps/v8/test/mjsunit/es6/species.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-species - // Test the ES2015 @@species feature 'use strict'; diff --git a/deps/v8/test/mjsunit/es6/spread-call-new-class.js b/deps/v8/test/mjsunit/es6/spread-call-new-class.js index 1fdf25b616..de88cff5d1 100644 --- a/deps/v8/test/mjsunit/es6/spread-call-new-class.js +++ b/deps/v8/test/mjsunit/es6/spread-call-new-class.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-sloppy - (function testConstructClassStrict() { "use strict"; diff --git a/deps/v8/test/mjsunit/es6/spread-call-super-property.js b/deps/v8/test/mjsunit/es6/spread-call-super-property.js index b298a69aa1..a85ea41638 100644 --- a/deps/v8/test/mjsunit/es6/spread-call-super-property.js +++ b/deps/v8/test/mjsunit/es6/spread-call-super-property.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-sloppy - (function testCallSuperPropertyStrict() { "use strict"; class BaseClass { diff --git a/deps/v8/test/mjsunit/harmony/string-match.js b/deps/v8/test/mjsunit/es6/string-match.js index 25a3ca2fd1..2c7affe454 100644 --- a/deps/v8/test/mjsunit/harmony/string-match.js +++ b/deps/v8/test/mjsunit/es6/string-match.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-regexp-subclass - var pattern = {}; pattern[Symbol.match] = function(string) { return string.length; diff --git a/deps/v8/test/mjsunit/harmony/string-replace.js b/deps/v8/test/mjsunit/es6/string-replace.js index 208c483fd0..0beb57a536 100644 --- a/deps/v8/test/mjsunit/harmony/string-replace.js +++ b/deps/v8/test/mjsunit/es6/string-replace.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-regexp-subclass - var pattern = { [Symbol.replace]: (string, newValue) => string + newValue }; diff --git a/deps/v8/test/mjsunit/es6/string-search.js b/deps/v8/test/mjsunit/es6/string-search.js index dc029826ad..cbdf33d692 100644 --- a/deps/v8/test/mjsunit/es6/string-search.js +++ b/deps/v8/test/mjsunit/es6/string-search.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-regexp-subclass - var pattern = {}; pattern[Symbol.search] = function(string) { return string.length; diff --git a/deps/v8/test/mjsunit/harmony/string-split.js b/deps/v8/test/mjsunit/es6/string-split.js index 1240d84bc1..8ca655cad9 100644 --- a/deps/v8/test/mjsunit/harmony/string-split.js +++ b/deps/v8/test/mjsunit/es6/string-split.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-regexp-subclass - var pattern = {}; var limit = { value: 3 }; pattern[Symbol.split] = function(string, limit) { diff --git a/deps/v8/test/mjsunit/es6/super.js b/deps/v8/test/mjsunit/es6/super.js index a2ba1e863b..4c80ce7711 100644 --- a/deps/v8/test/mjsunit/es6/super.js +++ b/deps/v8/test/mjsunit/es6/super.js @@ -3,7 +3,6 @@ // found in the LICENSE file. // Flags: --allow-natives-syntax -// Flags: --harmony-sloppy (function TestSuperNamedLoads() { function Base() { } diff --git a/deps/v8/test/mjsunit/es6/symbols.js b/deps/v8/test/mjsunit/es6/symbols.js index 9bac41f863..a21afb3770 100644 --- a/deps/v8/test/mjsunit/es6/symbols.js +++ b/deps/v8/test/mjsunit/es6/symbols.js @@ -555,7 +555,9 @@ TestContext(); function TestStringify(expected, input) { assertEquals(expected, JSON.stringify(input)); - assertEquals(expected, JSON.stringify(input, null, 0)); + assertEquals(expected, JSON.stringify(input, (key, value) => value)); + assertEquals(JSON.stringify(input, null, "="), + JSON.stringify(input, (key, value) => value, "=")); } TestStringify(undefined, Symbol("a")); diff --git a/deps/v8/test/mjsunit/es6/tail-call-megatest.js b/deps/v8/test/mjsunit/es6/tail-call-megatest.js index 1de8ec6c8e..3d2ecb8daa 100644 --- a/deps/v8/test/mjsunit/es6/tail-call-megatest.js +++ b/deps/v8/test/mjsunit/es6/tail-call-megatest.js @@ -10,6 +10,7 @@ Error.prepareStackTrace = (error,stack) => { return error.message + "\n at " + stack.join("\n at "); } +var verbose = typeof(arguments) !== "undefined" && arguments.indexOf("-v") >= 0; function checkStackTrace(expected) { var e = new Error(); @@ -340,32 +341,32 @@ function run_tests(shard) { return source; } - var f_args_variants = ["", "1", "1, 2"]; - var g_args_variants = ["", "10", "10, 20"]; + var f_args_variants = [/*"", "1",*/ "1, 2"]; + var g_args_variants = [/*"", "10",*/ "10, 20"]; var f_inlinable_variants = [true, false]; var g_inlinable_variants = [true, false]; // This is to avoid bailing out because of referencing new.target. - var check_new_target_variants = [true, false]; + var check_new_target_variants = [/*true,*/ false]; var deopt_mode_variants = ["none", "f", "g", "test"]; var f_variants = [ f_cfg_sloppy, f_cfg_strict, f_cfg_bound, f_cfg_proxy, - f_cfg_possibly_eval, +// f_cfg_possibly_eval, ]; var g_variants = [ g_cfg_normal, - g_cfg_reflect_apply, +// g_cfg_reflect_apply, g_cfg_function_apply, - g_cfg_function_apply_arguments_object, +// g_cfg_function_apply_arguments_object, g_cfg_function_call, ]; var test_warmup_counts = [0, 1, 2]; var iter = 0; var tests_executed = 0; - if (shard !== undefined) { + if (verbose && shard !== undefined) { print("Running shard #" + shard); } f_variants.forEach((f_cfg) => { @@ -378,7 +379,9 @@ function run_tests(shard) { g_inlinable_variants.forEach((g_inlinable) => { test_warmup_counts.forEach((test_warmup_count) => { if (shard !== undefined && (iter++) % SHARDS_COUNT != shard) { - print("skipping..."); + if (verbose) { + print("skipping..."); + } return; } tests_executed++; @@ -396,8 +399,10 @@ function run_tests(shard) { deopt_mode, }; var source = test_template(cfg); - print("===================="); - print(source); + if (verbose) { + // print("===================="); + // print(source); + } eval(source); }); }); @@ -408,7 +413,9 @@ function run_tests(shard) { }); }); }); - print("Number of tests executed: " + tests_executed); + if (verbose) { + print("Number of tests executed: " + tests_executed); + } } // Uncomment to run all the tests at once or use shard runners. diff --git a/deps/v8/test/mjsunit/es6/tail-call.js b/deps/v8/test/mjsunit/es6/tail-call.js index d0d00f4b3e..6ecf04f3d9 100644 --- a/deps/v8/test/mjsunit/es6/tail-call.js +++ b/deps/v8/test/mjsunit/es6/tail-call.js @@ -3,6 +3,8 @@ // found in the LICENSE file. // Flags: --allow-natives-syntax --harmony-tailcalls +// Flags: --harmony-do-expressions + "use strict"; Error.prepareStackTrace = (error,stack) => { @@ -259,9 +261,8 @@ function f_153(expected_call_stack, a) { } %NeverOptimizeFunction(g); - var context = 10; function f(v) { - return g(context); + return g(); } %SetForceInlineFlag(f); @@ -319,10 +320,57 @@ function f_153(expected_call_stack, a) { return f([f, g3, test], 13), f([f, test], 153); } + function g4(a) { + return f([f, g4, test], false) || + (f([f, g4, test], true) && f([f, test], true)); + } + + function g5(a) { + return f([f, g5, test], true) && + (f([f, g5, test], false) || f([f, test], true)); + } + + function g6(a) { + return f([f, g6, test], 13), f([f, g6, test], 42), + f([f, test], 153); + } + + function g7(a) { + return f([f, g7, test], false) || + (f([f, g7, test], false) ? f([f, test], true) + : f([f, test], true)); + } + + function g8(a) { + return f([f, g8, test], false) || f([f, g8, test], true) && + f([f, test], true); + } + + function g9(a) { + return f([f, g9, test], true) && f([f, g9, test], false) || + f([f, test], true); + } + + function g10(a) { + return f([f, g10, test], true) && f([f, g10, test], false) || + f([f, g10, test], true) ? + f([f, g10, test], true) && f([f, g10, test], false) || + f([f, test], true) : + f([f, g10, test], true) && f([f, g10, test], false) || + f([f, test], true); + } + function test() { assertEquals(true, g1()); assertEquals(true, g2()); assertEquals(153, g3()); + assertEquals(true, g4()); + assertEquals(true, g5()); + assertEquals(153, g6()); + assertEquals(true, g7()); + assertEquals(true, g8()); + assertEquals(true, g9()); + assertEquals(true, g10()); } test(); test(); @@ -534,9 +582,34 @@ function f_153(expected_call_stack, a) { return (() => f_153([f_153, test]))(); } + function g3(a) { + var closure = () => f([f, closure, test], true) + ? f_153([f_153, test]) + : f_153([f_153, test]); + return closure(); + } + function test() { assertEquals(153, g1()); assertEquals(153, g2()); + assertEquals(153, g3()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from do expressions. +(function () { + function g1(a) { + var a = do { return f_153([f_153, test]); 42; }; + return a; + } + + function test() { + assertEquals(153, g1()); } test(); test(); diff --git a/deps/v8/test/mjsunit/es6/typedarray-set-length-internal.js b/deps/v8/test/mjsunit/es6/typedarray-set-length-internal.js new file mode 100644 index 0000000000..22b8f67e0e --- /dev/null +++ b/deps/v8/test/mjsunit/es6/typedarray-set-length-internal.js @@ -0,0 +1,35 @@ +// Copyright 2016 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 typedArrayConstructors = [ + Uint8Array, + Int8Array, + Uint16Array, + Int16Array, + Uint32Array, + Int32Array, + Uint8ClampedArray, + Float32Array, + Float64Array +]; + +var descriptor = { get: function() { throw new Error("accessed length"); } }; + +for (var constructor of typedArrayConstructors) { + var differentConstructor = + constructor === Uint8Array ? Int8Array : Uint8Array; + var target = new constructor(16); + Object.defineProperty(target, "length", descriptor); + + var sameBuffer = new differentConstructor(target.buffer, 0, 2); + Object.defineProperty(sameBuffer, "length", descriptor); + target.set(sameBuffer); + + var differentBuffer = new differentConstructor(16); + Object.defineProperty(differentBuffer, "length", descriptor); + target.set(differentBuffer); + + var array = [0, 1, 2]; + target.set(array); +} diff --git a/deps/v8/test/mjsunit/harmony/typedarray-species.js b/deps/v8/test/mjsunit/es6/typedarray-species.js index 35a9ea1de7..020d65c501 100644 --- a/deps/v8/test/mjsunit/harmony/typedarray-species.js +++ b/deps/v8/test/mjsunit/es6/typedarray-species.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-species - // Subclasses of %TypedArray% construct themselves under map, etc var typedArrayConstructors = [ diff --git a/deps/v8/test/mjsunit/es6/typedarray-tostring.js b/deps/v8/test/mjsunit/es6/typedarray-tostring.js index e6adda0405..9d49cb1cc9 100644 --- a/deps/v8/test/mjsunit/es6/typedarray-tostring.js +++ b/deps/v8/test/mjsunit/es6/typedarray-tostring.js @@ -83,4 +83,17 @@ for (var constructor of typedArrayConstructors) { assertEquals("1,2", Array.prototype.join.call(a5)); assertEquals("1,2,3", Array.prototype.toString.call(a5)); assertEquals("1,2", Array.prototype.toLocaleString.call(a5)); + + (function TestToLocaleStringCalls() { + let log = []; + let pushArgs = (label) => (...args) => log.push(label, args); + + let NumberToLocaleString = Number.prototype.toLocaleString; + Number.prototype.toLocaleString = pushArgs("Number"); + + (new constructor([1, 2])).toLocaleString(); + assertEquals(["Number", [], "Number", []], log); + + Number.prototype.toLocaleString = NumberToLocaleString; + })(); } diff --git a/deps/v8/test/mjsunit/es6/typedarray.js b/deps/v8/test/mjsunit/es6/typedarray.js index 4bdf8226a8..b1bd8937be 100644 --- a/deps/v8/test/mjsunit/es6/typedarray.js +++ b/deps/v8/test/mjsunit/es6/typedarray.js @@ -229,6 +229,27 @@ function TestTypedArray(constr, elementSize, typicalElement) { RangeError); } + var aFromUndef = new constr(); + assertSame(elementSize, aFromUndef.BYTES_PER_ELEMENT); + assertSame(0, aFromUndef.length); + assertSame(0*elementSize, aFromUndef.byteLength); + assertSame(0, aFromUndef.byteOffset); + assertSame(0*elementSize, aFromUndef.buffer.byteLength); + + var aFromNull = new constr(null); + assertSame(elementSize, aFromNull.BYTES_PER_ELEMENT); + assertSame(0, aFromNull.length); + assertSame(0*elementSize, aFromNull.byteLength); + assertSame(0, aFromNull.byteOffset); + assertSame(0*elementSize, aFromNull.buffer.byteLength); + + var aFromBool = new constr(true); + assertSame(elementSize, aFromBool.BYTES_PER_ELEMENT); + assertSame(1, aFromBool.length); + assertSame(1*elementSize, aFromBool.byteLength); + assertSame(0, aFromBool.byteOffset); + assertSame(1*elementSize, aFromBool.buffer.byteLength); + var aFromString = new constr("30"); assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); assertSame(30, aFromString.length); @@ -236,6 +257,8 @@ function TestTypedArray(constr, elementSize, typicalElement) { assertSame(0, aFromString.byteOffset); assertSame(30*elementSize, aFromString.buffer.byteLength); + assertThrows(function() { new constr(Symbol()); }, TypeError); + var jsArray = []; for (i = 0; i < 30; i++) { jsArray.push(typicalElement); diff --git a/deps/v8/test/mjsunit/harmony/unicode-character-ranges.js b/deps/v8/test/mjsunit/es6/unicode-character-ranges.js index e4f5247c15..f39004fe97 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-character-ranges.js +++ b/deps/v8/test/mjsunit/es6/unicode-character-ranges.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-unicode-regexps --harmony-regexp-lookbehind +// Flags: --harmony-regexp-lookbehind function execl(expectation, regexp, subject) { if (regexp instanceof String) regexp = new RegExp(regexp, "u"); diff --git a/deps/v8/test/mjsunit/harmony/unicode-escapes-in-regexps.js b/deps/v8/test/mjsunit/es6/unicode-escapes-in-regexps.js index 7ea6f62990..2d2d11825d 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-escapes-in-regexps.js +++ b/deps/v8/test/mjsunit/es6/unicode-escapes-in-regexps.js @@ -4,8 +4,6 @@ // ES6 extends the \uxxxx escape and also allows \u{xxxxx}. -// Flags: --harmony-unicode-regexps - function testRegexpHelper(r) { assertTrue(r.test("foo")); assertTrue(r.test("boo")); diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-backrefs.js b/deps/v8/test/mjsunit/es6/unicode-regexp-backrefs.js index e02301be1e..56b9c5eb8c 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-backrefs.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-backrefs.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-unicode-regexps --harmony-regexp-lookbehind +// Flags: --harmony-regexp-lookbehind // Back reference does not end in the middle of a surrogate pair. function replace(string) { diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-ignore-case-noi18n.js b/deps/v8/test/mjsunit/es6/unicode-regexp-ignore-case-noi18n.js index a4cb9dc337..a99894234a 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-ignore-case-noi18n.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-ignore-case-noi18n.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-unicode-regexps - // Non-unicode use toUpperCase mappings. assertFalse(/[\u00e5]/i.test("\u212b")); assertFalse(/[\u212b]/i.test("\u00e5\u1234")); diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-ignore-case.js b/deps/v8/test/mjsunit/es6/unicode-regexp-ignore-case.js index 291b8662ff..dd02ca9d32 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-ignore-case.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-ignore-case.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-unicode-regexps - // Non-unicode use toUpperCase mappings. assertFalse(/[\u00e5]/i.test("\u212b")); assertFalse(/[\u212b]/i.test("\u00e5\u1234")); diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-last-index.js b/deps/v8/test/mjsunit/es6/unicode-regexp-last-index.js index 4a075d4380..67fbac7ef3 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-last-index.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-last-index.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-unicode-regexps --harmony-regexp-lookbehind +// Flags: --harmony-regexp-lookbehind var r = /./ug; assertEquals(["\ud800\udc00"], r.exec("\ud800\udc00\ud801\udc01")); diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-restricted-syntax.js b/deps/v8/test/mjsunit/es6/unicode-regexp-restricted-syntax.js index d129cc340e..dd4fa39ab5 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-restricted-syntax.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-restricted-syntax.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-unicode-regexps - // test262/data/test/language/literals/regexp/u-dec-esc assertThrows("/\\1/u", SyntaxError); // test262/language/literals/regexp/u-invalid-char-range-a diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-unanchored-advance.js b/deps/v8/test/mjsunit/es6/unicode-regexp-unanchored-advance.js index 97960e1cd3..c471122baf 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-unanchored-advance.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-unanchored-advance.js @@ -2,7 +2,5 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-unicode-regexps - var s = "a".repeat(1E7) + "\u1234"; assertEquals(["\u1234", "\u1234"], /(\u1234)/u.exec(s)); diff --git a/deps/v8/test/mjsunit/harmony/unicode-regexp-zero-length.js b/deps/v8/test/mjsunit/es6/unicode-regexp-zero-length.js index bbc17dc2d5..42bb2d71dc 100644 --- a/deps/v8/test/mjsunit/harmony/unicode-regexp-zero-length.js +++ b/deps/v8/test/mjsunit/es6/unicode-regexp-zero-length.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-unicode-regexps - var L = "\ud800"; var T = "\udc00"; var x = "x"; diff --git a/deps/v8/test/mjsunit/es7/array-includes-receiver.js b/deps/v8/test/mjsunit/es7/array-includes-receiver.js new file mode 100644 index 0000000000..85915d4958 --- /dev/null +++ b/deps/v8/test/mjsunit/es7/array-includes-receiver.js @@ -0,0 +1,634 @@ +// Copyright 2016 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 + +// Ensure `Array.prototype.includes` functions correctly for numerous elements +// kinds, and various exotic receiver types, + +// TODO(caitp): update kIterCount to a high enough number to trigger inlining, +// once inlining this builtin is supported +var kIterCount = 1; +var kTests = { + Array: { + FAST_ELEMENTS() { + var r = /foo/; + var s = new String("bar"); + var p = new Proxy({}, {}); + var o = {}; + + var array = [r, s, p]; + assertTrue(%HasFastObjectElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(p)); + assertFalse(array.includes(o)); + } + }, + + FAST_HOLEY_ELEMENTS() { + var r = /foo/; + var p = new Proxy({}, {}); + var o = {}; + + var array = [r, , p]; + assertTrue(%HasFastObjectElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(p)); + assertFalse(array.includes(o)); + } + }, + + FAST_SMI_ELEMENTS() { + var array = [0, 88, 9999, 1, -5, 7]; + assertTrue(%HasFastSmiElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(9999)); + assertTrue(array.includes(-5)); + assertFalse(array.includes(-5.00001)); + assertFalse(array.includes(undefined)); + assertFalse(array.includes(NaN)); + } + }, + + FAST_HOLEY_SMI_ELEMENTS() { + var array = [49, , , 72, , , 67, -48]; + assertTrue(%HasFastSmiElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(72)); + assertTrue(array.includes(-48)); + assertFalse(array.includes(72, 4)); + assertTrue(array.includes(undefined)); + assertFalse(array.includes(undefined, -2)); + assertFalse(array.includes(NaN)); + } + }, + + FAST_DOUBLE_ELEMENTS() { + var array = [7.00000001, -13000.89412, 73451.4124, + 5824.48, 6.0000495, 48.3488, 44.0, 76.35, NaN, 78.4]; + assertTrue(%HasFastDoubleElements(array)); + assertFalse(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(7.00000001)); + assertFalse(array.includes(7.00000001, 2)); + assertTrue(array.includes(NaN)); + assertFalse(array.includes(NaN, -1)); + assertTrue(array.includes(-13000.89412)); + assertFalse(array.includes(-13000.89412, -2)); + assertFalse(array.includes(undefined)); + } + }, + + FAST_HOLEY_DOUBLE_ELEMENTS() { + var array = [7.00000001, -13000.89412, , + 5824.48, , 48.3488, , NaN, , 78.4]; + assertTrue(%HasFastDoubleElements(array)); + assertTrue(%HasFastHoleyElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(7.00000001)); + assertFalse(array.includes(7.00000001, 2)); + assertTrue(array.includes(NaN)); + assertFalse(array.includes(NaN, -2)); + assertTrue(array.includes(-13000.89412)); + assertFalse(array.includes(-13000.89412, -2)); + assertTrue(array.includes(undefined, -2)); + assertFalse(array.includes(undefined, -1)); + } + }, + + DICTIONARY_ELEMENTS() { + var array = []; + Object.defineProperty(array, 4, { get() { return NaN; } }); + Object.defineProperty(array, 7, { value: Function }); + + assertTrue(%HasDictionaryElements(array)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(array.includes(NaN)); + assertFalse(array.includes(NaN, -3)); + assertTrue(array.includes(Function)); + assertTrue(array.includes(undefined)); + assertFalse(array.includes(undefined, 7)); + } + }, + }, + + Object: { + FAST_ELEMENTS() { + var r = /foo/; + var s = new String("bar"); + var p = new Proxy({}, {}); + var o = {}; + + var object = { 0: r, 1: s, 2: p, length: 3 }; + assertTrue(%HasFastObjectElements(object)); + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, p)); + assertFalse(Array.prototype.includes.call(object, o)); + } + }, + + FAST_HOLEY_ELEMENTS() { + var r = /foo/; + var p = new Proxy({}, {}); + var o = {}; + + var object = { 0: r, 2: p, length: 3 }; + assertTrue(%HasFastObjectElements(object)); + assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, p)); + assertFalse(Array.prototype.includes.call(object, o)); + } + }, + + FAST_SMI_ELEMENTS() { + var object = { 0: 0, 1: 88, 2: 9999, 3: 1, 4: -5, 5: 7, length: 6 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastSmiElements(object)); + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, 9999)); + assertTrue(Array.prototype.includes.call(object, -5)); + assertFalse(Array.prototype.includes.call(object, -5.00001)); + assertFalse(Array.prototype.includes.call(object, undefined)); + assertFalse(Array.prototype.includes.call(object, NaN)); + } + }, + + FAST_HOLEY_SMI_ELEMENTS() { + var object = { 0: 49, 3: 72, 6: 67, 7: -48, length: 8 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastSmiElements(object)); + // assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, 72)); + assertTrue(Array.prototype.includes.call(object, -48)); + assertFalse(Array.prototype.includes.call(object, 72, 4)); + assertTrue(Array.prototype.includes.call(object, undefined)); + assertFalse(Array.prototype.includes.call(object, undefined, -2)); + assertFalse(Array.prototype.includes.call(object, NaN)); + } + }, + + FAST_DOUBLE_ELEMENTS() { + var object = { 0: 7.00000001, 1: -13000.89412, 2: 73451.4124, + 3: 5824.48, 4: 6.0000495, 5: 48.3488, 6: 44.0, 7: 76.35, + 8: NaN, 9: 78.4, length: 10 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastDoubleElements(object)); + // assertFalse(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, 7.00000001)); + assertFalse(Array.prototype.includes.call(object, 7.00000001, 2)); + assertTrue(Array.prototype.includes.call(object, NaN)); + assertFalse(Array.prototype.includes.call(object, NaN, -1)); + assertTrue(Array.prototype.includes.call(object, -13000.89412)); + assertFalse(Array.prototype.includes.call(object, -13000.89412, -2)); + assertFalse(Array.prototype.includes.call(object, undefined)); + } + }, + + FAST_HOLEY_DOUBLE_ELEMENTS() { + var object = { 0: 7.00000001, 1: -13000.89412, 3: 5824.48, 5: 48.3488, + 7: NaN, 9: 78.4, length: 10 }; + // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS + // assertTrue(%HasFastDoubleElements(object)); + // assertTrue(%HasFastHoleyElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, 7.00000001)); + assertFalse(Array.prototype.includes.call(object, 7.00000001, 2)); + assertTrue(Array.prototype.includes.call(object, NaN)); + assertFalse(Array.prototype.includes.call(object, NaN, -2)); + assertTrue(Array.prototype.includes.call(object, -13000.89412)); + assertFalse(Array.prototype.includes.call(object, -13000.89412, -2)); + assertTrue(Array.prototype.includes.call(object, undefined, -2)); + assertFalse(Array.prototype.includes.call(object, undefined, -1)); + } + }, + + DICTIONARY_ELEMENTS() { + var object = { length: 8 }; + Object.defineProperty(object, 4, { get() { return NaN; } }); + Object.defineProperty(object, 7, { value: Function }); + + assertTrue(%HasDictionaryElements(object)); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call(object, NaN)); + assertFalse(Array.prototype.includes.call(object, NaN, -3)); + assertTrue(Array.prototype.includes.call(object, Function)); + assertTrue(Array.prototype.includes.call(object, undefined)); + assertFalse(Array.prototype.includes.call(object, undefined, 7)); + } + + (function prototypeModifiedDuringAccessor() { + function O() { + return { + __proto__: {}, + get 0() { + this.__proto__.__proto__ = { + get 1() { + this[2] = "c"; + return "b"; + } + }; + return "a"; + }, + length: 3 + }; + } + + // Switch to slow path when first accessor modifies the prototype + assertTrue(Array.prototype.includes.call(O(), "a")); + assertTrue(Array.prototype.includes.call(O(), "b")); + assertTrue(Array.prototype.includes.call(O(), "c")); + + // Avoid switching to slow path due to avoiding the accessor + assertFalse(Array.prototype.includes.call(O(), "c", 2)); + assertFalse(Array.prototype.includes.call(O(), "b", 1)); + assertTrue(Array.prototype.includes.call(O(), undefined, 1)); + }); + }, + }, + + String: { + FAST_STRING_ELEMENTS() { + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call("froyo", "y")); + assertFalse(Array.prototype.includes.call("froyo", "y", -1)); + assertTrue(Array.prototype.includes.call("froyo", "y", -2)); + assertFalse(Array.prototype.includes.call("froyo", NaN)); + assertFalse(Array.prototype.includes.call("froyo", undefined)); + } + }, + + SLOW_STRING_ELEMENTS() { + var string = new String("froyo"); + + // Never accessible from A.p.includes as 'length' is not configurable + Object.defineProperty(string, 34, { value: NaN }); + Object.defineProperty(string, 12, { get() { return "nope" } }); + + for (var i = 0; i < kIterCount; ++i) { + assertTrue(Array.prototype.includes.call("froyo", "y")); + assertFalse(Array.prototype.includes.call("froyo", "y", -1)); + assertTrue(Array.prototype.includes.call("froyo", "y", -2)); + assertFalse(Array.prototype.includes.call(string, NaN)); + assertFalse(Array.prototype.includes.call(string, undefined)); + assertFalse(Array.prototype.includes.call(string, "nope")); + } + }, + }, + + Arguments: { + FAST_SLOPPY_ARGUMENTS_ELEMENTS() { + var args = (function(a, b) { return arguments; })("foo", NaN, "bar"); + assertTrue(%HasSloppyArgumentsElements(args)); + + for (var i = 0; i < kIterCount; ++i) { + assertFalse(Array.prototype.includes.call(args, undefined)); + assertTrue(Array.prototype.includes.call(args, NaN)); + assertFalse(Array.prototype.includes.call(args, NaN, -1)); + assertTrue(Array.prototype.includes.call(args, "bar", -1)); + } + }, + + SLOW_SLOPPY_ARGUMENTS_ELEMENTS() { + var args = (function(a, a) { return arguments; })("foo", NaN, "bar"); + Object.defineProperty(args, 3, { get() { return "silver"; } }); + Object.defineProperty(args, "length", { value: 4 }); + assertTrue(%HasSloppyArgumentsElements(args)); + + for (var i = 0; i < kIterCount; ++i) { + assertFalse(Array.prototype.includes.call(args, undefined)); + assertTrue(Array.prototype.includes.call(args, NaN)); + assertFalse(Array.prototype.includes.call(args, NaN, -2)); + assertTrue(Array.prototype.includes.call(args, "bar", -2)); + assertTrue(Array.prototype.includes.call(args, "silver", -1)); + } + } + }, + + TypedArray: { + Int8Array() { + var array = new Int8Array([-129, 128, + NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, + +Infinity /* 0 */, -Infinity /* 0 */, + 255 /* -1 */, 127 /* 127 */, -255 /* 1 */]); + assertFalse(Array.prototype.includes.call(array, -129)); + assertFalse(Array.prototype.includes.call(array, 128)); + + assertTrue(Array.prototype.includes.call(array, 0, 2)); + assertTrue(Array.prototype.includes.call(array, 0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0, 7)); + + assertTrue(Array.prototype.includes.call(array, -1, 7)); + assertFalse(Array.prototype.includes.call(array, -1, 8)); + + assertTrue(Array.prototype.includes.call(array, 127, 8)); + assertFalse(Array.prototype.includes.call(array, 127, 9)); + + assertTrue(Array.prototype.includes.call(array, 1, 9)); + }, + + Detached_Int8Array() { + var array = new Int8Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Uint8Array() { + var array = new Uint8Array([-1, 256, + NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, + +Infinity /* 0 */, -Infinity /* 0 */, + 255 /* 255 */, 257 /* 1 */, -128 /* 128 */, + -2 /* 254 */]); + assertFalse(Array.prototype.includes.call(array, -1)); + assertFalse(Array.prototype.includes.call(array, 256)); + + assertTrue(Array.prototype.includes.call(array, 0, 2)); + assertTrue(Array.prototype.includes.call(array, 0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0, 7)); + + assertTrue(Array.prototype.includes.call(array, 255, 7)); + assertFalse(Array.prototype.includes.call(array, 255, 8)); + + assertTrue(Array.prototype.includes.call(array, 1, 8)); + assertFalse(Array.prototype.includes.call(array, 1, 9)); + + assertTrue(Array.prototype.includes.call(array, 128, 9)); + assertFalse(Array.prototype.includes.call(array, 128, 10)); + + assertTrue(Array.prototype.includes.call(array, 254, 10)); + }, + + Detached_Uint8Array() { + var array = new Uint8Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Uint8ClampedArray() { + var array = new Uint8ClampedArray([-1 /* 0 */, NaN /* 0 */, 256 /* 255 */, + 127.6 /* 128 */, 127.4 /* 127 */, + 121.5 /* 122 */, 124.5 /* 124 */]); + assertFalse(Array.prototype.includes.call(array, -1)); + assertFalse(Array.prototype.includes.call(array, 256)); + + assertTrue(Array.prototype.includes.call(array, 0)); + assertTrue(Array.prototype.includes.call(array, 0, 1)); + assertTrue(Array.prototype.includes.call(array, 255, 2)); + + assertTrue(Array.prototype.includes.call(array, 128, 3)); + assertFalse(Array.prototype.includes.call(array, 128, 4)); + + assertTrue(Array.prototype.includes.call(array, 127, 4)); + assertFalse(Array.prototype.includes.call(array, 127, 5)); + + assertTrue(Array.prototype.includes.call(array, 122, 5)); + assertFalse(Array.prototype.includes.call(array, 122, 6)); + + assertTrue(Array.prototype.includes.call(array, 124, 6)); + }, + + Detached_Uint8ClampedArray() { + var array = new Uint8ClampedArray(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Int16Array() { + var array = new Int16Array([-32769, 32768, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFF /* -1 */, 30000 /* 30000 */, + 300000 /* -27680 */]); + assertFalse(Array.prototype.includes.call(array, -32769)); + assertFalse(Array.prototype.includes.call(array, 32768)); + + assertTrue(Array.prototype.includes.call(array, 0, 2)); + assertTrue(Array.prototype.includes.call(array, 0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0, 7)); + + assertTrue(Array.prototype.includes.call(array, -1, 7)); + assertFalse(Array.prototype.includes.call(array, -1, 8)); + + assertTrue(Array.prototype.includes.call(array, 30000, 8)); + assertFalse(Array.prototype.includes.call(array, 30000, 9)); + + assertTrue(Array.prototype.includes.call(array, -27680, 9)); + }, + + Detached_Int16Array() { + var array = new Int16Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Uint16Array() { + var array = new Uint16Array([-1, 65536, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFF /* 65535 */, 300000 /* 37856 */, + 3000000 /* 50880 */]); + assertFalse(Array.prototype.includes.call(array, -1)); + assertFalse(Array.prototype.includes.call(array, 65536)); + + assertTrue(Array.prototype.includes.call(array, 0, 2)); + assertTrue(Array.prototype.includes.call(array, 0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0, 7)); + + assertTrue(Array.prototype.includes.call(array, 65535, 7)); + assertFalse(Array.prototype.includes.call(array, 65535, 8)); + + assertTrue(Array.prototype.includes.call(array, 37856, 8)); + assertFalse(Array.prototype.includes.call(array, 37856, 9)); + + assertTrue(Array.prototype.includes.call(array, 50880, 9)); + }, + + Detached_Uint16Array() { + var array = new Uint16Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Int32Array() { + var array = new Int32Array([-2147483649, 2147483648, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* -1 */, 4294968064 /* 768 */, + 4294959447 /* -7849 */]); + assertFalse(Array.prototype.includes.call(array, -2147483649)); + assertFalse(Array.prototype.includes.call(array, 2147483648)); + + assertTrue(Array.prototype.includes.call(array, 0.0, 2)); + assertTrue(Array.prototype.includes.call(array, 0.0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0.0, 6)); + assertFalse(Array.prototype.includes.call(array, 0.0, 7)); + + assertTrue(Array.prototype.includes.call(array, -1, 7)); + assertFalse(Array.prototype.includes.call(array, -1, 8)); + + assertTrue(Array.prototype.includes.call(array, 768, 8)); + assertFalse(Array.prototype.includes.call(array, 768, 9)); + + assertTrue(Array.prototype.includes.call(array, -7849, 9)); + }, + + Detached_Int32Array() { + var array = new Int32Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Uint32Array() { + var array = new Uint32Array([-1, 4294967296, + NaN /* 0 */, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 4294967295 */, + 4294968064 /* 768 */, + 4295079447 /* 112151 */]); + assertFalse(Array.prototype.includes.call(array, -1)); + assertFalse(Array.prototype.includes.call(array, 4294967296)); + + assertTrue(Array.prototype.includes.call(array, 0.0, 2)); + assertTrue(Array.prototype.includes.call(array, 0.0, 3)); + assertTrue(Array.prototype.includes.call(array, 0, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0.0, 6)); + assertFalse(Array.prototype.includes.call(array, 0.0, 7)); + + assertTrue(Array.prototype.includes.call(array, 4294967295, 7)); + assertFalse(Array.prototype.includes.call(array, 4294967295, 8)); + + assertTrue(Array.prototype.includes.call(array, 768, 8)); + assertFalse(Array.prototype.includes.call(array, 768, 9)); + + assertTrue(Array.prototype.includes.call(array, 112151, 9)); + }, + + Detached_Uint32Array() { + var array = new Uint32Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Float32Array() { + var array = new Float32Array([-1, 4294967296, + NaN, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 34359738368.0 */, + -4294968064 /* -4294968320.0 */, + 4295079447 /* 4295079424.0 */]); + assertTrue(Array.prototype.includes.call(array, -1.0)); + assertTrue(Array.prototype.includes.call(array, 4294967296)); + + assertTrue(Array.prototype.includes.call(array, NaN, 2)); + assertTrue(Array.prototype.includes.call(array, Infinity, 3)); + assertTrue(Array.prototype.includes.call(array, -Infinity, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0.0, 7)); + + assertTrue(Array.prototype.includes.call(array, 34359738368.0, 7)); + assertFalse(Array.prototype.includes.call(array, 34359738368.0, 8)); + + assertTrue(Array.prototype.includes.call(array, -4294968320.0, 8)); + assertFalse(Array.prototype.includes.call(array, -4294968320.0, 9)); + + assertTrue(Array.prototype.includes.call(array, 4295079424.0, 9)); + }, + + Detached_Float32Array() { + var array = new Float32Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + + Float64Array() { + var array = new Float64Array([-1, 4294967296, + NaN, Infinity /* 0 */, + -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, + 0x7FFFFFFFF /* 34359738367.0 */, + -4294968064 /* -4294968064.0 */, + 4295079447 /* 4295079447.0 */]); + assertTrue(Array.prototype.includes.call(array, -1.0)); + assertTrue(Array.prototype.includes.call(array, 4294967296)); + + assertTrue(Array.prototype.includes.call(array, NaN, 2)); + assertTrue(Array.prototype.includes.call(array, Infinity, 3)); + assertTrue(Array.prototype.includes.call(array, -Infinity, 4)); + assertTrue(Array.prototype.includes.call(array, 0, 5)); + assertTrue(Array.prototype.includes.call(array, 0, 6)); + assertFalse(Array.prototype.includes.call(array, 0.0, 7)); + + assertTrue(Array.prototype.includes.call(array, 34359738367.0, 7)); + assertFalse(Array.prototype.includes.call(array, 34359738367.0, 8)); + + assertTrue(Array.prototype.includes.call(array, -4294968064.0, 8)); + assertFalse(Array.prototype.includes.call(array, -4294968064.0, 9)); + + assertTrue(Array.prototype.includes.call(array, 4295079447.0, 9)); + }, + + Detached_Float64Array() { + var array = new Float32Array(10); + %ArrayBufferNeuter(array.buffer); + assertFalse(Array.prototype.includes.call(array, 0)); + assertFalse(Array.prototype.includes.call(array, 0, 10)); + }, + } +}; + +function runSuites(suites) { + Object.keys(suites).forEach(suite => runSuite(suites[suite])); + + function runSuite(suite) { + Object.keys(suite).forEach(test => suite[test]()); + } +} + +runSuites(kTests); diff --git a/deps/v8/test/mjsunit/es7/array-includes.js b/deps/v8/test/mjsunit/es7/array-includes.js index 303042a4c1..3981797a7c 100644 --- a/deps/v8/test/mjsunit/es7/array-includes.js +++ b/deps/v8/test/mjsunit/es7/array-includes.js @@ -673,3 +673,8 @@ assertFalse(Array.prototype.includes.call(new Uint8Array([1, 2, 3]), 4)); assertFalse(Array.prototype.includes.call(new Uint8Array([1, 2, 3]), 2, 2)); })(); + + +(function testUnscopable() { + assertTrue(Array.prototype[Symbol.unscopables].includes); +})(); diff --git a/deps/v8/test/mjsunit/harmony/exponentiation-operator.js b/deps/v8/test/mjsunit/es7/exponentiation-operator.js index 543e1046c9..9d934bdaac 100644 --- a/deps/v8/test/mjsunit/harmony/exponentiation-operator.js +++ b/deps/v8/test/mjsunit/es7/exponentiation-operator.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-exponentiation-operator - function TestBasic() { assertEquals(-(8 ** 2), -64); assertEquals(+(8 ** 2), 64); diff --git a/deps/v8/test/mjsunit/es7/object-observe-runtime.js b/deps/v8/test/mjsunit/es7/object-observe-runtime.js deleted file mode 100644 index 1a07141af6..0000000000 --- a/deps/v8/test/mjsunit/es7/object-observe-runtime.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 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-object-observe -// Flags: --allow-natives-syntax - -// These tests are meant to ensure that that the Object.observe runtime -// functions are hardened. - -var obj = {}; -%SetIsObserved(obj); -assertThrows(function() { - %SetIsObserved(obj); -}); - -assertThrows(function() { - %SetIsObserved(this); -}); diff --git a/deps/v8/test/mjsunit/es7/object-observe.js b/deps/v8/test/mjsunit/es7/object-observe.js deleted file mode 100644 index a558c51421..0000000000 --- a/deps/v8/test/mjsunit/es7/object-observe.js +++ /dev/null @@ -1,1865 +0,0 @@ -// Copyright 2012 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: --harmony-object-observe -// Flags: --allow-natives-syntax - -var allObservers = []; -function reset() { - allObservers.forEach(function(observer) { observer.reset(); }); -} - -function stringifyNoThrow(arg) { - try { - return JSON.stringify(arg); - } catch (e) { - return '{<circular reference>}'; - } -} - -function createObserver() { - "use strict"; // So that |this| in callback can be undefined. - - var observer = { - records: undefined, - callbackCount: 0, - reset: function() { - this.records = undefined; - this.callbackCount = 0; - }, - assertNotCalled: function() { - assertEquals(undefined, this.records); - assertEquals(0, this.callbackCount); - }, - assertCalled: function() { - assertEquals(1, this.callbackCount); - }, - assertRecordCount: function(count) { - this.assertCalled(); - assertEquals(count, this.records.length); - }, - assertCallbackRecords: function(recs) { - this.assertRecordCount(recs.length); - for (var i = 0; i < recs.length; i++) { - if ('name' in recs[i]) recs[i].name = String(recs[i].name); - print(i, stringifyNoThrow(this.records[i]), stringifyNoThrow(recs[i])); - assertSame(this.records[i].object, recs[i].object); - assertEquals('string', typeof recs[i].type); - assertPropertiesEqual(this.records[i], recs[i]); - } - } - }; - - observer.callback = function(r) { - assertEquals(undefined, this); - assertEquals('object', typeof r); - assertTrue(r instanceof Array) - observer.records = r; - observer.callbackCount++; - }; - - observer.reset(); - allObservers.push(observer); - return observer; -} - -var observer = createObserver(); -var observer2 = createObserver(); - -assertEquals("function", typeof observer.callback); -assertEquals("function", typeof observer2.callback); - -var obj = {}; - -function frozenFunction() {} -Object.freeze(frozenFunction); -var nonFunction = {}; -var changeRecordWithAccessor = { type: 'foo' }; -var recordCreated = false; -Object.defineProperty(changeRecordWithAccessor, 'name', { - get: function() { - recordCreated = true; - return "bar"; - }, - enumerable: true -}) - - -// Object.observe -assertThrows(function() { Object.observe("non-object", observer.callback); }, - TypeError); -assertThrows(function() { Object.observe(this, observer.callback); }, - TypeError); -assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); -assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); -assertEquals(obj, Object.observe(obj, observer.callback, [1])); -assertEquals(obj, Object.observe(obj, observer.callback, [true])); -assertEquals(obj, Object.observe(obj, observer.callback, ['foo', null])); -assertEquals(obj, Object.observe(obj, observer.callback, [undefined])); -assertEquals(obj, Object.observe(obj, observer.callback, - ['foo', 'bar', 'baz'])); -assertEquals(obj, Object.observe(obj, observer.callback, [])); -assertEquals(obj, Object.observe(obj, observer.callback, undefined)); -assertEquals(obj, Object.observe(obj, observer.callback)); - -// Object.unobserve -assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError); -assertThrows(function() { Object.unobserve(this, observer.callback); }, - TypeError); -assertThrows(function() { Object.unobserve(obj, nonFunction); }, TypeError); -assertEquals(obj, Object.unobserve(obj, observer.callback)); - - -// Object.getNotifier -var notifier = Object.getNotifier(obj); -assertSame(notifier, Object.getNotifier(obj)); -assertEquals(null, Object.getNotifier(Object.freeze({}))); -assertThrows(function() { Object.getNotifier(this) }, TypeError); -assertFalse(notifier.hasOwnProperty('notify')); -assertEquals([], Object.keys(notifier)); -var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify'); -assertTrue(notifyDesc.configurable); -assertTrue(notifyDesc.writable); -assertFalse(notifyDesc.enumerable); -assertThrows(function() { notifier.notify({}); }, TypeError); -assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); - -assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError); -assertThrows(function() { notifier.performChange(undefined, function(){}); }, TypeError); -assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError); -assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError); -var global = this; -notifier.performChange('foo', function() { - assertEquals(global, this); -}); - -var notify = notifier.notify; -assertThrows(function() { notify.call(undefined, { type: 'a' }); }, TypeError); -assertThrows(function() { notify.call(null, { type: 'a' }); }, TypeError); -assertThrows(function() { notify.call(5, { type: 'a' }); }, TypeError); -assertThrows(function() { notify.call('hello', { type: 'a' }); }, TypeError); -assertThrows(function() { notify.call(false, { type: 'a' }); }, TypeError); -assertThrows(function() { notify.call({}, { type: 'a' }); }, TypeError); -assertFalse(recordCreated); -notifier.notify(changeRecordWithAccessor); -assertFalse(recordCreated); // not observed yet - - -// Object.deliverChangeRecords -assertThrows(function() { Object.deliverChangeRecords(nonFunction); }, TypeError); - -Object.observe(obj, observer.callback); - - -// notify uses to [[CreateOwnProperty]] to create changeRecord; -reset(); -var protoExpandoAccessed = false; -Object.defineProperty(Object.prototype, 'protoExpando', - { - configurable: true, - set: function() { protoExpandoAccessed = true; } - } -); -notifier.notify({ type: 'foo', protoExpando: 'val'}); -assertFalse(protoExpandoAccessed); -delete Object.prototype.protoExpando; -Object.deliverChangeRecords(observer.callback); - - -// Multiple records are delivered. -reset(); -notifier.notify({ - type: 'update', - name: 'foo', - expando: 1 -}); - -notifier.notify({ - object: notifier, // object property is ignored - type: 'delete', - name: 'bar', - expando2: 'str' -}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: 'foo', type: 'update', expando: 1 }, - { object: obj, name: 'bar', type: 'delete', expando2: 'str' } -]); - -// Non-string accept values are coerced to strings -reset(); -Object.observe(obj, observer.callback, [true, 1, null, undefined]); -notifier = Object.getNotifier(obj); -notifier.notify({ type: 'true' }); -notifier.notify({ type: 'false' }); -notifier.notify({ type: '1' }); -notifier.notify({ type: '-1' }); -notifier.notify({ type: 'null' }); -notifier.notify({ type: 'nill' }); -notifier.notify({ type: 'undefined' }); -notifier.notify({ type: 'defined' }); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'true' }, - { object: obj, type: '1' }, - { object: obj, type: 'null' }, - { object: obj, type: 'undefined' } -]); - -// No delivery takes place if no records are pending -reset(); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - - -// Multiple observation has no effect. -reset(); -Object.observe(obj, observer.callback); -Object.observe(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', -}); -Object.deliverChangeRecords(observer.callback); -observer.assertCalled(); - - -// Observation can be stopped. -reset(); -Object.unobserve(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', -}); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - - -// Multiple unobservation has no effect -reset(); -Object.unobserve(obj, observer.callback); -Object.unobserve(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', -}); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - - -// Re-observation works and only includes changeRecords after of call. -reset(); -Object.getNotifier(obj).notify({ - type: 'update', -}); -Object.observe(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', -}); -records = undefined; -Object.deliverChangeRecords(observer.callback); -observer.assertRecordCount(1); - -// Get notifier prior to observing -reset(); -var obj = {}; -Object.getNotifier(obj); -Object.observe(obj, observer.callback); -obj.id = 1; -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'add', name: 'id' }, -]); - -// The empty-string property is observable -reset(); -var obj = {}; -Object.observe(obj, observer.callback); -obj[''] = ''; -obj[''] = ' '; -delete obj['']; -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'add', name: '' }, - { object: obj, type: 'update', name: '', oldValue: '' }, - { object: obj, type: 'delete', name: '', oldValue: ' ' }, -]); - -// Object.preventExtensions -reset(); -var obj = { foo: 'bar'}; -Object.observe(obj, observer.callback); -obj.baz = 'bat'; -Object.preventExtensions(obj); - -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'add', name: 'baz' }, - { object: obj, type: 'preventExtensions' }, -]); - -reset(); -var obj = { foo: 'bar'}; -Object.preventExtensions(obj); -Object.observe(obj, observer.callback); -Object.preventExtensions(obj); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - -// Object.freeze -reset(); -var obj = { a: 'a' }; -Object.defineProperty(obj, 'b', { - writable: false, - configurable: true, - value: 'b' -}); -Object.defineProperty(obj, 'c', { - writable: true, - configurable: false, - value: 'c' -}); -Object.defineProperty(obj, 'd', { - writable: false, - configurable: false, - value: 'd' -}); -Object.observe(obj, observer.callback); -Object.freeze(obj); - -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'preventExtensions' }, - { object: obj, type: 'reconfigure', name: 'a' }, - { object: obj, type: 'reconfigure', name: 'b' }, - { object: obj, type: 'reconfigure', name: 'c' }, -]); - -reset(); -var obj = { foo: 'bar'}; -Object.freeze(obj); -Object.observe(obj, observer.callback); -Object.freeze(obj); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - -// Object.seal -reset(); -var obj = { a: 'a' }; -Object.defineProperty(obj, 'b', { - writable: false, - configurable: true, - value: 'b' -}); -Object.defineProperty(obj, 'c', { - writable: true, - configurable: false, - value: 'c' -}); -Object.defineProperty(obj, 'd', { - writable: false, - configurable: false, - value: 'd' -}); -Object.observe(obj, observer.callback); -Object.seal(obj); - -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'preventExtensions' }, - { object: obj, type: 'reconfigure', name: 'a' }, - { object: obj, type: 'reconfigure', name: 'b' }, -]); - -reset(); -var obj = { foo: 'bar'}; -Object.seal(obj); -Object.observe(obj, observer.callback); -Object.seal(obj); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - -// Observing a continuous stream of changes, while itermittantly unobserving. -reset(); -var obj = {}; -Object.observe(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', - val: 1 -}); - -Object.unobserve(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', - val: 2 -}); - -Object.observe(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', - val: 3 -}); - -Object.unobserve(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', - val: 4 -}); - -Object.observe(obj, observer.callback); -Object.getNotifier(obj).notify({ - type: 'update', - val: 5 -}); - -Object.unobserve(obj, observer.callback); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'update', val: 1 }, - { object: obj, type: 'update', val: 3 }, - { object: obj, type: 'update', val: 5 } -]); - -// Accept -reset(); -Object.observe(obj, observer.callback, ['somethingElse']); -Object.getNotifier(obj).notify({ - type: 'add' -}); -Object.getNotifier(obj).notify({ - type: 'update' -}); -Object.getNotifier(obj).notify({ - type: 'delete' -}); -Object.getNotifier(obj).notify({ - type: 'reconfigure' -}); -Object.getNotifier(obj).notify({ - type: 'setPrototype' -}); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - -reset(); -Object.observe(obj, observer.callback, ['add', 'delete', 'setPrototype']); -Object.getNotifier(obj).notify({ - type: 'add' -}); -Object.getNotifier(obj).notify({ - type: 'update' -}); -Object.getNotifier(obj).notify({ - type: 'delete' -}); -Object.getNotifier(obj).notify({ - type: 'delete' -}); -Object.getNotifier(obj).notify({ - type: 'reconfigure' -}); -Object.getNotifier(obj).notify({ - type: 'setPrototype' -}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'add' }, - { object: obj, type: 'delete' }, - { object: obj, type: 'delete' }, - { object: obj, type: 'setPrototype' } -]); - -reset(); -Object.observe(obj, observer.callback, ['update', 'foo']); -Object.getNotifier(obj).notify({ - type: 'add' -}); -Object.getNotifier(obj).notify({ - type: 'update' -}); -Object.getNotifier(obj).notify({ - type: 'delete' -}); -Object.getNotifier(obj).notify({ - type: 'foo' -}); -Object.getNotifier(obj).notify({ - type: 'bar' -}); -Object.getNotifier(obj).notify({ - type: 'foo' -}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'update' }, - { object: obj, type: 'foo' }, - { object: obj, type: 'foo' } -]); - -reset(); -function Thingy(a, b, c) { - this.a = a; - this.b = b; -} - -Thingy.MULTIPLY = 'multiply'; -Thingy.INCREMENT = 'increment'; -Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; - -Thingy.prototype = { - increment: function(amount) { - var notifier = Object.getNotifier(this); - - var self = this; - notifier.performChange(Thingy.INCREMENT, function() { - self.a += amount; - self.b += amount; - - return { - incremented: amount - }; // implicit notify - }); - }, - - multiply: function(amount) { - var notifier = Object.getNotifier(this); - - var self = this; - notifier.performChange(Thingy.MULTIPLY, function() { - self.a *= amount; - self.b *= amount; - - return { - multiplied: amount - }; // implicit notify - }); - }, - - incrementAndMultiply: function(incAmount, multAmount) { - var notifier = Object.getNotifier(this); - - var self = this; - notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { - self.increment(incAmount); - self.multiply(multAmount); - - return { - incremented: incAmount, - multiplied: multAmount - }; // implicit notify - }); - } -} - -Thingy.observe = function(thingy, callback) { - Object.observe(thingy, callback, [Thingy.INCREMENT, - Thingy.MULTIPLY, - Thingy.INCREMENT_AND_MULTIPLY, - 'update']); -} - -Thingy.unobserve = function(thingy, callback) { - Object.unobserve(thingy); -} - -var thingy = new Thingy(2, 4); - -Object.observe(thingy, observer.callback); -Thingy.observe(thingy, observer2.callback); -thingy.increment(3); // { a: 5, b: 7 } -thingy.b++; // { a: 5, b: 8 } -thingy.multiply(2); // { a: 10, b: 16 } -thingy.a++; // { a: 11, b: 16 } -thingy.incrementAndMultiply(2, 2); // { a: 26, b: 36 } - -Object.deliverChangeRecords(observer.callback); -Object.deliverChangeRecords(observer2.callback); -observer.assertCallbackRecords([ - { object: thingy, type: 'update', name: 'a', oldValue: 2 }, - { object: thingy, type: 'update', name: 'b', oldValue: 4 }, - { object: thingy, type: 'update', name: 'b', oldValue: 7 }, - { object: thingy, type: 'update', name: 'a', oldValue: 5 }, - { object: thingy, type: 'update', name: 'b', oldValue: 8 }, - { object: thingy, type: 'update', name: 'a', oldValue: 10 }, - { object: thingy, type: 'update', name: 'a', oldValue: 11 }, - { object: thingy, type: 'update', name: 'b', oldValue: 16 }, - { object: thingy, type: 'update', name: 'a', oldValue: 13 }, - { object: thingy, type: 'update', name: 'b', oldValue: 18 }, -]); -observer2.assertCallbackRecords([ - { object: thingy, type: Thingy.INCREMENT, incremented: 3 }, - { object: thingy, type: 'update', name: 'b', oldValue: 7 }, - { object: thingy, type: Thingy.MULTIPLY, multiplied: 2 }, - { object: thingy, type: 'update', name: 'a', oldValue: 10 }, - { - object: thingy, - type: Thingy.INCREMENT_AND_MULTIPLY, - incremented: 2, - multiplied: 2 - } -]); - -// ArrayPush cached stub -reset(); - -function pushMultiple(arr) { - arr.push('a'); - arr.push('b'); - arr.push('c'); -} - -for (var i = 0; i < 5; i++) { - var arr = []; - pushMultiple(arr); -} - -for (var i = 0; i < 5; i++) { - reset(); - var arr = []; - Object.observe(arr, observer.callback); - pushMultiple(arr); - Object.unobserve(arr, observer.callback); - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: arr, type: 'add', name: '0' }, - { object: arr, type: 'update', name: 'length', oldValue: 0 }, - { object: arr, type: 'add', name: '1' }, - { object: arr, type: 'update', name: 'length', oldValue: 1 }, - { object: arr, type: 'add', name: '2' }, - { object: arr, type: 'update', name: 'length', oldValue: 2 }, - ]); -} - - -// ArrayPop cached stub -reset(); - -function popMultiple(arr) { - arr.pop(); - arr.pop(); - arr.pop(); -} - -for (var i = 0; i < 5; i++) { - var arr = ['a', 'b', 'c']; - popMultiple(arr); -} - -for (var i = 0; i < 5; i++) { - reset(); - var arr = ['a', 'b', 'c']; - Object.observe(arr, observer.callback); - popMultiple(arr); - Object.unobserve(arr, observer.callback); - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: arr, type: 'delete', name: '2', oldValue: 'c' }, - { object: arr, type: 'update', name: 'length', oldValue: 3 }, - { object: arr, type: 'delete', name: '1', oldValue: 'b' }, - { object: arr, type: 'update', name: 'length', oldValue: 2 }, - { object: arr, type: 'delete', name: '0', oldValue: 'a' }, - { object: arr, type: 'update', name: 'length', oldValue: 1 }, - ]); -} - - -reset(); -function RecursiveThingy() {} - -RecursiveThingy.MULTIPLY_FIRST_N = 'multiplyFirstN'; - -RecursiveThingy.prototype = { - __proto__: Array.prototype, - - multiplyFirstN: function(amount, n) { - if (!n) - return; - var notifier = Object.getNotifier(this); - var self = this; - notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { - self[n-1] = self[n-1]*amount; - self.multiplyFirstN(amount, n-1); - }); - - notifier.notify({ - type: RecursiveThingy.MULTIPLY_FIRST_N, - multiplied: amount, - n: n - }); - }, -} - -RecursiveThingy.observe = function(thingy, callback) { - Object.observe(thingy, callback, [RecursiveThingy.MULTIPLY_FIRST_N]); -} - -RecursiveThingy.unobserve = function(thingy, callback) { - Object.unobserve(thingy); -} - -var thingy = new RecursiveThingy; -thingy.push(1, 2, 3, 4); - -Object.observe(thingy, observer.callback); -RecursiveThingy.observe(thingy, observer2.callback); -thingy.multiplyFirstN(2, 3); // [2, 4, 6, 4] - -Object.deliverChangeRecords(observer.callback); -Object.deliverChangeRecords(observer2.callback); -observer.assertCallbackRecords([ - { object: thingy, type: 'update', name: '2', oldValue: 3 }, - { object: thingy, type: 'update', name: '1', oldValue: 2 }, - { object: thingy, type: 'update', name: '0', oldValue: 1 } -]); -observer2.assertCallbackRecords([ - { object: thingy, type: RecursiveThingy.MULTIPLY_FIRST_N, multiplied: 2, n: 3 } -]); - -reset(); -function DeckSuit() { - this.push('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'A', 'Q', 'K'); -} - -DeckSuit.SHUFFLE = 'shuffle'; - -DeckSuit.prototype = { - __proto__: Array.prototype, - - shuffle: function() { - var notifier = Object.getNotifier(this); - var self = this; - notifier.performChange(DeckSuit.SHUFFLE, function() { - self.reverse(); - self.sort(function() { return Math.random()* 2 - 1; }); - var cut = self.splice(0, 6); - Array.prototype.push.apply(self, cut); - self.reverse(); - self.sort(function() { return Math.random()* 2 - 1; }); - var cut = self.splice(0, 6); - Array.prototype.push.apply(self, cut); - self.reverse(); - self.sort(function() { return Math.random()* 2 - 1; }); - }); - - notifier.notify({ - type: DeckSuit.SHUFFLE - }); - }, -} - -DeckSuit.observe = function(thingy, callback) { - Object.observe(thingy, callback, [DeckSuit.SHUFFLE]); -} - -DeckSuit.unobserve = function(thingy, callback) { - Object.unobserve(thingy); -} - -var deck = new DeckSuit; - -DeckSuit.observe(deck, observer2.callback); -deck.shuffle(); - -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: deck, type: DeckSuit.SHUFFLE } -]); - -// Observing multiple objects; records appear in order. -reset(); -var obj2 = {}; -var obj3 = {} -Object.observe(obj, observer.callback); -Object.observe(obj3, observer.callback); -Object.observe(obj2, observer.callback); -Object.getNotifier(obj).notify({ - type: 'add', -}); -Object.getNotifier(obj2).notify({ - type: 'update', -}); -Object.getNotifier(obj3).notify({ - type: 'delete', -}); -Object.observe(obj3, observer.callback); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, type: 'add' }, - { object: obj2, type: 'update' }, - { object: obj3, type: 'delete' } -]); - - -// Recursive observation. -var obj = {a: 1}; -var callbackCount = 0; -function recursiveObserver(r) { - assertEquals(1, r.length); - ++callbackCount; - if (r[0].oldValue < 100) ++obj[r[0].name]; -} -Object.observe(obj, recursiveObserver); -++obj.a; -Object.deliverChangeRecords(recursiveObserver); -assertEquals(100, callbackCount); - -var obj1 = {a: 1}; -var obj2 = {a: 1}; -var recordCount = 0; -function recursiveObserver2(r) { - recordCount += r.length; - if (r[0].oldValue < 100) { - ++obj1.a; - ++obj2.a; - } -} -Object.observe(obj1, recursiveObserver2); -Object.observe(obj2, recursiveObserver2); -++obj1.a; -Object.deliverChangeRecords(recursiveObserver2); -assertEquals(199, recordCount); - - -// Observing named properties. -reset(); -var obj = {a: 1} -Object.observe(obj, observer.callback); -obj.a = 2; -obj["a"] = 3; -delete obj.a; -obj.a = 4; -obj.a = 4; // ignored -obj.a = 5; -Object.defineProperty(obj, "a", {value: 6}); -Object.defineProperty(obj, "a", {writable: false}); -obj.a = 7; // ignored -Object.defineProperty(obj, "a", {value: 8}); -Object.defineProperty(obj, "a", {value: 7, writable: true}); -Object.defineProperty(obj, "a", {get: function() {}}); -Object.defineProperty(obj, "a", {get: frozenFunction}); -Object.defineProperty(obj, "a", {get: frozenFunction}); // ignored -Object.defineProperty(obj, "a", {get: frozenFunction, set: frozenFunction}); -Object.defineProperty(obj, "a", {set: frozenFunction}); // ignored -Object.defineProperty(obj, "a", {get: undefined, set: frozenFunction}); -delete obj.a; -delete obj.a; -Object.defineProperty(obj, "a", {get: function() {}, configurable: true}); -Object.defineProperty(obj, "a", {value: 9, writable: true}); -obj.a = 10; -++obj.a; -obj.a++; -obj.a *= 3; -delete obj.a; -Object.defineProperty(obj, "a", {value: 11, configurable: true}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: "a", type: "update", oldValue: 1 }, - { object: obj, name: "a", type: "update", oldValue: 2 }, - { object: obj, name: "a", type: "delete", oldValue: 3 }, - { object: obj, name: "a", type: "add" }, - { object: obj, name: "a", type: "update", oldValue: 4 }, - { object: obj, name: "a", type: "update", oldValue: 5 }, - { object: obj, name: "a", type: "reconfigure" }, - { object: obj, name: "a", type: "update", oldValue: 6 }, - { object: obj, name: "a", type: "reconfigure", oldValue: 8 }, - { object: obj, name: "a", type: "reconfigure", oldValue: 7 }, - { object: obj, name: "a", type: "reconfigure" }, - { object: obj, name: "a", type: "reconfigure" }, - { object: obj, name: "a", type: "reconfigure" }, - { object: obj, name: "a", type: "delete" }, - { object: obj, name: "a", type: "add" }, - { object: obj, name: "a", type: "reconfigure" }, - { object: obj, name: "a", type: "update", oldValue: 9 }, - { object: obj, name: "a", type: "update", oldValue: 10 }, - { object: obj, name: "a", type: "update", oldValue: 11 }, - { object: obj, name: "a", type: "update", oldValue: 12 }, - { object: obj, name: "a", type: "delete", oldValue: 36 }, - { object: obj, name: "a", type: "add" }, -]); - - -// Observing indexed properties. -reset(); -var obj = {'1': 1} -Object.observe(obj, observer.callback); -obj[1] = 2; -obj[1] = 3; -delete obj[1]; -obj[1] = 4; -obj[1] = 4; // ignored -obj[1] = 5; -Object.defineProperty(obj, "1", {value: 6}); -Object.defineProperty(obj, "1", {writable: false}); -obj[1] = 7; // ignored -Object.defineProperty(obj, "1", {value: 8}); -Object.defineProperty(obj, "1", {value: 7, writable: true}); -Object.defineProperty(obj, "1", {get: function() {}}); -Object.defineProperty(obj, "1", {get: frozenFunction}); -Object.defineProperty(obj, "1", {get: frozenFunction}); // ignored -Object.defineProperty(obj, "1", {get: frozenFunction, set: frozenFunction}); -Object.defineProperty(obj, "1", {set: frozenFunction}); // ignored -Object.defineProperty(obj, "1", {get: undefined, set: frozenFunction}); -delete obj[1]; -delete obj[1]; -Object.defineProperty(obj, "1", {get: function() {}, configurable: true}); -Object.defineProperty(obj, "1", {value: 9, writable: true}); -obj[1] = 10; -++obj[1]; -obj[1]++; -obj[1] *= 3; -delete obj[1]; -Object.defineProperty(obj, "1", {value: 11, configurable: true}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: "1", type: "update", oldValue: 1 }, - { object: obj, name: "1", type: "update", oldValue: 2 }, - { object: obj, name: "1", type: "delete", oldValue: 3 }, - { object: obj, name: "1", type: "add" }, - { object: obj, name: "1", type: "update", oldValue: 4 }, - { object: obj, name: "1", type: "update", oldValue: 5 }, - { object: obj, name: "1", type: "reconfigure" }, - { object: obj, name: "1", type: "update", oldValue: 6 }, - { object: obj, name: "1", type: "reconfigure", oldValue: 8 }, - { object: obj, name: "1", type: "reconfigure", oldValue: 7 }, - { object: obj, name: "1", type: "reconfigure" }, - { object: obj, name: "1", type: "reconfigure" }, - { object: obj, name: "1", type: "reconfigure" }, - { object: obj, name: "1", type: "delete" }, - { object: obj, name: "1", type: "add" }, - { object: obj, name: "1", type: "reconfigure" }, - { object: obj, name: "1", type: "update", oldValue: 9 }, - { object: obj, name: "1", type: "update", oldValue: 10 }, - { object: obj, name: "1", type: "update", oldValue: 11 }, - { object: obj, name: "1", type: "update", oldValue: 12 }, - { object: obj, name: "1", type: "delete", oldValue: 36 }, - { object: obj, name: "1", type: "add" }, -]); - - -// Observing symbol properties (not). -print("*****") -reset(); -var obj = {} -var symbol = Symbol("secret"); -Object.observe(obj, observer.callback); -obj[symbol] = 3; -delete obj[symbol]; -Object.defineProperty(obj, symbol, {get: function() {}, configurable: true}); -Object.defineProperty(obj, symbol, {value: 6}); -Object.defineProperty(obj, symbol, {writable: false}); -delete obj[symbol]; -Object.defineProperty(obj, symbol, {value: 7}); -++obj[symbol]; -obj[symbol]++; -obj[symbol] *= 3; -delete obj[symbol]; -obj.__defineSetter__(symbol, function() {}); -obj.__defineGetter__(symbol, function() {}); -Object.deliverChangeRecords(observer.callback); -observer.assertNotCalled(); - - -// Test all kinds of objects generically. -function TestObserveConfigurable(obj, prop) { - reset(); - Object.observe(obj, observer.callback); - Object.unobserve(obj, observer.callback); - obj[prop] = 1; - Object.observe(obj, observer.callback); - obj[prop] = 2; - obj[prop] = 3; - delete obj[prop]; - obj[prop] = 4; - obj[prop] = 4; // ignored - obj[prop] = 5; - Object.defineProperty(obj, prop, {value: 6}); - Object.defineProperty(obj, prop, {writable: false}); - obj[prop] = 7; // ignored - Object.defineProperty(obj, prop, {value: 8}); - Object.defineProperty(obj, prop, {value: 7, writable: true}); - Object.defineProperty(obj, prop, {get: function() {}}); - Object.defineProperty(obj, prop, {get: frozenFunction}); - Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored - Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); - Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored - Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); - obj.__defineSetter__(prop, frozenFunction); // ignored - obj.__defineSetter__(prop, function() {}); - obj.__defineGetter__(prop, function() {}); - delete obj[prop]; - delete obj[prop]; // ignored - obj.__defineGetter__(prop, function() {}); - delete obj[prop]; - Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); - Object.defineProperty(obj, prop, {value: 9, writable: true}); - obj[prop] = 10; - ++obj[prop]; - obj[prop]++; - obj[prop] *= 3; - delete obj[prop]; - Object.defineProperty(obj, prop, {value: 11, configurable: true}); - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: obj, name: prop, type: "update", oldValue: 1 }, - { object: obj, name: prop, type: "update", oldValue: 2 }, - { object: obj, name: prop, type: "delete", oldValue: 3 }, - { object: obj, name: prop, type: "add" }, - { object: obj, name: prop, type: "update", oldValue: 4 }, - { object: obj, name: prop, type: "update", oldValue: 5 }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "update", oldValue: 6 }, - { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, - { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "delete" }, - { object: obj, name: prop, type: "add" }, - { object: obj, name: prop, type: "delete" }, - { object: obj, name: prop, type: "add" }, - { object: obj, name: prop, type: "reconfigure" }, - { object: obj, name: prop, type: "update", oldValue: 9 }, - { object: obj, name: prop, type: "update", oldValue: 10 }, - { object: obj, name: prop, type: "update", oldValue: 11 }, - { object: obj, name: prop, type: "update", oldValue: 12 }, - { object: obj, name: prop, type: "delete", oldValue: 36 }, - { object: obj, name: prop, type: "add" }, - ]); - Object.unobserve(obj, observer.callback); - delete obj[prop]; -} - -function TestObserveNonConfigurable(obj, prop, desc) { - reset(); - Object.observe(obj, observer.callback); - Object.unobserve(obj, observer.callback); - obj[prop] = 1; - Object.observe(obj, observer.callback); - obj[prop] = 4; - obj[prop] = 4; // ignored - obj[prop] = 5; - Object.defineProperty(obj, prop, {value: 6}); - Object.defineProperty(obj, prop, {value: 6}); // ignored - Object.defineProperty(obj, prop, {value: 7}); - Object.defineProperty(obj, prop, {enumerable: desc.enumerable}); // ignored - Object.defineProperty(obj, prop, {writable: false}); - obj[prop] = 7; // ignored - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: obj, name: prop, type: "update", oldValue: 1 }, - { object: obj, name: prop, type: "update", oldValue: 4 }, - { object: obj, name: prop, type: "update", oldValue: 5 }, - { object: obj, name: prop, type: "update", oldValue: 6 }, - { object: obj, name: prop, type: "reconfigure" }, - ]); - Object.unobserve(obj, observer.callback); -} - -// TODO(rafaelw) Enable when ES6 Proxies are implemented -/* -function createProxy(create, x) { - var handler = { - getPropertyDescriptor: function(k) { - for (var o = this.target; o; o = Object.getPrototypeOf(o)) { - var desc = Object.getOwnPropertyDescriptor(o, k); - if (desc) return desc; - } - return undefined; - }, - getOwnPropertyDescriptor: function(k) { - return Object.getOwnPropertyDescriptor(this.target, k); - }, - defineProperty: function(k, desc) { - var x = Object.defineProperty(this.target, k, desc); - Object.deliverChangeRecords(this.callback); - return x; - }, - delete: function(k) { - var x = delete this.target[k]; - Object.deliverChangeRecords(this.callback); - return x; - }, - getPropertyNames: function() { - return Object.getOwnPropertyNames(this.target); - }, - target: {isProxy: true}, - callback: function(changeRecords) { - print("callback", stringifyNoThrow(handler.proxy), stringifyNoThrow(got)); - for (var i in changeRecords) { - var got = changeRecords[i]; - var change = {object: handler.proxy, name: got.name, type: got.type}; - if ("oldValue" in got) change.oldValue = got.oldValue; - Object.getNotifier(handler.proxy).notify(change); - } - }, - }; - Object.observe(handler.target, handler.callback); - return handler.proxy = create(handler, x); -} -*/ - -var objects = [ - {}, - [], - function(){}, - (function(){ return arguments })(), - (function(){ "use strict"; return arguments })(), - Object(1), Object(true), Object("bla"), - new Date(), - Object, Function, Date, RegExp, - new Set, new Map, new WeakMap, - new ArrayBuffer(10), new Int32Array(5) -// TODO(rafaelw) Enable when ES6 Proxies are implemented. -// createProxy(Proxy.create, null), -// createProxy(Proxy.createFunction, function(){}), -]; -var properties = ["a", "1", 1, "length", "setPrototype", "name", "caller"]; - -// Cases that yield non-standard results. -function blacklisted(obj, prop) { - return (obj instanceof Int32Array && prop == 1) || - (obj instanceof Int32Array && prop === "length") || - (obj instanceof ArrayBuffer && prop == 1) || - (obj instanceof Function && prop === "name") || // Has its own test. - (obj instanceof Function && prop === "length"); // Has its own test. -} - -for (var i in objects) for (var j in properties) { - var obj = objects[i]; - var prop = properties[j]; - if (blacklisted(obj, prop)) continue; - var desc = Object.getOwnPropertyDescriptor(obj, prop); - print("***", typeof obj, stringifyNoThrow(obj), prop); - if (!desc || desc.configurable) - TestObserveConfigurable(obj, prop); - else if (desc.writable) - TestObserveNonConfigurable(obj, prop, desc); -} - - -// Observing array length (including truncation) -reset(); -var arr = ['a', 'b', 'c', 'd']; -var arr2 = ['alpha', 'beta']; -var arr3 = ['hello']; -arr3[2] = 'goodbye'; -arr3.length = 6; -Object.defineProperty(arr, '0', {configurable: false}); -Object.defineProperty(arr, '2', {get: function(){}}); -Object.defineProperty(arr2, '0', {get: function(){}, configurable: false}); -Object.observe(arr, observer.callback); -Array.observe(arr, observer2.callback); -Object.observe(arr2, observer.callback); -Array.observe(arr2, observer2.callback); -Object.observe(arr3, observer.callback); -Array.observe(arr3, observer2.callback); -arr.length = 2; -arr.length = 0; -arr.length = 10; -Object.defineProperty(arr, 'length', {writable: false}); -arr2.length = 0; -arr2.length = 1; // no change expected -Object.defineProperty(arr2, 'length', {value: 1, writable: false}); -arr3.length = 0; -++arr3.length; -arr3.length++; -arr3.length /= 2; -Object.defineProperty(arr3, 'length', {value: 5}); -arr3[4] = 5; -Object.defineProperty(arr3, 'length', {value: 1, writable: false}); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: arr, name: '3', type: 'delete', oldValue: 'd' }, - { object: arr, name: '2', type: 'delete' }, - { object: arr, name: 'length', type: 'update', oldValue: 4 }, - { object: arr, name: '1', type: 'delete', oldValue: 'b' }, - { object: arr, name: 'length', type: 'update', oldValue: 2 }, - { object: arr, name: 'length', type: 'update', oldValue: 1 }, - { object: arr, name: 'length', type: 'reconfigure' }, - { object: arr2, name: '1', type: 'delete', oldValue: 'beta' }, - { object: arr2, name: 'length', type: 'update', oldValue: 2 }, - { object: arr2, name: 'length', type: 'reconfigure' }, - { object: arr3, name: '2', type: 'delete', oldValue: 'goodbye' }, - { object: arr3, name: '0', type: 'delete', oldValue: 'hello' }, - { object: arr3, name: 'length', type: 'update', oldValue: 6 }, - { object: arr3, name: 'length', type: 'update', oldValue: 0 }, - { object: arr3, name: 'length', type: 'update', oldValue: 1 }, - { object: arr3, name: 'length', type: 'update', oldValue: 2 }, - { object: arr3, name: 'length', type: 'update', oldValue: 1 }, - { object: arr3, name: '4', type: 'add' }, - { object: arr3, name: '4', type: 'delete', oldValue: 5 }, - // TODO(rafaelw): It breaks spec compliance to get two records here. - // When the TODO in v8natives.js::DefineArrayProperty is addressed - // which prevents DefineProperty from over-writing the magic length - // property, these will collapse into a single record. - { object: arr3, name: 'length', type: 'update', oldValue: 5 }, - { object: arr3, name: 'length', type: 'reconfigure' } -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: arr, type: 'splice', index: 2, removed: [, 'd'], addedCount: 0 }, - { object: arr, type: 'splice', index: 1, removed: ['b'], addedCount: 0 }, - { object: arr, type: 'splice', index: 1, removed: [], addedCount: 9 }, - { object: arr2, type: 'splice', index: 1, removed: ['beta'], addedCount: 0 }, - { object: arr3, type: 'splice', index: 0, removed: ['hello',, 'goodbye',,,,], addedCount: 0 }, - { object: arr3, type: 'splice', index: 0, removed: [], addedCount: 1 }, - { object: arr3, type: 'splice', index: 1, removed: [], addedCount: 1 }, - { object: arr3, type: 'splice', index: 1, removed: [,], addedCount: 0 }, - { object: arr3, type: 'splice', index: 1, removed: [], addedCount: 4 }, - { object: arr3, name: '4', type: 'add' }, - { object: arr3, type: 'splice', index: 1, removed: [,,,5], addedCount: 0 } -]); - - -// Updating length on large (slow) array -reset(); -var slow_arr = %NormalizeElements([]); -slow_arr[500000000] = 'hello'; -slow_arr.length = 1000000000; -Object.observe(slow_arr, observer.callback); -var spliceRecords; -function slowSpliceCallback(records) { - spliceRecords = records; -} -Array.observe(slow_arr, slowSpliceCallback); -slow_arr.length = 100; -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: slow_arr, name: '500000000', type: 'delete', oldValue: 'hello' }, - { object: slow_arr, name: 'length', type: 'update', oldValue: 1000000000 }, -]); -Object.deliverChangeRecords(slowSpliceCallback); -assertEquals(spliceRecords.length, 1); -// Have to custom assert this splice record because the removed array is huge. -var splice = spliceRecords[0]; -assertSame(splice.object, slow_arr); -assertEquals(splice.type, 'splice'); -assertEquals(splice.index, 100); -assertEquals(splice.addedCount, 0); -var array_keys = %GetArrayKeys(splice.removed, splice.removed.length); -assertEquals(array_keys.length, 1); -assertEquals(array_keys[0], 499999900); -assertEquals(splice.removed[499999900], 'hello'); -assertEquals(splice.removed.length, 999999900); - - -// Assignments in loops (checking different IC states). -reset(); -var obj = {}; -Object.observe(obj, observer.callback); -for (var i = 0; i < 5; i++) { - obj["a" + i] = i; -} -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: "a0", type: "add" }, - { object: obj, name: "a1", type: "add" }, - { object: obj, name: "a2", type: "add" }, - { object: obj, name: "a3", type: "add" }, - { object: obj, name: "a4", type: "add" }, -]); - -reset(); -var obj = {}; -Object.observe(obj, observer.callback); -for (var i = 0; i < 5; i++) { - obj[i] = i; -} -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: "0", type: "add" }, - { object: obj, name: "1", type: "add" }, - { object: obj, name: "2", type: "add" }, - { object: obj, name: "3", type: "add" }, - { object: obj, name: "4", type: "add" }, -]); - - -// Adding elements past the end of an array should notify on length for -// Object.observe and emit "splices" for Array.observe. -reset(); -var arr = [1, 2, 3]; -Object.observe(arr, observer.callback); -Array.observe(arr, observer2.callback); -arr[3] = 10; -arr[100] = 20; -Object.defineProperty(arr, '200', {value: 7}); -Object.defineProperty(arr, '400', {get: function(){}}); -arr[50] = 30; // no length change expected -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: arr, name: '3', type: 'add' }, - { object: arr, name: 'length', type: 'update', oldValue: 3 }, - { object: arr, name: '100', type: 'add' }, - { object: arr, name: 'length', type: 'update', oldValue: 4 }, - { object: arr, name: '200', type: 'add' }, - { object: arr, name: 'length', type: 'update', oldValue: 101 }, - { object: arr, name: '400', type: 'add' }, - { object: arr, name: 'length', type: 'update', oldValue: 201 }, - { object: arr, name: '50', type: 'add' }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: arr, type: 'splice', index: 3, removed: [], addedCount: 1 }, - { object: arr, type: 'splice', index: 4, removed: [], addedCount: 97 }, - { object: arr, type: 'splice', index: 101, removed: [], addedCount: 100 }, - { object: arr, type: 'splice', index: 201, removed: [], addedCount: 200 }, - { object: arr, type: 'add', name: '50' }, -]); - - -// Tests for array methods, first on arrays and then on plain objects -// -// === ARRAYS === -// -// Push -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -Array.observe(array, observer2.callback); -array.push(3, 4); -array.push(5); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '2', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '3', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 3 }, - { object: array, name: '4', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 4 }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: array, type: 'splice', index: 2, removed: [], addedCount: 2 }, - { object: array, type: 'splice', index: 4, removed: [], addedCount: 1 } -]); - -// Pop -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -array.pop(); -array.pop(); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '1', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '0', type: 'delete', oldValue: 1 }, - { object: array, name: 'length', type: 'update', oldValue: 1 }, -]); - -// Shift -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -array.shift(); -array.shift(); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '0', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '0', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 1 }, -]); - -// Unshift -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -array.unshift(3, 4); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '3', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'add' }, - { object: array, name: '0', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'update', oldValue: 2 }, -]); - -// Splice -reset(); -var array = [1, 2, 3]; -Object.observe(array, observer.callback); -array.splice(1, 1, 4, 5); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '3', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 3 }, - { object: array, name: '1', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'update', oldValue: 3 }, -]); - -// Sort -reset(); -var array = [3, 2, 1]; -Object.observe(array, observer.callback); -array.sort(); -assertEquals(1, array[0]); -assertEquals(2, array[1]); -assertEquals(3, array[2]); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '1', type: 'update', oldValue: 2 }, - { object: array, name: '0', type: 'update', oldValue: 3 }, - { object: array, name: '2', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'update', oldValue: 3 }, - { object: array, name: '0', type: 'update', oldValue: 2 }, -]); - -// Splice emitted after Array mutation methods -function MockArray(initial, observer) { - for (var i = 0; i < initial.length; i++) - this[i] = initial[i]; - - this.length_ = initial.length; - this.observer = observer; -} -MockArray.prototype = { - set length(length) { - Object.getNotifier(this).notify({ type: 'lengthChange' }); - this.length_ = length; - Object.observe(this, this.observer.callback, ['splice']); - }, - get length() { - return this.length_; - } -} - -reset(); -var array = new MockArray([], observer); -Object.observe(array, observer.callback, ['lengthChange']); -Array.prototype.push.call(array, 1); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, type: 'lengthChange' }, - { object: array, type: 'splice', index: 0, removed: [], addedCount: 1 }, -]); - -reset(); -var array = new MockArray([1], observer); -Object.observe(array, observer.callback, ['lengthChange']); -Array.prototype.pop.call(array); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, type: 'lengthChange' }, - { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 }, -]); - -reset(); -var array = new MockArray([1], observer); -Object.observe(array, observer.callback, ['lengthChange']); -Array.prototype.shift.call(array); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, type: 'lengthChange' }, - { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 }, -]); - -reset(); -var array = new MockArray([], observer); -Object.observe(array, observer.callback, ['lengthChange']); -Array.prototype.unshift.call(array, 1); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, type: 'lengthChange' }, - { object: array, type: 'splice', index: 0, removed: [], addedCount: 1 }, -]); - -reset(); -var array = new MockArray([0, 1, 2], observer); -Object.observe(array, observer.callback, ['lengthChange']); -Array.prototype.splice.call(array, 1, 1); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, type: 'lengthChange' }, - { object: array, type: 'splice', index: 1, removed: [1], addedCount: 0 }, -]); - -// -// === PLAIN OBJECTS === -// -// Push -reset() -var array = {0: 1, 1: 2, length: 2} -Object.observe(array, observer.callback); -Array.prototype.push.call(array, 3, 4); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '2', type: 'add' }, - { object: array, name: '3', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, -]); - -// Pop -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -Array.observe(array, observer2.callback); -array.pop(); -array.pop(); -array.pop(); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '1', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '0', type: 'delete', oldValue: 1 }, - { object: array, name: 'length', type: 'update', oldValue: 1 }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: array, type: 'splice', index: 1, removed: [2], addedCount: 0 }, - { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 } -]); - -// Shift -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -Array.observe(array, observer2.callback); -array.shift(); -array.shift(); -array.shift(); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '0', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '0', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 1 }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 }, - { object: array, type: 'splice', index: 0, removed: [2], addedCount: 0 } -]); - -// Unshift -reset(); -var array = [1, 2]; -Object.observe(array, observer.callback); -Array.observe(array, observer2.callback); -array.unshift(3, 4); -array.unshift(5); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '3', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'add' }, - { object: array, name: '0', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'update', oldValue: 2 }, - { object: array, name: '4', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 4 }, - { object: array, name: '3', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'update', oldValue: 4 }, - { object: array, name: '0', type: 'update', oldValue: 3 }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: array, type: 'splice', index: 0, removed: [], addedCount: 2 }, - { object: array, type: 'splice', index: 0, removed: [], addedCount: 1 } -]); - -// Splice -reset(); -var array = [1, 2, 3]; -Object.observe(array, observer.callback); -Array.observe(array, observer2.callback); -array.splice(1, 0, 4, 5); // 1 4 5 2 3 -array.splice(0, 2); // 5 2 3 -array.splice(1, 2, 6, 7); // 5 6 7 -array.splice(2, 0); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '4', type: 'add' }, - { object: array, name: 'length', type: 'update', oldValue: 3 }, - { object: array, name: '3', type: 'add' }, - { object: array, name: '1', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'update', oldValue: 3 }, - - { object: array, name: '0', type: 'update', oldValue: 1 }, - { object: array, name: '1', type: 'update', oldValue: 4 }, - { object: array, name: '2', type: 'update', oldValue: 5 }, - { object: array, name: '4', type: 'delete', oldValue: 3 }, - { object: array, name: '3', type: 'delete', oldValue: 2 }, - { object: array, name: 'length', type: 'update', oldValue: 5 }, - - { object: array, name: '1', type: 'update', oldValue: 2 }, - { object: array, name: '2', type: 'update', oldValue: 3 }, -]); -Object.deliverChangeRecords(observer2.callback); -observer2.assertCallbackRecords([ - { object: array, type: 'splice', index: 1, removed: [], addedCount: 2 }, - { object: array, type: 'splice', index: 0, removed: [1, 4], addedCount: 0 }, - { object: array, type: 'splice', index: 1, removed: [2, 3], addedCount: 2 }, -]); - -// Exercise StoreIC_ArrayLength -reset(); -var dummy = {}; -Object.observe(dummy, observer.callback); -Object.unobserve(dummy, observer.callback); -var array = [0]; -Object.observe(array, observer.callback); -array.splice(0, 1); -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: array, name: '0', type: 'delete', oldValue: 0 }, - { object: array, name: 'length', type: 'update', oldValue: 1}, -]); - - -// __proto__ -reset(); -var obj = {}; -Object.observe(obj, observer.callback); -var p = {foo: 'yes'}; -var q = {bar: 'no'}; -obj.__proto__ = p; -obj.__proto__ = p; // ignored -obj.__proto__ = null; -obj.__proto__ = q; // the __proto__ accessor is gone -// TODO(adamk): Add tests for objects with hidden prototypes -// once we support observing the global object. -Object.deliverChangeRecords(observer.callback); -observer.assertCallbackRecords([ - { object: obj, name: '__proto__', type: 'setPrototype', - oldValue: Object.prototype }, - { object: obj, name: '__proto__', type: 'setPrototype', oldValue: p }, - { object: obj, name: '__proto__', type: 'add' }, -]); - - -// Function.prototype -reset(); -var fun = function(){}; -Object.observe(fun, observer.callback); -var myproto = {foo: 'bar'}; -fun.prototype = myproto; -fun.prototype = 7; -fun.prototype = 7; // ignored -Object.defineProperty(fun, 'prototype', {value: 8}); -Object.deliverChangeRecords(observer.callback); -observer.assertRecordCount(3); -// Manually examine the first record in order to test -// lazy creation of oldValue -assertSame(fun, observer.records[0].object); -assertEquals('prototype', observer.records[0].name); -assertEquals('update', observer.records[0].type); -// The only existing reference to the oldValue object is in this -// record, so to test that lazy creation happened correctly -// we compare its constructor to our function (one of the invariants -// ensured when creating an object via AllocateFunctionPrototype). -assertSame(fun, observer.records[0].oldValue.constructor); -observer.records.splice(0, 1); -observer.assertCallbackRecords([ - { object: fun, name: 'prototype', type: 'update', oldValue: myproto }, - { object: fun, name: 'prototype', type: 'update', oldValue: 7 }, -]); - -// Function.prototype should not be observable except on the object itself -reset(); -var fun = function(){}; -var obj = { __proto__: fun }; -Object.observe(obj, observer.callback); -obj.prototype = 7; -Object.deliverChangeRecords(observer.callback); -observer.assertRecordCount(1); -observer.assertCallbackRecords([ - { object: obj, name: 'prototype', type: 'add' }, -]); - -// Check that changes in observation status are detected in all IC states and -// in optimized code, especially in cases usually using fast elements. -var mutation = [ - "a[i] = v", - "a[i] ? ++a[i] : a[i] = v", - "a[i] ? a[i]++ : a[i] = v", - "a[i] ? a[i] += 1 : a[i] = v", - "a[i] ? a[i] -= -1 : a[i] = v", -]; - -var props = [1, "1", "a"]; - -function TestFastElements(prop, mutation, prepopulate, polymorphic, optimize) { - var setElement = eval( - "(function setElement(a, i, v) { " + mutation + "; " + - "/* " + [].join.call(arguments, " ") + " */" + - "})" - ); - print("TestFastElements:", setElement); - - var arr = prepopulate ? [1, 2, 3, 4, 5] : [0]; - if (prepopulate) arr[prop] = 2; // for non-element case - setElement(arr, prop, 3); - setElement(arr, prop, 4); - if (polymorphic) setElement(["M", "i", "l", "n", "e", "r"], 0, "m"); - if (optimize) %OptimizeFunctionOnNextCall(setElement); - setElement(arr, prop, 5); - - reset(); - Object.observe(arr, observer.callback); - setElement(arr, prop, 989898); - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: arr, name: "" + prop, type: 'update', oldValue: 5 } - ]); -} - -for (var b1 = 0; b1 < 2; ++b1) - for (var b2 = 0; b2 < 2; ++b2) - for (var b3 = 0; b3 < 2; ++b3) - for (var i in props) - for (var j in mutation) - TestFastElements(props[i], mutation[j], b1 != 0, b2 != 0, b3 != 0); - - -var mutation = [ - "a.length = v", - "a.length += newSize - oldSize", - "a.length -= oldSize - newSize", -]; - -var mutationByIncr = [ - "++a.length", - "a.length++", -]; - -function TestFastElementsLength( - mutation, polymorphic, optimize, oldSize, newSize) { - var setLength = eval( - "(function setLength(a, v) { " + mutation + "; " + - "/* " + [].join.call(arguments, " ") + " */" - + "})" - ); - print("TestFastElementsLength:", setLength); - - function array(n) { - var arr = new Array(n); - for (var i = 0; i < n; ++i) arr[i] = i; - return arr; - } - - setLength(array(oldSize), newSize); - setLength(array(oldSize), newSize); - if (polymorphic) setLength(array(oldSize).map(isNaN), newSize); - if (optimize) %OptimizeFunctionOnNextCall(setLength); - setLength(array(oldSize), newSize); - - reset(); - var arr = array(oldSize); - Object.observe(arr, observer.callback); - setLength(arr, newSize); - Object.deliverChangeRecords(observer.callback); - if (oldSize === newSize) { - observer.assertNotCalled(); - } else { - var count = oldSize > newSize ? oldSize - newSize : 0; - observer.assertRecordCount(count + 1); - var lengthRecord = observer.records[count]; - assertSame(arr, lengthRecord.object); - assertEquals('length', lengthRecord.name); - assertEquals('update', lengthRecord.type); - assertSame(oldSize, lengthRecord.oldValue); - } -} - -for (var b1 = 0; b1 < 2; ++b1) - for (var b2 = 0; b2 < 2; ++b2) - for (var n1 = 0; n1 < 3; ++n1) - for (var n2 = 0; n2 < 3; ++n2) - for (var i in mutation) - TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); - -for (var b1 = 0; b1 < 2; ++b1) - for (var b2 = 0; b2 < 2; ++b2) - for (var n = 0; n < 3; ++n) - for (var i in mutationByIncr) - TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); - - -(function TestFunctionName() { - reset(); - - function fun() {} - Object.observe(fun, observer.callback); - fun.name = 'x'; // No change. Not writable. - Object.defineProperty(fun, 'name', {value: 'a'}); - Object.defineProperty(fun, 'name', {writable: true}); - fun.name = 'b'; - delete fun.name; - fun.name = 'x'; // No change. Function.prototype.name is non writable - Object.defineProperty(Function.prototype, 'name', {writable: true}); - fun.name = 'c'; - fun.name = 'c'; // Same, no update. - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: fun, type: 'update', name: 'name', oldValue: 'fun' }, - { object: fun, type: 'reconfigure', name: 'name'}, - { object: fun, type: 'update', name: 'name', oldValue: 'a' }, - { object: fun, type: 'delete', name: 'name', oldValue: 'b' }, - { object: fun, type: 'add', name: 'name' }, - ]); -})(); - - -(function TestFunctionLength() { - reset(); - - function fun(x) {} - Object.observe(fun, observer.callback); - fun.length = 'x'; // No change. Not writable. - Object.defineProperty(fun, 'length', {value: 'a'}); - Object.defineProperty(fun, 'length', {writable: true}); - fun.length = 'b'; - delete fun.length; - fun.length = 'x'; // No change. Function.prototype.length is non writable - Object.defineProperty(Function.prototype, 'length', {writable: true}); - fun.length = 'c'; - fun.length = 'c'; // Same, no update. - Object.deliverChangeRecords(observer.callback); - observer.assertCallbackRecords([ - { object: fun, type: 'update', name: 'length', oldValue: 1 }, - { object: fun, type: 'reconfigure', name: 'length'}, - { object: fun, type: 'update', name: 'length', oldValue: 'a' }, - { object: fun, type: 'delete', name: 'length', oldValue: 'b' }, - { object: fun, type: 'add', name: 'length' }, - ]); -})(); - - -(function TestObserveInvalidAcceptMessage() { - var ex; - try { - Object.observe({}, function(){}, "not an object"); - } catch (e) { - ex = e; - } - assertInstanceof(ex, TypeError); - assertEquals("Third argument to Object.observe must be an array of strings.", - ex.message); -})() diff --git a/deps/v8/test/mjsunit/es7/regress/regress-443982.js b/deps/v8/test/mjsunit/es7/regress/regress-443982.js deleted file mode 100644 index e04f14c0c6..0000000000 --- a/deps/v8/test/mjsunit/es7/regress/regress-443982.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 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-object-observe - -var records; -function observer(r) { - records = r; -} - -Object.defineProperty(Array.prototype, '0', { - get: function() { return 0; }, - set: function() { throw "boom!"; } -}); -arr = [1, 2]; -Array.observe(arr, observer); -arr.length = 0; -assertEquals(0, arr.length); - -Object.deliverChangeRecords(observer); -assertEquals(1, records.length); -assertEquals('splice', records[0].type); -assertArrayEquals([1, 2], records[0].removed); diff --git a/deps/v8/test/mjsunit/es7/regress/regress-633883.js b/deps/v8/test/mjsunit/es7/regress/regress-633883.js new file mode 100644 index 0000000000..d3a4958da4 --- /dev/null +++ b/deps/v8/test/mjsunit/es7/regress/regress-633883.js @@ -0,0 +1,9 @@ +// Copyright 2016 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. + +v5 = new Array(); +v17 = encodeURIComponent(v5); +v19 = isFinite(); +v34 = new Array(v19); +v47 = v34.includes(v17); diff --git a/deps/v8/test/mjsunit/es7/regress/regress-634269.js b/deps/v8/test/mjsunit/es7/regress/regress-634269.js new file mode 100644 index 0000000000..3bd55eec41 --- /dev/null +++ b/deps/v8/test/mjsunit/es7/regress/regress-634269.js @@ -0,0 +1,7 @@ +// Copyright 2016 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_1 = new Uint8Array(); +Object.defineProperty(__v_1.__proto__, 'length', {value: 42}); +Array.prototype.includes.call(new Uint8Array(), 2); diff --git a/deps/v8/test/mjsunit/es7/regress/regress-634273.js b/deps/v8/test/mjsunit/es7/regress/regress-634273.js new file mode 100644 index 0000000000..7ee5b5a5fa --- /dev/null +++ b/deps/v8/test/mjsunit/es7/regress/regress-634273.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 + +array = new Array(undefined, undefined, undefined); +Object.defineProperty(array, 0, { + get: function() { + array.push(undefined, undefined); + } +}); +array[0x80000] = 1; +result = array.includes(new WeakMap()); diff --git a/deps/v8/test/mjsunit/es7/regress/regress-634357.js b/deps/v8/test/mjsunit/es7/regress/regress-634357.js new file mode 100644 index 0000000000..709edcbd50 --- /dev/null +++ b/deps/v8/test/mjsunit/es7/regress/regress-634357.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 + +array = new Array({}, {}, {}); +Object.defineProperty(array, 1, { + get: function() { + array.length = 0; + array[0] = -2147483648; + } +}); +result = array.includes(new Array()); diff --git a/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing-sloppy.js b/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing-sloppy.js new file mode 100644 index 0000000000..d02608606d --- /dev/null +++ b/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing-sloppy.js @@ -0,0 +1,410 @@ +// Copyright 2016 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-explicit-tailcalls +// Flags: --harmony-do-expressions + +var SyntaxErrorTests = [ + { msg: "Unexpected expression inside tail call", + tests: [ + { src: `()=>{ return continue foo ; }`, + err: ` ^^^`, + }, + { src: `()=>{ return continue 42 ; }`, + err: ` ^^`, + }, + { src: `()=>{ return continue new foo () ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ loop: return continue loop ; }`, + err: ` ^^^^`, + }, + { src: `class A { foo() { return continue super.x ; } }`, + err: ` ^^^^^^^`, + }, + { src: `()=>{ return continue this ; }`, + err: ` ^^^^`, + }, + { src: `()=>{ return continue class A {} ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ return continue class A extends B {} ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue function A() { } ; }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue { a: b, c: d} ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue function* Gen() { yield 1; } ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `function A() { return continue new.target ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ return continue () ; }`, + err: ` ^^`, + }, + { src: `()=>{ return continue ( 42 ) ; }`, + err: ` ^^^^^^`, + }, + { src: "()=>{ return continue `123 ${foo} 34lk` ; }", + err: ` ^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue do { x ? foo() : bar() ; } }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call expression is not allowed here", + tests: [ + { src: `class A {}; class B extends A { constructor() { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `class A extends continue f () {}; }`, + err: ` ^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call expressions are not allowed in non-strict mode", + tests: [ + { src: `()=>{ return continue continue continue b() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue ( continue b() ) ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() - a ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return b + continue f() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return 1, 2, 3, continue f() , 4 ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ var x = continue f ( ) ; }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f () ? 1 : 2 ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return (1, 2, 3, continue f()), 4; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, continue f() ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, ... continue f() ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, continue f(), 3 ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: "()=>{ return `123 ${a} ${ continue foo ( ) } 34lk` ; }", + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return g( 1, 2, continue f() ); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() || a; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || b || c || continue f() || d; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && b && c && continue f() && d; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && b || c && continue f() ? d : e; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a ? b : c && continue f() && d || e; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue foo() instanceof bar ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return bar instanceof continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue foo() in bar ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return bar in continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ function* G() { yield continue foo(); } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ (1, 2, 3, continue f() ) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ (... continue f()) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ (a, b, c, ... continue f() ) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a <= continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return b > continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a << continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return b >> continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return c >>> continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() = a ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a = continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a += continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a ** continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return delete continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ typeof continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return ~ continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return void continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return !continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return -continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return +continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return ++ continue f( ) ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() ++; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() --; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return (continue foo()) () ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = continue foo(); i < 10; i++) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = 0; i < continue foo(); i++) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = 0; i < 10; continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ if (continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ while (continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ do { smth; } while (continue foo()) ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ throw continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ switch (continue foo()) { case 1: break; } ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ with (continue foo()) { smth; } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ let x = continue foo() }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ const c = continue foo() }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { return continue f ( ) ; } catch(e) {} }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { try { smth; } catch(e) { return continue f( ) ; } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { try { smth; } catch(e) { return continue f( ) ; } } finally { bla; } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { smth; } catch(e) { return continue f ( ) ; } finally { blah; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { smth; } catch(e) { try { smth; } catch (e) { return continue f ( ) ; } } finally { blah; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var v in {a:0}) { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var v of [1, 2, 3]) { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue a.b.c.foo () ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue a().b.c().d.foo () ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue foo (1)(2)(3, 4) ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return ( continue b() ) ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: "()=>{ return continue bar`ab cd ef` ; }", + err: ` ^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: "()=>{ return continue bar`ab ${cd} ef` ; }", + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a , continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ function* G() { return continue foo(); } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ function B() { return continue new.target() ; } }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue do { x ? foo() : bar() ; }() }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue (do { x ? foo() : bar() ; })() }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return do { 1, continue foo() } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return do { x ? continue foo() : y } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || (b && continue c()); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && (b || continue c()); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || (b ? c : continue d()); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return 1, 2, 3, a || (b ? c : continue d()); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=> continue (foo ()) ;`, + err: ` ^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=> a || continue foo () ;`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=> a && continue foo () ;`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=> a ? continue foo () : b;`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Undefined label 'foo'", + tests: [ + { src: `()=>{ continue foo () ; }`, + err: ` ^^^`, + }, + ], + }, +]; + + +// Should parse successfully. +var NoErrorTests = [ + `()=>{ class A { foo() { return continue super.f() ; } } }`, + `()=>{ class A { foo() { return continue f() ; } } }`, + `()=>{ class A { foo() { return a || continue f() ; } } }`, + `()=>{ class A { foo() { return b && continue f() ; } } }`, +]; + + +(function() { + for (var test_set of SyntaxErrorTests) { + var expected_message = "SyntaxError: " + test_set.msg; + for (var test of test_set.tests) { + var passed = true; + var e = null; + try { + Realm.eval(0, test.src); + } catch (ee) { + e = ee; + } + print("======================================="); + print("Expected | " + expected_message); + print("Source | " + test.src); + print(" | " + test.err); + + if (e === null) { + print("FAILED"); + throw new Error("SyntaxError was not thrown"); + } + + var details = %GetExceptionDetails(e); + if (details.start_pos == undefined || + details.end_pos == undefined) { + throw new Error("Bad message object returned"); + } + var underline = " ".repeat(details.start_pos) + + "^".repeat(details.end_pos - details.start_pos); + var passed = expected_message === e.toString() && + test.err === underline; + + if (passed) { + print("PASSED"); + print(); + } else { + print("---------------------------------------"); + print("Actual | " + e); + print("Source | " + test.src); + print(" | " + underline); + print("FAILED"); + throw new Error("Test failed"); + } + } + } +})(); + + +(function() { + for (var src of NoErrorTests) { + print("======================================="); + print("Source | " + src); + Realm.eval(0, src); + print("PASSED"); + print(); + } +})(); diff --git a/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing.js b/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing.js new file mode 100644 index 0000000000..486c3e1da6 --- /dev/null +++ b/deps/v8/test/mjsunit/es8/syntactic-tail-call-parsing.js @@ -0,0 +1,393 @@ +// Copyright 2016 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-explicit-tailcalls +// Flags: --harmony-do-expressions --harmony-async-await +"use strict"; + +var SyntaxErrorTests = [ + { msg: "Unexpected expression inside tail call", + tests: [ + { src: `()=>{ return continue foo ; }`, + err: ` ^^^`, + }, + { src: `()=>{ return continue 42 ; }`, + err: ` ^^`, + }, + { src: `()=>{ return continue new foo () ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ loop: return continue loop ; }`, + err: ` ^^^^`, + }, + { src: `class A { foo() { return continue super.x ; } }`, + err: ` ^^^^^^^`, + }, + { src: `()=>{ return continue this ; }`, + err: ` ^^^^`, + }, + { src: `()=>{ return continue class A {} ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ return continue class A extends B {} ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue function A() { } ; }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue { a: b, c: d} ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue function* Gen() { yield 1; } ; }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + { src: `function A() { return continue new.target ; }`, + err: ` ^^^^^^^^^^`, + }, + { src: `()=>{ return continue () ; }`, + err: ` ^^`, + }, + { src: `()=>{ return continue ( 42 ) ; }`, + err: ` ^^^^^^`, + }, + { src: "()=>{ return continue `123 ${foo} 34lk` ; }", + err: ` ^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue do { x ? foo() : bar() ; } }`, + err: ` ^^^^^^^^^^^^^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call expression is not allowed here", + tests: [ + { src: `()=>{ return continue continue continue b() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue ( continue b() ) ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() - a ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return b + continue f() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return 1, 2, 3, continue f() , 4 ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ var x = continue f ( ) ; }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f () ? 1 : 2 ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return (1, 2, 3, continue f()), 4; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, continue f() ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, ... continue f() ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return [1, 2, continue f(), 3 ] ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: "()=>{ return `123 ${a} ${ continue foo ( ) } 34lk` ; }", + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return g( 1, 2, continue f() ); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() || a; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || b || c || continue f() || d; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && b && c && continue f() && d; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a && b || c && continue f() ? d : e; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a ? b : c && continue f() && d || e; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue foo() instanceof bar ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return bar instanceof continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue foo() in bar ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return bar in continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ function* G() { yield continue foo(); } }`, + err: ` ^^^^^`, + }, + { src: `()=>{ function* G() { return continue foo(); } }`, + err: ` ^^^^^`, + }, + { src: `()=>{ (1, 2, 3, continue f() ) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ (... continue f()) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ (a, b, c, ... continue f() ) => {} }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a <= continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return b > continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a << continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return b >> continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return c >>> continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() = a ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a = continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a += continue f(); }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return a ** continue f() ; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return delete continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ typeof continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return ~ continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return void continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return !continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return -continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return +continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return ++ continue f( ) ; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() ++; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return continue f() --; }`, + err: ` ^^^^^^^^^^^^`, + }, + { src: `()=>{ return (continue foo()) () ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = continue foo(); i < 10; i++) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = 0; i < continue foo(); i++) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var i = 0; i < 10; continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ if (continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ while (continue foo()) bar(); }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ do { smth; } while (continue foo()) ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ throw continue foo() ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ switch (continue foo()) { case 1: break; } ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ let x = continue foo() }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ const c = continue foo() }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `class A {}; class B extends A { constructor() { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^`, + }, + { src: `class A extends continue f () {}; }`, + err: ` ^^^^^^^^^^^^^`, + }, + { src: `async() => continue foo()`, + err: ` ^^^^^`, + }, + ], + }, + { msg: "Tail call expression in try block", + tests: [ + { src: `()=>{ try { return continue f ( ) ; } catch(e) {} }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { try { smth; } catch(e) { return continue f( ) ; } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { try { smth; } catch(e) { return continue f( ) ; } } finally { bla; } }`, + err: ` ^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call expression in catch block when finally block is also present", + tests: [ + { src: `()=>{ try { smth; } catch(e) { return continue f ( ) ; } finally { blah; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ try { smth; } catch(e) { try { smth; } catch (e) { return continue f ( ) ; } } finally { blah; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call expression in for-in/of body", + tests: [ + { src: `()=>{ for (var v in {a:0}) { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ for (var v of [1, 2, 3]) { return continue foo () ; } }`, + err: ` ^^^^^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Tail call of a direct eval is not allowed", + tests: [ + { src: `()=>{ return continue eval(" foo () " ) ; }`, + err: ` ^^^^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return a || continue eval("", 1, 2) ; }`, + err: ` ^^^^^^^^^^^^^^`, + }, + { src: `()=>{ return a, continue eval ( ) ; }`, + err: ` ^^^^^^^^^`, + }, + { src: `()=> a, continue eval ( ) ; `, + err: ` ^^^^^^^^^`, + }, + { src: `()=> a || continue eval (' ' ) ; `, + err: ` ^^^^^^^^^^^^`, + }, + ], + }, + { msg: "Undefined label 'foo'", + tests: [ + { src: `()=>{ continue foo () ; }`, + err: ` ^^^`, + }, + ], + }, +]; + + +// Should parse successfully. +var NoErrorTests = [ + `()=>{ return continue a.b.c.foo () ; }`, + `()=>{ return continue a().b.c().d.foo () ; }`, + `()=>{ return continue foo (1)(2)(3, 4) ; }`, + `()=>{ return continue (0, eval)(); }`, + `()=>{ return ( continue b() ) ; }`, + "()=>{ return continue bar`ab cd ef` ; }", + "()=>{ return continue bar`ab ${cd} ef` ; }", + `()=>{ return a || continue f() ; }`, + `()=>{ return a && continue f() ; }`, + `()=>{ return a , continue f() ; }`, + `()=>{ class A { foo() { return continue super.f() ; } } }`, + `()=>{ function B() { return continue new.target() ; } }`, + `()=>{ return continue do { x ? foo() : bar() ; }() }`, + `()=>{ return continue (do { x ? foo() : bar() ; })() }`, + `()=>{ return do { 1, continue foo() } }`, + `()=>{ return do { x ? continue foo() : y } }`, + `()=>{ return a || (b && continue c()); }`, + `()=>{ return a && (b || continue c()); }`, + `()=>{ return a || (b ? c : continue d()); }`, + `()=>{ return 1, 2, 3, a || (b ? c : continue d()); }`, + `()=> continue (foo ()) ;`, + `()=> a || continue foo () ;`, + `()=> a && continue foo () ;`, + `()=> a ? continue foo () : b;`, +]; + + +(function() { + for (var test_set of SyntaxErrorTests) { + var expected_message = "SyntaxError: " + test_set.msg; + for (var test of test_set.tests) { + var passed = true; + var e = null; + try { + eval(test.src); + } catch (ee) { + e = ee; + } + print("======================================="); + print("Expected | " + expected_message); + print("Source | " + test.src); + print(" | " + test.err); + + if (e === null) { + print("FAILED"); + throw new Error("SyntaxError was not thrown"); + } + + var details = %GetExceptionDetails(e); + if (details.start_pos == undefined || + details.end_pos == undefined) { + throw new Error("Bad message object returned"); + } + var underline = " ".repeat(details.start_pos) + + "^".repeat(details.end_pos - details.start_pos); + var passed = expected_message === e.toString() && + test.err === underline; + + if (passed) { + print("PASSED"); + print(); + } else { + print("---------------------------------------"); + print("Actual | " + e); + print("Source | " + test.src); + print(" | " + underline); + print("FAILED"); + throw new Error("Test failed"); + } + } + } +})(); + + +(function() { + for (var src of NoErrorTests) { + print("======================================="); + print("Source | " + src); + src = `"use strict"; ` + src; + Realm.eval(0, src); + print("PASSED"); + print(); + } +})(); diff --git a/deps/v8/test/mjsunit/es8/syntactic-tail-call-simple.js b/deps/v8/test/mjsunit/es8/syntactic-tail-call-simple.js new file mode 100644 index 0000000000..ec7ade6673 --- /dev/null +++ b/deps/v8/test/mjsunit/es8/syntactic-tail-call-simple.js @@ -0,0 +1,143 @@ +// Copyright 2016 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-explicit-tailcalls --stack-size=100 + +// +// Tail calls work only in strict mode. +// +(function() { + function f(n) { + if (n <= 0) { + return "foo"; + } + return f(n - 1); + } + assertThrows(()=>{ f(1e5) }); + %OptimizeFunctionOnNextCall(f); + assertThrows(()=>{ f(1e5) }); +})(); + + +// +// Tail call normal functions. +// +(function() { + "use strict"; + function f(n) { + if (n <= 0) { + return "foo"; + } + return continue f(n - 1); + } + assertEquals("foo", f(1e5)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); +})(); + + +(function() { + "use strict"; + function f(n) { + if (n <= 0) { + return "foo"; + } + return continue f(n - 1, 42); // Call with arguments adaptor. + } + assertEquals("foo", f(1e5)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); +})(); + + +(function() { + "use strict"; + function f(n){ + if (n <= 0) { + return "foo"; + } + return continue g(n - 1); + } + function g(n){ + if (n <= 0) { + return "bar"; + } + return continue f(n - 1); + } + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); +})(); + + +(function() { + "use strict"; + function f(n){ + if (n <= 0) { + return "foo"; + } + return continue g(n - 1, 42); // Call with arguments adaptor. + } + function g(n){ + if (n <= 0) { + return "bar"; + } + return continue f(n - 1, 42); // Call with arguments adaptor. + } + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); +})(); + + +// +// Tail call bound functions. +// +(function() { + "use strict"; + function f0(n) { + if (n <= 0) { + return "foo"; + } + return continue f_bound(n - 1); + } + var f_bound = f0.bind({}); + function f(n) { + return continue f_bound(n); + } + assertEquals("foo", f(1e5)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); +})(); + + +(function() { + "use strict"; + function f0(n){ + if (n <= 0) { + return "foo"; + } + return continue g_bound(n - 1); + } + function g0(n){ + if (n <= 0) { + return "bar"; + } + return continue f_bound(n - 1); + } + var f_bound = f0.bind({}); + var g_bound = g0.bind({}); + function f(n) { + return continue f_bound(n); + } + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); + %OptimizeFunctionOnNextCall(f); + assertEquals("foo", f(1e5)); + assertEquals("bar", f(1e5 + 1)); +})(); diff --git a/deps/v8/test/mjsunit/es8/syntactic-tail-call.js b/deps/v8/test/mjsunit/es8/syntactic-tail-call.js new file mode 100644 index 0000000000..44936a4b22 --- /dev/null +++ b/deps/v8/test/mjsunit/es8/syntactic-tail-call.js @@ -0,0 +1,604 @@ +// Copyright 2016 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-explicit-tailcalls +// Flags: --harmony-do-expressions + +"use strict"; + +Error.prepareStackTrace = (error,stack) => { + error.strace = stack; + return error.message + "\n at " + stack.join("\n at "); +} + + +function CheckStackTrace(expected) { + var e = new Error(); + e.stack; // prepare stack trace + var stack = e.strace; + assertEquals("CheckStackTrace", stack[0].getFunctionName()); + for (var i = 0; i < expected.length; i++) { + assertEquals(expected[i].name, stack[i + 1].getFunctionName()); + } +} +%NeverOptimizeFunction(CheckStackTrace); + + +function f(expected_call_stack, a, b) { + CheckStackTrace(expected_call_stack); + return a; +} + +function f_153(expected_call_stack, a) { + CheckStackTrace(expected_call_stack); + return 153; +} + + +// Tail call when caller does not have an arguments adaptor frame. +(function() { + // Caller and callee have same number of arguments. + function f1(a) { + CheckStackTrace([f1, test]); + return 10 + a; + } + function g1(a) { return continue f1(2); } + + // Caller has more arguments than callee. + function f2(a) { + CheckStackTrace([f2, test]); + return 10 + a; + } + function g2(a, b, c) { return continue f2(2); } + + // Caller has less arguments than callee. + function f3(a, b, c) { + CheckStackTrace([f3, test]); + return 10 + a + b + c; + } + function g3(a) { return continue f3(2, 3, 4); } + + // Callee has arguments adaptor frame. + function f4(a, b, c) { + CheckStackTrace([f4, test]); + return 10 + a; + } + function g4(a) { return continue f4(2); } + + function test() { + assertEquals(12, g1(1)); + assertEquals(12, g2(1, 2, 3)); + assertEquals(19, g3(1)); + assertEquals(12, g4(1)); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail call when caller has an arguments adaptor frame. +(function() { + // Caller and callee have same number of arguments. + function f1(a) { + CheckStackTrace([f1, test]); + return 10 + a; + } + function g1(a) { return continue f1(2); } + + // Caller has more arguments than callee. + function f2(a) { + CheckStackTrace([f2, test]); + return 10 + a; + } + function g2(a, b, c) { return continue f2(2); } + + // Caller has less arguments than callee. + function f3(a, b, c) { + CheckStackTrace([f3, test]); + return 10 + a + b + c; + } + function g3(a) { return continue f3(2, 3, 4); } + + // Callee has arguments adaptor frame. + function f4(a, b, c) { + CheckStackTrace([f4, test]); + return 10 + a; + } + function g4(a) { return continue f4(2); } + + function test() { + assertEquals(12, g1()); + assertEquals(12, g2()); + assertEquals(19, g3()); + assertEquals(12, g4()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail call bound function when caller does not have an arguments +// adaptor frame. +(function() { + // Caller and callee have same number of arguments. + function f1(a) { + assertEquals(153, this.a); + CheckStackTrace([f1, test]); + return 10 + a; + } + var b1 = f1.bind({a: 153}); + function g1(a) { return continue b1(2); } + + // Caller has more arguments than callee. + function f2(a) { + assertEquals(153, this.a); + CheckStackTrace([f2, test]); + return 10 + a; + } + var b2 = f2.bind({a: 153}); + function g2(a, b, c) { return continue b2(2); } + + // Caller has less arguments than callee. + function f3(a, b, c) { + assertEquals(153, this.a); + CheckStackTrace([f3, test]); + return 10 + a + b + c; + } + var b3 = f3.bind({a: 153}); + function g3(a) { return continue b3(2, 3, 4); } + + // Callee has arguments adaptor frame. + function f4(a, b, c) { + assertEquals(153, this.a); + CheckStackTrace([f4, test]); + return 10 + a; + } + var b4 = f4.bind({a: 153}); + function g4(a) { return continue b4(2); } + + function test() { + assertEquals(12, g1(1)); + assertEquals(12, g2(1, 2, 3)); + assertEquals(19, g3(1)); + assertEquals(12, g4(1)); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail call bound function when caller has an arguments adaptor frame. +(function() { + // Caller and callee have same number of arguments. + function f1(a) { + assertEquals(153, this.a); + CheckStackTrace([f1, test]); + return 10 + a; + } + var b1 = f1.bind({a: 153}); + function g1(a) { return continue b1(2); } + + // Caller has more arguments than callee. + function f2(a) { + assertEquals(153, this.a); + CheckStackTrace([f2, test]); + return 10 + a; + } + var b2 = f2.bind({a: 153}); + function g2(a, b, c) { return continue b2(2); } + + // Caller has less arguments than callee. + function f3(a, b, c) { + assertEquals(153, this.a); + CheckStackTrace([f3, test]); + return 10 + a + b + c; + } + var b3 = f3.bind({a: 153}); + function g3(a) { return continue b3(2, 3, 4); } + + // Callee has arguments adaptor frame. + function f4(a, b, c) { + assertEquals(153, this.a); + CheckStackTrace([f4, test]); + return 10 + a; + } + var b4 = f4.bind({a: 153}); + function g4(a) { return continue b4(2); } + + function test() { + assertEquals(12, g1()); + assertEquals(12, g2()); + assertEquals(19, g3()); + assertEquals(12, g4()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail calling from getter. +(function() { + function g(v) { + CheckStackTrace([g, test]); + %DeoptimizeFunction(test); + return 153; + } + %NeverOptimizeFunction(g); + + function f(v) { + return continue g(); + } + %SetForceInlineFlag(f); + + function test() { + var o = {}; + o.__defineGetter__('p', f); + assertEquals(153, o.p); + } + + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail calling from setter. +(function() { + function g() { + CheckStackTrace([g, test]); + %DeoptimizeFunction(test); + return 153; + } + %NeverOptimizeFunction(g); + + function f(v) { + return continue g(); + } + %SetForceInlineFlag(f); + + function test() { + var o = {}; + o.__defineSetter__('q', f); + assertEquals(1, o.q = 1); + } + + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail calling from constructor. +(function() { + function g(context) { + CheckStackTrace([g, test]); + %DeoptimizeFunction(test); + return {x: 153}; + } + %NeverOptimizeFunction(g); + + function A() { + this.x = 42; + return continue g(); + } + + function test() { + var o = new A(); + %DebugPrint(o); + assertEquals(153, o.x); + } + + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail calling via various expressions. +(function() { + function g1(a) { + return f([f, g1, test], false) || continue f([f, test], true); + } + + function g2(a) { + return f([f, g2, test], true) && continue f([f, test], true); + } + + function g3(a) { + return f([f, g3, test], 13), continue f([f, test], 153); + } + + function g4(a) { + return f([f, g4, test], false) || + (f([f, g4, test], true) && continue f([f, test], true)); + } + + function g5(a) { + return f([f, g5, test], true) && + (f([f, g5, test], false) || continue f([f, test], true)); + } + + function g6(a) { + return f([f, g6, test], 13), f([f, g6, test], 42), + continue f([f, test], 153); + } + + function g7(a) { + return f([f, g7, test], false) || + (f([f, g7, test], false) ? continue f([f, test], true) + : continue f([f, test], true)); + } + + function g8(a) { + return f([f, g8, test], false) || f([f, g8, test], true) && + continue f([f, test], true); + } + + function g9(a) { + return f([f, g9, test], true) && f([f, g9, test], false) || + continue f([f, test], true); + } + + function g10(a) { + return f([f, g10, test], true) && f([f, g10, test], false) || + f([f, g10, test], true) ? + f([f, g10, test], true) && f([f, g10, test], false) || + continue f([f, test], true) : + f([f, g10, test], true) && f([f, g10, test], false) || + continue f([f, test], true); + } + + function test() { + assertEquals(true, g1()); + assertEquals(true, g2()); + assertEquals(153, g3()); + assertEquals(true, g4()); + assertEquals(true, g5()); + assertEquals(153, g6()); + assertEquals(true, g7()); + assertEquals(true, g8()); + assertEquals(true, g9()); + assertEquals(true, g10()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Tail calling from various statements. +(function() { + function g3() { + for (var i = 0; i < 10; i++) { + return continue f_153([f_153, test]); + } + } + + function g4() { + while (true) { + return continue f_153([f_153, test]); + } + } + + function g5() { + do { + return continue f_153([f_153, test]); + } while (true); + } + + function test() { + assertEquals(153, g3()); + assertEquals(153, g4()); + assertEquals(153, g5()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from try-catch constructs. +(function() { + function tc1(a) { + try { + f_153([f_153, tc1, test]); + return f_153([f_153, tc1, test]); + } catch(e) { + f_153([f_153, tc1, test]); + } + } + + function tc2(a) { + try { + f_153([f_153, tc2, test]); + throw new Error("boom"); + } catch(e) { + f_153([f_153, tc2, test]); + return continue f_153([f_153, test]); + } + } + + function tc3(a) { + try { + f_153([f_153, tc3, test]); + throw new Error("boom"); + } catch(e) { + f_153([f_153, tc3, test]); + } + f_153([f_153, tc3, test]); + return continue f_153([f_153, test]); + } + + function test() { + assertEquals(153, tc1()); + assertEquals(153, tc2()); + assertEquals(153, tc3()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from try-finally constructs. +(function() { + function tf1(a) { + try { + f_153([f_153, tf1, test]); + return f_153([f_153, tf1, test]); + } finally { + f_153([f_153, tf1, test]); + } + } + + function tf2(a) { + try { + f_153([f_153, tf2, test]); + throw new Error("boom"); + } finally { + f_153([f_153, tf2, test]); + return continue f_153([f_153, test]); + } + } + + function tf3(a) { + try { + f_153([f_153, tf3, test]); + } finally { + f_153([f_153, tf3, test]); + } + return continue f_153([f_153, test]); + } + + function test() { + assertEquals(153, tf1()); + assertEquals(153, tf2()); + assertEquals(153, tf3()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from try-catch-finally constructs. +(function() { + function tcf1(a) { + try { + f_153([f_153, tcf1, test]); + return f_153([f_153, tcf1, test]); + } catch(e) { + } finally { + f_153([f_153, tcf1, test]); + } + } + + function tcf2(a) { + try { + f_153([f_153, tcf2, test]); + throw new Error("boom"); + } catch(e) { + f_153([f_153, tcf2, test]); + return f_153([f_153, tcf2, test]); + } finally { + f_153([f_153, tcf2, test]); + } + } + + function tcf3(a) { + try { + f_153([f_153, tcf3, test]); + throw new Error("boom"); + } catch(e) { + f_153([f_153, tcf3, test]); + } finally { + f_153([f_153, tcf3, test]); + return continue f_153([f_153, test]); + } + } + + function tcf4(a) { + try { + f_153([f_153, tcf4, test]); + throw new Error("boom"); + } catch(e) { + f_153([f_153, tcf4, test]); + } finally { + f_153([f_153, tcf4, test]); + } + return continue f_153([f_153, test]); + } + + function test() { + assertEquals(153, tcf1()); + assertEquals(153, tcf2()); + assertEquals(153, tcf3()); + assertEquals(153, tcf4()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from arrow functions. +(function () { + function g1(a) { + return continue (() => { return continue f_153([f_153, test]); })(); + } + + function g2(a) { + return continue (() => continue f_153([f_153, test]))(); + } + + function g3(a) { + var closure = () => f([f, closure, test], true) + ? continue f_153([f_153, test]) + : continue f_153([f_153, test]); + return continue closure(); + } + + function test() { + assertEquals(153, g1()); + assertEquals(153, g2()); + assertEquals(153, g3()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); + + +// Test tail calls from do expressions. +(function () { + function g1(a) { + var a = do { return continue f_153([f_153, test]); 42; }; + return a; + } + + function test() { + assertEquals(153, g1()); + } + test(); + test(); + %OptimizeFunctionOnNextCall(test); + test(); +})(); diff --git a/deps/v8/test/mjsunit/eval-origin.js b/deps/v8/test/mjsunit/eval-origin.js new file mode 100644 index 0000000000..bb86ef32fc --- /dev/null +++ b/deps/v8/test/mjsunit/eval-origin.js @@ -0,0 +1,39 @@ +// Copyright 2016 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: --nostress-opt + +Error.prepareStackTrace = function(exception, frames) { + return frames[0].getEvalOrigin(); +} + +var source = "new Error()"; +var eval_origin; +var geval = eval; +var log = []; + +(function() { + log.push([geval(source).stack, "17:13"]); + log.push([geval(source).stack, "18:13"]); + // log.push([geval(source).stack, "19:13"]); TODO(4921). +})(); + +(function() { + log.push([eval(source).stack, "23:13"]); + log.push([eval(source).stack, "24:13"]); + // log.push([eval(source).stack, "25:13"]); TODO(4921). +})(); + +log.push([eval(source).stack, "28:11"]); +log.push([eval(source).stack, "29:11"]); +// log.push([eval(source).stack, "30:11"]); TODO(4921). + +Error.prepareStackTrace = undefined; + +for (var item of log) { + var stacktraceline = item[0]; + var expectation = item[1]; + var re = new RegExp(`:${expectation}\\)$`); + assertTrue(re.test(stacktraceline)); +} diff --git a/deps/v8/test/mjsunit/fast-prototype.js b/deps/v8/test/mjsunit/fast-prototype.js index 7432ecce9d..aa0a62e954 100644 --- a/deps/v8/test/mjsunit/fast-prototype.js +++ b/deps/v8/test/mjsunit/fast-prototype.js @@ -46,14 +46,20 @@ function AddProps(obj) { function DoProtoMagic(proto, set__proto__) { + var receiver; if (set__proto__) { - (new Sub()).__proto__ = proto; + receiver = new Sub(); + receiver.__proto__ = proto; } else { Sub.prototype = proto; // Need to instantiate Sub to mark .prototype as prototype. Make sure the // instantiated object is used so that the allocation is not optimized away. - %DebugPrint(new Sub()); + receiver = new Sub(); } + // Prototypes are made fast when ICs encounter them. + function ic() { return typeof receiver.foo; } + ic(); + ic(); } diff --git a/deps/v8/test/mjsunit/for-in.js b/deps/v8/test/mjsunit/for-in.js index bece37a3ee..29d7445351 100644 --- a/deps/v8/test/mjsunit/for-in.js +++ b/deps/v8/test/mjsunit/for-in.js @@ -25,64 +25,141 @@ // (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: --noharmony-for-in + function props(x) { var array = []; for (var p in x) array.push(p); - return array.sort(); + return array; } -assertEquals(0, props({}).length, "olen0"); -assertEquals(1, props({x:1}).length, "olen1"); -assertEquals(2, props({x:1, y:2}).length, "olen2"); +(function forInBasic() { + 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"); + 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"); + 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"); + 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"); - -for (var hest = 'hest' in {}) { } -assertEquals('hest', hest, "empty-no-override"); - -var result = ''; -for (var p in {a : [0], b : 1}) { result += p; } -assertEquals('ab', result, "ab"); - -var result = ''; -for (var p in {a : {v:1}, b : 1}) { result += p; } -assertEquals('ab', result, "ab-nodeep"); - -var result = ''; -for (var p in { get a() {}, b : 1}) { result += p; } -assertEquals('ab', result, "abget"); - -var result = ''; -for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } -assertEquals('ab', result, "abgetset"); +(function forInPrototype() { + // Fast properties + fast elements + var obj = {a:true, 3:true, 4:true}; + obj.__proto__ = {c:true, b:true, 2:true, 1:true, 5:true}; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a125cb".split(""), props(obj)); + } + // Fast properties + dictionary elements + delete obj.__proto__[2]; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a15cb".split(""), props(obj)); + } + // Slow properties + dictionary elements + delete obj.__proto__.c; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a15b".split(""), props(obj)); + } + // Slow properties on the receiver as well + delete obj.a; + for (var i = 0; i < 3; i++) { + assertArrayEquals("3415b".split(""), props(obj)); + } + delete obj[3]; + for (var i = 0; i < 3; i++) { + assertArrayEquals("415b".split(""), props(obj)); + } +})(); + +(function forInShadowing() { + var obj = {a:true, 3:true, 4:true}; + obj.__proto__ = { + c:true, b:true, x:true, + 2:true, 1:true, 5:true, 9:true}; + Object.defineProperty(obj, 'x', {value:true, enumerable:false, configurable:true}); + Object.defineProperty(obj, '9', {value:true, enumerable:false, configurable:true}); + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a125cb".split(""), props(obj)); + } + // Fast properties + dictionary elements + delete obj.__proto__[2]; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a15cb".split(""), props(obj)); + } + // Slow properties + dictionary elements + delete obj.__proto__.c; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a15b".split(""), props(obj)); + } + // Remove the shadowing properties + delete obj.x; + delete obj[9]; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34a159bx".split(""), props(obj)); + } + // Slow properties on the receiver as well + delete obj.a; + for (var i = 0; i < 3; i++) { + assertArrayEquals("34159bx".split(""), props(obj)); + } + delete obj[3]; + for (var i = 0; i < 3; i++) { + assertArrayEquals("4159bx".split(""), props(obj)); + } +})(); + +(function forInCharCodes() { + 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"); +})(); + +(function forInArray() { + 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"); +})(); + +(function forInInitialize() { + for (var hest = 'hest' in {}) { } + assertEquals('hest', hest, "empty-no-override"); +})(); + +(function forInObjects() { + var result = ''; + for (var p in {a : [0], b : 1}) { result += p; } + assertEquals('ab', result, "ab"); + + var result = ''; + for (var p in {a : {v:1}, b : 1}) { result += p; } + assertEquals('ab', result, "ab-nodeep"); + + var result = ''; + for (var p in { get a() {}, b : 1}) { result += p; } + assertEquals('ab', result, "abget"); + + var result = ''; + for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } + assertEquals('ab', result, "abgetset"); +})(); // Test that for-in in the global scope works with a keyed property as "each". diff --git a/deps/v8/test/mjsunit/function-name-eval-shadowed.js b/deps/v8/test/mjsunit/function-name-eval-shadowed.js new file mode 100644 index 0000000000..70cc4b9c54 --- /dev/null +++ b/deps/v8/test/mjsunit/function-name-eval-shadowed.js @@ -0,0 +1,5 @@ +// Copyright 2016 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. + +assertEquals(200, (function f() { eval("var f = 100"); f = 200; return f })()); diff --git a/deps/v8/test/mjsunit/global-arrow-delete-this.js b/deps/v8/test/mjsunit/global-arrow-delete-this.js new file mode 100644 index 0000000000..9ebe8e48b4 --- /dev/null +++ b/deps/v8/test/mjsunit/global-arrow-delete-this.js @@ -0,0 +1,18 @@ +// Copyright 2016 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. + +// Make sure that we correctly resolve this when compiling an arrow function in +// a with scope in an arrow function. +a = () => { + let x + with ({}) x = () => { "use strict"; delete this } + return x +} +a()() + + +// Make sure that we correctly resolve this when compiling a program in an arrow +// function. +a = ()=>eval('"use strict"; delete this') +a() diff --git a/deps/v8/test/mjsunit/harmony/array-concat-array-proto-getter.js b/deps/v8/test/mjsunit/harmony/array-concat-array-proto-getter.js new file mode 100644 index 0000000000..9368e7fb6c --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-array-proto-getter.js @@ -0,0 +1,53 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype + +"use strict" + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +var concatSpreadable = false; +Object.defineProperty(Array.prototype, Symbol.isConcatSpreadable, { + get() { return concatSpreadable }, + configurable: true +}); + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +concatSpreadable = true; + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals([object], [].concat(object)); +assertEquals([1, 2, 3, object], array.concat(object)); +assertEquals([object], Array.prototype.concat.call(object,[])); +assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + + +delete Array.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/array-concat-array-proto.js b/deps/v8/test/mjsunit/harmony/array-concat-array-proto.js new file mode 100644 index 0000000000..520178fdaa --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-array-proto.js @@ -0,0 +1,48 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype + +"use strict" + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +Array.prototype[Symbol.isConcatSpreadable] = false; + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +Array.prototype[Symbol.isConcatSpreadable] = true; + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals([object], [].concat(object)); +assertEquals([1, 2, 3, object], array.concat(object)); +assertEquals([object], Array.prototype.concat.call(object,[])); +assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +delete Array.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict-getter.js b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict-getter.js new file mode 100644 index 0000000000..6e61588789 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict-getter.js @@ -0,0 +1,57 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype +// with a dictionary backing store. + +// Force Object.prototype into dictionary backing store by adding many +// properties. +for (var i = 0; i < 10*1000; i++) { + Object.prototype['generatedProperty'+i] = true; +} + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +var concatSpreadable = false; +Object.defineProperty(Object.prototype, Symbol.isConcatSpreadable, { + get() { return concatSpreadable }, + configurable: true +}); + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +concatSpreadable = true; + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals(['a'], [].concat(object)); +assertEquals([1, 2, 3, 'a'], array.concat(object)); +assertEquals(['a'], Array.prototype.concat.call(object,[])); +assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); + +delete Object.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict.js b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict.js new file mode 100644 index 0000000000..c817006c16 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-dict.js @@ -0,0 +1,53 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype +// with a dictionary backing store. + +// Force Object.prototype into dictionary backing store by adding many +// properties. +for (var i = 0; i < 10*1000; i++) { + Object.prototype['generatedProperty'+i] = true; +} + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +Object.prototype[Symbol.isConcatSpreadable] = false; + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +Object.prototype[Symbol.isConcatSpreadable] = true; + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals(['a'], [].concat(object)); +assertEquals([1, 2, 3, 'a'], array.concat(object)); +assertEquals(['a'], Array.prototype.concat.call(object,[])); +assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); + +delete Object.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/array-concat-object-proto-generic-dict.js b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-generic-dict.js new file mode 100644 index 0000000000..7b61422a44 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-object-proto-generic-dict.js @@ -0,0 +1,65 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype +// with a dictionary backing store. + +// Force Object.prototype into dictionary backing store by adding many +// properties. +for (var i = 0; i < 10*1000; i++) { + Object.prototype['generatedProperty'+i] = true; +} + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function SetProperty(receiver, key, value) { + receiver[key] = value; +} + +// Force the Keyed Store IC in SetProperty to be generic. +var receiver = {}; +for (var i = 0; i < 100; i++) { + SetProperty(receiver, 'prop'+i, 'value'); +} + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +// Use a generic IC to set @@isConcatSpreadable +SetProperty(Object.prototype, Symbol.isConcatSpreadable, false); + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +// Use a generic IC to set @@isConcatSpreadable +SetProperty(Object.prototype, Symbol.isConcatSpreadable, true); + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals(['a'], [].concat(object)); +assertEquals([1, 2, 3, 'a'], array.concat(object)); +assertEquals(['a'], Array.prototype.concat.call(object,[])); +assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); + +delete Object.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/array-concat-object-proto.js b/deps/v8/test/mjsunit/harmony/array-concat-object-proto.js new file mode 100644 index 0000000000..307326cbcd --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-concat-object-proto.js @@ -0,0 +1,48 @@ +// Copyright 2016 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. + +// Check that @@isConcatSpreadable is checked when set on Object.prototype + +"use strict" + +var array = [1, 2, 3]; +var object = {length: 1, '0': 'a'}; + +function testConcatDefaults() { + assertEquals(array, [].concat(array)); + assertEquals(array, array.concat([])); + assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); + assertEquals([object], [].concat(object)); + assertEquals([1, 2, 3, object], array.concat(object)); + assertEquals([object], Array.prototype.concat.call(object,[])); + assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); + assertEquals([object, object], Array.prototype.concat.call(object, object)); +} + +testConcatDefaults(); + +Object.prototype[Symbol.isConcatSpreadable] = false; + +assertEquals([[], array], [].concat(array)); +assertEquals([array, []], array.concat([])); +assertEquals([array, array], array.concat(array)); +assertEquals([[], object], [].concat(object)); +assertEquals([array, object], array.concat(object)); +assertEquals([object, []], Array.prototype.concat.call(object,[])); +assertEquals([object, array], Array.prototype.concat.call(object, array)); +assertEquals([object, object], Array.prototype.concat.call(object, object)); + +Object.prototype[Symbol.isConcatSpreadable] = true; + +assertEquals(array, [].concat(array)); +assertEquals(array, array.concat([])); +assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); +assertEquals(['a'], [].concat(object)); +assertEquals([1, 2, 3, 'a'], array.concat(object)); +assertEquals(['a'], Array.prototype.concat.call(object,[])); +assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); +assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); + +delete Object.prototype[Symbol.isConcatSpreadable]; +testConcatDefaults(); diff --git a/deps/v8/test/mjsunit/harmony/async-arrow-lexical-arguments.js b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-arguments.js new file mode 100644 index 0000000000..44d38a4275 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-arguments.js @@ -0,0 +1,42 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +assertEqualsAsync("[1,2,3]", () => (function() { + return (async () => JSON.stringify([...arguments]))(); +})(1, 2, 3)); + +assertEqualsAsync("[4,5,6]", + () => (function() { + return (async () => { + return JSON.stringify([...await arguments]) })(); + })(4, 5, 6)); diff --git a/deps/v8/test/mjsunit/harmony/async-arrow-lexical-new.target.js b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-new.target.js new file mode 100644 index 0000000000..72b29e69e9 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-new.target.js @@ -0,0 +1,43 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +class BaseClass { + constructor() { + return async () => new.target; + } +} + +class ChildClass extends BaseClass {} + +assertEqualsAsync(BaseClass, () => new BaseClass()()); +assertEqualsAsync(ChildClass, () => new ChildClass()()); diff --git a/deps/v8/test/mjsunit/harmony/async-arrow-lexical-super.js b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-super.js new file mode 100644 index 0000000000..78f5d555b6 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-super.js @@ -0,0 +1,58 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +class BaseClass { + constructor(x) { + this.name_ = x; + } + get name() { return this.name_; } +}; + +class DeferredSuperCall extends BaseClass { + constructor(x) { + return async() => super(x); + } +}; + +assertEqualsAsync( + "LexicalSuperCall", + () => new DeferredSuperCall("LexicalSuperCall")().then(x => x.name)); + + +class DeferredSuperProperty extends BaseClass { + deferredName() { return async() => super.name; } +}; + +assertEqualsAsync( + "LexicalSuperProperty", + () => new DeferredSuperProperty("LexicalSuperProperty").deferredName()()); diff --git a/deps/v8/test/mjsunit/harmony/async-arrow-lexical-this.js b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-this.js new file mode 100644 index 0000000000..182db47a22 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-arrow-lexical-this.js @@ -0,0 +1,48 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +var O = { + [Symbol.toStringTag]: "LexicalThis", + run(n) { + return async passFail => `${n}. ${passFail}: ${this}`; + }, +}; + +assertEqualsAsync("1. PASS: [object LexicalThis]", () => O.run(1)("PASS")); + +var O2 = { + [Symbol.toStringTag]: "LexicalThis", + run: O.run(2) +}; + +assertEqualsAsync("2. PASS: [object LexicalThis]", () => O2.run("PASS")); diff --git a/deps/v8/test/mjsunit/harmony/async-await-basic.js b/deps/v8/test/mjsunit/harmony/async-await-basic.js new file mode 100644 index 0000000000..51572cdb9f --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-await-basic.js @@ -0,0 +1,378 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +// Do not install `AsyncFunction` constructor on global object + +function assertThrowsAsync(run, errorType, message) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (!hadError) { + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw " + errorType.name + + ", but did not throw."); + } + if (!(actual instanceof errorType)) + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw " + errorType.name + + ", but threw '" + actual + "'"); + if (message !== void 0 && actual.message !== message) + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw '" + message + "', but threw '" + + actual.message + "'"); +}; + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +assertEquals(undefined, this.AsyncFunction); +let AsyncFunction = (async function() {}).constructor; + +// The AsyncFunction Constructor is the %AsyncFunction% intrinsic object and +// is a subclass of Function. +// (https://tc39.github.io/ecmascript-asyncawait/#async-function-constructor) +assertEquals(Object.getPrototypeOf(AsyncFunction), Function); +assertEquals(Object.getPrototypeOf(AsyncFunction.prototype), + Function.prototype); +assertTrue(async function() {} instanceof Function); + + +// Let functionPrototype be the intrinsic object %AsyncFunctionPrototype%. +async function asyncFunctionForProto() {} +assertEquals(AsyncFunction.prototype, + Object.getPrototypeOf(asyncFunctionForProto)); +assertEquals(AsyncFunction.prototype, + Object.getPrototypeOf(async function() {})); +assertEquals(AsyncFunction.prototype, Object.getPrototypeOf(async () => {})); +assertEquals(AsyncFunction.prototype, + Object.getPrototypeOf({ async method() {} }.method)); +assertEquals(AsyncFunction.prototype, Object.getPrototypeOf(AsyncFunction())); +assertEquals(AsyncFunction.prototype, + Object.getPrototypeOf(new AsyncFunction())); + +// AsyncFunctionCreate does not produce an object with a Prototype +assertEquals(undefined, asyncFunctionForProto.prototype); +assertEquals(false, asyncFunctionForProto.hasOwnProperty("prototype")); +assertEquals(undefined, (async function() {}).prototype); +assertEquals(false, (async function() {}).hasOwnProperty("prototype")); +assertEquals(undefined, (async() => {}).prototype); +assertEquals(false, (async() => {}).hasOwnProperty("prototype")); +assertEquals(undefined, ({ async method() {} }).method.prototype); +assertEquals(false, ({ async method() {} }).method.hasOwnProperty("prototype")); +assertEquals(undefined, AsyncFunction().prototype); +assertEquals(false, AsyncFunction().hasOwnProperty("prototype")); +assertEquals(undefined, (new AsyncFunction()).prototype); +assertEquals(false, (new AsyncFunction()).hasOwnProperty("prototype")); + +assertEquals(1, async function(a) { await 1; }.length); +assertEquals(2, async function(a, b) { await 1; }.length); +assertEquals(1, async function(a, b = 2) { await 1; }.length); +assertEquals(2, async function(a, b, ...c) { await 1; }.length); + +assertEquals(1, (async(a) => await 1).length); +assertEquals(2, (async(a, b) => await 1).length); +assertEquals(1, (async(a, b = 2) => await 1).length); +assertEquals(2, (async(a, b, ...c) => await 1).length); + +assertEquals(1, ({ async f(a) { await 1; } }).f.length); +assertEquals(2, ({ async f(a, b) { await 1; } }).f.length); +assertEquals(1, ({ async f(a, b = 2) { await 1; } }).f.length); +assertEquals(2, ({ async f(a, b, ...c) { await 1; } }).f.length); + +assertEquals(1, AsyncFunction("a", "await 1").length); +assertEquals(2, AsyncFunction("a", "b", "await 1").length); +assertEquals(1, AsyncFunction("a", "b = 2", "await 1").length); +assertEquals(2, AsyncFunction("a", "b", "...c", "await 1").length); + +assertEquals(1, (new AsyncFunction("a", "await 1")).length); +assertEquals(2, (new AsyncFunction("a", "b", "await 1")).length); +assertEquals(1, (new AsyncFunction("a", "b = 2", "await 1")).length); +assertEquals(2, (new AsyncFunction("a", "b", "...c", "await 1")).length); + +// AsyncFunction.prototype[ @@toStringTag ] +var descriptor = + Object.getOwnPropertyDescriptor(AsyncFunction.prototype, + Symbol.toStringTag); +assertEquals("AsyncFunction", descriptor.value); +assertEquals(false, descriptor.enumerable); +assertEquals(false, descriptor.writable); +assertEquals(true, descriptor.configurable); + +assertEquals(1, AsyncFunction.length); + +// Let F be ! FunctionAllocate(functionPrototype, Strict, "non-constructor") +async function asyncNonConstructorDecl() {} +assertThrows( + () => new asyncNonConstructorDecl(), TypeError); +assertThrows( + () => new (async function() {}), TypeError); +assertThrows( + () => new ({ async nonConstructor() {} }).nonConstructor(), TypeError); +assertThrows( + () => new (() => "not a constructor!"), TypeError); +assertThrows( + () => new (AsyncFunction()), TypeError); +assertThrows( + () => new (new AsyncFunction()), TypeError); + +// Normal completion +async function asyncDecl() { return "test"; } +assertEqualsAsync("test", asyncDecl); +assertEqualsAsync("test2", async function() { return "test2"; }); +assertEqualsAsync("test3", async () => "test3"); +assertEqualsAsync("test4", () => ({ async f() { return "test4"; } }).f()); +assertEqualsAsync("test5", () => AsyncFunction("no", "return 'test' + no;")(5)); +assertEqualsAsync("test6", + () => (new AsyncFunction("no", "return 'test' + no;"))(6)); + +class MyError extends Error {}; + +// Throw completion +async function asyncDeclThrower(e) { throw new MyError(e); } +assertThrowsAsync(() => asyncDeclThrower("boom!"), MyError, "boom!"); +assertThrowsAsync( + () => (async function(e) { throw new MyError(e); })("boom!!!"), + MyError, "boom!!!"); +assertThrowsAsync( + () => (async e => { throw new MyError(e) })("boom!!"), MyError, "boom!!"); +assertThrowsAsync( + () => ({ async thrower(e) { throw new MyError(e); } }).thrower("boom!1!"), + MyError, "boom!1!"); +assertThrowsAsync( + () => AsyncFunction("msg", "throw new MyError(msg)")("boom!2!!"), + MyError, "boom!2!!"); +assertThrowsAsync( + () => (new AsyncFunction("msg", "throw new MyError(msg)"))("boom!2!!!"), + MyError, "boom!2!!!"); + +function resolveLater(value) { return Promise.resolve(value); } +function rejectLater(error) { return Promise.reject(error); } + +// Resume after Normal completion +var log = []; +async function resumeAfterNormal(value) { + log.push("start:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + return value + 1; +} + +assertEqualsAsync(4, () => resumeAfterNormal(1)); +assertEquals("start:1 resume:2 resume:3", log.join(" ")); + +var O = { + async resumeAfterNormal(value) { + log.push("start:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + return value + 1; + } +}; +log = []; +assertEqualsAsync(5, () => O.resumeAfterNormal(2)); +assertEquals("start:2 resume:3 resume:4", log.join(" ")); + +var resumeAfterNormalArrow = async (value) => { + log.push("start:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + return value + 1; +}; +log = []; +assertEqualsAsync(6, () => resumeAfterNormalArrow(3)); +assertEquals("start:3 resume:4 resume:5", log.join(" ")); + +var resumeAfterNormalEval = AsyncFunction("value", ` + log.push("start:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + return value + 1;`); +log = []; +assertEqualsAsync(7, () => resumeAfterNormalEval(4)); +assertEquals("start:4 resume:5 resume:6", log.join(" ")); + +var resumeAfterNormalNewEval = new AsyncFunction("value", ` + log.push("start:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + value = await resolveLater(value + 1); + log.push("resume:" + value); + return value + 1;`); +log = []; +assertEqualsAsync(8, () => resumeAfterNormalNewEval(5)); +assertEquals("start:5 resume:6 resume:7", log.join(" ")); + +// Resume after Throw completion +async function resumeAfterThrow(value) { + log.push("start:" + value); + try { + value = await rejectLater("throw1"); + } catch (e) { + log.push("resume:" + e); + } + try { + value = await rejectLater("throw2"); + } catch (e) { + log.push("resume:" + e); + } + return value + 1; +} + +log = []; +assertEqualsAsync(2, () => resumeAfterThrow(1)); +assertEquals("start:1 resume:throw1 resume:throw2", log.join(" ")); + +var O = { + async resumeAfterThrow(value) { + log.push("start:" + value); + try { + value = await rejectLater("throw1"); + } catch (e) { + log.push("resume:" + e); + } + try { + value = await rejectLater("throw2"); + } catch (e) { + log.push("resume:" + e); + } + return value + 1; + } +} +log = []; +assertEqualsAsync(3, () => O.resumeAfterThrow(2)); +assertEquals("start:2 resume:throw1 resume:throw2", log.join(" ")); + +var resumeAfterThrowArrow = async (value) => { + log.push("start:" + value); + try { + value = await rejectLater("throw1"); + } catch (e) { + log.push("resume:" + e); + } + try { + value = await rejectLater("throw2"); + } catch (e) { + log.push("resume:" + e); + } + return value + 1; +}; + +log = []; + +assertEqualsAsync(4, () => resumeAfterThrowArrow(3)); +assertEquals("start:3 resume:throw1 resume:throw2", log.join(" ")); + +var resumeAfterThrowEval = AsyncFunction("value", ` + log.push("start:" + value); + try { + value = await rejectLater("throw1"); + } catch (e) { + log.push("resume:" + e); + } + try { + value = await rejectLater("throw2"); + } catch (e) { + log.push("resume:" + e); + } + return value + 1;`); +log = []; +assertEqualsAsync(5, () => resumeAfterThrowEval(4)); +assertEquals("start:4 resume:throw1 resume:throw2", log.join(" ")); + +var resumeAfterThrowNewEval = new AsyncFunction("value", ` + log.push("start:" + value); + try { + value = await rejectLater("throw1"); + } catch (e) { + log.push("resume:" + e); + } + try { + value = await rejectLater("throw2"); + } catch (e) { + log.push("resume:" + e); + } + return value + 1;`); +log = []; +assertEqualsAsync(6, () => resumeAfterThrowNewEval(5)); +assertEquals("start:5 resume:throw1 resume:throw2", log.join(" ")); + +async function foo() {} +assertEquals("async function foo() {}", foo.toString()); +assertEquals("async function () {}", async function () {}.toString()); +assertEquals("async x => x", (async x => x).toString()); +assertEquals("async x => { return x }", (async x => { return x }).toString()); +class AsyncMethod { async foo() { } } +assertEquals("async foo() { }", + Function.prototype.toString.call(AsyncMethod.prototype.foo)); +assertEquals("async foo() { }", + Function.prototype.toString.call({async foo() { }}.foo)); + +// Async functions are not constructible +assertThrows(() => class extends (async function() {}) {}, TypeError); + +// Regress v8:5148 +assertEqualsAsync("1", () => (async({ a = NaN }) => a)({ a: "1" })); +assertEqualsAsync( + "10", () => (async(foo, { a = NaN }) => foo + a)("1", { a: "0" })); +assertEqualsAsync("2", () => (async({ a = "2" }) => a)({ a: undefined })); +assertEqualsAsync( + "20", () => (async(foo, { a = "0" }) => foo + a)("2", { a: undefined })); +assertThrows(() => eval("async({ foo = 1 })"), SyntaxError); +assertThrows(() => eval("async(a, { foo = 1 })"), SyntaxError); + +// https://bugs.chromium.org/p/chromium/issues/detail?id=638019 +async function gaga() { + let i = 1; + while (i-- > 0) { await 42 } +} +assertDoesNotThrow(gaga); diff --git a/deps/v8/test/mjsunit/harmony/async-await-no-constructor.js b/deps/v8/test/mjsunit/harmony/async-await-no-constructor.js new file mode 100644 index 0000000000..30020019a6 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-await-no-constructor.js @@ -0,0 +1,27 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +'use strict'; + +var resolved = Promise.resolve(); +var count = 0; + +Object.defineProperty(Promise.prototype, 'constructor', + { get() { count++; return Promise; } }) + +async function foo() { + await resolved; + return resolved; +} + +async function bar() { + throw 1; +} + +foo(); +bar(); +%RunMicrotasks(); +assertEquals(0, count); diff --git a/deps/v8/test/mjsunit/harmony/async-await-resolve-new.js b/deps/v8/test/mjsunit/harmony/async-await-resolve-new.js new file mode 100644 index 0000000000..0711c95873 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-await-resolve-new.js @@ -0,0 +1,9 @@ +// Copyright 2016 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-async-await + +var resolved = Promise.resolve(); + +assertTrue((async() => resolved)() !== resolved); diff --git a/deps/v8/test/mjsunit/harmony/async-await-species.js b/deps/v8/test/mjsunit/harmony/async-await-species.js new file mode 100644 index 0000000000..bc3db83fdf --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-await-species.js @@ -0,0 +1,101 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +// Rename a function so that it can help omit things from stack trace. +function test(fn) { + return Object.defineProperty(fn, "name", { + enumerable: false, + configurable: true, + value: "@" + fn.name, + writable: false + }); +} + +function getStack(error) { + var stack = error.stack.split('\n'). + filter(function(line) { + return /^\s*at @?[a-zA-Z0-9_]/.test(line); + }). + map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1")); + + // remove `Promise.then()` invocation by assertEqualsAsync() + if (stack[2] === "assertEqualsAsync") return []; + + return stack.reverse(); +} + +var log = []; +class FakePromise extends Promise { + constructor(executor) { + var stack = getStack(new Error("Getting Callstack")); + if (stack.length) { + var first = -1; + for (var i = 0; i < stack.length; ++i) { + if (stack[i][0] === '@') { + first = i; + break; + } + } + while (first > 0) stack.shift(), --first; + if (stack.length) { + log.push("@@Species: [" + stack.join(" > ") + "]"); + } + } + return new Promise(executor); + } +}; + +Object.defineProperty(Promise, Symbol.species, { + value: FakePromise, + configurable: true, + enumerable: false, + writable: false +}); + +// Internal `AsyncFunctionAwait` only --- no @@species invocations. +async function asyncFn() { return await "foo"; } +assertEqualsAsync("foo", test(function testInternalOnly() { return asyncFn(); }, + "should not call Promise[@@Species]")); +assertEquals([], log); + +log.length = 0; +assertEqualsAsync( + "foo", + test(function testThenOnReturnedPromise() { + return asyncFn().then(x => (log.push("Then: " + x), x)); + }), + "should call Promise[@@Species] after non-internal Then"); +assertEquals([ + "@@Species: [@testThenOnReturnedPromise > Promise.then > FakePromise]", + "Then: foo" +], log); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-basic.js b/deps/v8/test/mjsunit/harmony/async-debug-basic.js new file mode 100644 index 0000000000..a4909729c5 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-basic.js @@ -0,0 +1,40 @@ +// Copyright 2016 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-async-await --allow-natives-syntax --expose-debug-as debug + +// Get the Debug object exposed from the debug context global object. +Debug = debug.Debug + +listenerComplete = false; +breakPointCount = 0; + +async function f() { + await (async function() { var a = "a"; await 1; debugger; })(); + + var b = "b"; + + assertTrue(listenerDone); + assertFalse(exception); + assertEquals(1, breakpointCount); +} + +function listener(event, exec_state, event_data, data) { + try { + if (event != Debug.DebugEvent.Break) return; + + breakpointCount++; + listenerDone = true; + assertEquals("a", exec_state.frame(0).evaluate("a")); + assertEquals("b", exec_state.frame(1).evaluate("b")); + assertEquals("c", exec_state.frame(2).evaluate("c")); + } catch (e) { + exception = e; + }; +}; + +Debug.setListener(listener); + +var c = "c"; +f(); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-caught-exception.js b/deps/v8/test/mjsunit/harmony/async-debug-caught-exception.js new file mode 100644 index 0000000000..b2ae18437d --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-caught-exception.js @@ -0,0 +1,89 @@ +// Copyright 2016 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-async-await --expose-debug-as debug + +Debug = debug.Debug + +var exception = null; +var log; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + var line = exec_state.frame(0).sourceLineText(); + var match = /Exception (\w)/.exec(line); + assertNotNull(match); + log.push(match[1]); + } catch (e) { + exception = e; + } +} + +async function thrower() { + throw "a"; // Exception a +} + +async function caught_throw() { + try { + await thrower(); + } catch (e) { + assertEquals("a", e); + } +} + + +// Caught throw, events on any exception. +log = []; +Debug.setListener(listener); +Debug.setBreakOnException(); +caught_throw(); +%RunMicrotasks(); +Debug.setListener(null); +Debug.clearBreakOnException(); +assertEquals(["a"], log); +assertNull(exception); + +// Caught throw, events on uncaught exception. +log = []; +Debug.setListener(listener); +Debug.setBreakOnUncaughtException(); +caught_throw(); +%RunMicrotasks(); +Debug.setListener(null); +Debug.clearBreakOnUncaughtException(); +assertEquals([], log); +assertNull(exception); + +var reject = Promise.reject("b"); + +async function caught_reject() { + try { + await reject; + } catch (e) { + assertEquals("b", e); + } +} + +// Caught reject, events on any exception. +log = []; +Debug.setListener(listener); +Debug.setBreakOnException(); +caught_reject(); +%RunMicrotasks(); +Debug.setListener(null); +Debug.clearBreakOnException(); +assertEquals([], log); +assertNull(exception); + +// Caught reject, events on uncaught exception. +log = []; +Debug.setListener(listener); +Debug.setBreakOnUncaughtException(); +caught_reject(); +%RunMicrotasks(); +Debug.setListener(null); +Debug.clearBreakOnUncaughtException(); +assertEquals([], log); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-abort-at-break.js b/deps/v8/test/mjsunit/harmony/async-debug-step-abort-at-break.js new file mode 100644 index 0000000000..be1f8056a8 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-abort-at-break.js @@ -0,0 +1,55 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B3 StepOut + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B4 StepNext + g(); // B2 StepIn + return a; +} + +f(); + +// Starting a new step action at an intermediate break point +// means that we will abort the current async step. +debugger; // B5 StepNext + +late_resolve(3); // B6 Continue + +%RunMicrotasks(); + +assertEquals(7, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-continue-at-break.js b/deps/v8/test/mjsunit/harmony/async-debug-step-continue-at-break.js new file mode 100644 index 0000000000..5099b2f53e --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-continue-at-break.js @@ -0,0 +1,55 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B3 StepOut + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B4 StepNext + g(); // B2 StepIn + return a; // B6 StepNext +} // B7 Continue + +f(); + +// Continuing at an intermediate break point means that we will +// carry on with the current async step. +debugger; // B5 Continue + +late_resolve(3); + +%RunMicrotasks(); + +assertEquals(8, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-in-and-out.js b/deps/v8/test/mjsunit/harmony/async-debug-step-in-and-out.js new file mode 100644 index 0000000000..30fe2d6053 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-in-and-out.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B3 StepOut + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B4 StepNext + g(); // B2 StepIn + return a; // B5 StepNext +} // B6 Continue + +f(); + +late_resolve(3); + +%RunMicrotasks(); + +assertEquals(7, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-in-out-out.js b/deps/v8/test/mjsunit/harmony/async-debug-step-in-out-out.js new file mode 100644 index 0000000000..c2f34bb029 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-in-out-out.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B3 StepOut + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B4 StepOut + g(); // B2 StepIn + return a; +} + +f(); + +late_resolve(3); // B5 Continue + +%RunMicrotasks(); + +assertEquals(6, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-in.js b/deps/v8/test/mjsunit/harmony/async-debug-step-in.js new file mode 100644 index 0000000000..0a7de1a2a3 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-in.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B3 StepIn + function(res, rej) { + late_resolve = res; // B4 StepIn + } // B5 StepIn + ); +} // B6 StepIn + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepIn + await // B7 StepIn + g(); // B2 StepIn + return a; // B8 StepIn +} // B9 Continue + +f().then(value => assertEquals(4, value)); + +late_resolve(3); + +%RunMicrotasks(); + +assertEquals(10, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-nested.js b/deps/v8/test/mjsunit/harmony/async-debug-step-nested.js new file mode 100644 index 0000000000..adf7a51432 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-nested.js @@ -0,0 +1,58 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( // B4 StepOut + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f1() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B6 StepNext + f2(); // B2 StepIn + return a; // B7 StepNext +} // B8 Continue + +async function f2() { + var b = + await // B5 StepOut + g(); // B3 StepIn + return b; +} + +f1(); + +late_resolve(3); + +%RunMicrotasks(); + +assertEquals(9, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-next-constant.js b/deps/v8/test/mjsunit/harmony/async-debug-step-next-constant.js new file mode 100644 index 0000000000..cea86d7a2f --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-next-constant.js @@ -0,0 +1,39 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B3 StepNext + 5; // B2 StepNext + return a; // B4 StepNext +} // B5 Continue + +f(); + +%RunMicrotasks(); + +assertEquals(6, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-next.js b/deps/v8/test/mjsunit/harmony/async-debug-step-next.js new file mode 100644 index 0000000000..952d88dd85 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-next.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += // B1 StepNext + await // B3 StepNext + g(); // B2 StepNext + return a; // B4 StepNext +} // B5 Continue + +f(); + +late_resolve(3); + +%RunMicrotasks(); + +assertEquals(6, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-debug-step-out.js b/deps/v8/test/mjsunit/harmony/async-debug-step-out.js new file mode 100644 index 0000000000..41779acb54 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-debug-step-out.js @@ -0,0 +1,49 @@ +// Copyright 2016 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 --harmony-async-await + +var Debug = debug.Debug; +var step_count = 0; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = execState.frame(0).sourceLineText(); + print(line); + var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line); + assertEquals(step_count++, parseInt(expected_count)); + if (step != "Continue") execState.prepareStep(Debug.StepAction[step]); + } catch (e) { + print(e, e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var late_resolve; + +function g() { + return new Promise( + function(res, rej) { + late_resolve = res; + } + ); +} + +async function f() { + var a = 1; + debugger; // B0 StepNext + a += await g(); // B1 StepOut + return a; +} + +f(); + +late_resolve(3); // B2 Continue + +%RunMicrotasks(); + +assertEquals(3, step_count); diff --git a/deps/v8/test/mjsunit/harmony/async-destructuring.js b/deps/v8/test/mjsunit/harmony/async-destructuring.js new file mode 100644 index 0000000000..95dbc18c7b --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-destructuring.js @@ -0,0 +1,515 @@ +// Copyright 2016 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-async-await --allow-natives-syntax + +function assertThrowsAsync(run, errorType, message) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (!hadError) { + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw " + errorType.name + + ", but did not throw."); + } + if (!(actual instanceof errorType)) + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw " + errorType.name + + ", but threw '" + actual + "'"); + if (message !== void 0 && actual.message !== message) + throw new MjsUnitAssertionError( + "Expected " + run + "() to throw '" + message + "', but threw '" + + actual.message + "'"); +}; + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + PrettyPrint(promise)); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +}; + +(function TestDefaultEvaluationOrder() { + var y = 0; + var z = 0; + var w = 0; + async function f1(x = (y = 1)) { z = 1; await undefined; w = 1; }; + assertEquals(0, y); + assertEquals(0, z); + assertEquals(0, w); + f1(); + assertEquals(1, y); + assertEquals(1, z); + assertEquals(0, w); + %RunMicrotasks(); + assertEquals(1, y); + assertEquals(1, z); + assertEquals(1, w); +})(); + +(function TestShadowingOfParameters() { + async function f1({x}) { var x = 2; return x } + assertEqualsAsync(2, () => f1({x: 1})); + async function f2({x}) { { var x = 2; } return x; } + assertEqualsAsync(2, () => f2({x: 1})); + async function f3({x}) { var y = x; var x = 2; return y; } + assertEqualsAsync(1, () => f3({x: 1})); + async function f4({x}) { { var y = x; var x = 2; } return y; } + assertEqualsAsync(1, () => f4({x: 1})); + async function f5({x}, g = () => x) { var x = 2; return g(); } + assertEqualsAsync(1, () => f5({x: 1})); + async function f6({x}, g = () => x) { { var x = 2; } return g(); } + assertEqualsAsync(1, () => f6({x: 1})); + async function f7({x}) { var g = () => x; var x = 2; return g(); } + assertEqualsAsync(2, () => f7({x: 1})); + async function f8({x}) { { var g = () => x; var x = 2; } return g(); } + assertEqualsAsync(2, () => f8({x: 1})); + async function f9({x}, g = () => eval("x")) { var x = 2; return g(); } + assertEqualsAsync(1, () => f9({x: 1})); + + async function f10({x}, y) { var y; return y } + assertEqualsAsync(2, () => f10({x: 6}, 2)); + async function f11({x}, y) { var z = y; var y = 2; return z; } + assertEqualsAsync(1, () => f11({x: 6}, 1)); + async function f12(y, g = () => y) { var y = 2; return g(); } + assertEqualsAsync(1, () => f12(1)); + async function f13({x}, y, [z], v) { var x, y, z; return x*y*z*v } + assertEqualsAsync(210, () => f13({x: 2}, 3, [5], 7)); + + async function f20({x}) { function x() { return 2 }; return x(); } + assertEqualsAsync(2, () => f20({x: 1})); + // Annex B 3.3 function hoisting is blocked by the conflicting x declaration + async function f21({x}) { { function x() { return 2 } } return x; } + assertEqualsAsync(1, () => f21({x: 1})); + + var g1 = async ({x}) => { var x = 2; return x }; + assertEqualsAsync(2, () => g1({x: 1})); + var g2 = async ({x}) => { { var x = 2; } return x; }; + assertEqualsAsync(2, () => g2({x: 1})); + var g3 = async ({x}) => { var y = x; var x = 2; return y; }; + assertEqualsAsync(1, () => g3({x: 1})); + var g4 = async ({x}) => { { var y = x; var x = 2; } return y; }; + assertEqualsAsync(1, () => g4({x: 1})); + var g5 = async ({x}, g = () => x) => { var x = 2; return g(); }; + assertEqualsAsync(1, () => g5({x: 1})); + var g6 = async ({x}, g = () => x) => { { var x = 2; } return g(); }; + assertEqualsAsync(1, () => g6({x: 1})); + var g7 = async ({x}) => { var g = () => x; var x = 2; return g(); }; + assertEqualsAsync(2, () => g7({x: 1})); + var g8 = async ({x}) => { { var g = () => x; var x = 2; } return g(); }; + assertEqualsAsync(2, () => g8({x: 1})); + var g9 = async ({x}, g = () => eval("x")) => { var x = 2; return g(); }; + assertEqualsAsync(1, () => g9({x: 1})); + + var g10 = async ({x}, y) => { var y; return y }; + assertEqualsAsync(2, () => g10({x: 6}, 2)); + var g11 = async ({x}, y) => { var z = y; var y = 2; return z; }; + assertEqualsAsync(1, () => g11({x: 6}, 1)); + var g12 = async (y, g = () => y) => { var y = 2; return g(); }; + assertEqualsAsync(1, () => g12(1)); + var g13 = async ({x}, y, [z], v) => { var x, y, z; return x*y*z*v }; + assertEqualsAsync(210, () => g13({x: 2}, 3, [5], 7)); + + var g20 = async ({x}) => { function x() { return 2 }; return x(); } + assertEqualsAsync(2, () => g20({x: 1})); + var g21 = async ({x}) => { { function x() { return 2 } } return x(); } + assertThrowsAsync(() => g21({x: 1}), TypeError); + + assertThrows("'use strict'; async function f(x) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; async function f({x}) { let x = 0; }", SyntaxError); + assertThrows("'use strict'; async function f(x) { const x = 0; }", SyntaxError); + assertThrows("'use strict'; async function f({x}) { const x = 0; }", SyntaxError); + + assertThrows("'use strict'; let g = async (x) => { let x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = async ({x}) => { let x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = async (x) => { const x = 0; }", SyntaxError); + assertThrows("'use strict'; let g = async ({x}) => { const x = 0; }", SyntaxError); +}()); + +(function TestDefaults() { + async function f1(x = 1) { return x } + assertEqualsAsync(1, () => f1()); + assertEqualsAsync(1, () => f1(undefined)); + assertEqualsAsync(2, () => f1(2)); + assertEqualsAsync(null, () => f1(null)); + + async function f2(x, y = x) { return x + y; } + assertEqualsAsync(8, () => f2(4)); + assertEqualsAsync(8, () => f2(4, undefined)); + assertEqualsAsync(6, () => f2(4, 2)); + + async function f3(x = 1, y) { return x + y; } + assertEqualsAsync(8, () => f3(5, 3)); + assertEqualsAsync(3, () => f3(undefined, 2)); + assertEqualsAsync(6, () => f3(4, 2)); + + async function f4(x = () => 1) { return x() } + assertEqualsAsync(1, () => f4()); + assertEqualsAsync(1, () => f4(undefined)); + assertEqualsAsync(2, () => f4(() => 2)); + assertThrowsAsync(() => f4(null), TypeError); + + async function f5(x, y = () => x) { return x + y(); } + assertEqualsAsync(8, () => f5(4)); + assertEqualsAsync(8, () => f5(4, undefined)); + assertEqualsAsync(6, () => f5(4, () => 2)); + + async function f6(x = {a: 1, m() { return 2 }}) { return x.a + x.m(); } + assertEqualsAsync(3, () => f6()); + assertEqualsAsync(3, () => f6(undefined)); + assertEqualsAsync(5, () => f6({a: 2, m() { return 3 }})); + + var g1 = async (x = 1) => { return x }; + assertEqualsAsync(1, () => g1()); + assertEqualsAsync(1, () => g1(undefined)); + assertEqualsAsync(2, () => g1(2)); + assertEqualsAsync(null, () => g1(null)); + + var g2 = async (x, y = x) => { return x + y; }; + assertEqualsAsync(8, () => g2(4)); + assertEqualsAsync(8, () => g2(4, undefined)); + assertEqualsAsync(6, () => g2(4, 2)); + + var g3 = async (x = 1, y) => { return x + y; }; + assertEqualsAsync(8, () => g3(5, 3)); + assertEqualsAsync(3, () => g3(undefined, 2)); + assertEqualsAsync(6, () => g3(4, 2)); + + var g4 = async (x = () => 1) => { return x() }; + assertEqualsAsync(1, () => g4()); + assertEqualsAsync(1, () => g4(undefined)); + assertEqualsAsync(2, () => g4(() => 2)); + assertThrowsAsync(() => g4(null), TypeError); + + var g5 = async (x, y = () => x) => { return x + y(); }; + assertEqualsAsync(8, () => g5(4)); + assertEqualsAsync(8, () => g5(4, undefined)); + assertEqualsAsync(6, () => g5(4, () => 2)); + + var g6 = async (x = {a: 1, m() { return 2 }}) => { return x.a + x.m(); }; + assertEqualsAsync(3, () => g6()); + assertEqualsAsync(3, () => g6(undefined)); + assertEqualsAsync(5, () => g6({a: 2, m() { return 3 }})); +}()); + + +(function TestEvalInParameters() { + async function f1(x = eval(0)) { return x } + assertEqualsAsync(0, f1); + async function f2(x = () => eval(1)) { return x() } + assertEqualsAsync(1, f2); +})(); + + +(function TestParameterScopingSloppy() { + var x = 1; + + async function f1(a = x) { var x = 2; return a; } + assertEqualsAsync(1, f1); + async function f2(a = x) { function x() {}; return a; } + assertEqualsAsync(1, () => f2()); + async function f3(a = eval("x")) { var x; return a; } + assertEqualsAsync(1, () => f3()); + async function f31(a = eval("'use strict'; x")) { var x; return a; } + assertEqualsAsync(1, () => f31()); + async function f4(a = function() { return x }) { var x; return a(); } + assertEqualsAsync(1, () => f4()); + async function f5(a = () => x) { var x; return a(); } + assertEqualsAsync(1, () => f5()); + async function f6(a = () => eval("x")) { var x; return a(); } + assertEqualsAsync(1, () => f6()); + async function f61(a = () => { 'use strict'; return eval("x") }) { var x; return a(); } + assertEqualsAsync(1, () => f61()); + async function f62(a = () => eval("'use strict'; x")) { var x; return a(); } + assertEqualsAsync(1, () => f62()); + + var g1 = async (a = x) => { var x = 2; return a; }; + assertEqualsAsync(1, () => g1()); + var g2 = async (a = x) => { function x() {}; return a; }; + assertEqualsAsync(1, () => g2()); + var g3 = async (a = eval("x")) => { var x; return a; }; + assertEqualsAsync(1, g3); + var g31 = async (a = eval("'use strict'; x")) => { var x; return a; }; + assertEqualsAsync(1, () => g31()); + var g4 = async (a = function() { return x }) => { var x; return a(); }; + assertEqualsAsync(1, () => g4()); + var g5 = async (a = () => x) => { var x; return a(); }; + assertEqualsAsync(1, () => g5()); + var g6 = async (a = () => eval("x")) => { var x; return a(); }; + assertEqualsAsync(1, () => g6()); + var g61 = async (a = () => { 'use strict'; return eval("x") }) => { var x; return a(); }; + assertEqualsAsync(1, () => g61()); + var g62 = async (a = () => eval("'use strict'; x")) => { var x; return a(); }; + assertEqualsAsync(1, () => g62()); + + var f11 = async function f(x = f) { var f; return x; } + assertEqualsAsync(f11, f11); + var f12 = async function f(x = f) { function f() {}; return x; } + assertEqualsAsync(f12, f12); + var f13 = async function f(f = 7, x = f) { return x; } + assertEqualsAsync(7, f13); + + var o1 = {f: async function(x = this) { return x; }}; + assertEqualsAsync(o1, () => o1.f()); + assertEqualsAsync(1, () => o1.f(1)); +})(); + +(function TestParameterScopingStrict() { + "use strict"; + var x = 1; + + async function f1(a = x) { let x = 2; return a; } + assertEqualsAsync(1, () => f1()); + async function f2(a = x) { const x = 2; return a; } + assertEqualsAsync(1, () => f2()); + async function f3(a = x) { function x() {}; return a; } + assertEqualsAsync(1, () => f3()); + async function f4(a = eval("x")) { var x; return a; } + assertEqualsAsync(1, () => f4()); + async function f5(a = () => eval("x")) { var x; return a(); } + assertEqualsAsync(1, () => f5()); + + var g1 = async (a = x) => { let x = 2; return a; }; + assertEqualsAsync(1, () => g1()); + var g2 = async (a = x) => { const x = 2; return a; }; + assertEqualsAsync(1, () => g2()); + var g3 = async (a = x) => { function x() {}; return a; }; + assertEqualsAsync(1, () => g3()); + var g4 = async (a = eval("x")) => { var x; return a; }; + assertEqualsAsync(1, () => g4()); + var g5 = async (a = () => eval("x")) => { var x; return a(); }; + assertEqualsAsync(1, () => g5()); + + var f11 = async function f(x = f) { let f; return x; } + assertEqualsAsync(f11, f11); + var f12 = async function f(x = f) { const f = 0; return x; } + assertEqualsAsync(f12, f12); + var f13 = async function f(x = f) { function f() {}; return x; } + assertEqualsAsync(f13, f13); +})(); + +(function TestSloppyEvalScoping() { + var x = 1; + + async function f1(y = eval("var x = 2")) { with ({}) { return x; } } + assertEqualsAsync(1, () => f1()); + async function f2(y = eval("var x = 2"), z = x) { return z; } + assertEqualsAsync(1, () => f2()); + assertEqualsAsync(1, () => f2(0)); + async function f3(y = eval("var x = 2"), z = eval("x")) { return z; } + assertEqualsAsync(1, () => f3()); + assertEqualsAsync(1, () => f3(0)); + async function f8(y = (eval("var x = 2"), x)) { return y; } + assertEqualsAsync(2, () => f8()); + assertEqualsAsync(0, () => f8(0)); + + async function f11(z = eval("var y = 2")) { return y; } + assertThrowsAsync(f11, ReferenceError); + async function f12(z = eval("var y = 2"), b = y) {} + assertThrowsAsync(f12, ReferenceError); + async function f13(z = eval("var y = 2"), b = eval("y")) {} + assertThrowsAsync(f13, ReferenceError); + + async function f21(f = () => x) { eval("var x = 2"); return f() } + assertEqualsAsync(1, () => f21()); + assertEqualsAsync(3, () => f21(() => 3)); + async function f22(f = () => eval("x")) { eval("var x = 2"); return f() } + assertEqualsAsync(1, () => f22()); + assertEqualsAsync(3, () => f22(() => 3)); + + var g1 = async (y = eval("var x = 2")) => { with ({}) { return x; } }; + assertEqualsAsync(1, () => g1()); + var g2 = async (y = eval("var x = 2"), z = x) => { return z; }; + assertEqualsAsync(1, () => g2()); + assertEqualsAsync(1, () => g2(0)); + var g3 = async (y = eval("var x = 2"), z = eval("x")) => { return z; }; + assertEqualsAsync(1, () => g3()); + assertEqualsAsync(1, () => g3(0)); + var g8 = async (y = (eval("var x = 2"), x)) => { return y; }; + assertEqualsAsync(2, () => g8()); + assertEqualsAsync(0, () => g8(0)); + + var g11 = async (z = eval("var y = 2")) => { return y; }; + assertThrowsAsync(g11, ReferenceError); + var g12 = async (z = eval("var y = 2"), b = y) => {}; + assertThrowsAsync(g12, ReferenceError); + var g13 = async (z = eval("var y = 2"), b = eval("y")) => {}; + assertThrowsAsync(g13, ReferenceError); + + var g21 = async (f = () => x) => { eval("var x = 2"); return f() }; + assertEqualsAsync(1, () => g21()); + assertEqualsAsync(3, () => g21(() => 3)); + var g22 = async (f = () => eval("x")) => { eval("var x = 2"); return f() }; + assertEqualsAsync(1, () => g22()); + assertEqualsAsync(3, () => g22(() => 3)); +})(); + + +(function TestStrictEvalScoping() { + 'use strict'; + var x = 1; + + async function f1(y = eval("var x = 2")) { return x; } + assertEqualsAsync(1, () => f1()); + async function f2(y = eval("var x = 2"), z = x) { return z; } + assertEqualsAsync(1, () => f2()); + assertEqualsAsync(1, () => f2(0)); + async function f3(y = eval("var x = 2"), z = eval("x")) { return z; } + assertEqualsAsync(1, () => f3()); + assertEqualsAsync(1, () => f3(0)); + async function f8(y = (eval("var x = 2"), x)) { return y; } + assertEqualsAsync(1, () => f8()); + assertEqualsAsync(0, () => f8(0)); + + async function f11(z = eval("var y = 2")) { return y; } + assertThrowsAsync(f11, ReferenceError); + async function f12(z = eval("var y = 2"), b = y) {} + assertThrowsAsync(f12, ReferenceError); + async function f13(z = eval("var y = 2"), b = eval("y")) {} + assertThrowsAsync(f13, ReferenceError); + + async function f21(f = () => x) { eval("var x = 2"); return f() } + assertEqualsAsync(1, () => f21()); + assertEqualsAsync(3, () => f21(() => 3)); + async function f22(f = () => eval("x")) { eval("var x = 2"); return f() } + assertEqualsAsync(1, () => f22()); + assertEqualsAsync(3, () => f22(() => 3)); +})(); + +(function TestParameterTDZSloppy() { + async function f1(a = x, x) { return a } + assertThrowsAsync(() => f1(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f1(4, 5)); + async function f2(a = eval("x"), x) { return a } + assertThrowsAsync(() => f2(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f2(4, 5)); + async function f3(a = eval("'use strict'; x"), x) { return a } + assertThrowsAsync(() => f3(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f3(4, 5)); + async function f4(a = () => x, x) { return a() } + assertEqualsAsync(4, () => f4(() => 4, 5)); + async function f5(a = () => eval("x"), x) { return a() } + assertEqualsAsync(4, () => f5(() => 4, 5)); + async function f6(a = () => eval("'use strict'; x"), x) { return a() } + assertEqualsAsync(4, () => f6(() => 4, 5)); + + async function f11(a = x, x = 2) { return a } + assertThrowsAsync(() => f11(), ReferenceError); + assertThrowsAsync(() => f11(undefined), ReferenceError); + assertThrowsAsync(() => f11(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f1(4, 5)); + async function f12(a = eval("x"), x = 2) { return a } + assertThrowsAsync(() => f12(), ReferenceError); + assertThrowsAsync(() => f12(undefined), ReferenceError); + assertThrowsAsync(() => f12(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f12(4, 5)); + async function f13(a = eval("'use strict'; x"), x = 2) { return a } + assertThrowsAsync(() => f13(), ReferenceError); + assertThrowsAsync(() => f13(undefined), ReferenceError); + assertThrowsAsync(() => f13(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f13(4, 5)); + + async function f21(x = function() { return a }, ...a) { return x()[0] } + assertEqualsAsync(4, () => f21(undefined, 4)); + async function f22(x = () => a, ...a) { return x()[0] } + assertEqualsAsync(4, () => f22(undefined, 4)); + async function f23(x = () => eval("a"), ...a) { return x()[0] } + assertEqualsAsync(4, () => f23(undefined, 4)); + async function f24(x = () => {'use strict'; return eval("a") }, ...a) { + return x()[0] + } + assertEqualsAsync(4, () => f24(undefined, 4)); + async function f25(x = () => eval("'use strict'; a"), ...a) { return x()[0] } + assertEqualsAsync(4, () => f25(undefined, 4)); + + var g1 = async (x = function() { return a }, ...a) => { return x()[0] }; + assertEqualsAsync(4, () => g1(undefined, 4)); + var g2 = async (x = () => a, ...a) => { return x()[0] }; + assertEqualsAsync(4, () => g2(undefined, 4)); +})(); + +(function TestParameterTDZStrict() { + "use strict"; + + async function f1(a = eval("x"), x) { return a } + assertThrowsAsync(() => f1(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f1(4, 5)); + async function f2(a = () => eval("x"), x) { return a() } + assertEqualsAsync(4, () => f2(() => 4, 5)); + + async function f11(a = eval("x"), x = 2) { return a } + assertThrowsAsync(() => f11(), ReferenceError); + assertThrowsAsync(() => f11(undefined), ReferenceError); + assertThrowsAsync(() => f11(undefined, 4), ReferenceError); + assertEqualsAsync(4, () => f11(4, 5)); + + async function f21(x = () => eval("a"), ...a) { return x()[0] } + assertEqualsAsync(4, () => f21(undefined, 4)); +})(); + +(function TestArgumentsForNonSimpleParameters() { + async function f1(x = 900) { arguments[0] = 1; return x } + assertEqualsAsync(9, () => f1(9)); + assertEqualsAsync(900, () => f1()); + async function f2(x = 1001) { x = 2; return arguments[0] } + assertEqualsAsync(10, () => f2(10)); + assertEqualsAsync(undefined, () => f2()); +}()); + + +(function TestFunctionLength() { + assertEquals(0, (async function(x = 1) {}).length); + assertEquals(0, (async function(x = 1, ...a) {}).length); + assertEquals(1, (async function(x, y = 1) {}).length); + assertEquals(1, (async function(x, y = 1, ...a) {}).length); + assertEquals(2, (async function(x, y, z = 1) {}).length); + assertEquals(2, (async function(x, y, z = 1, ...a) {}).length); + assertEquals(1, (async function(x, y = 1, z) {}).length); + assertEquals(1, (async function(x, y = 1, z, ...a) {}).length); + assertEquals(1, (async function(x, y = 1, z, v = 2) {}).length); + assertEquals(1, (async function(x, y = 1, z, v = 2, ...a) {}).length); +})(); + +(function TestDirectiveThrows() { + "use strict"; + + assertThrows("(async function(x=1){'use strict';})", SyntaxError); + assertThrows("(async function(a, x=1){'use strict';})", SyntaxError); + assertThrows("(async function({x}){'use strict';})", SyntaxError); +})(); diff --git a/deps/v8/test/mjsunit/harmony/async-function-debug-evaluate.js b/deps/v8/test/mjsunit/harmony/async-function-debug-evaluate.js new file mode 100644 index 0000000000..edf7bcab12 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-function-debug-evaluate.js @@ -0,0 +1,139 @@ +// Copyright 2016 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-async-await --expose-debug-as debug + +var Debug = debug.Debug; +var breakPointCount = 0; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + ++breakPointCount; + try { + if (breakPointCount === 1) { + assertEquals( + "inner", exec_state.frame(0).evaluate("inner").value()); + assertThrows(() => exec_state.frame(0).evaluate("letInner").value(), + ReferenceError); + assertThrows(() => exec_state.frame(0).evaluate("constInner").value(), + ReferenceError); + + assertEquals("outer", exec_state.frame(0).evaluate("outer").value()); + assertEquals( + "const outer", exec_state.frame(0).evaluate("constOuter").value()); + assertEquals( + "let outer", exec_state.frame(0).evaluate("letOuter").value()); + + assertEquals("outer", exec_state.frame(1).evaluate("outer").value()); + assertEquals( + "const outer", exec_state.frame(1).evaluate("constOuter").value()); + assertEquals( + "let outer", exec_state.frame(1).evaluate("letOuter").value()); + + assertThrows(() => exec_state.frame(0).evaluate("withVar").value(), + ReferenceError); + + } else if (breakPointCount === 2) { + assertEquals( + "inner", exec_state.frame(0).evaluate("inner").value()); + assertThrows(() => exec_state.frame(0).evaluate("letInner").value(), + ReferenceError); + assertThrows(() => exec_state.frame(0).evaluate("constInner").value(), + ReferenceError); + + assertEquals(57, exec_state.frame(0).evaluate("x").value()); + assertEquals(100, exec_state.frame(0).evaluate("y").value()); + + // From breakPointCount === 1 and later, it's not possible to access + // earlier framestates. + assertEquals("outer", exec_state.frame(0).evaluate("outer").value()); + assertEquals( + "const outer", exec_state.frame(0).evaluate("constOuter").value()); + assertEquals( + "let outer", exec_state.frame(0).evaluate("letOuter").value()); + + exec_state.frame(0).evaluate("x = `x later(${x})`"); + exec_state.frame(0).evaluate("y = `y later(${y})`"); + exec_state.frame(0).evaluate("z = `ZEE`"); + + } else if (breakPointCount === 3) { + assertEquals( + "inner", exec_state.frame(0).evaluate("inner").value()); + assertEquals( + "let inner", exec_state.frame(0).evaluate("letInner").value()); + assertEquals( + "const inner", exec_state.frame(0).evaluate("constInner").value()); + + } else if (breakPointCount === 4) { + assertEquals( + "oop", exec_state.frame(0).evaluate("error.message").value()); + assertEquals( + "Error", + exec_state.frame(0).evaluate("error.constructor.name").value()); + assertEquals("floof", exec_state.frame(0).evaluate("bun").value()); + assertThrows(() => exec_state.frame(0).evaluate("cow").value(), + ReferenceError); + + assertEquals("outer", exec_state.frame(0).evaluate("outer").value()); + assertEquals( + "const outer", exec_state.frame(0).evaluate("constOuter").value()); + assertEquals( + "let outer", exec_state.frame(0).evaluate("letOuter").value()); + } + } catch (e) { + print(e.stack); + quit(1); + } +} + +Debug.setListener(listener); + +var outer = "outer"; +const constOuter = "const outer"; +let letOuter = "let outer" + +async function thrower() { + return Promise.reject(new Error("oop")); +} + +async function testLater() { + return { x: 57, y: 100 }; +} + +async function test() { + var inner = "inner"; + debugger; + + let withVar = await testLater(); + with (withVar) { + debugger; + } + + assertEquals("x later(57)", withVar.x); + assertEquals("y later(100)", withVar.y); + assertEquals(undefined, withVar.z); + assertEquals("ZEE", z); + + let letInner = "let inner"; + const constInner = "const inner"; + debugger; + + try { + await thrower(); + } catch (error) { + const bun = "floof"; + debugger; + let cow = "moo"; + } +} + +test(). +then(x => { + Debug.setListener(null); +}). +catch(error => { + print(error.stack); + quit(1); + Debug.setListener(null); +}); diff --git a/deps/v8/test/mjsunit/harmony/async-function-debug-scopes.js b/deps/v8/test/mjsunit/harmony/async-function-debug-scopes.js new file mode 100644 index 0000000000..3d72549d2a --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-function-debug-scopes.js @@ -0,0 +1,616 @@ +// Copyright 2016 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-async-await --expose-debug-as debug + +var Debug = debug.Debug; + +var AsyncFunction = (async function() {}).constructor; + +async function thrower() { throw 'Exception'; } + +async function test(name, func, args, handler, continuation) { + var handler_called = false; + var exception = null; + + function listener(event, exec_state, event_data, data) { + try { + if (event == Debug.DebugEvent.Break) { + handler_called = true; + handler(exec_state); + } + } catch (e) { + exception = e; + } + } + + Debug.setListener(listener); + + var result; + if (typeof func === "object") + result = await func.method.apply(func, args); + else + result = await func.apply(null, args); + + if (typeof continuation === "function") { + await continuation(result); + } + + assertTrue(handler_called, `Expected ${name} handler to be called`); + if (exception) { + exception.message = `${name} / ${exception.message}`; + print(exception.stack); + quit(1); + } + + Debug.setListener(null); +} + +async function runTests() { + +// Simple +await test( + "(AsyncFunctionExpression) Local 1", + async function() { debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 1 --- resume normal", + async function() { let z = await 2; debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({z: 2}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 1 --- resume throw", + async function() { let q = await 1; + try { let z = await thrower(); } + catch (e) { debugger; } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e: 'Exception'}, 0, exec_state); + CheckScopeContent({q: 1}, 1, exec_state); + + }); + +// Simple With Parameter +await test( + "(AsyncFunctionExpression) Local 2", + async function(a) { debugger; }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ a: 1 }, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 2 --- resume normal", + async function(a) { let z = await 2; debugger; }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ a: 1, z: 2 }, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 2 --- resume throw", + async function(a) { let z = await 2; + try { await thrower(); } catch (e) { debugger; } }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ e: 'Exception' }, 0, exec_state); + CheckScopeContent({ a: 1, z: 2 }, 1, exec_state); + }); + +// Simple With Parameter and Variable +await test( + "(AsyncFunctionExpression) Local 3", + async function(a) { var b = 2; debugger; }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ a: 1, b: 2 }, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 3 --- resume normal", + async function(a) { let y = await 3; var b = 2; let z = await 4; + debugger; }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ a: 1, b: 2, y: 3, z: 4 }, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 3 --- resume throw", + async function(a) { let y = await 3; + try { var b = 2; let z = await thrower(); } + catch (e) { debugger; } }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ e: 'Exception' }, 0, exec_state); + CheckScopeContent({ a: 1, b: 2, y: 3 }, 1, exec_state); + }); + +// Local scope with parameters and local variables. +await test( + "(AsyncFunctionExpression) Local 4", + async function(a, b) { var x = 3; var y = 4; debugger; }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 4 --- resume normal", + async function(a, b) { let q = await 5; var x = 3; var y = 4; + let r = await 6; debugger; }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1,b:2,x:3,y:4, q: 5, r: 6}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 4 --- resume throw", + async function(a, b) { let q = await 5; var x = 3; var y = 4; + try { let r = await thrower(); } + catch (e) { debugger; } }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e: 'Exception'}, 0, exec_state); + CheckScopeContent({a:1,b:2,x:3,y:4, q: 5}, 1, exec_state); + }); + +// Empty local scope with use of eval. +await test( + "(AsyncFunctionExpression) Local 5", + async function() { eval(""); debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 5 --- resume normal", + async function() { let x = await 1; eval(""); let y = await 2; + debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ x: 1, y: 2 }, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 5 --- resume throw", + async function() { let x = await 1; eval(""); + try { let y = await thrower(); } + catch (e) { debugger; } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ e: 'Exception' }, 0, exec_state); + CheckScopeContent({ x: 1 }, 1, exec_state); + }); + +// Local introducing local variable using eval. +await test( + "(AsyncFunctionExpression) Local 6", + async function() { eval("var i = 5"); debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({i:5}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 6 --- resume normal", + async function() { let x = await 1; eval("var i = 5"); let y = await 2; + debugger; }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({i:5, x: 1, y: 2}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 6 --- resume throw", + async function() { let x = await 1; eval("var i = 5"); + try { let y = await thrower(); } + catch (e) { debugger; } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e: 'Exception' }, 0, exec_state); + CheckScopeContent({i:5, x: 1}, 1, exec_state); + }); + +// Local scope with parameters, local variables and local variable introduced +// using eval. +await test( + "(AsyncFunctionExpression) Local 7", + async function(a, b) { var x = 3; var y = 4; + eval("var i = 5;"); eval("var j = 6"); + debugger; }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 7 --- resume normal", + async function(a, b) { let z = await 7; var x = 3; var y = 4; + eval("var i = 5;"); eval("var j = 6"); + let q = await 8; + debugger; }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6, z:7, q:8}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Local 7 --- resume throw", + async function(a, b) { let z = await 7; var x = 3; var y = 4; + eval("var i = 5;"); eval("var j = 6"); + try { let q = await thrower(); } + catch (e) { debugger; } }, [1, 2], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e: 'Exception'}, 0, exec_state); + //CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6, z:7}, 1, exec_state); + }); + +// Nested empty with blocks. +await test( + "(AsyncFunctionExpression) With", + async function() { with ({}) { with ({}) { debugger; } } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.With, + debug.ScopeType.With, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({}, 0, exec_state); + CheckScopeContent({}, 1, exec_state); + }); + +await test( + "(AsyncFunctionExpression) With --- resume normal", + async function() { let x = await 1; with ({}) { with ({}) { + let y = await 2; debugger; } } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Block, + debug.ScopeType.With, + debug.ScopeType.With, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({y:2}, 0, exec_state); + CheckScopeContent({}, 1, exec_state); + CheckScopeContent({}, 2, exec_state); + CheckScopeContent({x:1}, 3, exec_state); + }); + +await test( + "(AsyncFunctionExpression) With --- resume throw", + async function() { let x = await 1; with ({}) { with ({}) { + try { let y = await thrower(); } + catch (e) { debugger; } } } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.With, + debug.ScopeType.With, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({ e: 'Exception'}, 0, exec_state); + CheckScopeContent({}, 1, exec_state); + CheckScopeContent({}, 2, exec_state); + CheckScopeContent({x:1}, 3, exec_state); + }); + +// Simple closure formed by returning an inner function referering the outer +// functions arguments. +await test( + "(AsyncFunctionExpression) Closure 1", + async function(a) { return function() { debugger; return a; } }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1}, 1, exec_state); + }, + result => result()); + +await test( + "(AsyncFunctionExpression) Closure 1 --- resume normal", + async function(a) { let x = await 2; + return function() { debugger; return a; } }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({a:1, x: 2}, 1, exec_state); + }, + result => result()); + +await test( + "(AsyncFunctionExpression) Closure 1 --- resume throw", + async function(a) { let x = await 2; + return async function() { + try { await thrower(); } + catch (e) { debugger; } return a; }; }, [1], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e: 'Exception'}, 0, exec_state); + CheckScopeContent({a:1, x: 2}, 2, exec_state); + }, + result => result()); + +await test( + "(AsyncFunctionExpression) Catch block 1", + async function() { try { throw 'Exception'; } catch (e) { debugger; } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e:'Exception'}, 0, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Catch block 1 --- resume normal", + async function() { + let x = await 1; + try { throw 'Exception'; } catch (e) { let y = await 2; debugger; } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Block, + debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({y: 2}, 0, exec_state); + CheckScopeContent({e:'Exception'}, 1, exec_state); + CheckScopeContent({x: 1}, 2, exec_state); + }); + +await test( + "(AsyncFunctionExpression) Catch block 1 --- resume throw", + async function() { + let x = await 1; + try { throw 'Exception!'; } catch (e) { + try { let y = await thrower(); } catch (e) { debugger; } } }, [], + exec_state => { + CheckScopeChain([debug.ScopeType.Catch, + debug.ScopeType.Catch, + debug.ScopeType.Local, + debug.ScopeType.Closure, + debug.ScopeType.Script, + debug.ScopeType.Global], exec_state); + CheckScopeContent({e:'Exception'}, 0, exec_state); + CheckScopeContent({e:'Exception!'}, 1, exec_state); + CheckScopeContent({x: 1}, 2, exec_state); + }); +} + +runTests().catch(error => { + print(error.stack); + quit(1); +}) + +// Check that two scope are the same. +function assertScopeMirrorEquals(scope1, scope2) { + assertEquals(scope1.scopeType(), scope2.scopeType()); + assertEquals(scope1.frameIndex(), scope2.frameIndex()); + assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); + assertPropertiesEqual( + scope1.scopeObject().value(), scope2.scopeObject().value()); +} + +function CheckFastAllScopes(scopes, exec_state) { + var fast_all_scopes = exec_state.frame().allScopes(true); + var length = fast_all_scopes.length; + assertTrue(scopes.length >= length); + for (var i = 0; i < scopes.length && i < length; i++) { + var scope = fast_all_scopes[length - i - 1]; + assertTrue(scope.isScope()); + assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); + } +} + +// Check that the scope chain contains the expected types of scopes. +function CheckScopeChain(scopes, exec_state) { + var all_scopes = exec_state.frame().allScopes(); + assertEquals( + scopes.length, all_scopes.length, "FrameMirror.allScopes length"); + for (var i = 0; i < scopes.length; i++) { + var scope = exec_state.frame().scope(i); + assertTrue(scope.isScope()); + assertEquals(scopes[i], scope.scopeType()); + assertScopeMirrorEquals(all_scopes[i], scope); + + // Check the global object when hitting the global scope. + if (scopes[i] == debug.ScopeType.Global) { + // Objects don't have same class (one is "global", other is "Object", + // so just check the properties directly. + assertPropertiesEqual(this, scope.scopeObject().value()); + } + } + CheckFastAllScopes(scopes, exec_state); + + // Get the debug command processor. + var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); + + // Send a scopes request and check the result. + var json; + var request_json = '{"seq":0,"type":"request","command":"scopes"}'; + var response_json = dcp.processDebugJSONRequest(request_json); + var response = JSON.parse(response_json); + assertEquals(scopes.length, response.body.scopes.length); + for (var i = 0; i < scopes.length; i++) { + var scopeRef = response.body.scopes[i].object.ref; + assertEquals(i, response.body.scopes[i].index); + assertEquals(scopes[i], response.body.scopes[i].type); + if (scopes[i] == debug.ScopeType.Local || + scopes[i] == debug.ScopeType.Script || + scopes[i] == debug.ScopeType.Closure) { + assertTrue(response.body.scopes[i].object.ref < 0); + } else { + assertTrue(response.body.scopes[i].object.ref >= 0); + } + var found = false; + for (var j = 0; j < response.refs.length && !found; j++) { + found = response.refs[j].handle == response.body.scopes[i].object.ref; + } + assertTrue(found, `Scope object ${scopeRef} not found`); + } +} + +// 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) { + var scope = exec_state.frame().scope(number); + var count = 0; + for (var p in content) { + var property_mirror = scope.scopeObject().property(p); + assertFalse(property_mirror.isUndefined(), + `property ${p} not found in scope`); + if (typeof(content[p]) === 'function') { + assertTrue(property_mirror.value().isFunction()); + } else { + assertEquals(content[p], property_mirror.value().value(), + `property ${p} has unexpected value`); + } + count++; + } + + // 'arguments' and might be exposed in the local and closure scope. Just + // ignore this. + var scope_size = scope.scopeObject().properties().length; + if (!scope.scopeObject().property('arguments').isUndefined()) { + scope_size--; + } + // Skip property with empty name. + if (!scope.scopeObject().property('').isUndefined()) { + scope_size--; + } + + if (count != scope_size) { + print('Names found in scope:'); + var names = scope.scopeObject().propertyNames(); + for (var i = 0; i < names.length; i++) { + print(names[i]); + } + } + assertEquals(count, scope_size); + + // Get the debug command processor. + var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); + + // Send a scope request for information on a single scope and check the + // result. + var request_json = `{ + "seq": 0, + "type": "request", + "command": "scope", + "arguments": { + "number": `; + request_json += scope.scopeIndex(); + request_json += '}}'; + var response_json = dcp.processDebugJSONRequest(request_json); + var response = JSON.parse(response_json); + assertEquals(scope.scopeType(), response.body.type); + assertEquals(number, response.body.index); + if (scope.scopeType() == debug.ScopeType.Local || + scope.scopeType() == debug.ScopeType.Script || + scope.scopeType() == debug.ScopeType.Closure) { + assertTrue(response.body.object.ref < 0); + } else { + assertTrue(response.body.object.ref >= 0); + } + var found = false; + for (var i = 0; i < response.refs.length && !found; i++) { + found = response.refs[i].handle == response.body.object.ref; + } + assertTrue(found, "Scope object " + response.body.object.ref + " not found"); +} diff --git a/deps/v8/test/mjsunit/harmony/async-function-stacktrace.js b/deps/v8/test/mjsunit/harmony/async-function-stacktrace.js new file mode 100644 index 0000000000..5ab20881a6 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-function-stacktrace.js @@ -0,0 +1,178 @@ +// Copyright 2016 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-async-await + +async function test(func, funcs) { + try { + await func(); + throw new Error("Expected " + func.toString() + " to throw"); + } catch (e) { + var stack = e.stack.split('\n'). + slice(1). + map(line => line.trim()). + map(line => line.match(/at (?:(.*) )?.*$/)[1]). + filter(x => typeof x === 'string' && x.length); + + assertEquals(funcs, stack, `Unexpected stack trace ${e.stack}`); + } +} + +function thrower() { throw new Error("NOPE"); } +function reject() { return Promise.reject(new Error("NOPE")); } + +async function runTests() { + await test(async function a() { + throw new Error("FAIL"); + }, + ["a", "test", "runTests"]); + + await test(async function a2() { + await 1; + throw new Error("FAIL"); + }, ["a2"]); + + await test(async function a3() { + await 1; + try { await thrower(); } catch (e) { throw new Error("FAIL"); } + }, ["a3"]); + + await test(async function a4() { + await 1; + try { await reject(); } catch (e) { throw new Error("FAIL"); } + }, ["a4"]); + + await test({ async b() { + throw new Error("FAIL"); + }}.b, + ["b", "test", "runTests"]); + + await test({ async b2() { + await 1; + throw new Error("FAIL"); + }}.b2, ["b2"]); + + await test({ async b3() { + await 1; + try { await thrower(); } catch (e) { throw new Error("FAIL"); } + } }.b3, ["b3"]); + + await test({ async b4() { + await 1; + try { await reject(); } catch (e) { throw new Error("FAIL"); } + } }.b4, ["b4"]); + + await test((new class { async c() { + throw new Error("FAIL"); + } }).c, + ["c", "test", "runTests"]); + + await test((new class { async c2() { + await 1; + throw new Error("FAIL"); + } }).c2, ["c2"]); + + await test((new class { async c3() { + await 1; + try { await thrower(); } catch (e) { throw new Error("FAIL"); } + } }).c3, ["c3"]); + + await test((new class { async c4() { + await 1; + try { await reject(); } catch (e) { throw new Error("FAIL"); } + } }).c4, ["c4"]); + + // TODO(caitp): We should infer anonymous async functions as the empty + // string, not as the name of a function they're passed as a parameter to. + await test(async x => { throw new Error("FAIL") }, + ["test", "test", "runTests"]); + await test(async() => { throw new Error("FAIL") }, + ["test", "test", "runTests"]); + await test(async(a) => { throw new Error("FAIL") }, + ["test", "test", "runTests"]); + await test(async(a, b) => { throw new Error("FAIL") }, + ["test", "test", "runTests"]); + + await test(async x => { await 1; throw new Error("FAIL") }, ["test"]); + await test(async() => { await 1; throw new Error("FAIL") }, ["test"]); + await test(async(a) => { await 1; throw new Error("FAIL") }, ["test"]); + await test(async(a, b) => { await 1; throw new Error("FAIL") }, ["test"]); + + await test(async x => { + await 1; + try { + await thrower(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async() => { + await 1; + try { + await thrower(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async(a) => { + await 1; + try { + await thrower(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async(a, b) => { + await 1; + try { + await thrower(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async x => { + await 1; + try { + await reject(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async() => { + await 1; + try { + await reject(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async(a) => { + await 1; + try { + await reject(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); + + await test(async(a, b) => { + await 1; + try { + await reject(); + } catch (e) { + throw new Error("FAIL"); + } + }, ["test"]); +} + +runTests().catch(e => { + print(e); + quit(1); +}); diff --git a/deps/v8/test/mjsunit/harmony/atomics.js b/deps/v8/test/mjsunit/harmony/atomics.js index bf27eb46d5..e608df3342 100644 --- a/deps/v8/test/mjsunit/harmony/atomics.js +++ b/deps/v8/test/mjsunit/harmony/atomics.js @@ -16,26 +16,19 @@ function toRangeWrapped(value) { return value; } -function toRangeClamped(value) { - if (value < this.min) return this.min; - if (value > this.max) return this.max; - return value; -} - function makeConstructorObject(constr, min, max, toRange) { var o = {constr: constr, min: min, max: max}; - o.toRange = toRange.bind(o); + o.toRange = toRangeWrapped.bind(o); return o; } var IntegerTypedArrayConstructors = [ - makeConstructorObject(Int8Array, -128, 127, toRangeWrapped), - makeConstructorObject(Int16Array, -32768, 32767, toRangeWrapped), - makeConstructorObject(Int32Array, -0x80000000, 0x7fffffff, toRangeWrapped), - makeConstructorObject(Uint8Array, 0, 255, toRangeWrapped), - makeConstructorObject(Uint8ClampedArray, 0, 255, toRangeClamped), - makeConstructorObject(Uint16Array, 0, 65535, toRangeWrapped), - makeConstructorObject(Uint32Array, 0, 0xffffffff, toRangeWrapped), + makeConstructorObject(Int8Array, -128, 127), + makeConstructorObject(Int16Array, -32768, 32767), + makeConstructorObject(Int32Array, -0x80000000, 0x7fffffff), + makeConstructorObject(Uint8Array, 0, 255), + makeConstructorObject(Uint16Array, 0, 65535), + makeConstructorObject(Uint32Array, 0, 0xffffffff), ]; (function TestBadArray() { @@ -44,9 +37,13 @@ var IntegerTypedArrayConstructors = [ var sab = new SharedArrayBuffer(128); var sf32a = new Float32Array(sab); var sf64a = new Float64Array(sab); + var u8ca = new Uint8ClampedArray(sab); // Atomic ops required integer shared typed arrays - [undefined, 1, 'hi', 3.4, ab, u32a, sab, sf32a, sf64a].forEach(function(o) { + var badArrayTypes = [ + undefined, 1, 'hi', 3.4, ab, u32a, sab, sf32a, sf64a, u8ca + ]; + badArrayTypes.forEach(function(o) { assertThrows(function() { Atomics.compareExchange(o, 0, 0, 0); }, TypeError); assertThrows(function() { Atomics.load(o, 0); }, TypeError); @@ -129,15 +126,16 @@ var IntegerTypedArrayConstructors = [ var testOp = function(op, ia, index, expectedIndex, name) { for (var i = 0; i < ia.length; ++i) - ia[i] = 22; + ia[i] = i * 2; ia[expectedIndex] = 0; - assertEquals(0, op(ia, index, 0, 0), name); + var result = op(ia, index, 0, 0); + assertEquals(0, result, name); assertEquals(0, ia[expectedIndex], name); for (var i = 0; i < ia.length; ++i) { if (i == expectedIndex) continue; - assertEquals(22, ia[i], name); + assertEquals(i * 2, ia[i], name); } }; @@ -222,6 +220,24 @@ function clearArray(sab) { } }) }); + + // Test Smi range + (function () { + var sab = new SharedArrayBuffer(4); + var i32 = new Int32Array(sab); + var u32 = new Uint32Array(sab); + + function testLoad(signedValue, unsignedValue) { + u32[0] = unsignedValue; + assertEquals(unsignedValue, Atomics.load(u32, 0)); + assertEquals(signedValue, Atomics.load(i32, 0)); + } + + testLoad(0x3fffffff, 0x3fffffff); // 2**30-1 (always smi) + testLoad(0x40000000, 0x40000000); // 2**30 (smi if signed and 32-bits) + testLoad(0x80000000, -0x80000000); // 2**31 (smi if signed and 32-bits) + testLoad(0xffffffff, -1); // 2**31 (smi if signed) + }); })(); (function TestStore() { @@ -405,7 +421,7 @@ function clearArray(sab) { assertEquals(50, Atomics.compareExchange(sta, 0, v, v), name); // Store - assertEquals(+v, Atomics.store(sta, 0, v), name); + assertEquals(v|0, Atomics.store(sta, 0, v), name); assertEquals(v|0, sta[0], name); // Add diff --git a/deps/v8/test/mjsunit/harmony/block-sloppy-function.js b/deps/v8/test/mjsunit/harmony/block-sloppy-function.js deleted file mode 100644 index 2bea1476ab..0000000000 --- a/deps/v8/test/mjsunit/harmony/block-sloppy-function.js +++ /dev/null @@ -1,301 +0,0 @@ -// 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 -// Flags: --harmony-sloppy-function - -// Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. -// http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-declarations-web-legacy-compatibility-semantics - -(function overridingLocalFunction() { - var x = []; - assertEquals('function', typeof f); - function f() { - x.push(1); - } - f(); - { - f(); - function f() { - x.push(2); - } - f(); - } - f(); - { - f(); - function f() { - x.push(3); - } - f(); - } - f(); - assertArrayEquals([1, 2, 2, 2, 3, 3, 3], x); -})(); - -(function newFunctionBinding() { - var x = []; - assertEquals('undefined', typeof f); - { - f(); - function f() { - x.push(2); - } - f(); - } - f(); - { - f(); - function f() { - x.push(3); - } - f(); - } - f(); - assertArrayEquals([2, 2, 2, 3, 3, 3], x); -})(); - -(function shadowingLetDoesntBind() { - let f = 1; - assertEquals(1, f); - { - let y = 3; - function f() { - y = 2; - } - f(); - assertEquals(2, y); - } - assertEquals(1, f); -})(); - -(function shadowingClassDoesntBind() { - class f { } - assertEquals('class f { }', f.toString()); - { - let y = 3; - function f() { - y = 2; - } - f(); - assertEquals(2, y); - } - assertEquals('class f { }', f.toString()); -})(); - -(function shadowingConstDoesntBind() { - const f = 1; - assertEquals(1, f); - { - let y = 3; - function f() { - y = 2; - } - f(); - assertEquals(2, y); - } - assertEquals(1, f); -})(); - -(function shadowingVarBinds() { - var f = 1; - assertEquals(1, f); - { - let y = 3; - function f() { - y = 2; - } - f(); - assertEquals(2, y); - } - assertEquals('function', typeof f); -})(); - -(function conditional() { - if (true) { - function f() { return 1; } - } else { - function f() { return 2; } - } - assertEquals(1, f()); - - if (false) { - function g() { return 1; } - } else { - function g() { return 2; } - } - assertEquals(2, g()); -})(); - -(function skipExecution() { - { - function f() { return 1; } - } - assertEquals(1, f()); - { - function f() { return 2; } - } - assertEquals(2, f()); - L: { - assertEquals(3, f()); - break L; - function f() { return 3; } - } - assertEquals(2, f()); -})(); - -// Test that shadowing arguments is fine -(function shadowArguments(x) { - assertArrayEquals([1], arguments); - { - assertEquals('function', typeof arguments); - function arguments() {} - assertEquals('function', typeof arguments); - } - assertEquals('function', typeof arguments); -})(1); - -// Shadow function parameter -(function shadowParameter(x) { - assertEquals(1, x); - { - function x() {} - } - assertEquals('function', typeof x); -})(1); - -// Shadow function parameter -(function shadowDefaultParameter(x = 0) { - assertEquals(1, x); - { - function x() {} - } - // TODO(littledan): Once destructured parameters are no longer - // let-bound, enable this assertion. This is the core of the test. - // assertEquals('function', typeof x); -})(1); - -(function shadowRestParameter(...x) { - assertArrayEquals([1], x); - { - function x() {} - } - // TODO(littledan): Once destructured parameters are no longer - // let-bound, enable this assertion. This is the core of the test. - // assertEquals('function', typeof x); -})(1); - -assertThrows(function notInDefaultScope(x = y) { - { - function 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/dataview-accessors.js b/deps/v8/test/mjsunit/harmony/dataview-accessors.js index c54f8cc20d..d1bd6210bf 100644 --- a/deps/v8/test/mjsunit/harmony/dataview-accessors.js +++ b/deps/v8/test/mjsunit/harmony/dataview-accessors.js @@ -400,12 +400,8 @@ function TestGeneralAccessors() { assertThrows(function() { f(); }, TypeError); f.call(a, 0, 0); // should not throw assertThrows(function() { f.call({}, 0, 0); }, TypeError); - assertThrows(function() { f.call(a); }, TypeError); - if (name.indexOf("set") == 0) { - assertThrows(function() { f.call(a, 1); }, TypeError); - } else { - f.call(a, 1); // should not throw - } + f.call(a); + f.call(a, 1); // should not throw } CheckAccessor("getUint8"); CheckAccessor("setUint8"); @@ -429,33 +425,27 @@ TestGeneralAccessors(); function TestInsufficientArguments() { var a = new DataView(new ArrayBuffer(256)); + function CheckInsuficientArguments(type) { + var expectedValue = type === "Float32" || type === "Float64" ? NaN : 0; + var offset = getElementSize(type); - assertThrows(function() { a.getUint8(); }, TypeError); - assertThrows(function() { a.getInt8(); }, TypeError); - assertThrows(function() { a.getUint16(); }, TypeError); - assertThrows(function() { a.getInt16(); }, TypeError); - assertThrows(function() { a.getUint32(); }, TypeError); - assertThrows(function() { a.getInt32(); }, TypeError); - assertThrows(function() { a.getFloat32(); }, TypeError); - assertThrows(function() { a.getFloat64(); }, TypeError); - - assertThrows(function() { a.setUint8(); }, TypeError); - assertThrows(function() { a.setInt8(); }, TypeError); - assertThrows(function() { a.setUint16(); }, TypeError); - assertThrows(function() { a.setInt16(); }, TypeError); - assertThrows(function() { a.setUint32(); }, TypeError); - assertThrows(function() { a.setInt32(); }, TypeError); - assertThrows(function() { a.setFloat32(); }, TypeError); - assertThrows(function() { a.setFloat64(); }, TypeError); - - assertThrows(function() { a.setUint8(1) }, TypeError); - assertThrows(function() { a.setInt8(1) }, TypeError); - assertThrows(function() { a.setUint16(1) }, TypeError); - assertThrows(function() { a.setInt16(1) }, TypeError); - assertThrows(function() { a.setUint32(1) }, TypeError); - assertThrows(function() { a.setInt32(1) }, TypeError); - assertThrows(function() { a.setFloat32(1) }, TypeError); - assertThrows(function() { a.setFloat64(1) }, TypeError); + assertSame(undefined, a["set" + type](0, 7)); + assertSame(undefined, a["set" + type]()); + assertSame(expectedValue, a["get" + type]()); + + assertSame(undefined, a["set" + type](offset, 7)); + assertSame(undefined, a["set" + type](offset)); + assertSame(expectedValue, a["get" + type](offset)); + } + + CheckInsuficientArguments("Uint8"); + CheckInsuficientArguments("Int8"); + CheckInsuficientArguments("Uint16"); + CheckInsuficientArguments("Int16"); + CheckInsuficientArguments("Uint32"); + CheckInsuficientArguments("Int32"); + CheckInsuficientArguments("Float32"); + CheckInsuficientArguments("Float64"); } TestInsufficientArguments(); diff --git a/deps/v8/test/mjsunit/harmony/debug-async-break-on-stack.js b/deps/v8/test/mjsunit/harmony/debug-async-break-on-stack.js new file mode 100644 index 0000000000..d3d9d8bef6 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/debug-async-break-on-stack.js @@ -0,0 +1,78 @@ +// Copyright 2016 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 +// Flags: --harmony-async-await --allow-natives-syntax + +var Debug = debug.Debug; + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + promise); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +} + +var break_count = 0; +var exception = null; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + break_count++; + var line = exec_state.frame(0).sourceLineText(); + print(line); + assertTrue(line.indexOf(`B${break_count}`) > 0); + } catch (e) { + exception = e; + } +} + + +async function g() { + setbreaks(); + throw 1; // B1 +} + +async function f() { + try { + await g(); + } catch (e) {} + return 2; // B2 +} + +function setbreaks() { + Debug.setListener(listener); + Debug.setBreakPoint(g, 2); + Debug.setBreakPoint(f, 4); +} + +f(); + +%RunMicrotasks(); + +assertEqualsAsync(2, async () => break_count); +assertEqualsAsync(null, async () => exception); + +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/harmony/debug-async-break.js b/deps/v8/test/mjsunit/harmony/debug-async-break.js new file mode 100644 index 0000000000..3b6b71baca --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/debug-async-break.js @@ -0,0 +1,76 @@ +// Copyright 2016 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 +// Flags: --harmony-async-await --allow-natives-syntax + +var Debug = debug.Debug; + +function assertEqualsAsync(expected, run, msg) { + var actual; + var hadValue = false; + var hadError = false; + var promise = run(); + + if (typeof promise !== "object" || typeof promise.then !== "function") { + throw new MjsUnitAssertionError( + "Expected " + run.toString() + + " to return a Promise, but it returned " + promise); + } + + promise.then(function(value) { hadValue = true; actual = value; }, + function(error) { hadError = true; actual = error; }); + + assertFalse(hadValue || hadError); + + %RunMicrotasks(); + + if (hadError) throw actual; + + assertTrue( + hadValue, "Expected '" + run.toString() + "' to produce a value"); + + assertEquals(expected, actual, msg); +} + +var break_count = 0; +var exception = null; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + break_count++; + var line = exec_state.frame(0).sourceLineText(); + assertTrue(line.indexOf(`B${break_count}`) > 0); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +async function g() { + throw 1; +} + +async function f() { + try { + await g(); // B1 + } catch (e) {} + assertEquals(2, break_count); // B2 + return 1; // B3 +} + +Debug.setBreakPoint(f, 2); +Debug.setBreakPoint(f, 4); +Debug.setBreakPoint(f, 5); + +f(); + +%RunMicrotasks(); + +assertEqualsAsync(3, async () => break_count); +assertEqualsAsync(null, async () => exception); + +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/es7/object-observe-debug-event.js b/deps/v8/test/mjsunit/harmony/debug-async-function-async-task-event.js index 06123b8dc2..249f02fc8f 100644 --- a/deps/v8/test/mjsunit/es7/object-observe-debug-event.js +++ b/deps/v8/test/mjsunit/harmony/debug-async-function-async-task-event.js @@ -1,9 +1,8 @@ -// Copyright 2014 the V8 project authors. All rights reserved. +// Copyright 2016 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-object-observe -// Flags: --expose-debug-as debug +// Flags: --harmony-async-await --expose-debug-as debug --allow-natives-syntax Debug = debug.Debug; @@ -12,7 +11,18 @@ var exception = null; var expected = [ "enqueue #1", "willHandle #1", + "then #1", + "enqueue #2", + "enqueue #3", "didHandle #1", + "willHandle #2", + "then #2", + "didHandle #2", + "willHandle #3", + "enqueue #4", + "didHandle #3", + "willHandle #4", + "didHandle #4", ]; function assertLog(msg) { @@ -30,7 +40,8 @@ function listener(event, exec_state, event_data, data) { if (base_id < 0) base_id = event_data.id(); var id = event_data.id() - base_id + 1; - assertEquals("Object.observe", event_data.name()); + assertTrue("Promise.resolve" == event_data.name() || + "PromiseResolveThenableJob" == event_data.name()); assertLog(event_data.type() + " #" + id); } catch (e) { print(e + e.stack) @@ -40,13 +51,20 @@ function listener(event, exec_state, event_data, data) { Debug.setListener(listener); -var obj = {}; -Object.observe(obj, function(changes) { - print(change.type + " " + change.name + " " + change.oldValue); +var resolver; +var p = new Promise(function(resolve, reject) { + resolver = resolve; }); -obj.foo = 1; -obj.zoo = 2; -obj.foo = 3; +async function main() { + await p; + assertLog("then #1"); + await undefined; + assertLog("then #2"); +} +main(); +resolver(); + +%RunMicrotasks(); assertNull(exception); diff --git a/deps/v8/test/mjsunit/harmony/debug-async-liveedit.js b/deps/v8/test/mjsunit/harmony/debug-async-liveedit.js new file mode 100644 index 0000000000..276ae7a79d --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/debug-async-liveedit.js @@ -0,0 +1,133 @@ +// Copyright 2016 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-async-await +// Flags: --expose-debug-as debug --allow-natives-syntax + +var Debug = debug.Debug; +var LiveEdit = Debug.LiveEdit; + +unique_id = 0; + +var AsyncFunction = (async function(){}).constructor; + +function assertPromiseValue(value, promise) { + promise.then(resolve => { + went = true; + if (resolve !== value) { + print(`expected ${value} found ${resolve}`); + quit(1); + } + }, reject => { + print(`rejected ${reject}`); + quit(1); + }); +} + +function MakeAsyncFunction() { + // Prevents eval script caching. + unique_id++; + return AsyncFunction('callback', + "/* " + unique_id + "*/\n" + + "await callback();\n" + + "return 'Cat';\n"); +} + +function MakeFunction() { + // Prevents eval script caching. + unique_id++; + return Function('callback', + "/* " + unique_id + "*/\n" + + "callback();\n" + + "return 'Cat';\n"); +} + +// First, try MakeGenerator with no perturbations. +(function(){ + var asyncfn = MakeAsyncFunction(); + function callback() {}; + var promise = asyncfn(callback); + assertPromiseValue('Cat', promise); +})(); + +function patch(fun, from, to) { + function debug() { + var log = new Array(); + var script = Debug.findScript(fun); + var pos = script.source.indexOf(from); + print(`pos ${pos}`); + try { + LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, + log); + } finally { + print("Change log: " + JSON.stringify(log) + "\n"); + } + } + %ExecuteInDebugContext(debug); +} + +// Try to edit a MakeAsyncFunction while it's running, then again while it's +// stopped. +(function(){ + var asyncfn = MakeAsyncFunction(); + + var patch_attempted = false; + function attempt_patch() { + assertFalse(patch_attempted); + patch_attempted = true; + assertThrows(function() { patch(asyncfn, "'Cat'", "'Capybara'") }, + LiveEdit.Failure); + }; + var promise = asyncfn(attempt_patch); + // Patch should not succeed because there is a live async function activation + // on the stack. + assertPromiseValue("Cat", promise); + assertTrue(patch_attempted); + + %RunMicrotasks(); + + // At this point one iterator is live, but closed, so the patch will succeed. + patch(asyncfn, "'Cat'", "'Capybara'"); + promise = asyncfn(function(){}); + // Patch successful. + assertPromiseValue("Capybara", promise); + + // Patching will fail however when an async function is suspended. + var resolve; + promise = asyncfn(function(){return new Promise(function(r){resolve = r})}); + assertThrows(function() { patch(asyncfn, "'Capybara'", "'Tapir'") }, + LiveEdit.Failure); + resolve(); + assertPromiseValue("Capybara", promise); + + // Try to patch functions with activations inside and outside async + // function activations. We should succeed in the former case, but not in the + // latter. + var fun_outside = MakeFunction(); + var fun_inside = MakeFunction(); + var fun_patch_attempted = false; + var fun_patch_restarted = false; + function attempt_fun_patches() { + if (fun_patch_attempted) { + assertFalse(fun_patch_restarted); + fun_patch_restarted = true; + return; + } + fun_patch_attempted = true; + // Patching outside an async function activation must fail. + assertThrows(function() { patch(fun_outside, "'Cat'", "'Cobra'") }, + LiveEdit.Failure); + // Patching inside an async function activation may succeed. + patch(fun_inside, "'Cat'", "'Koala'"); + } + promise = asyncfn(function() { return fun_inside(attempt_fun_patches) }); + assertEquals('Cat', + fun_outside(function () { + assertPromiseValue('Capybara', promise); + assertTrue(fun_patch_restarted); + assertTrue(fun_inside.toString().includes("'Koala'")); + })); +})(); + +%RunMicrotasks(); diff --git a/deps/v8/test/mjsunit/harmony/do-expressions.js b/deps/v8/test/mjsunit/harmony/do-expressions.js index b3be4eca91..38b68b6ed7 100644 --- a/deps/v8/test/mjsunit/harmony/do-expressions.js +++ b/deps/v8/test/mjsunit/harmony/do-expressions.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-do-expressions --harmony-sloppy-let --allow-natives-syntax +// Flags: --harmony-do-expressions --allow-natives-syntax function returnValue(v) { return v; } function MyError() {} diff --git a/deps/v8/test/mjsunit/harmony/for-in.js b/deps/v8/test/mjsunit/harmony/for-in.js new file mode 100644 index 0000000000..58e343b903 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/for-in.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-for-in + +assertThrows("for (var x = 0 in {});", SyntaxError); +assertThrows("for (const x = 0 in {});", SyntaxError); +assertThrows("for (let x = 0 in {});", SyntaxError); diff --git a/deps/v8/test/mjsunit/harmony/function-sent.js b/deps/v8/test/mjsunit/harmony/function-sent.js index b3cd644dd9..cd0ca957a8 100644 --- a/deps/v8/test/mjsunit/harmony/function-sent.js +++ b/deps/v8/test/mjsunit/harmony/function-sent.js @@ -49,7 +49,7 @@ try { yield function.sent; } finally { - return 666; + return 23; } } @@ -77,7 +77,7 @@ let x = g(); assertEquals({value: 1, done: false}, x.next(1)); assertEquals({value: undefined, done: false}, x.next(2)); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 23, done: true}, x.return(42)); } } diff --git a/deps/v8/test/mjsunit/harmony/futex.js b/deps/v8/test/mjsunit/harmony/futex.js index 626cff5fdb..f90b773aa3 100644 --- a/deps/v8/test/mjsunit/harmony/futex.js +++ b/deps/v8/test/mjsunit/harmony/futex.js @@ -19,9 +19,8 @@ [i8a, i16a, i32a, ui8a, ui8ca, ui16a, ui32a, f32a, f64a].forEach(function( ta) { - assertThrows(function() { Atomics.futexWait(ta, 0, 0); }); - assertThrows(function() { Atomics.futexWake(ta, 0, 1); }); - assertThrows(function() { Atomics.futexWakeOrRequeue(ta, 0, 1, 0, 0); }); + assertThrows(function() { Atomics.wait(ta, 0, 0); }); + assertThrows(function() { Atomics.wake(ta, 0, 1); }); }); })(); @@ -39,9 +38,8 @@ [i8a, i16a, ui8a, ui8ca, ui16a, ui32a, f32a, f64a].forEach(function( ta) { - assertThrows(function() { Atomics.futexWait(ta, 0, 0); }); - assertThrows(function() { Atomics.futexWake(ta, 0, 1); }); - assertThrows(function() { Atomics.futexWakeOrRequeue(ta, 0, 1, 0, 0); }); + assertThrows(function() { Atomics.wait(ta, 0, 0); }); + assertThrows(function() { Atomics.wake(ta, 0, 1); }); }); })(); @@ -52,35 +50,23 @@ // Valid indexes are 0-3. [-1, 4, 100].forEach(function(invalidIndex) { assertThrows(function() { - Atomics.futexWait(i32a, invalidIndex, 0); + Atomics.wait(i32a, invalidIndex, 0); }, RangeError); assertThrows(function() { - Atomics.futexWake(i32a, invalidIndex, 0); + Atomics.wake(i32a, invalidIndex, 0); }, RangeError); var validIndex = 0; - assertThrows(function() { - Atomics.futexWakeOrRequeue(i32a, invalidIndex, 0, 0, validIndex); - }, RangeError); - assertThrows(function() { - Atomics.futexWakeOrRequeue(i32a, validIndex, 0, 0, invalidIndex); - }, RangeError); }); i32a = new Int32Array(sab, 8); [-1, 2, 100].forEach(function(invalidIndex) { assertThrows(function() { - Atomics.futexWait(i32a, invalidIndex, 0); + Atomics.wait(i32a, invalidIndex, 0); }, RangeError); assertThrows(function() { - Atomics.futexWake(i32a, invalidIndex, 0); + Atomics.wake(i32a, invalidIndex, 0); }, RangeError); var validIndex = 0; - assertThrows(function() { - Atomics.futexWakeOrRequeue(i32a, invalidIndex, 0, 0, validIndex); - }, RangeError); - assertThrows(function() { - Atomics.futexWakeOrRequeue(i32a, validIndex, 0, 0, invalidIndex); - }, RangeError); }); })(); @@ -88,7 +74,7 @@ var i32a = new Int32Array(new SharedArrayBuffer(16)); var waitMs = 100; var startTime = new Date(); - assertEquals(Atomics.TIMEDOUT, Atomics.futexWait(i32a, 0, 0, waitMs)); + assertEquals("timed-out", Atomics.wait(i32a, 0, 0, waitMs)); var endTime = new Date(); assertTrue(endTime - startTime >= waitMs); })(); @@ -96,17 +82,17 @@ (function TestWaitNotEqual() { var sab = new SharedArrayBuffer(16); var i32a = new Int32Array(sab); - assertEquals(Atomics.NOTEQUAL, Atomics.futexWait(i32a, 0, 42)); + assertEquals("not-equal", Atomics.wait(i32a, 0, 42)); i32a = new Int32Array(sab, 8); i32a[0] = 1; - assertEquals(Atomics.NOTEQUAL, Atomics.futexWait(i32a, 0, 0)); + assertEquals("not-equal", Atomics.wait(i32a, 0, 0)); })(); (function TestWaitNegativeTimeout() { var i32a = new Int32Array(new SharedArrayBuffer(16)); - assertEquals(Atomics.TIMEDOUT, Atomics.futexWait(i32a, 0, 0, -1)); - assertEquals(Atomics.TIMEDOUT, Atomics.futexWait(i32a, 0, 0, -Infinity)); + assertEquals("timed-out", Atomics.wait(i32a, 0, 0, -1)); + assertEquals("timed-out", Atomics.wait(i32a, 0, 0, -Infinity)); })(); //// WORKER ONLY TESTS @@ -120,7 +106,7 @@ if (this.Worker) { var workerScript = `onmessage = function(msg) { var i32a = new Int32Array(msg.sab, msg.offset); - var result = Atomics.futexWait(i32a, 0, 0, ${timeout}); + var result = Atomics.wait(i32a, 0, 0, ${timeout}); postMessage(result); };`; @@ -128,10 +114,10 @@ if (this.Worker) { worker.postMessage({sab: sab, offset: offset}, [sab]); // Spin until the worker is waiting on the futex. - while (%AtomicsFutexNumWaitersForTesting(i32a, 0) != 1) {} + while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {} - Atomics.futexWake(i32a, 0, 1); - assertEquals(Atomics.OK, worker.getMessage()); + Atomics.wake(i32a, 0, 1); + assertEquals("ok", worker.getMessage()); worker.terminate(); var worker2 = new Worker(workerScript); @@ -140,9 +126,9 @@ if (this.Worker) { worker2.postMessage({sab: sab, offset: offset}, [sab]); // Spin until the worker is waiting on the futex. - while (%AtomicsFutexNumWaitersForTesting(i32a2, 0) != 1) {} - Atomics.futexWake(i32a2, 0, 1); - assertEquals(Atomics.OK, worker2.getMessage()); + while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {} + Atomics.wake(i32a2, 0, 1); + assertEquals("ok", worker2.getMessage()); worker2.terminate(); // Futex should work when index and buffer views are different, but @@ -152,9 +138,9 @@ if (this.Worker) { worker3.postMessage({sab: sab, offset: 8}, [sab]); // Spin until the worker is waiting on the futex. - while (%AtomicsFutexNumWaitersForTesting(i32a2, 1) != 1) {} - Atomics.futexWake(i32a2, 1, 1); - assertEquals(Atomics.OK, worker3.getMessage()); + while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {} + Atomics.wake(i32a2, 1, 1); + assertEquals("ok", worker3.getMessage()); worker3.terminate(); }; @@ -184,7 +170,7 @@ if (this.Worker) { var i32a = new Int32Array(msg.sab); // Wait on i32a[4] (should be zero). - var result = Atomics.futexWait(i32a, 4, 0); + var result = Atomics.wait(i32a, 4, 0); // Set i32a[id] to 1 to notify the main thread which workers were // woken up. Atomics.store(i32a, id, 1); @@ -199,10 +185,10 @@ if (this.Worker) { } // Spin until all workers are waiting on the futex. - while (%AtomicsFutexNumWaitersForTesting(i32a, 4) != 4) {} + while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {} // Wake up three waiters. - assertEquals(3, Atomics.futexWake(i32a, 4, 3)); + assertEquals(3, Atomics.wake(i32a, 4, 3)); var wokenCount = 0; var waitingId = 0 + 1 + 2 + 3; @@ -211,7 +197,7 @@ if (this.Worker) { // Look for workers that have not yet been reaped. Set i32a[id] to 2 // when they've been processed so we don't look at them again. if (Atomics.compareExchange(i32a, id, 1, 2) == 1) { - assertEquals(Atomics.OK, workers[id].getMessage()); + assertEquals("ok", workers[id].getMessage()); workers[id].terminate(); waitingId -= id; wokenCount++; @@ -221,131 +207,14 @@ if (this.Worker) { assertEquals(3, wokenCount); assertEquals(0, Atomics.load(i32a, waitingId)); - assertEquals(1, %AtomicsFutexNumWaitersForTesting(i32a, 4)); + assertEquals(1, %AtomicsNumWaitersForTesting(i32a, 4)); // Finally wake the last waiter. - assertEquals(1, Atomics.futexWake(i32a, 4, 1)); - assertEquals(Atomics.OK, workers[waitingId].getMessage()); + assertEquals(1, Atomics.wake(i32a, 4, 1)); + assertEquals("ok", workers[waitingId].getMessage()); workers[waitingId].terminate(); - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a, 4)); - - })(); - - (function TestWakeOrRequeue() { - var sab = new SharedArrayBuffer(24); - var i32a = new Int32Array(sab); - - // SAB values: - // i32a[id], where id in range [0, 3]: - // 0 => Worker |id| is still waiting on the futex - // 1 => Worker |id| is not waiting on futex, but has not be reaped by the - // main thread. - // 2 => Worker |id| has been reaped. - // - // i32a[4]: - // always 0. Each worker will initially wait on this index. - // - // i32a[5]: - // always 0. Requeued workers will wait on this index. - - var workerScript = - `onmessage = function(msg) { - var id = msg.id; - var i32a = new Int32Array(msg.sab); - - var result = Atomics.futexWait(i32a, 4, 0, Infinity); - Atomics.store(i32a, id, 1); - postMessage(result); - };`; - - var workers = []; - for (id = 0; id < 4; id++) { - workers[id] = new Worker(workerScript); - workers[id].postMessage({sab: sab, id: id}, [sab]); - } - - // Spin until all workers are waiting on the futex. - while (%AtomicsFutexNumWaitersForTesting(i32a, 4) != 4) {} - - var index1 = 4; - var index2 = 5; - - // If futexWakeOrRequeue is called with the incorrect value, it shouldn't - // wake any waiters. - assertEquals(Atomics.NOTEQUAL, - Atomics.futexWakeOrRequeue(i32a, index1, 1, 42, index2)); - - assertEquals(4, %AtomicsFutexNumWaitersForTesting(i32a, index1)); - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a, index2)); - - // Now wake with the correct value. - assertEquals(1, Atomics.futexWakeOrRequeue(i32a, index1, 1, 0, index2)); - - // The workers that are still waiting should atomically be transferred to - // the new index. - assertEquals(3, %AtomicsFutexNumWaitersForTesting(i32a, index2)); - - // The woken worker may not have been scheduled yet. Look for which thread - // has set its i32a value to 1. - var wokenCount = 0; - while (wokenCount < 1) { - for (id = 0; id < 4; id++) { - if (Atomics.compareExchange(i32a, id, 1, 2) == 1) { - wokenCount++; - } - } - } - - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a, index1)); - - // Wake the remaining waiters. - assertEquals(3, Atomics.futexWake(i32a, index2, 3)); - - // As above, wait until the workers have been scheduled. - wokenCount = 0; - while (wokenCount < 3) { - for (id = 0; id < 4; id++) { - if (Atomics.compareExchange(i32a, id, 1, 2) == 1) { - wokenCount++; - } - } - } - - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a, index1)); - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a, index2)); - - for (id = 0; id < 4; ++id) { - assertEquals(Atomics.OK, workers[id].getMessage()); - } - - // Test futexWakeOrRequeue on offset typed array - var offset = 16; - sab = new SharedArrayBuffer(24); - i32a = new Int32Array(sab); - var i32a2 = new Int32Array(sab, offset); - - for (id = 0; id < 4; id++) { - workers[id].postMessage({sab: sab, id: id}, [sab]); - } - - while (%AtomicsFutexNumWaitersForTesting(i32a2, 0) != 4) { } - - index1 = 0; - index2 = 1; - assertEquals(4, %AtomicsFutexNumWaitersForTesting(i32a2, index1)); - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a2, index2)); - - assertEquals(2, Atomics.futexWakeOrRequeue(i32a2, index1, 2, 0, index2)); - assertEquals(2, %AtomicsFutexNumWaitersForTesting(i32a2, index2)); - assertEquals(0, %AtomicsFutexNumWaitersForTesting(i32a2, index1)); - - assertEquals(2, Atomics.futexWake(i32a2, index2, 2)); - - for (id = 0; id < 4; ++id) { - assertEquals(Atomics.OK, workers[id].getMessage()); - workers[id].terminate(); - } + assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4)); })(); diff --git a/deps/v8/test/mjsunit/harmony/generators-turbo.js b/deps/v8/test/mjsunit/harmony/generators-turbo.js new file mode 100644 index 0000000000..61334b93f8 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/generators-turbo.js @@ -0,0 +1,667 @@ +// Copyright 2016 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: --ignition --harmony-do-expressions +// Flags: --allow-natives-syntax --turbo --turbo-from-bytecode + + +// This file is identical to mjsunit/harmony/generators.js, except for its Flags +// lines. The purpose is to explicitly mention --turbo-from-bytecode such that +// Clusterfuzz can thoroughly test the new generators implementation. + + +function MaybeOptimizeOrDeoptimize(f) { + let x = Math.random(); // --random-seed makes this deterministic + if (x <= 0.33) { + %OptimizeFunctionOnNextCall(f); + } else if (x <= 0.66) { + %DeoptimizeFunction(f); + } +} + +function Next(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.next(...args); +} + +function Return(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.return(...args); +} + +function Throw(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.throw(...args); +} + + +{ // yield in try-catch + + let g = function*() { + try {yield 1} catch (error) {assertEquals("caught", error)} + }; + + assertThrowsEquals(() => Throw(g(), "not caught"), "not caught"); + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Throw(x, "caught")); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + assertThrowsEquals(() => Throw(x, "not caught"), "not caught"); + } +} + + +{ // return that doesn't close + let g = function*() { try {return 42} finally {yield 43} }; + + { + let x = g(); + assertEquals({value: 43, done: false}, Next(x)); + assertEquals({value: 42, done: true}, Next(x)); + } +} + + +{ // return that doesn't close + let x; + let g = function*() { try {return 42} finally {Throw(x, 666)} }; + + { + x = g(); + assertThrows(() => Next(x), TypeError); // still executing + } +} + + +{ // yield in try-finally, finally clause performs return + + let g = function*() { try {yield 42} finally {return 13} }; + + { // "return" closes at suspendedStart + let x = g(); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertThrowsEquals(() => Throw(x, 43), 43); + assertEquals({value: 42, done: true}, Return(x, 42)); + } + + { // "throw" closes at suspendedStart + let x = g(); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertEquals({value: 43, done: true}, Return(x, 43)); + assertThrowsEquals(() => Throw(x, 44), 44); + } + + { // "next" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Next(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + } + + { // "return" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertEquals({value: 666, done: true}, Return(x, 666)); + } + + { // "throw" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Throw(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 666)); + } +} + + +{ // yield in try-finally, finally clause doesn't perform return + + let g = function*() { try {yield 42} finally {13} }; + + { // "return" closes at suspendedStart + let x = g(); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertThrowsEquals(() => Throw(x, 43), 43); + assertEquals({value: 42, done: true}, Return(x, 42)); + } + + { // "throw" closes at suspendedStart + let x = g(); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertEquals({value: 43, done: true}, Return(x, 43)); + assertThrowsEquals(() => Throw(x, 44), 44); + } + + { // "next" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: 42, done: true}, Return(x, 42)); + } + + { // "return" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 44), 44); + assertEquals({value: 42, done: true}, Return(x, 42)); + } + + { // "throw" closes at suspendedYield + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: 42, done: true}, Return(x, 42)); + } +} + + +{ // yield in try-finally, finally clause yields and performs return + + let g = function*() { try {yield 42} finally {yield 43; return 13} }; + + { + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 13, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); + } + + { + let x = g(); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); + } +} + + +{ // yield in try-finally, finally clause yields and doesn't perform return + + let g = function*() { try {yield 42} finally {yield 43; 13} }; + + { + let x = g(); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 666, done: true}, Next(x)); + assertEquals({value: 5, done: true}, Return(x, 5)); + } + + { + let x = g(); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); + } +} + + +{ // yield*, finally clause performs return + + let h = function*() { try {yield 42} finally {yield 43; return 13} }; + let g = function*() { yield 1; yield yield* h(); }; + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Next(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Throw(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + } +} + + +{ // yield*, finally clause does not perform return + + let h = function*() { try {yield 42} finally {yield 43; 13} }; + let g = function*() { yield 1; yield yield* h(); }; + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Next(x, 666)); + assertEquals({value: undefined, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 44)); + assertEquals({value: 44, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Throw(x, 666)); + assertThrowsEquals(() => Next(x), 666); + } +} + + +{ // yield*, .return argument is final result + + function* inner() { + yield 2; + } + + function* g() { + yield 1; + return yield* inner(); + } + + { + let x = g(); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 2, done: false}, Next(x)); + assertEquals({value: 42, done: true}, Return(x, 42)); + } +} + + +// More or less random tests from here on. + + +{ + function* foo() { } + let g = foo(); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { return new.target } + let g = foo(); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { throw 666; return 42} + let g = foo(); + assertThrowsEquals(() => Next(g), 666); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo(a) { return a; } + let g = foo(42); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo(a) { a.iwashere = true; return a; } + let x = {}; + let g = foo(x); + assertEquals({value: {iwashere: true}, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 42; + function* foo() { return a; } + let g = foo(); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 40; + function* foo(b) { return a + b; } + let g = foo(2); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 40; + function* foo(b) { a--; b++; return a + b; } + let g = foo(2); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let g; + function* foo() { Next(g) } + g = foo(); + assertThrows(() => Next(g), TypeError); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; yield 3; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + + +{ + function* foo() { yield 2; if (true) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; if (true) { yield 3; yield 4 } } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; if (false) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; while (true) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; (yield 3) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; (do {yield 3}) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; return (yield 3) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 42, done: true}, Next(g, 0)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let x = 42; + function* foo() { + yield x; + for (let x in {a: 1, b: 2}) { + let i = 2; + yield x; + yield i; + do { + yield i; + } while (i-- > 0); + } + yield x; + return 5; + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 'a', done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 'b', done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 5, done: true}, Next(g)); +} + +{ + let a = 3; + function* foo() { + let b = 4; + yield 1; + { let c = 5; yield 2; yield a; yield b; yield c; } + } + g = foo(); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: 5, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + } + g = foo(); + for (let i = 0; i < 100; ++i) { + assertEquals({value: 42, done: false}, i%25 === 0 ? Next(g) : g.next()); + } + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { + for (let i = 0; i < 3; ++i) { + let j = 0 + yield i; + do { + yield (i + 10); + } while (++j < 2); + } + } + g = foo(); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 10, done: false}, Next(g)); + assertEquals({value: 10, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 11, done: false}, Next(g)); + assertEquals({value: 11, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 12, done: false}, Next(g)); + assertEquals({value: 12, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let foo = function*() { + while (true) { + if (true || false) yield 42; + continue; + } + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); +} + +{ + let foo = function*() { + yield* (function*() { yield 42; }()); + assertUnreachable(); + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 23, done: true}, Return(g, 23)); +} + +{ + let iterable = { + [Symbol.iterator]() { + return { next() { return {} } }; + } + }; + let foo = function*() { yield* iterable }; + g = foo(); + g.next(); + assertThrows(() => Throw(g), TypeError); +} diff --git a/deps/v8/test/mjsunit/harmony/generators.js b/deps/v8/test/mjsunit/harmony/generators.js index df6cec8925..a4fc1c4aa4 100644 --- a/deps/v8/test/mjsunit/harmony/generators.js +++ b/deps/v8/test/mjsunit/harmony/generators.js @@ -2,6 +2,33 @@ // 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 MaybeOptimizeOrDeoptimize(f) { + let x = Math.random(); // --random-seed makes this deterministic + if (x <= 0.33) { + %OptimizeFunctionOnNextCall(f); + } else if (x <= 0.66) { + %DeoptimizeFunction(f); + } +} + +function Next(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.next(...args); +} + +function Return(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.return(...args); +} + +function Throw(generator, ...args) { + MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); + return generator.throw(...args); +} + { // yield in try-catch @@ -9,19 +36,19 @@ try {yield 1} catch (error) {assertEquals("caught", error)} }; - assertThrowsEquals(() => g().throw("not caught"), "not caught"); + assertThrowsEquals(() => Throw(g(), "not caught"), "not caught"); { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.throw("caught")); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Throw(x, "caught")); } { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); - assertThrowsEquals(() => x.throw("not caught"), "not caught"); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); + assertThrowsEquals(() => Throw(x, "not caught"), "not caught"); } } @@ -31,19 +58,19 @@ { let x = g(); - assertEquals({value: 43, done: false}, x.next()); - assertEquals({value: 42, done: true}, x.next()); + assertEquals({value: 43, done: false}, Next(x)); + assertEquals({value: 42, done: true}, Next(x)); } } { // return that doesn't close let x; - let g = function*() { try {return 42} finally {x.throw(666)} }; + let g = function*() { try {return 42} finally {Throw(x, 666)} }; { x = g(); - assertThrows(() => x.next(), TypeError); // still executing + assertThrows(() => Next(x), TypeError); // still executing } } @@ -54,42 +81,42 @@ { // "return" closes at suspendedStart let x = g(); - assertEquals({value: 666, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next(42)); - assertThrowsEquals(() => x.throw(43), 43); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertThrowsEquals(() => Throw(x, 43), 43); + assertEquals({value: 42, done: true}, Return(x, 42)); } { // "throw" closes at suspendedStart let x = g(); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: undefined, done: true}, x.next(42)); - assertEquals({value: 43, done: true}, x.return(43)); - assertThrowsEquals(() => x.throw(44), 44); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertEquals({value: 43, done: true}, Return(x, 43)); + assertThrowsEquals(() => Throw(x, 44), 44); } { // "next" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 13, done: true}, x.next(666)); - assertEquals({value: undefined, done: true}, x.next(666)); - assertThrowsEquals(() => x.throw(666), 666); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Next(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); } { // "return" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 13, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next(666)); - assertEquals({value: 666, done: true}, x.return(666)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertEquals({value: 666, done: true}, Return(x, 666)); } { // "throw" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 13, done: true}, x.throw(666)); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: undefined, done: true}, x.next(666)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 13, done: true}, Throw(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 666)); } } @@ -100,45 +127,45 @@ { // "return" closes at suspendedStart let x = g(); - assertEquals({value: 666, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next(42)); - assertThrowsEquals(() => x.throw(43), 43); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertThrowsEquals(() => Throw(x, 43), 43); + assertEquals({value: 42, done: true}, Return(x, 42)); } { // "throw" closes at suspendedStart let x = g(); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: undefined, done: true}, x.next(42)); - assertEquals({value: 43, done: true}, x.return(43)); - assertThrowsEquals(() => x.throw(44), 44); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 42)); + assertEquals({value: 43, done: true}, Return(x, 43)); + assertThrowsEquals(() => Throw(x, 44), 44); } { // "next" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next(666)); - assertEquals({value: undefined, done: true}, x.next(666)); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: 42, done: true}, Return(x, 42)); } { // "return" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 666, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next(666)); - assertThrowsEquals(() => x.throw(44), 44); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 44), 44); + assertEquals({value: 42, done: true}, Return(x, 42)); } { // "throw" closes at suspendedYield let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: undefined, done: true}, x.next(666)); - assertThrowsEquals(() => x.throw(666), 666); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 42, done: false}, Next(x)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: undefined, done: true}, Next(x, 666)); + assertThrowsEquals(() => Throw(x, 666), 666); + assertEquals({value: 42, done: true}, Return(x, 42)); } } @@ -149,17 +176,17 @@ { let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.return(666)); - assertEquals({value: 13, done: true}, x.next()); - assertEquals({value: 666, done: true}, x.return(666)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 13, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); } { let x = g(); - assertEquals({value: 666, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next()); - assertEquals({value: 666, done: true}, x.return(666)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); } } @@ -170,17 +197,17 @@ { let x = g(); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.return(666)); - assertEquals({value: 666, done: true}, x.next()); - assertEquals({value: 5, done: true}, x.return(5)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 666, done: true}, Next(x)); + assertEquals({value: 5, done: true}, Return(x, 5)); } { let x = g(); - assertEquals({value: 666, done: true}, x.return(666)); - assertEquals({value: undefined, done: true}, x.next()); - assertEquals({value: 666, done: true}, x.return(666)); + assertEquals({value: 666, done: true}, Return(x, 666)); + assertEquals({value: undefined, done: true}, Next(x)); + assertEquals({value: 666, done: true}, Return(x, 666)); } } @@ -192,29 +219,29 @@ { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.next(666)); - assertEquals({value: 13, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Next(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); } { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.return(666)); - assertEquals({value: 13, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); } { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.throw(666)); - assertEquals({value: 13, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Throw(x, 666)); + assertEquals({value: 13, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); } } @@ -226,28 +253,28 @@ { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.next(666)); - assertEquals({value: undefined, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Next(x, 666)); + assertEquals({value: undefined, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); } { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.return(44)); - assertEquals({value: 44, done: false}, x.next()); - assertEquals({value: undefined, done: true}, x.next()); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Return(x, 44)); + assertEquals({value: 44, done: false}, Next(x)); + assertEquals({value: undefined, done: true}, Next(x)); } { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 42, done: false}, x.next()); - assertEquals({value: 43, done: false}, x.throw(666)); - assertThrowsEquals(() => x.next(), 666); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 42, done: false}, Next(x)); + assertEquals({value: 43, done: false}, Throw(x, 666)); + assertThrowsEquals(() => Next(x), 666); } } @@ -265,8 +292,370 @@ { let x = g(); - assertEquals({value: 1, done: false}, x.next()); - assertEquals({value: 2, done: false}, x.next()); - assertEquals({value: 42, done: true}, x.return(42)); + assertEquals({value: 1, done: false}, Next(x)); + assertEquals({value: 2, done: false}, Next(x)); + assertEquals({value: 42, done: true}, Return(x, 42)); + } +} + + +// More or less random tests from here on. + + +{ + function* foo() { } + let g = foo(); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { return new.target } + let g = foo(); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { throw 666; return 42} + let g = foo(); + assertThrowsEquals(() => Next(g), 666); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo(a) { return a; } + let g = foo(42); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo(a) { a.iwashere = true; return a; } + let x = {}; + let g = foo(x); + assertEquals({value: {iwashere: true}, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 42; + function* foo() { return a; } + let g = foo(); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 40; + function* foo(b) { return a + b; } + let g = foo(2); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let a = 40; + function* foo(b) { a--; b++; return a + b; } + let g = foo(2); + assertEquals({value: 42, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let g; + function* foo() { Next(g) } + g = foo(); + assertThrows(() => Next(g), TypeError); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; yield 3; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + + +{ + function* foo() { yield 2; if (true) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; if (true) { yield 3; yield 4 } } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; if (false) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { yield 2; while (true) { yield 3 }; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; (yield 3) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; (do {yield 3}) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); +} + +{ + function* foo() { yield 2; return (yield 3) + 42; yield 4 } + g = foo(); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 42, done: true}, Next(g, 0)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let x = 42; + function* foo() { + yield x; + for (let x in {a: 1, b: 2}) { + let i = 2; + yield x; + yield i; + do { + yield i; + } while (i-- > 0); + } + yield x; + return 5; + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 'a', done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 'b', done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 5, done: true}, Next(g)); +} + +{ + let a = 3; + function* foo() { + let b = 4; + yield 1; + { let c = 5; yield 2; yield a; yield b; yield c; } + } + g = foo(); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 3, done: false}, Next(g)); + assertEquals({value: 4, done: false}, Next(g)); + assertEquals({value: 5, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + yield 42; + } + g = foo(); + for (let i = 0; i < 100; ++i) { + assertEquals({value: 42, done: false}, i%25 === 0 ? Next(g) : g.next()); + } + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + function* foo() { + for (let i = 0; i < 3; ++i) { + let j = 0 + yield i; + do { + yield (i + 10); + } while (++j < 2); + } } + g = foo(); + assertEquals({value: 0, done: false}, Next(g)); + assertEquals({value: 10, done: false}, Next(g)); + assertEquals({value: 10, done: false}, Next(g)); + assertEquals({value: 1, done: false}, Next(g)); + assertEquals({value: 11, done: false}, Next(g)); + assertEquals({value: 11, done: false}, Next(g)); + assertEquals({value: 2, done: false}, Next(g)); + assertEquals({value: 12, done: false}, Next(g)); + assertEquals({value: 12, done: false}, Next(g)); + assertEquals({value: undefined, done: true}, Next(g)); +} + +{ + let foo = function*() { + while (true) { + if (true || false) yield 42; + continue; + } + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 42, done: false}, Next(g)); +} + +{ + let foo = function*() { + yield* (function*() { yield 42; }()); + assertUnreachable(); + } + g = foo(); + assertEquals({value: 42, done: false}, Next(g)); + assertEquals({value: 23, done: true}, Return(g, 23)); +} + +{ + let iterable = { + [Symbol.iterator]() { + return { next() { return {} } }; + } + }; + let foo = function*() { yield* iterable }; + g = foo(); + g.next(); + assertThrows(() => Throw(g), TypeError); } diff --git a/deps/v8/test/mjsunit/harmony/harmony-string-pad-end.js b/deps/v8/test/mjsunit/harmony/harmony-string-pad-end.js index 3292e94eee..03e5aeacdb 100644 --- a/deps/v8/test/mjsunit/harmony/harmony-string-pad-end.js +++ b/deps/v8/test/mjsunit/harmony/harmony-string-pad-end.js @@ -67,8 +67,19 @@ (function TestFillerToString() { assertEquals(". ", ".".padEnd(10)); assertEquals(". ", ".".padEnd(10, undefined)); - assertEquals(". ", ".".padEnd(10, { toString() { return ""; } })); assertEquals(".nullnulln", ".".padEnd(10, null)); + assertEquals(".XXXXXXXXX", ".".padEnd(10, { toString() { return "X"; } })); + assertEquals( + ".111111111", + ".".padEnd(10, { toString: undefined, valueOf() { return 1; } })); +})(); + + +(function TestFillerEmptyString() { + assertEquals(".", ".".padEnd(10, "")); + assertEquals(".", ".".padEnd(10, { toString() { return ""; } })); + assertEquals( + ".", ".".padEnd(10, { toString: undefined, valueOf() { return ""; } })); })(); diff --git a/deps/v8/test/mjsunit/harmony/harmony-string-pad-start.js b/deps/v8/test/mjsunit/harmony/harmony-string-pad-start.js index 2b2d004251..33bf8f3c9d 100644 --- a/deps/v8/test/mjsunit/harmony/harmony-string-pad-start.js +++ b/deps/v8/test/mjsunit/harmony/harmony-string-pad-start.js @@ -67,8 +67,19 @@ (function TestFillerToString() { assertEquals(" .", ".".padStart(10)); assertEquals(" .", ".".padStart(10, undefined)); - assertEquals(" .", ".".padStart(10, { toString() { return ""; } })); assertEquals("nullnulln.", ".".padStart(10, null)); + assertEquals("XXXXXXXXX.", ".".padStart(10, { toString() { return "X"; } })); + assertEquals( + "111111111.", + ".".padStart(10, { toString: undefined, valueOf() { return 1; } })); +})(); + + +(function TestFillerEmptyString() { + assertEquals(".", ".".padStart(10, "")); + assertEquals(".", ".".padStart(10, { toString() { return ""; } })); + assertEquals( + ".", ".".padStart(10, { toString: undefined, valueOf() { return ""; } })); })(); diff --git a/deps/v8/test/mjsunit/harmony/mirror-async-function-promise.js b/deps/v8/test/mjsunit/harmony/mirror-async-function-promise.js new file mode 100644 index 0000000000..966b0ce267 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/mirror-async-function-promise.js @@ -0,0 +1,93 @@ +// Copyright 2016 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 --harmony-async-await --allow-natives-syntax +// Test the mirror object for promises. + +var AsyncFunction = (async function() {}).constructor; + +function MirrorRefCache(json_refs) { + var tmp = eval('(' + json_refs + ')'); + this.refs_ = []; + for (var i = 0; i < tmp.length; i++) { + this.refs_[tmp[i].handle] = tmp[i]; + } +} + +MirrorRefCache.prototype.lookup = function(handle) { + return this.refs_[handle]; +} + +function testPromiseMirror(promise, status, value) { + // Create mirror and JSON representation. + var mirror = debug.MakeMirror(promise); + var serializer = debug.MakeMirrorSerializer(); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); + + // Check the mirror hierachy. + assertTrue(mirror instanceof debug.Mirror); + assertTrue(mirror instanceof debug.ValueMirror); + assertTrue(mirror instanceof debug.ObjectMirror); + assertTrue(mirror instanceof debug.PromiseMirror); + + // Check the mirror properties. + assertEquals(status, mirror.status()); + assertTrue(mirror.isPromise()); + assertEquals('promise', mirror.type()); + assertFalse(mirror.isPrimitive()); + assertEquals("Object", mirror.className()); + assertEquals("#<Promise>", mirror.toText()); + assertSame(promise, mirror.value()); + assertTrue(mirror.promiseValue() instanceof debug.Mirror); + assertEquals(value, mirror.promiseValue().value()); + + // Parse JSON representation and check. + var fromJSON = eval('(' + json + ')'); + assertEquals('promise', fromJSON.type); + assertEquals('Object', fromJSON.className); + assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); + assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name); + assertEquals(status, fromJSON.status); + assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value); +} + +// Test a number of different promises. +var resolved = (async function() {})(); +var rejected = (async function() { throw undefined; })(); +var pending = (async function() { await 1; })(); + +testPromiseMirror(resolved, "resolved", undefined); +testPromiseMirror(rejected, "rejected", undefined); +testPromiseMirror(pending, "pending", undefined); + +var resolvedv = (async function() { return "resolve"; })(); +var rejectedv = (async function() { return Promise.reject("reject"); })(); +var thrownv = (async function() { throw "throw"; })(); + +testPromiseMirror(resolvedv, "resolved", 'resolve'); +testPromiseMirror(rejectedv, "rejected", 'reject'); +testPromiseMirror(thrownv, "rejected", 'throw'); + +// Test internal properties of different promises. +var m1 = debug.MakeMirror((async function() { return 1; })()); +var ip = m1.internalProperties(); +assertEquals(2, ip.length); +assertEquals("[[PromiseStatus]]", ip[0].name()); +assertEquals("[[PromiseValue]]", ip[1].name()); +assertEquals("resolved", ip[0].value().value()); +assertEquals(1, ip[1].value().value()); + +var m2 = debug.MakeMirror((async function() { throw 2; })()); +ip = m2.internalProperties(); +assertEquals("rejected", ip[0].value().value()); +assertEquals(2, ip[1].value().value()); + +var m3 = debug.MakeMirror((async function() { await 1; })()); +ip = m3.internalProperties(); +assertEquals("pending", ip[0].value().value()); +assertEquals("undefined", typeof(ip[1].value().value())); + +%RunMicrotasks(); diff --git a/deps/v8/test/mjsunit/harmony/mirror-async-function.js b/deps/v8/test/mjsunit/harmony/mirror-async-function.js new file mode 100644 index 0000000000..b4ba8314a5 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/mirror-async-function.js @@ -0,0 +1,76 @@ +// Copyright 2016 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 --harmony-async-await --allow-natives-syntax +// Test the mirror object for functions. + +var AsyncFunction = (async function() {}).constructor; + +function MirrorRefCache(json_refs) { + var tmp = eval('(' + json_refs + ')'); + this.refs_ = []; + for (var i = 0; i < tmp.length; i++) { + this.refs_[tmp[i].handle] = tmp[i]; + } +} + +MirrorRefCache.prototype.lookup = function(handle) { + return this.refs_[handle]; +} + +function testFunctionMirror(f) { + // Create mirror and JSON representation. + var mirror = debug.MakeMirror(f); + var serializer = debug.MakeMirrorSerializer(); + var json = JSON.stringify(serializer.serializeValue(mirror)); + var refs = new MirrorRefCache( + JSON.stringify(serializer.serializeReferencedObjects())); + + // Check the mirror hierachy. + assertTrue(mirror instanceof debug.Mirror); + assertTrue(mirror instanceof debug.ValueMirror); + assertTrue(mirror instanceof debug.ObjectMirror); + assertTrue(mirror instanceof debug.FunctionMirror); + + // Check the mirror properties. + assertTrue(mirror.isFunction()); + assertEquals('function', mirror.type()); + assertFalse(mirror.isPrimitive()); + assertEquals("Function", mirror.className()); + assertEquals(f.name, mirror.name()); + assertTrue(mirror.resolved()); + assertEquals(f.toString(), mirror.source()); + assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); + assertTrue(mirror.protoObject() instanceof debug.Mirror); + assertTrue(mirror.prototypeObject() instanceof debug.Mirror); + + // Test text representation + assertEquals(f.toString(), mirror.toText()); + + // Parse JSON representation and check. + var fromJSON = eval('(' + json + ')'); + assertEquals('function', fromJSON.type); + assertEquals('Function', fromJSON.className); + assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); + assertEquals('AsyncFunction', + refs.lookup(fromJSON.constructorFunction.ref).name); + assertTrue(fromJSON.resolved); + assertEquals(f.name, fromJSON.name); + assertEquals(f.toString(), fromJSON.source); + + // Check the formatted text (regress 1142074). + assertEquals(f.toString(), fromJSON.text); +} + + +// Test a number of different functions. +testFunctionMirror(async function(){}); +testFunctionMirror(AsyncFunction()); +testFunctionMirror(new AsyncFunction()); +testFunctionMirror(async() => {}); +testFunctionMirror(async function a(){return 1;}); +testFunctionMirror(({ async foo() {} }).foo); +testFunctionMirror((async function(){}).bind({}), "Object"); + +%RunMicrotasks(); diff --git a/deps/v8/test/mjsunit/harmony/modules.js b/deps/v8/test/mjsunit/harmony/modules.js deleted file mode 100644 index e56880500b..0000000000 --- a/deps/v8/test/mjsunit/harmony/modules.js +++ /dev/null @@ -1,8 +0,0 @@ -// 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. -// -// MODULE - -export let a = 42; -assertEquals(42, a); diff --git a/deps/v8/test/mjsunit/harmony/object-get-own-property-descriptors.js b/deps/v8/test/mjsunit/harmony/object-get-own-property-descriptors.js index 7f631d8e58..c71b20a226 100644 --- a/deps/v8/test/mjsunit/harmony/object-get-own-property-descriptors.js +++ b/deps/v8/test/mjsunit/harmony/object-get-own-property-descriptors.js @@ -195,7 +195,14 @@ function TestDuplicateKeys() { }); var result = Object.getOwnPropertyDescriptors(P); - assertEquals({ "A": undefined }, result); + assertEquals({ + "A": { + "value": "VALUE", + "writable": false, + "enumerable": false, + "configurable": true + } + }, result); assertTrue(result.hasOwnProperty("A")); assertEquals([ "ownKeys()", @@ -204,3 +211,25 @@ function TestDuplicateKeys() { ], log); } TestDuplicateKeys(); + +function TestFakeProperty() { + var log = []; + var P = new Proxy({}, { + ownKeys() { + log.push(`ownKeys()`); + return ["fakeProperty"]; + }, + getOwnPropertyDescriptor(target, name) { + log.push(`getOwnPropertyDescriptor(${name})`); + return; + } + }); + var result = Object.getOwnPropertyDescriptors(P); + assertEquals({}, result); + assertFalse(result.hasOwnProperty("fakeProperty")); + assertEquals([ + "ownKeys()", + "getOwnPropertyDescriptor(fakeProperty)" + ], log); +} +TestFakeProperty(); diff --git a/deps/v8/test/mjsunit/harmony/regexp-change-exec.js b/deps/v8/test/mjsunit/harmony/regexp-change-exec.js index 4c9757e3d5..ff84506d89 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-change-exec.js +++ b/deps/v8/test/mjsunit/harmony/regexp-change-exec.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-regexp-exec - class MyError extends Error { } RegExp.prototype.exec = () => { throw new MyError() }; assertThrows(() => "foo".match(/bar/), MyError); diff --git a/deps/v8/test/mjsunit/harmony/regexp-named-captures.js b/deps/v8/test/mjsunit/harmony/regexp-named-captures.js new file mode 100644 index 0000000000..ced8e4b2f6 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regexp-named-captures.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: --harmony-regexp-named-captures + +// Malformed named captures. +assertThrows("/(?<>a)/u"); // Empty name. +assertThrows("/(?<aa)/u"); // Unterminated name. +assertThrows("/(?<42a>a)/u"); // Name starting with digits. +assertThrows("/(?<:a>a)/u"); // Name starting with invalid char. +assertThrows("/(?<a:>a)/u"); // Name containing with invalid char. +assertThrows("/(?<a>a)(?<a>a)/u"); // Duplicate name. +assertThrows("/(?<a>a)(?<b>b)(?<a>a)/u"); // Duplicate name. +assertThrows("/\\k<a>/u"); // Invalid reference. +assertThrows("/(?<a>a)\\k<ab>/u"); // Invalid reference. +assertThrows("/(?<ab>a)\\k<a>/u"); // Invalid reference. +assertThrows("/\\k<a>(?<ab>a)/u"); // Invalid reference. + +// Fallback behavior in non-unicode mode. +assertThrows("/(?<>a)/"); +assertThrows("/(?<aa)/"); +assertThrows("/(?<42a>a)/"); +assertThrows("/(?<:a>a)/"); +assertThrows("/(?<a:>a)/"); +assertThrows("/(?<a>a)(?<a>a)/"); +assertThrows("/(?<a>a)(?<b>b)(?<a>a)/"); +assertThrows("/(?<a>a)\\k<ab>/"); +assertThrows("/(?<ab>a)\\k<a>/"); + +assertEquals(["k<a>"], "xxxk<a>xxx".match(/\k<a>/)); +assertEquals(["k<a"], "xxxk<a>xxx".match(/\k<a/)); + +// Basic named groups. +assertEquals(["a", "a"], "bab".match(/(?<a>a)/u)); +assertEquals(["a", "a"], "bab".match(/(?<a42>a)/u)); +assertEquals(["a", "a"], "bab".match(/(?<_>a)/u)); +assertEquals(["a", "a"], "bab".match(/(?<$>a)/u)); +assertEquals(["bab", "a"], "bab".match(/.(?<$>a)./u)); +assertEquals(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/u)); +assertEquals(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/u)); +assertEquals(["bab", "ab"], "bab".match(/.(?<a>\w\w)/u)); +assertEquals(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/u)); +assertEquals(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/u)); + +assertEquals("bab".match(/(a)/u), "bab".match(/(?<a>a)/u)); +assertEquals("bab".match(/(a)/u), "bab".match(/(?<a42>a)/u)); +assertEquals("bab".match(/(a)/u), "bab".match(/(?<_>a)/u)); +assertEquals("bab".match(/(a)/u), "bab".match(/(?<$>a)/u)); +assertEquals("bab".match(/.(a)./u), "bab".match(/.(?<$>a)./u)); +assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(.)/u)); +assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(?<b>.)/u)); +assertEquals("bab".match(/.(\w\w)/u), "bab".match(/.(?<a>\w\w)/u)); +assertEquals("bab".match(/(\w\w\w)/u), "bab".match(/(?<a>\w\w\w)/u)); +assertEquals("bab".match(/(\w\w)(\w)/u), "bab".match(/(?<a>\w\w)(?<b>\w)/u)); + +assertEquals(["bab", "b"], "bab".match(/(?<b>b).\1/u)); +assertEquals(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/u)); +assertEquals(["baba", "b", "a", "b", "a"], + "baba".match(/(.)(?<a>a)(?<b>\1)(\2)/u)); +assertEquals(["<a", "<"], "<a".match(/(?<lt><)a/u)); +assertEquals([">a", ">"], ">a".match(/(?<gt>>)a/u)); + +// Named references. +assertEquals(["bab", "b"], "bab".match(/(?<b>.).\k<b>/u)); +assertNull("baa".match(/(?<b>.).\k<b>/u)); + +// Nested groups. +assertEquals(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u)); + +// Reference inside group. +assertEquals(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u)); + +// Reference before group. +assertEquals(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/u)); +assertEquals(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u)); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-binary.js b/deps/v8/test/mjsunit/harmony/regexp-property-binary.js new file mode 100644 index 0000000000..c0b4426d5e --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regexp-property-binary.js @@ -0,0 +1,25 @@ +// Copyright 2016 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-property + +function t(re, s) { assertTrue(re.test(s)); } +function f(re, s) { assertFalse(re.test(s)); } + +t(/\p{Bidi_Control}+/u, "\u200E"); +f(/\p{Bidi_C}+/u, "On a dark desert highway, cool wind in my hair"); +t(/\p{AHex}+/u, "DEADBEEF"); +t(/\p{Alphabetic}+/u, "abcdefg"); +t(/\P{Alphabetic}+/u, "1234"); +t(/\p{White_Space}+/u, "\u00A0"); +t(/\p{Uppercase}+/u, "V"); +f(/\p{Lower}+/u, "U"); +t(/\p{Ideo}+/u, "字"); +f(/\p{Ideo}+/u, "x"); + +assertThrows("/\\p{Hiragana}/u"); +assertThrows("/\\p{Bidi_Class}/u"); +assertThrows("/\\p{Bidi_C=False}/u"); +assertThrows("/\\P{Bidi_Control=Y}/u"); +assertThrows("/\\p{AHex=Yes}/u"); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-blocks.js b/deps/v8/test/mjsunit/harmony/regexp-property-blocks.js index d186e985f9..de3fd1e276 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-blocks.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-blocks.js @@ -2,33 +2,33 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-regexp-property --harmony-unicode-regexps +// Flags: --harmony-regexp-property function t(re, s) { assertTrue(re.test(s)); } function f(re, s) { assertFalse(re.test(s)); } -t(/\p{InASCII}+/u, "."); -t(/\p{InASCII}+/u, "supercalifragilisticexpialidocious"); -t(/\p{InBasic_Latin}+/u, "."); -t(/\p{InBasic_Latin}+/u, "supercalifragilisticexpialidocious"); +t(/\p{Block=ASCII}+/u, "."); +t(/\p{Block=ASCII}+/u, "supercalifragilisticexpialidocious"); +t(/\p{Block=Basic_Latin}+/u, "."); +t(/\p{Block=Basic_Latin}+/u, "supercalifragilisticexpialidocious"); -t(/\p{InCJK}+/u, "话说天下大势,分久必合,合久必分"); -t(/\p{InCJK_Unified_Ideographs}+/u, "吾庄后有一桃园,花开正盛"); -f(/\p{InCJK}+/u, "おはようございます"); -f(/\p{InCJK_Unified_Ideographs}+/u, +t(/\p{blk=CJK}+/u, "话说天下大势,分久必合,合久必分"); +t(/\p{blk=CJK_Unified_Ideographs}+/u, "吾庄后有一桃园,花开正盛"); +f(/\p{blk=CJK}+/u, "おはようございます"); +f(/\p{blk=CJK_Unified_Ideographs}+/u, "Something is rotten in the state of Denmark"); -t(/\p{InLatin_1}+/u, "Wie froh bin ich, daß ich weg bin!"); -f(/\p{InLatin_1_Supplement}+/u, "奔腾千里荡尘埃,渡水登山紫雾开"); -f(/\p{InLatin_1_Sup}+/u, "いただきます"); +t(/\p{blk=Latin_1}+/u, "Wie froh bin ich, daß ich weg bin!"); +f(/\p{blk=Latin_1_Supplement}+/u, "奔腾千里荡尘埃,渡水登山紫雾开"); +f(/\p{blk=Latin_1_Sup}+/u, "いただきます"); -t(/\p{InHiragana}/u, "いただきます"); -t(/\p{Hiragana}/u, "\u{1b001}"); // This refers to the script "Hiragana". -f(/\p{InHiragana}/u, "\u{1b001}"); // This refers to the block "Hiragana". +t(/\p{blk=Hiragana}/u, "いただきます"); +t(/\p{sc=Hiragana}/u, "\u{1b001}"); // This refers to the script "Hiragana". +f(/\p{blk=Hiragana}/u, "\u{1b001}"); // This refers to the block "Hiragana". -t(/\p{InGreek_And_Coptic}/u, +t(/\p{blk=Greek_And_Coptic}/u, "ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ"); -t(/\p{InGreek}/u, "μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος"); +t(/\p{blk=Greek}/u, "μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος"); assertThrows("/\\p{In}/u"); assertThrows("/\\pI/u"); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-char-class.js b/deps/v8/test/mjsunit/harmony/regexp-property-char-class.js index 76774cb572..c70e82676e 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-char-class.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-char-class.js @@ -2,16 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-unicode-regexps --harmony-regexp-property +// Flags: --harmony-regexp-property assertThrows("/[\\p]/u"); assertThrows("/[\\p{garbage}]/u"); assertThrows("/[\\p{}]/u"); assertThrows("/[\\p{]/u"); assertThrows("/[\\p}]/u"); -assertThrows("/[\\p{Math}]/u"); -assertThrows("/[\\p{Bidi_M}]/u"); -assertThrows("/[\\p{Hex}]/u"); assertTrue(/^[\p{Lu}\p{Ll}]+$/u.test("ABCabc")); assertTrue(/^[\p{Lu}-\p{Ll}]+$/u.test("ABC-abc")); @@ -19,6 +16,9 @@ assertFalse(/^[\P{Lu}\p{Ll}]+$/u.test("ABCabc")); assertTrue(/^[\P{Lu}\p{Ll}]+$/u.test("abc")); assertTrue(/^[\P{Lu}]+$/u.test("abc123")); assertFalse(/^[\P{Lu}]+$/u.test("XYZ")); +assertTrue(/[\p{Math}]/u.test("+")); +assertTrue(/[\P{Bidi_M}]/u.test(" ")); +assertTrue(/[\p{Hex}]/u.test("A")); assertTrue(/^[^\P{Lu}]+$/u.test("XYZ")); assertFalse(/^[^\p{Lu}\p{Ll}]+$/u.test("abc")); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-disabled.js b/deps/v8/test/mjsunit/harmony/regexp-property-disabled.js index 7a3158c68b..f471ef4d9d 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-disabled.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-disabled.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-unicode-regexps --no-harmony-regexp-property +// Flags: --no-harmony-regexp-property function test(source, message) { try { diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-enumerated.js b/deps/v8/test/mjsunit/harmony/regexp-property-enumerated.js new file mode 100644 index 0000000000..dba8397e78 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regexp-property-enumerated.js @@ -0,0 +1,28 @@ +// Copyright 2016 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-property + +function t(re, s) { assertTrue(re.test(s)); } +function f(re, s) { assertFalse(re.test(s)); } + +t(/\p{Bidi_Class=L}+/u, "Is this the real life?"); +t(/\p{bc=Left_To_Right}+/u, "Is this just fantasy?"); +t(/\p{bc=AL}+/u, "السلام عليكم"); +t(/\p{bc=Arabic_Letter}+/u, "متشرف بمعرفتك"); + +t(/\p{Line_Break=Glue}/u, "\u00A0"); +t(/\p{lb=AL}/u, "~"); + +assertThrows("/\\p{Block=}/u"); +assertThrows("/\\p{=}/u"); +assertThrows("/\\p{=L}/u"); +assertThrows("/\\p{=Hiragana}/u"); +assertThrows("/\\p{Block=CJK=}/u"); + +assertThrows("/\\p{Age=V8_0}/u"); +assertThrows("/\\p{General_Category=Letter}/u"); +assertThrows("/\\p{gc=L}/u"); +assertThrows("/\\p{General_Category_Mask=Letter}/u"); +assertThrows("/\\p{gcm=L}/u"); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-exact-match.js b/deps/v8/test/mjsunit/harmony/regexp-property-exact-match.js index 4dfcc5f96e..0d1f70459e 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-exact-match.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-exact-match.js @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-regexp-property --harmony-unicode-regexps +// Flags: --harmony-regexp-property assertThrows("/\\p{In CJK}/u"); assertThrows("/\\p{InCJKUnifiedIdeographs}/u"); -assertDoesNotThrow("/\\p{InCJK}/u"); -assertDoesNotThrow("/\\p{InCJK_Unified_Ideographs}/u"); +assertThrows("/\\p{InCJK}/u"); +assertThrows("/\\p{InCJK_Unified_Ideographs}/u"); -assertDoesNotThrow("/\\p{InCyrillic_Sup}/u"); -assertDoesNotThrow("/\\p{InCyrillic_Supplement}/u"); -assertDoesNotThrow("/\\p{InCyrillic_Supplementary}/u"); +assertThrows("/\\p{InCyrillic_Sup}/u"); +assertThrows("/\\p{InCyrillic_Supplement}/u"); +assertThrows("/\\p{InCyrillic_Supplementary}/u"); assertThrows("/\\p{InCyrillicSupplementary}/u"); assertThrows("/\\p{InCyrillic_supplementary}/u"); -assertDoesNotThrow("/\\pC/u"); +assertDoesNotThrow("/\\p{C}/u"); assertDoesNotThrow("/\\p{Other}/u"); assertDoesNotThrow("/\\p{Cc}/u"); assertDoesNotThrow("/\\p{Control}/u"); @@ -25,9 +25,18 @@ assertDoesNotThrow("/\\p{Mark}/u"); assertDoesNotThrow("/\\p{Combining_Mark}/u"); assertThrows("/\\p{Combining Mark}/u"); -assertDoesNotThrow("/\\p{Copt}/u"); -assertDoesNotThrow("/\\p{Coptic}/u"); -assertDoesNotThrow("/\\p{Qaac}/u"); -assertDoesNotThrow("/\\p{Egyp}/u"); -assertDoesNotThrow("/\\p{Egyptian_Hieroglyphs}/u"); +assertDoesNotThrow("/\\p{Script=Copt}/u"); +assertThrows("/\\p{Coptic}/u"); +assertThrows("/\\p{Qaac}/u"); +assertThrows("/\\p{Egyp}/u"); +assertDoesNotThrow("/\\p{Script=Egyptian_Hieroglyphs}/u"); assertThrows("/\\p{EgyptianHieroglyphs}/u"); + +assertThrows("/\\p{BidiClass=LeftToRight}/u"); +assertThrows("/\\p{BidiC=LeftToRight}/u"); +assertThrows("/\\p{bidi_c=Left_To_Right}/u"); + +assertDoesNotThrow("/\\p{Block=CJK}/u"); +assertThrows("/\\p{Block = CJK}/u"); +assertThrows("/\\p{Block=cjk}/u"); +assertThrows("/\\p{BLK=CJK}/u"); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-general-category.js b/deps/v8/test/mjsunit/harmony/regexp-property-general-category.js index e2015ad72d..e4fb8b5232 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-general-category.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-general-category.js @@ -2,16 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-regexp-property --harmony-unicode-regexps +// Flags: --harmony-regexp-property assertThrows("/\\p/u"); assertThrows("/\\p{garbage}/u"); assertThrows("/\\p{}/u"); assertThrows("/\\p{/u"); assertThrows("/\\p}/u"); -assertThrows("/\p{Math}/u"); -assertThrows("/\p{Bidi_M}/u"); -assertThrows("/\p{Hex}/u"); +assertThrows("/\\pL/u"); +assertThrows("/\\P/u"); +assertThrows("/\\P{garbage}/u"); +assertThrows("/\\P{}/u"); +assertThrows("/\\P{/u"); +assertThrows("/\\P}/u"); +assertThrows("/\\PL/u"); assertTrue(/\p{Ll}/u.test("a")); assertFalse(/\P{Ll}/u.test("a")); @@ -26,10 +30,10 @@ assertTrue(/\p{Ll}/iu.test("a")); assertTrue(/\p{Ll}/iu.test("\u{118D4}")); assertTrue(/\p{Ll}/iu.test("A")); assertTrue(/\p{Ll}/iu.test("\u{118B4}")); -assertFalse(/\P{Ll}/iu.test("a")); -assertFalse(/\P{Ll}/iu.test("\u{118D4}")); -assertFalse(/\P{Ll}/iu.test("A")); -assertFalse(/\P{Ll}/iu.test("\u{118B4}")); +assertTrue(/\P{Ll}/iu.test("a")); +assertTrue(/\P{Ll}/iu.test("\u{118D4}")); +assertTrue(/\P{Ll}/iu.test("A")); +assertTrue(/\P{Ll}/iu.test("\u{118B4}")); assertTrue(/\p{Lu}/u.test("A")); assertFalse(/\P{Lu}/u.test("A")); @@ -44,22 +48,16 @@ assertTrue(/\p{Lu}/iu.test("a")); assertTrue(/\p{Lu}/iu.test("\u{118D4}")); assertTrue(/\p{Lu}/iu.test("A")); assertTrue(/\p{Lu}/iu.test("\u{118B4}")); -assertFalse(/\P{Lu}/iu.test("a")); -assertFalse(/\P{Lu}/iu.test("\u{118D4}")); -assertFalse(/\P{Lu}/iu.test("A")); -assertFalse(/\P{Lu}/iu.test("\u{118B4}")); +assertTrue(/\P{Lu}/iu.test("a")); +assertTrue(/\P{Lu}/iu.test("\u{118D4}")); +assertTrue(/\P{Lu}/iu.test("A")); +assertTrue(/\P{Lu}/iu.test("\u{118B4}")); assertTrue(/\p{Sm}/u.test("+")); assertFalse(/\P{Sm}/u.test("+")); assertTrue(/\p{Sm}/u.test("\u{1D6C1}")); assertFalse(/\P{Sm}/u.test("\u{1D6C1}")); -assertTrue(/\pL/u.test("a")); -assertFalse(/\PL/u.test("a")); -assertFalse(/\pL/u.test("1")); -assertTrue(/\PL/u.test("1")); -assertTrue(/\pL/u.test("\u1FAB")); -assertFalse(/\PL/u.test("\u1FAB")); assertFalse(/\p{L}/u.test("\uA6EE")); assertTrue(/\P{L}/u.test("\uA6EE")); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-lu-ui.js b/deps/v8/test/mjsunit/harmony/regexp-property-lu-ui.js new file mode 100644 index 0000000000..115e064005 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regexp-property-lu-ui.js @@ -0,0 +1,13 @@ +// Copyright 2016 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-property + +const regexp = /\P{Lu}/ui; +const regexpu = /[\0-@\[-\xBF\xD7\xDF-\xFF\u0101\u0103\u0105\u0107\u0109\u010B\u010D\u010F\u0111\u0113\u0115\u0117\u0119\u011B\u011D\u011F\u0121\u0123\u0125\u0127\u0129\u012B\u012D\u012F\u0131\u0133\u0135\u0137\u0138\u013A\u013C\u013E\u0140\u0142\u0144\u0146\u0148\u0149\u014B\u014D\u014F\u0151\u0153\u0155\u0157\u0159\u015B\u015D\u015F\u0161\u0163\u0165\u0167\u0169\u016B\u016D\u016F\u0171\u0173\u0175\u0177\u017A\u017C\u017E-\u0180\u0183\u0185\u0188\u018C\u018D\u0192\u0195\u0199-\u019B\u019E\u01A1\u01A3\u01A5\u01A8\u01AA\u01AB\u01AD\u01B0\u01B4\u01B6\u01B9-\u01BB\u01BD-\u01C3\u01C5\u01C6\u01C8\u01C9\u01CB\u01CC\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8\u01DA\u01DC\u01DD\u01DF\u01E1\u01E3\u01E5\u01E7\u01E9\u01EB\u01ED\u01EF\u01F0\u01F2\u01F3\u01F5\u01F9\u01FB\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B\u020D\u020F\u0211\u0213\u0215\u0217\u0219\u021B\u021D\u021F\u0221\u0223\u0225\u0227\u0229\u022B\u022D\u022F\u0231\u0233-\u0239\u023C\u023F\u0240\u0242\u0247\u0249\u024B\u024D\u024F-\u036F\u0371\u0373-\u0375\u0377-\u037E\u0380-\u0385\u0387\u038B\u038D\u0390\u03A2\u03AC-\u03CE\u03D0\u03D1\u03D5-\u03D7\u03D9\u03DB\u03DD\u03DF\u03E1\u03E3\u03E5\u03E7\u03E9\u03EB\u03ED\u03EF-\u03F3\u03F5\u03F6\u03F8\u03FB\u03FC\u0430-\u045F\u0461\u0463\u0465\u0467\u0469\u046B\u046D\u046F\u0471\u0473\u0475\u0477\u0479\u047B\u047D\u047F\u0481-\u0489\u048B\u048D\u048F\u0491\u0493\u0495\u0497\u0499\u049B\u049D\u049F\u04A1\u04A3\u04A5\u04A7\u04A9\u04AB\u04AD\u04AF\u04B1\u04B3\u04B5\u04B7\u04B9\u04BB\u04BD\u04BF\u04C2\u04C4\u04C6\u04C8\u04CA\u04CC\u04CE\u04CF\u04D1\u04D3\u04D5\u04D7\u04D9\u04DB\u04DD\u04DF\u04E1\u04E3\u04E5\u04E7\u04E9\u04EB\u04ED\u04EF\u04F1\u04F3\u04F5\u04F7\u04F9\u04FB\u04FD\u04FF\u0501\u0503\u0505\u0507\u0509\u050B\u050D\u050F\u0511\u0513\u0515\u0517\u0519\u051B\u051D\u051F\u0521\u0523\u0525\u0527\u0529\u052B\u052D\u052F\u0530\u0557-\u109F\u10C6\u10C8-\u10CC\u10CE-\u139F\u13F6-\u1DFF\u1E01\u1E03\u1E05\u1E07\u1E09\u1E0B\u1E0D\u1E0F\u1E11\u1E13\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E1F\u1E21\u1E23\u1E25\u1E27\u1E29\u1E2B\u1E2D\u1E2F\u1E31\u1E33\u1E35\u1E37\u1E39\u1E3B\u1E3D\u1E3F\u1E41\u1E43\u1E45\u1E47\u1E49\u1E4B\u1E4D\u1E4F\u1E51\u1E53\u1E55\u1E57\u1E59\u1E5B\u1E5D\u1E5F\u1E61\u1E63\u1E65\u1E67\u1E69\u1E6B\u1E6D\u1E6F\u1E71\u1E73\u1E75\u1E77\u1E79\u1E7B\u1E7D\u1E7F\u1E81\u1E83\u1E85\u1E87\u1E89\u1E8B\u1E8D\u1E8F\u1E91\u1E93\u1E95-\u1E9D\u1E9F\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB\u1EED\u1EEF\u1EF1\u1EF3\u1EF5\u1EF7\u1EF9\u1EFB\u1EFD\u1EFF-\u1F07\u1F10-\u1F17\u1F1E-\u1F27\u1F30-\u1F37\u1F40-\u1F47\u1F4E-\u1F58\u1F5A\u1F5C\u1F5E\u1F60-\u1F67\u1F70-\u1FB7\u1FBC-\u1FC7\u1FCC-\u1FD7\u1FDC-\u1FE7\u1FED-\u1FF7\u1FFC-\u2101\u2103-\u2106\u2108-\u210A\u210E\u210F\u2113\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u212F\u2134-\u213D\u2140-\u2144\u2146-\u2182\u2184-\u2BFF\u2C2F-\u2C5F\u2C61\u2C65\u2C66\u2C68\u2C6A\u2C6C\u2C71\u2C73\u2C74\u2C76-\u2C7D\u2C81\u2C83\u2C85\u2C87\u2C89\u2C8B\u2C8D\u2C8F\u2C91\u2C93\u2C95\u2C97\u2C99\u2C9B\u2C9D\u2C9F\u2CA1\u2CA3\u2CA5\u2CA7\u2CA9\u2CAB\u2CAD\u2CAF\u2CB1\u2CB3\u2CB5\u2CB7\u2CB9\u2CBB\u2CBD\u2CBF\u2CC1\u2CC3\u2CC5\u2CC7\u2CC9\u2CCB\u2CCD\u2CCF\u2CD1\u2CD3\u2CD5\u2CD7\u2CD9\u2CDB\u2CDD\u2CDF\u2CE1\u2CE3-\u2CEA\u2CEC\u2CEE-\u2CF1\u2CF3-\uA63F\uA641\uA643\uA645\uA647\uA649\uA64B\uA64D\uA64F\uA651\uA653\uA655\uA657\uA659\uA65B\uA65D\uA65F\uA661\uA663\uA665\uA667\uA669\uA66B\uA66D-\uA67F\uA681\uA683\uA685\uA687\uA689\uA68B\uA68D\uA68F\uA691\uA693\uA695\uA697\uA699\uA69B-\uA721\uA723\uA725\uA727\uA729\uA72B\uA72D\uA72F-\uA731\uA733\uA735\uA737\uA739\uA73B\uA73D\uA73F\uA741\uA743\uA745\uA747\uA749\uA74B\uA74D\uA74F\uA751\uA753\uA755\uA757\uA759\uA75B\uA75D\uA75F\uA761\uA763\uA765\uA767\uA769\uA76B\uA76D\uA76F-\uA778\uA77A\uA77C\uA77F\uA781\uA783\uA785\uA787-\uA78A\uA78C\uA78E\uA78F\uA791\uA793-\uA795\uA797\uA799\uA79B\uA79D\uA79F\uA7A1\uA7A3\uA7A5\uA7A7\uA7A9\uA7AE\uA7AF\uA7B5\uA7B7-\uFF20\uFF3B-\u{103FF}\u{10428}-\u{10C7F}\u{10CB3}-\u{1189F}\u{118C0}-\u{1D3FF}\u{1D41A}-\u{1D433}\u{1D44E}-\u{1D467}\u{1D482}-\u{1D49B}\u{1D49D}\u{1D4A0}\u{1D4A1}\u{1D4A3}\u{1D4A4}\u{1D4A7}\u{1D4A8}\u{1D4AD}\u{1D4B6}-\u{1D4CF}\u{1D4EA}-\u{1D503}\u{1D506}\u{1D50B}\u{1D50C}\u{1D515}\u{1D51D}-\u{1D537}\u{1D53A}\u{1D53F}\u{1D545}\u{1D547}-\u{1D549}\u{1D551}-\u{1D56B}\u{1D586}-\u{1D59F}\u{1D5BA}-\u{1D5D3}\u{1D5EE}-\u{1D607}\u{1D622}-\u{1D63B}\u{1D656}-\u{1D66F}\u{1D68A}-\u{1D6A7}\u{1D6C1}-\u{1D6E1}\u{1D6FB}-\u{1D71B}\u{1D735}-\u{1D755}\u{1D76F}-\u{1D78F}\u{1D7A9}-\u{1D7C9}\u{1D7CB}-\u{10FFFF}]/ui; + +for (let codePoint = 0; codePoint <= 0x10FFFF; codePoint++) { + const string = String.fromCodePoint(codePoint); + assertEquals(regexp.test(string), regexpu.test(string)); +} diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-scripts.js b/deps/v8/test/mjsunit/harmony/regexp-property-scripts.js index 19b50ee7db..565a59ab0a 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-property-scripts.js +++ b/deps/v8/test/mjsunit/harmony/regexp-property-scripts.js @@ -2,38 +2,38 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-regexp-property --harmony-unicode-regexps +// Flags: --harmony-regexp-property function t(re, s) { assertTrue(re.test(s)); } function f(re, s) { assertFalse(re.test(s)); } -t(/\p{Common}+/u, "."); -f(/\p{Common}+/u, "supercalifragilisticexpialidocious"); +t(/\p{Script=Common}+/u, "."); +f(/\p{Script=Common}+/u, "supercalifragilisticexpialidocious"); -t(/\p{Han}+/u, "话说天下大势,分久必合,合久必分"); -t(/\p{Hani}+/u, "吾庄后有一桃园,花开正盛"); -f(/\p{Han}+/u, "おはようございます"); -f(/\p{Hani}+/u, "Something is rotten in the state of Denmark"); +t(/\p{Script=Han}+/u, "话说天下大势,分久必合,合久必分"); +t(/\p{Script=Hani}+/u, "吾庄后有一桃园,花开正盛"); +f(/\p{Script=Han}+/u, "おはようございます"); +f(/\p{Script=Hani}+/u, "Something is rotten in the state of Denmark"); -t(/\p{Latin}+/u, "Wie froh bin ich, daß ich weg bin!"); -t(/\p{Latn}+/u, +t(/\p{Script=Latin}+/u, "Wie froh bin ich, daß ich weg bin!"); +t(/\p{Script=Latn}+/u, "It was a bright day in April, and the clocks were striking thirteen"); -f(/\p{Latin}+/u, "奔腾千里荡尘埃,渡水登山紫雾开"); -f(/\p{Latn}+/u, "いただきます"); +f(/\p{Script=Latin}+/u, "奔腾千里荡尘埃,渡水登山紫雾开"); +f(/\p{Script=Latn}+/u, "いただきます"); -t(/\p{Hiragana}/u, "いただきます"); -t(/\p{Hira}/u, "ありがとうございました"); -f(/\p{Hiragana}/u, +t(/\p{sc=Hiragana}/u, "いただきます"); +t(/\p{sc=Hira}/u, "ありがとうございました"); +f(/\p{sc=Hiragana}/u, "Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte"); -f(/\p{Hira}/u, "Call me Ishmael"); +f(/\p{sc=Hira}/u, "Call me Ishmael"); -t(/\p{Phoenician}/u, "\u{10900}\u{1091a}"); -t(/\p{Phnx}/u, "\u{1091f}\u{10916}"); -f(/\p{Phoenician}/u, "Arthur est un perroquet"); -f(/\p{Phnx}/u, "设心狠毒非良士,操卓原来一路人"); +t(/\p{sc=Phoenician}/u, "\u{10900}\u{1091a}"); +t(/\p{sc=Phnx}/u, "\u{1091f}\u{10916}"); +f(/\p{sc=Phoenician}/u, "Arthur est un perroquet"); +f(/\p{sc=Phnx}/u, "设心狠毒非良士,操卓原来一路人"); -t(/\p{Grek}/u, "ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ"); -t(/\p{Greek}/u, "μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος"); -f(/\p{Greek}/u, "高贤未服英雄志,屈节偏生杰士疑"); -f(/\p{Greek}/u, +t(/\p{sc=Grek}/u, "ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ"); +t(/\p{sc=Greek}/u, "μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος"); +f(/\p{sc=Greek}/u, "高贤未服英雄志,屈节偏生杰士疑"); +f(/\p{sc=Greek}/u, "Mr. Jones, of the Manor Farm, had locked the hen-houses for the night"); diff --git a/deps/v8/test/mjsunit/harmony/regexp-property-special.js b/deps/v8/test/mjsunit/harmony/regexp-property-special.js new file mode 100644 index 0000000000..204b77fb23 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regexp-property-special.js @@ -0,0 +1,51 @@ +// Copyright 2016 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-property + +function t(re, s) { assertTrue(re.test(s)); } +function f(re, s) { assertFalse(re.test(s)); } + +t(/\p{ASCII}+/u, "abc123"); +f(/\p{ASCII}+/u, "ⓐⓑⓒ①②③"); +f(/\p{ASCII}+/u, "🄰🄱🄲①②③"); +f(/\P{ASCII}+/u, "abcd123"); +t(/\P{ASCII}+/u, "ⓐⓑⓒ①②③"); +t(/\P{ASCII}+/u, "🄰🄱🄲①②③"); + +f(/[^\p{ASCII}]+/u, "abc123"); +f(/[\p{ASCII}]+/u, "ⓐⓑⓒ①②③"); +f(/[\p{ASCII}]+/u, "🄰🄱🄲①②③"); +t(/[^\P{ASCII}]+/u, "abcd123"); +t(/[\P{ASCII}]+/u, "ⓐⓑⓒ①②③"); +f(/[^\P{ASCII}]+/u, "🄰🄱🄲①②③"); + +t(/\p{Any}+/u, "🄰🄱🄲①②③"); + +assertEquals(["\ud800"], /\p{Any}/u.exec("\ud800\ud801")); +assertEquals(["\udc00"], /\p{Any}/u.exec("\udc00\udc01")); +assertEquals(["\ud800\udc01"], /\p{Any}/u.exec("\ud800\udc01")); +assertEquals(["\udc01"], /\p{Any}/u.exec("\udc01")); + +f(/\P{Any}+/u, "123"); +f(/[\P{Any}]+/u, "123"); +t(/[\P{Any}\d]+/u, "123"); +t(/[^\P{Any}]+/u, "123"); + +t(/\p{Assigned}+/u, "123"); +t(/\p{Assigned}+/u, "🄰🄱🄲"); +f(/\p{Assigned}+/u, "\ufdd0"); +f(/\p{Assigned}+/u, "\u{fffff}"); + +f(/\P{Assigned}+/u, "123"); +f(/\P{Assigned}+/u, "🄰🄱🄲"); +t(/\P{Assigned}+/u, "\ufdd0"); +t(/\P{Assigned}+/u, "\u{fffff}"); +f(/\P{Assigned}/u, ""); + +t(/[^\P{Assigned}]+/u, "123"); +f(/[\P{Assigned}]+/u, "🄰🄱🄲"); +f(/[^\P{Assigned}]+/u, "\ufdd0"); +t(/[\P{Assigned}]+/u, "\u{fffff}"); +f(/[\P{Assigned}]/u, ""); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-4904.js b/deps/v8/test/mjsunit/harmony/regress/regress-4904.js new file mode 100644 index 0000000000..a57d246b6f --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-4904.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. + +// Flags: --harmony-do-expressions + +(function testCatchScopeInDoExpression() { + var f = (s = 17, y = do { try { throw 25; } catch(e) { s += e; }; }) => s; + var result = f(); + assertEquals(result, 42); +})(); + +(function testCatchScopeInDoExpression() { + var f = (s = 17, y = do { let t; try { throw 25; } catch(e) { s += e; }; }) => s; + var result = f(); + assertEquals(result, 42); +})(); + +(function testCatchScopeInDoExpression() { + let t1; + var f = (s = 17, y = do { let t2; try { throw 25; } catch(e) { s += e; }; }) => s; + var result = f(); + assertEquals(result, 42); +})(); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-618603.js b/deps/v8/test/mjsunit/harmony/regress/regress-618603.js new file mode 100644 index 0000000000..8f45cd88f0 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-618603.js @@ -0,0 +1,14 @@ +// Copyright 2016 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-async-await + +try { +} catch(e) {; } +function __f_7(expected, run) { + var __v_10 = run(); +}; +__f_7("[1,2,3]", () => (function() { + return (async () => {[...await arguments] })(); + })()); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-624300.js b/deps/v8/test/mjsunit/harmony/regress/regress-624300.js new file mode 100644 index 0000000000..f96fbbb5aa --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-624300.js @@ -0,0 +1,13 @@ +// Copyright 2016 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-async-await + +(function f() { + try { + f(); + } catch (e) { + (async() => await 1).length; + } +})(); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621111.js b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621111.js new file mode 100644 index 0000000000..58a0d5ce3f --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621111.js @@ -0,0 +1,6 @@ +// Copyright 2016 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. + +(y = 1[1, [...[]]]) => 1; // will core dump, if not fixed +(y = 1[1, [...[]]]) => {}; // will core dump, if not fixed diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621496.js b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621496.js new file mode 100644 index 0000000000..4db7a95039 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/regress/regress-crbug-621496.js @@ -0,0 +1,7 @@ +// Copyright 2016 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 testIllegalSpreadAsSingleArrowParameter() { + assertThrows("(...[42]) => 42)", SyntaxError) // will core dump, if not fixed +})(); diff --git a/deps/v8/test/mjsunit/harmony/regress/regress-observe-empty-double-array.js b/deps/v8/test/mjsunit/harmony/regress/regress-observe-empty-double-array.js deleted file mode 100644 index 1460889f45..0000000000 --- a/deps/v8/test/mjsunit/harmony/regress/regress-observe-empty-double-array.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2012 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: --harmony-object-observe -// Flags: --allow-natives-syntax -// -// Test passes if it does not crash. - -arr = [1.1]; -Object.observe(arr, function(){}); -arr.length = 0; -// TODO(observe): we currently disallow fast elements for observed object. -// assertTrue(%HasFastDoubleElements(arr)); -// Should not crash -arr.push(1.1); diff --git a/deps/v8/test/mjsunit/harmony/sharedarraybuffer.js b/deps/v8/test/mjsunit/harmony/sharedarraybuffer.js index 7bd4e5b121..7c34ed3009 100644 --- a/deps/v8/test/mjsunit/harmony/sharedarraybuffer.js +++ b/deps/v8/test/mjsunit/harmony/sharedarraybuffer.js @@ -572,3 +572,21 @@ for(i = 0; i < typedArrayConstructors.length; i++) { assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), TypeError); } + +// byteLength from prototype can be overwritten +var s = new SharedArrayBuffer(10); +assertEquals(10, s.byteLength); +Object.defineProperty(s, 'byteLength', {value: 42}); +assertEquals(42, s.byteLength); + +// byteLength on incompatible type (shared vs. regular ArrayBuffer) +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength'); +s = new SharedArrayBuffer(10); +Object.defineProperty(s, 'byteLength', desc); +assertThrows(function() {s.byteLength}, TypeError); + +desc = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, + 'byteLength'); +var a = new ArrayBuffer(10); +Object.defineProperty(a, 'byteLength', desc); +assertThrows(function() {a.byteLength}, TypeError); diff --git a/deps/v8/test/mjsunit/harmony/simd.js b/deps/v8/test/mjsunit/harmony/simd.js index 1868050e50..a3d46159c1 100644 --- a/deps/v8/test/mjsunit/harmony/simd.js +++ b/deps/v8/test/mjsunit/harmony/simd.js @@ -622,7 +622,9 @@ TestSIMDObject() function TestStringify(expected, input) { assertEquals(expected, JSON.stringify(input)); - assertEquals(expected, JSON.stringify(input, null, 0)); + assertEquals(expected, JSON.stringify(input, (key, value) => value)); + assertEquals(JSON.stringify(input, null, "="), + JSON.stringify(input, (key, value) => value, "=")); } TestStringify(undefined, SIMD.Float32x4(1, 2, 3, 4)); diff --git a/deps/v8/test/mjsunit/harmony/sloppy-legacy-duplicate-generators.js b/deps/v8/test/mjsunit/harmony/sloppy-legacy-duplicate-generators.js new file mode 100644 index 0000000000..1fde47507e --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/sloppy-legacy-duplicate-generators.js @@ -0,0 +1,60 @@ +// Copyright 2016 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: --no-harmony-restrictive-generators + +// In legacy mode, generators get sloppy-mode block-scoped function hoisting + +// Hoisting to the global scope + +{ + function* foo() {} + assertEquals('function', typeof foo); +} +//assertEquals('function', typeof foo); + +// Hoisting within a function scope +(function() { + { function* bar() {} } + assertEquals('function', typeof bar); +})(); + +// Lexical shadowing allowed; hoisting happens +(function() { + function* x() { yield 1; } + { function* x() { yield 2 } } + assertEquals(2, x().next().value); +})(); + +// Duplicates allowed +(function() { + function* y() { yield 1; } + function* y() { yield 2 } + assertEquals(2, y().next().value); +})(); + +// Functions and generators may duplicate each other +(function() { + function* z() { yield 1; } + function z() { return 2 } + assertEquals(2, z()); + + function a() { return 1; } + function* a() { yield 2 } + assertEquals(2, a().next().value); +})(); + +// In strict mode, none of this happens + +(function() { + 'use strict'; + + { function* bar() {} } + assertEquals('undefined', typeof bar); + + // Lexical shadowing allowed; hoisting happens + function* x() { yield 1; } + { function* x() { yield 2 } } + assertEquals(1, x().next().value); +})(); diff --git a/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-async.js b/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-async.js new file mode 100644 index 0000000000..97411c0c83 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-async.js @@ -0,0 +1,30 @@ +// Copyright 2016 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-async-await + +// Async functions don't get sloppy-mode block-scoped function hoisting + +// No hoisting to the global scope + +{ + async function foo() {} + assertEquals('function', typeof foo); +} +assertEquals('undefined', typeof foo); + +// No hoisting within a function scope +(function() { + { async function bar() {} } + assertEquals('undefined', typeof bar); +})(); + +// Lexical shadowing allowed, no hoisting +(function() { + var y; + async function x() { y = 1; } + { async function x() { y = 2; } } + x(); + assertEquals(1, y); +})(); diff --git a/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-generators.js b/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-generators.js new file mode 100644 index 0000000000..de2e461f95 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/sloppy-no-duplicate-generators.js @@ -0,0 +1,28 @@ +// Copyright 2016 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-restrictive-generators + +// Generators don't get sloppy-mode block-scoped function hoisting + +// No hoisting to the global scope + +{ + function* foo() {} + assertEquals('function', typeof foo); +} +assertEquals('undefined', typeof foo); + +// No hoisting within a function scope +(function() { + { function* bar() {} } + assertEquals('undefined', typeof bar); +})(); + +// Lexical shadowing allowed, no hoisting +(function() { + function* x() { yield 1; } + { function* x() { yield 2 } } + assertEquals(1, x().next().value); +})(); diff --git a/deps/v8/test/mjsunit/harmony/to-name.js b/deps/v8/test/mjsunit/harmony/to-name.js index 6d5d64e5e4..0a2c043a2f 100644 --- a/deps/v8/test/mjsunit/harmony/to-name.js +++ b/deps/v8/test/mjsunit/harmony/to-name.js @@ -5,50 +5,37 @@ // Flags: --allow-natives-syntax assertEquals("1", %ToName(1)); -assertEquals("1", %_ToName(1)); assertEquals("0.5", %ToName(.5)); -assertEquals("0.5", %_ToName(.5)); assertEquals("null", %ToName(null)); -assertEquals("null", %_ToName(null)); assertEquals("true", %ToName(true)); -assertEquals("true", %_ToName(true)); assertEquals("false", %ToName(false)); -assertEquals("false", %_ToName(false)); assertEquals("undefined", %ToName(undefined)); -assertEquals("undefined", %_ToName(undefined)); assertEquals("random text", %ToName("random text")); -assertEquals("random text", %_ToName("random text")); assertEquals(Symbol.toPrimitive, %ToName(Symbol.toPrimitive)); -assertEquals(Symbol.toPrimitive, %_ToName(Symbol.toPrimitive)); var a = { toString: function() { return "xyz" }}; assertEquals("xyz", %ToName(a)); -assertEquals("xyz", %_ToName(a)); var b = { valueOf: function() { return 42 }}; assertEquals("[object Object]", %ToName(b)); -assertEquals("[object Object]", %_ToName(b)); var c = { toString: function() { return "x"}, valueOf: function() { return 123 } }; assertEquals("x", %ToName(c)); -assertEquals("x", %_ToName(c)); var d = { [Symbol.toPrimitive]: function(hint) { return hint } }; assertEquals("string", %ToName(d)); -assertEquals("string", %_ToName(d)); var e = new Date(0); assertEquals(e.toString(), %ToName(e)); -assertEquals(e.toString(), %_ToName(e)); diff --git a/deps/v8/test/mjsunit/harmony/to-primitive.js b/deps/v8/test/mjsunit/harmony/to-primitive.js index 09280bf1ee..8decb04657 100644 --- a/deps/v8/test/mjsunit/harmony/to-primitive.js +++ b/deps/v8/test/mjsunit/harmony/to-primitive.js @@ -6,75 +6,35 @@ assertEquals(1, %ToPrimitive(1)); assertEquals(1, %ToPrimitive_Number(1)); -assertEquals(1, %ToPrimitive_String(1)); -assertEquals(1, %_ToPrimitive(1)); -assertEquals(1, %_ToPrimitive_Number(1)); -assertEquals(1, %_ToPrimitive_String(1)); assertEquals(.5, %ToPrimitive(.5)); assertEquals(.5, %ToPrimitive_Number(.5)); -assertEquals(.5, %ToPrimitive_String(.5)); -assertEquals(.5, %_ToPrimitive(.5)); -assertEquals(.5, %_ToPrimitive_Number(.5)); -assertEquals(.5, %_ToPrimitive_String(.5)); assertEquals(null, %ToPrimitive(null)); assertEquals(null, %ToPrimitive_Number(null)); -assertEquals(null, %ToPrimitive_String(null)); -assertEquals(null, %_ToPrimitive(null)); -assertEquals(null, %_ToPrimitive_Number(null)); -assertEquals(null, %_ToPrimitive_String(null)); assertEquals(true, %ToPrimitive(true)); assertEquals(true, %ToPrimitive_Number(true)); -assertEquals(true, %ToPrimitive_String(true)); -assertEquals(true, %_ToPrimitive(true)); -assertEquals(true, %_ToPrimitive_Number(true)); -assertEquals(true, %_ToPrimitive_String(true)); assertEquals(false, %ToPrimitive(false)); assertEquals(false, %ToPrimitive_Number(false)); -assertEquals(false, %ToPrimitive_String(false)); -assertEquals(false, %_ToPrimitive(false)); -assertEquals(false, %_ToPrimitive_Number(false)); -assertEquals(false, %_ToPrimitive_String(false)); assertEquals(undefined, %ToPrimitive(undefined)); assertEquals(undefined, %ToPrimitive_Number(undefined)); -assertEquals(undefined, %ToPrimitive_String(undefined)); -assertEquals(undefined, %_ToPrimitive(undefined)); -assertEquals(undefined, %_ToPrimitive_Number(undefined)); -assertEquals(undefined, %_ToPrimitive_String(undefined)); assertEquals("random text", %ToPrimitive("random text")); assertEquals("random text", %ToPrimitive_Number("random text")); -assertEquals("random text", %ToPrimitive_String("random text")); -assertEquals("random text", %_ToPrimitive("random text")); -assertEquals("random text", %_ToPrimitive_Number("random text")); -assertEquals("random text", %_ToPrimitive_String("random text")); assertEquals(Symbol.toPrimitive, %ToPrimitive(Symbol.toPrimitive)); assertEquals(Symbol.toPrimitive, %ToPrimitive_Number(Symbol.toPrimitive)); -assertEquals(Symbol.toPrimitive, %ToPrimitive_String(Symbol.toPrimitive)); -assertEquals(Symbol.toPrimitive, %_ToPrimitive(Symbol.toPrimitive)); -assertEquals(Symbol.toPrimitive, %_ToPrimitive_Number(Symbol.toPrimitive)); -assertEquals(Symbol.toPrimitive, %_ToPrimitive_String(Symbol.toPrimitive)); var a = { toString: function() { return "xyz" }}; assertEquals("xyz", %ToPrimitive(a)); assertEquals("xyz", %ToPrimitive_Number(a)); -assertEquals("xyz", %ToPrimitive_String(a)); -assertEquals("xyz", %_ToPrimitive(a)); -assertEquals("xyz", %_ToPrimitive_Number(a)); -assertEquals("xyz", %_ToPrimitive_String(a)); var b = { valueOf: function() { return 42 }}; assertEquals(42, %ToPrimitive(b)); assertEquals(42, %ToPrimitive_Number(b)); -assertEquals("[object Object]", %ToPrimitive_String(b)); -assertEquals(42, %_ToPrimitive(b)); -assertEquals(42, %_ToPrimitive_Number(b)); -assertEquals("[object Object]", %_ToPrimitive_String(b)); var c = { toString: function() { return "x"}, @@ -82,25 +42,13 @@ var c = { }; assertEquals(123, %ToPrimitive(c)); assertEquals(123, %ToPrimitive_Number(c)); -assertEquals("x", %ToPrimitive_String(c)); -assertEquals(123, %_ToPrimitive(c)); -assertEquals(123, %_ToPrimitive_Number(c)); -assertEquals("x", %_ToPrimitive_String(c)); var d = { [Symbol.toPrimitive]: function(hint) { return hint } }; assertEquals("default", %ToPrimitive(d)); assertEquals("number", %ToPrimitive_Number(d)); -assertEquals("string", %ToPrimitive_String(d)); -assertEquals("default", %_ToPrimitive(d)); -assertEquals("number", %_ToPrimitive_Number(d)); -assertEquals("string", %_ToPrimitive_String(d)); var e = new Date(0); assertEquals(e.toString(), %ToPrimitive(e)); assertEquals(0, %ToPrimitive_Number(e)); -assertEquals(e.toString(), %ToPrimitive_String(e)); -assertEquals(e.toString(), %_ToPrimitive(e)); -assertEquals(0, %_ToPrimitive_Number(e)); -assertEquals(e.toString(), %_ToPrimitive_String(e)); diff --git a/deps/v8/test/mjsunit/harmony/to-string.js b/deps/v8/test/mjsunit/harmony/to-string.js index 103ba89d1d..dfe36c2dd9 100644 --- a/deps/v8/test/mjsunit/harmony/to-string.js +++ b/deps/v8/test/mjsunit/harmony/to-string.js @@ -50,5 +50,5 @@ assertEquals("string", %ToString(d)); assertEquals("string", %_ToString(d)); var e = new Date(0); -assertEquals(e.toString(), %ToName(e)); -assertEquals(e.toString(), %_ToName(e)); +assertEquals(e.toString(), %ToString(e)); +assertEquals(e.toString(), %_ToString(e)); diff --git a/deps/v8/test/mjsunit/harmony/trailing-commas-length.js b/deps/v8/test/mjsunit/harmony/trailing-commas-length.js new file mode 100644 index 0000000000..9d5e59c16b --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/trailing-commas-length.js @@ -0,0 +1,31 @@ +// Copyright 2016 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-trailing-commas + +function f1(a,) {} +function f2(a,b,) {} +function f3(a,b,c,) {} +assertEquals(1, f1.length); +assertEquals(2, f2.length); +assertEquals(3, f3.length); + +function* g1(a,) {} +function* g2(a,b,) {} +function* g3(a,b,c,) {} +assertEquals(1, g1.length); +assertEquals(2, g2.length); +assertEquals(3, g3.length); + +assertEquals(1, (function(a,) {}).length); +assertEquals(2, (function(a,b,) {}).length); +assertEquals(3, (function(a,b,c,) {}).length); + +assertEquals(1, (function*(a,) {}).length); +assertEquals(2, (function*(a,b,) {}).length); +assertEquals(3, (function*(a,b,c,) {}).length); + +assertEquals(1, ((a,) => {}).length); +assertEquals(2, ((a,b,) => {}).length); +assertEquals(3, ((a,b,c,) => {}).length); diff --git a/deps/v8/test/mjsunit/holy-double-no-arg-array.js b/deps/v8/test/mjsunit/holy-double-no-arg-array.js new file mode 100644 index 0000000000..73e2ddc6ce --- /dev/null +++ b/deps/v8/test/mjsunit/holy-double-no-arg-array.js @@ -0,0 +1,14 @@ +// Copyright 2016 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() { + function f() { + return new Array(); + } + var a = f(); + a[0] = 0.5; + var b = f(); + b[2] = 0.5; + assertEquals(undefined, b[0]); +})(); diff --git a/deps/v8/test/mjsunit/ignition/debug-break-mixed-stack.js b/deps/v8/test/mjsunit/ignition/debug-break-mixed-stack.js new file mode 100644 index 0000000000..878a918d5c --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/debug-break-mixed-stack.js @@ -0,0 +1,52 @@ +// Copyright 2016 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 + +Debug = debug.Debug + +var exception = null; +var frame_depth = 10; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertEquals(frame_depth, exec_state.frameCount()); + assertTrue(/\/\/ Break$/.test(exec_state.frame(0).sourceLineText())); + assertEquals(12 - frame_depth, exec_state.frame(0).evaluate("x").value()); + frame_depth--; + } catch (e) { + exception = e; + print(e + e.stack); + } +} + +function ChooseCode(f, x) { + if (x == 1) { + Debug.setBreakPoint(factorial, 4); + } + switch (x % 2) { + case 0: + %BaselineFunctionOnNextCall(f); + break; + case 1: + %InterpretFunctionOnNextCall(f); + break; + } +} + +function factorial(x) { + ChooseCode(factorial, x); + if (x == 1) return 1; + var factor = factorial(x - 1); + return x * factor; // Break +} + +Debug.setListener(listener); + +assertEquals(3628800, factorial(10)); + +Debug.setListener(null); +assertNull(exception); +assertEquals(1, frame_depth); diff --git a/deps/v8/test/mjsunit/ignition/debug-step-mixed-stack.js b/deps/v8/test/mjsunit/ignition/debug-step-mixed-stack.js new file mode 100644 index 0000000000..6566431175 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/debug-step-mixed-stack.js @@ -0,0 +1,53 @@ +// Copyright 2016 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 + +Debug = debug.Debug + +var exception = null; +var frame_depth = 11; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertEquals(frame_depth, exec_state.frameCount()); + assertTrue(/\/\/ Break$/.test(exec_state.frame(0).sourceLineText())); + assertEquals(12 - frame_depth, exec_state.frame(0).evaluate("x").value()); + if (frame_depth > 2) exec_state.prepareStep(Debug.StepAction.StepOut); + frame_depth--; + } catch (e) { + exception = e; + print(e + e.stack); + } +} + +function ChooseCode(f, x) { + switch (x % 2) { + case 0: + %BaselineFunctionOnNextCall(f); + break; + case 1: + %InterpretFunctionOnNextCall(f); + break; + } +} + +function factorial(x) { + ChooseCode(factorial, x); + if (x == 1) { + debugger; // Break + return 1; + } + var factor = factorial(x - 1); + return x * factor; // Break +} + +Debug.setListener(listener); + +assertEquals(3628800, factorial(10)); + +Debug.setListener(null); +assertNull(exception); +assertEquals(1, frame_depth); diff --git a/deps/v8/test/mjsunit/ignition/elided-instruction-no-ignition.js b/deps/v8/test/mjsunit/ignition/elided-instruction-no-ignition.js deleted file mode 100644 index d31150b6d3..0000000000 --- a/deps/v8/test/mjsunit/ignition/elided-instruction-no-ignition.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 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 - -Debug = debug.Debug - -var exception = null; -var break_count = 0; - -function listener(event, exec_state, event_data, data) { - if (event != Debug.DebugEvent.Break) return; - try { - print(event_data.sourceLineText()); - var column = event_data.sourceColumn(); - assertTrue(event_data.sourceLineText().indexOf( - `Break ${break_count++}. ${column}.`) > 0); - exec_state.prepareStep(Debug.StepAction.StepIn); - } catch (e) { - print(e + e.stack); - exception = e; - } -}; - -function f() { - var a = 1; // Break 2. 10. - return a; // Break 3. 2. -} // Break 4. 0. - -Debug.setListener(listener); -debugger; // Break 0. 0. -f(); // Break 1. 0. -Debug.setListener(null); // Break 5. 0. - -assertNull(exception); -assertEquals(6, break_count); diff --git a/deps/v8/test/mjsunit/ignition/elided-instruction.js b/deps/v8/test/mjsunit/ignition/elided-instruction.js index 807974bbc1..d31150b6d3 100644 --- a/deps/v8/test/mjsunit/ignition/elided-instruction.js +++ b/deps/v8/test/mjsunit/ignition/elided-instruction.js @@ -25,17 +25,13 @@ function listener(event, exec_state, event_data, data) { function f() { var a = 1; // Break 2. 10. - // This return statement emits no bytecode instruction for the evaluation of - // the to-be-returned expression. Therefore we cannot set a break location - // before the statement and a second break location immediately before - // returning to the caller. - return a; -} // Break 3. 0. + return a; // Break 3. 2. +} // Break 4. 0. Debug.setListener(listener); debugger; // Break 0. 0. f(); // Break 1. 0. -Debug.setListener(null); // Break 4. 0. +Debug.setListener(null); // Break 5. 0. assertNull(exception); -assertEquals(5, break_count); +assertEquals(6, break_count); diff --git a/deps/v8/test/mjsunit/ignition/ignition-statistics-extension.js b/deps/v8/test/mjsunit/ignition/ignition-statistics-extension.js new file mode 100644 index 0000000000..43d05c94a3 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/ignition-statistics-extension.js @@ -0,0 +1,62 @@ +// Copyright 2016 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: --ignition --trace-ignition-dispatches + +assertEquals(typeof getIgnitionDispatchCounters, "function"); + +var old_dispatch_counters = getIgnitionDispatchCounters(); + +// Check that old_dispatch_counters is a non-empty object of objects, such that +// the value of each property in the inner objects is a number. + +assertEquals(typeof old_dispatch_counters, "object"); +assertTrue(Object.getOwnPropertyNames(old_dispatch_counters).length > 0); +for (var source_bytecode in old_dispatch_counters) { + var counters_row = old_dispatch_counters[source_bytecode]; + assertEquals(typeof counters_row, "object"); + for (var counter in counters_row) { + assertEquals(typeof counters_row[counter], "number"); + } +} + +// Do something +function f(x) { return x*x; } +f(42); + +var new_dispatch_counters = getIgnitionDispatchCounters(); + +var old_source_bytecodes = Object.getOwnPropertyNames(old_dispatch_counters); +var new_source_bytecodes = Object.getOwnPropertyNames(new_dispatch_counters); +var common_source_bytecodes = new_source_bytecodes.filter(function (name) { + return old_source_bytecodes.indexOf(name) > -1; +}); + +// Check that the keys on the outer objects are the same +assertEquals(common_source_bytecodes, old_source_bytecodes); +assertEquals(common_source_bytecodes, new_source_bytecodes); + +common_source_bytecodes.forEach(function (source_bytecode) { + var new_counters_row = new_dispatch_counters[source_bytecode]; + var old_counters_row = old_dispatch_counters[source_bytecode]; + + var old_destination_bytecodes = Object.getOwnPropertyNames(old_counters_row); + var new_destination_bytecodes = Object.getOwnPropertyNames(new_counters_row); + + // Check that all the keys in old_ are in new_ too + old_destination_bytecodes.forEach(function (name) { + assertTrue(new_destination_bytecodes.indexOf(name) > -1); + }); + + // Check that for each source-destination pair, the counter has either + // appeared (was undefined before calling f()), is unchanged, or incremented. + new_destination_bytecodes.forEach(function (destination_bytecode) { + var new_counter = new_counters_row[destination_bytecode]; + var old_counter = old_counters_row[destination_bytecode]; + assertTrue(typeof new_counter === "number"); + if (typeof old_counter === "number") { + assertTrue(new_counter >= old_counter); + } + }); +}); diff --git a/deps/v8/test/mjsunit/ignition/osr-from-bytecode.js b/deps/v8/test/mjsunit/ignition/osr-from-bytecode.js new file mode 100644 index 0000000000..d4f40bad79 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/osr-from-bytecode.js @@ -0,0 +1,12 @@ +// Copyright 2016 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 --ignition --ignition-osr --turbo-from-bytecode + +function f() { + for (var i = 0; i < 10; i++) { + if (i == 5) %OptimizeOsr(); + } +} +f(); diff --git a/deps/v8/test/mjsunit/ignition/osr-from-generator.js b/deps/v8/test/mjsunit/ignition/osr-from-generator.js new file mode 100644 index 0000000000..2344a31ce4 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/osr-from-generator.js @@ -0,0 +1,65 @@ +// Copyright 2016 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 TestGeneratorOSRSimple() { + function* gen1() { + for (var i = 0; i < 3; ++i) { + if (i == 1) %OptimizeOsr(); + } + return 23; + } + var g = gen1(); + assertEquals({ value:23, done:true }, g.next()); +})(); + +(function TestGeneratorOSRYieldAfterArming() { + function* gen2() { + for (var i = 0; i < 3; ++i) { + if (i == 1) %OptimizeOsr(); + yield i; + } + return 23; + } + var g = gen2(); + assertEquals({ value:0, done:false }, g.next()); + assertEquals({ value:1, done:false }, g.next()); + assertEquals({ value:2, done:false }, g.next()); + assertEquals({ value:23, done:true }, g.next()); +})(); + +(function TestGeneratorOSRYieldBeforeArming() { + function* gen3() { + for (var i = 0; i < 3; ++i) { + yield i; + if (i == 1) %OptimizeOsr(); + } + return 23; + } + var g = gen3(); + assertEquals({ value:0, done:false }, g.next()); + assertEquals({ value:1, done:false }, g.next()); + assertEquals({ value:2, done:false }, g.next()); + assertEquals({ value:23, done:true }, g.next()); +})(); + +(function TestGeneratorOSRNested() { + function* gen4() { + for (var i = 0; i < 3; ++i) { + for (var j = 0; j < 3; ++j) { + for (var k = 0; k < 10; ++k) { + if (k == 5) %OptimizeOsr(); + } + } + yield i; + } + return 23; + } + var g = gen4(); + assertEquals({ value:0, done:false }, g.next()); + assertEquals({ value:1, done:false }, g.next()); + assertEquals({ value:2, done:false }, g.next()); + assertEquals({ value:23, done:true }, g.next()); +})(); diff --git a/deps/v8/test/mjsunit/ignition/regress-599001-verifyheap.js b/deps/v8/test/mjsunit/ignition/regress-599001-verifyheap.js index 5aa2efdb36..ce5b46de95 100644 --- a/deps/v8/test/mjsunit/ignition/regress-599001-verifyheap.js +++ b/deps/v8/test/mjsunit/ignition/regress-599001-verifyheap.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: --verify-heap --expose-gc +// Flags: --ignition --verify-heap --expose-gc // Tests that verify heap works for BytecodeArrays in the large object space. diff --git a/deps/v8/test/mjsunit/ignition/regress-612386-smi-to-double-transition.js b/deps/v8/test/mjsunit/ignition/regress-612386-smi-to-double-transition.js new file mode 100644 index 0000000000..275f7d62d3 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/regress-612386-smi-to-double-transition.js @@ -0,0 +1,29 @@ +// Copyright 2016 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: --no-inline-new + +function keyed_store(obj, key, value) { + obj[key] = value; +} + +function foo() { + obj = {}; + obj.smi = 1; + obj.dbl = 1.5; + obj.obj = {a:1}; + + // Transition keyed store IC to polymorphic. + keyed_store(obj, "smi", 100); + keyed_store(obj, "dbl", 100); + keyed_store(obj, "obj", 100); + + // Now call with a FAST_SMI_ELEMENTS object. + var smi_array = [5, 1, 1]; + keyed_store(smi_array, 1, 6); + // Transition from FAST_SMI_ELEMENTS to FAST_DOUBLE_ELEMENTS. + keyed_store(smi_array, 2, 1.2); +} + +foo(); diff --git a/deps/v8/test/mjsunit/ignition/regress-616064.js b/deps/v8/test/mjsunit/ignition/regress-616064.js new file mode 100644 index 0000000000..06de873293 --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/regress-616064.js @@ -0,0 +1,26 @@ +// Copyright 2016 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: --ignition + +function foo() { + if (this.Worker) { + function __f_0() { this.s = a; } + function __f_1() { + this.l = __f_0; + } + + with ( 'source' , Object ) throw function __f_0(__f_0) { + return Worker.__f_0(-2147483648, __f_0); + }; + + var __v_9 = new Worker(''); + __f_1 = {s: Math.s, __f_1: true}; + } +} + +try { + foo(); +} catch(e) { +} diff --git a/deps/v8/test/mjsunit/ignition/regress-629792-source-position-on-jump.js b/deps/v8/test/mjsunit/ignition/regress-629792-source-position-on-jump.js new file mode 100644 index 0000000000..f87caf681a --- /dev/null +++ b/deps/v8/test/mjsunit/ignition/regress-629792-source-position-on-jump.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(t) { + var f = t || this; + for (var i in t) { + for (var j in t) { + (j); + continue; + } + } +} +f(); diff --git a/deps/v8/test/mjsunit/induction-variable-turbofan.js b/deps/v8/test/mjsunit/induction-variable-turbofan.js new file mode 100644 index 0000000000..6957859f9e --- /dev/null +++ b/deps/v8/test/mjsunit/induction-variable-turbofan.js @@ -0,0 +1,102 @@ +// Copyright 2016 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 + +// TurboFan optimizes integer loops. These tests check that we compute +// the correct upper and lower bounds. +function positive_increment() { + for (var i = 5; i < 10; i++) { + if (i < 0) return false; + if (i > 20) return false; + if (i === 7) return true; + } + return false; +} + +function positive_increment_strict() { + for (var i = 5; i < 10; i++) { + if (i < 0) return false; + if (i === 10) return false; + } + return true; +} + +function positive_increment_non_strict() { + for (var i = 5; i <= 10; i++) { + if (i < 0) return false; + if (i === 10) return true; + } + return false; +} + +function negative_increment() { + for (var i = 10; i > 5;) { + if (i < 0) return false; + if (i > 20) return false; + if (i === 7) return true; + i -= 1; + } + return false; +} + +function positive_decrement() { + for (var i = 10; i > 5; i--) { + if (i < 0) return false; + if (i === 7) return true; + } + return false; +} + +function positive_decrement_strict() { + for (var i = 10; i > 5; i--) { + if (i < 0) return false; + if (i === 5) return false; + } + return true; +} +function positive_decrement_non_strict() { + for (var i = 10; i >= 5; i--) { + if (i < 0) return false; + if (i === 5) return true; + } + return false; +} + +function negative_decrement() { + for (var i = 5; i < 10;) { + if (i < 0) return false; + if (i === 7) return true; + i -= -1; + } + return false; +} + +function variable_bound() { + for (var i = 5; i < 10; i++) { + for (var j = 5; j < i; j++) { + if (j < 0) return false; + if (j === 7) return true; + } + } + return false; + +} + +function test(f) { + f(); + assertTrue(f()); + %OptimizeFunctionOnNextCall(f); + assertTrue(f()); +} + +test(positive_increment); +test(positive_increment_strict); +test(positive_increment_non_strict); +test(negative_increment); +test(positive_decrement); +test(positive_decrement_strict); +test(positive_decrement_non_strict); +test(negative_decrement); +test(variable_bound); diff --git a/deps/v8/test/mjsunit/json-replacer-order.js b/deps/v8/test/mjsunit/json-replacer-order.js index 8cb64414e7..19b69bfe7a 100644 --- a/deps/v8/test/mjsunit/json-replacer-order.js +++ b/deps/v8/test/mjsunit/json-replacer-order.js @@ -20,7 +20,6 @@ var space = Object.defineProperty(new String, 'toString', { }); JSON.stringify('', replacer, space); - assertEquals(2, log.length); assertEquals('get 0', log[0]); assertEquals('toString', log[1]); diff --git a/deps/v8/test/mjsunit/json-stringify-holder.js b/deps/v8/test/mjsunit/json-stringify-holder.js new file mode 100644 index 0000000000..2f06d77095 --- /dev/null +++ b/deps/v8/test/mjsunit/json-stringify-holder.js @@ -0,0 +1,104 @@ +// Copyright 2016 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 testBasic() { + var stack = []; + var object = {a: false}; + var replaced = {a: false, replaced: true}; + + function replacer(key, value) { + stack.push({ holder: this, key, value }); + if (stack.length === 1) return replaced; + if (key === "a") return true; + return value; + } + + assertEquals(`{"a":true,"replaced":true}`, JSON.stringify(object, replacer)); + + assertEquals([ + { + holder: { "": { a: false } }, + key: "", + value: { a: false } + }, + { + holder: { a: false, replaced: true }, + key: "a", + value: false + }, + { + holder: { a: false, replaced: true }, + key: "replaced", + value: true + } + ], stack); + + assertSame(stack[0].holder[""], object); + assertSame(stack[0].value, object); + assertSame(stack[1].holder, replaced); + assertSame(stack[2].holder, replaced); +})(); + +(function testToJSON() { + var stack = []; + var object = {a: false, toJSON }; + var nested = { toJSON: nestedToJSON }; + var replaced = {a: false, replaced: true, nested }; + var toJSONd = {a: false, toJSONd: true } + var nestedToJSONd = { nestedToJSONd: true }; + + function toJSON(key, value) { + return toJSONd; + } + + function nestedToJSON(key, value) { + return nestedToJSONd; + } + + function replacer(key, value) { + stack.push({ holder: this, key, value }); + if (stack.length === 1) return replaced; + if (key === "a") return true; + return value; + } + + assertEquals(`{"a":true,"replaced":true,"nested":{"nestedToJSONd":true}}`, + JSON.stringify(object, replacer)); + + assertEquals([ + { + holder: { "": { a: false, toJSON: toJSON } }, + key: "", + value: { a: false, toJSONd: true } + }, + { + holder: { a: false, replaced: true, nested: { toJSON: nestedToJSON } }, + key: "a", + value: false + }, + { + holder: { a: false, replaced: true, nested: { toJSON: nestedToJSON } }, + key: "replaced", + value: true + }, + { + holder: { a: false, replaced: true, nested: { toJSON: nestedToJSON } }, + key: "nested", + value: { nestedToJSONd: true } + }, + { + holder: { nestedToJSONd: true }, + key: "nestedToJSONd", + value: true + } + ], stack); + + assertSame(stack[0].holder[""], object); + assertSame(stack[0].value, toJSONd); + assertSame(stack[1].holder, replaced); + assertSame(stack[2].holder, replaced); + assertSame(stack[3].holder, replaced); + assertSame(stack[3].value, nestedToJSONd); + assertSame(stack[4].holder, nestedToJSONd); +})(); diff --git a/deps/v8/test/mjsunit/json.js b/deps/v8/test/mjsunit/json.js index 84f2056856..3652febc3c 100644 --- a/deps/v8/test/mjsunit/json.js +++ b/deps/v8/test/mjsunit/json.js @@ -234,7 +234,9 @@ TestInvalid('"Garbage""After string"'); function TestStringify(expected, input) { assertEquals(expected, JSON.stringify(input)); - assertEquals(expected, JSON.stringify(input, null, 0)); + assertEquals(expected, JSON.stringify(input, (key, value) => value)); + assertEquals(JSON.stringify(input, null, "="), + JSON.stringify(input, (key, value) => value, "=")); } TestStringify("true", true); @@ -451,8 +453,8 @@ var counter = { get toJSON() { getCount++; // RegExps are not callable, so they are stringified as objects. TestStringify('{}', /regexp/); TestStringify('42', counter); -assertEquals(2, getCount); -assertEquals(2, callCount); +assertEquals(4, getCount); +assertEquals(4, callCount); var oddball2 = Object(42); var oddball3 = Object("foo"); @@ -518,3 +520,6 @@ reviver = function(p, v) { return p === "" ? v : 42; } assertEquals({a: 0, b: 1}, JSON.parse('{"a":0,"b":1}', reviver)); + +reviver = (k, v) => (v === Infinity) ? "inf" : v; +assertEquals('{"":"inf"}', JSON.stringify({"":Infinity}, reviver)); diff --git a/deps/v8/test/mjsunit/json2.js b/deps/v8/test/mjsunit/json2.js index f68c76c92a..75e25f8924 100644 --- a/deps/v8/test/mjsunit/json2.js +++ b/deps/v8/test/mjsunit/json2.js @@ -35,7 +35,9 @@ assertTrue(JSON.stringify(this, null, 0).indexOf('"a":12345') > 0); // Test JSON.stringify of array in dictionary mode. function TestStringify(expected, input) { assertEquals(expected, JSON.stringify(input)); - assertEquals(expected, JSON.stringify(input, null, 0)); + assertEquals(expected, JSON.stringify(input, (key, value) => value)); + assertEquals(JSON.stringify(input, null, "="), + JSON.stringify(input, (key, value) => value, "=")); } var array_1 = []; @@ -76,7 +78,7 @@ var getter_obj = { get getter() { return 123; } }; TestStringify('{"getter":123}', getter_obj); -assertEquals(2, counter); +assertEquals(4, counter); // Test toJSON function. var tojson_obj = { toJSON: function() { @@ -85,7 +87,7 @@ var tojson_obj = { toJSON: function() { }, a: 1}; TestStringify('[1,2]', tojson_obj); -assertEquals(4, counter); +assertEquals(8, counter); // Test that we don't recursively look for the toJSON function. var tojson_proto_obj = { a: 'fail' }; diff --git a/deps/v8/test/mjsunit/lithium/SeqStringSetChar.js b/deps/v8/test/mjsunit/lithium/SeqStringSetChar.js deleted file mode 100644 index c5bd1450f9..0000000000 --- a/deps/v8/test/mjsunit/lithium/SeqStringSetChar.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 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 - -function MyStringFromCharCode(code, i) { - var one_byte = %NewString(3, true); - %_OneByteSeqStringSetChar(0, code, one_byte); - %_OneByteSeqStringSetChar(1, code, one_byte); - %_OneByteSeqStringSetChar(i, code, one_byte); - var two_byte = %NewString(3, false); - %_TwoByteSeqStringSetChar(0, code, two_byte); - %_TwoByteSeqStringSetChar(1, code, two_byte); - %_TwoByteSeqStringSetChar(i, code, two_byte); - return one_byte + two_byte; -} - -MyStringFromCharCode(65, 2); -var r1 = MyStringFromCharCode(65, 2); -%OptimizeFunctionOnNextCall(MyStringFromCharCode); -var r2 = MyStringFromCharCode(65, 2); -assertEquals(r1, r2); diff --git a/deps/v8/test/mjsunit/messages.js b/deps/v8/test/mjsunit/messages.js index 8796d05f16..30abc197e9 100644 --- a/deps/v8/test/mjsunit/messages.js +++ b/deps/v8/test/mjsunit/messages.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // Flags: --stack-size=100 --harmony -// Flags: --harmony-simd --harmony-instanceof +// Flags: --harmony-simd function test(f, expected, type) { try { @@ -147,7 +147,12 @@ test(function() { }, "Method Set.prototype.add called on incompatible receiver [object Array]", TypeError); -// kInstanceofFunctionExpected +// kNonCallableInInstanceOfCheck +test(function() { + 1 instanceof {}; +}, "Right-hand side of 'instanceof' is not callable", TypeError); + +// kNonObjectInInstanceOfCheck test(function() { 1 instanceof 1; }, "Right-hand side of 'instanceof' is not an object", TypeError); diff --git a/deps/v8/test/mjsunit/migrations.js b/deps/v8/test/mjsunit/migrations.js index a18d884059..2bd70fb771 100644 --- a/deps/v8/test/mjsunit/migrations.js +++ b/deps/v8/test/mjsunit/migrations.js @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-ayle license that can be // found in the LICENSE file. -// Flags: --harmony-object-observe // Flags: --allow-natives-syntax --track-fields --expose-gc var global = Function('return this')(); @@ -275,10 +274,6 @@ var migrations = [ }, }, { - name: "observe", - migr: function(o, i) { Object.observe(o, function(){}); }, - }, - { name: "seal", migr: function(o, i) { Object.seal(o); }, }, diff --git a/deps/v8/test/mjsunit/mirror-object.js b/deps/v8/test/mjsunit/mirror-object.js index 834d7a580a..a46c41a3c9 100644 --- a/deps/v8/test/mjsunit/mirror-object.js +++ b/deps/v8/test/mjsunit/mirror-object.js @@ -200,10 +200,10 @@ assertFalse(math_mirror.property("E").canDelete()); // Test objects with JavaScript accessors. o = {} -o.__defineGetter__('a', function(){return 'a';}); -o.__defineSetter__('b', function(){}); -o.__defineGetter__('c', function(){throw 'c';}); -o.__defineSetter__('c', function(){throw 'c';}); +o.__defineGetter__('a', function (){return 'a';}); +o.__defineSetter__('b', function (){}); +o.__defineGetter__('c', function (){throw 'c';}); +o.__defineSetter__('c', function (){throw 'c';}); testObjectMirror(o, 'Object', 'Object'); mirror = debug.MakeMirror(o); // a has getter but no setter. @@ -265,3 +265,27 @@ assertEquals(Number, property_map["[[TargetFunction]]"].value().value()); assertTrue("[[BoundArgs]]" in property_map); assertEquals("object", property_map["[[BoundArgs]]"].value().type()); assertEquals(1, property_map["[[BoundArgs]]"].value().value().length); + +// Test JSProxy internal properties. +var target = {}; +var handler = { + get: function (target, name, receiver) { + return target[name]; + }, + set: function(target, name, value, receiver) { + target[name] = value; + return value; + } +} +ip = debug.ObjectMirror.GetInternalProperties(new Proxy(target, handler)); +assertEquals(3, ip.length); +var property_map = {}; +for (var i = 0; i < ip.length; i++) { + property_map[ip[i].name()] = ip[i]; +} +assertTrue("[[Target]]" in property_map); +assertEquals(target, property_map["[[Target]]"].value().value()); +assertTrue("[[Handler]]" in property_map); +assertEquals(handler, property_map["[[Handler]]"].value().value()); +assertTrue("[[IsRevoked]]" in property_map); +assertEquals(false, property_map["[[IsRevoked]]"].value().value()); diff --git a/deps/v8/test/mjsunit/mirror-regexp.js b/deps/v8/test/mjsunit/mirror-regexp.js index 7aae1c62ec..0711ff95ae 100644 --- a/deps/v8/test/mjsunit/mirror-regexp.js +++ b/deps/v8/test/mjsunit/mirror-regexp.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: --expose-debug-as debug --harmony-unicode-regexps +// Flags: --expose-debug-as debug // Test the mirror object for regular expression values var dont_enum = debug.PropertyAttribute.DontEnum; diff --git a/deps/v8/test/mjsunit/mirror-script.js b/deps/v8/test/mjsunit/mirror-script.js index ed0dd12ace..635c658ac3 100644 --- a/deps/v8/test/mjsunit/mirror-script.js +++ b/deps/v8/test/mjsunit/mirror-script.js @@ -83,16 +83,7 @@ function testScriptMirror(f, file_name, file_lines, type, compilation_type, // Test the script mirror for different functions. -testScriptMirror(function(){}, 'mirror-script.js', 99, 2, 0); -testScriptMirror(Math.abs, 'native math.js', -1, 0, 0); +testScriptMirror(function(){}, 'mirror-script.js', 90, 2, 0); +testScriptMirror(Math.random, 'native math.js', -1, 0, 0); testScriptMirror(eval('(function(){})'), null, 1, 2, 1, '(function(){})', 87); testScriptMirror(eval('(function(){\n })'), null, 2, 2, 1, '(function(){\n })', 88); - -// Test taking slices of source. -var mirror = debug.MakeMirror(eval('(function(){\n 1;\n})')).script(); -assertEquals('(function(){\n', mirror.sourceSlice(0, 1).sourceText()); -assertEquals(' 1;\n', mirror.sourceSlice(1, 2).sourceText()); -assertEquals('})', mirror.sourceSlice(2, 3).sourceText()); -assertEquals('(function(){\n 1;\n', mirror.sourceSlice(0, 2).sourceText()); -assertEquals(' 1;\n})', mirror.sourceSlice(1, 3).sourceText()); -assertEquals('(function(){\n 1;\n})', mirror.sourceSlice(0, 3).sourceText()); diff --git a/deps/v8/test/mjsunit/mjsunit.gyp b/deps/v8/test/mjsunit/mjsunit.gyp index 35ce2ffdee..e0a7469248 100644 --- a/deps/v8/test/mjsunit/mjsunit.gyp +++ b/deps/v8/test/mjsunit/mjsunit.gyp @@ -13,8 +13,8 @@ '../../src/d8.gyp:d8_run', ], 'includes': [ - '../../build/features.gypi', - '../../build/isolate.gypi', + '../../gypfiles/features.gypi', + '../../gypfiles/isolate.gypi', ], 'sources': [ 'mjsunit.isolate', diff --git a/deps/v8/test/mjsunit/mjsunit.isolate b/deps/v8/test/mjsunit/mjsunit.isolate index 18b73c2a14..6ebd801eac 100644 --- a/deps/v8/test/mjsunit/mjsunit.isolate +++ b/deps/v8/test/mjsunit/mjsunit.isolate @@ -13,7 +13,8 @@ '../../tools/profile_view.js', '../../tools/profviz/composer.js', '../../tools/splaytree.js', - '../../tools/tickprocessor.js' + '../../tools/tickprocessor.js', + '../../tools/dumpcpp.js' ], }, 'includes': [ diff --git a/deps/v8/test/mjsunit/mjsunit.js b/deps/v8/test/mjsunit/mjsunit.js index 9b07953c8a..6a7c2da9e4 100644 --- a/deps/v8/test/mjsunit/mjsunit.js +++ b/deps/v8/test/mjsunit/mjsunit.js @@ -114,6 +114,9 @@ var assertUnreachable; var assertOptimized; var assertUnoptimized; +// Assert that a string contains another expected substring. +var assertContains; + (function () { // Scope for utility functions. @@ -416,6 +419,12 @@ var assertUnoptimized; throw new MjsUnitAssertionError(message); }; + assertContains = function(sub, value, name_opt) { + if (value == null ? (sub != null) : value.indexOf(sub) == -1) { + fail("contains '" + String(sub) + "'", value, name_opt); + } + }; + var OptimizationStatusImpl = undefined; var OptimizationStatus = function(fun, sync_opt) { diff --git a/deps/v8/test/mjsunit/mjsunit.status b/deps/v8/test/mjsunit/mjsunit.status index ce7436f2c2..5231070b60 100644 --- a/deps/v8/test/mjsunit/mjsunit.status +++ b/deps/v8/test/mjsunit/mjsunit.status @@ -55,108 +55,12 @@ 'es6/debug-promises/reject-with-undefined-reject': [FAIL], 'es6/debug-promises/reject-with-invalid-reject': [FAIL], - ############################################################################## - # TurboFan compiler failures. - - # TODO(verwaest): Some tests are over-restrictive about object layout. - 'array-constructor-feedback': [PASS, NO_VARIANTS], - 'array-feedback': [PASS, NO_VARIANTS], - 'compare-known-objects-slow': [PASS, NO_VARIANTS], - 'elements-kind': [PASS, NO_VARIANTS], - 'opt-elements-kind': [PASS, NO_VARIANTS], - 'smi-representation': [PASS, NO_VARIANTS], - - # Some tests are just too slow to run for now. - 'big-object-literal': [PASS, NO_VARIANTS], - 'bit-not': [PASS, NO_VARIANTS], - 'json2': [PASS, NO_VARIANTS], - 'packed-elements': [PASS, NO_VARIANTS], - 'string-indexof-1': [PASS, NO_VARIANTS], - 'unbox-double-arrays': [PASS, NO_VARIANTS], - 'unicode-test': [PASS, NO_VARIANTS], - 'whitespaces': [PASS, NO_VARIANTS], - 'compiler/osr-assert': [PASS, NO_VARIANTS], - 'es6/string-fromcodepoint': [PASS, NO_VARIANTS], - 'regress/regress-2185-2': [PASS, NO_VARIANTS], - 'regress/regress-2612': [PASS, NO_VARIANTS], - # Issue 3660: Replacing activated TurboFan frames by unoptimized code does # not work, but we expect it to not crash. 'debug-step-turbofan': [PASS, FAIL], - # TODO(mstarzinger): Optimizing top-level code revealed some issues. Fix! - 'bitops-info': [PASS, NO_VARIANTS], # fails on ARM hardware. - 'md5': [PASS, NO_VARIANTS], # fails on ARM hardware. - 'debug-break-inline': [PASS, NO_VARIANTS], # very flaky. - 'debug-compile-event-newfunction': [PASS, NO_VARIANTS], - 'debug-conditional-breakpoints': [PASS, NO_VARIANTS], - 'debug-evaluate-locals-optimized': [PASS, NO_VARIANTS], - 'debug-evaluate-locals-optimized-double': [PASS, NO_VARIANTS], - 'debug-evaluate-recursive': [PASS, NO_VARIANTS], # only in no-snap debug. - 'debug-ignore-breakpoints': [PASS, NO_VARIANTS], # only in no-snap debug. - 'debug-setbreakpoint': [PASS, NO_VARIANTS], # only in no-snap debug. - 'debug-step': [PASS, NO_VARIANTS], # windows only. - 'debug-step-2': [PASS, NO_VARIANTS], # flaky in no-snap mode. - '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. - 'debug-listbreakpoints': [PASS, NO_VARIANTS], # arm64 nosnap with turbofan - 'debug-enable-disable-breakpoints': [PASS, NO_VARIANTS], #arm64 nosnap with turbofan. - - # Issue 4035: unexpected frame->context() in debugger - 'regress/regress-crbug-107996': [PASS, NO_VARIANTS], - 'regress/regress-crbug-171715': [PASS, NO_VARIANTS], - 'regress/regress-crbug-222893': [PASS, NO_VARIANTS], - 'regress/regress-crbug-323936': [PASS, NO_VARIANTS], - 'regress/regress-crbug-491943': [PASS, NO_VARIANTS], - 'regress/regress-325676': [PASS, NO_VARIANTS], - 'debug-evaluate-closure': [PASS, NO_VARIANTS], - 'debug-evaluate-with': [PASS, NO_VARIANTS], - - # TODO(mstarzinger): Optimizing top-level code flushed out some correctness - # issues on ARM and ARM64. - 'es6/math-log2-log10': [PASS, NO_VARIANTS], # on ARM and ARM64. - 'mirror-script': [PASS, NO_VARIANTS], # on ARM64 only. - - # TODO(jarin/mstarzinger): Investigate debugger issues with TurboFan. - 'debug-evaluate-const': [PASS, NO_VARIANTS], - 'debug-evaluate-locals': [PASS, NO_VARIANTS], - 'debug-evaluate-locals-capturing': [PASS, NO_VARIANTS], - 'debug-liveedit-check-stack': [PASS, NO_VARIANTS], # only in no-snap mode. - 'debug-liveedit-double-call': [PASS, NO_VARIANTS], - 'debug-set-variable-value': [PASS, NO_VARIANTS], - 'debug-stepout-scope-part1': [PASS, NO_VARIANTS], - 'debug-stepout-scope-part2': [PASS, NO_VARIANTS], - 'debug-stepout-scope-part3': [PASS, NO_VARIANTS], - 'es6/debug-evaluate-blockscopes': [PASS, NO_VARIANTS], - # Issue 4055: Scope chain length observed by debugger is off. - 'es6/generators-debug-scopes': [PASS, NO_VARIANTS], - - # TODO(titzer): --always-opt incorrectly disables CrankShaft soft deopt points - 'result-table-min': [PASS, NO_VARIANTS], - 'result-table-max': [PASS, NO_VARIANTS], - # 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], - 'regress/regress-store-uncacheable': [PASS, NO_VARIANTS], - - # issue 4078: - 'allocation-site-info': [PASS, NO_VARIANTS], - - # TODO(turbofan): The escape analysis needs some investigation. - 'compiler/escape-analysis-deopt-5': [PASS, NO_VARIANTS], - 'compiler/escape-analysis-9': [PASS, NO_VARIANTS], - ############################################################################## # Too slow in debug mode with --stress-opt mode. - 'compiler/regress-stacktrace-methods': [PASS, ['mode == debug', SKIP]], - 'compiler/regress-funcaller': [PASS, ['mode == debug', SKIP]], 'regress/regress-2318': [PASS, ['mode == debug', SKIP]], 'regress/regress-create-exception': [PASS, ['mode == debug', SKIP]], @@ -197,11 +101,6 @@ 'regress/regress-crbug-482998': [PASS, NO_VARIANTS, ['arch == arm or arch == arm64 or arch == android_arm or arch == android_arm64 or arch == mipsel or arch == mips64el or arch == mips', SKIP]], ############################################################################## - # This test expects to reach a certain recursion depth, which may not work - # for debug mode. - 'json-recursive': [PASS, ['mode == debug', PASS, FAIL]], - - ############################################################################## # Skip long running tests that time out in debug mode. 'generated-transition-stub': [PASS, ['mode == debug', SKIP]], 'migrations': [SKIP], @@ -217,6 +116,7 @@ # that, it doesn't make sense to run several variants of d8-os anyways. 'd8-os': [PASS, NO_VARIANTS, ['isolates or arch == android_arm or arch == android_arm64 or arch == android_ia32', SKIP]], 'tools/tickprocessor': [PASS, NO_VARIANTS, ['arch == android_arm or arch == android_arm64 or arch == android_ia32', SKIP]], + 'tools/dumpcpp': [PASS, NO_VARIANTS, ['arch == android_arm or arch == android_arm64 or arch == android_ia32', SKIP]], ############################################################################## # Long running test that reproduces memory leak and should be run manually. @@ -231,7 +131,6 @@ # Tests with different versions for release and debug. 'compiler/alloc-number': [PASS, ['mode == debug', SKIP]], 'compiler/alloc-number-debug': [PASS, ['mode == release', SKIP]], - 'regress/regress-634': [PASS, ['mode == debug', SKIP]], 'regress/regress-634-debug': [PASS, ['mode == release', SKIP]], # BUG(336820). TODO(bmeurer): Investigate. @@ -241,10 +140,6 @@ # nosse2. Also for arm novfp3. 'regress/regress-2989': [FAIL, NO_VARIANTS, ['system == linux and arch == x87 or arch == arm and simulator == True', PASS]], - # Skip endain dependent test for mips due to different typed views of the same - # array buffer. - 'nans': [PASS, ], - # This test variant makes only sense on arm. 'math-floor-of-div-nosudiv': [PASS, SLOW, ['arch not in [arm, arm64, android_arm, android_arm64]', SKIP]], @@ -253,42 +148,42 @@ 'asm/poppler/*': [PASS, SLOW, FAST_VARIANTS], 'asm/sqlite3/*': [PASS, SLOW, FAST_VARIANTS], - # BUG(v8:4458). TODO(mvstanton): reenable the test once --vector-stores is - # prermanently enabled. - 'call-counts': [SKIP], - # 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-1200351': [PASS, SLOW], 'regress/regress-crbug-474297': [PASS, ['mode == debug', SLOW]], - 'es6/tail-call-megatest*': [PASS, FAST_VARIANTS], + 'es6/tail-call-megatest*': [PASS, SLOW, FAST_VARIANTS, ['tsan', SKIP]], # TODO(titzer): ASM->WASM tests on these platforms 'wasm/asm-wasm': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], # TODO(branelson): Figure out why ignition + asm-wasm-stdlib fails. - 'wasm/asm-wasm-stdlib': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el] or ignition == True', SKIP]], - 'wasm/asm-wasm-literals': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el] or ignition == True', SKIP]], + # TODO(branelson): The old status entry was misconfigured as it added + # "or ignition == True". This was deprecated at some point and was never + # true. Essentially the next lines skip the tests for a bunch of + # architectures. + 'wasm/asm-wasm-stdlib': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], + 'wasm/asm-wasm-literals': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], 'wasm/asm-wasm-copy': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], 'wasm/asm-wasm-deopt': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], - - # TODO(branelson): Figure out why ignition + asm->wasm fails embenchen. - 'wasm/embenchen/*': [PASS, ['arch == arm64', SKIP], ['ignition == True', SKIP]], - - # TODO(bradnelson) Fix and re-enable. - 'wasm/embenchen/box2d': [SKIP], # hang - 'wasm/embenchen/lua_binarytrees': [SKIP], # fails decode - #'wasm/embenchen/zlib': [SKIP], # fails gc-stress + 'wasm/asm-wasm-switch': [PASS, ['arch in [arm, arm64, mips, mipsel, mips64, mips64el]', SKIP]], # case-insensitive unicode regexp relies on case mapping provided by ICU. - 'harmony/unicode-regexp-ignore-case': [PASS, ['no_i18n == True', FAIL]], - 'harmony/unicode-regexp-ignore-case-noi18n': [FAIL, ['no_i18n == True', PASS]], + 'es6/unicode-regexp-ignore-case': [PASS, ['no_i18n == True', FAIL]], + 'es6/unicode-regexp-ignore-case-noi18n': [FAIL, ['no_i18n == True', PASS]], 'regress/regress-5036': [PASS, ['no_i18n == True', FAIL]], # desugaring regexp property class relies on ICU. 'harmony/regexp-property-*': [PASS, ['no_i18n == True', FAIL]], + + # TODO(bmeurer): Flaky timeouts (sometimes <1s, sometimes >3m). + 'unicodelctest': [PASS, NO_VARIANTS], + 'unicodelctest-no-optimization': [PASS, NO_VARIANTS], + + # TODO(rmcilroy,5038): Crashes in Deoptimizer::PatchCodeForDeoptimization on + # nosnap builds when --stress-opt and --turbo-from-bytecode is enabled. + 'harmony/generators-turbo': [PASS, FAST_VARIANTS], }], # ALWAYS ['novfp3 == True', { @@ -335,7 +230,6 @@ # TODO(mstarzinger): Takes too long with TF. 'array-sort': [PASS, NO_VARIANTS], 'regress/regress-91008': [PASS, NO_VARIANTS], - 'regress/regress-417709a': [PASS, ['arch == arm64', NO_VARIANTS]], 'regress/regress-transcendental': [PASS, ['arch == arm64', NO_VARIANTS]], 'compiler/osr-regress-max-locals': [PASS, NO_VARIANTS], 'math-floor-of-div': [PASS, NO_VARIANTS], @@ -363,18 +257,12 @@ # BUG(v8:3097) 'debug-references': [SKIP], - # BUG(v8:4754). - 'debug-referenced-by': [PASS, NO_VARIANTS], - # BUG(v8:4779): Crashes flakily with stress mode on arm64. 'array-splice': [PASS, SLOW, ['arch == arm64', FAST_VARIANTS]], -}], # 'gc_stress == True' -############################################################################## -['no_i18n == True and mode == debug', { - # Tests too slow for no18n debug. - 'regress/regress-1200351': [SKIP], -}], # 'no_i18n == True and mode == debug' + # BUG(v8:5053). + 'wasm/embenchen/fasta': [PASS, FAST_VARIANTS], +}], # 'gc_stress == True' ############################################################################## ['byteorder == big', { @@ -384,8 +272,6 @@ 'asm/sqlite3/*': [SKIP], # TODO(mips-team): Fix Wasm for big-endian. 'wasm/*': [SKIP], - 'regress/regress-599717': [SKIP], - 'regress/regress-599719': [SKIP], }], # 'byteorder == big' ############################################################################## @@ -407,15 +293,12 @@ 'big-object-literal': [SKIP], 'compiler/regress-arguments': [SKIP], 'compiler/regress-gvn': [SKIP], - 'compiler/regress-max-locals-for-osr': [SKIP], 'compiler/regress-4': [SKIP], 'compiler/regress-or': [SKIP], 'compiler/regress-rep-change': [SKIP], 'regress/regress-1117': [SKIP], - 'regress/regress-1145': [SKIP], 'regress/regress-1849': [SKIP], 'regress/regress-3247124': [SKIP], - 'regress/regress-634': [SKIP], 'regress/regress-91008': [SKIP], 'regress/regress-91010': [SKIP], 'regress/regress-91013': [SKIP], @@ -464,11 +347,9 @@ ['arch == arm64 and mode == debug and simulator_run == True', { # Pass but take too long with the simulator in debug mode. - 'array-iterate-backwards': [PASS, TIMEOUT], 'array-sort': [PASS, TIMEOUT], 'packed-elements': [SKIP], 'regexp-global': [SKIP], - 'compiler/alloc-numbers': [SKIP], 'math-floor-of-div': [PASS, TIMEOUT], 'math-floor-of-div-nosudiv': [PASS, TIMEOUT], 'unicodelctest': [PASS, TIMEOUT], @@ -497,6 +378,9 @@ 'deep-recursion': [SKIP], 'regress/regress-builtinbust-7': [SKIP], 'string-localecompare': [SKIP], + + # Too slow. + 'harmony/regexp-property-lu-ui': [SKIP], }], # 'msan == True' ############################################################################## @@ -520,7 +404,6 @@ 'big-object-literal': [SKIP], 'compiler/alloc-number': [SKIP], 'regress/regress-490': [SKIP], - 'regress/regress-634': [SKIP], 'regress/regress-create-exception': [SKIP], 'regress/regress-3247124': [SKIP], @@ -564,7 +447,6 @@ # the buildbot. 'compiler/alloc-number': [SKIP], 'regress/regress-490': [SKIP], - 'regress/regress-634': [SKIP], 'regress/regress-create-exception': [SKIP], 'regress/regress-3247124': [SKIP], @@ -584,13 +466,6 @@ }], # 'arch == mips' ############################################################################## -['arch == x87', { - # Turbofan will hit the known issue that x87 changes sNaN to qNaN by default. - 'regress/regress-undefined-nan': [SKIP], - 'regress/regress-crbug-242924': [SKIP], -}], # 'arch == x87' - -############################################################################## ['arch == mips64el or arch == mips64', { # Slow tests which times out in debug mode. @@ -627,7 +502,6 @@ 'compiler/regress-3249650': [PASS, SLOW], 'compiler/simple-deopt': [PASS, SLOW], 'regress/regress-490': [PASS, SLOW], - 'regress/regress-634': [PASS, SLOW], 'regress/regress-create-exception': [PASS, SLOW], 'regress/regress-3218915': [PASS, SLOW], 'regress/regress-3247124': [PASS, SLOW], @@ -644,10 +518,9 @@ ############################################################################## ['system == windows', { # TODO(mstarzinger): Too slow with turbo fan. - 'big-object-literal': [PASS, ['mode == debug', SKIP]], + 'big-object-literal': [SKIP], 'math-floor-of-div': [PASS, ['mode == debug', SKIP]], 'math-floor-of-div-nosudiv': [PASS, ['mode == debug', SKIP]], - 'osr-regress-max-locals': [PASS, ['mode == debug', SKIP]], 'unicodelctest': [PASS, ['mode == debug', SKIP]], # BUG(v8:3435) @@ -658,59 +531,6 @@ }], # 'system == windows' ############################################################################## -# Native Client uses the ARM simulator so will behave similarly to arm -# on mjsunit tests. -# TODO(bradchen): enable more tests for NaCl V8 when it stops using -# the ARM simulator. -############################################################################## -['arch == nacl_ia32 or arch == nacl_x64', { - # There is no /tmp directory for NaCl runs - 'd8-os': [SKIP], - - # Stack manipulations in LiveEdit is not implemented for this arch. - 'debug-liveedit-check-stack': [SKIP], - 'debug-liveedit-stack-padding': [SKIP], - 'debug-liveedit-restart-frame': [SKIP], - 'debug-liveedit-double-call': [SKIP], - - # NaCl builds have problems with this test since Pepper_28. - # V8 Issue 2786 - 'math-exp-precision': [SKIP], - - # Requires bigger stack size in the Genesis and if stack size is increased, - # the test requires too much time to run. However, the problem test covers - # should be platform-independent. - 'regress/regress-1132': [SKIP], - - # Poor performance for NaCl V8 causes an assertion failure for this test. - 'regress/regress-165637': [SKIP], - - # Skip long running test that times out in debug mode and goes OOM on NaCl. - 'regress/regress-crbug-160010': [SKIP], - - # Skip tests that timout with turbofan. - 'regress/regress-1257': [PASS, NO_VARIANTS], - 'regress/regress-2618': [PASS, NO_VARIANTS], - 'regress/regress-298269': [PASS, NO_VARIANTS], - 'regress/regress-634': [PASS, NO_VARIANTS], - 'regress/regress-91008': [PASS, NO_VARIANTS], - 'compiler/osr-alignment': [PASS, NO_VARIANTS], - 'compiler/osr-one': [PASS, NO_VARIANTS], - 'compiler/osr-two': [PASS, NO_VARIANTS], - 'stack-traces-overflow': [PASS, NO_VARIANTS], - 'mirror-object': [PASS, NO_VARIANTS], - - # Bug(v8:2978). - 'lithium/MathExp': [PASS, FAIL], - - # Lead to OOM: - 'string-oom-*': [SKIP], - - # Crashes. - 'harmony/private': [SKIP], -}], # 'arch == nacl_ia32 or arch == nacl_x64' - -############################################################################## ['arch == s390 or arch == s390x', { # Stack manipulations in LiveEdit is not implemented for this arch. @@ -758,104 +578,233 @@ 'regress/regress-1132': [SKIP], }], # 'arch == ppc and simulator_run == True' +############################################################################## ['arch == ppc64', { # stack overflow 'big-array-literal': [SKIP], + 'regress/regress-353551': [SKIP], }], # 'arch == ppc64' ############################################################################## +['variant == stress', { + 'debug-evaluate-locals-optimized': [FAIL], + 'debug-evaluate-locals-optimized-double': [FAIL], + 'ignition/regress-599001-verifyheap': [SKIP], + 'unicode-test': [SKIP], +}], # variant == stress + +############################################################################## +['variant == turbofan', { + + # Assumptions about optimization need investigation in TurboFan. + 'regress-sync-optimized-lists': [FAIL], + +}], # variant == turbofan + +############################################################################## +['variant == turbofan_opt', { + + # TODO(jarin/mstarzinger): Investigate debugger issues with TurboFan. + 'debug-evaluate-closure': [FAIL], + 'debug-evaluate-locals': [FAIL], + 'debug-set-variable-value': [FAIL], + 'debug-evaluate-locals-optimized': [FAIL], + 'debug-evaluate-locals-optimized-double': [FAIL], + 'debug-liveedit-double-call': [FAIL], + 'es6/debug-evaluate-blockscopes': [FAIL], + + # TODO(jgruber): Fails in --turbo --always-opt mode. + 'regress/regress-105': [FAIL], + + # Too slow. + 'big-object-literal': [SKIP], + 'ignition/regress-599001-verifyheap': [SKIP], + 'unicode-test': [SKIP], + +}], # variant == turbofan_opt ############################################################################## -['ignition == True', { - # TODO(yangguo,4690): assertion failures in debugger tests. - 'debug-allscopes-on-debugger': [FAIL], - 'es6/debug-stepnext-for': [FAIL], - 'es6/debug-promises/stepin-constructor': [FAIL], - 'es6/debug-stepin-proxies': [FAIL], - 'regress/regress-crbug-119800': [FAIL], - 'regress/regress-opt-after-debug-deopt': [FAIL], - - # TODO(yangguo,4690): flaky failures on the bots. - 'debug-stepin-builtin-callback-opt': [SKIP], - - # TODO(rmcilroy,4765): assertion failures in LiveEdit tests. - 'debug-liveedit-restart-frame': [FAIL], - 'debug-liveedit-literals': [FAIL], - 'debug-liveedit-3': [FAIL], - 'debug-liveedit-1': [FAIL], - 'debug-liveedit-2': [FAIL], - 'debug-liveedit-patch-positions-replace': [FAIL], - 'debug-liveedit-patch-positions': [FAIL], - 'debug-liveedit-stepin': [FAIL], - 'debug-liveedit-newsource': [FAIL], - 'debug-liveedit-stack-padding': [FAIL], - 'debug-liveedit-breakpoints': [FAIL], - 'es6/debug-liveedit-new-target-1': [FAIL], - 'es6/debug-liveedit-new-target-2': [FAIL], - 'es6/debug-liveedit-new-target-3': [FAIL], - 'es6/generators-debug-liveedit': [FAIL], +['variant == ignition', { + 'debug-liveedit-double-call': [FAIL], + 'regress-sync-optimized-lists': [FAIL], + + # Might trigger stack overflow. + 'unicode-test': [SKIP], # TODO(mythria, 4780): Related to type feedback for calls in interpreter. 'array-literal-feedback': [FAIL], 'regress/regress-4121': [FAIL], - # TODO(mythria, 4764): lack of osr support. - 'regress/regress-2618': [FAIL], - # TODO(mythria, 4764): lack of osr support. The tests waits in a loop - # till it is optimized. So test timeouts. - 'array-literal-transitions': [SKIP], + # TODO(4680): Test doesn't know about three tier compiler pipeline. + 'assert-opt-and-deopt': [SKIP], - # TODO(mythria, 4680): Relate to GC and ignition holding references to - # objects. - 'es6/mirror-collections': [FAIL], + # BUG(rmcilroy,4989): Function is optimized without type feedback and so immediately deopts again, causing check failure in the test. + 'compiler/deopt-inlined-from-call': [FAIL], + 'compiler/increment-typefeedback': [FAIL], + 'compiler/manual-concurrent-recompile': [FAIL], + 'constant-folding-2': [FAIL], + 'debug-is-active': [FAIL], + 'deopt-with-fp-regs': [FAIL], + 'deserialize-optimize-inner': [FAIL], + 'div-mul-minus-one': [FAIL], + 'double-intrinsics': [FAIL], + 'elements-transition-hoisting': [FAIL], + 'es6/block-let-crankshaft': [FAIL], + 'es6/block-let-crankshaft-sloppy': [FAIL], + 'getters-on-elements': [FAIL], + 'harmony/do-expressions': [FAIL], + 'math-floor-of-div-minus-zero': [FAIL], + 'regress/regress-2132': [FAIL], + 'regress/regress-2339': [FAIL], + 'regress/regress-3176': [FAIL], + 'regress/regress-3709': [FAIL], + 'regress/regress-385565': [FAIL], + 'regress/regress-crbug-594183': [FAIL], + 'regress/regress-embedded-cons-string': [FAIL], + 'regress/regress-map-invalidation-2': [FAIL], + 'regress/regress-param-local-type': [FAIL], + 'regress/regress-prepare-break-while-recompile': [FAIL], + 'shift-for-integer-div': [FAIL], + 'sin-cos': [FAIL], + 'smi-mul-const': [FAIL], + 'smi-mul': [FAIL], + 'unary-minus-deopt': [FAIL], + 'array-constructor-feedback': [FAIL], + 'array-feedback': [FAIL], + 'allocation-site-info': [FAIL], +}], # variant == ignition + +['variant == ignition and arch == arm64', { + # TODO(rmcilroy,4680): Arm64 specific timeouts. + 'asm/construct-double': [SKIP], + 'compiler/osr-one': [SKIP], + 'compiler/osr-two': [SKIP], + 'wasm/asm-wasm-i32': [SKIP], + 'wasm/asm-wasm-u32': [SKIP], +}], # variant == ignition and arch == arm64 - # TODO(mythria, 4680): Fails with context_register_count_ > 0 (0 vs. 0) when - # trying to get a context register in BytecodeGenerator. - 'harmony/regress/regress-4658': [FAIL, ['mode == release and dcheck_always_on == False', PASS],], +['variant == ignition and arch == arm', { + # TODO(rmcilroy,4680): Arm specific timeouts. + 'compiler/osr-one': [SKIP], + 'compiler/osr-two': [SKIP], + 'regress/regress-1257': [SKIP], +}], # variant == ignition and arch == arm - # TODO(rmcilroy, 4680): Script throws RangeError as expected, but does so during - # eager compile of the whole script instead of during lazy compile of the function - # f(), so we can't catch the exception in the try/catch. Skip because on some - # platforms the stack limit is different and the exception doesn't fire. - 'regress/regress-crbug-589472': [SKIP], +['variant == ignition and msan', { + # TODO(mythria,4680): All of these tests have large loops and hence slow + # and timeout. + 'compiler/osr-big': [SKIP], + 'compiler/osr-nested': [SKIP], + 'regress/regress-298269': [SKIP], + 'regress/regress-crbug-319860': [SKIP], + 'regress/regress-deep-proto': [SKIP], + 'try': [SKIP], + # Too slow for interpreter and msan. + 'es6/tail-call-megatest*': [SKIP], +}], # variant == ignition and msan - # Debugger test cases that pass with ignition, but not full-codegen. - # These differences between full-codegen and ignition are deliberate. - 'ignition/elided-instruction-no-ignition': [FAIL], +############################################################################## +['variant == ignition_staging', { + 'allocation-site-info': [FAIL], + 'array-constructor-feedback': [FAIL], + 'array-feedback': [FAIL], + 'array-literal-feedback': [FAIL], + 'assert-opt-and-deopt': [SKIP], + 'compiler/deopt-inlined-from-call': [FAIL], + 'compiler/increment-typefeedback': [FAIL], + 'compiler/manual-concurrent-recompile': [FAIL], + 'constant-folding-2': [FAIL], + 'debug-is-active': [FAIL], + 'debug-liveedit-double-call': [FAIL], + 'deopt-with-fp-regs': [FAIL], + 'deserialize-optimize-inner': [FAIL], + 'div-mul-minus-one': [FAIL], + 'elements-transition-hoisting': [FAIL], + 'es6/block-let-crankshaft': [FAIL], + 'es6/block-let-crankshaft-sloppy': [FAIL], + 'getters-on-elements': [FAIL], + 'harmony/do-expressions': [FAIL], + 'math-floor-of-div-minus-zero': [FAIL], + 'regress/regress-2132': [FAIL], + 'regress/regress-2339': [FAIL], + 'regress/regress-3176': [FAIL], + 'regress/regress-3709': [FAIL], + 'regress/regress-385565': [FAIL], + 'regress/regress-4121': [FAIL], + 'regress/regress-crbug-594183': [FAIL], + 'regress/regress-embedded-cons-string': [FAIL], + 'regress/regress-map-invalidation-2': [FAIL], + 'regress/regress-param-local-type': [FAIL], + 'regress/regress-prepare-break-while-recompile': [FAIL], + 'regress-sync-optimized-lists': [FAIL], + 'shift-for-integer-div': [FAIL], + 'sin-cos': [FAIL], + 'smi-mul-const': [FAIL], + 'smi-mul': [FAIL], + 'unary-minus-deopt': [FAIL], + + # Flaky. + 'asm/int32div': [SKIP], + 'asm/int32mod': [SKIP], + 'compiler/uint32': [SKIP], + 'regress/regress-454725': [SKIP], + + # Might trigger stack overflow. + 'unicode-test': [SKIP], + +}], # variant == ignition_staging + +############################################################################## +['variant == ignition_turbofan', { + 'debug-liveedit-double-call': [FAIL], + + # Might trigger stack overflow. + 'unicode-test': [SKIP], + + # TODO(mythria, 4780): Related to type feedback for calls in interpreter. + 'array-literal-feedback': [FAIL], + 'regress/regress-4121': [FAIL], + 'array-constructor-feedback': [FAIL], + 'array-feedback': [FAIL], + 'allocation-site-info': [FAIL], 'wasm/asm-wasm-f32': [PASS, ['arch in [arm64]', SKIP]], 'wasm/asm-wasm-f64': [PASS, ['arch in [arm64]', SKIP]], -}], # ignition == True -['ignition == True and system == windows', { - # TODO(rmcilroy,4680): Crash on windows nosnap shared. - 'regress/regress-crbug-352058': [PASS, ['no_snap == True', SKIP]], + # TODO(rmcilroy,titzer): Times out after + # https://codereview.chromium.org/1951013002 . + 'regress/regress-599717': [PASS, ['tsan', SKIP]], + + # TODO(rmcilroy,5038): Crashes in Deoptimizer::PatchCodeForDeoptimization on + # nosnap builds when --stress-opt and --turbo-from-bytecode is enabled. + 'harmony/generators-turbo': [PASS, FAST_VARIANTS], + 'regress/regress-crbug-352058': [SKIP], - # TODO(513471): Attempting to optimize generator hits unreachable path. - 'regress/regress-crbug-513471': [PASS, ['no_snap == True', SKIP]], + # TODO(jarin): No truncations on CheckFloat64Hole. + 'getters-on-elements': [SKIP], - # TODO(rmcilroy,4680): Fails on win32 debug. - 'div-mod': [PASS, ['arch == ia32', SKIP]], -}], # ignition == True and system == windows + # TODO(rmcilroy): Flaky OOM. + 'unicodelctest-no-optimization': [SKIP], +}], # variant == ignition_turbofan -['ignition == True and arch == arm64', { +['variant == ignition_turbofan and arch == arm64', { # TODO(rmcilroy,4680): Arm64 specific timeouts. 'asm/construct-double': [SKIP], 'compiler/osr-one': [SKIP], 'compiler/osr-two': [SKIP], 'wasm/asm-wasm-i32': [SKIP], 'wasm/asm-wasm-u32': [SKIP], -}], # ignition == True and arch == arm64 +}], # variant == ignition_turbofan and arch == arm64 -['ignition == True and arch == arm', { +['variant == ignition_turbofan and arch == arm', { # TODO(rmcilroy,4680): Arm specific timeouts. 'compiler/osr-one': [SKIP], 'compiler/osr-two': [SKIP], 'regress/regress-1257': [SKIP], -}], # ignition == True and arch == arm +}], # variant == ignition_turbofan and arch == arm -['ignition == True and msan', { +['variant == ignition_turbofan and msan', { # TODO(mythria,4680): All of these tests have large loops and hence slow # and timeout. 'compiler/osr-big': [SKIP], @@ -866,55 +815,7 @@ 'try': [SKIP], # Too slow for interpreter and msan. 'es6/tail-call-megatest*': [SKIP], -}], # ignition == True and msan - -['ignition == True and gc_stress == True', { - # TODO(oth,4680): failures from the bots. - 'es6/debug-step-destructuring-bind': [SKIP], - 'es6/debug-stepin-collections-foreach': [SKIP], - 'ignition/elided-instruction': [SKIP], - 'regress/regress-269': [SKIP], -}], # ignition == True and gc_stress == True - -['ignition == False', { - # Debugger test cases that pass with full-codegen, but not ignition. - # These differences between full-codegen and ignition are deliberate. - 'ignition/elided-instruction': [FAIL], -}], # ignition == False - -['ignition == True and system == windows and no_snap', { - # TODO(rmcilroy): Fail with nosnap and shared libraries. - 'es6/array-from': [FAIL], - 'es6/classes-subclass-builtins': [FAIL], - 'es6/computed-property-names-classes': [FAIL], - 'es6/computed-property-names-object-literals-methods': [FAIL], - 'es6/debug-stepin-generators': [FAIL], - 'es6/destructuring': [FAIL], - 'es6/destructuring-assignment': [FAIL], - 'es6/generators-iteration': [FAIL], - 'es6/generators-mirror': [FAIL], - 'es6/generators-parsing': [FAIL], - 'es6/generators-poisoned-properties': [FAIL], - 'es6/generators-relocation': [FAIL], - 'es6/generators-states': [FAIL], - 'es6/iteration-semantics': [FAIL], - 'es6/object-literals-method': [FAIL], - 'es6/object-literals-super': [FAIL], - 'es6/promises': [FAIL], - 'es6/regress/regress-2681': [FAIL], - 'es6/regress/regress-2691': [FAIL], - 'es6/regress/regress-3280': [FAIL], - 'es6/spread-array': [FAIL], - 'es6/spread-call': [FAIL], - 'es6/typedarray': [FAIL], - 'es6/typedarray-from': [FAIL], - 'harmony/function-sent': [FAIL], - 'harmony/generators': [FAIL], - 'harmony/iterator-close': [FAIL], - 'harmony/regress/regress-4482': [FAIL], - 'messages': [FAIL], - 'regress-3225': [FAIL], -}], # ignition == True and system == windows and no_snap +}], # variant == ignition_turbofan and msan ############################################################################## ['gcov_coverage', { diff --git a/deps/v8/test/mjsunit/object-define-property.js b/deps/v8/test/mjsunit/object-define-property.js index 4c495c6824..1aac489839 100644 --- a/deps/v8/test/mjsunit/object-define-property.js +++ b/deps/v8/test/mjsunit/object-define-property.js @@ -467,53 +467,6 @@ try { } -// 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 diff --git a/deps/v8/test/mjsunit/object-literal.js b/deps/v8/test/mjsunit/object-literal.js index 19860ff389..b861d443c0 100644 --- a/deps/v8/test/mjsunit/object-literal.js +++ b/deps/v8/test/mjsunit/object-literal.js @@ -24,8 +24,6 @@ // 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-function-name var obj = { a: 7, diff --git a/deps/v8/test/mjsunit/osr-elements-kind.js b/deps/v8/test/mjsunit/osr-elements-kind.js index bd15ef37e4..aee7017134 100644 --- a/deps/v8/test/mjsunit/osr-elements-kind.js +++ b/deps/v8/test/mjsunit/osr-elements-kind.js @@ -30,7 +30,7 @@ // Limit the number of stress runs to reduce polymorphism it defeats some of the // assumptions made about how elements transitions work because transition stubs // end up going generic. -// Flags: --stress-runs=2 +// Flags: --stress-runs=1 var elements_kind = { fast_smi_only : 'fast smi only elements', diff --git a/deps/v8/test/mjsunit/realm-property-access.js b/deps/v8/test/mjsunit/realm-property-access.js new file mode 100644 index 0000000000..679886d66a --- /dev/null +++ b/deps/v8/test/mjsunit/realm-property-access.js @@ -0,0 +1,20 @@ +// Copyright 2016 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 r = Realm.create(); +var f = Realm.eval(r, "function f() { return this }; f()"); +assertEquals(f, Realm.global(r)); + +// Cross-origin property access throws +assertThrows(() => f.a, TypeError); +assertThrows(() => { 'use strict'; f.a = 1 }, TypeError); + +var r2 = Realm.createAllowCrossRealmAccess(); +var f2 = Realm.eval(r2, "function f() { return this }; f()"); +assertEquals(f2, Realm.global(r2)); + +// Same-origin property access doesn't throw +assertEquals(undefined, f2.a); +f2.a = 1; +assertEquals(1, f2.a); diff --git a/deps/v8/test/mjsunit/regexp-compile.js b/deps/v8/test/mjsunit/regexp-compile.js index 92c3f7b3dd..f00178008c 100644 --- a/deps/v8/test/mjsunit/regexp-compile.js +++ b/deps/v8/test/mjsunit/regexp-compile.js @@ -42,3 +42,7 @@ re.compile("(y)"); assertEquals(["y", "y"], re.exec("axyb")); assertEquals(2, re.compile.length); + +// If RegExp parsing fails, the RegExp is not modified +var r = /./; try { r.compile('? invalid'); } catch(err){} +assertEquals("/./", r.toString()); diff --git a/deps/v8/test/mjsunit/regexp-lastIndex.js b/deps/v8/test/mjsunit/regexp-lastIndex.js deleted file mode 100644 index 1445b9b2ae..0000000000 --- a/deps/v8/test/mjsunit/regexp-lastIndex.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 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. - -// lastIndex is set according to funny rules. It is typically set only -// for global or sticky RegExps, but on a failure to find a match, it is -// set unconditionally. If a set fails, then it acts as if in strict mode -// and throws. - -var re = /x/; -Object.defineProperty(re, 'lastIndex', {writable: false}); -assertThrows(() => re.exec(""), TypeError); -assertEquals(["x"], re.exec("x")); - -var re = /x/y; -Object.defineProperty(re, 'lastIndex', {writable: false}); -assertThrows(() => re.exec(""), TypeError); -assertThrows(() => re.exec("x"), TypeError); diff --git a/deps/v8/test/mjsunit/regexp-string-methods.js b/deps/v8/test/mjsunit/regexp-string-methods.js index fa01a33ce4..d5ad9c3386 100644 --- a/deps/v8/test/mjsunit/regexp-string-methods.js +++ b/deps/v8/test/mjsunit/regexp-string-methods.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: --no-harmony-regexp-exec - // Regexp shouldn't use String.prototype.slice() var s = new String("foo"); assertEquals("f", s.slice(0,1)); @@ -43,11 +41,3 @@ assertEquals("g", "foo".charAt(0)); var f2 = new RegExp("[g]", "i"); assertEquals(["G"], f2.exec("G")); assertTrue(f2.ignoreCase); - -// On the other hand test is defined in a semi-coherent way as a call to exec. -// 15.10.6.3 -// We match other browsers in using the original value of RegExp.prototype.exec. -// I.e., RegExp.prototype.test shouldn't use the current value of -// RegExp.prototype.exec. -RegExp.prototype.exec = function(string) { return 'x'; }; -assertFalse(/f/.test('x')); diff --git a/deps/v8/test/mjsunit/regress-604044.js b/deps/v8/test/mjsunit/regress-604044.js new file mode 100644 index 0000000000..58ccfbed99 --- /dev/null +++ b/deps/v8/test/mjsunit/regress-604044.js @@ -0,0 +1,7 @@ +// Copyright 2016 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: --min-preparse-length 1 + +(function(_ = function() {}){}) diff --git a/deps/v8/test/mjsunit/regress/regress-449070.js b/deps/v8/test/mjsunit/regress-crbug-619476.js index 7a0f0a838c..33204ae773 100644 --- a/deps/v8/test/mjsunit/regress/regress-449070.js +++ b/deps/v8/test/mjsunit/regress-crbug-619476.js @@ -1,10 +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: --allow-natives-syntax -try { - %NormalizeElements(this); -} catch(e) { -} +var x = {}; +// Crashes in debug mode if an erroneous DCHECK in dfb8d333 is not removed. +eval, x[eval]; diff --git a/deps/v8/test/mjsunit/regress/redeclaration-error-types.js b/deps/v8/test/mjsunit/regress/redeclaration-error-types.js new file mode 100644 index 0000000000..72e097db57 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/redeclaration-error-types.js @@ -0,0 +1,145 @@ +// Copyright 2016 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 doTest(scripts, expectedError) { + var realm = Realm.create(); + + for (var i = 0; i < scripts.length - 1; i++) { + Realm.eval(realm, scripts[i]); + } + assertThrows(function() { + Realm.eval(realm, scripts[scripts.length - 1]); + }, Realm.eval(realm, expectedError)); + + Realm.dispose(realm); +} + +var tests = [ + { + // ES#sec-globaldeclarationinstantiation 5.a: + // If envRec.HasVarDeclaration(name) is true, throw a SyntaxError + // exception. + scripts: [ + "var a;", + "let a;", + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-globaldeclarationinstantiation 6.a: + // If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + // exception. + scripts: [ + "let a;", + "var a;", + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-globaldeclarationinstantiation 5.b: + // If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + // exception. + scripts: [ + "let a;", + "let a;", + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-evaldeclarationinstantiation 5.a.i.1: + // If varEnvRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + // exception. + scripts: [ + 'let a; eval("var a;");', + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-evaldeclarationinstantiation 5.a.i.1: + // If varEnvRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + // exception. + scripts: [ + 'let a; eval("function a() {}");', + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-evaldeclarationinstantiation 5.d.ii.2.a.i: + // Throw a SyntaxError exception. + scripts: [ + '(function() { let a; eval("var a;"); })();', + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-evaldeclarationinstantiation 5.d.ii.2.a.i: + // Throw a SyntaxError exception. + scripts: [ + '(function() { let a; eval("function a() {}"); })();', + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-globaldeclarationinstantiation 5.d: + // If hasRestrictedGlobal is true, throw a SyntaxError exception. + scripts: [ + 'let NaN;', + ], + expectedError: "SyntaxError", + }, + { + // ES#sec-globaldeclarationinstantiation 5.d: + // If hasRestrictedGlobal is true, throw a SyntaxError exception. + scripts: [ + 'function NaN() {}', + ], + expectedError: "SyntaxError", + }, + + { + // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: + // If fnDefinable is false, throw a TypeError exception. + scripts: [ + 'eval("function NaN() {}");', + ], + expectedError: "TypeError", + }, + { + // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: + // If fnDefinable is false, throw a TypeError exception. + scripts: [ + ` + let a; + try { + eval("function a() {}"); + } catch (e) {} + eval("function NaN() {}"); + `, + ], + expectedError: "TypeError", + }, + { + // ES#sec-evaldeclarationinstantiation 8.a.iv.1.b: + // If fnDefinable is false, throw a TypeError exception. + scripts: [ + ` + eval(" + function f() { + function b() { + (0, eval)('function NaN() {}'); + } + b(); + } + f(); + "); + `.replace(/"/g, '`'), + ], + expectedError: "TypeError", + }, +]; + +tests.forEach(function(test) { + doTest(test.scripts, test.expectedError); +}); diff --git a/deps/v8/test/mjsunit/regress/regress-105.js b/deps/v8/test/mjsunit/regress/regress-105.js index 877cb82317..8b8030ffec 100644 --- a/deps/v8/test/mjsunit/regress/regress-105.js +++ b/deps/v8/test/mjsunit/regress/regress-105.js @@ -26,12 +26,12 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var custom_valueOf = function() { - assertEquals(null, custom_valueOf.caller); + assertEquals(Number, custom_valueOf.caller); return 2; } var custom_toString = function() { - assertEquals(null, custom_toString.caller); + assertEquals(String, custom_toString.caller); return "I used to be an adventurer like you"; } diff --git a/deps/v8/test/mjsunit/regress/regress-1132.js b/deps/v8/test/mjsunit/regress/regress-1132.js index a5cb0a1d5f..adb56b0fa8 100644 --- a/deps/v8/test/mjsunit/regress/regress-1132.js +++ b/deps/v8/test/mjsunit/regress/regress-1132.js @@ -28,7 +28,7 @@ // Test the case when exception is thrown from the parser when lazy // compiling a function. -// Flags: --stack-size=46 +// Flags: --stack-size=100 // NOTE: stack size constant above has been empirically chosen. // If the test starts to fail in Genesis, consider increasing this constant. diff --git a/deps/v8/test/mjsunit/regress/regress-1246.js b/deps/v8/test/mjsunit/regress/regress-1246.js deleted file mode 100644 index ca425ec2b7..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-1246.js +++ /dev/null @@ -1,82 +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. - -// This regression tests the behaviour of the parseInt function when -// the given radix is not a SMI. - -// Flags: --allow-natives-syntax - -var nonSmi10 = Math.log(Math.exp(10)); -var nonSmi16 = Math.log(Math.exp(16)); - -assertTrue(!%_IsSmi(nonSmi10) && nonSmi10 == 10); -assertTrue(!%_IsSmi(nonSmi16) && nonSmi16 == 16); - -// Giving these values as the radix argument triggers radix detection. -var radix_detect = [0, -0, NaN, Infinity, -Infinity, undefined, null, - "0", "-0", "a"]; - -// These values will result in an integer radix outside of the valid range. -var radix_invalid = [1, 37, -2, "-2", "37"]; - -// These values will trigger decimal parsing. -var radix10 = [10, 10.1, "10", "10.1", nonSmi10]; - -// These values will trigger hexadecimal parsing. -var radix16 = [16, 16.1, 0x10, "0X10", nonSmi16]; - -for (var i = 0; i < radix_detect.length; i++) { - var radix = radix_detect[i]; - assertEquals(NaN, parseInt("", radix)); - assertEquals(23, parseInt("23", radix)); - assertEquals(0xaf, parseInt("0xaf", radix)); - assertEquals(NaN, parseInt("af", radix)); -} - -for (var i = 0; i < radix_invalid.length; i++) { - var radix = radix_invalid[i]; - assertEquals(NaN, parseInt("", radix)); - assertEquals(NaN, parseInt("23", radix)); - assertEquals(NaN, parseInt("0xaf", radix)); - assertEquals(NaN, parseInt("af", radix)); -} - -for (var i = 0; i < radix10.length; i++) { - var radix = radix10[i]; - assertEquals(NaN, parseInt("", radix)); - assertEquals(23, parseInt("23", radix)); - assertEquals(0, parseInt("0xaf", radix)); - assertEquals(NaN, parseInt("af", radix)); -} - -for (var i = 0; i < radix16.length; i++) { - var radix = radix16[i]; - assertEquals(NaN, parseInt("", radix)); - assertEquals(0x23, parseInt("23", radix)); - assertEquals(0xaf, parseInt("0xaf", radix)); - assertEquals(0xaf, parseInt("af", radix)); -} diff --git a/deps/v8/test/mjsunit/regress/regress-1403.js b/deps/v8/test/mjsunit/regress/regress-1403.js index f2520ccbc9..91df6d65f6 100644 --- a/deps/v8/test/mjsunit/regress/regress-1403.js +++ b/deps/v8/test/mjsunit/regress/regress-1403.js @@ -28,7 +28,7 @@ // See: http://code.google.com/p/v8/issues/detail?id=1403 a = []; -Object.prototype.__proto__ = { __proto__: null }; +assertThrows(() => Object.prototype.__proto__ = { __proto__: null }, TypeError); a.shift(); a = []; diff --git a/deps/v8/test/mjsunit/regress/regress-1980.js b/deps/v8/test/mjsunit/regress/regress-1980.js index d87ff45074..e1e492b883 100644 --- a/deps/v8/test/mjsunit/regress/regress-1980.js +++ b/deps/v8/test/mjsunit/regress/regress-1980.js @@ -27,6 +27,8 @@ // See: http://code.google.com/p/v8/issues/detail?id=1980 +var msg = "Method Error.prototype.toString called on incompatible receiver "; + var invalid_this = [ "invalid", 23, undefined, null ]; for (var i = 0; i < invalid_this.length; i++) { var exception = false; @@ -34,7 +36,7 @@ for (var i = 0; i < invalid_this.length; i++) { Error.prototype.toString.call(invalid_this[i]); } catch (e) { exception = true; - assertEquals("Error.prototype.toString called on non-object", e.message); + assertEquals(msg + invalid_this[i], e.message); } assertTrue(exception); } diff --git a/deps/v8/test/mjsunit/regress/regress-2618.js b/deps/v8/test/mjsunit/regress/regress-2618.js index 6e52bcad78..2634c80c66 100644 --- a/deps/v8/test/mjsunit/regress/regress-2618.js +++ b/deps/v8/test/mjsunit/regress/regress-2618.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: --use-osr --allow-natives-syntax +// Flags: --use-osr --allow-natives-syntax --ignition-osr --turbo-from-bytecode function f() { do { diff --git a/deps/v8/test/mjsunit/regress/regress-3229.js b/deps/v8/test/mjsunit/regress/regress-3229.js index 419cade8cd..53e14cd541 100644 --- a/deps/v8/test/mjsunit/regress/regress-3229.js +++ b/deps/v8/test/mjsunit/regress/regress-3229.js @@ -12,7 +12,7 @@ testEscapes("\\/", /\//); testEscapes("\\/\\/", /\/\//); testEscapes("\\/", new RegExp("/")); testEscapes("\\/", new RegExp("\\/")); -testEscapes("\\\\/", new RegExp("\\\\/")); +testEscapes("\\\\\\/", new RegExp("\\\\/")); testEscapes("\\/\\/", new RegExp("\\/\\/")); testEscapes("\\/\\/\\/\\/", new RegExp("////")); testEscapes("\\/\\/\\/\\/", new RegExp("\\//\\//")); diff --git a/deps/v8/test/mjsunit/regress/regress-3315.js b/deps/v8/test/mjsunit/regress/regress-3315.js deleted file mode 100644 index bfd7df29b8..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-3315.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 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-object-observe - -var indexZeroCallCount = 0; -var indexOneCallCount = 0; -var lengthCallCount = 0; -var acceptList = { - get 0() { - indexZeroCallCount++; - return 'foo'; - }, - get 1() { - indexOneCallCount++; - return 'bar'; - }, - get length() { - lengthCallCount++; - return 1; - } -}; - -Object.observe({}, function(){}, acceptList); -assertEquals(1, lengthCallCount); -assertEquals(1, indexZeroCallCount); -assertEquals(0, indexOneCallCount); diff --git a/deps/v8/test/mjsunit/regress/regress-349870.js b/deps/v8/test/mjsunit/regress/regress-349870.js deleted file mode 100644 index 72df05524b..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-349870.js +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2014 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 r = /x/; -Object.freeze(r); -r.compile("x"); diff --git a/deps/v8/test/mjsunit/regress/regress-353004.js b/deps/v8/test/mjsunit/regress/regress-353004.js index 658fd6dbeb..7e1fb7e939 100644 --- a/deps/v8/test/mjsunit/regress/regress-353004.js +++ b/deps/v8/test/mjsunit/regress/regress-353004.js @@ -41,19 +41,21 @@ assertThrows(function() { var buffer5 = new ArrayBuffer(100 * 1024); -var buffer6 = buffer5.slice({valueOf : function() { - %ArrayBufferNeuter(buffer5); - return 0; -}}, 100 * 1024 * 1024); -assertEquals(0, buffer6.byteLength); +assertThrows(function() { + buffer5.slice({valueOf : function() { + %ArrayBufferNeuter(buffer5); + return 0; + }}, 100 * 1024 * 1024); +}, TypeError); var buffer7 = new ArrayBuffer(100 * 1024 * 1024); -var buffer8 = buffer7.slice(0, {valueOf : function() { - %ArrayBufferNeuter(buffer7); - return 100 * 1024 * 1024; -}}); -assertEquals(0, buffer8.byteLength); +assertThrows(function() { + buffer7.slice(0, {valueOf : function() { + %ArrayBufferNeuter(buffer7); + return 100 * 1024 * 1024; + }}); +}, TypeError); var buffer9 = new ArrayBuffer(1024); var array9 = new Uint8Array(buffer9); diff --git a/deps/v8/test/mjsunit/regress/regress-353551.js b/deps/v8/test/mjsunit/regress/regress-353551.js index c6e7856d34..ea5a234658 100644 --- a/deps/v8/test/mjsunit/regress/regress-353551.js +++ b/deps/v8/test/mjsunit/regress/regress-353551.js @@ -30,7 +30,7 @@ function __f_3(x) { var __v_1 = arguments; __v_1[1000] = 123; depth++; - if (depth > 3000) return; + if (depth > 2500) return; function __f_4() { ++__v_1[0]; __f_3(0.5); diff --git a/deps/v8/test/mjsunit/regress/regress-356589.js b/deps/v8/test/mjsunit/regress/regress-356589.js deleted file mode 100644 index a47f51bac1..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-356589.js +++ /dev/null @@ -1,36 +0,0 @@ -// 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: -// -// * 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: --harmony-object-observe - -// This test passes if it does not crash in debug mode - -arr = ['a', 'b', 'c', 'd']; -Object.defineProperty(arr.__proto__, '0', { get: function(){} }); -Object.defineProperty(arr, '2', {get: function(){} }); -Object.observe(arr, function() {}); -arr.length = 2; diff --git a/deps/v8/test/mjsunit/regress/regress-3926.js b/deps/v8/test/mjsunit/regress/regress-3926.js index 4720c1b908..4d9b2983d2 100644 --- a/deps/v8/test/mjsunit/regress/regress-3926.js +++ b/deps/v8/test/mjsunit/regress/regress-3926.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-sloppy --harmony-sloppy-let - // See: http://code.google.com/p/v8/issues/detail?id=3926 // Switch statements should disable hole check elimination diff --git a/deps/v8/test/mjsunit/regress/regress-403292.js b/deps/v8/test/mjsunit/regress/regress-403292.js deleted file mode 100644 index 2e24d48ac4..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-403292.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 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-natives-as=builtins --expose-gc - -var SetIterator = builtins.ImportNow("SetIterator"); -var MapIterator = builtins.ImportNow("MapIterator"); -var __v_7 = []; -var __v_8 = {}; -var __v_10 = {}; -var __v_11 = this; -var __v_12 = {}; -var __v_13 = {}; -var __v_14 = ""; -var __v_15 = {}; -try { -__v_1 = {x:0}; -%OptimizeFunctionOnNextCall(__f_1); -assertEquals("good", __f_1()); -delete __v_1.x; -assertEquals("good", __f_1()); -} catch(e) { print("Caught: " + e); } -try { -__v_3 = new Set(); -__v_5 = new SetIterator(__v_3, -12); -__v_4 = new Map(); -__v_6 = new MapIterator(__v_4, 2); -__f_3(Array); -} catch(e) { print("Caught: " + e); } -function __f_4(__v_8, filter) { - function __f_6(v) { - for (var __v_4 in v) { - for (var __v_4 in v) {} - } - %OptimizeFunctionOnNextCall(filter); - return filter(v); - } - var __v_7 = eval(__v_8); - gc(); - return __f_6(__v_7); -} -function __f_5(__v_6) { - var __v_5 = new Array(__v_6); - for (var __v_4 = 0; __v_4 < __v_6; __v_4++) __v_5.push('{}'); - return __v_5; -} -try { -try { - __v_8.test("\x80"); - assertUnreachable(); -} catch (e) { -} -gc(); -} catch(e) { print("Caught: " + e); } diff --git a/deps/v8/test/mjsunit/regress/regress-417709a.js b/deps/v8/test/mjsunit/regress/regress-417709a.js deleted file mode 100644 index 5500be2cf0..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-417709a.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2014 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-object-observe -// Flags: --stack-size=100 - -var a = []; - -Object.observe(a, function() {}); - -function f(a, x) { - a.length = x; - f(a, x + 1); -} - -assertThrows(function() { f(a, 1); }, RangeError); diff --git a/deps/v8/test/mjsunit/regress/regress-417709b.js b/deps/v8/test/mjsunit/regress/regress-417709b.js deleted file mode 100644 index 4d9572e7d7..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-417709b.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 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-object-observe --stack-size=100 - -var a = []; - -Array.observe(a, function() {}); - -function f(a, x) { - a.length = x; - f(a, x + 1); -} - -assertThrows(function() { f(a, 1); }, RangeError); diff --git a/deps/v8/test/mjsunit/regress/regress-4659.js b/deps/v8/test/mjsunit/regress/regress-4659.js index ff436bec1b..8992bb89fe 100644 --- a/deps/v8/test/mjsunit/regress/regress-4659.js +++ b/deps/v8/test/mjsunit/regress/regress-4659.js @@ -1,8 +1,6 @@ // Copyright 2016 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-function-name var obj = { get longerName(){ diff --git a/deps/v8/test/mjsunit/regress/regress-4665-2.js b/deps/v8/test/mjsunit/regress/regress-4665-2.js deleted file mode 100644 index b94301eea8..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-4665-2.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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-species - -// First test case - -function FirstBuffer () {} -FirstBuffer.prototype.__proto__ = Uint8Array.prototype -FirstBuffer.__proto__ = Uint8Array - -var buf = new Uint8Array(10) -buf.__proto__ = FirstBuffer.prototype - -var buf2 = buf.subarray(2) -assertEquals(8, buf2.length); - -// Second test case - -function SecondBuffer (arg) { - var arr = new Uint8Array(arg) - arr.__proto__ = SecondBuffer.prototype - return arr -} -SecondBuffer.prototype.__proto__ = Uint8Array.prototype -SecondBuffer.__proto__ = Uint8Array - -var buf3 = new SecondBuffer(10) - -var buf4 = buf3.subarray(2) - -assertEquals(8, buf4.length); diff --git a/deps/v8/test/mjsunit/regress/regress-4665.js b/deps/v8/test/mjsunit/regress/regress-4665.js index 9d7307acc7..a75d68f105 100644 --- a/deps/v8/test/mjsunit/regress/regress-4665.js +++ b/deps/v8/test/mjsunit/regress/regress-4665.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: --noharmony-species - // First test case function FirstBuffer () {} diff --git a/deps/v8/test/mjsunit/regress/regress-4693.js b/deps/v8/test/mjsunit/regress/regress-4693.js index 13b4e2b68e..2c31cd95e6 100644 --- a/deps/v8/test/mjsunit/regress/regress-4693.js +++ b/deps/v8/test/mjsunit/regress/regress-4693.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-sloppy-function // In sloppy mode we allow function redeclarations within blocks for webcompat. (function() { diff --git a/deps/v8/test/mjsunit/regress/regress-4703.js b/deps/v8/test/mjsunit/regress/regress-4703.js new file mode 100644 index 0000000000..dad8a97874 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4703.js @@ -0,0 +1,30 @@ +// Copyright 2016 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 listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var all_scopes = exec_state.frame().allScopes(); + assertEquals([ debug.ScopeType.Block, + debug.ScopeType.Local, + debug.ScopeType.Script, + debug.ScopeType.Global ], + all_scopes.map(scope => scope.scopeType())); + } catch (e) { + exception = e; + } +} + +debug.Debug.setListener(listener); + +(function(arg, ...rest) { + var one = 1; + function inner() { + one; + arg; + } + debugger; +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-4815.js b/deps/v8/test/mjsunit/regress/regress-4815.js new file mode 100644 index 0000000000..68764865f7 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4815.js @@ -0,0 +1,52 @@ +// Copyright 2016 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 thrower = { [Symbol.toPrimitive]: () => FAIL }; + +// Tests that a native conversion function is included in the +// stack trace. +function testTraceNativeConversion(nativeFunc) { + var nativeFuncName = nativeFunc.name; + try { + nativeFunc(thrower); + assertUnreachable(nativeFuncName); + } catch (e) { + assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); + } +} + +// C++ builtins. +testTraceNativeConversion(Math.acos); +testTraceNativeConversion(Math.asin); +testTraceNativeConversion(Math.fround); +testTraceNativeConversion(Math.imul); + + +function testBuiltinInStackTrace(script, expectedString) { + try { + eval(script); + assertUnreachable(expectedString); + } catch (e) { + assertTrue(e.stack.indexOf(expectedString) >= 0, expectedString); + } +} + +// C++ builtins. +testBuiltinInStackTrace("Boolean.prototype.toString.call(thrower);", + "at Object.toString"); + +// Constructor builtins. +testBuiltinInStackTrace("new Date(thrower);", "at new Date"); + +// Ensure we correctly pick up the receiver's string tag. +testBuiltinInStackTrace("Math.acos(thrower);", "at Math.acos"); +testBuiltinInStackTrace("Math.asin(thrower);", "at Math.asin"); +testBuiltinInStackTrace("Math.fround(thrower);", "at Math.fround"); +testBuiltinInStackTrace("Math.imul(thrower);", "at Math.imul"); + +// As above, but function passed as an argument and then called. +testBuiltinInStackTrace("((f, x) => f(x))(Math.acos, thrower);", "at acos"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.asin, thrower);", "at asin"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.fround, thrower);", "at fround"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.imul, thrower);", "at imul"); diff --git a/deps/v8/test/mjsunit/regress/regress-4908.js b/deps/v8/test/mjsunit/regress/regress-4908.js new file mode 100644 index 0000000000..ec618b32c5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4908.js @@ -0,0 +1,7 @@ +// Copyright 2016 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: --always-opt --no-lazy + +(function() { ((s = 17, y = s) => s)() })(); diff --git a/deps/v8/test/mjsunit/regress/regress-4945.js b/deps/v8/test/mjsunit/regress/regress-4945.js new file mode 100644 index 0000000000..8e595e6fde --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4945.js @@ -0,0 +1,10 @@ +// Copyright 2016 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* g(o) { + yield 'x' in o; +} + +assertTrue(g({x: 1}).next().value); +assertFalse(g({}).next().value); diff --git a/deps/v8/test/mjsunit/regress/regress-4964.js b/deps/v8/test/mjsunit/regress/regress-4964.js new file mode 100644 index 0000000000..d834708667 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4964.js @@ -0,0 +1,22 @@ +// Copyright 2016 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 + +// Neutered source +var ab = new ArrayBuffer(10); +ab.constructor = { get [Symbol.species]() { %ArrayBufferNeuter(ab); return ArrayBuffer; } }; +assertThrows(() => ab.slice(0), TypeError); + +// Neutered target +class NeuteredArrayBuffer extends ArrayBuffer { + constructor(...args) { + super(...args); + %ArrayBufferNeuter(this); + } +} + +var ab2 = new ArrayBuffer(10); +ab2.constructor = NeuteredArrayBuffer; +assertThrows(() => ab2.slice(0), TypeError); diff --git a/deps/v8/test/mjsunit/regress/regress-4967.js b/deps/v8/test/mjsunit/regress/regress-4967.js new file mode 100644 index 0000000000..9b36405cf4 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4967.js @@ -0,0 +1,9 @@ +// Copyright 2016 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. + +assertThrows(() => { + new class extends Object { + constructor() { (() => delete super[super()])(); } + } +}, ReferenceError); diff --git a/deps/v8/test/mjsunit/regress/regress-4971.js b/deps/v8/test/mjsunit/regress/regress-4971.js new file mode 100644 index 0000000000..041f6c2a57 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4971.js @@ -0,0 +1,41 @@ +// Copyright 2016 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 TestDeoptInNamedSuperGetter() { + class C { m() { return 23 } } + class D extends C { f() { return super.boom() } } + + var should_deoptimize_caller = false; + Object.defineProperty(C.prototype, "boom", { get: function() { + if (should_deoptimize_caller) %DeoptimizeFunction(D.prototype.f); + return this.m + }}) + + assertEquals(23, new D().f()); + assertEquals(23, new D().f()); + %OptimizeFunctionOnNextCall(D.prototype.f); + assertEquals(23, new D().f()); + should_deoptimize_caller = true; + assertEquals(23, new D().f()); +})(); + +(function TestDeoptInKeyedSuperGetter() { + class C { m() { return 23 } } + class D extends C { f(name) { return super[name]() } } + + var should_deoptimize_caller = false; + Object.defineProperty(C.prototype, "boom", { get: function() { + if (should_deoptimize_caller) %DeoptimizeFunction(D.prototype.f); + return this.m + }}) + + assertEquals(23, new D().f("boom")); + assertEquals(23, new D().f("boom")); + %OptimizeFunctionOnNextCall(D.prototype.f); + assertEquals(23, new D().f("boom")); + should_deoptimize_caller = true; + assertEquals(23, new D().f("boom")); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-5004.js b/deps/v8/test/mjsunit/regress/regress-5004.js new file mode 100644 index 0000000000..234f5d4eb6 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5004.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: --allow-natives-syntax + +function assertAsync(b, s) { + if (!b) { + %AbortJS(" FAILED!") + } +} + +class P extends Promise { + constructor() { + super(...arguments) + return new Proxy(this, { + get: (_, key) => { + return key == 'then' ? + this.then.bind(this) : + this.constructor.resolve(20) + } + }) + } +} + +let p = P.resolve(10) +p.key.then(v => assertAsync(v === 20)); diff --git a/deps/v8/test/mjsunit/regress/regress-5018.js b/deps/v8/test/mjsunit/regress/regress-5018.js new file mode 100644 index 0000000000..22025dc2d8 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5018.js @@ -0,0 +1,29 @@ +// Copyright 2016 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 dv = new DataView(new ArrayBuffer(4), 2); + +function getByteLength(a) { + return a.byteLength; +} + +assertEquals(2, getByteLength(dv)); +assertEquals(2, getByteLength(dv)); + +Object.defineProperty(dv.__proto__, 'byteLength', {value: 42}); + +assertEquals(42, dv.byteLength); +assertEquals(42, getByteLength(dv)); + +function getByteOffset(a) { + return a.byteOffset; +} + +assertEquals(2, getByteOffset(dv)); +assertEquals(2, getByteOffset(dv)); + +Object.defineProperty(dv.__proto__, 'byteOffset', {value: 42}); + +assertEquals(42, dv.byteOffset); +assertEquals(42, getByteOffset(dv)); diff --git a/deps/v8/test/mjsunit/regress/regress-5036.js b/deps/v8/test/mjsunit/regress/regress-5036.js index 036edd949f..77bd242490 100644 --- a/deps/v8/test/mjsunit/regress/regress-5036.js +++ b/deps/v8/test/mjsunit/regress/regress-5036.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-unicode-regexps - assertEquals(["1\u212a"], /\d\w/ui.exec("1\u212a")); diff --git a/deps/v8/test/mjsunit/regress/regress-5071.js b/deps/v8/test/mjsunit/regress/regress-5071.js new file mode 100644 index 0000000000..41c1250031 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5071.js @@ -0,0 +1,26 @@ +// Copyright 2016 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; + +function listener(event, exec_state, event_data, data) { + assertEquals(2, exec_state.frameCount()); + assertEquals("a", exec_state.frame(0).localName(0)); + assertEquals("1", exec_state.frame(0).localValue(0).value()); + assertEquals(1, exec_state.frame(0).localCount()); +} + +Debug.setListener(listener); + +function f() { + var a = 1; + { + let b = 2; + debugger; + } +} + +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-5085.js b/deps/v8/test/mjsunit/regress/regress-5085.js new file mode 100644 index 0000000000..0ed034dc2d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5085.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { + return x instanceof Proxy; +} + +assertFalse(foo({})); +assertFalse(foo({})); +%OptimizeFunctionOnNextCall(foo); +assertFalse(foo({})); diff --git a/deps/v8/test/mjsunit/regress/regress-5106.js b/deps/v8/test/mjsunit/regress/regress-5106.js new file mode 100644 index 0000000000..52d550a878 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5106.js @@ -0,0 +1,29 @@ +// Copyright 2016 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* g1() { + try { + throw {}; + } catch ({a = class extends (yield) {}}) { + } +} +g1().next(); // crashes without fix + +function* g2() { + let x = function(){}; + try { + throw {}; + } catch ({b = class extends x {}}) { + } +} +g2().next(); // crashes without fix + +function* g3() { + let x = 42; + try { + throw {}; + } catch ({c = (function() { return x })()}) { + } +} +g3().next(); // throws a ReferenceError without fix diff --git a/deps/v8/test/mjsunit/regress/regress-5164.js b/deps/v8/test/mjsunit/regress/regress-5164.js new file mode 100644 index 0000000000..5c13937821 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5164.js @@ -0,0 +1,44 @@ +// Copyright 2016 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 failure = null; +var args; + +function listener(event, exec_state, event_data, data) { + if (event != debug.Debug.DebugEvent.Break) return; + try { + args = exec_state.frame(0).evaluate('arguments').value(); + } catch (e) { + failure = e; + } +} + +debug.Debug.setListener(listener); + +function* gen(a, b) { + debugger; + yield a; + yield b; +} + +var foo = gen(1, 2); + +foo.next() +assertEquals(2, args.length); +assertEquals(undefined, args[0]); +assertEquals(undefined, args[1]); + +foo.next() +assertEquals(2, args.length); +assertEquals(undefined, args[0]); +assertEquals(undefined, args[1]); + +foo.next() +assertEquals(2, args.length); +assertEquals(undefined, args[0]); +assertEquals(undefined, args[1]); + +assertNull(failure); diff --git a/deps/v8/test/mjsunit/regress/regress-5173.js b/deps/v8/test/mjsunit/regress/regress-5173.js new file mode 100644 index 0000000000..74f58cc473 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5173.js @@ -0,0 +1,51 @@ +// Copyright 2016 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 thrower = { [Symbol.toPrimitive]: () => FAIL }; + +// Tests that a native conversion function is included in the +// stack trace. +function testTraceNativeConversion(nativeFunc) { + var nativeFuncName = nativeFunc.name; + try { + nativeFunc(thrower); + assertUnreachable(nativeFuncName); + } catch (e) { + assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); + } +} + +testTraceNativeConversion(Math.max); +testTraceNativeConversion(Math.min); + +function testBuiltinInStackTrace(script, expectedString) { + try { + eval(script); + assertUnreachable(expectedString); + } catch (e) { + assertTrue(e.stack.indexOf(expectedString) >= 0, expectedString); + } +} + +testBuiltinInStackTrace("Date.prototype.getDate.call('')", "at String.getDate"); +testBuiltinInStackTrace("Date.prototype.getUTCDate.call('')", + "at String.getUTCDate"); +testBuiltinInStackTrace("Date.prototype.getTime.call('')", "at String.getTime"); + +testBuiltinInStackTrace("Number(thrower);", "at Number"); +testBuiltinInStackTrace("new Number(thrower);", "at new Number"); +testBuiltinInStackTrace("String(thrower);", "at String"); +testBuiltinInStackTrace("new String(thrower);", "at new String"); + +// Ensure we correctly pick up the receiver's string tag. +testBuiltinInStackTrace("Math.acos(thrower);", "at Math.acos"); +testBuiltinInStackTrace("Math.asin(thrower);", "at Math.asin"); +testBuiltinInStackTrace("Math.fround(thrower);", "at Math.fround"); +testBuiltinInStackTrace("Math.imul(thrower);", "at Math.imul"); + +// As above, but function passed as an argument and then called. +testBuiltinInStackTrace("((f, x) => f(x))(Math.acos, thrower);", "at acos"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.asin, thrower);", "at asin"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.fround, thrower);", "at fround"); +testBuiltinInStackTrace("((f, x) => f(x))(Math.imul, thrower);", "at imul"); diff --git a/deps/v8/test/mjsunit/regress/regress-5174.js b/deps/v8/test/mjsunit/regress/regress-5174.js new file mode 100644 index 0000000000..390d24e682 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5174.js @@ -0,0 +1,6 @@ +// Copyright 2016 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. + +assertEquals([], Object.keys(new Proxy([], {}))); +assertEquals([], Object.keys(new Proxy(/regex/, {}))); diff --git a/deps/v8/test/mjsunit/regress/regress-5178.js b/deps/v8/test/mjsunit/regress/regress-5178.js new file mode 100644 index 0000000000..cf10ae7187 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5178.js @@ -0,0 +1,9 @@ +// Copyright 2016 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. + +assertThrows(() => { + try { throw {} } catch({a=b, b}) { a+b } +}, ReferenceError); + +try { throw {a: 42} } catch({a, b=a}) { assertEquals(42, b) }; diff --git a/deps/v8/test/mjsunit/regress/regress-5181.js b/deps/v8/test/mjsunit/regress/regress-5181.js new file mode 100644 index 0000000000..d8dfc4a0b6 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5181.js @@ -0,0 +1,11 @@ +// Copyright 2016 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 target = Object.create(null); +var proxy = new Proxy(target, { + ownKeys: function() { + return ['a']; + } +}); +for (var key in proxy) ; diff --git a/deps/v8/test/mjsunit/regress/regress-520029.js b/deps/v8/test/mjsunit/regress/regress-520029.js index 299dd75017..9a1d200307 100644 --- a/deps/v8/test/mjsunit/regress/regress-520029.js +++ b/deps/v8/test/mjsunit/regress/regress-520029.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-sloppy-let --harmony-sloppy - // Test that hoisting a function out of a lexical scope does not // lead to a parsing error diff --git a/deps/v8/test/mjsunit/regress/regress-5205.js b/deps/v8/test/mjsunit/regress/regress-5205.js new file mode 100644 index 0000000000..0d88f45053 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5205.js @@ -0,0 +1,37 @@ +// Copyright 2016 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 --gc-global + +(function TestGCDuringToObjectForWith() { + function f(o) { + if (o == 'warmup') { return g() } + with (o) { return x } + } + function g() { + // Only a marker function serving as weak embedded object. + } + + // Warm up 'f' so that weak embedded object 'g' will be used. + f('warmup'); + f('warmup'); + g = null; + + // Test that 'f' behaves correctly unoptimized. + assertEquals(23, f({ x:23 })); + assertEquals(42, f({ x:42 })); + + // Test that 'f' behaves correctly optimized. + %OptimizeFunctionOnNextCall(f); + assertEquals(65, f({ x:65 })); + + // Test that 'f' behaves correctly on numbers. + Number.prototype.x = 99; + assertEquals(99, f(0)); + + // Make sure the next [[ToObject]] allocation triggers GC. This in turn will + // deoptimize 'f' because it has the weak embedded object 'g' in the code. + %SetAllocationTimeout(1000, 1, false); + assertEquals(99, f(0)); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-5207.js b/deps/v8/test/mjsunit/regress/regress-5207.js new file mode 100644 index 0000000000..1472b541b5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5207.js @@ -0,0 +1,30 @@ +// Copyright 2012 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; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var scopes = exec_state.frame(0).allScopes(); + assertEquals(debug.ScopeType.Eval, scopes[0].scopeType()); + assertEquals(1, scopes[0].scopeObject().value().a); + assertEquals(debug.ScopeType.Script, scopes[1].scopeType()); + assertEquals(undefined, scopes[1].scopeObject().value().a); + assertEquals(debug.ScopeType.Global, scopes[2].scopeType()); + assertEquals(undefined, scopes[2].scopeObject().value().a); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); +// Eval inherits strict mode. +eval("var a = 1; debugger;"); +Debug.setListener(null); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/regress/regress-5213.js b/deps/v8/test/mjsunit/regress/regress-5213.js new file mode 100644 index 0000000000..831e1346d8 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5213.js @@ -0,0 +1,8 @@ +// Copyright 2016 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. + +// See http://code.google.com/p/v8/issues/detail?id=5213 + +assertEquals(0, Math.pow(2,-2147483648)); +assertEquals(0, Math.pow(2,-9223372036854775808)); diff --git a/deps/v8/test/mjsunit/regress/regress-5214.js b/deps/v8/test/mjsunit/regress/regress-5214.js new file mode 100644 index 0000000000..f90a590253 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5214.js @@ -0,0 +1,10 @@ +// Copyright 2016 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. + +// See http://code.google.com/p/v8/issues/detail?id=5214 + + +assertEquals(Infinity, Math.pow(2, 0x80000000)); +assertEquals(Infinity, Math.pow(2, 0xc0000000)); +assertEquals(0, Math.pow(2, -0x80000000)); diff --git a/deps/v8/test/mjsunit/harmony/regexp-no-change-exec.js b/deps/v8/test/mjsunit/regress/regress-5216.js index 30b5050945..9097310fc2 100644 --- a/deps/v8/test/mjsunit/harmony/regexp-no-change-exec.js +++ b/deps/v8/test/mjsunit/regress/regress-5216.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: --no-harmony-regexp-exec +// Ensure that custom error constructors don't show up in stack traces. class MyError extends Error { } -RegExp.prototype.exec = () => { throw new MyError() }; -assertEquals(null, "foo".match(/bar/)); +assertFalse(new MyError().stack.includes("at MyError")); diff --git a/deps/v8/test/mjsunit/regress/regress-5245.js b/deps/v8/test/mjsunit/regress/regress-5245.js new file mode 100644 index 0000000000..9c4f6e7dbd --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5245.js @@ -0,0 +1,24 @@ +// Copyright 2016 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"; + +// After captureStackTrace. + +var a = {}; +Error.captureStackTrace(a, Error); +a.stack = 1; // Should not throw, stack should be writable. + +// After the standard Error constructor. + +var b = new Error(); +b.stack = 1; // Should not throw, stack should be writable. +b.stack = 1; // Still writable. + +// After read access to stack. + +var c = new Error(); +var old_stack = c.stack; +c.stack = 1; // Should not throw, stack should be writable. +c.stack = 1; // Still writable. diff --git a/deps/v8/test/mjsunit/regress/regress-5252.js b/deps/v8/test/mjsunit/regress/regress-5252.js new file mode 100644 index 0000000000..682d3193ea --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5252.js @@ -0,0 +1,31 @@ +// Copyright 2016 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 --ignition --ignition-osr --turbo-from-bytecode + +(function TestNonLoopyLoop() { + function f() { + do { + %OptimizeOsr(); + return 23; + } while(false) + } + assertEquals(23, f()); + assertEquals(23, f()); +})(); + +(function TestNonLoopyGenerator() { + function* g() { + do { + %OptimizeOsr(); + yield 23; + yield 42; + } while(false) + return 999; + } + var gen = g(); + assertEquals({ value:23, done:false }, gen.next()); + assertEquals({ value:42, done:false }, gen.next()); + assertEquals({ value:999, done:true }, gen.next()); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-5262.js b/deps/v8/test/mjsunit/regress/regress-5262.js new file mode 100644 index 0000000000..394bb49ca5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5262.js @@ -0,0 +1,25 @@ +// Copyright 2016 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: --ignition --ignition-osr --turbo-from-bytecode --allow-natives-syntax + +function g() { return 23 } +function h() { return 42 } +function boom(o) { o.g = h } +function f(osr_and_recurse) { + if (osr_and_recurse) { + for (var i = 0; i < 3; ++i) { + if (i == 1) %OptimizeOsr(); + } + %OptimizeFunctionOnNextCall(f); + f(false); // Trigger tier-up due to recursive call. + boom(this); // Causes a deopt due to below dependency. + var x = g(); // Install dependency on the {g} function. + return x; + } + return 65; +} +assertEquals(65, f(false)); +assertEquals(65, f(false)); +assertEquals(42, f(true)); diff --git a/deps/v8/test/mjsunit/regress/regress-5275-1.js b/deps/v8/test/mjsunit/regress/regress-5275-1.js new file mode 100644 index 0000000000..542bae0602 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5275-1.js @@ -0,0 +1,18 @@ +// Copyright 2016 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(x) { + var a = new Array(1); + a[0] = x; + return a; +} + +assertEquals([1], foo(1)); +assertEquals([1], foo(1)); +%OptimizeFunctionOnNextCall(foo); +assertEquals([1], foo(1)); +Array.prototype.__defineSetter__("0", function() {}); +assertEquals([undefined], foo(1)); diff --git a/deps/v8/test/mjsunit/regress/regress-5275-2.js b/deps/v8/test/mjsunit/regress/regress-5275-2.js new file mode 100644 index 0000000000..2da422de97 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5275-2.js @@ -0,0 +1,18 @@ +// Copyright 2016 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(x) { + var a = new Array(1); + a[0] = x; + return a; +} + +assertEquals([1], foo(1)); +assertEquals([1], foo(1)); +%OptimizeFunctionOnNextCall(foo); +assertEquals([1], foo(1)); +Object.prototype.__defineSetter__("0", function() {}); +assertEquals([undefined], foo(1)); diff --git a/deps/v8/test/mjsunit/regress/regress-5279.js b/deps/v8/test/mjsunit/regress/regress-5279.js new file mode 100644 index 0000000000..847f5df054 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5279.js @@ -0,0 +1,16 @@ +// Copyright 2016 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-debug-as debug + +var Debug = debug.Debug; + +Debug.setListener(() => undefined); + +const myObj = {}; + +for (let i = 0; i < 10; i++) { + %OptimizeOsr(); + %ScheduleBreak(); +} diff --git a/deps/v8/test/mjsunit/regress/regress-5286.js b/deps/v8/test/mjsunit/regress/regress-5286.js new file mode 100644 index 0000000000..210d986a66 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5286.js @@ -0,0 +1,41 @@ +// Copyright 2016 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() { + function foo(x, y) { return x % y; } + + assertEquals(0, foo(2, 2)); + assertEquals(0, foo(4, 4)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-0, foo(-8, 8)); +})(); + +(function() { + function foo(x, y) { return x % y; } + + assertEquals(0, foo(1, 1)); + assertEquals(0, foo(2, 2)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-0, foo(-3, 3)); +})(); + +(function() { + function foo(x, y) { return x % y; } + + assertEquals(0, foo(1, 1)); + assertEquals(0, foo(2, 2)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-0, foo(-2147483648, -1)); +})(); + +(function() { + function foo(x, y) { return x % y; } + + assertEquals(0, foo(1, 1)); + assertEquals(0, foo(2, 2)); + %OptimizeFunctionOnNextCall(foo); + assertEquals(-0, foo(-2147483648, -2147483648)); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-5342.js b/deps/v8/test/mjsunit/regress/regress-5342.js new file mode 100644 index 0000000000..8cdd808622 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-5342.js @@ -0,0 +1,7 @@ +// Copyright 2016 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 o = {} +Error.captureStackTrace(o); +assertEquals(-1, o.stack.indexOf("captureStackTrace")); diff --git a/deps/v8/test/mjsunit/regress/regress-536751.js b/deps/v8/test/mjsunit/regress/regress-536751.js index 0707e008ea..a63fae3957 100644 --- a/deps/v8/test/mjsunit/regress/regress-536751.js +++ b/deps/v8/test/mjsunit/regress/regress-536751.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-sloppy --harmony-sloppy-function --harmony-sloppy-let // Flags: --no-harmony-restrictive-declarations // At some point, this code led to DCHECK errors in debug mode diff --git a/deps/v8/test/mjsunit/regress/regress-542099.js b/deps/v8/test/mjsunit/regress/regress-542099.js index eef49538cc..6345fd468a 100644 --- a/deps/v8/test/mjsunit/regress/regress-542099.js +++ b/deps/v8/test/mjsunit/regress/regress-542099.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-sloppy --harmony-sloppy-function // Flags: --no-harmony-restrictive-declarations // Previously, this caused a CHECK fail in debug mode diff --git a/deps/v8/test/mjsunit/regress/regress-542100.js b/deps/v8/test/mjsunit/regress/regress-542100.js index 70fb5dc147..c16e6284fa 100644 --- a/deps/v8/test/mjsunit/regress/regress-542100.js +++ b/deps/v8/test/mjsunit/regress/regress-542100.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-sloppy --harmony-sloppy-function // Flags: --no-harmony-restrictive-declarations (function() { diff --git a/deps/v8/test/mjsunit/regress/regress-544991.js b/deps/v8/test/mjsunit/regress/regress-544991.js index 911d8acc89..a9fd809a3b 100644 --- a/deps/v8/test/mjsunit/regress/regress-544991.js +++ b/deps/v8/test/mjsunit/regress/regress-544991.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-species - 'use strict'; var typedArray = new Int8Array(1); diff --git a/deps/v8/test/mjsunit/regress/regress-575364.js b/deps/v8/test/mjsunit/regress/regress-575364.js index c0652058fa..8671aec06b 100644 --- a/deps/v8/test/mjsunit/regress/regress-575364.js +++ b/deps/v8/test/mjsunit/regress/regress-575364.js @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm +// Flags: --expose-wasm --validate-asm --allow-natives-syntax function f() { "use asm"; } assertFalse(Wasm == undefined); -assertThrows(function() { Wasm.instantiateModuleFromAsm(f.toString()); }); +assertTrue(%IsNotAsmWasmCode(f)); diff --git a/deps/v8/test/mjsunit/regress/regress-585041.js b/deps/v8/test/mjsunit/regress/regress-585041.js new file mode 100644 index 0000000000..c072ed2a15 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-585041.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 f(arr, i) { + arr[i] = 50; +} + +function boom(dummy) { + var arr = new Array(10); + f(arr, 10); + if (dummy) { + f(arr, -2147483648); + } +} + +boom(false); +%OptimizeFunctionOnNextCall(boom); +boom(false); diff --git a/deps/v8/test/mjsunit/regress/regress-592352.js b/deps/v8/test/mjsunit/regress/regress-592352.js new file mode 100644 index 0000000000..7947fdba2c --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-592352.js @@ -0,0 +1,20 @@ +// Copyright 2016 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 --validate-asm + +function __f_76() { + "use asm"; + function __f_72() { + %OptimizeFunctionOnNextCall(); + } + return {__f_72:__f_72}; +} + +try { + assertTrue(%IsAsmWasmCode(__f_76)); + assertTrue(false); +} catch (e) { + print("Caught: " + e); +} diff --git a/deps/v8/test/mjsunit/regress/regress-599068-func-bindings.js b/deps/v8/test/mjsunit/regress/regress-599068-func-bindings.js new file mode 100644 index 0000000000..887c00099a --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-599068-func-bindings.js @@ -0,0 +1,45 @@ +// Copyright 2016 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 + +// Tests function bindings are correctly handled in ignition. +(function f() { + function assignSloppy() { + f = 0; + } + assertDoesNotThrow(assignSloppy); + + function assignStrict() { + 'use strict'; + f = 0; + } + assertThrows(assignStrict, TypeError); + + function assignStrictLookup() { + eval("'use strict'; f = 1;"); + } + assertThrows(assignStrictLookup, TypeError); +})(); + +// Tests for compound assignments which are handled differently +// in crankshaft. +(function f() { + function assignSloppy() { + f += "x"; + } + assertDoesNotThrow(assignSloppy); + assertDoesNotThrow(assignSloppy); + %OptimizeFunctionOnNextCall(assignSloppy); + assertDoesNotThrow(assignSloppy); + + function assignStrict() { + 'use strict'; + f += "x"; + } + assertThrows(assignStrict, TypeError); + assertThrows(assignStrict, TypeError); + %OptimizeFunctionOnNextCall(assignStrict); + assertThrows(assignStrict, TypeError); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-599717.js b/deps/v8/test/mjsunit/regress/regress-599717.js new file mode 100644 index 0000000000..51831860e9 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-599717.js @@ -0,0 +1,26 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function __f_61(stdlib, foreign, buffer) { + "use asm"; + var __v_14 = new stdlib.Float64Array(buffer); + function __f_74() { + var __v_35 = 6.0; + __v_14[2] = __v_35 + 1.0; + } + return {__f_74: __f_74}; +} +var ok = false; +try { + var __v_12 = new ArrayBuffer(2147483648); + ok = true; +} catch (e) { + // Can happen on 32 bit systems. +} +if (ok) { + var module = __f_61(this, null, __v_12); + assertTrue(%IsAsmWasmCode(__f_61)); +} diff --git a/deps/v8/test/mjsunit/regress/regress-599719.js b/deps/v8/test/mjsunit/regress/regress-599719.js new file mode 100644 index 0000000000..cdd30991b0 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-599719.js @@ -0,0 +1,25 @@ +// Copyright 2016 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 --validate-asm + +function __f_7() { + %DeoptimizeFunction(__f_5); +} +function __f_8(global, env) { + "use asm"; + var __f_7 = env.__f_7; + function __f_9(i4, i5) { + i4 = i4 | 0; + i5 = i5 | 0; + __f_7(); + } + return {'__f_9': __f_9} +} +function __f_5() { + var __v_5 = __f_8({}, {'__f_7': __f_7}); + assertTrue(%IsAsmWasmCode(__f_8)); + __v_5.__f_9(0, 0, 0); +} +__f_5(); diff --git a/deps/v8/test/mjsunit/regress/regress-599825.js b/deps/v8/test/mjsunit/regress/regress-599825.js index 83075ee9ab..a878eb49c9 100644 --- a/deps/v8/test/mjsunit/regress/regress-599825.js +++ b/deps/v8/test/mjsunit/regress/regress-599825.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax function __f_97(stdlib, buffer) { "use asm"; @@ -12,6 +12,5 @@ function __f_97(stdlib, buffer) { __v_30[__v_27 >> __v_2] = ((__v_30[-1073741825]|-10) + 2) | 0; } } -assertThrows(function() { - var module = Wasm.instantiateModuleFromAsm( __f_97.toString()); -}); +var module = __f_97(this); +assertTrue(%IsNotAsmWasmCode(__f_97)); diff --git a/deps/v8/test/mjsunit/regress/regress-605470.js b/deps/v8/test/mjsunit/regress/regress-605470.js new file mode 100644 index 0000000000..722e8ae130 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-605470.js @@ -0,0 +1,17 @@ +// Copyright 2016 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: --ignition + +function function_with_m_args(m) { + var source = '(function f() { return; })('; + for (var arg = 0; arg < m ; arg++) { + if (arg != 0) source += ','; + source += arg; + } + source += ')'; + return eval(source); +} + +function_with_m_args(0x7FFF); diff --git a/deps/v8/test/mjsunit/regress/regress-606021.js b/deps/v8/test/mjsunit/regress/regress-606021.js new file mode 100644 index 0000000000..54b283efc4 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-606021.js @@ -0,0 +1,32 @@ +// Copyright 2016 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() { + return function(c) { + var double_var = [3.0, 3.5][0]; + var literal = c ? [1, double_var] : [double_var, 3.5]; + return literal[0]; + }; +} + +var f1 = foo(); +var f2 = foo(); + +// Both closures point to full code. +f1(false); +f2(false); + +// Optimize f1, but don't initialize the [1, double_var] literal. +%OptimizeFunctionOnNextCall(f1); +f1(false); + +// Initialize the [1, double_var] literal, and transition the boilerplate to +// double. +f2(true); + +// Trick crankshaft into writing double_var at the wrong position. +var l = f1(true); +assertEquals(1, l); diff --git a/deps/v8/test/mjsunit/regress/regress-608630.js b/deps/v8/test/mjsunit/regress/regress-608630.js new file mode 100644 index 0000000000..58a95af7c3 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-608630.js @@ -0,0 +1,71 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +var __v_5 = {}; +var __v_35 = {}; +var __v_44 = {}; +var __v_43 = {}; + +try { +__v_1 = 1; +__v_2 = { + get: function() { return function() {} }, + has() { return true }, + getOwnPropertyDescriptor: function() { + if (__v_1-- == 0) throw "please die"; + return {value: function() {}, configurable: true}; + } +}; +__v_3 = new Proxy({}, __v_2); +__v_30 = Object.create(__v_35); +with (__v_5) { f() } +} catch(e) { print("Caught: " + e); } + +function __f_1(asmfunc, expect) { + var __v_1 = asmfunc.toString(); + var __v_2 = __v_1.replace(new RegExp("use asm"), ""); + var __v_39 = {Math: Math}; + var __v_4 = eval("(" + __v_2 + ")")(__v_3); + print("Testing " + asmfunc.name + " (js)..."); + __v_44.valueOf = __v_43; + expect(__v_4); + print("Testing " + asmfunc.name + " (asm.js)..."); + var __v_5 = asmfunc(__v_3); + expect(__v_5); + print("Testing " + asmfunc.name + " (wasm)..."); + var module_func = eval(__v_1); + var __v_6 = module_func({}, __v_3); + assertTrue(%IsAsmWasmCode(module_func)); + expect(__v_6); +} +function __f_2() { + "use asm"; + function __f_3() { return 0; } + function __f_4() { return 1; } + function __f_5() { return 4; } + function __f_6() { return 64; } + function __f_7() { return 137; } + function __f_8() { return 128; } + function __f_9() { return -1; } + function __f_10() { return 1000; } + function __f_11() { return 2000000; } + function __f_12() { return 2147483647; } + return {__f_3: __f_3, __f_4: __f_4, __f_5: __f_5, __f_6: __f_6, __f_7: __f_7, __f_8: __f_8, + __f_9: __f_9, __f_10: __f_10, __f_11, __f_12: __f_12}; +} +try { +__f_1(__f_2, function(module) { + assertEquals(0, module.__f_3()); + assertEquals(1, module.__f_4()); + assertEquals(4, module.__f_5()); + assertEquals(64, module.__f_6()); + assertEquals(128, module.__f_8()); + assertEquals(-1, module.__f_9()); + assertEquals(1000, module.__f_10()); + assertEquals(2000000, module.__f_11()); + assertEquals(2147483647, module.__f_12()); +}); +} catch(e) { print("Caught: " + e); } diff --git a/deps/v8/test/mjsunit/regress/regress-610633.js b/deps/v8/test/mjsunit/regress/regress-610633.js new file mode 100644 index 0000000000..8ee0e7ed43 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-610633.js @@ -0,0 +1,40 @@ +// Copyright 2016 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 getLength(a) { + return a.length; +} + +function getByteLength(a) { + return a.byteLength; +} + +function getByteOffset(a) { + return a.byteOffset; +} + +var a = new Uint8Array([1, 2, 3]); +getLength(a); +getLength(a); + +Object.defineProperty(a.__proto__, 'length', {value: 42}); + +assertEquals(42, getLength(a)); +assertEquals(42, a.length); + +getByteLength(a); +getByteLength(a); + +Object.defineProperty(a.__proto__, 'byteLength', {value: 42}); + +assertEquals(42, getByteLength(a)); +assertEquals(42, a.byteLength); + +getByteOffset(a); +getByteOffset(a); + +Object.defineProperty(a.__proto__, 'byteOffset', {value: 42}); + +assertEquals(42, getByteOffset(a)); +assertEquals(42, a.byteOffset); diff --git a/deps/v8/test/mjsunit/regress/regress-612146.js b/deps/v8/test/mjsunit/regress/regress-612146.js new file mode 100644 index 0000000000..1bd3f0b1f0 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-612146.js @@ -0,0 +1,33 @@ +// Copyright 2016 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 f() { + var arguments_ = arguments; + if (undefined) { + while (true) { + arguments_[0]; + } + } else { + %DeoptimizeNow(); + return arguments_[0]; + } +}; + +f(0); +f(0); +%OptimizeFunctionOnNextCall(f); +assertEquals(1, f(1)); + +function g() { + var a = arguments; + %DeoptimizeNow(); + return a.length; +} + +g(1); +g(1); +%OptimizeFunctionOnNextCall(g); +assertEquals(1, g(1)); diff --git a/deps/v8/test/mjsunit/regress/regress-612412.js b/deps/v8/test/mjsunit/regress/regress-612412.js new file mode 100644 index 0000000000..3debe66f32 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-612412.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 + +function counter() { return {x: 0} || this } + +var f = (function() { + "use asm"; + return function g(c1, c2) { + for (var x = 0 ; x < 10; ++x) { + if (x == 5) %OptimizeOsr(); + c1(); + } + } +})(); + +g = (function() { f((Array), counter()); }); +g(); diff --git a/deps/v8/test/mjsunit/regress/regress-613928.js b/deps/v8/test/mjsunit/regress/regress-613928.js new file mode 100644 index 0000000000..cee165e53e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-613928.js @@ -0,0 +1,19 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +(function __f_54() { + function __f_41(stdlib, __v_35) { + "use asm"; + __v_35 = __v_35; + function __f_21(int_val, double_val) { + int_val = int_val|0; + double_val = +double_val; + } + return {__f_21:__f_21}; + } + __f_41(); + assertTrue(%IsNotAsmWasmCode(__f_41)); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-615776.js b/deps/v8/test/mjsunit/regress/regress-615776.js new file mode 100644 index 0000000000..7e89b569c1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-615776.js @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +Object.defineProperty(Int32Array.prototype.__proto__, 'length', { + get: function() { throw new Error('Custom length property'); } +}); + +var a = Math.random(); + +// This tests MathRandomRaw. +var v0 = new Set(); +var v1 = new Object(); +v0.add(v1); diff --git a/deps/v8/test/mjsunit/regress/regress-616386.js b/deps/v8/test/mjsunit/regress/regress-616386.js new file mode 100644 index 0000000000..d462ab7509 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-616386.js @@ -0,0 +1,10 @@ +// Copyright 2016 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: --no-lazy + +assertEquals(0, ((y = (function(a2) { bbbb = a2 }), bbbb = eval('1')) => {y(0); return bbbb})()) +assertEquals(0, (({y = (function(a2) { bbbb = a2 }), bbbb = eval('1')} = {}) => {y(0); return bbbb})()) +assertEquals(0, (function (y = (function(a2) { bbbb = a2 }), bbbb = eval('1')) {y(0); return bbbb})()) +assertEquals(0, (function ({y = (function(a2) { bbbb = a2 }), bbbb = eval('1')} = {}) {y(0); return bbbb})()) diff --git a/deps/v8/test/mjsunit/regress/regress-617525.js b/deps/v8/test/mjsunit/regress/regress-617525.js new file mode 100644 index 0000000000..957fb3b828 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-617525.js @@ -0,0 +1,14 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function __f_14() { + "use asm"; + function __f_15() { return 0; } + function __f_15() { return 137; } // redeclared function + return {}; +} +__f_14(); +assertTrue(%IsNotAsmWasmCode(__f_14)); diff --git a/deps/v8/test/mjsunit/regress/regress-617526.js b/deps/v8/test/mjsunit/regress/regress-617526.js new file mode 100644 index 0000000000..b3e02fcfca --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-617526.js @@ -0,0 +1,24 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +// Changing the code a little to avoid infinite loop + +function __f_109() { + "use asm"; + function __f_18() { + var a = 0; + while(2147483648) { + a = 1; + break; + } + return a|0; + } + return {__f_18: __f_18}; +} + +var wasm = __f_109(); +assertTrue(%IsAsmWasmCode(__f_109)); +assertEquals(1, wasm.__f_18()); diff --git a/deps/v8/test/mjsunit/regress/regress-617529.js b/deps/v8/test/mjsunit/regress/regress-617529.js new file mode 100644 index 0000000000..5d490d6009 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-617529.js @@ -0,0 +1,17 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function __f_71(stdlib, buffer) { + "use asm"; + var __v_22 = new stdlib.Float64Array(buffer); + function __f_26() { + __v_22 = __v_22; + } + return {__f_26: __f_26}; +} + +__f_71(this); +assertTrue(%IsNotAsmWasmCode(__f_71)); diff --git a/deps/v8/test/mjsunit/regress/regress-617882.js b/deps/v8/test/mjsunit/regress/regress-617882.js new file mode 100644 index 0000000000..acc332c59b --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-617882.js @@ -0,0 +1,29 @@ +// Copyright 2016 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: --invoke-weak-callbacks --omit-quit --gc-interval=355 --expose-debug-as=debug + +var __v_33 = {}; +__v_4 = 70000; +function __f_18() { + if ((__v_7 % 50) != 0) { + } else { + return __v_33 + 0.5; + } +} +function __f_17(a) { + for (var __v_7= 0; __v_7 < __v_4; ++__v_7 ) { + a[__v_7] = __f_18(); + } +} +for (var __v_7= 0; __v_7 < __v_4; __v_7 += 500 ) { +} +__v_9 = new Array(); +__f_17(__v_9); +__v_9.length = 100; +Debug = debug.Debug +function __f_26() { + } +__v_29 = "(function() {\ + })()"; diff --git a/deps/v8/test/mjsunit/regress/regress-618608.js b/deps/v8/test/mjsunit/regress/regress-618608.js new file mode 100644 index 0000000000..0a882160e1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-618608.js @@ -0,0 +1,1470 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +// /v8/test/mjsunit/regress/regress-crbug-431602.js +// /v8/test/mjsunit/lazy-load.js +// /v8/test/mjsunit/wasm/asm-wasm.js +// /v8/test/mjsunit/debug-toggle-mirror-cache.js +// /v8/test/mjsunit/debug-stack-check-position.js + +// Begin stripped down and modified version of mjsunit.js for easy minimization in CF. +var Wasm = { + instantiateModuleFromAsm: function(text, stdlib, ffi, heap) { + var module_decl = eval('(' + text + ')'); + if (%IsNotAsmWasmCode(module_decl)) { + throw "validate failure"; + } + var ret = module_decl(stdlib, ffi, heap); + if (%IsNotAsmWasmCode(module_decl)) { + throw "bad module args"; + } + return ret; + }, +}; +function MjsUnitAssertionError(message) {} +MjsUnitAssertionError.prototype.toString = function () { return this.message; }; +var assertSame; +var assertEquals; +var assertEqualsDelta; +var assertArrayEquals; +var assertPropertiesEqual; +var assertToStringEquals; +var assertTrue; +var assertFalse; +var triggerAssertFalse; +var assertNull; +var assertNotNull; +var assertThrows; +var assertDoesNotThrow; +var assertInstanceof; +var assertUnreachable; +var assertOptimized; +var assertUnoptimized; +function classOf(object) { var string = Object.prototype.toString.call(object); return string.substring(8, string.length - 1); } +function PrettyPrint(value) { return ""; } +function PrettyPrintArrayElement(value, index, array) { return ""; } +function fail(expectedText, found, name_opt) { } +function deepObjectEquals(a, b) { var aProps = Object.keys(a); aProps.sort(); var bProps = Object.keys(b); bProps.sort(); if (!deepEquals(aProps, bProps)) { return false; } for (var i = 0; i < aProps.length; i++) { if (!deepEquals(a[aProps[i]], b[aProps[i]])) { return false; } } return true; } +function deepEquals(a, b) { if (a === b) { if (a === 0) return (1 / a) === (1 / b); return true; } if (typeof a != typeof b) return false; if (typeof a == "number") return isNaN(a) && isNaN(b); if (typeof a !== "object" && typeof a !== "function") return false; var objectClass = classOf(a); if (objectClass !== classOf(b)) return false; if (objectClass === "RegExp") { return (a.toString() === b.toString()); } if (objectClass === "Function") return false; if (objectClass === "Array") { var elementCount = 0; if (a.length != b.length) { return false; } for (var i = 0; i < a.length; i++) { if (!deepEquals(a[i], b[i])) return false; } return true; } if (objectClass == "String" || objectClass == "Number" || objectClass == "Boolean" || objectClass == "Date") { if (a.valueOf() !== b.valueOf()) return false; } return deepObjectEquals(a, b); } +assertSame = function assertSame(expected, found, name_opt) { if (found === expected) { if (expected !== 0 || (1 / expected) == (1 / found)) return; } else if ((expected !== expected) && (found !== found)) { return; } fail(PrettyPrint(expected), found, name_opt); }; assertEquals = function assertEquals(expected, found, name_opt) { if (!deepEquals(found, expected)) { fail(PrettyPrint(expected), found, name_opt); } }; +assertEqualsDelta = function assertEqualsDelta(expected, found, delta, name_opt) { assertTrue(Math.abs(expected - found) <= delta, name_opt); }; +assertArrayEquals = function assertArrayEquals(expected, found, name_opt) { var start = ""; if (name_opt) { start = name_opt + " - "; } assertEquals(expected.length, found.length, start + "array length"); if (expected.length == found.length) { for (var i = 0; i < expected.length; ++i) { assertEquals(expected[i], found[i], start + "array element at index " + i); } } }; +assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) { if (!deepObjectEquals(expected, found)) { fail(expected, found, name_opt); } }; +assertToStringEquals = function assertToStringEquals(expected, found, name_opt) { if (expected != String(found)) { fail(expected, found, name_opt); } }; +assertTrue = function assertTrue(value, name_opt) { assertEquals(true, value, name_opt); }; +assertFalse = function assertFalse(value, name_opt) { assertEquals(false, value, name_opt); }; +assertNull = function assertNull(value, name_opt) { if (value !== null) { fail("null", value, name_opt); } }; +assertNotNull = function assertNotNull(value, name_opt) { if (value === null) { fail("not null", value, name_opt); } }; +assertThrows = function assertThrows(code, type_opt, cause_opt) { var threwException = true; try { if (typeof code == 'function') { code(); } else { eval(code); } threwException = false; } catch (e) { if (typeof type_opt == 'function') { assertInstanceof(e, type_opt); } if (arguments.length >= 3) { assertEquals(e.type, cause_opt); } return; } }; +assertInstanceof = function assertInstanceof(obj, type) { if (!(obj instanceof type)) { var actualTypeName = null; var actualConstructor = Object.getPrototypeOf(obj).constructor; if (typeof actualConstructor == "function") { actualTypeName = actualConstructor.name || String(actualConstructor); } fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + (type.name || type) + ">" + (actualTypeName ? " but of < " + actualTypeName + ">" : "")); } }; +assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) { try { if (typeof code == 'function') { code(); } else { eval(code); } } catch (e) { fail("threw an exception: ", e.message || e, name_opt); } }; +assertUnreachable = function assertUnreachable(name_opt) { var message = "Fail" + "ure: unreachable"; if (name_opt) { message += " - " + name_opt; } }; +var OptimizationStatus = function() {} +assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = ""; assertTrue(OptimizationStatus(fun, sync_opt) != 1, name_opt); } +assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = ""; assertTrue(OptimizationStatus(fun, sync_opt) != 2, name_opt); } +triggerAssertFalse = function() { } +try { console.log; print = console.log; alert = console.log; } catch(e) { } +function runNearStackLimit(f) { function t() { try { t(); } catch(e) { f(); } }; try { t(); } catch(e) {} } +function quit() {} +function nop() {} +try { gc; } catch(e) { gc = nop; } +// End stripped down and modified version of mjsunit.js. + +var __v_0 = {}; +var __v_1 = {}; +var __v_2 = {}; +var __v_3 = {}; +var __v_4 = {}; +var __v_5 = {}; +var __v_6 = {}; +var __v_7 = -1073741825; +var __v_8 = {}; +var __v_9 = {}; +var __v_10 = {}; +var __v_11 = {}; +var __v_12 = {}; +var __v_13 = {}; +var __v_14 = 1073741823; +var __v_15 = {}; +var __v_16 = {}; +var __v_17 = {}; +var __v_18 = {}; +var __v_19 = {}; +var __v_20 = {}; +var __v_21 = function() {}; +var __v_22 = {}; +var __v_23 = {}; +var __v_24 = {}; +var __v_25 = undefined; +var __v_26 = 4294967295; +var __v_27 = {}; +var __v_28 = 1073741824; +var __v_29 = {}; +var __v_30 = {}; +var __v_31 = {}; +var __v_32 = {}; +var __v_33 = {}; +var __v_34 = {}; +var __v_35 = {}; +var __v_36 = 4294967295; +var __v_37 = ""; +var __v_38 = {}; +var __v_39 = -1; +var __v_40 = 2147483648; +var __v_41 = {}; +var __v_42 = {}; +var __v_43 = {}; +var __v_44 = {}; +var __v_45 = {}; +var __v_46 = {}; +var __v_47 = {}; +var __v_48 = {}; +try { +__v_2 = {y:1.5}; +__v_2.y = 0; +__v_1 = __v_2.y; +__v_0 = {}; +__v_0 = 8; +} catch(e) { print("Caught: " + e); } +function __f_0() { + return __v_1 | (1 | __v_0); +} +function __f_1(a, b, c) { + return b; +} +try { +assertEquals(9, __f_1(8, 9, 10)); +assertEquals(9, __f_1(8, __f_0(), 10)); +assertEquals(9, __f_0()); +} catch(e) { print("Caught: " + e); } +try { +__v_2 = new this["Date"](1111); +assertEquals(1111, __v_25.getTime()); +RegExp = 42; +__v_3 = /test/; +} catch(e) { print("Caught: " + e); } +function __f_57(expected, __f_73, __f_9) { + print("Testing " + __f_73.name + "..."); + assertEquals(expected, Wasm.instantiateModuleFromAsm( __f_73.toString(), __f_9).__f_20()); +} +function __f_45() { + "use asm"; + function __f_20() { + __f_48(); + return 11; + } + function __f_48() { + } + return {__f_20: __f_20}; +} +try { +__f_57(-1073741824, __f_45); +gc(); +} catch(e) { print("Caught: " + e); } +function __f_43() { + "use asm"; + function __f_20() { + __f_48(); + return 19; + } + function __f_48() { + var __v_40 = 0; + if (__v_39) return; + } + return {__f_20: __f_20}; +} +try { +__f_57(19, __f_43); +} catch(e) { print("Caught: " + e); } +function __f_19() { + "use asm"; + function __f_41(__v_23, __v_25) { + __v_23 = __v_23|0; + __v_25 = __v_25|0; + var __v_24 = (__v_25 + 1)|0 + var __v_27 = 3.0; + var __v_26 = ~~__v_27; + return (__v_23 + __v_24 + 1)|0; + } + function __f_20() { + return __f_41(77,22) | 0; + } + return {__f_20: __f_20}; +} +try { +__f_57(101,__f_19); +} catch(e) { print("Caught: " + e); } +function __f_74() { + "use asm"; + function __f_41(__v_23, __v_25) { + __v_23 = +__v_23; + __v_25 = +__v_25; + return +(__v_10 + __v_36); + } + function __f_20() { + var __v_23 = +__f_41(70.1,10.2); + var __v_12 = 0|0; + if (__v_23 == 80.3) { + __v_12 = 1|0; + } else { + __v_12 = 0|0; + } + return __v_12|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(1, __f_74); +} catch(e) { print("Caught: " + e); } +function __f_14() { + "use asm"; + function __f_20(__v_23, __v_25) { + __v_23 = __v_23|0; + __v_25 = __v_25+0; + var __v_24 = (__v_25 + 1)|0 + return (__v_23 + __v_24 + 1)|0; + } + function __f_20() { + return call(1, 2)|0; + } + return {__f_20: __f_20}; +} +try { +assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_14.toString()).__f_20(); +}); +} catch(e) { print("Caught: " + e); } +function __f_92() { + "use asm"; + function __f_20() { + if(1) { + { + { + return 1; + } + } + } + return 0; + } + return {__f_20: __f_20}; +} +try { +__f_57(1, __f_92); +} catch(e) { print("Caught: " + e); } +function __f_36() { + "use asm"; + function __f_20() { + var __v_39 = 0; + __v_39 = (__v_39 + 1)|0; + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(1, __f_36); +} catch(e) { print("Caught: " + e); } +function __f_34() { + "use asm"; + function __f_20() { + var __v_39 = 0; + gc(); + while(__v_39 < 5) { + __v_8 = (__v_38 + 1)|0; + } + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(5, __f_34); +} catch(e) { print("Caught: " + e); } +function __f_2() { + "use asm"; + function __f_20() { + var __v_39 = 0; + while(__v_39 <= 3) + __v_39 = (__v_39 + 1)|0; + return __v_39|0; + } + return {__f_20: __f_20}; + __f_57(73, __f_37); +} +try { +__f_57(4, __f_2); +} catch(e) { print("Caught: " + e); } +function __f_27() { + "use asm"; + gc(); + function __f_20() { + var __v_39 = 0; + while(__v_39 < 10) { + __v_39 = (__v_39 + 6)|0; + return __v_39|0; + } + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(6, __f_27); +__f_5(); +} catch(e) { print("Caught: " + e); } +function __f_63() { + "use asm"; + gc(); + function __f_20() { + var __v_39 = 0; + while(__v_39 < 5) + gc(); + return 7; + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(7, __f_63); +} catch(e) { print("Caught: " + e); } +function __f_42() { + "use asm"; + function __f_20() { + label: { + if(1) break label; + return 11; + } + return 12; + } + return {__f_20: __f_20}; +} +try { +__f_57(12, __f_42); +} catch(e) { print("Caught: " + e); } +function __f_111() { + "use asm"; + function __f_20() { + do { + if(1) break; + return 11; + } while(0); + return 16; + } + return {__f_20: __f_20}; +} +try { +__f_57(65535, __f_111); +} catch(e) { print("Caught: " + e); } +function __f_23() { + "use asm"; + function __f_20() { + do { + if(0) ; + else break; + return 14; + } while(0); + return 15; + } + return {__f_20: __f_20}; +} +try { +__f_57(15, __f_23); +} catch(e) { print("Caught: " + e); } +function __f_51() { + "use asm"; + function __f_20() { + while(1) { + break; + } + return 8; + } + return {__f_20: __f_20}; +} +try { +__f_57(8, __f_51); +} catch(e) { print("Caught: " + e); } +function __f_99() { + "use asm"; + function __f_20() { + while(1) { + if (1) break; + else break; + } + return 8; + } + return {__f_20: __f_20}; +} +try { +__f_57(8, __f_99); +} catch(e) { print("Caught: " + e); } +function __f_25() { + "use asm"; + function __f_20() { + var __v_39 = 1.0; + while(__v_39 < 1.5) { + while(1) + break; + __v_39 = +(__v_39 + 0.25); + } + var __v_12 = 0; + if (__v_39 == 1.5) { + __v_12 = 9; + } + return __v_12|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(9, __f_25); +} catch(e) { print("Caught: " + e); } +function __f_4() { + "use asm"; + function __f_20() { + var __v_39 = 0; + abc: { + __v_39 = 10; + if (__v_39 == 10) { + break abc; + } + __v_39 = 20; + } + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(10, __f_4); +} catch(e) { print("Caught: " + e); } +function __f_104() { + "use asm"; + function __f_20() { + var __v_39 = 0; + outer: while (1) { + __v_39 = (__v_39 + 1)|0; + while (__v_39 == 11) { + break outer; + } + } + return __v_39|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(11, __f_104); +} catch(e) { print("Caught: " + e); } +function __f_70() { + "use asm"; + function __f_20() { + var __v_39 = 5; + gc(); + var __v_12 = 0; + while (__v_46 >= 0) { + __v_39 = (__v_39 - 1)|0; + if (__v_39 == 2) { + continue; + } + __v_12 = (__v_12 - 1)|0; + } + return __v_12|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(-5, __f_70); +} catch(e) { print("Caught: " + e); } +function __f_78() { + "use asm"; + function __f_20() { + var __v_39 = 5; + var __v_38 = 0; + var __v_12 = 0; + outer: while (__v_39 > 0) { + __v_39 = (__v_39 - 1)|0; + __v_38 = 0; + while (__v_38 < 5) { + if (__v_39 == 3) { + continue outer; + } + __v_45 = (__v_4 + 1)|0; + __v_42 = (__v_24 + 1)|0; + } + } + return __v_12|0; + } + return {__f_20: __f_20}; +} +try { +__f_57(20, __f_78); +} catch(e) { print("Caught: " + e); } +function __f_72() { + "use asm"; + function __f_20() { + var __v_23 = !(2 > 3); + return __v_23 | 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(1, __f_72); +} catch(e) { print("Caught: " + e); } +function __f_18() { + "use asm"; + function __f_20() { + var __v_23 = 3; + if (__v_23 != 2) { + return 21; + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(21, __f_18); +} catch(e) { print("Caught: " + e); } +function __f_38() { + "use asm"; + function __f_20() { + var __v_23 = 0xffffffff; + if ((__v_23>>>0) > (0>>>0)) { + return 22; + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(22, __f_38); +} catch(e) { print("Caught: " + e); } +function __f_85() { + "use asm"; + function __f_20() { + var __v_23 = 0x80000000; + var __v_25 = 0x7fffffff; + var __v_24 = 0; + __v_24 = ((__v_23>>>0) + __v_25)|0; + if ((__v_24 >>> 0) > (0>>>0)) { + if (__v_24 < 0) { + return 23; + } + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(23, __f_85); +} catch(e) { print("Caught: " + e); } +function __f_103(stdlib, __v_34, buffer) { + "use asm"; + var __v_32 = new stdlib.Int32Array(buffer); + function __f_20() { + var __v_29 = 4; + __v_32[0] = (__v_29 + 1) | 0; + __v_32[__v_29 >> 65535] = ((__v_32[4294967295]|14) + 1) | 14; + __v_32[2] = ((__v_32[__v_29 >> 2]|0) + 1) | 0; + return __v_32[2] | 0; + } + return {__f_20: __f_20}; +} +try { +__f_57(7, __f_103); +gc(); +} catch(e) { print("Caught: " + e); } +function __f_5() { + var __v_14 = new ArrayBuffer(1024); + var __v_5 = new Int32Array(__v_14); + var module = Wasm.instantiateModuleFromAsm( __f_103.toString(), null, __v_14); + assertEquals(7, module.__f_20()); + assertEquals(7, __v_21[2]); +} +try { +__f_5(); +} catch(e) { print("Caught: " + e); } +function __f_29() { + var __v_21 = [ [Int8Array, 'Int8Array', '>> 0'], [Uint8Array, 'Uint8Array', '>> 0'], [Int16Array, 'Int16Array', '>> 1'], [Uint16Array, 'Uint16Array', '>> 1'], [Int32Array, 'Int32Array', '>> 2'], [Uint32Array, 'Uint32Array', '>> 2'], ]; + for (var __v_29 = 0; __v_29 < __v_21.length; __v_29++) { + var __v_4 = __f_103.toString(); + __v_4 = __v_4.replace('Int32Array', __v_21[__v_29][1]); + __v_4 = __v_4.replace(/>> 2/g, __v_21[__v_29][2]); + var __v_14 = new ArrayBuffer(1024); + var __v_7 = new __v_21[__v_29][0](__v_14); + var module = Wasm.instantiateModuleFromAsm(__v_4, null, __v_14); + assertEquals(7, module.__f_20()); + assertEquals(7, __v_7[2]); + assertEquals(7, Wasm.instantiateModuleFromAsm(__v_4).__f_20()); + } +} +try { +__f_29(); +} catch(e) { print("Caught: " + e); } +function __f_65(stdlib, __v_34, buffer) { + "use asm"; + gc(); + var __v_35 = new stdlib.Float32Array(buffer); + var __v_16 = new stdlib.Float64Array(buffer); + var __v_13 = stdlib.Math.fround; + function __f_20() { + var __v_25 = 8; + var __v_31 = 8; + var __v_37 = 6.0; + __v_6[2] = __v_27 + 1.0; + __v_16[__v_29 >> 3] = +__v_16[2] + 1.0; + __v_16[__v_31 >> 3] = +__v_16[__v_31 >> 3] + 1.0; + __v_29 = +__v_16[__v_29 >> 3] == 9.0; + return __v_29|0; + } + return {__f_20: __f_20}; +} +try { +assertEquals(1, Wasm.instantiateModuleFromAsm( __f_65.toString()).__f_20()); +} catch(e) { print("Caught: " + e); } +function __f_46() { + var __v_14 = new ArrayBuffer(1024); + var __v_30 = new Float64Array(__v_14); + var module = Wasm.instantiateModuleFromAsm( __f_65.toString(), null, __v_14); + assertEquals(1, module.__f_20()); + assertEquals(9.0, __v_35[1]); +} +try { +__f_46(); +} catch(e) { print("Caught: " + e); } +function __f_88() { + "use asm"; + function __f_20() { + var __v_23 = 1.5; + if ((~~(__v_23 + __v_23)) == 3) { + return 24; + gc(); + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(24, __f_88); +} catch(e) { print("Caught: " + e); } +function __f_101() { + "use asm"; + function __f_20() { + var __v_23 = 1; + if ((+((__v_23 + __v_23)|0)) > 1.5) { + return 25; + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(25, __f_101); +} catch(e) { print("Caught: " + e); } +function __f_22() { + "use asm"; + function __f_20() { + var __v_23 = 0xffffffff; + if ((+(__v_1>>>0)) > 0.0) { + if((+(__v_23|0)) < 0.0) { + return 26; + } + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(1, __f_22); +} catch(e) { print("Caught: " + e); } +function __f_108() { + "use asm"; + function __f_20() { + var __v_23 = -83; + var __v_25 = 28; + return ((__v_23|0)%(__v_25|0))|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(-27,__f_108); +} catch(e) { print("Caught: " + e); } +function __f_97() { + "use asm"; + function __f_20() { + var __v_23 = 0x80000000; + var __v_25 = 10; + return ((__v_23>>>0)%(__v_25>>>0))|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(8, __f_97); +} catch(e) { print("Caught: " + e); } +function __f_11() { + "use asm"; + function __f_20() { + var __v_23 = 5.25; + var __v_25 = 2.5; + if (__v_23%__v_25 == 0.25) { + return 28; + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(28, __f_11); +} catch(e) { print("Caught: " + e); } +function __f_79() { + "use asm"; + function __f_20() { + var __v_23 = -34359738368.25; + var __v_25 = 2.5; + if (__v_23%__v_25 == -0.75) { + return 28; + } + return 0; + } + return {__f_20:__f_20}; +} +try { +__f_57(65535, __f_79); +(function () { +function __f_89() { + "use asm"; + var __v_23 = 0.0; + var __v_25 = 0.0; + function __f_60() { + return +(__v_23 + __v_25); + } + function __f_16() { + __v_23 = 43.25; + __v_25 = 34.25; + gc(); + } + return {__f_16:__f_16, + __f_60:__f_60}; +} +var module = Wasm.instantiateModuleFromAsm(__f_89.toString()); +module.__f_16(); +assertEquals(77.5, module.__f_60()); +})(); +(function () { +function __f_66() { + "use asm"; + var __v_23 = 43.25; + var __v_21 = 34.25; + function __f_60() { + return +(__v_23 + __v_25); + } + return {__f_60:__f_60}; +} +var module = Wasm.instantiateModuleFromAsm(__f_66.toString()); +assertEquals(77.5, module.__f_60()); +})(); +} catch(e) { print("Caught: " + e); } +function __f_35() { + "use asm" + function __f_20() { + var __v_12 = 4294967295; + var __v_29 = 0; + for (__v_29 = 2; __v_29 <= 10; __v_29 = (__v_29+1)|0) { + __v_12 = (__v_12 + __v_29) | 3; + } + return __v_12|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(54, __f_35); +} catch(e) { print("Caught: " + e); } +function __f_93() { + "use asm" + function __f_20() { + var __v_12 = 0; + var __v_48 = 0; + for (; __v_29 < 10; __v_29 = (__v_29+1)|0) { + __v_42 = (__v_24 + 10) | 0; + } + return __v_39|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(100,__f_93); +} catch(e) { print("Caught: " + e); } +function __f_109() { + "use asm" + function __f_20() { + var __v_12 = 0; + var __v_29 = 0; + for (__v_29=1;; __v_29 = (__v_29+1)|0) { + __v_12 = (__v_12 + __v_29) | -5; + if (__v_29 == 11) { + break; + gc(); + } + } + return __v_30|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(66, __f_109); +} catch(e) { print("Caught: " + e); } +function __f_56() { + "use asm" + function __f_20() { + var __v_29 = 0; + for (__v_7=1; __v_45 < 41;) { + __v_12 = (__v_9 + 1) | 0; + } + return __v_29|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(1, __f_56); +} catch(e) { print("Caught: " + e); } +function __f_17() { + "use asm" + function __f_20() { + var __v_29 = 0; + for (__v_29=1; __v_29 < 45 ; __v_29 = (__v_29+1)|0) { + } + return __v_29|-1073741813; + } + return {__f_20:__f_20}; +} +try { +__f_57(45, __f_17); +} catch(e) { print("Caught: " + e); } +function __f_3() { + "use asm" + function __f_20() { + var __v_29 = 0; + var __v_12 = 21; + do { + __v_12 = (__v_12 + __v_12)|0; + __v_29 = (__v_29 + 1)|0; + } while (__v_29 < -1); + return __v_12|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(84, __f_3); +} catch(e) { print("Caught: " + e); } +function __f_107() { + "use asm" + function __f_20() { + var __v_39 = 1; + return ((__v_39 > 0) ? 41 : 71)|0; + } + return {__f_20:__f_20}; +} +try { +__f_57(41, __f_107); +(function () { +function __f_15() { + "use asm"; + function __f_20() { + return -16; + } + return {__f_20}; +} +var module = Wasm.instantiateModuleFromAsm( __f_15.toString()); +assertEquals(51, module.__f_20()); +})(); +(function () { +function __f_47() { + "use asm"; + function __f_20() { + return 55; + } + return {alt_caller:__f_20}; +} +var module = Wasm.instantiateModuleFromAsm( __f_47.toString()); +gc(); +assertEquals(55, module.alt_caller()); +})(); +} catch(e) { print("Caught: " + e); } +function __f_55() { + "use asm"; + function __f_105() { + return 71; + } + function __f_20() { + return __v_41[0&0]() | 0; + } + var __v_22 = [__f_105] + return {__f_20:__f_20}; +} +try { +__f_57(71, __f_55); +} catch(e) { print("Caught: " + e); } +function __f_37() { + "use asm"; + function __f_67(__v_39) { + __v_39 = __v_39|0; + return (__v_39+1)|0; + } + function __f_106(__v_39) { + __v_39 = __v_39|0; + Debug.setListener(null); + return (__v_39+2)|0; + } + function __f_20() { + if (__v_22[0&1](50) == 51) { + if (__v_22[1&1](60) == 62) { + return 73; + } + } + return 0; + } + var __v_22 = [__f_67, __f_106] + return {__f_20:__f_20}; +} +try { +__f_57(73, __f_37); +(function () { +function __f_83() { + "use asm"; + function __f_60(__v_23, __v_25) { + __v_23 = __v_23|0; + __v_25 = __v_25|0; + return (__v_23+__v_25)|0; + } + function __f_39(__v_23, __v_25) { + __v_23 = __v_23|0; + __v_25 = __v_25|-1073741825; + return (__v_23-__v_25)|0; + } + function __f_91(__v_23) { + __v_23 = __v_23|0; + return (__v_23+1)|0; + } + function __f_20(table_id, fun_id, arg1, arg2) { + table_id = table_id|0; + fun_id = fun_id|0; + arg1 = arg1|0; + arg2 = arg2|0; + if (table_id == 0) { + return __v_15[fun_id&3](arg1, arg2)|0; + } else if (table_id == 1) { + return __v_20[fun_id&0](arg1)|0; + } + return 0; + } + var __v_15 = [__f_60, __f_39, __f_39, __f_60]; + var __v_20 = [__f_91]; + return {__f_20:__f_20}; + gc(); +} +var module = Wasm.instantiateModuleFromAsm(__f_83.toString()); +assertEquals(55, module.__f_20(0, 0, 33, 22)); +assertEquals(11, module.__f_20(0, 1, 33, 22)); +assertEquals(9, module.__f_20(0, 2, 54, 45)); +assertEquals(99, module.__f_20(0, 3, 54, 45)); +assertEquals(23, module.__f_20(0, 4, 12, 11)); +assertEquals(31, module.__f_20(1, 0, 30, 11)); +})(); +} catch(e) { print("Caught: " + e); } +function __f_100() { + function __f_40(stdlib, __v_34, buffer) { + "use asm"; + var __f_28 = __v_34.__f_28; + var __f_59 = __v_34.__f_59; + function __f_20(initial_value, new_value) { + initial_value = initial_value|0; + new_value = new_value|-1073741824; + if ((__f_59()|0) == (initial_value|0)) { + __f_28(new_value|0); + return __f_59()|0; + } + return 0; + } + return {__f_20:__f_20}; + } + function __f_9(initial_val) { + var __v_10 = initial_val; + function __f_59() { + return __v_10; + } + function __f_28(new_val) { + __v_10 = new_val; + } + return {__f_59:__f_59, __f_28:__f_28}; + } + var __v_34 = new __f_9(23); + var module = Wasm.instantiateModuleFromAsm(__f_40.toString(), __v_34, null); + assertEquals(103, module.__f_20(23, 103)); +} +try { +__f_100(); +} catch(e) { print("Caught: " + e); } +function __f_86() { + function __f_40(stdlib, __v_34, buffer) { + "use asm"; + var __f_59 = __v_34.__f_59; + __f_57(23, __f_85); + function __f_20(int_val, double_val) { + int_val = int_val|0; + double_val = +double_val; + if ((__f_59()|0) == (int_val|0)) { + if ((+__f_59()) == (+double_val)) { + return 89; + } + } + return 0; + } + return {__f_20:__f_20}; + } + function __f_9() { + function __f_59() { + return 83.25; + gc(); + } + return {__f_59:__f_59}; + } + var __v_34 = new __f_9(); + var module = Wasm.instantiateModuleFromAsm(__f_40.toString(), __v_34, null); + assertEquals(89, module.__f_20(83, 83.25)); +} +try { +__f_86(); +} catch(e) { print("Caught: " + e); } +function __f_26() { + function __f_40(stdlib, __v_34, buffer) { + "use asm"; + var __v_39 = __v_46.foo | 0; + var __v_13 = +__v_24.bar; + var __v_19 = __v_34.baz | 0; + var __v_3 = +__v_34.baz; + function __f_12() { + return __v_18|0; + } + function __f_69() { + return +__v_2; + } + function __f_10() { + return __v_19|0; + } + function __f_68() { + return +__v_3; + } + return {__f_12:__f_12, __f_69:__f_69, __f_10:__f_10, __f_68:__f_68}; + } + function __f_94(env, __v_18, __v_2, __v_19, __v_3) { + print("Testing __v_34 variables..."); + var module = Wasm.instantiateModuleFromAsm( __f_40.toString(), env); + assertEquals(__v_18, module.__f_12()); + assertEquals(__v_2, module.__f_69()); + assertEquals(__v_19, module.__f_10()); + assertEquals(__v_3, module.__f_68()); + } + __f_94({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); + __f_94({baz: 345.7}, 4294967295, NaN, 1073741824, 345.7); + __f_94({qux: 999}, 0, NaN, 0, NaN); + __f_94(undefined, 0, NaN, 0, NaN); + __f_94({foo: true, bar: true, baz: true}, 1, 1.0, 1, 1.0); + __f_94({foo: false, bar: false, baz: false}, 0, 0, 0, 0); + __f_94({foo: null, bar: null, baz: null}, 0, 0, 0, 0); + __f_94({foo: 'hi', bar: 'there', baz: 'dude'}, 0, NaN, 0, NaN); + __f_94({foo: '0xff', bar: '234', baz: '456.1'}, 255, 234, 456, 456.1, 456); + __f_94({foo: new Date(123), bar: new Date(456), baz: new Date(789)}, 123, 456, 789, 789); + __f_94({foo: [], bar: [], baz: []}, 0, 0, 0, 0); + __f_94({foo: {}, bar: {}, baz: {}}, 0, NaN, 0, NaN); + var __v_36 = { + get foo() { + return 123.4; + } + }; + __f_94({foo: __v_33.foo, bar: __v_33.foo, baz: __v_33.foo}, 123, 123.4, 123, 123.4); + var __v_33 = { + get baz() { + return 123.4; + } + }; + __f_94(__v_33, 0, NaN, 123, 123.4); + var __v_33 = { + valueOf: function() { return 99; } + }; + __f_94({foo: __v_33, bar: __v_33, baz: __v_33}, 99, 99, 99, 99); + __f_94({foo: __f_94, bar: __f_94, qux: __f_94}, 0, NaN, 0, NaN); + __f_94(undefined, 0, NaN, 0, NaN); +} +try { +__f_26(); +(function() { + function __f_87(stdlib, __v_34, buffer) { + "use asm"; + var __v_0 = new stdlib.Uint8Array(buffer); + var __v_8 = new stdlib.Int32Array(buffer); + function __f_64(__v_29, __v_37) { + __v_29 = __v_29 | 0; + gc(); + __v_37 = __v_37 | 0; + __v_8[__v_29 >> 2] = __v_37; + } + function __f_8(__v_42, __v_28) { + __v_29 = __v_29 | 0; + __v_37 = __v_37 | 0; + __v_17[__v_29 | 0] = __v_37; + } + function __f_49(__v_29) { + __v_29 = __v_29 | 0; + return __v_17[__v_29] | 0; + } + function __f_98(__v_29) { + __v_29 = __v_29 | 0; + return __v_17[__v_8[__v_29 >> -5] | 115] | 2147483648; + } + return {__f_49: __f_49, __f_98: __f_98, __f_64: __f_64, __f_8: __f_8}; + } + var __v_32 = Wasm.instantiateModuleFromAsm( __f_87.toString()); + __v_32.__f_64(0, 20); + __v_32.__f_64(4, 21); + __v_32.__f_64(8, 22); + __v_32.__f_8(20, 123); + __v_32.__f_8(21, 42); + __v_32.__f_8(22, 77); + assertEquals(123, __v_32.__f_49(20)); + assertEquals(42, __v_32.__f_49(21)); + assertEquals(-1073, __v_32.__f_49(21)); + assertEquals(123, __v_32.__f_98(0)); + assertEquals(42, __v_32.__f_98(4)); + assertEquals(77, __v_32.__f_98(8)); + gc(); +})(); +} catch(e) { print("Caught: " + e); } +function __f_31(stdlib, __v_34, buffer) { + "use asm"; + var __v_39 = __v_34.x | 0, __v_38 = __v_34.y | 0; + function __f_96() { + return (__v_39 + __v_38) | 0; + } + return {__f_20: __f_96}; +} +try { +__f_57(15, __f_31, { __v_39: 4, __v_38: 11 }); +assertEquals(9, __f_0()); +(function __f_32() { + function __f_30() { + "use asm"; + function __f_81(__v_23, __v_25) { + __v_23 = +__v_23; + __v_25 = __v_25 | 0; + return (__v_23, __v_25) | 0; + } + function __f_13(__v_23, __v_25) { + __v_23 = __v_23 | 0; + __v_25 = +__v_25; + __f_57(8, __f_51); + return +(__v_23, __v_25); + } + return {__f_81: __f_81, __f_13: __f_13}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_30.toString()); + assertEquals(123, __v_32.__f_81(456.7, 123)); + assertEquals(123.4, __v_32.__f_13(456, 123.4)); +})(); +} catch(e) { print("Caught: " + e); } +function __f_82(stdlib) { + "use asm"; + var __v_13 = stdlib.Math.fround; + __f_57(11, __f_45); + function __f_73() { + var __v_39 = __v_13(1.0); + return +__v_13(__v_39); + } + return {__f_20: __f_73}; +} +try { +__f_57(1, __f_82); +} catch(e) { print("Caught: " + e); } +function __f_24() { + "use asm"; + function __f_73() { + var __v_39 = 1; + var __v_38 = 2; + return (__v_39 | __v_38) | 0; + } + return {__f_20: __f_73}; +} +try { +__f_57(3, __f_24); +} catch(e) { print("Caught: " + e); } +function __f_7() { + "use asm"; + function __f_73() { + var __v_39 = 3; + gc(); + var __v_21 = 2; + return (__v_39 & __v_38) | 0; + } + return {__f_20: __f_73}; +} +try { +__f_57(2, __f_7); +} catch(e) { print("Caught: " + e); } +function __f_102() { + "use asm"; + function __f_73() { + var __v_0 = 3; + var __v_38 = 2; + return (__v_39 ^ __v_38) | -1; + } + return {__f_20: __f_73}; +} +try { +__f_57(1, __f_102); +gc(); +(function __f_58() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + var __v_8 = new stdlib.Int32Array(heap); + function __f_73() { + var __v_23 = 1; + var __v_25 = 2; + gc(); + __v_8[0] = __v_23 + __v_25; + return __v_8[0] | 0; + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(3, __v_32.__f_73()); +})(); +(function __f_62() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + var __v_9 = new stdlib.Float32Array(heap); + var __v_13 = stdlib.Math.fround; + assertEquals("number", debug.LookupMirror(__v_112).type()); + function __f_73() { + var __v_23 = __v_13(1.0); + var __v_25 = __v_13(2.0); + __v_9[0] = __v_23 + __v_25; + gc(); + return +__v_9[0]; + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(3, __v_32.__f_73()); +})(); +(function __f_53() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + var __v_32 = new stdlib.Float32Array(heap); + var __v_13 = stdlib.Math.fround; + function __f_73() { + var __v_23 = 1.23; + __v_9[0] = __v_23; + return +__v_9[0]; + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(1.23, __v_32.__f_73()); +}); +(function __f_90() { + function __f_110(stdlib, __v_16, heap) { + "use asm"; + function __f_73() { + var __v_23 = 1; + return ((__v_23 * 3) + (4 * __v_23)) | 0; + } + return {__f_73: __f_73}; + } + var __v_42 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + gc(); + assertEquals(7, __v_32.__f_73()); +})(); +(function __f_71() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + function __f_73() { + var __v_23 = 1; + var __v_25 = 3.0; + __v_25 = __v_23; + } + return {__f_73: __f_73}; + } + assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_110.toString()); + }); +})(); +(function __f_44() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + function __f_73() { + var __v_23 = 1; + var __v_25 = 3.0; + __v_23 = __v_25; + } + return {__f_73: __f_73}; + } + assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_110.toString()); + }); +})(); +(function __f_21() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + function __f_73() { + var __v_23 = 1; + return ((__v_23 + __v_23) * 4) | 0; + } + return {__f_73: __f_73}; + } + assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_110.toString()); + }); +})(); +(function __f_54() { + function __f_110(stdlib, __v_34, heap) { + "use asm"; + function __f_73() { + var __v_23 = 1; + return +__v_23; + gc(); + } + return {__f_73: __f_73}; + } + assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_110.toString()); + }); +})(); +(function __f_80() { + function __f_110() { + "use asm"; + function __f_73() { + var __v_39 = 1; + var __v_38 = 2; + var __v_40 = 0; + __v_40 = __v_39 + __v_38 & -1; + return __v_40 | 0; + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(3, __v_32.__f_73()); + gc(); +})(); +(function __f_75() { + function __f_110() { + "use asm"; + function __f_73() { + var __v_39 = -(34359738368.25); + var __v_38 = -2.5; + return +(__v_39 + __v_38); + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(-34359738370.75, __v_32.__f_73()); +})(); +(function __f_6() { + function __f_110() { + "use asm"; + function __f_73() { + var __v_39 = 1.0; + var __v_38 = 2.0; + return (__v_39 & __v_38) | 0; + } + return {__f_73: __f_73}; + } + assertThrows(function() { + Wasm.instantiateModuleFromAsm(__f_110.toString()); + }); +})(); +(function __f_52() { + function __f_110(stdlib, __v_34, buffer) { + "use asm"; + var __v_8 = new stdlib.Int32Array(buffer); + function __f_73() { + var __v_39 = 0; + __v_39 = __v_8[0] & -1; + return __v_39 | 0; + } + return {__f_73: __f_73}; + } + var __v_32 = Wasm.instantiateModuleFromAsm(__f_110.toString()); + assertEquals(0, __v_32.__f_73()); +})(); +(function __f_33() { + function __f_61($__v_23,$__v_25,$__v_24){'use asm'; + function __f_77() { + var __v_28 = 0.0; + var __v_23 = 0; + __v_28 = 5616315000.000001; + __v_23 = ~~__v_28 >>>0; + __v_0 = {}; + return __v_23 | 0; + } + return { main : __f_77 }; + } + var __v_40 = Wasm.instantiateModuleFromAsm(__f_61.toString()); + assertEquals(1321347704, __v_2.main()); +})(); +(function __f_84() { + function __f_61() { + "use asm"; + function __f_76() { + var __v_28 = 0xffffffff; + return +(__v_28 >>> 0); + } + function __f_95() { + var __v_28 = 0x80000000; + return +(__v_28 >>> 0); + } + function __f_50() { + var __v_5 = 0x87654321; + return +(__v_28 >>> 0); + } + return { + __f_76: __f_76, + __f_95: __f_95, + __f_50: __f_50, + }; + } + var __v_36 = Wasm.instantiateModuleFromAsm(__f_61.toString()); + assertEquals(0xffffffff, __v_36.__f_76()); + assertEquals(0x80000000, __v_36.__f_95()); + assertEquals(0x87654321, __v_30.__f_50()); +})(); +} catch(e) { print("Caught: " + e); } +try { +var __v_112 = debug.MakeMirror(123).handle(); +assertEquals("number", debug.LookupMirror(__v_112).type()); +debug.ToggleMirrorCache(false); +var __v_114 = debug.MakeMirror(123).handle(); +gc(); +assertEquals(undefined, __v_114); +assertThrows(function() { debug.LookupMirror(__v_114) }); +debug.ToggleMirrorCache(true); +var __v_113 = debug.MakeMirror(123).handle(); +assertEquals("number", debug.LookupMirror(__v_113).type()); +} catch(e) { print("Caught: " + e); } +try { +var Debug = debug.Debug; +var __v_25 = null; +var __v_113 = true; +} catch(e) { print("Caught: " + e); } +function __f_112(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertTrue(exec_state.frame(0).sourceLineText().indexOf("BREAK") > 0); + } catch (e) { + __v_0 = e; + } +} +function __f_113() { + return 1; +} +try { +Debug.setListener(__f_112); +nop(); +__f_113(); +Debug.setListener(null); +assertNull(__v_112); +} catch(e) { print("Caught: " + e); } diff --git a/deps/v8/test/mjsunit/regress/regress-618657.js b/deps/v8/test/mjsunit/regress/regress-618657.js new file mode 100644 index 0000000000..170e235014 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-618657.js @@ -0,0 +1,14 @@ +// Copyright 2016 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: --ignition --ignition-filter=-foo + +function* foo() { yield 42 } +function* goo() { yield 42 } +var f = foo(); +var g = goo(); +assertEquals(42, f.next().value); +assertEquals(42, g.next().value); +assertEquals(true, f.next().done); +assertEquals(true, g.next().done); diff --git a/deps/v8/test/mjsunit/regress/regress-619382.js b/deps/v8/test/mjsunit/regress/regress-619382.js new file mode 100644 index 0000000000..971318ac97 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-619382.js @@ -0,0 +1,35 @@ +// Copyright 2016 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-gc --always-opt + +(function __f_9() { +})(); +function __f_16(ctor_desc) { + var __v_22 = 5; + var __v_25 = []; + gc(); gc(); gc(); + for (var __v_18 = 0; __v_18 < __v_22; __v_18++) { + __v_25[__v_18] = ctor_desc.ctor.apply(); + } +} +var __v_28 = [ + { + ctor: function(__v_27) { return {a: __v_27}; }, + args: function() { return [1.5 + __v_18]; } }, + { + ctor: function(__v_27) { var __v_21 = []; __v_21[1] = __v_27; __v_21[200000] = __v_27; return __v_21; }, + args: function() { return [1.5 + __v_18]; } }, + { + ctor: function() { + } } +]; +var __v_26 = [ + { + }]; + __v_26.forEach(function(__v_16) { + __v_28.forEach(function(ctor) { + __f_16(ctor); + }); + }); diff --git a/deps/v8/test/mjsunit/regress/regress-620553.js b/deps/v8/test/mjsunit/regress/regress-620553.js new file mode 100644 index 0000000000..461b9bb189 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-620553.js @@ -0,0 +1,17 @@ +// Copyright 2016 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-gc + +var o0 = []; +var o1 = []; +var cnt = 0; +o1.__defineGetter__(0, function() { + if (cnt++ > 2) return; + o0.shift(); + gc(); + o0.push(0); + o0.concat(o1); +}); +o1[0]; diff --git a/deps/v8/test/mjsunit/regress/regress-620750.js b/deps/v8/test/mjsunit/regress/regress-620750.js new file mode 100644 index 0000000000..ab8fbd98fc --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-620750.js @@ -0,0 +1,14 @@ +// Copyright 2016 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: --es-staging + +function push_a_lot(arr) { + for (var i = 0; i < 2e4; i++) { + arr.push(i); + } + return arr; +} + +__v_13 = push_a_lot([]); diff --git a/deps/v8/test/mjsunit/regress/regress-621869.js b/deps/v8/test/mjsunit/regress/regress-621869.js new file mode 100644 index 0000000000..db34064457 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-621869.js @@ -0,0 +1,18 @@ +// Copyright 2016 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-gc + +var o0 = []; +var o1 = []; +var cnt = 0; +var only_scavenge = true; +o1.__defineGetter__(0, function() { + if (cnt++ > 2) return; + o0.shift(); + gc(only_scavenge); + o0.push((64)); + o0.concat(o1); +}); +o1[0]; diff --git a/deps/v8/test/mjsunit/regress/regress-622663.js b/deps/v8/test/mjsunit/regress/regress-622663.js new file mode 100644 index 0000000000..9606bd86fa --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-622663.js @@ -0,0 +1,14 @@ ++// Copyright 2016 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: --no-lazy + +(function() { + try { (y = [...[]]) => {} } catch(_) {} // will core dump, if not fixed +})(); + +(function() { + try { ((y = [...[]]) => {})(); } catch(_) {} // will core dump, if not fixed, + // even without --no-lazy +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-625121.js b/deps/v8/test/mjsunit/regress/regress-625121.js new file mode 100644 index 0000000000..27ad0f5faf --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-625121.js @@ -0,0 +1,16 @@ +// Copyright 2016 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 test(f) { + f(0); + f(NaN); + %OptimizeFunctionOnNextCall(f); + f(1.0); +} + +test(x => Math.cosh(+x)); +test(x => Math.sinh(+x)); +test(x => Math.tanh(+x)); diff --git a/deps/v8/test/mjsunit/regress/regress-631050.js b/deps/v8/test/mjsunit/regress/regress-631050.js new file mode 100644 index 0000000000..b31c6a2022 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-631050.js @@ -0,0 +1,15 @@ +// Copyright 2016 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: --gc-global --stress-runs=8 + +function __f_3(x, expected) { + var __v_3 = []; + __v_3.length = x; + __f_3(true, 1); +} + +try { + __f_3(2147483648, 2147483648); +} catch (e) {} diff --git a/deps/v8/test/mjsunit/regress/regress-632289.js b/deps/v8/test/mjsunit/regress/regress-632289.js new file mode 100644 index 0000000000..65a22558de --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-632289.js @@ -0,0 +1,22 @@ +// Copyright 2016 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: --ignition --turbo-from-bytecode --always-opt --allow-natives-syntax + +try { +} catch(e) {; } +(function __f_12() { +})(); +(function __f_6() { + function __f_3() { + } + function __f_4() { + try { + } catch (e) { + } + } + __f_4(); + %OptimizeFunctionOnNextCall(__f_4); + __f_4(); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-633998.js b/deps/v8/test/mjsunit/regress/regress-633998.js new file mode 100644 index 0000000000..ff34a0a44e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-633998.js @@ -0,0 +1,44 @@ +// 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 err_str_1 = "apply was called on , which is a object and not a function"; +var err_str_2 = + "apply was called on Error, which is a object and not a function"; + +var reached = false; +var error = new Error(); +error.name = error; +try { + Reflect.apply(error); + reached = true; +} catch (e) { + assertTrue(e.stack.indexOf(err_str_1) != -1); +} finally { + assertFalse(reached); +} + +reached = false; +error = new Error(); +error.msg = error; +try { + Reflect.apply(error); + reached = true; +} catch (e) { + assertTrue(e.stack.indexOf(err_str_2) != -1); +} finally { + assertFalse(reached); +} + +reached = false; +error = new Error(); +error.name = error; +error.msg = error; +try { + Reflect.apply(error); + reached = true; +} catch (e) { + assertTrue(e.stack.indexOf(err_str_1) != -1); +} finally { + assertFalse(reached); +} diff --git a/deps/v8/test/mjsunit/regress/regress-635429.js b/deps/v8/test/mjsunit/regress/regress-635429.js new file mode 100644 index 0000000000..7fbce0d3cf --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-635429.js @@ -0,0 +1,12 @@ +// Copyright 2016 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: --stack-size=150 + +function foo() { + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "a" + "boom"}; + +try { + foo() +} catch(e) {} diff --git a/deps/v8/test/mjsunit/regress/regress-638134.js b/deps/v8/test/mjsunit/regress/regress-638134.js new file mode 100644 index 0000000000..5391eed148 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-638134.js @@ -0,0 +1,20 @@ +// Copyright 2016 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() { + // Generates a forward branch that puts 200 in the constant pool. + var i = 0; + if (i) { + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; + } + // Emit a 200 literal which also ends up in the constant pool. + var j = 0.2e3; +} +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-639270.js b/deps/v8/test/mjsunit/regress/regress-639270.js new file mode 100644 index 0000000000..0924650de7 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-639270.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 --es-staging --ignition-staging --turbo + +"use strict"; + +var g = (async () => { return JSON.stringify() }); + +g(); +g(); +%OptimizeFunctionOnNextCall(g); +g(); diff --git a/deps/v8/test/mjsunit/regress/regress-674753.js b/deps/v8/test/mjsunit/regress/regress-674753.js index b3704ea96a..d8a504a695 100644 --- a/deps/v8/test/mjsunit/regress/regress-674753.js +++ b/deps/v8/test/mjsunit/regress/regress-674753.js @@ -25,62 +25,138 @@ // (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 + +var undetectable = %GetUndetectable(); + // Number assertTrue(typeof 0 == 'number'); assertTrue(typeof 0 === 'number'); +assertFalse(typeof 0 != 'number'); +assertFalse(typeof 0 !== 'number'); assertTrue(typeof 1.2 == 'number'); assertTrue(typeof 1.2 === 'number'); +assertFalse(typeof 1.2 != 'number'); +assertFalse(typeof 1.2 !== 'number'); +assertTrue(typeof 'x' != 'number'); +assertTrue(typeof 'x' !== 'number'); assertFalse(typeof 'x' == 'number'); assertFalse(typeof 'x' === 'number'); +assertTrue(typeof Object() != 'number'); +assertTrue(typeof Object() !== 'number'); +assertFalse(typeof Object() == 'number'); +assertFalse(typeof Object() === 'number'); // String assertTrue(typeof 'x' == 'string'); assertTrue(typeof 'x' === 'string'); +assertFalse(typeof 'x' != 'string'); +assertFalse(typeof 'x' !== 'string'); assertTrue(typeof ('x' + 'x') == 'string'); assertTrue(typeof ('x' + 'x') === 'string'); +assertFalse(typeof ('x' + 'x') != 'string'); +assertFalse(typeof ('x' + 'x') !== 'string'); +assertTrue(typeof 1 != 'string'); +assertTrue(typeof 1 !== 'string'); assertFalse(typeof 1 == 'string'); assertFalse(typeof 1 === 'string'); +assertTrue(typeof Object() != 'string'); +assertTrue(typeof Object() !== 'string'); assertFalse(typeof Object() == 'string'); assertFalse(typeof Object() === 'string'); // Boolean assertTrue(typeof true == 'boolean'); assertTrue(typeof true === 'boolean'); +assertFalse(typeof true != 'boolean'); +assertFalse(typeof true !== 'boolean'); assertTrue(typeof false == 'boolean'); assertTrue(typeof false === 'boolean'); +assertFalse(typeof false != 'boolean'); +assertFalse(typeof false !== 'boolean'); +assertTrue(typeof 1 != 'boolean'); +assertTrue(typeof 1 !== 'boolean'); assertFalse(typeof 1 == 'boolean'); assertFalse(typeof 1 === 'boolean'); +assertTrue(typeof 'x' != 'boolean'); +assertTrue(typeof 'x' !== 'boolean'); +assertFalse(typeof 'x' == 'boolean'); +assertFalse(typeof 'x' === 'boolean'); +assertTrue(typeof Object() != 'boolean'); +assertTrue(typeof Object() !== 'boolean'); assertFalse(typeof Object() == 'boolean'); assertFalse(typeof Object() === 'boolean'); // Undefined assertTrue(typeof void 0 == 'undefined'); assertTrue(typeof void 0 === 'undefined'); +assertFalse(typeof void 0 != 'undefined'); +assertFalse(typeof void 0 !== 'undefined'); +assertTrue(typeof 1 != 'undefined'); +assertTrue(typeof 1 !== 'undefined'); assertFalse(typeof 1 == 'undefined'); assertFalse(typeof 1 === 'undefined'); +assertTrue(typeof null != 'undefined'); +assertTrue(typeof null !== 'undefined'); +assertFalse(typeof null == 'undefined'); +assertFalse(typeof null === 'undefined'); +assertTrue(typeof Object() != 'undefined'); +assertTrue(typeof Object() !== 'undefined'); assertFalse(typeof Object() == 'undefined'); assertFalse(typeof Object() === 'undefined'); +assertTrue(typeof undetectable == 'undefined'); +assertTrue(typeof undetectable === 'undefined'); +assertFalse(typeof undetectable != 'undefined'); +assertFalse(typeof undetectable !== 'undefined'); // Function assertTrue(typeof Object == 'function'); assertTrue(typeof Object === 'function'); +assertFalse(typeof Object != 'function'); +assertFalse(typeof Object !== 'function'); +assertTrue(typeof 1 != 'function'); +assertTrue(typeof 1 !== 'function'); assertFalse(typeof 1 == 'function'); assertFalse(typeof 1 === 'function'); +assertTrue(typeof Object() != 'function'); +assertTrue(typeof Object() !== 'function'); assertFalse(typeof Object() == 'function'); assertFalse(typeof Object() === 'function'); +assertTrue(typeof undetectable != 'function'); +assertTrue(typeof undetectable !== 'function'); +assertFalse(typeof undetectable == 'function'); +assertFalse(typeof undetectable === 'function'); // Object assertTrue(typeof Object() == 'object'); assertTrue(typeof Object() === 'object'); +assertFalse(typeof Object() != 'object'); +assertFalse(typeof Object() !== 'object'); assertTrue(typeof new String('x') == 'object'); assertTrue(typeof new String('x') === 'object'); +assertFalse(typeof new String('x') != 'object'); +assertFalse(typeof new String('x') !== 'object'); assertTrue(typeof ['x'] == 'object'); assertTrue(typeof ['x'] === 'object'); +assertFalse(typeof ['x'] != 'object'); +assertFalse(typeof ['x'] !== 'object'); assertTrue(typeof null == 'object'); assertTrue(typeof null === 'object'); +assertFalse(typeof null != 'object'); +assertFalse(typeof null !== 'object'); +assertTrue(typeof 1 != 'object'); +assertTrue(typeof 1 !== 'object'); assertFalse(typeof 1 == 'object'); assertFalse(typeof 1 === 'object'); +assertTrue(typeof 'x' != 'object'); +assertTrue(typeof 'x' !== 'object'); assertFalse(typeof 'x' == 'object'); // bug #674753 assertFalse(typeof 'x' === 'object'); +assertTrue(typeof Object != 'object'); +assertTrue(typeof Object !== 'object'); assertFalse(typeof Object == 'object'); assertFalse(typeof Object === 'object'); +assertTrue(typeof undetectable != 'object'); +assertTrue(typeof undetectable !== 'object'); +assertFalse(typeof undetectable == 'object'); +assertFalse(typeof undetectable === 'object'); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-119800.js b/deps/v8/test/mjsunit/regress/regress-crbug-119800.js index 3946fbb71d..85f28a7bc8 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-119800.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-119800.js @@ -5,9 +5,9 @@ // Flags: --expose-debug-as debug function f() { - 1; - 2; - 3; + print(1); + print(2); + print(3); } var Debug = debug.Debug; @@ -34,4 +34,5 @@ Debug.setListener(null); Debug.debuggerFlags().breakPointsActive.setValue(true); assertNull(exception); -assertEquals(breaks, ["1;", "2;", "3;", "}", "Debug.setListener(null);"]); +assertEquals(breaks, ["print(1);", "print(2);", "print(3);", "}", + "Debug.setListener(null);"]); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-320922.js b/deps/v8/test/mjsunit/regress/regress-crbug-320922.js deleted file mode 100644 index f19962843a..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-crbug-320922.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 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 - -var string = "internalized dummy"; -var expected = "internalized dummy"; -string = "hello world"; -expected = "Hello " + "world"; -function Capitalize() { - %_OneByteSeqStringSetChar(0, 0x48, string); -} -Capitalize(); -assertEquals(expected, string); -Capitalize(); -assertEquals(expected, string); - -var twobyte = "\u20ACello world"; - -function TwoByteCapitalize() { - %_TwoByteSeqStringSetChar(0, 0x48, twobyte); -} -TwoByteCapitalize(); -assertEquals(expected, twobyte); -TwoByteCapitalize(); -assertEquals(expected, twobyte); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-401915.js b/deps/v8/test/mjsunit/regress/regress-crbug-401915.js index 67ea19158e..96dce04868 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() {})); } catch (e) { } throw new Error(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-451770.js b/deps/v8/test/mjsunit/regress/regress-crbug-451770.js index 770c8073cf..b4f088d00e 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-451770.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-451770.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-sloppy - assertThrows(function f() { var t = { toString: function() { throw new Error(); } }; var o = { [t]: 23 }; diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-480807.js b/deps/v8/test/mjsunit/regress/regress-crbug-480807.js index c273f20a78..a1448d6de6 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-480807.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-480807.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: --allow-natives-syntax --use-osr --turbo-osr --noalways-opt +// Flags: --allow-natives-syntax --use-osr --noalways-opt function foo() { var c = 0; diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-495493.js b/deps/v8/test/mjsunit/regress/regress-crbug-495493.js new file mode 100644 index 0000000000..3dba236c37 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-495493.js @@ -0,0 +1,12 @@ +// Copyright 2016 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: --nofold-constants --enable-slow-asserts --debug-code + +function foo(p) { + for (var i = 0; i < 100000; ++i) { + p = Math.min(-1, 0); + } +} +foo(0); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-498142.js b/deps/v8/test/mjsunit/regress/regress-crbug-498142.js deleted file mode 100644 index fcec5d1bd7..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-crbug-498142.js +++ /dev/null @@ -1,8 +0,0 @@ -// 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-sharedarraybuffer - -var sab = new SharedArrayBuffer(16); -assertThrows(function() { %ArrayBufferNeuter(sab); }); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-500497.js b/deps/v8/test/mjsunit/regress/regress-crbug-500497.js index 9117440c2c..356e4e6942 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-500497.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-500497.js @@ -4,6 +4,7 @@ // New space must be at max capacity to trigger pretenuring decision. // Flags: --allow-natives-syntax --verify-heap --max-semi-space-size=1 +// Flags: --expose-gc var global = []; // Used to keep some objects alive. @@ -12,6 +13,8 @@ function Ctor() { return result; } +gc(); + for (var i = 0; i < 120; i++) { // Make the "a" property long-lived, while everything else is short-lived. global.push(Ctor().a); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-515897.js b/deps/v8/test/mjsunit/regress/regress-crbug-515897.js new file mode 100644 index 0000000000..45a812c781 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-515897.js @@ -0,0 +1,9 @@ +// Copyright 2016 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 r1 = new RegExp("\\\\/"); +assertTrue(r1.test("\\/")); +var r2 = eval("/" + r1.source + "/"); +assertEquals("\\\\\\/", r1.source); +assertEquals("\\\\\\/", r2.source); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-570651.js b/deps/v8/test/mjsunit/regress/regress-crbug-570651.js deleted file mode 100644 index 9860b428b1..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-crbug-570651.js +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -Error.prepareStackTrace = (e,s) => s; -var __v_3 = Error().stack[0].constructor; -var __v_4 = {}; -function __f_3() {} -var __v_5 = __v_3.call(null, __v_4, __f_3, {valueOf() { return 1611877293 }}); - __v_5.getColumnNumber(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-571517.js b/deps/v8/test/mjsunit/regress/regress-crbug-571517.js index 03bf76cb5e..ca7d7f73ba 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-571517.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-571517.js @@ -11,7 +11,10 @@ function f(a) { var rec = new Receiver(); -var proto = rec.__proto__.__proto__; +// Formerly, this mutated rec.__proto__.__proto__, but +// the global object prototype chain is now immutable; +// not sure if this test now hits the original hazard case. +var proto = rec.__proto__; // Initialize prototype chain dependent IC (nonexistent load). assertEquals(undefined, f(rec)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-582048.js b/deps/v8/test/mjsunit/regress/regress-crbug-582048.js new file mode 100644 index 0000000000..6d98f488e3 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-582048.js @@ -0,0 +1,31 @@ +// Copyright 2016 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; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var frame_count = exec_state.frameCount(); + for (var i = 0; i < frame_count; i++) { + var frame = exec_state.frame(i); + var scope_count = frame.scopeCount(); + for (var j = 0; j < scope_count; j++) { + var scope = frame.scope(j); + assertTrue(scope.scopeObject().property('').isUndefined()); + } + } + } catch (e) { + print(e, e.stack); + exception = e; + } +} + +Debug.setListener(listener); + +(function(a = 1) { debugger; })(); + +Debug.setListener(null); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-599067.js b/deps/v8/test/mjsunit/regress/regress-crbug-599067.js index bc10aa44c2..de3c99af03 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-599067.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-599067.js @@ -7,5 +7,5 @@ try { var p = new Proxy({}, o); Error.captureStackTrace(p); } catch(e) { - assertEquals("Cannot pass private property name to proxy trap", e.message); + assertEquals("invalid_argument", e.message); } diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-600257.js b/deps/v8/test/mjsunit/regress/regress-crbug-600257.js new file mode 100644 index 0000000000..87bd2e39af --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-600257.js @@ -0,0 +1,13 @@ +// Copyright 2016 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: --stack-size=100 + +(function rec() { + try { + rec(); + } catch (e) { + /{/; + } +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-600995.js b/deps/v8/test/mjsunit/regress/regress-crbug-600995.js deleted file mode 100644 index c532608799..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-crbug-600995.js +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2016 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: --noharmony-iterator-close - -// The {Set} function will produce a different type feedback vector layout -// depending on whether Harmony iterator finalization is enabled or not. - -new Set(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-602184.js b/deps/v8/test/mjsunit/regress/regress-crbug-602184.js new file mode 100644 index 0000000000..c7d793bb0e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-602184.js @@ -0,0 +1,17 @@ +// Copyright 2016 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(test, a) { + var v; + if (test) { + v = v|0; + } + a[v] = 1; +} +var v = new String(); +f(false, v); +f(false, v); + +v = new Int32Array(10); +f(true, v); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-602595.js b/deps/v8/test/mjsunit/regress/regress-crbug-602595.js new file mode 100644 index 0000000000..7f6d478e05 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-602595.js @@ -0,0 +1,12 @@ +// Copyright 2016 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-escape + +function f(a) { return [a] } + +assertEquals([23], f(23)); +assertEquals([42], f(42)); +%OptimizeFunctionOnNextCall(f); +assertEquals([65], f(65)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-603463.js b/deps/v8/test/mjsunit/regress/regress-crbug-603463.js new file mode 100644 index 0000000000..20bfae65c5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-603463.js @@ -0,0 +1,16 @@ +// Copyright 2016 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 load(a, i) { + return a[i]; +} + +function f() { + return load(new Proxy({}, {}), undefined); +} + +f(); +f(); +load([11, 22, 33], 0); +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-604299.js b/deps/v8/test/mjsunit/regress/regress-crbug-604299.js new file mode 100644 index 0000000000..9908f2df4d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-604299.js @@ -0,0 +1,9 @@ +// Copyright 2016 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. + +Array.prototype.__defineSetter__(0,function(value){}); + +if (this.Intl) { + var o = new Intl.DateTimeFormat('en-US', {'timeZone': 'Asia/Katmandu'}) +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-605060.js b/deps/v8/test/mjsunit/regress/regress-crbug-605060.js new file mode 100644 index 0000000000..d2dc79a310 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-605060.js @@ -0,0 +1,10 @@ +// Copyright 2016 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 + +Array.prototype.__defineGetter__('map', function(){}); +Array.prototype.__defineGetter__('map', function(){}); +Array.prototype.__defineGetter__('map', function(){}); +assertTrue(%HasFastProperties(Array.prototype)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-605581.js b/deps/v8/test/mjsunit/regress/regress-crbug-605581.js new file mode 100644 index 0000000000..0f1daabead --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-605581.js @@ -0,0 +1,28 @@ +// Copyright 2016 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; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertThrows(() => exec_state.frame(0).evaluate("bar.baz"), ReferenceError); + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +(function() { + debugger; // bar is still in TDZ at this point. + let bar = 1; + (x => bar); // force bar to be context-allocated. +})(); + +Debug.setListener(null); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-605862.js b/deps/v8/test/mjsunit/regress/regress-crbug-605862.js new file mode 100644 index 0000000000..82a5d454ec --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-605862.js @@ -0,0 +1,6 @@ +// Copyright 2016 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. + +/[]*1/u.exec("\u1234"); +/[^\u0000-\u{10ffff}]*1/u.exec("\u1234"); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-608279.js b/deps/v8/test/mjsunit/regress/regress-crbug-608279.js new file mode 100644 index 0000000000..22c69f252d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-608279.js @@ -0,0 +1,18 @@ +// Copyright 2016 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: --always-opt --no-lazy + +function __f_38() { + try { + throw 0; + } catch (e) { + eval(); + var __v_38 = { a: 'hest' }; + __v_38.m = function () { return __v_38.a; }; + } + return __v_38; +} +var __v_40 = __f_38(); +__v_40.m(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-609029.js b/deps/v8/test/mjsunit/regress/regress-crbug-609029.js new file mode 100644 index 0000000000..bd77de28a9 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-609029.js @@ -0,0 +1,7 @@ +// Copyright 2016 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: --always-opt --function-context-specialization --gc-interval=14 +// Flags: --turbo-filter=match --verify-heap +"xxx".match(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-609046.js b/deps/v8/test/mjsunit/regress/regress-crbug-609046.js new file mode 100644 index 0000000000..10b63af3e3 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-609046.js @@ -0,0 +1,36 @@ +// Copyright 2016 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 + +// Test that hidden scopes are correctly walked in the scope chain. + +var Debug = debug.Debug; +var exception = null; +var delegate = null; +var done = false; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertEquals([ debug.ScopeType.Block, + debug.ScopeType.Script, + debug.ScopeType.Global ], + exec_state.frame(0).allScopes().map(s => s.scopeType())); + done = true; + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +for(let a = 0; a < 3; a++) { + debugger; + eval(); // Force context-allocation of everything. +} + +Debug.setListener(null); +assertNull(exception); +assertTrue(done); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-610207.js b/deps/v8/test/mjsunit/regress/regress-crbug-610207.js new file mode 100644 index 0000000000..4396a56a77 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-610207.js @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +Error.prepareStackTrace = function(exception, frames) { + return frames[0].getEvalOrigin(); +} + +try { + Realm.eval(0, "throw new Error('boom');"); +} catch(e) { + print(e.stack); +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-612109.js b/deps/v8/test/mjsunit/regress/regress-crbug-612109.js new file mode 100644 index 0000000000..202bd96c77 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-612109.js @@ -0,0 +1,8 @@ +// Copyright 2016 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. + + +s = "string for triggering osr in __f_0"; +for (var i = 0; i < 16; i++) s = s + s; +decodeURI(encodeURI(s)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-612142.js b/deps/v8/test/mjsunit/regress/regress-crbug-612142.js new file mode 100644 index 0000000000..de2dc8d04a --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-612142.js @@ -0,0 +1,10 @@ +// Copyright 2016 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 thrower = {[Symbol.toPrimitive]: function(e) { throw e }}; +try { + for (var i = 0; i < 10; i++) { } + for (var i = 0.5; i < 100000; ++i) { } + for (var i = 16 | 0 || 0 || this || 1; i;) { String.fromCharCode(thrower); } +} catch (e) { } diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-613494.js b/deps/v8/test/mjsunit/regress/regress-crbug-613494.js new file mode 100644 index 0000000000..6fcc1e94f4 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-613494.js @@ -0,0 +1,14 @@ +// Copyright 2016 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-escape --noanalyze-environment-liveness + +function f() { + var bound = 0; + function g() { return bound } +} +f(); +f(); +%OptimizeFunctionOnNextCall(f); +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-613570.js b/deps/v8/test/mjsunit/regress/regress-crbug-613570.js new file mode 100644 index 0000000000..3cd9857761 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-613570.js @@ -0,0 +1,6 @@ +// Copyright 2016 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. + +assertEquals("[\n\u26031,\n\u26032\n]", + JSON.stringify([1, 2], null, "\u2603")); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-613905.js b/deps/v8/test/mjsunit/regress/regress-crbug-613905.js new file mode 100644 index 0000000000..8bb38c9b9d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-613905.js @@ -0,0 +1,11 @@ +// Copyright 2016 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. + +Error.prepareStackTrace = (e,s) => s; +var CallSiteConstructor = Error().stack[0].constructor; + +try { + (new CallSiteConstructor(3, 6)).toString(); +} catch (e) { +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-613919.js b/deps/v8/test/mjsunit/regress/regress-crbug-613919.js new file mode 100644 index 0000000000..cbd3e43b96 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-613919.js @@ -0,0 +1,18 @@ +// Copyright 2016 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-escape + +function g(a) { + if (a) return arguments; + %DeoptimizeNow(); + return 23; +} +function f() { + return g(false); +} +assertEquals(23, f()); +assertEquals(23, f()); +%OptimizeFunctionOnNextCall(f); +assertEquals(23, f()); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-614292.js b/deps/v8/test/mjsunit/regress/regress-crbug-614292.js new file mode 100644 index 0000000000..3a67c17f60 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-614292.js @@ -0,0 +1,14 @@ +// Copyright 2016 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() { + return [] | 0 && values[0] || false; +} + +%OptimizeFunctionOnNextCall(foo); +try { + foo(); +} catch (e) {} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-614644.js b/deps/v8/test/mjsunit/regress/regress-crbug-614644.js new file mode 100644 index 0000000000..d219cd3b92 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-614644.js @@ -0,0 +1,15 @@ +// Copyright 2016 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 f(a, x) { + a.shift(2, a.length = 2); + a[0] = x; +} + +f([ ], 1.1); +f([1], 1.1); +%OptimizeFunctionOnNextCall(f); +f([1], 1.1); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-614727.js b/deps/v8/test/mjsunit/regress/regress-crbug-614727.js new file mode 100644 index 0000000000..0845afc5ac --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-614727.js @@ -0,0 +1,23 @@ +// Copyright 2016 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"; + +function f(a, b, c) { return arguments } +function g(...args) { return args } + +// On 64-bit machine this produces a 768K array which is sufficiently small to +// not cause a stack overflow, but big enough to move the allocated arguments +// object into large object space (kMaxRegularHeapObjectSize == 600K). +var length = Math.pow(2, 15) * 3; +var args = new Array(length); +assertEquals(length, f.apply(null, args).length); +assertEquals(length, g.apply(null, args).length); + +// On 32-bit machines this produces an equally sized array, however it might in +// turn trigger a stack overflow on 64-bit machines, which we need to catch. +var length = Math.pow(2, 16) * 3; +var args = new Array(length); +try { f.apply(null, args) } catch(e) {} +try { g.apply(null, args) } catch(e) {} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-615774.js b/deps/v8/test/mjsunit/regress/regress-crbug-615774.js new file mode 100644 index 0000000000..ea5e67513e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-615774.js @@ -0,0 +1,11 @@ +// Copyright 2016 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. + +Error.prepareStackTrace = (e,s) => s; +var CallSiteConstructor = Error().stack[0].constructor; + +try { + (new CallSiteConstructor(CallSiteConstructor, 6)).toString(); +} catch (e) { +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-616709-1.js b/deps/v8/test/mjsunit/regress/regress-crbug-616709-1.js new file mode 100644 index 0000000000..75abe3c2e1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-616709-1.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 + +// Make the Object prototype have dictionary properties. +for (var i = 0; i < 2000; i++) { + Object.prototype['X'+i] = true; +} + +function boom(a1) { + return a1[0]; +} + +var a = new Array(1); +a[0] = 0.1; +boom(a); +boom(a); +%OptimizeFunctionOnNextCall(boom); +boom(a); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-616709-2.js b/deps/v8/test/mjsunit/regress/regress-crbug-616709-2.js new file mode 100644 index 0000000000..27e5d2d9da --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-616709-2.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 + +// Make the Array prototype have dictionary properties. +for (var i = 0; i < 2000; i++) { + Array.prototype['X'+i] = true; +} + +function boom(a1) { + return a1[0]; +} + +var a = new Array(1); +a[0] = 0.1; +boom(a); +boom(a); +%OptimizeFunctionOnNextCall(boom); +boom(a); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-617527.js b/deps/v8/test/mjsunit/regress/regress-crbug-617527.js new file mode 100644 index 0000000000..cf4662871c --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-617527.js @@ -0,0 +1,8 @@ +// Copyright 2016 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 + +Object.defineProperty(Array.prototype, "1", { get: toLocaleString }); +assertThrows(_ => new RegExp(0, 0)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-617567.js b/deps/v8/test/mjsunit/regress/regress-crbug-617567.js new file mode 100644 index 0000000000..f0c696e14b --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-617567.js @@ -0,0 +1,24 @@ +// Copyright 2016 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: --turbo-filter=* --allow-natives-syntax + +var v1 = {}; +function g() { + v1 = []; + for (var i = 0; i < 1; i++) { + v1[i](); + } +} + +var v2 = {}; +var v3 = {}; +function f() { + v3 = v2; + g(); +} + +assertThrows(g); +%OptimizeFunctionOnNextCall(f); +assertThrows(f); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-618788.js b/deps/v8/test/mjsunit/regress/regress-crbug-618788.js new file mode 100644 index 0000000000..a104d8d39e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-618788.js @@ -0,0 +1,21 @@ +// Copyright 2016 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. + +// Slice and splice both try to set the length property of their return +// value. Add a bogus setter to allow that. +Object.defineProperty(Int32Array.prototype, 'length', { set(v) { } }); + +(function testSlice() { + var a = new Array(); + a.constructor = Int32Array; + a.length = 1000; // Make the length >= 1000 so UseSparseVariant returns true. + assertTrue(a.slice() instanceof Int32Array); +})(); + +(function testSplice() { + var a = new Array(); + a.constructor = Int32Array; + a.length = 1000; // Make the length >= 1000 so UseSparseVariant returns true. + assertTrue(a.splice(1) instanceof Int32Array); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-618845.js b/deps/v8/test/mjsunit/regress/regress-crbug-618845.js new file mode 100644 index 0000000000..ea3baba0bb --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-618845.js @@ -0,0 +1,16 @@ +// Copyright 2016 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() {} +Object.defineProperty(Foo.prototype, "name", + {get: function() { return "FooName"; }}); + +function ic(f) { + return f.prototype.name; +} + +assertEquals("FooName", ic(Foo)); +assertEquals("FooName", ic(Foo)); // Don't crash, don't time out. diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-620119.js b/deps/v8/test/mjsunit/regress/regress-crbug-620119.js new file mode 100644 index 0000000000..cbe5a78713 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-620119.js @@ -0,0 +1,8 @@ +// Copyright 2016 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: --no-lazy + +assertEquals(0, ((x, {[(x = function() { y = 0 }, "foo")]: y = eval(1)}) => { x(); return y })(42, {})); +assertEquals(0, (function (x, {[(x = function() { y = 0 }, "foo")]: y = eval(1)}) { x(); return y })(42, {})); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-620253.js b/deps/v8/test/mjsunit/regress/regress-crbug-620253.js new file mode 100644 index 0000000000..811a4e7715 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-620253.js @@ -0,0 +1,7 @@ +// Copyright 2016 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: --throws + +load("test/mjsunit/regress/regress-crbug-620253.js"); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-620650.js b/deps/v8/test/mjsunit/regress/regress-crbug-620650.js new file mode 100644 index 0000000000..25a92cab20 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-620650.js @@ -0,0 +1,16 @@ +// Copyright 2016 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() { + function f(src, dst, i) { + dst[i] = src[i]; + } + var buf = new ArrayBuffer(16); + var view_int32 = new Int32Array(buf); + view_int32[1] = 0xFFF7FFFF; + var view_f64 = new Float64Array(buf); + var arr = [,0.1]; + f(view_f64, arr, -1); + f(view_f64, arr, 0); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-621361.js b/deps/v8/test/mjsunit/regress/regress-crbug-621361.js new file mode 100644 index 0000000000..f9496ae87d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-621361.js @@ -0,0 +1,40 @@ +// Copyright 2016 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 steps = 0; +var exception = null; + +function listener(event, execState, eventData, data) { + if (event != Debug.DebugEvent.Break) return; + try { + assertEquals([ debug.ScopeType.Local, + debug.ScopeType.Script, + debug.ScopeType.Global], + execState.frame().allScopes().map(s => s.scopeType())); + var x_value = execState.frame().evaluate("x").value(); + if (steps < 2) { + assertEquals(undefined, x_value); + execState.prepareStep(Debug.StepAction.StepIn); + } else { + assertEquals("l => l", x_value.toString()); + } + steps++; + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); + +(function() { + debugger; + var x = l => l; +})(); + +Debug.setListener(null); +assertNull(exception); +assertEquals(3, steps); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-621611.js b/deps/v8/test/mjsunit/regress/regress-crbug-621611.js new file mode 100644 index 0000000000..bf9a4605cd --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-621611.js @@ -0,0 +1,11 @@ +// Copyright 2016 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. + +assertEquals(Math.E, Math.exp(1)); +assertEquals(Math.LN10, Math.log(10)); +assertEquals(Math.LN2, Math.log(2)); +assertEquals(Math.LOG10E, Math.log10(Math.E)); +assertEquals(Math.LOG2E, Math.log2(Math.E)); +assertEquals(Math.SQRT1_2, Math.sqrt(0.5)); +assertEquals(Math.SQRT2, Math.sqrt(2)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-621816.js b/deps/v8/test/mjsunit/regress/regress-crbug-621816.js new file mode 100644 index 0000000000..ca7f5ac6df --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-621816.js @@ -0,0 +1,18 @@ +// Copyright 2016 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 + +function f() { + var o = {}; + o.a = 1; +} +function g() { + var o = { ['a']: function(){} }; + f(); +} +f(); +f(); +%OptimizeFunctionOnNextCall(g); +g(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-624747.js b/deps/v8/test/mjsunit/regress/regress-crbug-624747.js new file mode 100644 index 0000000000..7927263f8e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-624747.js @@ -0,0 +1,22 @@ +// Copyright 2016 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 --es-staging + +"use strict"; + +function bar() { + try { + unref; + } catch (e) { + return (1 instanceof TypeError) && unref(); // Call in tail position! + } +} + +function foo() { + return bar(); // Call in tail position! +} + +%OptimizeFunctionOnNextCall(foo); +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-624919.js b/deps/v8/test/mjsunit/regress/regress-crbug-624919.js new file mode 100644 index 0000000000..5a2b100daf --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-624919.js @@ -0,0 +1,14 @@ +// Copyright 2016 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 f(a, b, c, d, e) { + if (a && (b, c ? d() : e())) return 0; +} + +f(); +f(); +%OptimizeFunctionOnNextCall(f); +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-625547.js b/deps/v8/test/mjsunit/regress/regress-crbug-625547.js new file mode 100644 index 0000000000..20eb85db5e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-625547.js @@ -0,0 +1,21 @@ +// Copyright 2016 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 v1 = {}; +v1 = 0; +var v2 = {}; +v2 = 0; +gc(); + +var minus_zero = {z:-0.0}.z; +var nan = undefined + 1; +function f() { + v1 = minus_zero; + v2 = nan; +}; +%OptimizeFunctionOnNextCall(f); +f(); +gc(); // Boom! diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-625590.js b/deps/v8/test/mjsunit/regress/regress-crbug-625590.js new file mode 100644 index 0000000000..aa9ff8a5df --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-625590.js @@ -0,0 +1,12 @@ +// Copyright 2016 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 obj = {}; +function f() {} +f.prototype = { + mSloppy() { + super[obj] = 15; + } +}; +new f().mSloppy(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-626715.js b/deps/v8/test/mjsunit/regress/regress-crbug-626715.js new file mode 100644 index 0000000000..e842fa61c7 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-626715.js @@ -0,0 +1,28 @@ +// Copyright 2016 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. + +// Create a prototype object which has a lot of fast properties. +var body = ""; +for (var i = 0; i < 100; i++) { + body += `this.a${i} = 0;\n`; +} +var Proto = new Function(body); + +function A() {} +A.prototype = new Proto(); + +// Create a object and add properties that already exist in the prototype. +// At some point the object will turn into a dictionary mode and one of +// the fast details from the prototype will be reinterpreted as a details +// for a new property ... +var o = new A(); +for (var i = 0; i < 100; i++) { + o["a" + i] = i; +} + +// ... which will break the enumeration order of the slow properties. +var names = Object.getOwnPropertyNames(o); +for (var i = 0; i < 100; i++) { + assertEquals("a" + i, names[i]); +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-627828.js b/deps/v8/test/mjsunit/regress/regress-crbug-627828.js new file mode 100644 index 0000000000..75ff77cb64 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-627828.js @@ -0,0 +1,40 @@ +// Copyright 2016 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 TestDeoptFromCopmputedNameInObjectLiteral() { + function f() { + var o = { + toString: function() { + %DeoptimizeFunction(f); + return "x"; + } + }; + return { [o]() { return 23 } }; + } + assertEquals(23, f().x()); + assertEquals(23, f().x()); + %OptimizeFunctionOnNextCall(f); + assertEquals(23, f().x()); +})(); + +(function TestDeoptFromCopmputedNameInClassLiteral() { + function g() { + var o = { + toString: function() { + %DeoptimizeFunction(g); + return "y"; + } + }; + class C { + [o]() { return 42 }; + } + return new C(); + } + assertEquals(42, g().y()); + assertEquals(42, g().y()); + %OptimizeFunctionOnNextCall(g); + assertEquals(42, g().y()); +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-627934.js b/deps/v8/test/mjsunit/regress/regress-crbug-627934.js new file mode 100644 index 0000000000..242dc4a78e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-627934.js @@ -0,0 +1,12 @@ +// Copyright 2016 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 x = "1".repeat(32 * 1024 * 1024); +for (var z = x;;) { + try { + z += {toString: function() { return x; }}; + } catch (e) { + break; + } +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-627935.js b/deps/v8/test/mjsunit/regress/regress-crbug-627935.js new file mode 100644 index 0000000000..fdc4d2acde --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-627935.js @@ -0,0 +1,12 @@ +// Copyright 2016 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. + +if (this.Intl) { + assertThrows("Intl.DateTimeFormat('en-US', {timeZone: 0})", RangeError); + assertThrows("Intl.DateTimeFormat('en-US', {timeZone: true})", RangeError); + assertThrows("Intl.DateTimeFormat('en-US', {timeZone: null})", RangeError); + + var object = { toString: function() { return "UTC" } }; + assertDoesNotThrow("Intl.DateTimeFormat('en-US', {timeZone: object})"); +} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-628573.js b/deps/v8/test/mjsunit/regress/regress-crbug-628573.js new file mode 100644 index 0000000000..5ba184d9ab --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-628573.js @@ -0,0 +1,17 @@ +// Copyright 2016 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 + +var z = {valueOf: function() { return 3; }}; + +(function() { + try { + var tmp = { x: 12 }; + with (tmp) { + z++; + } + throw new Error("boom"); + } catch(e) {} +})(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-629062.js b/deps/v8/test/mjsunit/regress/regress-crbug-629062.js new file mode 100644 index 0000000000..228ae6d2d5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-629062.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { + return 1 + ((1 == 0) && undefined); +} + +foo(false); +foo(false); +%OptimizeFunctionOnNextCall(foo); +foo(true); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-629435.js b/deps/v8/test/mjsunit/regress/regress-crbug-629435.js new file mode 100644 index 0000000000..b73f601c71 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-629435.js @@ -0,0 +1,19 @@ +// Copyright 2016 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 bar(v) { + v.constructor; +} + +bar([]); +bar([]); + +function foo() { + var x = -0; + bar(x + 1); +} +%OptimizeFunctionOnNextCall(foo); +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-629823.js b/deps/v8/test/mjsunit/regress/regress-crbug-629823.js new file mode 100644 index 0000000000..bbf74b80af --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-629823.js @@ -0,0 +1,17 @@ +// Copyright 2016 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 + +var o = {} +function bar() { + o[0] = +o[0]; + o = /\u23a1|__v_4/; +} +bar(); +bar(); +bar(); +function foo() { bar(); } +%OptimizeFunctionOnNextCall(foo); +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-629996.js b/deps/v8/test/mjsunit/regress/regress-crbug-629996.js new file mode 100644 index 0000000000..025a86ee72 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-629996.js @@ -0,0 +1,9 @@ +// Copyright 2016 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 mirror = debug.MakeMirror(new Proxy({}, {})); +// As long as we have no special mirror for proxies, we use an object mirror. +assertEquals("object", mirror.type()); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-492526.js b/deps/v8/test/mjsunit/regress/regress-crbug-630559.js index e8ea298f8b..f9623ed879 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-492526.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-630559.js @@ -1,7 +1,7 @@ -// Copyright 2015 the V8 project authors. All rights reserved. +// Copyright 2016 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 -assertThrows(function() { %FormatMessageString(-1, "", "", ""); }); +assertThrows("try{}%"); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-630561.js b/deps/v8/test/mjsunit/regress/regress-crbug-630561.js new file mode 100644 index 0000000000..798f33d658 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-630561.js @@ -0,0 +1,13 @@ +// Copyright 2016 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: --gc-interval=30 + +var dict_elements = {}; + +for (var i= 0; i< 100; i++) { + dict_elements[2147483648 + i] = i; +} + +var keys = Object.keys(dict_elements); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-630923.js b/deps/v8/test/mjsunit/regress/regress-crbug-630923.js new file mode 100644 index 0000000000..ff0d2dd05e --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-630923.js @@ -0,0 +1,16 @@ +// Copyright 2016 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 + +var o = {}; +function bar(o) { + return 1 + (o.t ? 1 : 2); +} +function foo() { + bar(o); +} +foo(); +%OptimizeFunctionOnNextCall(foo); +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-630951.js b/deps/v8/test/mjsunit/regress/regress-crbug-630951.js new file mode 100644 index 0000000000..58af024d3a --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-630951.js @@ -0,0 +1,12 @@ +// Copyright 2016 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() { + "use asm"; + var o = new Int32Array(64 * 1024); + return () => { o[i1 >> 2] | 0; } +} +assertThrows(foo()); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-630952.js b/deps/v8/test/mjsunit/regress/regress-crbug-630952.js new file mode 100644 index 0000000000..42d30a3ec1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-630952.js @@ -0,0 +1,25 @@ +// Copyright 2016 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: --always-opt +try { +function __f_4(sign_bit, + mantissa_29_bits) { +} +__f_4.prototype.returnSpecial = function() { + this.mantissa_29_bits * mantissa_29_shift; +} +__f_4.prototype.toSingle = function() { + if (-65535) return this.toSingleSubnormal(); +} +__f_4.prototype.toSingleSubnormal = function() { + if (__v_15) { + var __v_7 = this.mantissa_29_bits == -1 && + (__v_13 & __v_10 ) == 0; + } + __v_8 >>= __v_7; +} +__v_14 = new __f_4(); +__v_14.toSingle(); +} catch(e) {} diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-1.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-1.js new file mode 100644 index 0000000000..bd40dcd3a2 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-1.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x < x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-10.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-10.js new file mode 100644 index 0000000000..1c4fccaac1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-10.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x << x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-11.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-11.js new file mode 100644 index 0000000000..a03a125ede --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-11.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x >> x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-12.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-12.js new file mode 100644 index 0000000000..f710bd0149 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-12.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x >>> x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-13.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-13.js new file mode 100644 index 0000000000..7a784481ee --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-13.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x & x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-14.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-14.js new file mode 100644 index 0000000000..829bf900b6 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-14.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x | x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-15.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-15.js new file mode 100644 index 0000000000..1257d797ae --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-15.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x ^ x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-2.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-2.js new file mode 100644 index 0000000000..ce46b27886 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-2.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x > x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-3.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-3.js new file mode 100644 index 0000000000..4258b15508 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-3.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x >= x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-4.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-4.js new file mode 100644 index 0000000000..7e8cdf8f56 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-4.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x <= x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-5.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-5.js new file mode 100644 index 0000000000..acdedcba13 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-5.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x + x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-6.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-6.js new file mode 100644 index 0000000000..d17772f17c --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-6.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x / x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-7.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-7.js new file mode 100644 index 0000000000..7d03fa8551 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-7.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x * x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-8.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-8.js new file mode 100644 index 0000000000..474110b53d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-8.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x % x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631318-9.js b/deps/v8/test/mjsunit/regress/regress-crbug-631318-9.js new file mode 100644 index 0000000000..ad472e0722 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631318-9.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { return x - x; } +foo(1); +foo(2); + +function bar(x) { foo(x); } +%OptimizeFunctionOnNextCall(bar); + +assertThrows(() => bar(Symbol.toPrimitive)); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-631917.js b/deps/v8/test/mjsunit/regress/regress-crbug-631917.js new file mode 100644 index 0000000000..ca7a94c844 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-631917.js @@ -0,0 +1,38 @@ +// Copyright 2016 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 b = { toString: function() { return "b"; } }; +var c = { toString: function() { return "c"; } }; + +(function() { + var expected_receiver; + var obj1 = { + a: 100, + b_: 200, + get b() { assertEquals(expected_receiver, this); return this.b_; }, + set b(v) { assertEquals(expected_receiver, this); this.b_ = v; }, + c_: 300, + get c() { assertEquals(expected_receiver, this); return this.c_; }, + set c(v) { assertEquals(expected_receiver, this); this.c_ = v; }, + }; + var obj2 = { + boom() { + super.a++; + super[b]++; + super[c]++; + }, + } + Object.setPrototypeOf(obj2, obj1); + + expected_receiver = obj2; + obj2.boom(); + assertEquals(101, obj2.a); + assertEquals(201, obj2[b]); + assertEquals(301, obj2[c]); + + expected_receiver = obj1; + assertEquals(100, obj1.a); + assertEquals(200, obj1[b]); + assertEquals(300, obj1[c]); +}()); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-632800.js b/deps/v8/test/mjsunit/regress/regress-crbug-632800.js new file mode 100644 index 0000000000..6296572c17 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-632800.js @@ -0,0 +1,10 @@ +// Copyright 2016 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: --ignition --ignition-osr --turbo-from-bytecode + +function osr() { + for (var i = 0; i < 50000; ++i) Math.random(); +} +osr(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-633585.js b/deps/v8/test/mjsunit/regress/regress-crbug-633585.js new file mode 100644 index 0000000000..c483e47bbc --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-633585.js @@ -0,0 +1,18 @@ +// Copyright 2016 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-gc --turbo --always-opt + +function f() { this.x = this.x.x; } +gc(); +f.prototype.x = { x:1 } +new f(); +new f(); + +function g() { + function h() {}; + h.prototype = { set x(value) { } }; + new f(); +} +g(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-633884.js b/deps/v8/test/mjsunit/regress/regress-crbug-633884.js new file mode 100644 index 0000000000..6f46e96725 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-633884.js @@ -0,0 +1,15 @@ +// Copyright 2016 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. + +try { + // Leave "blarg" as the hole in a new ScriptContext. + Realm.eval(Realm.current(), "throw Error(); let blarg"); +} catch (e) { } + +// Access "blarg" via a dynamic lookup. Should not crash! +assertThrows(function() { + // Prevent full-codegen from optimizing away the %LoadLookupSlot call. + eval("var x = 5"); + blarg; +}); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-633999.js b/deps/v8/test/mjsunit/regress/regress-crbug-633999.js new file mode 100644 index 0000000000..3f16908610 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-633999.js @@ -0,0 +1,40 @@ +// Copyright 2016 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 --noturbo + +var Debug = debug.Debug +var exception = null; +var step = 0; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Exception) return; + try { + step++; + } catch (e) { + exception = e; + } +} + +Debug.setBreakOnException(); +Debug.setListener(listener); + +(function () { + "use asm"; + function f() { + try { + throw 666; + } catch (e) { + } + } + f(); + f(); + %OptimizeFunctionOnNextCall(f); + f(); + assertOptimized(f); +})(); + +Debug.setListener(null); +assertNull(exception); +assertEquals(3, step); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-635798.js b/deps/v8/test/mjsunit/regress/regress-crbug-635798.js new file mode 100644 index 0000000000..5456682ddc --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-635798.js @@ -0,0 +1,15 @@ +// Copyright 2016 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() { + var x = []; + var y = []; + x.__proto__ = y; + for (var i = 0; i < 200000; ++i) { + y[i] = 1; + } +} +foo(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-638551.js b/deps/v8/test/mjsunit/regress/regress-crbug-638551.js new file mode 100644 index 0000000000..baa8e9b051 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-638551.js @@ -0,0 +1,18 @@ +// Copyright 2016 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 --ignition-staging --no-lazy + +function f() { + for (var i = 0; i < 10; i++) if (i == 5) %OptimizeOsr(); + function g() {} + %OptimizeFunctionOnNextCall(g); + g(); +} +f(); +gc(); // Make sure that ... +gc(); // ... code flushing ... +gc(); // ... clears code ... +gc(); // ... attached to {g}. +f(); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-390925.js b/deps/v8/test/mjsunit/regress/regress-crbug-640369.js index c4d98adb3e..97982d1224 100644 --- a/deps/v8/test/mjsunit/regress/regress-crbug-390925.js +++ b/deps/v8/test/mjsunit/regress/regress-crbug-640369.js @@ -4,7 +4,12 @@ // Flags: --allow-natives-syntax -var a = new Array(); -var b = new Array(); -Object.freeze(a); -assertThrows(function() { %LiveEditCheckAndDropActivations(a, b, true); }); +function A() { + this.x = 0; + for (var i = 0; i < max; ) {} +} +function foo() { + for (var i = 0; i < 1; i = 2) %OptimizeOsr(); + return new A(); +} +try { foo(); } catch (e) { } diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-642056.js b/deps/v8/test/mjsunit/regress/regress-crbug-642056.js new file mode 100644 index 0000000000..ca9fc78ef6 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-642056.js @@ -0,0 +1,17 @@ +// Copyright 2016 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 f(o) { + return o.x instanceof Array; +} + +var o = { x : 1.5 }; +o.x = 0; + +f(o); +f(o); +%OptimizeFunctionOnNextCall(f); +f(o); diff --git a/deps/v8/test/mjsunit/regress/regress-crbug-644215.js b/deps/v8/test/mjsunit/regress/regress-crbug-644215.js new file mode 100644 index 0000000000..c74112542d --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-crbug-644215.js @@ -0,0 +1,13 @@ +// Copyright 2016 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 + +var arr = [...[],,]; +assertTrue(%HasFastHoleyElements(arr)); +assertEquals(1, arr.length); +assertFalse(arr.hasOwnProperty(0)); +assertEquals(undefined, arr[0]); +// Should not crash. +assertThrows(() => arr[0][0], TypeError); diff --git a/deps/v8/test/mjsunit/regress/regress-double-canonicalization.js b/deps/v8/test/mjsunit/regress/regress-double-canonicalization.js new file mode 100644 index 0000000000..2b345d2bb7 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-double-canonicalization.js @@ -0,0 +1,24 @@ +// Copyright 2016 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 + +var ab = new ArrayBuffer(8); +var i_view = new Int32Array(ab); +i_view[0] = %GetHoleNaNUpper() +i_view[1] = %GetHoleNaNLower(); +var hole_nan = (new Float64Array(ab))[0]; + +var array = []; + +function write() { + array[0] = hole_nan; +} + +write(); +%OptimizeFunctionOnNextCall(write); +write(); +array[1] = undefined; +assertTrue(isNaN(array[0])); +assertEquals("number", typeof array[0]); diff --git a/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated-2.js b/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated-2.js new file mode 100644 index 0000000000..89693de1a4 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated-2.js @@ -0,0 +1,8 @@ +// Copyright 2016 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 x = {a:1, b:2}; +Object.defineProperty(x, "c", {set(v) {}}) +var y = {get c() { return {a:1, b:2.5} }}; +Object.assign(x, y, x); diff --git a/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated.js b/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated.js new file mode 100644 index 0000000000..d2e60f99e5 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-object-assign-deprecated.js @@ -0,0 +1,7 @@ +// Copyright 2016 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 x = {a:1, b:2}; +var y = {a:1, b:2.5}; +Object.assign(x, x); diff --git a/deps/v8/test/mjsunit/regress/regress-observe-map-cache.js b/deps/v8/test/mjsunit/regress/regress-observe-map-cache.js deleted file mode 100644 index c71759c0cc..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-observe-map-cache.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2014 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-object-observe -// Flags: --allow-natives-syntax --enable-slow-asserts - -function f() { - var x = new Array(0); - x[-1] = -1; - Object.observe(x, function() { }); -} - -f(); -f(); diff --git a/deps/v8/test/mjsunit/regress/regress-put-prototype-transition.js b/deps/v8/test/mjsunit/regress/regress-put-prototype-transition.js index 70f0074683..c5b4c5abc0 100644 --- a/deps/v8/test/mjsunit/regress/regress-put-prototype-transition.js +++ b/deps/v8/test/mjsunit/regress/regress-put-prototype-transition.js @@ -30,7 +30,7 @@ function __f_1(__v_4, add_first, __v_6, same_map_as) { __f_4(__v_1); assertFalse(%HasFastProperties(__v_1)); __f_0(__v_1, __v_6); - assertTrue(%HasFastProperties(__v_1)); + assertFalse(%HasFastProperties(__v_1)); } else { __f_0(__v_1, __v_6); assertTrue(%HasFastProperties(__v_1)); diff --git a/deps/v8/test/mjsunit/regress/regress-recurse-patch-binary-op.js b/deps/v8/test/mjsunit/regress/regress-recurse-patch-binary-op.js new file mode 100644 index 0000000000..842cc79fc8 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-recurse-patch-binary-op.js @@ -0,0 +1,10 @@ +// Copyright 2016 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 i = 0 +function valueOf() { + while (true) return i++ < 4 ? 1 + this : 2 +} + +1 + ({valueOf}) diff --git a/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex1.js b/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex1.js deleted file mode 100644 index 444fe4beb4..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex1.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 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 - -// stubbed version of ToNumber -function ToNumber(x) { - return 311; -} - -// Reduced version of String.fromCharCode; -// does not actually do the same calculation but exhibits untagging bug. -function StringFromCharCode(code) { - var n = arguments.length; - var one_byte = %NewString(n, true); - var i; - for (i = 0; i < n; i++) { - var code = arguments[i]; - if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff; - if (code > 0xff) break; - } - - var two_byte = %NewString(n - i, false); - for (var j = 0; i < n; i++, j++) { - var code = arguments[i]; - %_TwoByteSeqStringSetChar(j, code, two_byte); - } - return one_byte + two_byte; -} - -StringFromCharCode(0xFFF, 0xFFF); -StringFromCharCode(0x7C, 0x7C); -%OptimizeFunctionOnNextCall(StringFromCharCode); -StringFromCharCode(0x7C, 0x7C); -StringFromCharCode(0xFFF, 0xFFF); diff --git a/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex3.js b/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex3.js deleted file mode 100644 index 0a6b211648..0000000000 --- a/deps/v8/test/mjsunit/regress/regress-seqstrsetchar-ex3.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 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 - -function test() { - var string = %NewString(10, true); - for (var i = 0; i < 10; i++) { - %_OneByteSeqStringSetChar(i, 65, string); - %_OneByteSeqStringSetChar(i, 66, string); - } - for (var i = 0; i < 10; i++) { - assertEquals("B", string[i]); - } -} - -test(); -test(); -%OptimizeFunctionOnNextCall(test); -test(); diff --git a/deps/v8/test/mjsunit/regress/regress-string-from-char-code-tonumber.js b/deps/v8/test/mjsunit/regress/regress-string-from-char-code-tonumber.js new file mode 100644 index 0000000000..a02a2778b6 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-string-from-char-code-tonumber.js @@ -0,0 +1,26 @@ +// Copyright 2016 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 + +var thrower = { [Symbol.toPrimitive]: function() { FAIL } }; + +function testTrace(func) { + try { + func(thrower); + assertUnreachable(); + } catch (e) { + assertTrue(e.stack.indexOf("fromCharCode") >= 0); + } +} + +testTrace(String.fromCharCode); + +function foo(x) { return String.fromCharCode(x); } + +foo(1); +foo(2); +testTrace(foo); +%OptimizeFunctionOnNextCall(foo); +testTrace(foo); diff --git a/deps/v8/test/mjsunit/regress/regress-typedarray-length.js b/deps/v8/test/mjsunit/regress/regress-typedarray-length.js index a0b99980c7..0dde61fc27 100644 --- a/deps/v8/test/mjsunit/regress/regress-typedarray-length.js +++ b/deps/v8/test/mjsunit/regress/regress-typedarray-length.js @@ -108,13 +108,13 @@ assertEquals(undefined, get(a)); assertEquals("blah", get(a)); })(); -// Ensure we cannot delete length, byteOffset, byteLength. +// Ensure we can delete length, byteOffset, byteLength. assertTrue(Int32Array.prototype.__proto__.hasOwnProperty("length")); assertTrue(Int32Array.prototype.__proto__.hasOwnProperty("byteOffset")); assertTrue(Int32Array.prototype.__proto__.hasOwnProperty("byteLength")); -assertFalse(delete Int32Array.prototype.__proto__.length); -assertFalse(delete Int32Array.prototype.__proto__.byteOffset); -assertFalse(delete Int32Array.prototype.__proto__.byteLength); +assertTrue(delete Int32Array.prototype.__proto__.length); +assertTrue(delete Int32Array.prototype.__proto__.byteOffset); +assertTrue(delete Int32Array.prototype.__proto__.byteLength); a = new Int32Array(100); @@ -122,28 +122,28 @@ get = function(a) { return a.length; } -assertEquals(100, get(a)); -assertEquals(100, get(a)); -assertEquals(100, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); %OptimizeFunctionOnNextCall(get); -assertEquals(100, get(a)); +assertEquals(undefined, get(a)); get = function(a) { return a.byteLength; } -assertEquals(400, get(a)); -assertEquals(400, get(a)); -assertEquals(400, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); %OptimizeFunctionOnNextCall(get); -assertEquals(400, get(a)); +assertEquals(undefined, get(a)); get = function(a) { return a.byteOffset; } -assertEquals(0, get(a)); -assertEquals(0, get(a)); -assertEquals(0, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); +assertEquals(undefined, get(a)); %OptimizeFunctionOnNextCall(get); -assertEquals(0, get(a)); +assertEquals(undefined, get(a)); diff --git a/deps/v8/test/mjsunit/regress/regress-v8-5254-1.js b/deps/v8/test/mjsunit/regress/regress-v8-5254-1.js new file mode 100644 index 0000000000..624c85f477 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-v8-5254-1.js @@ -0,0 +1,27 @@ +// Copyright 2016 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 + +var foo = (function() { + "use asm"; + var a = new Uint16Array(2); + a[0] = 32815; + a[1] = 32114; + + function foo() { + var x = a[0]|0; + var y = a[1]|0; + if (x < 0) x = 4294967296 + x|0; + if (y < 0) y = 4294967296 + y|0; + return x >= y; + } + + return foo; +})(); + +assertTrue(foo()); +assertTrue(foo()); +%OptimizeFunctionOnNextCall(foo); +assertTrue(foo()); diff --git a/deps/v8/test/mjsunit/regress/regress-v8-5254-2.js b/deps/v8/test/mjsunit/regress/regress-v8-5254-2.js new file mode 100644 index 0000000000..f486fa8aa3 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-v8-5254-2.js @@ -0,0 +1,27 @@ +// Copyright 2016 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 + +var foo = (function() { + "use asm"; + var a = new Uint8Array(2); + a[0] = 128; + a[1] = 127; + + function foo() { + var x = a[0]|0; + var y = a[1]|0; + if (x < 0) x = 4294967296 + x|0; + if (y < 0) y = 4294967296 + y|0; + return x >= y; + } + + return foo; +})(); + +assertTrue(foo()); +assertTrue(foo()); +%OptimizeFunctionOnNextCall(foo); +assertTrue(foo()); diff --git a/deps/v8/test/mjsunit/regress/regress-v8-5255-1.js b/deps/v8/test/mjsunit/regress/regress-v8-5255-1.js new file mode 100644 index 0000000000..cd14d63792 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-v8-5255-1.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { + return (x ? true : "7") >> 0; +} + +assertEquals(1, foo(1)); +assertEquals(1, foo(1)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(7, foo(0)); diff --git a/deps/v8/test/mjsunit/regress/regress-v8-5255-2.js b/deps/v8/test/mjsunit/regress/regress-v8-5255-2.js new file mode 100644 index 0000000000..5ae57ce64a --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-v8-5255-2.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { + return (x ? true : "7") << 0; +} + +assertEquals(1, foo(1)); +assertEquals(1, foo(1)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(7, foo(0)); diff --git a/deps/v8/test/mjsunit/regress/regress-v8-5255-3.js b/deps/v8/test/mjsunit/regress/regress-v8-5255-3.js new file mode 100644 index 0000000000..004d6874ad --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-v8-5255-3.js @@ -0,0 +1,14 @@ +// Copyright 2016 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(x) { + return (x ? true : "7") >>> 0; +} + +assertEquals(1, foo(1)); +assertEquals(1, foo(1)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(7, foo(0)); diff --git a/deps/v8/test/mjsunit/regress/regress-wasm-crbug-599413.js b/deps/v8/test/mjsunit/regress/regress-wasm-crbug-599413.js new file mode 100644 index 0000000000..8f11ee0425 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-wasm-crbug-599413.js @@ -0,0 +1,18 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function __f_100() { + "use asm"; + function __f_76() { + var __v_39 = 0; + outer: while (1) { + while (__v_39 == 4294967295) { + } + } + } + return {__f_76: __f_76}; +} +assertTrue(%IsNotAsmWasmCode(__f_100)); diff --git a/deps/v8/test/mjsunit/regress/regress-wasm-crbug-618602.js b/deps/v8/test/mjsunit/regress/regress-wasm-crbug-618602.js new file mode 100644 index 0000000000..7aafe18475 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-wasm-crbug-618602.js @@ -0,0 +1,15 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function __f_1() { + 'use asm'; + function __f_3() { + var __v_11 = 1, __v_10 = 0, __v_12 = 0; + __v_12 = (__v_10 | 12) % 4294967295 | -1073741824; + } + return { __f_3: __f_3 }; +} +assertTrue(%IsNotAsmWasmCode(__f_1)); diff --git a/deps/v8/test/mjsunit/regress/string-set-char-deopt.js b/deps/v8/test/mjsunit/regress/string-set-char-deopt.js deleted file mode 100644 index 8956e287db..0000000000 --- a/deps/v8/test/mjsunit/regress/string-set-char-deopt.js +++ /dev/null @@ -1,85 +0,0 @@ -// 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: -// -// * 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 - -(function OneByteSeqStringSetCharDeoptOsr() { - function deopt() { - %DeoptimizeFunction(f); - } - - function f(string, osr) { - var world = " world"; - %_OneByteSeqStringSetChar(0, (deopt(), 0x48), string); - - for (var i = 0; osr && i < 2; i++) %OptimizeOsr(); - - return string + world; - } - - assertEquals("Hello " + "world", f("hello", false)); - %OptimizeFunctionOnNextCall(f); - assertEquals("Hello " + "world", f("hello", true)); -})(); - - -(function OneByteSeqStringSetCharDeopt() { - function deopt() { - %DeoptimizeFunction(f); - } - - function g(x) { - } - - function f(string) { - g(%_OneByteSeqStringSetChar(0, (deopt(), 0x48), string)); - return string; - } - - assertEquals("Hell" + "o", f("hello")); - %OptimizeFunctionOnNextCall(f); - assertEquals("Hell" + "o", f("hello")); -})(); - - -(function TwoByteSeqStringSetCharDeopt() { - function deopt() { - %DeoptimizeFunction(f); - } - - function g(x) { - } - - function f(string) { - g(%_TwoByteSeqStringSetChar(0, (deopt(), 0x48), string)); - return string; - } - - assertEquals("Hell" + "o", f("\u20ACello")); - %OptimizeFunctionOnNextCall(f); - assertEquals("Hell" + "o", f("\u20ACello")); -})(); diff --git a/deps/v8/test/mjsunit/stack-traces-overflow.js b/deps/v8/test/mjsunit/stack-traces-overflow.js index e20c6091d7..706f8fcef9 100644 --- a/deps/v8/test/mjsunit/stack-traces-overflow.js +++ b/deps/v8/test/mjsunit/stack-traces-overflow.js @@ -27,10 +27,22 @@ // Flags: --stack-size=100 +function overflow() { + var a, b, c, d, e; // Allocates some locals on the function's stack frame. + overflow(); +} function rec1(a) { rec1(a+1); } function rec2(a) { rec3(a+1); } function rec3(a) { rec2(a+1); } +// Test stack trace has correct function location at top of the stack. +try { + overflow(); +} catch (e) { + var first_frame = e.stack.split("\n")[1] + assertTrue(first_frame.indexOf("stack-traces-overflow.js:30:18") > 0); +} + // Test stack trace getter and setter. try { rec1(0); @@ -63,9 +75,9 @@ try { function testErrorPrototype(prototype) { var object = {}; object.__proto__ = prototype; - object.stack = "123"; // Overwriting stack property fails. - assertEquals(prototype.stack, object.stack); - assertTrue("123" != prototype.stack); + object.stack = "123"; // Overwriting stack property succeeds. + assertTrue(prototype.stack != object.stack); + assertEquals("123", object.stack); } try { diff --git a/deps/v8/test/mjsunit/stack-traces.js b/deps/v8/test/mjsunit/stack-traces.js index 41de146346..8603d7cf28 100644 --- a/deps/v8/test/mjsunit/stack-traces.js +++ b/deps/v8/test/mjsunit/stack-traces.js @@ -252,11 +252,14 @@ function testTraceNativeConversion(nativeFunc) { function testOmittedBuiltin(throwing, omitted) { + var reached = false; try { throwing(); - assertUnreachable(omitted); + reached = true; } catch (e) { assertTrue(e.stack.indexOf(omitted) < 0, omitted); + } finally { + assertFalse(reached); } } @@ -305,19 +308,18 @@ testOmittedBuiltin(function(){ [thrower, 2].sort(function (a,b) { // Omitted because ADD from runtime.js is non-native builtin. testOmittedBuiltin(function(){ thrower + 2; }, "ADD"); +var reached = false; var error = new Error(); -error.toString = function() { assertUnreachable(); }; +error.toString = function() { reached = true; }; error.stack; +assertFalse(reached); +reached = false; error = new Error(); -error.name = { toString: function() { assertUnreachable(); }}; -error.message = { toString: function() { assertUnreachable(); }}; -error.stack; - -error = new Error(); -Array.prototype.push = function(x) { assertUnreachable(); }; -Array.prototype.join = function(x) { assertUnreachable(); }; +Array.prototype.push = function(x) { reached = true; }; +Array.prototype.join = function(x) { reached = true; }; error.stack; +assertFalse(reached); var fired = false; error = new Error({ toString: function() { fired = true; } }); @@ -366,3 +368,75 @@ my_error = new Error(); var stolen_getter = Object.getOwnPropertyDescriptor(my_error, 'stack').get; Object.defineProperty(fake_error, 'stack', { get: stolen_getter }); assertEquals(undefined, fake_error.stack); + +// Check that overwriting the stack property during stack trace formatting +// does not crash. +error = new Error(); +error.__defineGetter__("name", function() { error.stack = "abc"; }); +assertEquals("abc", error.stack); + +error = new Error(); +error.__defineGetter__("name", function() { delete error.stack; }); +assertEquals(undefined, error.stack); + +// Check that repeated trace collection does not crash. +error = new Error(); +Error.captureStackTrace(error); + +// Check property descriptor. +var o = {}; +Error.captureStackTrace(o); +assertEquals([], Object.keys(o)); +var desc = Object.getOwnPropertyDescriptor(o, "stack"); +assertFalse(desc.enumerable); +assertTrue(desc.configurable); +assertTrue(desc.writable); + +// Check that exceptions thrown within prepareStackTrace throws an exception. +Error.prepareStackTrace = function(e, frames) { throw 42; } + +var x = {} +assertThrows(() => Error.captureStackTrace(x)); + +// Check that we don't crash when CaptureSimpleStackTrace returns undefined. +var o = {}; +var oldStackTraceLimit = Error.stackTraceLimit; +Error.stackTraceLimit = "not a number"; +Error.captureStackTrace(o); +Error.stackTraceLimit = oldStackTraceLimit; + +// Check that we don't crash when a callsite's function's script is empty. +Error.prepareStackTrace = function(e, frames) { + assertEquals(undefined, frames[0].getEvalOrigin()); +} +try { + DataView(); + assertUnreachable(); +} catch (e) { + assertEquals(undefined, e.stack); +} + +// Check that a tight recursion in prepareStackTrace throws when accessing +// stack. Trying again without a custom formatting function formats correctly. +var err = new Error("abc"); +Error.prepareStackTrace = () => Error.prepareStackTrace(); +try { + err.stack; + assertUnreachable(); +} catch (e) { + err = e; +} + +Error.prepareStackTrace = undefined; +assertTrue( + err.stack.indexOf("RangeError: Maximum call stack size exceeded") != -1); +assertTrue(err.stack.indexOf("prepareStackTrace") != -1); + +// Check that the callsite constructor throws. + +Error.prepareStackTrace = (e,s) => s; +var constructor = new Error().stack[0].constructor; + +assertThrows(() => constructor.call()); +assertThrows(() => constructor.call( + null, {}, () => undefined, {valueOf() { return 0 }}, false)); diff --git a/deps/v8/test/mjsunit/string-natives.js b/deps/v8/test/mjsunit/string-natives.js deleted file mode 100644 index 40fe9c697e..0000000000 --- a/deps/v8/test/mjsunit/string-natives.js +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2012 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Flags: --expose-gc --allow-natives-syntax - -function test() { - var s1 = %NewString(26, true); - for (i = 0; i < 26; i++) %_OneByteSeqStringSetChar(i, 65, s1); - assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAA", s1); - %_OneByteSeqStringSetChar(25, 66, s1); - assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAB", s1); - for (i = 0; i < 26; i++) %_OneByteSeqStringSetChar(i, i+65, s1); - assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s1); - s1 = %TruncateString(s1, 13); - assertEquals("ABCDEFGHIJKLM", s1); - - var s2 = %NewString(26, false); - for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(i, 65, s2); - assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAA", s2); - %_TwoByteSeqStringSetChar(25, 66, s2); - assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAB", s2); - for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(i, i+65, s2); - assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s2); - s2 = %TruncateString(s2, 13); - assertEquals("ABCDEFGHIJKLM", s2); - - var s3 = %NewString(26, false); - for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(i, i+1000, s3); - for (i = 0; i < 26; i++) assertEquals(s3[i], String.fromCharCode(i+1000)); - - var a = []; - for (var i = 0; i < 1000; i++) { - var s = %NewString(10000, i % 2 == 1); - a.push(s); - } - - gc(); - - for (var i = 0; i < 1000; i++) { - assertEquals(10000, a[i].length); - a[i] = %TruncateString(a[i], 5000); - } - - gc(); - - for (var i = 0; i < 1000; i++) { - assertEquals(5000, a[i].length); - } -} - - -test(); -test(); -%OptimizeFunctionOnNextCall(test); -test(); diff --git a/deps/v8/test/mjsunit/string-wrapper.js b/deps/v8/test/mjsunit/string-wrapper.js new file mode 100644 index 0000000000..d4b65005d3 --- /dev/null +++ b/deps/v8/test/mjsunit/string-wrapper.js @@ -0,0 +1,62 @@ +// Copyright 2016 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 limit = 10000; + +function testStringWrapper(string) { + assertEquals('a', string[0]); + assertEquals('b', string[1]); + assertEquals('c', string[2]); +} + +(function testFastStringWrapperGrow() { + var string = new String("abc"); + for (var i = 0; i < limit; i += 2) { + string[i] = {}; + } + testStringWrapper(string); + + for (var i = limit; i > 0; i -= 2) { + delete string[i]; + } + testStringWrapper(string); +})(); + +(function testSlowStringWrapperGrow() { + var string = new String("abc"); + // Force Slow String Wrapper Elements Kind + string[limit] = limit; + for (var i = 0; i < limit; i += 2) { + string[i] = {}; + } + testStringWrapper(string); + assertEquals(limit, string[limit]); + + for (var i = limit; i > 0; i -= 2) { + delete string[i]; + } + testStringWrapper(string); + assertEquals(undefined, string[limit]); +})(); + + +(function testReconfigureStringWrapperElements() { + var s = new String('abc'); + // Can't reconfigure string contents. + assertThrows(() => Object.defineProperty(s, '1', {value: "value"}), TypeError); + + // Configure a property outside the string range + var value = 'v1'; + Object.defineProperty(s, '3', { + get: () => {return value}, + configurable:true + }); + assertEquals('v1', s[3]); + value = 'v2'; + assertEquals('v2', s[3]); + + Object.defineProperty(s, '3', {value: 'v3', configurable: false}); + assertEquals('v3', s[3]); + assertThrows(() => Object.defineProperty(s, '3', {value:2}), TypeError); +})(); diff --git a/deps/v8/test/mjsunit/substr.js b/deps/v8/test/mjsunit/substr.js index cab8b1bf6d..83929362a0 100644 --- a/deps/v8/test/mjsunit/substr.js +++ b/deps/v8/test/mjsunit/substr.js @@ -152,3 +152,22 @@ for (var i = 63; i >= 0; i--) { assertEquals(xl - offset, z.length); offset -= i; } + + +// Order of conversions. +{ + let log = []; + let string = {[Symbol.toPrimitive]() { log.push("this"); return "abc" }}; + let start = {[Symbol.toPrimitive]() { log.push("start"); return 0 }}; + let length = {[Symbol.toPrimitive]() { log.push("length"); return 1 }}; + assertEquals("a", String.prototype.substr.call(string, start, length)); + assertEquals(["this", "start", "length"], log); +} +{ + let log = []; + let string = {[Symbol.toPrimitive]() { log.push("this"); return "abc" }}; + let start = {[Symbol.toPrimitive]() { log.push("start"); return 0 }}; + let length = {[Symbol.toPrimitive]() { log.push("length"); return 0 }}; + assertEquals("", String.prototype.substr.call(string, start, length)); + assertEquals(["this", "start", "length"], log); +} diff --git a/deps/v8/test/mjsunit/tools/dumpcpp.js b/deps/v8/test/mjsunit/tools/dumpcpp.js new file mode 100644 index 0000000000..49b4675bf1 --- /dev/null +++ b/deps/v8/test/mjsunit/tools/dumpcpp.js @@ -0,0 +1,53 @@ +// Copyright 2016 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. + +// Load implementations from <project root>/tools. +// Files: tools/splaytree.js tools/codemap.js tools/csvparser.js +// Files: tools/consarray.js tools/profile.js tools/profile_view.js +// Files: tools/logreader.js tools/tickprocessor.js +// Files: tools/dumpcpp.js +// Env: TEST_FILE_NAME + +(function testProcessSharedLibrary() { + var oldLoadSymbols = UnixCppEntriesProvider.prototype.loadSymbols; + + UnixCppEntriesProvider.prototype.loadSymbols = function(libName) { + this.symbols = [[ + '00000100 00000001 t v8::internal::Runtime_StringReplaceRegExpWithString(v8::internal::Arguments)', + '00000110 00000001 T v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle<v8::internal::Object>, unsigned int)', + '00000120 00000001 t v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Arguments)', + '00000130 00000001 W v8::internal::RegExpMacroAssembler::CheckPosition(int, v8::internal::Label*)' + ].join('\n'), '']; + }; + + var testCppProcessor = new CppProcessor(new UnixCppEntriesProvider(), + false, false); + testCppProcessor.processSharedLibrary( + '/usr/local/google/home/lpy/v8/out/native/d8', + 0x00000100, 0x00000400, 0); + + var staticEntries = testCppProcessor.codeMap_.getAllStaticEntriesWithAddresses(); + var total = staticEntries.length; + assertEquals(total, 3); + assertEquals(staticEntries[0], + [288,{size:1, + name:'v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Arguments)', + type:'CPP', + nameUpdated_:false} + ]); + assertEquals(staticEntries[1], + [272,{size:1, + name:'v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle<v8::internal::Object>, unsigned int)', + type:'CPP', + nameUpdated_:false} + ]); + assertEquals(staticEntries[2], + [256,{size:1, + name:'v8::internal::Runtime_StringReplaceRegExpWithString(v8::internal::Arguments)', + type:'CPP', + nameUpdated_:false} + ]); + + UnixCppEntriesProvider.prototype.loadSymbols = oldLoadSymbols; +})(); diff --git a/deps/v8/test/mjsunit/tools/tickprocessor-test-func-info.log b/deps/v8/test/mjsunit/tools/tickprocessor-test-func-info.log index 94aa56d36c..fcbf3b1a65 100644 --- a/deps/v8/test/mjsunit/tools/tickprocessor-test-func-info.log +++ b/deps/v8/test/mjsunit/tools/tickprocessor-test-func-info.log @@ -1,6 +1,6 @@ -shared-library,"shell",0x08048000,0x081ee000 -shared-library,"/lib32/libm-2.7.so",0xf7db6000,0xf7dd9000 -shared-library,"ffffe000-fffff000",0xffffe000,0xfffff000 +shared-library,"shell",0x08048000,0x081ee000,0 +shared-library,"/lib32/libm-2.7.so",0xf7db6000,0xf7dd9000,0 +shared-library,"ffffe000-fffff000",0xffffe000,0xfffff000,0 profiler,"begin",1 code-creation,Stub,0,0x424260,348,"CompareStub_GE" code-creation,LazyCompile,0,0x2a8100,18535,"DrawQube 3d-cube.js:188",0xf43abcac, diff --git a/deps/v8/test/mjsunit/tools/tickprocessor-test.log b/deps/v8/test/mjsunit/tools/tickprocessor-test.log index cf8b90d73b..fbc868ebf2 100644 --- a/deps/v8/test/mjsunit/tools/tickprocessor-test.log +++ b/deps/v8/test/mjsunit/tools/tickprocessor-test.log @@ -1,6 +1,6 @@ -shared-library,"shell",0x08048000,0x081ee000 -shared-library,"/lib32/libm-2.7.so",0xf7db6000,0xf7dd9000 -shared-library,"ffffe000-fffff000",0xffffe000,0xfffff000 +shared-library,"shell",0x08048000,0x081ee000,0 +shared-library,"/lib32/libm-2.7.so",0xf7db6000,0xf7dd9000,0 +shared-library,"ffffe000-fffff000",0xffffe000,0xfffff000,0 profiler,"begin",1 code-creation,Stub,0,0xf540a100,474,"CEntryStub" code-creation,Script,0,0xf541cd80,736,"exp.js" diff --git a/deps/v8/test/mjsunit/tools/tickprocessor.js b/deps/v8/test/mjsunit/tools/tickprocessor.js index 73af098e7f..804a85de78 100644 --- a/deps/v8/test/mjsunit/tools/tickprocessor.js +++ b/deps/v8/test/mjsunit/tools/tickprocessor.js @@ -81,7 +81,7 @@ var shell_prov = new UnixCppEntriesProvider(); var shell_syms = []; - shell_prov.parseVmSymbols('shell', 0x08048000, 0x081ee000, + shell_prov.parseVmSymbols('shell', 0x08048000, 0x081ee000, 0, function (name, start, end) { shell_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -107,7 +107,7 @@ }; var libc_prov = new UnixCppEntriesProvider(); var libc_syms = []; - libc_prov.parseVmSymbols('libc', 0xf7c5c000, 0xf7da5000, + libc_prov.parseVmSymbols('libc', 0xf7c5c000, 0xf7da5000, 0, function (name, start, end) { libc_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -145,17 +145,17 @@ var shell_prov = new MacCppEntriesProvider(); var shell_syms = []; - shell_prov.parseVmSymbols('shell', 0x00001b00, 0x00163156, + shell_prov.parseVmSymbols('shell', 0x00001c00, 0x00163256, 0x100, function (name, start, end) { shell_syms.push(Array.prototype.slice.apply(arguments, [0])); }); assertEquals( - [['start', 0x00001b00, 0x00001b40], - ['dyld_stub_binding_helper', 0x00001b40, 0x0011b710], - ['v8::internal::RegExpMacroAssembler::CheckPosition', 0x0011b710, 0x00134250], - ['v8::internal::Runtime_StringReplaceRegExpWithString', 0x00134250, 0x00137220], - ['v8::internal::Runtime::GetElementOrCharAt', 0x00137220, 0x00137400], - ['v8::internal::Runtime_DebugGetPropertyDetails', 0x00137400, 0x00163156]], + [['start', 0x00001c00, 0x00001c40], + ['dyld_stub_binding_helper', 0x00001c40, 0x0011b810], + ['v8::internal::RegExpMacroAssembler::CheckPosition', 0x0011b810, 0x00134350], + ['v8::internal::Runtime_StringReplaceRegExpWithString', 0x00134350, 0x00137320], + ['v8::internal::Runtime::GetElementOrCharAt', 0x00137320, 0x00137500], + ['v8::internal::Runtime_DebugGetPropertyDetails', 0x00137500, 0x00163256]], shell_syms); // stdc++ library @@ -168,7 +168,7 @@ }; var stdc_prov = new MacCppEntriesProvider(); var stdc_syms = []; - stdc_prov.parseVmSymbols('stdc++', 0x95728fb4, 0x95770005, + stdc_prov.parseVmSymbols('stdc++', 0x95728fb4, 0x95770005, 0, function (name, start, end) { stdc_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -211,7 +211,7 @@ }; var shell_prov = new WindowsCppEntriesProvider(); var shell_syms = []; - shell_prov.parseVmSymbols('shell.exe', 0x00400000, 0x0057c000, + shell_prov.parseVmSymbols('shell.exe', 0x00400000, 0x0057c000, 0, function (name, start, end) { shell_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -252,7 +252,7 @@ read = exeSymbols; var exe_exe_syms = []; (new WindowsCppEntriesProvider()).parseVmSymbols( - 'chrome.exe', 0x00400000, 0x00472000, + 'chrome.exe', 0x00400000, 0x00472000, 0, function (name, start, end) { exe_exe_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -264,7 +264,7 @@ read = dllSymbols; var exe_dll_syms = []; (new WindowsCppEntriesProvider()).parseVmSymbols( - 'chrome.exe', 0x00400000, 0x00472000, + 'chrome.exe', 0x00400000, 0x00472000, 0, function (name, start, end) { exe_dll_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -275,7 +275,7 @@ read = dllSymbols; var dll_dll_syms = []; (new WindowsCppEntriesProvider()).parseVmSymbols( - 'chrome.dll', 0x01c30000, 0x02b80000, + 'chrome.dll', 0x01c30000, 0x02b80000, 0, function (name, start, end) { dll_dll_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -287,7 +287,7 @@ read = exeSymbols; var dll_exe_syms = []; (new WindowsCppEntriesProvider()).parseVmSymbols( - 'chrome.dll', 0x01c30000, 0x02b80000, + 'chrome.dll', 0x01c30000, 0x02b80000, 0, function (name, start, end) { dll_exe_syms.push(Array.prototype.slice.apply(arguments, [0])); }); @@ -304,7 +304,7 @@ function CppEntriesProviderMock() { CppEntriesProviderMock.prototype.parseVmSymbols = function( - name, startAddr, endAddr, symbolAdder) { + name, startAddr, endAddr, slideAddr, symbolAdder) { var symbols = { 'shell': [['v8::internal::JSObject::LookupOwnRealNamedProperty(v8::internal::String*, v8::internal::LookupResult*)', 0x080f8800, 0x080f8d90], diff --git a/deps/v8/test/mjsunit/unicode-test.js b/deps/v8/test/mjsunit/unicode-test.js index 5be1b41562..1d64420c30 100644 --- a/deps/v8/test/mjsunit/unicode-test.js +++ b/deps/v8/test/mjsunit/unicode-test.js @@ -5726,7 +5726,7 @@ var source = " All uses of av_ are via get_malloc_state().\n" + " At most one \"call\" to get_malloc_state is made per invocation of\n" + " the public versions of malloc and free, but other routines\n" + -" that in turn invoke malloc and/or free may call more then once.\n" + +" that in turn invoke malloc and/or free may call more than once.\n" + " Also, it is called in check* routines if DEBUG is set.\n" + "*/\n" + "\n" + diff --git a/deps/v8/test/mjsunit/wasm/OWNERS b/deps/v8/test/mjsunit/wasm/OWNERS index c2abc8a6ad..eda8deabfd 100644 --- a/deps/v8/test/mjsunit/wasm/OWNERS +++ b/deps/v8/test/mjsunit/wasm/OWNERS @@ -1,3 +1,5 @@ -titzer@chromium.org -bradnelson@chromium.org ahaas@chromium.org +bradnelson@chromium.org +mtrofin@chromium.org +rossberg@chromium.org +titzer@chromium.org diff --git a/deps/v8/test/mjsunit/wasm/adapter-frame.js b/deps/v8/test/mjsunit/wasm/adapter-frame.js index 0e5d4b8c74..e595c3fb89 100644 --- a/deps/v8/test/mjsunit/wasm/adapter-frame.js +++ b/deps/v8/test/mjsunit/wasm/adapter-frame.js @@ -26,10 +26,9 @@ function makeSelect(type, args, which) { } var builder = new WasmModuleBuilder(); - var sig = new Array(); - sig.push(type); - for (var i = 0; i < args; i++) sig.push(type); - builder.addFunction("select", sig) + var params = []; + for (var i = 0; i < args; i++) params.push(type); + builder.addFunction("select", makeSig(params, [type])) .addBody([kExprGetLocal, which]) .exportFunc(); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-copy.js b/deps/v8/test/mjsunit/wasm/asm-wasm-copy.js index 35c5f76ef1..149196e1b9 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-copy.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-copy.js @@ -22,6 +22,7 @@ } return { func: func }; } - var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); - assertEquals(asmModule().func(), wasm.func()); + var wasm = asmModule(); + var js = eval('(' + asmModule.toString().replace('use asm', '') + ')')(); + assertEquals(js.func(), wasm.func()); })(); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-deopt.js b/deps/v8/test/mjsunit/wasm/asm-wasm-deopt.js index 4b16b71239..460894ea5e 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-deopt.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-deopt.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: --expose-wasm -// Flags: --allow-natives-syntax +// Flags: --validate-asm --allow-natives-syntax (function TestDeoptimizeArgMismatch() { function deopt() { @@ -21,8 +20,7 @@ return {'_main': _main} } function test() { - var wasm = Wasm.instantiateModuleFromAsm( - Module.toString(), {'deopt': deopt}); + var wasm = Module(null, {'deopt': deopt}); wasm._main(0, 0, 0); } test(); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-f32.js b/deps/v8/test/mjsunit/wasm/asm-wasm-f32.js index a94994d26f..a5d5a6c2cc 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-f32.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-f32.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax function WrapInAsmModule(func) { function MODULE_NAME(stdlib) { @@ -26,22 +26,19 @@ function WrapInAsmModule(func) { return eval("(" + source + ")"); } -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); var stdlib = {Math: Math}; - var js_module = eval("(" + nonasm_source + ")")(stdlib); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); - expect(wasm_module); } const fround = Math.fround; @@ -218,7 +215,7 @@ var funcs = [ (function () { for (func of funcs) { - RunThreeWayTest(WrapInAsmModule(func), function (module) { + RunAsmJsTest(WrapInAsmModule(func), function (module) { if (func.length == 1) { for (a of inputs) { assertEquals(func(a), module.main(a)); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-f64.js b/deps/v8/test/mjsunit/wasm/asm-wasm-f64.js index 11f9da38f9..1fd51ff9d5 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-f64.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-f64.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax function WrapInAsmModule(func) { function MODULE_NAME(stdlib) { @@ -34,22 +34,19 @@ function WrapInAsmModule(func) { return eval("(" + source + ")"); } -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); var stdlib = {Math: Math}; - var js_module = eval("(" + nonasm_source + ")")(stdlib); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); - expect(wasm_module); } const Math_ceil = Math.ceil; @@ -290,7 +287,7 @@ var funcs = [ (function () { for (func of funcs) { - RunThreeWayTest(WrapInAsmModule(func), function (module) { + RunAsmJsTest(WrapInAsmModule(func), function (module) { if (func.length == 1) { for (a of inputs) { assertEquals(func(a), module.main(a)); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-heap.js b/deps/v8/test/mjsunit/wasm/asm-wasm-heap.js index 055b1e94a5..d81cb6134e 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-heap.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-heap.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax const stdlib = { Math: Math, @@ -54,21 +54,18 @@ function checkView(view, load, shift) { } } -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); - var js_module = eval("(" + nonasm_source + ")")(stdlib, {}, buffer); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib, {}, buffer); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib, {}, buffer); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, null, buffer); - expect(wasm_module); } function LoadAt_i32(stdlib, foreign, buffer) { @@ -81,7 +78,7 @@ function LoadAt_i32(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_i32, function(module) { +RunAsmJsTest(LoadAt_i32, function(module) { var load = module.load; assertEquals(BASE, load(0)); assertEquals(BASE | 0x30, load(0x30)); @@ -110,7 +107,7 @@ function LoadAt_i16(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_i16, function(module) { +RunAsmJsTest(LoadAt_i16, function(module) { var load = module.load; var LOWER = (BASE << 16) >> 16; var UPPER = BASE >> 16; @@ -146,7 +143,7 @@ function LoadAt_u16(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_u16, function(module) { +RunAsmJsTest(LoadAt_u16, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(0, load(index)); checkView(new Uint16Array(buffer), load, 1); @@ -162,7 +159,7 @@ function LoadAt_i8(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_i8, function(module) { +RunAsmJsTest(LoadAt_i8, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(0, load(index)); checkView(new Int8Array(buffer), load, 0); @@ -178,7 +175,7 @@ function LoadAt_u8(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_u8, function(module) { +RunAsmJsTest(LoadAt_u8, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(0, load(index)); checkView(new Uint8Array(buffer), load, 0); @@ -195,7 +192,7 @@ function LoadAt_u32(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_u32, function(module) { +RunAsmJsTest(LoadAt_u32, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(0, load(index)); checkView(new Uint32Array(buffer), load, 2); @@ -212,7 +209,7 @@ function LoadAt_f32(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_f32, function(module) { +RunAsmJsTest(LoadAt_f32, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(NaN, load(index)); checkView(new Float32Array(buffer), load, 2); @@ -228,7 +225,7 @@ function LoadAt_f64(stdlib, foreign, buffer) { return {load: load}; } -RunThreeWayTest(LoadAt_f64, function(module) { +RunAsmJsTest(LoadAt_f64, function(module) { var load = module.load; for (index of OOB_INDEXES) assertEquals(NaN, load(index)); checkView(new Float64Array(buffer), load, 3); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-i32.js b/deps/v8/test/mjsunit/wasm/asm-wasm-i32.js index 6224e8fa1f..29f071c84c 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-i32.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-i32.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax function WrapInAsmModule(func) { function MODULE_NAME(stdlib) { @@ -23,22 +23,19 @@ function WrapInAsmModule(func) { return eval("(" + source + ")"); } -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); var stdlib = {Math: Math}; - var js_module = eval("(" + nonasm_source + ")")(stdlib); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); - expect(wasm_module); } const imul = Math.imul; @@ -67,13 +64,13 @@ function i32_mul(a, b) { function i32_div(a, b) { a = a | 0; b = b | 0; - return (a / b) | 0; + return ((a | 0) / (b | 0)) | 0; } function i32_mod(a, b) { a = a | 0; b = b | 0; - return (a % b) | 0; + return ((a | 0) % (b | 0)) | 0; } function i32_and(a, b) { @@ -234,7 +231,7 @@ var funcs = [ (function () { for (func of funcs) { - RunThreeWayTest(WrapInAsmModule(func), function (module) { + RunAsmJsTest(WrapInAsmModule(func), function (module) { if (func.length == 1) { for (a of inputs) { assertEquals(func(a), module.main(a)); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-literals.js b/deps/v8/test/mjsunit/wasm/asm-wasm-literals.js index e4e312f1d4..172c5a3776 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-literals.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-literals.js @@ -2,24 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); var stdlib = {Math: Math}; - var js_module = eval("(" + nonasm_source + ")")(stdlib); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); - expect(wasm_module); } function PositiveIntLiterals() { @@ -38,9 +35,10 @@ function PositiveIntLiterals() { f256: f256, f1000: f1000, f2000000, fmax: fmax}; } -RunThreeWayTest(PositiveIntLiterals, function(module) { +RunAsmJsTest(PositiveIntLiterals, function(module) { assertEquals(0, module.f0()); assertEquals(1, module.f1()); + assertEquals(1, module.f1()); assertEquals(4, module.f4()); assertEquals(64, module.f64()); assertEquals(128, module.f128()); @@ -65,7 +63,7 @@ function NegativeIntLiterals() { f256: f256, f1000: f1000, f2000000, fmin: fmin}; } -RunThreeWayTest(NegativeIntLiterals, function (module) { +RunAsmJsTest(NegativeIntLiterals, function (module) { assertEquals(-1, module.f1()); assertEquals(-4, module.f4()); assertEquals(-64, module.f64()); @@ -93,7 +91,7 @@ function PositiveUnsignedLiterals() { f256: f256, f1000: f1000, f2000000, fmax: fmax}; } -RunThreeWayTest(PositiveUnsignedLiterals, function (module) { +RunAsmJsTest(PositiveUnsignedLiterals, function (module) { assertEquals(0, module.f0()); assertEquals(1, module.f1()); assertEquals(4, module.f4()); @@ -130,7 +128,7 @@ function LargeUnsignedLiterals() { return {a: a, b: b, c: c, d: d, e: e}; } -RunThreeWayTest(LargeUnsignedLiterals, function(module) { +RunAsmJsTest(LargeUnsignedLiterals, function(module) { assertEquals(2147483648, module.a()); assertEquals(2147483649, module.b()); assertEquals(0x80000000, module.c()); @@ -165,7 +163,7 @@ function ManyI32() { return {main: main}; } -RunThreeWayTest(ManyI32, function(module) { +RunAsmJsTest(ManyI32, function(module) { assertEquals(-222411306, module.main()); }); @@ -187,7 +185,7 @@ function ManyF64a() { return {main: main}; } -RunThreeWayTest(ManyF64a, function(module) { +RunAsmJsTest(ManyF64a, function(module) { assertEquals(-8640233.599945681, module.main()); }); @@ -203,7 +201,7 @@ function ManyF64b() { return {k1: k1, k2: k2, k3: k3, k4: k4, k5: k5, k6: k6}; } -RunThreeWayTest(ManyF64b, function(module) { +RunAsmJsTest(ManyF64b, function(module) { assertEquals(2.4e-24, module.k1()); assertEquals(2.4e-19, module.k2()); assertEquals(2.4e-14, module.k3()); @@ -225,7 +223,7 @@ function ManyF64c() { return {k1: k1, k2: k2, k3: k3, k4: k4, k5: k5, k6: k6}; } -RunThreeWayTest(ManyF64c, function(module) { +RunAsmJsTest(ManyF64c, function(module) { assertEquals(2.4000000000000004e+26, module.k1()); assertEquals(2.4e+21, module.k2()); assertEquals(2.4e+16, module.k3()); @@ -250,7 +248,7 @@ function ManyF32a(stdlib) { if (false) { // TODO(bradnelson): fails validation of F32 literals somehow. -RunThreeWayTest(ManyF32a, function(module) { +RunAsmJsTest(ManyF32a, function(module) { assertEquals(2.0999999917333043e-24, module.k1()); assertEquals(2.099999868734112e-19, module.k2()); assertEquals(2.099999997029825e-14, module.k3()); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-stdlib.js b/deps/v8/test/mjsunit/wasm/asm-wasm-stdlib.js index fe39a30a88..05e1ca509c 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-stdlib.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-stdlib.js @@ -2,7 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax + +var stdlib = this; + +function assertValidAsm(func) { + assertTrue(%IsAsmWasmCode(func)); +} (function TestStdlibConstants() { function Module(stdlib) { @@ -39,17 +45,109 @@ return {caller:caller, nanCheck:nanCheck}; } - var m =Wasm.instantiateModuleFromAsm(Module.toString()); + var m = Module(stdlib); + assertValidAsm(Module); assertEquals(1, m.caller()); assertTrue(isNaN(m.nanCheck())); })(); +var stdlib = this; +var stdlib_root_members = [ + 'Infinity', + 'NaN', +]; +var stdlib_math_members = [ + 'E', + 'LN10', + 'LN2', + 'LOG2E', + 'LOG10E', + 'PI', + 'SQRT1_2', + 'SQRT2', + 'ceil', + 'clz32', + 'floor', + 'sqrt', + 'abs', + 'min', + 'max', + 'acos', + 'asin', + 'atan', + 'cos', + 'sin', + 'tan', + 'exp', + 'log', + 'atan2', + 'pow', + 'imul', + 'fround', +]; + + +(function TestBadStdlib() { + function Module(stdlib) { + "use asm"; + var foo = stdlib.NaN; + return {}; + } + for (var i = 0; i < stdlib_root_members.length; ++i) { + var member = stdlib_root_members[i]; + var stdlib = {}; + stdlib[member] = 0; + print(member); + var code = Module.toString().replace('NaN', member); + var decl = eval('(' + code + ')'); + decl(stdlib); + assertTrue(%IsNotAsmWasmCode(decl)); + } + for (var i = 0; i < stdlib_math_members.length; ++i) { + var member = stdlib_math_members[i]; + var stdlib = {Math:{}}; + stdlib['Math'][member] = 0; + print(member); + var code = Module.toString().replace('NaN', 'Math.' + member); + var decl = eval('(' + code + ')'); + decl(stdlib); + assertTrue(%IsNotAsmWasmCode(decl)); + } +})(); + + +(function TestMissingNaNStdlib() { + function Module(stdlib) { + "use asm"; + var foo = stdlib.NaN; + return {}; + } + for (var i = 0; i < stdlib_root_members.length; ++i) { + var member = stdlib_root_members[i]; + var code = Module.toString().replace('NaN', member); + var decl = eval('(' + code + ')'); + decl({}); + assertTrue(%IsNotAsmWasmCode(decl)); + } + for (var i = 0; i < stdlib_math_members.length; ++i) { + var member = stdlib_math_members[i]; + var code = Module.toString().replace('NaN', 'Math.' + member); + var decl = eval('(' + code + ')'); + assertThrows(function() { + decl({}); + assertTrue(%IsNotAsmWasmCode(decl)); + }); + } +})(); + + (function TestStdlibFunctionsInside() { function Module(stdlib) { "use asm"; var StdlibMathCeil = stdlib.Math.ceil; + var StdlibMathClz32 = stdlib.Math.clz32; var StdlibMathFloor = stdlib.Math.floor; var StdlibMathSqrt = stdlib.Math.sqrt; var StdlibMathAbs = stdlib.Math.abs; @@ -83,33 +181,35 @@ } function caller() { - if (!deltaEqual(StdlibMathSqrt(123.0), 11.090536506409418)) return 0; - if (StdlibMathSqrt(fround(256.0)) != fround(16.0)) return 0; - if (StdlibMathCeil(123.7) != 124.0) return 0; - if (StdlibMathCeil(fround(123.7)) != fround(124.0)) return 0; - if (StdlibMathFloor(123.7) != 123.0) return 0; - if (StdlibMathFloor(fround(123.7)) != fround(123.0)) return 0; - if (StdlibMathAbs(-123.0) != 123.0) return 0; - if (StdlibMathAbs(fround(-123.0)) != fround(123.0)) return 0; - if (StdlibMathMin(123.4, 1236.4) != 123.4) return 0; - if (StdlibMathMin(fround(123.4), - fround(1236.4)) != fround(123.4)) return 0; - if (StdlibMathMax(123.4, 1236.4) != 1236.4) return 0; - if (StdlibMathMax(fround(123.4), fround(1236.4)) + if (!(deltaEqual(+StdlibMathSqrt(123.0), 11.090536506409418)|0)) return 0; + if (fround(StdlibMathSqrt(fround(256.0))) != fround(16.0)) return 0; + if (+StdlibMathCeil(123.7) != 124.0) return 0; + if (fround(StdlibMathCeil(fround(123.7))) != fround(124.0)) return 0; + if (+StdlibMathFloor(123.7) != 123.0) return 0; + if (fround(StdlibMathFloor(fround(123.7))) != fround(123.0)) return 0; + if (+StdlibMathAbs(-123.0) != 123.0) return 0; + if (fround(StdlibMathAbs(fround(-123.0))) != fround(123.0)) return 0; + if (+StdlibMathMin(123.4, 1236.4) != 123.4) return 0; + if (fround(StdlibMathMin(fround(123.4), + fround(1236.4))) != fround(123.4)) return 0; + if (+StdlibMathMax(123.4, 1236.4) != 1236.4) return 0; + if (fround(StdlibMathMax(fround(123.4), fround(1236.4))) != fround(1236.4)) return 0; - if (!deltaEqual(StdlibMathAcos(0.1), 1.4706289056333368)) return 0; - if (!deltaEqual(StdlibMathAsin(0.2), 0.2013579207903308)) return 0; - if (!deltaEqual(StdlibMathAtan(0.2), 0.19739555984988078)) return 0; - if (!deltaEqual(StdlibMathCos(0.2), 0.9800665778412416)) return 0; - if (!deltaEqual(StdlibMathSin(0.2), 0.19866933079506122)) return 0; - if (!deltaEqual(StdlibMathTan(0.2), 0.20271003550867250)) return 0; - if (!deltaEqual(StdlibMathExp(0.2), 1.2214027581601699)) return 0; - if (!deltaEqual(StdlibMathLog(0.2), -1.6094379124341003)) return 0; - - if (StdlibMathImul(6, 7) != 42) return 0; - if (!deltaEqual(StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)) return 0; - if (StdlibMathPow(6.0, 7.0) != 279936.0) return 0; + if (!(deltaEqual(+StdlibMathAcos(0.1), 1.4706289056333368)|0)) return 0; + if (!(deltaEqual(+StdlibMathAsin(0.2), 0.2013579207903308)|0)) return 0; + if (!(deltaEqual(+StdlibMathAtan(0.2), 0.19739555984988078)|0)) return 0; + if (!(deltaEqual(+StdlibMathCos(0.2), 0.9800665778412416)|0)) return 0; + if (!(deltaEqual(+StdlibMathSin(0.2), 0.19866933079506122)|0)) return 0; + if (!(deltaEqual(+StdlibMathTan(0.2), 0.20271003550867250)|0)) return 0; + if (!(deltaEqual(+StdlibMathExp(0.2), 1.2214027581601699)|0)) return 0; + if (!(deltaEqual(+StdlibMathLog(0.2), -1.6094379124341003)|0)) return 0; + if ((StdlibMathClz32(134217728)|0) != 4) return 0; + + if ((StdlibMathImul(6, 7)|0) != 42) return 0; + if (!(deltaEqual(+StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)|0)) + return 0; + if (+StdlibMathPow(6.0, 7.0) != 279936.0) return 0; return 1; } @@ -117,7 +217,8 @@ return {caller:caller}; } - var m = Wasm.instantiateModuleFromAsm(Module.toString()); + var m = Module(stdlib); + assertValidAsm(Module); assertEquals(1, m.caller()); })(); @@ -261,7 +362,8 @@ max_f64: max_f64, }; } - var m = Wasm.instantiateModuleFromAsm(Module.toString()); + var m = Module(stdlib); + assertValidAsm(Module); var values = { i32: [ 0, 1, -1, 123, 456, -123, -456, diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-switch.js b/deps/v8/test/mjsunit/wasm/asm-wasm-switch.js new file mode 100644 index 0000000000..f4875d0dc1 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-switch.js @@ -0,0 +1,486 @@ +// Copyright 2016 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: --validate-asm --allow-natives-syntax + +function assertValidAsm(func) { + assertTrue(%IsAsmWasmCode(func)); +} + +(function TestSwitch0() { + function asmModule() { + "use asm" + + function caller() { + var ret = 0; + var x = 7; + switch (x|0) { + case 1: { + return 0; + } + case 7: { + ret = 5; + break; + } + default: return 0; + } + return ret|0; + } + + return {caller:caller}; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(5, wasm.caller()); +})(); + +(function TestSwitch() { + function asmModule() { + "use asm" + + function caller() { + var ret = 0; + var x = 7; + switch (x|0) { + case 1: return 0; + case 7: { + ret = 12; + break; + } + default: return 0; + } + switch (x|0) { + case 1: return 0; + case 8: return 0; + default: ret = (ret + 11)|0; + } + return ret|0; + } + + return {caller:caller}; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(23, wasm.caller()); +})(); + +(function TestSwitchFallthrough() { + function asmModule() { + "use asm" + + function caller() { + var x = 17; + var ret = 0; + switch (x|0) { + case 17: + case 14: ret = 39; + case 1: ret = (ret + 3)|0; + case 4: break; + default: ret = (ret + 1)|0; + } + return ret|0; + } + + return {caller:caller}; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(42, wasm.caller()); +})(); + +(function TestNestedSwitch() { + function asmModule() { + "use asm" + + function caller() { + var x = 3; + var y = -13; + switch (x|0) { + case 1: return 0; + case 3: { + switch (y|0) { + case 2: return 0; + case -13: return 43; + default: return 0; + } + } + default: return 0; + } + return 0; + } + + return {caller:caller}; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(43, wasm.caller()); +})(); + +(function TestSwitchWithDefaultOnly() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + switch(x|0) { + default: return -10; + } + return 0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(-10, wasm.main(2)); + assertEquals(-10, wasm.main(54)); +})(); + +(function TestEmptySwitch() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + switch(x|0) { + } + return 73; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(73, wasm.main(7)); +})(); + +(function TestSwitchWithBrTable() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + switch(x|0) { + case 14: return 23; + case 12: return 25; + case 15: return 29; + case 19: return 34; + case 18: return 17; + case 16: return 16; + default: return -1; + } + return 0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(25, wasm.main(12)); + assertEquals(23, wasm.main(14)); + assertEquals(29, wasm.main(15)); + assertEquals(16, wasm.main(16)); + assertEquals(17, wasm.main(18)); + assertEquals(34, wasm.main(19)); + assertEquals(-1, wasm.main(-1)); +})(); + +(function TestSwitchWithBalancedTree() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + switch(x|0) { + case 5: return 52; + case 1: return 11; + case 6: return 63; + case 9: return 19; + case -4: return -4; + } + return 0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(-4, wasm.main(-4)); + assertEquals(11, wasm.main(1)); + assertEquals(52, wasm.main(5)); + assertEquals(63, wasm.main(6)); + assertEquals(19, wasm.main(9)); + assertEquals(0, wasm.main(11)); +})(); + +(function TestSwitchHybrid() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + switch(x|0) { + case 1: return -4; + case 2: return 23; + case 3: return 32; + case 4: return 14; + case 7: return 17; + case 10: return 10; + case 11: return 121; + case 12: return 112; + case 13: return 31; + case 16: return 16; + default: return -1; + } + return 0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(-4, wasm.main(1)); + assertEquals(23, wasm.main(2)); + assertEquals(32, wasm.main(3)); + assertEquals(14, wasm.main(4)); + assertEquals(17, wasm.main(7)); + assertEquals(10, wasm.main(10)); + assertEquals(121, wasm.main(11)); + assertEquals(112, wasm.main(12)); + assertEquals(31, wasm.main(13)); + assertEquals(16, wasm.main(16)); + assertEquals(-1, wasm.main(20)); +})(); + +(function TestSwitchFallthroughWithBrTable() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + var ret = 0; + switch(x|0) { + case 1: { + ret = 21; + break; + } + case 2: { + ret = 12; + break; + } + case 3: { + ret = 43; + } + case 4: { + ret = 54; + break; + } + default: { + ret = 10; + break; + } + } + return ret|0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(12, wasm.main(2)); + assertEquals(10, wasm.main(10)); + assertEquals(54, wasm.main(3)); +})(); + +(function TestSwitchFallthroughHybrid() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + var ret = 0; + switch(x|0) { + case 1: { + ret = 1; + break; + } + case 2: { + ret = 2; + break; + } + case 3: { + ret = 3; + break; + } + case 4: { + ret = 4; + } + case 7: { + ret = 7; + break; + } + case 10: { + ret = 10; + } + case 16: { + ret = 16; + break; + } + case 17: { + ret = 17; + break; + } + case 18: { + ret = 18; + break; + } + case 19: { + ret = 19; + } + default: { + ret = -1; + break; + } + } + return ret|0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(7, wasm.main(4)); + assertEquals(16, wasm.main(10)); + assertEquals(-1, wasm.main(19)); + assertEquals(-1, wasm.main(23)); +})(); + +(function TestSwitchHybridWithNoDefault() { + function asmModule() { + "use asm"; + function main(x) { + x = x|0; + var ret = 19; + switch(x|0) { + case 1: { + ret = 1; + break; + } + case 2: { + ret = 2; + break; + } + case 3: { + ret = 3; + break; + } + case 4: { + ret = 4; + break; + } + case 7: { + ret = 7; + break; + } + } + return ret|0; + } + return { + main: main, + }; + } + var wasm = asmModule(); + assertValidAsm(asmModule); + assertEquals(2, wasm.main(2)); + assertEquals(7, wasm.main(7)); + assertEquals(19, wasm.main(-1)); +})(); + +(function TestLargeSwitch() { + function LargeSwitchGenerator(begin, end, gap, handle_case) { + var str = "function asmModule() {\ + \"use asm\";\ + function main(x) {\ + x = x|0;\ + switch(x|0) {"; + for (var i = begin; i <= end; i = i + gap) { + str = str.concat("case ", i.toString(), ": ", handle_case(i)); + } + str = str.concat("default: return -1;\ + }\ + return -2;\ + }\ + return {main: main}; }"); + + var decl = eval('(' + str + ')'); + var wasm = decl(); + assertValidAsm(decl); + return wasm; + } + + var handle_case = function(k) { + return "return ".concat(k, ";"); + } + var wasm = LargeSwitchGenerator(0, 513, 1, handle_case); + for (var i = 0; i <= 513; i++) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + + wasm = LargeSwitchGenerator(0, 1024, 3, handle_case); + for (var i = 0; i <= 1024; i = i + 3) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + + wasm = LargeSwitchGenerator(-2147483648, -2147483000, 1, handle_case); + for (var i = -2147483648; i <= -2147483000; i++) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + assertEquals(-1, wasm.main(214748647)); + + wasm = LargeSwitchGenerator(-2147483648, -2147483000, 3, handle_case); + for (var i = -2147483648; i <= -2147483000; i = i + 3) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + assertEquals(-1, wasm.main(214748647)); + + wasm = LargeSwitchGenerator(2147483000, 2147483647, 1, handle_case); + for (var i = 2147483000; i <= 2147483647; i++) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + assertEquals(-1, wasm.main(-214748647)); + + wasm = LargeSwitchGenerator(2147483000, 2147483647, 4, handle_case); + for (var i = 2147483000; i <= 2147483647; i = i + 4) { + assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + assertEquals(-1, wasm.main(-214748647)); + + handle_case = function(k) { + if (k != 7) return "return ".concat(k, ";"); + else return "break;"; + } + wasm = LargeSwitchGenerator(0, 1499, 7, handle_case); + for (var i = 0; i <= 1499; i = i + 7) { + if (i == 7) assertEquals(-2, wasm.main(i)); + else assertEquals(i, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); + + handle_case = function(k) { + if (k != 56) return "break;"; + else return "return 23;"; + } + wasm = LargeSwitchGenerator(0, 638, 2, handle_case); + for (var i = 0; i <= 638; i = i + 2) { + if (i == 56) assertEquals(23, wasm.main(i)); + else assertEquals(-2, wasm.main(i)); + } + assertEquals(-1, wasm.main(-1)); +})(); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm-u32.js b/deps/v8/test/mjsunit/wasm/asm-wasm-u32.js index 514ddefb7e..8276015214 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm-u32.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm-u32.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: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax function WrapInAsmModule(func) { function MODULE_NAME(stdlib) { @@ -20,22 +20,19 @@ function WrapInAsmModule(func) { return eval("(" + source + ")"); } -function RunThreeWayTest(asmfunc, expect) { +function RunAsmJsTest(asmfunc, expect) { var asm_source = asmfunc.toString(); var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); var stdlib = {Math: Math}; - var js_module = eval("(" + nonasm_source + ")")(stdlib); print("Testing " + asmfunc.name + " (js)..."); + var js_module = eval("(" + nonasm_source + ")")(stdlib); expect(js_module); print("Testing " + asmfunc.name + " (asm.js)..."); var asm_module = asmfunc(stdlib); + assertTrue(%IsAsmWasmCode(asmfunc)); expect(asm_module); - - print("Testing " + asmfunc.name + " (wasm)..."); - var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); - expect(wasm_module); } const imul = Math.imul; @@ -212,7 +209,7 @@ var funcs = [ (function () { for (func of funcs) { - RunThreeWayTest(WrapInAsmModule(func), function (module) { + RunAsmJsTest(WrapInAsmModule(func), function (module) { for (a of inputs) { for (b of inputs) { var expected = func(a, b); diff --git a/deps/v8/test/mjsunit/wasm/asm-wasm.js b/deps/v8/test/mjsunit/wasm/asm-wasm.js index 2efb006436..a580c5c7e9 100644 --- a/deps/v8/test/mjsunit/wasm/asm-wasm.js +++ b/deps/v8/test/mjsunit/wasm/asm-wasm.js @@ -2,15 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax + +var stdlib = this; + +function assertValidAsm(func) { + assertTrue(%IsAsmWasmCode(func)); +} function assertWasm(expected, func, ffi) { print("Testing " + func.name + "..."); - assertEquals(expected, Wasm.instantiateModuleFromAsm( - func.toString(), ffi).caller()); + assertEquals( + expected, func(stdlib, ffi, new ArrayBuffer(1024)).caller()); + assertValidAsm(func); } -function EmptyTest() { +function EmptyTest(a, b, c) { "use asm"; function caller() { empty(); @@ -23,15 +30,31 @@ function EmptyTest() { assertWasm(11, EmptyTest); +function VoidReturnTest(a, b, c) { + "use asm"; + function caller() { + empty(); + return 19; + } + function empty() { + var x = 0; + if (x) return; + } + return {caller: caller}; +} + +assertWasm(19, VoidReturnTest); -function IntTest() { +function IntTest(a, b, c) { "use asm"; function sum(a, b) { a = a|0; b = b|0; - var c = (b + 1)|0 + var c = 0; var d = 3.0; - var e = ~~d; // double conversion + var e = 0; + e = ~~d; // double conversion + c = (b + 1)|0 return (a + c + 1)|0; } @@ -54,8 +77,9 @@ function Float64Test() { } function caller() { - var a = +sum(70.1,10.2); + var a = 0.0; var ret = 0|0; + a = +sum(70.1,10.2); if (a == 80.3) { ret = 1|0; } else { @@ -75,7 +99,8 @@ function BadModule() { function caller(a, b) { a = a|0; b = b+0; - var c = (b + 1)|0 + var c = 0; + c = (b + 1)|0 return (a + c + 1)|0; } @@ -86,9 +111,7 @@ function BadModule() { return {caller: caller}; } -assertThrows(function() { - Wasm.instantiateModuleFromAsm(BadModule.toString()).caller(); -}); +assertTrue(%IsNotAsmWasmCode(BadModule)); function TestReturnInBlock() { @@ -131,7 +154,7 @@ function TestWhileSimple() { function caller() { var x = 0; - while(x < 5) { + while((x|0) < 5) { x = (x + 1)|0; } return x|0; @@ -148,7 +171,7 @@ function TestWhileWithoutBraces() { function caller() { var x = 0; - while(x <= 3) + while((x|0) <= 3) x = (x + 1)|0; return x|0; } @@ -164,7 +187,7 @@ function TestReturnInWhile() { function caller() { var x = 0; - while(x < 10) { + while((x|0) < 10) { x = (x + 6)|0; return x|0; } @@ -182,7 +205,7 @@ function TestReturnInWhileWithoutBraces() { function caller() { var x = 0; - while(x < 5) + while((x|0) < 5) return 7; return x|0; } @@ -193,6 +216,55 @@ function TestReturnInWhileWithoutBraces() { assertWasm(7, TestReturnInWhileWithoutBraces); +function TestBreakInIf() { + "use asm"; + + function caller() { + label: { + if(1) break label; + return 11; + } + return 12; + } + + return {caller: caller}; +} + +assertWasm(12, TestBreakInIf); + +function TestBreakInIfInDoWhileFalse() { + "use asm"; + + function caller() { + do { + if(1) break; + return 11; + } while(0); + return 12; + } + + return {caller: caller}; +} + +assertWasm(12, TestBreakInIfInDoWhileFalse); + +function TestBreakInElse() { + "use asm"; + + function caller() { + do { + if(0) ; + else break; + return 14; + } while(0); + return 15; + } + + return {caller: caller}; +} + +assertWasm(15, TestBreakInElse); + function TestBreakInWhile() { "use asm"; @@ -209,17 +281,33 @@ function TestBreakInWhile() { assertWasm(8, TestBreakInWhile); +function TestBreakInIfInWhile() { + "use asm"; + + function caller() { + while(1) { + if (1) break; + else break; + } + return 8; + } + + return {caller: caller}; +} + +assertWasm(8, TestBreakInIfInWhile); + function TestBreakInNestedWhile() { "use asm"; function caller() { var x = 1.0; + var ret = 0; while(x < 1.5) { while(1) break; x = +(x + 0.25); } - var ret = 0; if (x == 1.5) { ret = 9; } @@ -239,7 +327,7 @@ function TestBreakInBlock() { var x = 0; abc: { x = 10; - if (x == 10) { + if ((x|0) == 10) { break abc; } x = 20; @@ -260,7 +348,7 @@ function TestBreakInNamedWhile() { var x = 0; outer: while (1) { x = (x + 1)|0; - while (x == 11) { + while ((x|0) == 11) { break outer; } } @@ -279,9 +367,9 @@ function TestContinue() { function caller() { var x = 5; var ret = 0; - while (x >= 0) { + while ((x|0) >= 0) { x = (x - 1)|0; - if (x == 2) { + if ((x|0) == 2) { continue; } ret = (ret - 1)|0; @@ -302,11 +390,11 @@ function TestContinueInNamedWhile() { var x = 5; var y = 0; var ret = 0; - outer: while (x > 0) { + outer: while ((x|0) > 0) { x = (x - 1)|0; y = 0; - while (y < 5) { - if (x == 3) { + while ((y|0) < 5) { + if ((x|0) == 3) { continue outer; } ret = (ret + 1)|0; @@ -326,7 +414,8 @@ function TestNot() { "use asm"; function caller() { - var a = !(2 > 3); + var a = 0; + a = !(2 > 3); return a | 0; } @@ -341,7 +430,7 @@ function TestNotEquals() { function caller() { var a = 3; - if (a != 2) { + if ((a|0) != 2) { return 21; } return 0; @@ -379,7 +468,7 @@ function TestMixedAdd() { var c = 0; c = ((a>>>0) + b)|0; if ((c >>> 0) > (0>>>0)) { - if (c < 0) { + if ((c|0) < 0) { return 23; } } @@ -414,8 +503,9 @@ assertWasm(7, TestInt32HeapAccess); function TestInt32HeapAccessExternal() { var memory = new ArrayBuffer(1024); var memory_int32 = new Int32Array(memory); - var module = Wasm.instantiateModuleFromAsm( - TestInt32HeapAccess.toString(), null, memory); + var module_decl = eval('(' + TestInt32HeapAccess.toString() + ')'); + var module = module_decl(stdlib, null, memory); + assertValidAsm(module_decl); assertEquals(7, module.caller()); assertEquals(7, memory_int32[2]); } @@ -438,10 +528,13 @@ function TestHeapAccessIntTypes() { code = code.replace(/>> 2/g, types[i][2]); var memory = new ArrayBuffer(1024); var memory_view = new types[i][0](memory); - var module = Wasm.instantiateModuleFromAsm(code, null, memory); + var module_decl = eval('(' + code + ')'); + var module = module_decl(stdlib, null, memory); + assertValidAsm(module_decl); assertEquals(7, module.caller()); assertEquals(7, memory_view[2]); - assertEquals(7, Wasm.instantiateModuleFromAsm(code).caller()); + assertEquals(7, module_decl(stdlib).caller()); + assertValidAsm(module_decl); } } @@ -469,15 +562,15 @@ function TestFloatHeapAccess(stdlib, foreign, buffer) { return {caller: caller}; } -assertEquals(1, Wasm.instantiateModuleFromAsm( - TestFloatHeapAccess.toString()).caller()); +assertWasm(1, TestFloatHeapAccess); function TestFloatHeapAccessExternal() { var memory = new ArrayBuffer(1024); var memory_float64 = new Float64Array(memory); - var module = Wasm.instantiateModuleFromAsm( - TestFloatHeapAccess.toString(), null, memory); + var module_decl = eval('(' + TestFloatHeapAccess.toString() + ')'); + var module = module_decl(stdlib, null, memory); + assertValidAsm(module_decl); assertEquals(1, module.caller()); assertEquals(9.0, memory_float64[1]); } @@ -603,6 +696,7 @@ function TestModDoubleNegative() { assertWasm(28, TestModDoubleNegative); + (function () { function TestNamedFunctions() { "use asm"; @@ -623,11 +717,14 @@ function TestNamedFunctions() { add:add}; } -var module = Wasm.instantiateModuleFromAsm(TestNamedFunctions.toString()); +var module_decl = eval('(' + TestNamedFunctions.toString() + ')'); +var module = module_decl(stdlib); +assertValidAsm(module_decl); module.init(); assertEquals(77.5, module.add()); })(); + (function () { function TestGlobalsWithInit() { "use asm"; @@ -642,7 +739,9 @@ function TestGlobalsWithInit() { return {add:add}; } -var module = Wasm.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); +var module_decl = eval('(' + TestGlobalsWithInit.toString() + ')'); +var module = module_decl(stdlib); +assertValidAsm(module_decl); assertEquals(77.5, module.add()); })(); @@ -652,7 +751,7 @@ function TestForLoop() { function caller() { var ret = 0; var i = 0; - for (i = 2; i <= 10; i = (i+1)|0) { + for (i = 2; (i|0) <= 10; i = (i+1)|0) { ret = (ret + i) | 0; } return ret|0; @@ -670,7 +769,7 @@ function TestForLoopWithoutInit() { function caller() { var ret = 0; var i = 0; - for (; i < 10; i = (i+1)|0) { + for (; (i|0) < 10; i = (i+1)|0) { ret = (ret + 10) | 0; } return ret|0; @@ -690,7 +789,7 @@ function TestForLoopWithoutCondition() { var i = 0; for (i=1;; i = (i+1)|0) { ret = (ret + i) | 0; - if (i == 11) { + if ((i|0) == 11) { break; } } @@ -708,7 +807,7 @@ function TestForLoopWithoutNext() { function caller() { var i = 0; - for (i=1; i < 41;) { + for (i=1; (i|0) < 41;) { i = (i + 1) | 0; } return i|0; @@ -725,7 +824,7 @@ function TestForLoopWithoutBody() { function caller() { var i = 0; - for (i=1; i < 45 ; i = (i+1)|0) { + for (i=1; (i|0) < 45 ; i = (i+1)|0) { } return i|0; } @@ -745,7 +844,7 @@ function TestDoWhile() { do { ret = (ret + ret)|0; i = (i + 1)|0; - } while (i < 2); + } while ((i|0) < 2); return ret|0; } @@ -760,7 +859,7 @@ function TestConditional() { function caller() { var x = 1; - return ((x > 0) ? 41 : 71)|0; + return (((x|0) > 0) ? 41 : 71)|0; } return {caller:caller}; @@ -769,83 +868,6 @@ function TestConditional() { assertWasm(41, TestConditional); -function TestSwitch() { - "use asm" - - function caller() { - var ret = 0; - var x = 7; - switch (x) { - case 1: return 0; - case 7: { - ret = 12; - break; - } - default: return 0; - } - switch (x) { - case 1: return 0; - case 8: return 0; - default: ret = (ret + 11)|0; - } - return ret|0; - } - - return {caller:caller}; -} - -assertWasm(23, TestSwitch); - - -function TestSwitchFallthrough() { - "use asm" - - function caller() { - var x = 17; - var ret = 0; - switch (x) { - case 17: - case 14: ret = 39; - case 1: ret = (ret + 3)|0; - case 4: break; - default: ret = (ret + 1)|0; - } - return ret|0; - } - - return {caller:caller}; -} - -assertWasm(42, TestSwitchFallthrough); - - -function TestNestedSwitch() { - "use asm" - - function caller() { - var x = 3; - var y = -13; - switch (x) { - case 1: return 0; - case 3: { - switch (y) { - case 2: return 0; - case -13: return 43; - default: return 0; - } - } - default: return 0; - } - return 0; - } - - return {caller:caller}; -} - -assertWasm(43, TestNestedSwitch); - - -(function () { function TestInitFunctionWithNoGlobals() { "use asm"; function caller() { @@ -854,10 +876,8 @@ function TestInitFunctionWithNoGlobals() { return {caller}; } -var module = Wasm.instantiateModuleFromAsm( - TestInitFunctionWithNoGlobals.toString()); -assertEquals(51, module.caller()); -})(); +assertWasm(51, TestInitFunctionWithNoGlobals); + (function () { function TestExportNameDifferentFromFunctionName() { @@ -868,11 +888,14 @@ function TestExportNameDifferentFromFunctionName() { return {alt_caller:caller}; } -var module = Wasm.instantiateModuleFromAsm( - TestExportNameDifferentFromFunctionName.toString()); +var module_decl = eval( + '(' + TestExportNameDifferentFromFunctionName.toString() + ')'); +var module = module_decl(stdlib); +assertValidAsm(module_decl); assertEquals(55, module.alt_caller()); })(); + function TestFunctionTableSingleFunction() { "use asm"; @@ -881,7 +904,9 @@ function TestFunctionTableSingleFunction() { } function caller() { - return function_table[0&0]() | 0; + // TODO(jpp): the parser optimizes function_table[0&0] to function table[0]. + var v = 0; + return function_table[v&0]() | 0; } var function_table = [dummy] @@ -906,8 +931,9 @@ function TestFunctionTableMultipleFunctions() { } function caller() { - if (function_table[0&1](50) == 51) { - if (function_table[1&1](60) == 62) { + var i = 0, j = 1; + if ((function_table[i&1](50)|0) == 51) { + if ((function_table[j&1](60)|0) == 62) { return 73; } } @@ -923,7 +949,7 @@ assertWasm(73, TestFunctionTableMultipleFunctions); (function () { -function TestFunctionTable() { +function TestFunctionTable(stdlib, foreign, buffer) { "use asm"; function add(a, b) { @@ -948,9 +974,9 @@ function TestFunctionTable() { fun_id = fun_id|0; arg1 = arg1|0; arg2 = arg2|0; - if (table_id == 0) { + if ((table_id|0) == 0) { return funBin[fun_id&3](arg1, arg2)|0; - } else if (table_id == 1) { + } else if ((table_id|0) == 1) { return fun[fun_id&0](arg1)|0; } return 0; @@ -962,7 +988,7 @@ function TestFunctionTable() { return {caller:caller}; } -var module = Wasm.instantiateModuleFromAsm(TestFunctionTable.toString()); +var module = TestFunctionTable(stdlib); assertEquals(55, module.caller(0, 0, 33, 22)); assertEquals(11, module.caller(0, 1, 33, 22)); assertEquals(9, module.caller(0, 2, 54, 45)); @@ -1008,8 +1034,8 @@ function TestForeignFunctions() { var foreign = new ffi(23); - var module = Wasm.instantiateModuleFromAsm(AsmModule.toString(), - foreign, null); + var module = AsmModule({Math: Math}, foreign, null); + assertValidAsm(AsmModule); assertEquals(103, module.caller(23, 103)); } @@ -1047,8 +1073,9 @@ function TestForeignFunctionMultipleUse() { var foreign = new ffi(); - var module = Wasm.instantiateModuleFromAsm(AsmModule.toString(), - foreign, null); + var module_decl = eval('(' + AsmModule.toString() + ')'); + var module = module_decl(stdlib, foreign, null); + assertValidAsm(module_decl); assertEquals(89, module.caller(83, 83.25)); } @@ -1086,8 +1113,9 @@ function TestForeignVariables() { function TestCase(env, i1, f1, i2, f2) { print("Testing foreign variables..."); - var module = Wasm.instantiateModuleFromAsm( - AsmModule.toString(), env); + var module_decl = eval('(' + AsmModule.toString() + ')'); + var module = module_decl(stdlib, env); + assertValidAsm(module_decl); assertEquals(i1, module.geti1()); assertEquals(f1, module.getf1()); assertEquals(i2, module.geti2()); @@ -1178,8 +1206,9 @@ TestForeignVariables(); return {load: load, iload: iload, store: store, storeb: storeb}; } - var m = Wasm.instantiateModuleFromAsm( - TestByteHeapAccessCompat.toString()); + var module_decl = eval('(' + TestByteHeapAccessCompat.toString() + ')'); + var m = module_decl(stdlib); + assertValidAsm(module_decl); m.store(0, 20); m.store(4, 21); m.store(8, 22); @@ -1228,7 +1257,9 @@ assertWasm(15, TestGlobalBlock, { x: 4, y: 11 }); return {ifunc: ifunc, dfunc: dfunc}; } - var m = Wasm.instantiateModuleFromAsm(CommaModule.toString()); + var module_decl = eval('(' + CommaModule.toString() + ')'); + var m = module_decl(stdlib); + assertValidAsm(module_decl); assertEquals(123, m.ifunc(456.7, 123)); assertEquals(123.4, m.dfunc(456, 123.4)); })(); @@ -1285,73 +1316,91 @@ function TestXor() { assertWasm(1, TestXor); -(function TestIntishAssignment() { - function Module(stdlib, foreign, heap) { - "use asm"; - var HEAP32 = new stdlib.Int32Array(heap); - function func() { - var a = 1; - var b = 2; - HEAP32[0] = a + b; - return HEAP32[0] | 0; - } - return {func: func}; +function TestIntishAssignment(stdlib, foreign, heap) { + "use asm"; + var HEAP32 = new stdlib.Int32Array(heap); + function func() { + var a = 1; + var b = 2; + HEAP32[0] = a + b; + return HEAP32[0] | 0; } + return {caller: func}; +} - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(3, m.func()); -})(); +assertWasm(3, TestIntishAssignment); -(function TestFloatishAssignment() { - function Module(stdlib, foreign, heap) { - "use asm"; - var HEAPF32 = new stdlib.Float32Array(heap); - var fround = stdlib.Math.fround; - function func() { - var a = fround(1.0); - var b = fround(2.0); - HEAPF32[0] = a + b; - return +HEAPF32[0]; - } - return {func: func}; +function TestFloatishAssignment(stdlib, foreign, heap) { + "use asm"; + var HEAPF32 = new stdlib.Float32Array(heap); + var fround = stdlib.Math.fround; + function func() { + var a = fround(1.0); + var b = fround(2.0); + HEAPF32[0] = a + b; + return +HEAPF32[0]; } + return {caller: func}; +} - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(3, m.func()); -})(); +assertWasm(3, TestFloatishAssignment); -(function TestDoubleToFloatAssignment() { +function TestDoubleToFloatAssignment(stdlib, foreign, heap) { + "use asm"; + var HEAPF32 = new stdlib.Float32Array(heap); + var fround = stdlib.Math.fround; + function func() { + var a = 1.23; + HEAPF32[0] = a; + return +HEAPF32[0]; + } + return {caller: func}; +} + +assertWasm(Math.fround(1.23), TestDoubleToFloatAssignment); + + +function TestIntegerMultiplyBothWays(stdlib, foreign, heap) { + "use asm"; + function func() { + var a = 1; + return (((a * 3)|0) + ((4 * a)|0)) | 0; + } + return {caller: func}; +} + +assertWasm(7, TestIntegerMultiplyBothWays); + + +(function TestBadAssignDoubleFromIntish() { function Module(stdlib, foreign, heap) { "use asm"; - var HEAPF32 = new stdlib.Float32Array(heap); - var fround = stdlib.Math.fround; function func() { - var a = 1.23; - HEAPF32[0] = a; - return +HEAPF32[0]; + var a = 1; + var b = 3.0; + b = a; } return {func: func}; } - - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(1.23, m.func()); -}); + Module(stdlib); + assertTrue(%IsNotAsmWasmCode(Module)); +})(); -(function TestIntegerMultiplyBothWays() { +(function TestBadAssignIntFromDouble() { function Module(stdlib, foreign, heap) { "use asm"; function func() { var a = 1; - return ((a * 3) + (4 * a)) | 0; + var b = 3.0; + a = b; } return {func: func}; } - - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(7, m.func()); + Module(stdlib); + assertTrue(%IsNotAsmWasmCode(Module)); })(); @@ -1364,9 +1413,8 @@ assertWasm(1, TestXor); } return {func: func}; } - assertThrows(function() { - Wasm.instantiateModuleFromAsm(Module.toString()); - }); + Module(stdlib); + assertTrue(%IsNotAsmWasmCode(Module)); })(); @@ -1379,44 +1427,37 @@ assertWasm(1, TestXor); } return {func: func}; } - assertThrows(function() { - Wasm.instantiateModuleFromAsm(Module.toString()); - }); + Module(stdlib); + assertTrue(%IsNotAsmWasmCode(Module)); })(); -(function TestAndNegative() { - function Module() { - "use asm"; - function func() { - var x = 1; - var y = 2; - var z = 0; - z = x + y & -1; - return z | 0; - } - return {func: func}; +function TestAndNegative() { + "use asm"; + function func() { + var x = 1; + var y = 2; + var z = 0; + z = x + y & -1; + return z | 0; } + return {caller: func}; +} - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(3, m.func()); -})(); +assertWasm(3, TestAndNegative); -(function TestNegativeDouble() { - function Module() { - "use asm"; - function func() { - var x = -(34359738368.25); - var y = -2.5; - return +(x + y); - } - return {func: func}; +function TestNegativeDouble() { + "use asm"; + function func() { + var x = -(34359738368.25); + var y = -2.5; + return +(x + y); } + return {caller: func}; +} - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(-34359738370.75, m.func()); -})(); +assertWasm(-34359738370.75, TestNegativeDouble); (function TestBadAndDouble() { @@ -1430,42 +1471,38 @@ assertWasm(1, TestXor); return {func: func}; } - assertThrows(function() { - Wasm.instantiateModuleFromAsm(Module.toString()); - }); + Module(stdlib); + assertTrue(%IsNotAsmWasmCode(Module)); })(); -(function TestAndIntAndHeapValue() { - function Module(stdlib, foreign, buffer) { - "use asm"; - var HEAP32 = new stdlib.Int32Array(buffer); - function func() { - var x = 0; - x = HEAP32[0] & -1; - return x | 0; - } - return {func: func}; +function TestAndIntAndHeapValue(stdlib, foreign, buffer) { + "use asm"; + var HEAP32 = new stdlib.Int32Array(buffer); + function func() { + var x = 0; + x = HEAP32[0] & -1; + return x | 0; } + return {caller: func}; +} - var m = Wasm.instantiateModuleFromAsm(Module.toString()); - assertEquals(0, m.func()); -})(); +assertWasm(0, TestAndIntAndHeapValue); -(function TestOutOfBoundsConversion() { - function asmModule($a,$b,$c){'use asm'; - function aaa() { - var f = 0.0; - var a = 0; - f = 5616315000.000001; - a = ~~f >>>0; - return a | 0; - } - return { main : aaa }; + +function TestOutOfBoundsConversion($a,$b,$c){'use asm'; + function aaa() { + var f = 0.0; + var a = 0; + f = 5616315000.000001; + a = ~~f >>>0; + return a | 0; } - var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); - assertEquals(1321347704, wasm.main()); -})(); + return { caller : aaa }; +} + +assertWasm(1321347704, TestOutOfBoundsConversion); + (function TestUnsignedLiterals() { function asmModule() { @@ -1488,8 +1525,59 @@ assertWasm(1, TestXor); u0x87654321: u0x87654321, }; } - var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); + var decl = eval('(' + asmModule.toString() + ')'); + var wasm = decl(stdlib); + assertValidAsm(decl); assertEquals(0xffffffff, wasm.u0xffffffff()); assertEquals(0x80000000, wasm.u0x80000000()); assertEquals(0x87654321, wasm.u0x87654321()); })(); + + +function TestIfWithUnsigned() { + "use asm"; + function main() { + if (2147483658) { // 2^31 + 10 + return 231; + } + return 0; + } + return {caller:main}; +} + +assertWasm(231, TestIfWithUnsigned); + + +function TestLoopsWithUnsigned() { + "use asm"; + function main() { + var val = 1; + var count = 0; + for (val = 2147483648; 2147483648;) { + val = 2147483649; + break; + } + while (val>>>0) { + val = (val + 1) | 0; + count = (count + 1)|0; + if ((count|0) == 9) { + break; + } + } + count = 0; + do { + val = (val + 2) | 0; + count = (count + 1)|0; + if ((count|0) == 5) { + break; + } + } while (0xffffffff); + if ((val>>>0) == 2147483668) { + return 323; + } + return 0; + } + return {caller:main}; +} + +assertWasm(323, TestLoopsWithUnsigned); diff --git a/deps/v8/test/mjsunit/wasm/calls.js b/deps/v8/test/mjsunit/wasm/calls.js index 11cc92a8ec..4da0501cf2 100644 --- a/deps/v8/test/mjsunit/wasm/calls.js +++ b/deps/v8/test/mjsunit/wasm/calls.js @@ -37,7 +37,6 @@ function assertFunction(module, func) { assertFalse(exp === null); assertFalse(exp === 0); assertEquals("function", typeof exp); - return exp; } @@ -46,11 +45,12 @@ function assertFunction(module, func) { var builder = new WasmModuleBuilder(); builder.addMemory(1, 1, true); - builder.addFunction("sub", [kAstI32, kAstI32, kAstI32]) + builder.addFunction("sub", kSig_i_ii) .addBody([ - kExprI32Sub, // -- kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 1, // -- + kExprI32Sub, // -- + ]) .exportFunc() var module = builder.instantiate(); @@ -70,7 +70,7 @@ function assertFunction(module, func) { var kPages = 2; builder.addMemory(kPages, kPages, true); - builder.addFunction("nop", [kAstStmt]) + builder.addFunction("nop", kSig_v_v) .addBody([kExprNop]) .exportFunc(); @@ -87,11 +87,12 @@ function assertFunction(module, func) { var kPages = 3; builder.addMemory(kPages, kPages, true); - builder.addFunction("flt", [kAstI32, kAstF64, kAstF64]) + builder.addFunction("flt", kSig_i_dd) .addBody([ - kExprF64Lt, // -- kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 1, // -- + kExprF64Lt // -- + ]) // -- .exportFunc(); var module = builder.instantiate(); diff --git a/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js b/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js new file mode 100644 index 0000000000..94cc894275 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/compiled-module-serialization.js @@ -0,0 +1,80 @@ +// 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-wasm --allow-natives-syntax --expose-gc + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +(function SerializeAndDeserializeModule() { + var builder = new WasmModuleBuilder(); + builder.addMemory(1,1, true); + var kSig_v_i = makeSig([kAstI32], []); + var signature = builder.addType(kSig_v_i); + builder.addImport("some_value", kSig_i); + builder.addImport("writer", signature); + + builder.addFunction("main", kSig_i_i) + .addBody([ + kExprI32Const, 1, + kExprGetLocal, 0, + kExprI32LoadMem, 0, 0, + kExprCallIndirect, kArity1, signature, + kExprGetLocal,0, + kExprI32LoadMem,0, 0, + kExprCallImport, kArity0, 0, + kExprI32Add + ]).exportFunc(); + + // writer(mem[i]); + // return mem[i] + some_value(); + builder.addFunction("_wrap_writer", signature) + .addBody([ + kExprGetLocal, 0, + kExprCallImport, kArity1, 1]); + builder.appendToTable([0, 1]); + + + var module = new WebAssembly.Module(builder.toBuffer()); + var buff = %SerializeWasmModule(module); + module = null; + gc(); + module = %DeserializeWasmModule(buff); + + var mem_1 = new ArrayBuffer(4); + var view_1 = new Int32Array(mem_1); + + view_1[0] = 42; + + var outval_1; + var i1 = new WebAssembly.Instance(module, {some_value: () => 1, + writer: (x)=>outval_1 = x }, mem_1); + + assertEquals(43, i1.exports.main(0)); + + assertEquals(42, outval_1); +})(); + +(function DeserializeInvalidObject() { + var invalid_buffer = new ArrayBuffer(10); + + module = %DeserializeWasmModule(invalid_buffer); + assertEquals(module, undefined); +})(); + +(function RelationBetweenModuleAndClone() { + let builder = new WasmModuleBuilder(); + builder.addFunction("main", kSig_i) + .addBody([kExprI8Const, 42]) + .exportFunc(); + + var compiled_module = new WebAssembly.Module(builder.toBuffer()); + var serialized = %SerializeWasmModule(compiled_module); + var clone = %DeserializeWasmModule(serialized); + + assertNotNull(clone); + assertFalse(clone == undefined); + assertFalse(clone == compiled_module); + assertEquals(clone.constructor, compiled_module.constructor); +})() diff --git a/deps/v8/test/mjsunit/wasm/debug-disassembly.js b/deps/v8/test/mjsunit/wasm/debug-disassembly.js new file mode 100644 index 0000000000..976098a853 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/debug-disassembly.js @@ -0,0 +1,128 @@ +// Copyright 2016 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-wasm --expose-debug-as debug + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +Debug = debug.Debug + +// Initialized in setup(). +var exception; +var break_count; +var num_wasm_scripts; +var module; + +function listener(event, exec_state, event_data, data) { + try { + if (event == Debug.DebugEvent.Break) { + ++break_count; + // Request frame details. This should trigger creation of the Script + // objects for all frames on the stack. + var num_frames = exec_state.frameCount(); + for (var i = 0; i < num_frames; ++i) { + var frame = exec_state.frame(i); + var details = frame.details(); + var script = details.script(); + if (script.type == Debug.ScriptType.Wasm) { + var pos = frame.sourcePosition(); + var name = script.nameOrSourceURL(); + var disassembly = Debug.disassembleWasmFunction(script.id); + var offset_table = Debug.getWasmFunctionOffsetTable(script.id); + assertEquals(0, offset_table.length % 3); + var lineNr = null; + var columnNr = null; + for (var p = 0; p < offset_table.length; p += 3) { + if (offset_table[p] != pos) continue; + lineNr = offset_table[p+1]; + columnNr = offset_table[p+2]; + } + assertNotNull(lineNr, "position should occur in offset table"); + assertNotNull(columnNr, "position should occur in offset table"); + var line = disassembly.split("\n")[lineNr]; + assertTrue(!!line, "line number must occur in disassembly"); + assertTrue(line.length > columnNr, "column number must be valid"); + var expected_string; + if (name.endsWith("/0")) { + // Function 0 calls the imported function. + expected_string = "kExprCallImport,"; + } else if (name.endsWith("/1")) { + // Function 1 calls function 0. + expected_string = "kExprCallFunction,"; + } else { + assertTrue(false, "Unexpected wasm script: " + name); + } + assertTrue(line.substr(columnNr).startsWith(expected_string), + "offset " + columnNr + " should start with '" + expected_string + + "': " + line); + } + } + } else if (event == Debug.DebugEvent.AfterCompile) { + var script = event_data.script(); + if (script.scriptType() == Debug.ScriptType.Wasm) { + ++num_wasm_scripts; + } + } + } catch (e) { + print("exception: " + e); + exception = e; + } +}; + +var builder = new WasmModuleBuilder(); + +builder.addImport("func", kSig_v_v); + +builder.addFunction("call_import", kSig_v_v) + .addBody([kExprCallImport, kArity0, 0]) + .exportFunc(); + +// Add a bit of unneccessary code to increase the byte offset. +builder.addFunction("call_call_import", kSig_v_v) + .addLocals({i32_count: 2}) + .addBody([ + kExprI32Const, 27, kExprSetLocal, 0, + kExprI32Const, (-7 & 0x7f), kExprSetLocal, 1, + kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add, kExprI64UConvertI32, + kExprI64Const, 0, + kExprI64Ne, kExprIf, + kExprCallFunction, kArity0, 0, + kExprEnd + ]) + .exportFunc(); + +function call_debugger() { + debugger; +} + +function setup() { + module = builder.instantiate({func: call_debugger}); + exception = null; + break_count = 0; + num_wasm_scripts = 0; +} + +(function testRegisteredWasmScripts1() { + setup(); + Debug.setListener(listener); + // Call the "call_import" function -> 1 script. + module.exports.call_import(); + module.exports.call_import(); + module.exports.call_call_import(); + Debug.setListener(null); + + assertEquals(3, break_count); + if (exception) throw exception; +})(); + +(function testRegisteredWasmScripts2() { + setup(); + Debug.setListener(listener); + module.exports.call_call_import(); + Debug.setListener(null); + + assertEquals(1, break_count); + if (exception) throw exception; +})(); diff --git a/deps/v8/test/mjsunit/wasm/divrem-trap.js b/deps/v8/test/mjsunit/wasm/divrem-trap.js index 976e4736bc..6f3ff5db73 100644 --- a/deps/v8/test/mjsunit/wasm/divrem-trap.js +++ b/deps/v8/test/mjsunit/wasm/divrem-trap.js @@ -33,8 +33,12 @@ function assertTraps(code, msg) { function makeBinop(opcode) { var builder = new WasmModuleBuilder(); - builder.addFunction("main", [kAstI32, kAstI32, kAstI32]) - .addBody([opcode, kExprGetLocal, 0, kExprGetLocal, 1]) + builder.addFunction("main", kSig_i_ii) + .addBody([ + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + opcode, // -- + ]) .exportFunc(); return builder.instantiate().exports.main; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/box2d.js b/deps/v8/test/mjsunit/wasm/embenchen/box2d.js index d9c78124d9..d8800e7758 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/box2d.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/box2d.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = /frame averages: .+ \+- .+, range: .+ to .+ \n/; @@ -6038,7 +6038,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -20100,9 +20101,10 @@ function b6() { var FUNCTION_TABLE_viiii = [b11,__ZNK11b2EdgeShape11ComputeAABBEP6b2AABBRK11b2Transformi,__ZNK14b2PolygonShape11ComputeAABBEP6b2AABBRK11b2Transformi,__ZN22b2EdgeAndCircleContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN23b2EdgeAndPolygonContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN25b2PolygonAndCircleContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN16b2PolygonContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN23b2ChainAndCircleContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN24b2ChainAndPolygonContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZN15b2CircleContact8EvaluateEP10b2ManifoldRK11b2TransformS4_,__ZNK10__cxxabiv117__class_type_info27has_unambiguous_public_baseEPNS_19__dynamic_cast_infoEPvi,__ZNK10__cxxabiv120__si_class_type_info27has_unambiguous_public_baseEPNS_19__dynamic_cast_infoEPvi,b11,b11,b11,b11]; return { _strlen: _strlen, _free: _free, _main: _main, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9, dynCall_iiii: dynCall_iiii, dynCall_viiiii: dynCall_viiiii, dynCall_vi: dynCall_vi, dynCall_vii: dynCall_vii, dynCall_ii: dynCall_ii, dynCall_viii: dynCall_viii, dynCall_v: dynCall_v, dynCall_viid: dynCall_viid, dynCall_viiiiii: dynCall_viiiiii, dynCall_iii: dynCall_iii, dynCall_iiiiii: dynCall_iiiiii, dynCall_viiii: dynCall_viiii }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_viiiii": invoke_viiiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_ii": invoke_ii, "invoke_viii": invoke_viii, "invoke_v": invoke_v, "invoke_viid": invoke_viid, "invoke_viiiiii": invoke_viiiiii, "invoke_iii": invoke_iii, "invoke_iiiiii": invoke_iiiiii, "invoke_viiii": invoke_viiii, "___cxa_throw": ___cxa_throw, "_emscripten_run_script": _emscripten_run_script, "_cosf": _cosf, "_send": _send, "__ZSt9terminatev": __ZSt9terminatev, "__reallyNegative": __reallyNegative, "___cxa_is_number_type": ___cxa_is_number_type, "___assert_fail": ___assert_fail, "___cxa_allocate_exception": ___cxa_allocate_exception, "___cxa_find_matching_catch": ___cxa_find_matching_catch, "_fflush": _fflush, "_pwrite": _pwrite, "___setErrNo": ___setErrNo, "_sbrk": _sbrk, "___cxa_begin_catch": ___cxa_begin_catch, "_sinf": _sinf, "_fileno": _fileno, "___resumeException": ___resumeException, "__ZSt18uncaught_exceptionv": __ZSt18uncaught_exceptionv, "_sysconf": _sysconf, "_clock": _clock, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_puts": _puts, "_mkport": _mkport, "_floorf": _floorf, "_sqrtf": _sqrtf, "_write": _write, "_emscripten_set_main_loop": _emscripten_set_main_loop, "___errno_location": ___errno_location, "__ZNSt9exceptionD2Ev": __ZNSt9exceptionD2Ev, "_printf": _printf, "___cxa_does_inherit": ___cxa_does_inherit, "__exit": __exit, "_fputc": _fputc, "_abort": _abort, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "_emscripten_cancel_main_loop": _emscripten_cancel_main_loop, "__formatString": __formatString, "_fputs": _fputs, "_exit": _exit, "___cxa_pure_virtual": ___cxa_pure_virtual, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity, "__ZTISt9exception": __ZTISt9exception }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_viiiii": invoke_viiiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_ii": invoke_ii, "invoke_viii": invoke_viii, "invoke_v": invoke_v, "invoke_viid": invoke_viid, "invoke_viiiiii": invoke_viiiiii, "invoke_iii": invoke_iii, "invoke_iiiiii": invoke_iiiiii, "invoke_viiii": invoke_viiii, "___cxa_throw": ___cxa_throw, "_emscripten_run_script": _emscripten_run_script, "_cosf": _cosf, "_send": _send, "__ZSt9terminatev": __ZSt9terminatev, "__reallyNegative": __reallyNegative, "___cxa_is_number_type": ___cxa_is_number_type, "___assert_fail": ___assert_fail, "___cxa_allocate_exception": ___cxa_allocate_exception, "___cxa_find_matching_catch": ___cxa_find_matching_catch, "_fflush": _fflush, "_pwrite": _pwrite, "___setErrNo": ___setErrNo, "_sbrk": _sbrk, "___cxa_begin_catch": ___cxa_begin_catch, "_sinf": _sinf, "_fileno": _fileno, "___resumeException": ___resumeException, "__ZSt18uncaught_exceptionv": __ZSt18uncaught_exceptionv, "_sysconf": _sysconf, "_clock": _clock, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_puts": _puts, "_mkport": _mkport, "_floorf": _floorf, "_sqrtf": _sqrtf, "_write": _write, "_emscripten_set_main_loop": _emscripten_set_main_loop, "___errno_location": ___errno_location, "__ZNSt9exceptionD2Ev": __ZNSt9exceptionD2Ev, "_printf": _printf, "___cxa_does_inherit": ___cxa_does_inherit, "__exit": __exit, "_fputc": _fputc, "_abort": _abort, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "_emscripten_cancel_main_loop": _emscripten_cancel_main_loop, "__formatString": __formatString, "_fputs": _fputs, "_exit": _exit, "___cxa_pure_virtual": ___cxa_pure_virtual, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity, "__ZTISt9exception": __ZTISt9exception }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _free = Module["_free"] = asm["_free"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/copy.js b/deps/v8/test/mjsunit/wasm/embenchen/copy.js index 70609aa242..ce2ea9273e 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/copy.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/copy.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'sum:8930\n'; var Module = { @@ -5452,7 +5452,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -5768,9 +5769,10 @@ function stackSave() { return { _strlen: _strlen, _memcpy: _memcpy, _main: _main, _memset: _memset, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9 }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _memcpy = Module["_memcpy"] = asm["_memcpy"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/corrections.js b/deps/v8/test/mjsunit/wasm/embenchen/corrections.js index 23bec5f5c7..e8c46316b8 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/corrections.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/corrections.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'final: 40006013:58243.\n'; var Module = { @@ -5452,7 +5452,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -5775,9 +5776,10 @@ function stackSave() { return { _strlen: _strlen, _memcpy: _memcpy, _main: _main, _memset: _memset, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9 }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _memcpy = Module["_memcpy"] = asm["_memcpy"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/fannkuch.js b/deps/v8/test/mjsunit/wasm/embenchen/fannkuch.js index 8c03a344f2..86ba2862f0 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/fannkuch.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/fannkuch.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = '123456789\n' + @@ -5666,7 +5666,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -8225,9 +8226,10 @@ function stackSave() { return { _strlen: _strlen, _free: _free, _main: _main, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9 }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_fflush": _fflush, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_putchar": _putchar, "_fputc": _fputc, "_send": _send, "_pwrite": _pwrite, "_abort": _abort, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_sbrk": _sbrk, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_printf": _printf, "_time": _time, "_sysconf": _sysconf, "_write": _write, "___errno_location": ___errno_location, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_fflush": _fflush, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_putchar": _putchar, "_fputc": _fputc, "_send": _send, "_pwrite": _pwrite, "_abort": _abort, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_sbrk": _sbrk, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_printf": _printf, "_time": _time, "_sysconf": _sysconf, "_write": _write, "___errno_location": ___errno_location, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _free = Module["_free"] = asm["_free"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/fasta.js b/deps/v8/test/mjsunit/wasm/embenchen/fasta.js index 1cd47fa1db..4c9f611160 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/fasta.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/fasta.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA\n' + @@ -5828,7 +5828,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -8392,9 +8393,10 @@ function b2() { var FUNCTION_TABLE_v = [b2]; return { _strlen: _strlen, _free: _free, _main: _main, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9, dynCall_ii: dynCall_ii, dynCall_vi: dynCall_vi, dynCall_v: dynCall_v }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_ii": invoke_ii, "invoke_vi": invoke_vi, "invoke_v": invoke_v, "_send": _send, "___setErrNo": ___setErrNo, "___cxa_is_number_type": ___cxa_is_number_type, "___cxa_allocate_exception": ___cxa_allocate_exception, "___cxa_find_matching_catch": ___cxa_find_matching_catch, "_fflush": _fflush, "_time": _time, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_sbrk": _sbrk, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_fileno": _fileno, "___resumeException": ___resumeException, "__ZSt18uncaught_exceptionv": __ZSt18uncaught_exceptionv, "_sysconf": _sysconf, "_puts": _puts, "_mkport": _mkport, "_write": _write, "___errno_location": ___errno_location, "__ZNSt9exceptionD2Ev": __ZNSt9exceptionD2Ev, "_fputc": _fputc, "___cxa_throw": ___cxa_throw, "_abort": _abort, "_fwrite": _fwrite, "___cxa_does_inherit": ___cxa_does_inherit, "_fprintf": _fprintf, "__formatString": __formatString, "_fputs": _fputs, "_printf": _printf, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity, "__ZTISt9exception": __ZTISt9exception, "__ZTVN10__cxxabiv120__si_class_type_infoE": __ZTVN10__cxxabiv120__si_class_type_infoE }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_ii": invoke_ii, "invoke_vi": invoke_vi, "invoke_v": invoke_v, "_send": _send, "___setErrNo": ___setErrNo, "___cxa_is_number_type": ___cxa_is_number_type, "___cxa_allocate_exception": ___cxa_allocate_exception, "___cxa_find_matching_catch": ___cxa_find_matching_catch, "_fflush": _fflush, "_time": _time, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_sbrk": _sbrk, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_fileno": _fileno, "___resumeException": ___resumeException, "__ZSt18uncaught_exceptionv": __ZSt18uncaught_exceptionv, "_sysconf": _sysconf, "_puts": _puts, "_mkport": _mkport, "_write": _write, "___errno_location": ___errno_location, "__ZNSt9exceptionD2Ev": __ZNSt9exceptionD2Ev, "_fputc": _fputc, "___cxa_throw": ___cxa_throw, "_abort": _abort, "_fwrite": _fwrite, "___cxa_does_inherit": ___cxa_does_inherit, "_fprintf": _fprintf, "__formatString": __formatString, "_fputs": _fputs, "_printf": _printf, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity, "__ZTISt9exception": __ZTISt9exception, "__ZTVN10__cxxabiv120__si_class_type_infoE": __ZTVN10__cxxabiv120__si_class_type_infoE }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _free = Module["_free"] = asm["_free"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/lua_binarytrees.js b/deps/v8/test/mjsunit/wasm/embenchen/lua_binarytrees.js index a5f8228b82..17d52a33b7 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/lua_binarytrees.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/lua_binarytrees.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'stretch tree of depth 10\t check: -1\n' + @@ -7208,7 +7208,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -40877,9 +40878,10 @@ function b1(i1) { var FUNCTION_TABLE_iii = [b5,_lua_newstate]; return { _testSetjmp: _testSetjmp, _i64Subtract: _i64Subtract, _free: _free, _main: _main, _rand_r: _rand_r, _realloc: _realloc, _i64Add: _i64Add, _tolower: _tolower, _saveSetjmp: _saveSetjmp, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, _strlen: _strlen, _rand: _rand, _bitshift64Shl: _bitshift64Shl, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9, dynCall_iiii: dynCall_iiii, dynCall_vi: dynCall_vi, dynCall_vii: dynCall_vii, dynCall_ii: dynCall_ii, dynCall_iiiii: dynCall_iiiii, dynCall_iii: dynCall_iii }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_ii": invoke_ii, "invoke_iiiii": invoke_iiiii, "invoke_iii": invoke_iii, "_isalnum": _isalnum, "_fabs": _fabs, "_frexp": _frexp, "_exp": _exp, "_fread": _fread, "__reallyNegative": __reallyNegative, "_longjmp": _longjmp, "__addDays": __addDays, "_fsync": _fsync, "_signal": _signal, "_rename": _rename, "_sbrk": _sbrk, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_sinh": _sinh, "_sysconf": _sysconf, "_close": _close, "_ferror": _ferror, "_clock": _clock, "_cos": _cos, "_tanh": _tanh, "_unlink": _unlink, "_write": _write, "__isLeapYear": __isLeapYear, "_ftell": _ftell, "_isupper": _isupper, "_gmtime_r": _gmtime_r, "_islower": _islower, "_tmpnam": _tmpnam, "_tmpfile": _tmpfile, "_send": _send, "_abort": _abort, "_setvbuf": _setvbuf, "_atan2": _atan2, "_setlocale": _setlocale, "_isgraph": _isgraph, "_modf": _modf, "_strerror_r": _strerror_r, "_fscanf": _fscanf, "___setErrNo": ___setErrNo, "_isalpha": _isalpha, "_srand": _srand, "_mktime": _mktime, "_putchar": _putchar, "_gmtime": _gmtime, "_localeconv": _localeconv, "_sprintf": _sprintf, "_localtime": _localtime, "_read": _read, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "_exit": _exit, "_freopen": _freopen, "_llvm_pow_f64": _llvm_pow_f64, "_fgetc": _fgetc, "_fmod": _fmod, "_lseek": _lseek, "_rmdir": _rmdir, "_asin": _asin, "_floor": _floor, "_pwrite": _pwrite, "_localtime_r": _localtime_r, "_tzset": _tzset, "_open": _open, "_remove": _remove, "_snprintf": _snprintf, "__scanString": __scanString, "_strftime": _strftime, "_fseek": _fseek, "_iscntrl": _iscntrl, "_isxdigit": _isxdigit, "_fclose": _fclose, "_log": _log, "_recv": _recv, "_tan": _tan, "_copysign": _copysign, "__getFloat": __getFloat, "_fputc": _fputc, "_ispunct": _ispunct, "_ceil": _ceil, "_isspace": _isspace, "_fopen": _fopen, "_sin": _sin, "_acos": _acos, "_cosh": _cosh, "___buildEnvironment": ___buildEnvironment, "_difftime": _difftime, "_ungetc": _ungetc, "_system": _system, "_fflush": _fflush, "_log10": _log10, "_fileno": _fileno, "__exit": __exit, "__arraySum": __arraySum, "_fgets": _fgets, "_atan": _atan, "_pread": _pread, "_mkport": _mkport, "_toupper": _toupper, "_feof": _feof, "___errno_location": ___errno_location, "_clearerr": _clearerr, "_getenv": _getenv, "_strerror": _strerror, "_emscripten_longjmp": _emscripten_longjmp, "__formatString": __formatString, "_fputs": _fputs, "_sqrt": _sqrt, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "cttz_i8": cttz_i8, "ctlz_i8": ctlz_i8, "___rand_seed": ___rand_seed, "NaN": NaN, "Infinity": Infinity, "_stderr": _stderr, "_stdin": _stdin, "_stdout": _stdout }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_ii": invoke_ii, "invoke_iiiii": invoke_iiiii, "invoke_iii": invoke_iii, "_isalnum": _isalnum, "_fabs": _fabs, "_frexp": _frexp, "_exp": _exp, "_fread": _fread, "__reallyNegative": __reallyNegative, "_longjmp": _longjmp, "__addDays": __addDays, "_fsync": _fsync, "_signal": _signal, "_rename": _rename, "_sbrk": _sbrk, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_sinh": _sinh, "_sysconf": _sysconf, "_close": _close, "_ferror": _ferror, "_clock": _clock, "_cos": _cos, "_tanh": _tanh, "_unlink": _unlink, "_write": _write, "__isLeapYear": __isLeapYear, "_ftell": _ftell, "_isupper": _isupper, "_gmtime_r": _gmtime_r, "_islower": _islower, "_tmpnam": _tmpnam, "_tmpfile": _tmpfile, "_send": _send, "_abort": _abort, "_setvbuf": _setvbuf, "_atan2": _atan2, "_setlocale": _setlocale, "_isgraph": _isgraph, "_modf": _modf, "_strerror_r": _strerror_r, "_fscanf": _fscanf, "___setErrNo": ___setErrNo, "_isalpha": _isalpha, "_srand": _srand, "_mktime": _mktime, "_putchar": _putchar, "_gmtime": _gmtime, "_localeconv": _localeconv, "_sprintf": _sprintf, "_localtime": _localtime, "_read": _read, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "_exit": _exit, "_freopen": _freopen, "_llvm_pow_f64": _llvm_pow_f64, "_fgetc": _fgetc, "_fmod": _fmod, "_lseek": _lseek, "_rmdir": _rmdir, "_asin": _asin, "_floor": _floor, "_pwrite": _pwrite, "_localtime_r": _localtime_r, "_tzset": _tzset, "_open": _open, "_remove": _remove, "_snprintf": _snprintf, "__scanString": __scanString, "_strftime": _strftime, "_fseek": _fseek, "_iscntrl": _iscntrl, "_isxdigit": _isxdigit, "_fclose": _fclose, "_log": _log, "_recv": _recv, "_tan": _tan, "_copysign": _copysign, "__getFloat": __getFloat, "_fputc": _fputc, "_ispunct": _ispunct, "_ceil": _ceil, "_isspace": _isspace, "_fopen": _fopen, "_sin": _sin, "_acos": _acos, "_cosh": _cosh, "___buildEnvironment": ___buildEnvironment, "_difftime": _difftime, "_ungetc": _ungetc, "_system": _system, "_fflush": _fflush, "_log10": _log10, "_fileno": _fileno, "__exit": __exit, "__arraySum": __arraySum, "_fgets": _fgets, "_atan": _atan, "_pread": _pread, "_mkport": _mkport, "_toupper": _toupper, "_feof": _feof, "___errno_location": ___errno_location, "_clearerr": _clearerr, "_getenv": _getenv, "_strerror": _strerror, "_emscripten_longjmp": _emscripten_longjmp, "__formatString": __formatString, "_fputs": _fputs, "_sqrt": _sqrt, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "cttz_i8": cttz_i8, "ctlz_i8": ctlz_i8, "___rand_seed": ___rand_seed, "NaN": NaN, "Infinity": Infinity, "_stderr": _stderr, "_stdin": _stdin, "_stdout": _stdout }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _testSetjmp = Module["_testSetjmp"] = asm["_testSetjmp"]; var _i64Subtract = Module["_i64Subtract"] = asm["_i64Subtract"]; var _free = Module["_free"] = asm["_free"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/memops.js b/deps/v8/test/mjsunit/wasm/embenchen/memops.js index 09bbd36eae..aa8c12f486 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/memops.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/memops.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'final: 840.\n'; var Module = { @@ -5613,7 +5613,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -7877,9 +7878,10 @@ function stackSave() { return { _strlen: _strlen, _free: _free, _main: _main, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9 }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_fflush": _fflush, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "_abort": _abort, "___setErrNo": ___setErrNo, "_fwrite": _fwrite, "_sbrk": _sbrk, "_time": _time, "_mkport": _mkport, "__reallyNegative": __reallyNegative, "__formatString": __formatString, "_fileno": _fileno, "_write": _write, "_fprintf": _fprintf, "_sysconf": _sysconf, "___errno_location": ___errno_location, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_fflush": _fflush, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "_abort": _abort, "___setErrNo": ___setErrNo, "_fwrite": _fwrite, "_sbrk": _sbrk, "_time": _time, "_mkport": _mkport, "__reallyNegative": __reallyNegative, "__formatString": __formatString, "_fileno": _fileno, "_write": _write, "_fprintf": _fprintf, "_sysconf": _sysconf, "___errno_location": ___errno_location, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _free = Module["_free"] = asm["_free"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/primes.js b/deps/v8/test/mjsunit/wasm/embenchen/primes.js index 5e02d79dec..95cb6535e7 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/primes.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/primes.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'lastprime: 387677.\n'; var Module = { @@ -5454,7 +5454,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -5776,9 +5777,10 @@ function stackSave() { return { _strlen: _strlen, _memcpy: _memcpy, _main: _main, _memset: _memset, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9 }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "_sqrtf": _sqrtf, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "_free": _free, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_printf": _printf, "_send": _send, "_pwrite": _pwrite, "_sqrtf": _sqrtf, "__reallyNegative": __reallyNegative, "_fwrite": _fwrite, "_malloc": _malloc, "_mkport": _mkport, "_fprintf": _fprintf, "___setErrNo": ___setErrNo, "__formatString": __formatString, "_fileno": _fileno, "_fflush": _fflush, "_write": _write, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _memcpy = Module["_memcpy"] = asm["_memcpy"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/embenchen/zlib.js b/deps/v8/test/mjsunit/wasm/embenchen/zlib.js index 9c0d30a813..1628babecf 100644 --- a/deps/v8/test/mjsunit/wasm/embenchen/zlib.js +++ b/deps/v8/test/mjsunit/wasm/embenchen/zlib.js @@ -1,5 +1,5 @@ // Modified embenchen to direct to asm-wasm. -// Flags: --expose-wasm +// Flags: --validate-asm --allow-natives-syntax var EXPECTED_OUTPUT = 'sizes: 100000,25906\nok.\n'; var Module = { @@ -5687,7 +5687,8 @@ function asmPrintFloat(x, y) { Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack); } // EMSCRIPTEN_START_ASM -var asm = Wasm.instantiateModuleFromAsm((function Module(global, env, buffer) { +var ModuleFunc; +var asm = (ModuleFunc = function(global, env, buffer) { 'use asm'; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -14539,9 +14540,10 @@ function stackSave() { var FUNCTION_TABLE_iii = [b2,_deflate_stored,_deflate_fast,_deflate_slow]; return { _strlen: _strlen, _free: _free, _main: _main, _memset: _memset, _malloc: _malloc, _memcpy: _memcpy, runPostSets: runPostSets, stackAlloc: stackAlloc, stackSave: stackSave, stackRestore: stackRestore, setThrew: setThrew, setTempRet0: setTempRet0, setTempRet1: setTempRet1, setTempRet2: setTempRet2, setTempRet3: setTempRet3, setTempRet4: setTempRet4, setTempRet5: setTempRet5, setTempRet6: setTempRet6, setTempRet7: setTempRet7, setTempRet8: setTempRet8, setTempRet9: setTempRet9, dynCall_iiii: dynCall_iiii, dynCall_vii: dynCall_vii, dynCall_iii: dynCall_iii }; -}).toString(), +}) // EMSCRIPTEN_END_ASM -{ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_vii": invoke_vii, "invoke_iii": invoke_iii, "_send": _send, "___setErrNo": ___setErrNo, "___assert_fail": ___assert_fail, "_fflush": _fflush, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_sbrk": _sbrk, "___errno_location": ___errno_location, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_fileno": _fileno, "_sysconf": _sysconf, "_puts": _puts, "_mkport": _mkport, "_write": _write, "_llvm_bswap_i32": _llvm_bswap_i32, "_fputc": _fputc, "_abort": _abort, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "__formatString": __formatString, "_fputs": _fputs, "_printf": _printf, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_vii": invoke_vii, "invoke_iii": invoke_iii, "_send": _send, "___setErrNo": ___setErrNo, "___assert_fail": ___assert_fail, "_fflush": _fflush, "_pwrite": _pwrite, "__reallyNegative": __reallyNegative, "_sbrk": _sbrk, "___errno_location": ___errno_location, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_fileno": _fileno, "_sysconf": _sysconf, "_puts": _puts, "_mkport": _mkport, "_write": _write, "_llvm_bswap_i32": _llvm_bswap_i32, "_fputc": _fputc, "_abort": _abort, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "__formatString": __formatString, "_fputs": _fputs, "_printf": _printf, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "NaN": NaN, "Infinity": Infinity }, buffer); +assertTrue(%IsAsmWasmCode(ModuleFunc)); var _strlen = Module["_strlen"] = asm["_strlen"]; var _free = Module["_free"] = asm["_free"]; var _main = Module["_main"] = asm["_main"]; diff --git a/deps/v8/test/mjsunit/wasm/ensure-wasm-binaries-up-to-date.js b/deps/v8/test/mjsunit/wasm/ensure-wasm-binaries-up-to-date.js new file mode 100644 index 0000000000..3fab8c65b1 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/ensure-wasm-binaries-up-to-date.js @@ -0,0 +1,16 @@ +// Copyright 2016 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-wasm + +// Ensure checked in wasm binaries used by integration tests from v8 hosts +// (such as chromium) are up to date. + +(function ensure_incrementer() { + var buff = readbuffer("test/mjsunit/wasm/incrementer.wasm"); + var mod = new WebAssembly.Module(buff); + var inst = new WebAssembly.Instance(mod); + var inc = inst.exports.increment; + assertEquals(3, inc(2)); +}()) diff --git a/deps/v8/test/mjsunit/wasm/export-table.js b/deps/v8/test/mjsunit/wasm/export-table.js index e85da9b664..2084ddfc0a 100644 --- a/deps/v8/test/mjsunit/wasm/export-table.js +++ b/deps/v8/test/mjsunit/wasm/export-table.js @@ -11,11 +11,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var kReturnValue = 88; var builder = new WasmModuleBuilder(); - builder.addFunction("main", [kAstI32]) + builder.addFunction("main", kSig_i) .addBody([ - kExprReturn, kExprI8Const, - kReturnValue]) + kReturnValue, + kExprReturn, kArity1 + ]) .exportFunc(); var module = builder.instantiate(); @@ -31,11 +32,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var builder = new WasmModuleBuilder(); - builder.addFunction("main", [kAstI32]) + builder.addFunction("main", kSig_i) .addBody([ - kExprReturn, kExprI8Const, - kReturnValue]) + kReturnValue, + kExprReturn, kArity1 + ]) .exportAs("blah") .exportAs("foo"); @@ -48,3 +50,40 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(kReturnValue, module.exports.foo()); assertEquals(kReturnValue, module.exports.blah()); })(); + + +(function testNumericName() { + var kReturnValue = 93; + + var builder = new WasmModuleBuilder(); + + builder.addFunction("main", kSig_i) + .addBody([ + kExprI8Const, + kReturnValue, + kExprReturn, kArity1 + ]) + .exportAs("0"); + + var module = builder.instantiate(); + + assertEquals("object", typeof module.exports); + assertEquals("function", typeof module.exports["0"]); + + assertEquals(kReturnValue, module.exports["0"]()); +})(); + +(function testExportNameClash() { + var builder = new WasmModuleBuilder(); + + builder.addFunction("one", kSig_v_v).addBody([kExprNop]).exportAs("main"); + builder.addFunction("two", kSig_v_v).addBody([kExprNop]).exportAs("other"); + builder.addFunction("three", kSig_v_v).addBody([kExprNop]).exportAs("main"); + + try { + builder.instantiate(); + assertUnreachable("should have thrown an exception"); + } catch (e) { + assertContains("Duplicate export", e.toString()); + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/ffi-error.js b/deps/v8/test/mjsunit/wasm/ffi-error.js index 649ee273ae..81dc47806e 100644 --- a/deps/v8/test/mjsunit/wasm/ffi-error.js +++ b/deps/v8/test/mjsunit/wasm/ffi-error.js @@ -10,13 +10,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function testCallFFI(ffi) { var builder = new WasmModuleBuilder(); - var sig_index = [kAstI32, kAstF64, kAstF64]; + var sig_index = kSig_i_dd; builder.addImport("fun", sig_index); builder.addFunction("main", sig_index) .addBody([ - kExprCallImport, 0, // -- - kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallFunction, kArity2, 0, // -- + ]) // -- .exportFunc(); var module = builder.instantiate(ffi); @@ -58,3 +59,22 @@ assertThrows(function() { ffi.fun = 0; testCallFFI(ffi); }); + + +(function I64InSignatureThrows() { + var builder = new WasmModuleBuilder(); + + builder.addMemory(1, 1, true); + builder.addFunction("function_with_invalid_signature", kSig_l_ll) + .addBody([ // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprI64Sub]) // -- + .exportFunc() + + var module = builder.instantiate(); + + assertThrows(function() { + module.exports.function_with_invalid_signature(33, 88); + }, TypeError); +})(); diff --git a/deps/v8/test/mjsunit/wasm/ffi.js b/deps/v8/test/mjsunit/wasm/ffi.js index 61fcf02b3c..e84f038e68 100644 --- a/deps/v8/test/mjsunit/wasm/ffi.js +++ b/deps/v8/test/mjsunit/wasm/ffi.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: --expose-wasm +// Flags: --expose-wasm --allow-natives-syntax load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-module-builder.js"); @@ -10,13 +10,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function testCallFFI(func, check) { var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([kAstI32, kAstF64, kAstF64]); + var sig_index = builder.addType(kSig_i_dd); builder.addImport("func", sig_index); builder.addFunction("main", sig_index) .addBody([ - kExprCallImport, 0, // -- - kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallImport, kArity2, 0 // -- + ]) // -- .exportFunc(); var main = builder.instantiate({func: func}).exports.main; @@ -24,7 +25,9 @@ function testCallFFI(func, check) { for (var i = 0; i < 100000; i += 10003) { var a = 22.5 + i, b = 10.5 + i; var r = main(a, b); - check(r, a, b); + if (check) { + check(r, a, b); + } } } @@ -51,8 +54,63 @@ function check_FOREIGN_SUB(r, a, b) { was_called = false; } +// Test calling a normal JSFunction. +print("JSFunction"); testCallFFI(FOREIGN_SUB, check_FOREIGN_SUB); +// Test calling a proxy. +print("Proxy"); +var proxy_sub = new Proxy(FOREIGN_SUB, {}); +testCallFFI(proxy_sub, check_FOREIGN_SUB); + +// Test calling a bind function. +print("Bind function"); +var bind_sub = FOREIGN_SUB.bind(); +testCallFFI(bind_sub, check_FOREIGN_SUB); + +var main_for_constructor_test; +print("Constructor"); +(function testCallConstructor() { + class C {} + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_i_dd); + builder.addImport("func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallImport, kArity2, 0 // -- + ]) // -- + .exportFunc(); + + main_for_constructor_test = builder.instantiate({func: C}).exports.main; + + assertThrows("main_for_constructor_test(12, 43)", TypeError); +}) (); + +print("Native function"); +(function test_ffi_call_to_native() { + + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_d); + builder.addImport("func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprCallImport, kArity0, 0 // -- + ]) // -- + .exportFunc(); + + var main = builder.instantiate({func: Object.prototype.toString}).exports.main; + // The result of the call to Object.prototype.toString should be + // [object Undefined]. However, we cannot test for this result because wasm + // cannot return objects but converts them to float64 in this test. + assertEquals(NaN, main()); +})(); + +print("Callable JSObject"); +testCallFFI(%GetCallable(), function check(r, a, b) {assertEquals(a - b, r);}); function FOREIGN_ABCD(a, b, c, d) { print("FOREIGN_ABCD(" + a + ", " + b + ", " + c + ", " + d + ")"); @@ -184,14 +242,14 @@ function testCallBinopVoid(type, func, check) { var builder = new WasmModuleBuilder(); - builder.addImport("func", [kAstStmt, type, type]); - builder.addFunction("main", [kAstI32, type, type]) + builder.addImport("func", makeSig_v_xx(type)); + builder.addFunction("main", makeSig_r_xx(kAstI32, type)) .addBody([ - kExprBlock, 2, // -- - kExprCallImport, 0, // -- - kExprGetLocal, 0, // -- - kExprGetLocal, 1, // -- - kExprI8Const, 99]) // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallImport, kArity2, 0, // -- + kExprI8Const, 99 // -- + ]) // -- .exportFunc() var main = builder.instantiate(ffi).exports.main; @@ -240,15 +298,15 @@ testCallBinopVoid(kAstF64); function testCallPrint() { var builder = new WasmModuleBuilder(); - builder.addImport("print", [kAstStmt, kAstI32]); - builder.addImport("print", [kAstStmt, kAstF64]); - builder.addFunction("main", [kAstStmt, kAstF64]) + builder.addImport("print", makeSig_v_x(kAstI32)); + builder.addImport("print", makeSig_v_x(kAstF64)); + builder.addFunction("main", makeSig_v_x(kAstF64)) .addBody([ - kExprBlock, 2, // -- - kExprCallImport, 0, // -- - kExprI8Const, 97, // -- - kExprCallImport, 1, // -- - kExprGetLocal, 0]) // -- + kExprI8Const, 97, // -- + kExprCallImport, kArity1, 0, // -- + kExprGetLocal, 0, // -- + kExprCallImport, kArity1, 1 // -- + ]) // -- .exportFunc() var main = builder.instantiate({print: print}).exports.main; diff --git a/deps/v8/test/mjsunit/wasm/frame-inspection.js b/deps/v8/test/mjsunit/wasm/frame-inspection.js new file mode 100644 index 0000000000..4d342e6cae --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/frame-inspection.js @@ -0,0 +1,74 @@ +// Copyright 2016 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-wasm --expose-debug-as debug + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +Debug = debug.Debug + +var exception = null; +var break_count = 0; + +const expected_num_frames = 5; +const expected_wasm_frames = [false, true, true, false, false]; +const expected_wasm_positions = [0, 1, 2, 0, 0]; +const expected_function_names = ["call_debugger", "wasm_2", "wasm_1", "testFrameInspection", ""]; + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + ++break_count; + try { + var break_id = exec_state.break_id; + var frame_count = exec_state.frameCount(); + assertEquals(expected_num_frames, frame_count); + + for (var i = 0; i < frame_count; ++i) { + var frame = exec_state.frame(i); + // wasm frames have unresolved function, others resolved ones. + assertEquals(expected_wasm_frames[i], !frame.func().resolved()); + assertEquals(expected_function_names[i], frame.func().name()); + if (expected_wasm_frames[i]) { + var script = frame.details().script(); + assertNotNull(script); + assertEquals(expected_wasm_positions[i], frame.details().sourcePosition()); + var loc = script.locationFromPosition(frame.details().sourcePosition()); + assertEquals(expected_wasm_positions[i], loc.column); + assertEquals(expected_wasm_positions[i], loc.position); + } + } + } catch (e) { + exception = e; + } +}; + +var builder = new WasmModuleBuilder(); + +// wasm_1 calls wasm_2 on offset 2. +// wasm_2 calls call_debugger on offset 1. + +builder.addImport("func", kSig_v_v); + +builder.addFunction("wasm_1", kSig_v_v) + .addBody([kExprNop, kExprCallFunction, kArity0, 1]) + .exportAs("main"); + +builder.addFunction("wasm_2", kSig_v_v) + .addBody([kExprCallImport, kArity0, 0]); + +function call_debugger() { + debugger; +} + +var module = builder.instantiate({func: call_debugger}); + +(function testFrameInspection() { + Debug.setListener(listener); + module.exports.main(); + Debug.setListener(null); + + assertEquals(1, break_count); + if (exception) throw exception; +})(); diff --git a/deps/v8/test/mjsunit/wasm/function-names.js b/deps/v8/test/mjsunit/wasm/function-names.js new file mode 100644 index 0000000000..15771d8470 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/function-names.js @@ -0,0 +1,69 @@ +// Copyright 2016 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-wasm + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +var builder = new WasmModuleBuilder(); + +var last_func_index = builder.addFunction("exec_unreachable", kSig_v_v) + .addBody([kExprUnreachable]) + +var illegal_func_name = [0xff]; +var func_names = [ "☠", illegal_func_name, "some math: (½)² = ¼", "" ]; +var expected_names = ["exec_unreachable", "☠", null, + "some math: (½)² = ¼", "", "main"]; + +for (var func_name of func_names) { + last_func_index = builder.addFunction(func_name, kSig_v_v) + .addBody([kExprCallFunction, kArity0, last_func_index]).index; +} + +builder.addFunction("main", kSig_v_v) + .addBody([kExprCallFunction, kArity0, last_func_index]) + .exportFunc(); + +var module = builder.instantiate(); + +(function testFunctionNamesAsString() { + var names = expected_names.concat(["testFunctionNamesAsString", null]); + try { + module.exports.main(); + assertFalse("should throw"); + } catch (e) { + var lines = e.stack.split(/\r?\n/); + lines.shift(); + assertEquals(names.length, lines.length); + for (var i = 0; i < names.length; ++i) { + var line = lines[i].trim(); + if (names[i] === null) continue; + var printed_name = names[i] === undefined ? "<WASM UNNAMED>" : names[i] + var expected_start = "at " + printed_name + " ("; + assertTrue(line.startsWith(expected_start), + "should start with '" + expected_start + "': '" + line + "'"); + } + } +})(); + +// For the remaining tests, collect the Callsite objects instead of just a +// string: +Error.prepareStackTrace = function(error, frames) { + return frames; +}; + + +(function testFunctionNamesAsCallSites() { + var names = expected_names.concat(["testFunctionNamesAsCallSites", null]); + try { + module.exports.main(); + assertFalse("should throw"); + } catch (e) { + assertEquals(names.length, e.stack.length); + for (var i = 0; i < names.length; ++i) { + assertEquals(names[i], e.stack[i].getFunctionName()); + } + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/function-prototype.js b/deps/v8/test/mjsunit/wasm/function-prototype.js index db04b950bb..25339adea7 100644 --- a/deps/v8/test/mjsunit/wasm/function-prototype.js +++ b/deps/v8/test/mjsunit/wasm/function-prototype.js @@ -10,7 +10,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); (function TestFunctionPrototype() { var builder = new WasmModuleBuilder(); - builder.addFunction("nine", [kAstI32]) + builder.addFunction("nine", kSig_i) .addBody([kExprI8Const, 9]) .exportFunc(); diff --git a/deps/v8/test/mjsunit/wasm/gc-frame.js b/deps/v8/test/mjsunit/wasm/gc-frame.js index 8387d26176..9c37fe485f 100644 --- a/deps/v8/test/mjsunit/wasm/gc-frame.js +++ b/deps/v8/test/mjsunit/wasm/gc-frame.js @@ -10,14 +10,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function makeFFI(func, t) { var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([t,t,t,t,t,t,t,t,t,t,t]); + var sig_index = builder.addType(makeSig([t,t,t,t,t,t,t,t,t,t], [t])); builder.addImport("func", sig_index); // Try to create a frame with lots of spilled values and parameters // on the stack to try to catch GC bugs in the reference maps for // the different parts of the stack. builder.addFunction("main", sig_index) .addBody([ - kExprCallImport, 0, // -- kExprGetLocal, 0, // -- kExprGetLocal, 1, // -- kExprGetLocal, 2, // -- @@ -28,7 +27,7 @@ function makeFFI(func, t) { kExprGetLocal, 7, // -- kExprGetLocal, 8, // -- kExprGetLocal, 9, // -- - kExprCallImport, 0, // -- + kExprCallImport, 10, 0, // -- kExprGetLocal, 0, // -- kExprGetLocal, 1, // -- kExprGetLocal, 2, // -- @@ -38,7 +37,8 @@ function makeFFI(func, t) { kExprGetLocal, 6, // -- kExprGetLocal, 7, // -- kExprGetLocal, 8, // -- - kExprGetLocal, 9 // -- + kExprGetLocal, 9, // -- + kExprCallImport, 10, 0 // -- ]) // -- .exportFunc(); @@ -66,9 +66,32 @@ function print10(a, b, c, d, e, f, g, h, i) { } })(); -(function I32Test() { +(function F64Test() { var main = makeFFI(print10, kAstF64); for (var i = 1; i < 2e+80; i *= -1137) { main(i - 1, i, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8); } })(); + +(function GCInJSToWasmTest() { + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_i_i); + builder.addFunction("main", sig_index) + .addBody([ + kExprGetLocal, 0, // -- + ]) // -- + .exportFunc(); + + var main = builder.instantiate({}).exports.main; + + var gc_object = { + valueOf: function() { + // Call the GC in valueOf, which is called within the JSToWasm wrapper. + gc(); + return {}; + } + }; + + main(gc_object); +})(); diff --git a/deps/v8/test/mjsunit/wasm/grow-memory.js b/deps/v8/test/mjsunit/wasm/grow-memory.js new file mode 100644 index 0000000000..27aca22d1a --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/grow-memory.js @@ -0,0 +1,119 @@ +// Copyright 2016 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-wasm --expose-gc --stress-compaction + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +var kPageSize = 0x10000; + +function genGrowMemoryBuilder() { + var builder = new WasmModuleBuilder(); + builder.addFunction("grow_memory", kSig_i_i) + .addBody([kExprGetLocal, 0, kExprGrowMemory]) + .exportFunc(); + builder.addFunction("load", kSig_i_i) + .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) + .exportFunc(); + builder.addFunction("store", kSig_i_ii) + .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0]) + .exportFunc(); + return builder; +} + +function testGrowMemoryReadWrite() { + var builder = genGrowMemoryBuilder(); + builder.addMemory(1, 1, false); + var module = builder.instantiate(); + var offset; + function peek() { return module.exports.load(offset); } + function poke(value) { return module.exports.store(offset, value); } + function growMem(pages) { return module.exports.grow_memory(pages); } + + for(offset = 0; offset <= (kPageSize - 4); offset++) { + poke(20); + assertEquals(20, peek()); + } + for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) { + assertTraps(kTrapMemOutOfBounds, poke); + assertTraps(kTrapMemOutOfBounds, peek); + } + + assertEquals(1, growMem(3)); + + for (offset = kPageSize; offset <= 4*kPageSize -4; offset++) { + poke(20); + assertEquals(20, peek()); + } + for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) { + assertTraps(kTrapMemOutOfBounds, poke); + assertTraps(kTrapMemOutOfBounds, peek); + } + + assertEquals(4, growMem(15)); + + for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) { + poke(20); + assertEquals(20, peek()); + } + for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset++) { + poke(20); + assertEquals(20, peek()); + } + for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) { + assertTraps(kTrapMemOutOfBounds, poke); + assertTraps(kTrapMemOutOfBounds, peek); + } +} + +testGrowMemoryReadWrite(); + +function testGrowMemoryZeroInitialSize() { + var builder = genGrowMemoryBuilder(); + var module = builder.instantiate(); + var offset; + function peek() { return module.exports.load(offset); } + function poke(value) { return module.exports.store(offset, value); } + function growMem(pages) { return module.exports.grow_memory(pages); } + + assertTraps(kTrapMemOutOfBounds, peek); + assertTraps(kTrapMemOutOfBounds, poke); + + assertEquals(0, growMem(1)); + + for(offset = 0; offset <= kPageSize - 4; offset++) { + poke(20); + assertEquals(20, peek()); + } + + //TODO(gdeepti): Fix tests with correct write boundaries + //when runtime function is fixed. + for(offset = kPageSize; offset <= kPageSize + 5; offset++) { + assertTraps(kTrapMemOutOfBounds, peek); + } +} + +testGrowMemoryZeroInitialSize(); + +function testGrowMemoryTrapMaxPagesZeroInitialMemory() { + var builder = genGrowMemoryBuilder(); + var module = builder.instantiate(); + var maxPages = 16385; + function growMem(pages) { return module.exports.grow_memory(pages); } + assertEquals(-1, growMem(maxPages)); +} + +testGrowMemoryTrapMaxPagesZeroInitialMemory(); + +function testGrowMemoryTrapMaxPages() { + var builder = genGrowMemoryBuilder(); + builder.addMemory(1, 1, false); + var module = builder.instantiate(); + var maxPages = 16384; + function growMem(pages) { return module.exports.grow_memory(pages); } + assertEquals(-1, growMem(maxPages)); +} + +testGrowMemoryTrapMaxPages(); diff --git a/deps/v8/test/mjsunit/wasm/import-table.js b/deps/v8/test/mjsunit/wasm/import-table.js index 7579901651..8680addf61 100644 --- a/deps/v8/test/mjsunit/wasm/import-table.js +++ b/deps/v8/test/mjsunit/wasm/import-table.js @@ -10,13 +10,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function testCallImport(func, check) { var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([kAstI32, kAstF64, kAstF64]); + var sig_index = builder.addType(kSig_i_dd); builder.addImport("func", sig_index); builder.addFunction("main", sig_index) .addBody([ - kExprCallImport, 0, // -- kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 1, // -- + kExprCallImport, 2, 0]) // -- .exportAs("main"); var main = builder.instantiate({func: func}).exports.main; @@ -45,7 +45,7 @@ function FOREIGN_SUB(a, b) { function check_FOREIGN_SUB(r, a, b) { assertEquals(a - b | 0, r); assertTrue(was_called); -// assertEquals(global, params[0]); // sloppy mode + assertEquals(global, params[0]); // sloppy mode assertEquals(a, params[1]); assertEquals(b, params[2]); was_called = false; @@ -68,7 +68,7 @@ function FOREIGN_ABCD(a, b, c, d) { function check_FOREIGN_ABCD(r, a, b) { assertEquals((a * b * 6) | 0, r); assertTrue(was_called); -// assertEquals(global, params[0]); // sloppy mode. + assertEquals(global, params[0]); // sloppy mode. assertEquals(a, params[1]); assertEquals(b, params[2]); assertEquals(undefined, params[3]); @@ -186,14 +186,14 @@ function testCallBinopVoid(type, func, check) { var builder = new WasmModuleBuilder(); - builder.addImport("func", [kAstStmt, type, type]); - builder.addFunction("main", [kAstI32, type, type]) + builder.addImport("func", makeSig_v_xx(type)); + builder.addFunction("main", makeSig_r_xx(kAstI32, type)) .addBody([ - kExprBlock, 2, // -- - kExprCallImport, 0, // -- kExprGetLocal, 0, // -- kExprGetLocal, 1, // -- - kExprI8Const, 99]) + kExprCallImport, 2, 0, // -- + kExprI8Const, 99, // -- + ]) .exportFunc("main"); var main = builder.instantiate(ffi).exports.main; @@ -241,15 +241,15 @@ testCallBinopVoid(kAstF64); function testCallPrint() { var builder = new WasmModuleBuilder(); - builder.addImport("print", [kAstStmt, kAstI32]); - builder.addImport("print", [kAstStmt, kAstF64]); - builder.addFunction("main", [kAstStmt, kAstF64]) + builder.addImport("print", makeSig_v_x(kAstI32)); + builder.addImport("print", makeSig_r_x(kAstF64, kAstF64)); + builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64)) .addBody([ - kExprBlock, 2, // -- - kExprCallImport, 0, // -- - kExprI8Const, 97, // -- - kExprCallImport, 1, // -- - kExprGetLocal, 0]) // -- + kExprI8Const, 97, // -- + kExprCallImport, kArity1, 0, // -- + kExprGetLocal, 0, // -- + kExprCallImport, kArity1, 1 // -- + ]) .exportFunc(); var main = builder.instantiate({print: print}).exports.main; @@ -266,13 +266,14 @@ testCallPrint(); function testCallImport2(foo, bar, expected) { var builder = new WasmModuleBuilder(); - builder.addImport("foo", [kAstI32]); - builder.addImport("bar", [kAstI32]); - builder.addFunction("main", [kAstI32]) + builder.addImport("foo", kSig_i); + builder.addImport("bar", kSig_i); + builder.addFunction("main", kSig_i) .addBody([ + kExprCallImport, kArity0, 0, // -- + kExprCallImport, kArity0, 1, // -- kExprI32Add, // -- - kExprCallImport, 0, // -- - kExprCallImport, 1]) // -- + ]) // -- .exportFunc(); var main = builder.instantiate({foo: foo, bar: bar}).exports.main; diff --git a/deps/v8/test/mjsunit/wasm/incrementer.wasm b/deps/v8/test/mjsunit/wasm/incrementer.wasm Binary files differnew file mode 100644 index 0000000000..f80f7ad597 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/incrementer.wasm diff --git a/deps/v8/test/mjsunit/wasm/indirect-calls.js b/deps/v8/test/mjsunit/wasm/indirect-calls.js index 3258687431..1e87c6f823 100644 --- a/deps/v8/test/mjsunit/wasm/indirect-calls.js +++ b/deps/v8/test/mjsunit/wasm/indirect-calls.js @@ -10,24 +10,27 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var module = (function () { var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([kAstI32, kAstI32, kAstI32]); + var sig_index = builder.addType(kSig_i_ii); builder.addImport("add", sig_index); builder.addFunction("add", sig_index) .addBody([ - kExprCallImport, 0, kExprGetLocal, 0, kExprGetLocal, 1 + kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 ]); builder.addFunction("sub", sig_index) .addBody([ - kExprI32Sub, kExprGetLocal, 0, kExprGetLocal, 1 + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprI32Sub, // -- ]); - builder.addFunction("main", [kAstI32, kAstI32, kAstI32, kAstI32]) + builder.addFunction("main", kSig_i_iii) .addBody([ - kExprCallIndirect, sig_index, kExprGetLocal, 0, kExprGetLocal, 1, - kExprGetLocal, 2]) + kExprGetLocal, 2, + kExprCallIndirect, kArity2, sig_index + ]) .exportFunc() - builder.appendToFunctionTable([0, 1, 2]); + builder.appendToTable([0, 1, 2]); return builder.instantiate({add: function(a, b) { return a + b | 0; }}); })(); diff --git a/deps/v8/test/mjsunit/wasm/instantiate-module-basic.js b/deps/v8/test/mjsunit/wasm/instantiate-module-basic.js index bc13122f1b..92cdc14ff9 100644 --- a/deps/v8/test/mjsunit/wasm/instantiate-module-basic.js +++ b/deps/v8/test/mjsunit/wasm/instantiate-module-basic.js @@ -7,44 +7,149 @@ load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-module-builder.js"); -var kReturnValue = 117; - -var module = (function Build() { - var builder = new WasmModuleBuilder(); +let kReturnValue = 117; +let buffer = (() => { + let builder = new WasmModuleBuilder(); builder.addMemory(1, 1, true); - builder.addFunction("main", [kAstI32]) + builder.addFunction("main", kSig_i) .addBody([kExprI8Const, kReturnValue]) .exportFunc(); - return builder.instantiate(); -})(); + return builder.toBuffer(); +})() + +function CheckInstance(instance) { + assertFalse(instance === undefined); + assertFalse(instance === null); + assertFalse(instance === 0); + assertEquals("object", typeof instance); + + // Check the memory is an ArrayBuffer. + var mem = instance.exports.memory; + assertFalse(mem === undefined); + assertFalse(mem === null); + assertFalse(mem === 0); + assertEquals("object", typeof mem); + assertTrue(mem instanceof ArrayBuffer); + for (let i = 0; i < 4; i++) { + instance.exports.memory = 0; // should be ignored + assertSame(mem, instance.exports.memory); + } + + assertEquals(65536, instance.exports.memory.byteLength); + + // Check the properties of the main function. + let main = instance.exports.main; + assertFalse(main === undefined); + assertFalse(main === null); + assertFalse(main === 0); + assertEquals("function", typeof main); -// Check the module exists. -assertFalse(module === undefined); -assertFalse(module === null); -assertFalse(module === 0); -assertEquals("object", typeof module); - -// Check the memory is an ArrayBuffer. -var mem = module.exports.memory; -assertFalse(mem === undefined); -assertFalse(mem === null); -assertFalse(mem === 0); -assertEquals("object", typeof mem); -assertTrue(mem instanceof ArrayBuffer); -for (var i = 0; i < 4; i++) { - module.exports.memory = 0; // should be ignored - assertEquals(mem, module.exports.memory); + assertEquals(kReturnValue, main()); } -assertEquals(65536, module.exports.memory.byteLength); +// Deprecated experimental API. +CheckInstance(Wasm.instantiateModule(buffer)); + +// Official API +let module = new WebAssembly.Module(buffer); +CheckInstance(new WebAssembly.Instance(module)); + +let promise = WebAssembly.compile(buffer); +promise.then(module => CheckInstance(new WebAssembly.Instance(module))); + +// Negative tests. +(function InvalidModules() { + let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; + let len = invalid_cases.length; + for (var i = 0; i < len; ++i) { + try { + let instance = new WebAssembly.Instance(1); + assertUnreachable("should not be able to instantiate invalid modules."); + } catch (e) { + assertContains("Argument 0", e.toString()); + } + } +})(); + +// Compile async an invalid blob. +(function InvalidBinaryAsyncCompilation() { + let builder = new WasmModuleBuilder(); + builder.addFunction("f", kSig_i_i) + .addBody([kExprCallImport, kArity0, 0]); + let promise = WebAssembly.compile(builder.toBuffer()); + promise + .then(compiled => + assertUnreachable("should not be able to compile invalid blob.")) + .catch(e => assertContains("invalid signature index", e.toString())); +})(); + +// Multiple instances tests. +(function ManyInstances() { + let compiled_module = new WebAssembly.Module(buffer); + let instance_1 = new WebAssembly.Instance(compiled_module); + let instance_2 = new WebAssembly.Instance(compiled_module); + assertTrue(instance_1 != instance_2); +})(); + +(function ManyInstancesAsync() { + let promise = WebAssembly.compile(buffer); + promise.then(compiled_module => { + let instance_1 = new WebAssembly.Instance(compiled_module); + let instance_2 = new WebAssembly.Instance(compiled_module); + assertTrue(instance_1 != instance_2); + }); +})(); + +(function InstancesAreIsolatedFromEachother() { + var builder = new WasmModuleBuilder(); + builder.addMemory(1,1, true); + var kSig_v_i = makeSig([kAstI32], []); + var signature = builder.addType(kSig_v_i); + builder.addImport("some_value", kSig_i); + builder.addImport("writer", signature); + + builder.addFunction("main", kSig_i_i) + .addBody([ + kExprI32Const, 1, + kExprGetLocal, 0, + kExprI32LoadMem, 0, 0, + kExprCallIndirect, kArity1, signature, + kExprGetLocal,0, + kExprI32LoadMem,0, 0, + kExprCallImport, kArity0, 0, + kExprI32Add + ]).exportFunc(); -// Check the properties of the main function. -var main = module.exports.main; -assertFalse(main === undefined); -assertFalse(main === null); -assertFalse(main === 0); -assertEquals("function", typeof main); + // writer(mem[i]); + // return mem[i] + some_value(); + builder.addFunction("_wrap_writer", signature) + .addBody([ + kExprGetLocal, 0, + kExprCallImport, kArity1, 1]); + builder.appendToTable([0, 1]); -assertEquals(kReturnValue, main()); + + var module = new WebAssembly.Module(builder.toBuffer()); + var mem_1 = new ArrayBuffer(4); + var mem_2 = new ArrayBuffer(4); + var view_1 = new Int32Array(mem_1); + var view_2 = new Int32Array(mem_2); + + view_1[0] = 42; + view_2[0] = 1000; + + var outval_1; + var outval_2; + var i1 = new WebAssembly.Instance(module, {some_value: () => 1, + writer: (x)=>outval_1 = x }, mem_1); + var i2 = new WebAssembly.Instance(module, {some_value: () => 2, + writer: (x)=>outval_2 = x }, mem_2); + + assertEquals(43, i1.exports.main(0)); + assertEquals(1002, i2.exports.main(0)); + + assertEquals(42, outval_1); + assertEquals(1000, outval_2); +})(); diff --git a/deps/v8/test/mjsunit/wasm/instantiate-run-basic.js b/deps/v8/test/mjsunit/wasm/instantiate-run-basic.js index 2e649a0bd2..fe6fc14e05 100644 --- a/deps/v8/test/mjsunit/wasm/instantiate-run-basic.js +++ b/deps/v8/test/mjsunit/wasm/instantiate-run-basic.js @@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var kReturnValue = 107; var builder = new WasmModuleBuilder(); - builder.addFunction("main", [kAstI32]) + builder.addFunction("main", kSig_i_i) .addBody([kExprI8Const, kReturnValue]) .exportFunc(); diff --git a/deps/v8/test/mjsunit/wasm/module-memory.js b/deps/v8/test/mjsunit/wasm/module-memory.js index ef85eb2357..a5e5f42488 100644 --- a/deps/v8/test/mjsunit/wasm/module-memory.js +++ b/deps/v8/test/mjsunit/wasm/module-memory.js @@ -13,19 +13,27 @@ function genModule(memory) { var builder = new WasmModuleBuilder(); builder.addMemory(1, 1, true); - builder.addFunction("main", [kAstI32, kAstI32]) + builder.addFunction("main", kSig_i_i) .addBody([ - kExprBlock,2, - kExprLoop,1, - kExprIf, + // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; + kExprLoop, + kExprGetLocal,0, + kExprIf, kExprGetLocal,0, - kExprBr, 0, - kExprIfElse, - kExprI32LoadMem,0,0,kExprGetLocal,0, - kExprBr,2, kExprI8Const, 255, - kExprSetLocal,0, - kExprI32Sub,kExprGetLocal,0,kExprI8Const,4, - kExprI8Const,0]) + kExprI32LoadMem,0,0, + kExprIf, + kExprI8Const,255, + kExprReturn, kArity1, + kExprEnd, + kExprGetLocal,0, + kExprI8Const,4, + kExprI32Sub, + kExprSetLocal,0, + kExprBr, kArity1, 1, + kExprEnd, + kExprEnd, + kExprI8Const,0 + ]) .exportFunc(); return builder.instantiate(null, memory); @@ -120,14 +128,16 @@ function testOOBThrows() { var builder = new WasmModuleBuilder(); builder.addMemory(1, 1, true); - builder.addFunction("geti", [kAstI32, kAstI32, kAstI32]) + builder.addFunction("geti", kSig_i_ii) .addBody([ - kExprI32StoreMem, 0, 0, kExprGetLocal, 0, kExprI32LoadMem, 0, 0, kExprGetLocal, 1 + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprI32LoadMem, 0, 0, + kExprI32StoreMem, 0, 0 ]) .exportFunc(); var module = builder.instantiate(); - var offset; function read() { return module.exports.geti(0, offset); } diff --git a/deps/v8/test/mjsunit/wasm/no-wasm-by-default.js b/deps/v8/test/mjsunit/wasm/no-wasm-by-default.js new file mode 100644 index 0000000000..2f9622e2c4 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/no-wasm-by-default.js @@ -0,0 +1,6 @@ +// Copyright 2016 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. + +// TODO(titzer): remove this test when WASM ships. +assertThrows(function() { var g = Wasm; }); diff --git a/deps/v8/test/mjsunit/wasm/parallel_compilation.js b/deps/v8/test/mjsunit/wasm/parallel_compilation.js new file mode 100644 index 0000000000..23c5658dcd --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/parallel_compilation.js @@ -0,0 +1,100 @@ +// Copyright 2016 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-wasm --wasm-num-compilation-tasks=10 + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +function assertModule(module, memsize) { + // Check the module exists. + assertFalse(module === undefined); + assertFalse(module === null); + assertFalse(module === 0); + assertEquals("object", typeof module); + + // Check the memory is an ArrayBuffer. + var mem = module.exports.memory; + assertFalse(mem === undefined); + assertFalse(mem === null); + assertFalse(mem === 0); + assertEquals("object", typeof mem); + assertTrue(mem instanceof ArrayBuffer); + for (var i = 0; i < 4; i++) { + module.exports.memory = 0; // should be ignored + assertEquals(mem, module.exports.memory); + } + + assertEquals(memsize, module.exports.memory.byteLength); +} + +function assertFunction(module, func) { + assertEquals("object", typeof module.exports); + + var exp = module.exports[func]; + assertFalse(exp === undefined); + assertFalse(exp === null); + assertFalse(exp === 0); + assertEquals("function", typeof exp); + return exp; +} + +(function CompileFunctionsTest() { + + var builder = new WasmModuleBuilder(); + + builder.addMemory(1, 1, true); + for (i = 0; i < 1000; i++) { + builder.addFunction("sub" + i, kSig_i_i) + .addBody([ // -- + kExprGetLocal, 0, // -- + kExprI32Const, i % 61, // -- + kExprI32Sub]) // -- + .exportFunc() + } + + var module = builder.instantiate(); + assertModule(module, kPageSize); + + // Check the properties of the functions. + for (i = 0; i < 1000; i++) { + var sub = assertFunction(module, "sub" + i); + assertEquals(33 - (i % 61), sub(33)); + } +})(); + +(function CallFunctionsTest() { + + var builder = new WasmModuleBuilder(); + + var f = [] + + f[0] = builder.addFunction("add0", kSig_i_ii) + .addBody([ + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprI32Add, // -- + ]) + .exportFunc() + + builder.addMemory(1, 1, true); + for (i = 1; i < 256; i++) { + f[i] = builder.addFunction("add" + i, kSig_i_ii) + .addBody([ // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallFunction, kArity2, f[i >>> 1].index]) // -- + .exportFunc() + } + var module = builder.instantiate(); + assertModule(module, kPageSize); + + // Check the properties of the functions. + for (i = 0; i < 256; i++) { + var add = assertFunction(module, "add" + i); + assertEquals(88, add(33, 55)); + assertEquals(88888, add(33333, 55555)); + assertEquals(8888888, add(3333333, 5555555)); + } +})(); diff --git a/deps/v8/test/mjsunit/wasm/params.js b/deps/v8/test/mjsunit/wasm/params.js index 7c2b3d1794..fe1b7d4cfe 100644 --- a/deps/v8/test/mjsunit/wasm/params.js +++ b/deps/v8/test/mjsunit/wasm/params.js @@ -17,7 +17,7 @@ function testSelect2(type) { var builder = new WasmModuleBuilder(); - builder.addFunction("select", [type, type, type]) + builder.addFunction("select", makeSig_r_xx(type, type)) .addBody([kExprGetLocal, which]) .exportFunc() @@ -79,7 +79,7 @@ function testSelect10(t) { print("type = " + t + ", which = " + which); var builder = new WasmModuleBuilder(); - builder.addFunction("select", [t,t,t,t,t,t,t,t,t,t,t]) + builder.addFunction("select", makeSig([t,t,t,t,t,t,t,t,t,t], [t])) .addBody([kExprGetLocal, which]) .exportFunc(); diff --git a/deps/v8/test/mjsunit/wasm/receiver.js b/deps/v8/test/mjsunit/wasm/receiver.js new file mode 100644 index 0000000000..c0070f8b91 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/receiver.js @@ -0,0 +1,45 @@ +// Copyright 2016 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-wasm + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +function testCallImport(func, expected, a, b) { + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_i_dd); + builder.addImport("func", sig_index); + builder.addFunction("main", sig_index) + .addBody([ + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallImport, 2, 0]) // -- + .exportAs("main"); + + var main = builder.instantiate({func: func}).exports.main; + + assertEquals(expected, main(a, b)); +} + +var global = (function() { return this; })(); + +function sloppyReceiver(a, b) { + assertEquals(global, this); + assertEquals(33.3, a); + assertEquals(44.4, b); + return 11; +} + +function strictReceiver(a, b) { + 'use strict'; + assertEquals(undefined, this); + assertEquals(55.5, a); + assertEquals(66.6, b); + return 22; +} + +testCallImport(sloppyReceiver, 11, 33.3, 44.4); +testCallImport(strictReceiver, 22, 55.5, 66.6); diff --git a/deps/v8/test/mjsunit/wasm/stack.js b/deps/v8/test/mjsunit/wasm/stack.js index ed05517ae5..0197b77caf 100644 --- a/deps/v8/test/mjsunit/wasm/stack.js +++ b/deps/v8/test/mjsunit/wasm/stack.js @@ -2,39 +2,148 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// clang-format off // Flags: --expose-wasm load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-module-builder.js"); -var expected = "Error\n" + - // The line numbers below will change as this test gains / loses lines.. - " at STACK (stack.js:24:11)\n" + // -- - " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here. - " at testStack (stack.js:38:18)\n" + // -- - " at stack.js:40:3"; // -- - // The stack trace contains file path, only keep "stack.js". function stripPath(s) { return s.replace(/[^ (]*stack\.js/g, "stack.js"); } +function verifyStack(frames, expected) { + assertEquals(expected.length, frames.length, "number of frames mismatch"); + expected.forEach(function(exp, i) { + assertEquals(exp[1], frames[i].getFunctionName(), + "["+i+"].getFunctionName()"); + assertEquals(exp[2], frames[i].getLineNumber(), "["+i+"].getLineNumber()"); + if (exp[0]) + assertEquals(exp[3], frames[i].getPosition(), + "["+i+"].getPosition()"); + assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()"); + var toString; + if (exp[0]) { + toString = exp[1] + " (<WASM>[" + exp[2] + "]+" + exp[3] + ")"; + } else { + toString = exp[4] + ":" + exp[2] + ":"; + } + assertContains(toString, frames[i].toString(), "["+i+"].toString()"); + }); +} + + var stack; function STACK() { var e = new Error(); stack = e.stack; } -(function testStack() { - var builder = new WasmModuleBuilder(); +var builder = new WasmModuleBuilder(); + +builder.addImport("func", kSig_v_v); - builder.addImport("func", [kAstStmt]); +builder.addFunction("main", kSig_v_v) + .addBody([kExprCallImport, kArity0, 0]) + .exportAs("main"); - builder.addFunction(undefined, [kAstStmt]) - .addBody([kExprCallImport, 0]) - .exportAs("main"); +builder.addFunction("exec_unreachable", kSig_v_v) + .addBody([kExprUnreachable]) + .exportAs("exec_unreachable"); + +// Make this function unnamed, just to test also this case. +var mem_oob_func = builder.addFunction(undefined, kSig_v_v) + // Access the memory at offset -1, to provoke a trap. + .addBody([kExprI32Const, 0x7f, kExprI32LoadMem8S, 0, 0]) + .exportAs("mem_out_of_bounds"); + +// Call the mem_out_of_bounds function, in order to have two WASM stack frames. +builder.addFunction("call_mem_out_of_bounds", kSig_v_v) + .addBody([kExprCallFunction, kArity0, mem_oob_func.index]) + .exportAs("call_mem_out_of_bounds"); + +var module = builder.instantiate({func: STACK}); + +(function testSimpleStack() { + var expected_string = "Error\n" + + // The line numbers below will change as this test gains / loses lines.. + " at STACK (stack.js:39:11)\n" + // -- + " at main (<WASM>[0]+1)\n" + // -- + " at testSimpleStack (stack.js:76:18)\n" + // -- + " at stack.js:78:3"; // -- - var module = builder.instantiate({func: STACK}); module.exports.main(); - assertEquals(expected, stripPath(stack)); + assertEquals(expected_string, stripPath(stack)); +})(); + +// For the remaining tests, collect the Callsite objects instead of just a +// string: +Error.prepareStackTrace = function(error, frames) { + return frames; +}; + +(function testStackFrames() { + module.exports.main(); + + verifyStack(stack, [ + // isWasm function line pos file + [ false, "STACK", 39, 0, "stack.js"], + [ true, "main", 0, 1, null], + [ false, "testStackFrames", 87, 0, "stack.js"], + [ false, null, 96, 0, "stack.js"] + ]); +})(); + +(function testWasmUnreachable() { + try { + module.exports.exec_unreachable(); + fail("expected wasm exception"); + } catch (e) { + assertContains("unreachable", e.message); + verifyStack(e.stack, [ + // isWasm function line pos file + [ true, "exec_unreachable", 1, 1, null], + [ false, "testWasmUnreachable", 100, 0, "stack.js"], + [ false, null, 111, 0, "stack.js"] + ]); + } +})(); + +(function testWasmMemOutOfBounds() { + try { + module.exports.call_mem_out_of_bounds(); + fail("expected wasm exception"); + } catch (e) { + assertContains("out of bounds", e.message); + verifyStack(e.stack, [ + // isWasm function line pos file + [ true, "", 2, 3, null], + [ true, "call_mem_out_of_bounds", 3, 1, null], + [ false, "testWasmMemOutOfBounds", 115, 0, "stack.js"], + [ false, null, 127, 0, "stack.js"] + ]); + } +})(); + + +(function testStackOverflow() { + print("testStackOverflow"); + var builder = new WasmModuleBuilder(); + + var sig_index = builder.addType(kSig_v_v); + builder.addFunction("recursion", sig_index) + .addBody([ + kExprI32Const, 0, + kExprCallIndirect, kArity0, sig_index + ]) + .exportFunc() + builder.appendToTable([0]); + + try { + builder.instantiate().exports.recursion(); + fail("expected wasm exception"); + } catch (e) { + assertEquals("Maximum call stack size exceeded", e.message, "trap reason"); + } })(); diff --git a/deps/v8/test/mjsunit/wasm/stackwalk.js b/deps/v8/test/mjsunit/wasm/stackwalk.js index 8b8fb7e4d4..913269fdf4 100644 --- a/deps/v8/test/mjsunit/wasm/stackwalk.js +++ b/deps/v8/test/mjsunit/wasm/stackwalk.js @@ -10,13 +10,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function makeFFI(func) { var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([kAstI32, kAstF64, kAstF64]); + var sig_index = builder.addType(kSig_i_dd); builder.addImport("func", sig_index); builder.addFunction("main", sig_index) .addBody([ - kExprCallImport, 0, // -- - kExprGetLocal, 0, // -- - kExprGetLocal, 1]) // -- + kExprGetLocal, 0, // -- + kExprGetLocal, 1, // -- + kExprCallImport, kArity2, 0, // -- + ]) .exportFunc() return builder.instantiate({func: func}).exports.main; diff --git a/deps/v8/test/mjsunit/wasm/start-function.js b/deps/v8/test/mjsunit/wasm/start-function.js index bd4ccf22c3..c4d299e871 100644 --- a/deps/v8/test/mjsunit/wasm/start-function.js +++ b/deps/v8/test/mjsunit/wasm/start-function.js @@ -37,19 +37,19 @@ function assertVerifies(sig, body) { return module; } -assertVerifies([kAstStmt], [kExprNop]); -assertVerifies([kAstI32], [kExprI8Const, 0]); +assertVerifies(kSig_v_v, [kExprNop]); +assertVerifies(kSig_i, [kExprI8Const, 0]); // Arguments aren't allow to start functions. -assertFails([kAstI32, kAstI32], [kExprGetLocal, 0]); -assertFails([kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]); -assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); +assertFails(kSig_i_i, [kExprGetLocal, 0]); +assertFails(kSig_i_ii, [kExprGetLocal, 0]); +assertFails(kSig_i_dd, [kExprGetLocal, 0]); (function testInvalidIndex() { print("testInvalidIndex"); var builder = new WasmModuleBuilder(); - var func = builder.addFunction("", [kAstStmt]) + var func = builder.addFunction("", kSig_v_v) .addBody([kExprNop]); builder.addStart(func.index + 1); @@ -62,11 +62,11 @@ assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); print("testTwoStartFuncs"); var builder = new WasmModuleBuilder(); - var func = builder.addFunction("", [kAstStmt]) + var func = builder.addFunction("", kSig_v_v) .addBody([kExprNop]); - builder.addExplicitSection([kDeclStartFunction, 0]); - builder.addExplicitSection([kDeclStartFunction, 0]); + builder.addExplicitSection([kDeclStart, 0]); + builder.addExplicitSection([kDeclStart, 0]); assertThrows(builder.instantiate); })(); @@ -78,8 +78,8 @@ assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); builder.addMemory(12, 12, true); - var func = builder.addFunction("", [kAstStmt]) - .addBody([kExprI32StoreMem, 0, 0, kExprI8Const, 0, kExprI8Const, 77]); + var func = builder.addFunction("", kSig_v_v) + .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); builder.addStart(func.index); @@ -98,11 +98,11 @@ assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); }}; var builder = new WasmModuleBuilder(); - var sig_index = builder.addSignature([kAstStmt]); + var sig_index = builder.addType(kSig_v_v); builder.addImport("foo", sig_index); var func = builder.addFunction("", sig_index) - .addBody([kExprCallImport, 0]); + .addBody([kExprCallImport, kArity0, 0]); builder.addStart(func.index); diff --git a/deps/v8/test/mjsunit/wasm/test-import-export-wrapper.js b/deps/v8/test/mjsunit/wasm/test-import-export-wrapper.js new file mode 100644 index 0000000000..e180611818 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/test-import-export-wrapper.js @@ -0,0 +1,241 @@ +// Copyright 2016 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-wasm --allow-natives-syntax + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +var expect_elison = 0; +var expect_no_elison = 1; +// function calls stack: first_export -> first_func -> first_import -> +// second_export -> second_import +// In this case, first_import and second_export have same signature, +// So that wrappers will be removed +(function TestWasmWrapperElision() { + var imported = function (a) { + return a; + }; + + var second_module = new WasmModuleBuilder(); + var sig_index = second_module.addType(kSig_i_i); + second_module + .addImportWithModule("import_module_2", "import_name_2", sig_index); + second_module + .addFunction("second_export", sig_index) + .addBody([ + kExprGetLocal, 0, + kExprCallImport, kArity1, 0, + kExprReturn, kArity1 + ]) + .exportFunc(); + + var first_module = new WasmModuleBuilder(); + var sig_index = first_module.addType(kSig_i_i); + first_module + .addImportWithModule("import_module_1", "import_name_1", sig_index); + first_module + .addFunction("first_export", sig_index) + .addBody([ + kExprGetLocal, 0, + kExprCallFunction, kArity1, 1, + kExprReturn, kArity1 + ]) + .exportFunc(); + first_module + .addFunction("first_func", sig_index) + .addBody([ + kExprI32Const, 1, + kExprGetLocal, 0, + kExprI32Add, + kExprCallImport, kArity1, 0, + kExprReturn, kArity1 + ]); + + var f = second_module + .instantiate({import_module_2: {import_name_2: imported}}) + .exports.second_export; + var the_export = first_module + .instantiate({import_module_1: {import_name_1: f}}) + .exports.first_export; + assertEquals(the_export(2), 3); + assertEquals(the_export(-1), 0); + assertEquals(the_export(0), 1); + assertEquals(the_export(5.5), 6); + assertEquals(%CheckWasmWrapperElision(the_export, expect_elison), true); +})(); + +// function calls stack: first_export -> first_func -> first_import -> +// second_export -> second_import +// In this case, second_export has less params than first_import, +// So that wrappers will not be removed +(function TestWasmWrapperNoElisionLessParams() { + var imported = function (a) { + return a; + }; + + var second_module = new WasmModuleBuilder(); + var sig_index_1 = second_module.addType(kSig_i_i); + second_module + .addImportWithModule("import_module_2", "import_name_2", sig_index_1); + second_module + .addFunction("second_export", sig_index_1) + .addBody([ + kExprGetLocal, 0, + kExprCallImport, kArity1, 0, + kExprReturn, kArity1 + ]) + .exportFunc(); + + var first_module = new WasmModuleBuilder(); + var sig_index_2 = first_module.addType(kSig_i_ii); + first_module + .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + first_module + .addFunction("first_export", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallFunction, kArity2, 1, + kExprReturn, kArity1 + ]) + .exportFunc(); + first_module + .addFunction("first_func", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallImport, kArity2, 0, + kExprReturn, kArity1 + ]); + + var f = second_module + .instantiate({import_module_2: {import_name_2: imported}}) + .exports.second_export; + var the_export = first_module + .instantiate({import_module_1: {import_name_1: f}}) + .exports.first_export; + assertEquals(the_export(4, 5), 4); + assertEquals(the_export(-1, 4), -1); + assertEquals(the_export(0, 2), 0); + assertEquals(the_export(9.9, 4.3), 9); + assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); +})(); + +// function calls stack: first_export -> first_func -> first_import -> +// second_export -> second_import +// In this case, second_export has more params than first_import, +// So that wrappers will not be removed +(function TestWasmWrapperNoElisionMoreParams() { + var imported = function (a, b, c) { + return a+b+c; + }; + + var second_module = new WasmModuleBuilder(); + var sig_index_3 = second_module.addType(kSig_i_iii); + second_module + .addImportWithModule("import_module_2", "import_name_2", sig_index_3); + second_module + .addFunction("second_export", sig_index_3) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprGetLocal, 2, + kExprCallImport, kArity3, 0, + kExprReturn, kArity1 + ]) + .exportFunc(); + + var first_module = new WasmModuleBuilder(); + var sig_index_2 = first_module.addType(kSig_i_ii); + first_module + .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + first_module + .addFunction("first_export", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallFunction, kArity2, 1, + kExprReturn, kArity1 + ]) + .exportFunc(); + first_module + .addFunction("first_func", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallImport, kArity2, 0, + kExprReturn, kArity1 + ]); + + var f = second_module + .instantiate({import_module_2: {import_name_2: imported}}) + .exports.second_export; + var the_export = first_module + .instantiate({import_module_1: {import_name_1: f}}) + .exports.first_export; + assertEquals(the_export(5, 6), 11); + assertEquals(the_export(-1, -4), -5); + assertEquals(the_export(0, 0), 0); + assertEquals(the_export(1.1, 2.7), 3); + assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); +})(); + +// function calls stack: first_export -> first_func -> first_import -> +// second_export -> second_import +// In this case, second_export has different params type with first_import, +// So that wrappers will not be removed +(function TestWasmWrapperNoElisionTypeMismatch() { + var imported = function (a, b) { + return a+b; + }; + + var second_module = new WasmModuleBuilder(); + var sig_index_2 = second_module.addType(kSig_d_dd); + second_module + .addImportWithModule("import_module_2", "import_name_2", sig_index_2); + second_module + .addFunction("second_export", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallImport, kArity2, 0, + kExprReturn, kArity1 + ]) + .exportFunc(); + + var first_module = new WasmModuleBuilder(); + var sig_index_2 = first_module.addType(kSig_i_ii); + first_module + .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + first_module + .addFunction("first_export", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallFunction, kArity2, 1, + kExprReturn, kArity1 + ]) + .exportFunc(); + first_module + .addFunction("first_func", sig_index_2) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 1, + kExprCallImport, kArity2, 0, + kExprReturn, kArity1 + ]); + + var f = second_module + .instantiate({import_module_2: {import_name_2: imported}}) + .exports.second_export; + var the_export = first_module + .instantiate({import_module_1: {import_name_1: f}}) + .exports.first_export; + assertEquals(the_export(2.8, 9.1), 11); + assertEquals(the_export(-1.7, -2.5), -3); + assertEquals(the_export(0.0, 0.0), 0); + assertEquals(the_export(2, -2), 0); + assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); +})(); diff --git a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js index 50797d0554..72d5a7aaa4 100644 --- a/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js +++ b/deps/v8/test/mjsunit/wasm/test-wasm-module-builder.js @@ -12,7 +12,7 @@ var debug = false; (function BasicTest() { var module = new WasmModuleBuilder(); module.addMemory(1, 2, false); - module.addFunction("foo", [kAstI32]) + module.addFunction("foo", kSig_i) .addBody([kExprI8Const, 11]) .exportAs("blarg"); @@ -23,9 +23,9 @@ var debug = false; (function ImportTest() { var module = new WasmModuleBuilder(); - var index = module.addImport("print", [kAstStmt, kAstI32]); - module.addFunction("foo", [kAstStmt]) - .addBody([kExprCallImport, index, kExprI8Const, 13]) + var index = module.addImport("print", makeSig_v_x(kAstI32)); + module.addFunction("foo", kSig_v_v) + .addBody([kExprI8Const, 13, kExprCallImport, kArity1, index]) .exportAs("main"); var buffer = module.toBuffer(debug); @@ -36,9 +36,9 @@ var debug = false; (function LocalsTest() { var module = new WasmModuleBuilder(); - module.addFunction(undefined, [kAstI32, kAstI32]) + module.addFunction(undefined, kSig_i_i) .addLocals({i32_count: 1}) - .addBody([kExprSetLocal, 1, kExprGetLocal, 0]) + .addBody([kExprGetLocal, 0, kExprSetLocal, 1]) .exportAs("main"); var buffer = module.toBuffer(debug); @@ -58,9 +58,9 @@ var debug = false; for (p of types) { var module = new WasmModuleBuilder(); - module.addFunction(undefined, [p.type, p.type]) + module.addFunction(undefined, makeSig_r_x(p.type, p.type)) .addLocals(p.locals) - .addBody([kExprSetLocal, 1, kExprGetLocal, 0]) + .addBody([kExprGetLocal, 0, kExprSetLocal, 1]) .exportAs("main"); var buffer = module.toBuffer(debug); @@ -72,10 +72,10 @@ var debug = false; (function CallTest() { var module = new WasmModuleBuilder(); - module.addFunction("add", [kAstI32, kAstI32, kAstI32]) - .addBody([kExprI32Add, kExprGetLocal, 0, kExprGetLocal, 1]); - module.addFunction("main", [kAstI32, kAstI32, kAstI32]) - .addBody([kExprCallFunction, 0, kExprGetLocal, 0, kExprGetLocal, 1]) + module.addFunction("add", kSig_i_ii) + .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]); + module.addFunction("main", kSig_i_ii) + .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, kArity2, 0]) .exportAs("main"); var instance = module.instantiate(); @@ -85,13 +85,13 @@ var debug = false; (function IndirectCallTest() { var module = new WasmModuleBuilder(); - module.addFunction("add", [kAstI32, kAstI32, kAstI32]) - .addBody([kExprI32Add, kExprGetLocal, 0, kExprGetLocal, 1]); - module.addFunction("main", [kAstI32, kAstI32, kAstI32, kAstI32]) - .addBody([kExprCallIndirect, 0, kExprGetLocal, - 0, kExprGetLocal, 1, kExprGetLocal, 2]) + module.addFunction("add", kSig_i_ii) + .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]); + module.addFunction("main", kSig_i_iii) + .addBody([kExprGetLocal, + 0, kExprGetLocal, 1, kExprGetLocal, 2, kExprCallIndirect, kArity2, 0]) .exportAs("main"); - module.appendToFunctionTable([0]); + module.appendToTable([0]); var instance = module.instantiate(); assertEquals(44, instance.exports.main(0, 11, 33)); @@ -102,8 +102,8 @@ var debug = false; (function DataSegmentTest() { var module = new WasmModuleBuilder(); module.addMemory(1, 1, false); - module.addFunction("load", [kAstI32, kAstI32]) - .addBody([kExprI32LoadMem, 0, 0, kExprGetLocal, 0]) + module.addFunction("load", kSig_i_i) + .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .exportAs("load"); module.addDataSegment(0, [9, 9, 9, 9], true); @@ -116,7 +116,7 @@ var debug = false; (function BasicTestWithUint8Array() { var module = new WasmModuleBuilder(); module.addMemory(1, 2, false); - module.addFunction("foo", [kAstI32]) + module.addFunction("foo", kSig_i) .addBody([kExprI8Const, 17]) .exportAs("blarg"); @@ -141,9 +141,9 @@ var debug = false; (function ImportTestTwoLevel() { var module = new WasmModuleBuilder(); - var index = module.addImportWithModule("mod", "print", [kAstStmt, kAstI32]); - module.addFunction("foo", [kAstStmt]) - .addBody([kExprCallImport, index, kExprI8Const, 19]) + var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32)); + module.addFunction("foo", kSig_v_v) + .addBody([kExprI8Const, 19, kExprCallImport, kArity1, index]) .exportAs("main"); var buffer = module.toBuffer(debug); diff --git a/deps/v8/test/mjsunit/wasm/trap-location.js b/deps/v8/test/mjsunit/wasm/trap-location.js new file mode 100644 index 0000000000..0440af9ccc --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/trap-location.js @@ -0,0 +1,78 @@ +// Copyright 2016 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-wasm + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +// Collect the Callsite objects instead of just a string: +Error.prepareStackTrace = function(error, frames) { + return frames; +}; + +var builder = new WasmModuleBuilder(); + +var sig_index = builder.addType(kSig_i_v) + +// Build a function to resemble this code: +// if (idx < 2) { +// return load(-2 / idx); +// } else if (idx == 2) { +// unreachable; +// } else { +// return call_indirect(idx); +// } +// There are four different traps which are triggered by different input values: +// (0) division by zero; (1) mem oob; (2) unreachable; (3) invalid call target +// Each of them also has a different location where it traps. +builder.addFunction("main", kSig_i_i) + .addBody([ + // offset 1 + kExprBlock, + kExprGetLocal, 0, + kExprI32Const, 2, + kExprI32LtU, + kExprIf, + // offset 8 + kExprI32Const, 0x7e /* -2 */, + kExprGetLocal, 0, + kExprI32DivU, + // offset 13 + kExprI32LoadMem, 0, 0, + kExprBr, 1, 1, + kExprEnd, + // offset 20 + kExprGetLocal, 0, + kExprI32Const, 2, + kExprI32Eq, + kExprIf, + kExprUnreachable, + kExprEnd, + // offset 28 + kExprGetLocal, 0, + kExprCallIndirect, kArity0, sig_index, + kExprEnd, + ]) + .exportAs("main"); + +var module = builder.instantiate(); + +function testWasmTrap(value, reason, position) { + try { + module.exports.main(value); + fail("expected wasm exception"); + } catch (e) { + assertEquals(kTrapMsgs[reason], e.message, "trap reason"); + assertEquals(3, e.stack.length, "number of frames"); + assertEquals(0, e.stack[0].getLineNumber(), "wasmFunctionIndex"); + assertEquals(position, e.stack[0].getPosition(), "position"); + } +} + +// The actual tests: +testWasmTrap(0, kTrapDivByZero, 12); +testWasmTrap(1, kTrapMemOutOfBounds, 13); +testWasmTrap(2, kTrapUnreachable, 26); +testWasmTrap(3, kTrapFuncInvalid, 30); diff --git a/deps/v8/test/mjsunit/wasm/unicode-validation.js b/deps/v8/test/mjsunit/wasm/unicode-validation.js new file mode 100644 index 0000000000..b2e4603087 --- /dev/null +++ b/deps/v8/test/mjsunit/wasm/unicode-validation.js @@ -0,0 +1,121 @@ +// Copyright 2016 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-wasm + +load("test/mjsunit/wasm/wasm-constants.js"); +load("test/mjsunit/wasm/wasm-module-builder.js"); + +function toByteArray(s) { + var arr = []; + for (var i = 0; i < s.length; ++i) { + arr.push(s.charCodeAt(i) & 0xff); + } + return arr; +} + +function toString(arr) { + if (typeof arr === "string") return arr; + var s = ""; + for (var b of arr) s += String.fromCharCode(b); + return s; +} + +function toUTF8(arr) { + if (typeof arr === "string" || arr === undefined) return arr; + return decodeURIComponent(escape(toString(arr))); +} + +function isValidUtf8(arr) { + if (typeof arr === "string" || arr === undefined) return true; + try { + var s = toUTF8(arr); + for (var i = 0; i < s.length; ++i) + if ((s.charCodeAt(i) & 0xfffe) == 0xfffe) + return false; + return true; + } catch (e) { + if (e instanceof URIError) return false; + throw e; + } +} + +function checkImportsAndExports(imported_module_name, imported_function_name, + internal_function_name, exported_function_name, shouldThrow) { + var builder = new WasmModuleBuilder(); + + builder.addImportWithModule(imported_module_name, imported_function_name, + kSig_v_v); + + builder.addFunction(internal_function_name, kSig_v_v) + .addBody([kExprCallImport, kArity0, 0]) + .exportAs(exported_function_name); + + // sanity check: does javascript agree with out shouldThrow annotation? + assertEquals(shouldThrow, + !isValidUtf8(imported_module_name) || + !isValidUtf8(imported_function_name) || + !isValidUtf8(exported_function_name), + "JavaScript does not agree with our shouldThrow expectation"); + + if (!shouldThrow) { + imported_module_name = toUTF8(imported_module_name); + imported_function_name = toUTF8(imported_function_name); + } + + var ffi = new Object(); + if (imported_function_name === undefined) { + ffi[imported_module_name] = function() { }; + } else { + ffi[imported_module_name] = new Object(); + ffi[imported_module_name][imported_function_name] = function() { }; + } + + var hasThrown = true; + try { + builder.instantiate(ffi); + hasThrown = false; + } catch (err) { + if (!shouldThrow) print(err); + assertTrue(shouldThrow, "Should not throw error on valid names"); + assertContains("UTF-8", err.toString()); + } + assertEquals(shouldThrow, hasThrown, + "Should throw validation error on invalid names"); +} + +function checkImportedModuleName(name, shouldThrow) { + checkImportsAndExports(name, "imp", "func", undefined, shouldThrow); +} + +function checkImportedFunctionName(name, shouldThrow) { + checkImportsAndExports("module", name, "func", "func", shouldThrow); +} + +function checkExportedFunctionName(name, shouldThrow) { + checkImportsAndExports("module", "func", "func", name, shouldThrow); +} + +function checkInternalFunctionName(name) { + checkImportsAndExports("module", "func", name, "func", false); +} + +function checkAll(name, shouldThrow) { + checkImportedModuleName(name, shouldThrow); + checkImportedFunctionName(name, shouldThrow); + checkExportedFunctionName(name, shouldThrow); + checkInternalFunctionName(name); +} + +checkAll("ascii", false); +checkAll("some math: (½)² = ¼", false); +checkAll("中国历史系列条目\n北", false); +checkAll(toByteArray("\xef\xb7\x8f"), false); +checkAll(toByteArray("a\xc2\x81\xe1\x80\xbf\xf1\x80\xa0\xbf"), false); +checkAll(toByteArray("\xff"), true); +checkAll(toByteArray("\xed\xa0\x8f"), true); // surrogate code points +checkAll(toByteArray("\xe0\x82\x80"), true); // overlong sequence +checkAll(toByteArray("\xf4\x90\x80\x80"), true); // beyond limit: U+110000 +checkAll(toByteArray("\xef\xbf\xbe"), true); // non-character; U+FFFE +checkAll(toByteArray("with\x00null"), false); diff --git a/deps/v8/test/mjsunit/wasm/unreachable.js b/deps/v8/test/mjsunit/wasm/unreachable.js index 3e2dffb4e9..d77b53ea53 100644 --- a/deps/v8/test/mjsunit/wasm/unreachable.js +++ b/deps/v8/test/mjsunit/wasm/unreachable.js @@ -9,7 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var main = (function () { var builder = new WasmModuleBuilder(); - builder.addFunction("main", [kAstStmt]) + builder.addFunction("main", kSig_v_v) .addBody([kExprUnreachable]) .exportAs("main"); @@ -23,4 +23,4 @@ try { print("correctly caught: " + e); exception = e; } -assertEquals("unreachable", exception); +assertEquals("unreachable", exception.message); diff --git a/deps/v8/test/mjsunit/wasm/verify-function-simple.js b/deps/v8/test/mjsunit/wasm/verify-function-simple.js index aa5c67683e..31c23a6b69 100644 --- a/deps/v8/test/mjsunit/wasm/verify-function-simple.js +++ b/deps/v8/test/mjsunit/wasm/verify-function-simple.js @@ -8,9 +8,9 @@ load("test/mjsunit/wasm/wasm-constants.js"); try { var data = bytes( - 0, kAstStmt, // signature - kDeclNoLocals, // -- - kExprNop // body + kWasmFunctionTypeForm, 0, kAstStmt, // signature + kDeclNoLocals, // -- + kExprNop // body ); Wasm.verifyFunction(data); @@ -23,9 +23,9 @@ try { var threw = false; try { var data = bytes( - 0, kAstI32, // signature - kDeclNoLocals, // -- - kExprBlock, 2, kExprNop, kExprNop // body + kWasmFunctionTypeForm, 0, 1, kAstI32, // signature + kDeclNoLocals, // -- + kExprBlock, kExprNop, kExprNop, kExprEnd // body ); Wasm.verifyFunction(data); diff --git a/deps/v8/test/mjsunit/wasm/wasm-constants.js b/deps/v8/test/mjsunit/wasm/wasm-constants.js index cc620bb458..04ac0c9592 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-constants.js +++ b/deps/v8/test/mjsunit/wasm/wasm-constants.js @@ -21,7 +21,7 @@ var kWasmH1 = 0x61; var kWasmH2 = 0x73; var kWasmH3 = 0x6d; -var kWasmV0 = 10; +var kWasmV0 = 11; var kWasmV1 = 0; var kWasmV2 = 0; var kWasmV3 = 0; @@ -52,23 +52,29 @@ var kDeclNoLocals = 0; // Section declaration constants var kDeclMemory = 0x00; -var kDeclSignatures = 0x01; +var kDeclTypes = 0x01; var kDeclFunctions = 0x02; var kDeclGlobals = 0x03; -var kDeclDataSegments = 0x04; -var kDeclFunctionTable = 0x05; +var kDeclData = 0x04; +var kDeclTable = 0x05; var kDeclEnd = 0x06; -var kDeclStartFunction = 0x07; -var kDeclImportTable = 0x08; -var kDeclExportTable = 0x09; -var kDeclFunctionSignatures = 0x0a; -var kDeclFunctionBodies = 0x0b; +var kDeclStart = 0x07; +var kDeclImports = 0x08; +var kDeclExports = 0x09; +var kDeclFunctions = 0x0a; +var kDeclCode = 0x0b; var kDeclNames = 0x0c; +var kArity0 = 0; +var kArity1 = 1; +var kArity2 = 2; +var kArity3 = 3; +var kWasmFunctionTypeForm = 0x40; + var section_names = [ - "memory", "signatures", "functions", "globals", "data_segments", - "function_table", "end", "start_function", "import_table", "export_table", - "function_signatures", "function_bodies", "names"]; + "memory", "type", "old_function", "global", "data", + "table", "end", "start", "import", "export", + "function", "code", "name"]; // Function declaration flags var kDeclFunctionName = 0x01; @@ -83,31 +89,73 @@ var kAstI64 = 2; var kAstF32 = 3; var kAstF64 = 4; +// Useful signatures +var kSig_i = makeSig([], [kAstI32]); +var kSig_d = makeSig([], [kAstF64]); +var kSig_i_i = makeSig([kAstI32], [kAstI32]); +var kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]); +var kSig_i_iii = makeSig([kAstI32, kAstI32, kAstI32], [kAstI32]); +var kSig_d_dd = makeSig([kAstF64, kAstF64], [kAstF64]); +var kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]); +var kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]); +var kSig_v_v = makeSig([], []); +var kSig_i_v = makeSig([], [kAstI32]); +var kSig_v_i = makeSig([kAstI32], []); +var kSig_v_ii = makeSig([kAstI32, kAstI32], []); +var kSig_v_iii = makeSig([kAstI32, kAstI32, kAstI32], []); +var kSig_v_d = makeSig([kAstF64], []); +var kSig_v_dd = makeSig([kAstF64, kAstF64], []); + +function makeSig(params, results) { + return {params: params, results: results}; +} + +function makeSig_v_x(x) { + return makeSig([x], []); +} + +function makeSig_v_xx(x) { + return makeSig([x, x], []); +} + +function makeSig_r_v(r) { + return makeSig([], [r]); +} + +function makeSig_r_x(r, x) { + return makeSig([x], [r]); +} + +function makeSig_r_xx(r, x) { + return makeSig([x, x], [r]); +} + // Opcodes var kExprNop = 0x00; var kExprBlock = 0x01; var kExprLoop = 0x02; var kExprIf = 0x03; -var kExprIfElse = 0x04; +var kExprElse = 0x04; var kExprSelect = 0x05; var kExprBr = 0x06; var kExprBrIf = 0x07; -var kExprTableSwitch = 0x08; -var kExprReturn = 0x14; -var kExprUnreachable = 0x15; +var kExprBrTable = 0x08; +var kExprReturn = 0x09; +var kExprUnreachable = 0x0a; +var kExprEnd = 0x0f; -var kExprI8Const = 0x09; -var kExprI32Const = 0x0a; -var kExprI64Const = 0x0b; -var kExprF64Const = 0x0c; -var kExprF32Const = 0x0d; -var kExprGetLocal = 0x0e; -var kExprSetLocal = 0x0f; -var kExprLoadGlobal = 0x10; -var kExprStoreGlobal = 0x11; -var kExprCallFunction = 0x12; -var kExprCallIndirect = 0x13; -var kExprCallImport = 0x1F; +var kExprI32Const = 0x10; +var kExprI64Const = 0x11; +var kExprF64Const = 0x12; +var kExprF32Const = 0x13; +var kExprGetLocal = 0x14; +var kExprSetLocal = 0x15; +var kExprCallFunction = 0x16; +var kExprCallIndirect = 0x17; +var kExprCallImport = 0x18; +var kExprI8Const = 0xcb; +var kExprGetGlobal = 0xbb; +var kExprSetGlobal = 0xbc; var kExprI32LoadMem8S = 0x20; var kExprI32LoadMem8U = 0x21; @@ -268,6 +316,7 @@ var kTrapRemByZero = 4; var kTrapFloatUnrepresentable = 5; var kTrapFuncInvalid = 6; var kTrapFuncSigMismatch = 7; +var kTrapInvalidIndex = 8; var kTrapMsgs = [ "unreachable", @@ -277,7 +326,8 @@ var kTrapMsgs = [ "remainder by zero", "integer result unrepresentable", "invalid function", - "function signature mismatch" + "function signature mismatch", + "invalid index into function table" ]; function assertTraps(trap, code) { @@ -290,8 +340,8 @@ function assertTraps(trap, code) { } threwException = false; } catch (e) { - assertEquals("string", typeof e); - assertEquals(kTrapMsgs[trap], e); + assertEquals("object", typeof e); + assertEquals(kTrapMsgs[trap], e.message); // Success. return; } diff --git a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js index e1d996338c..fecd164b56 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-module-builder.js +++ b/deps/v8/test/mjsunit/wasm/wasm-module-builder.js @@ -2,334 +2,364 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -function WasmFunctionBuilder(name, sig_index) { +class Binary extends Array { + emit_u8(val) { + this.push(val); + } + + emit_u16(val) { + this.push(val & 0xff); + this.push((val >> 8) & 0xff); + } + + emit_u32(val) { + this.push(val & 0xff); + this.push((val >> 8) & 0xff); + this.push((val >> 16) & 0xff); + this.push((val >> 24) & 0xff); + } + + emit_varint(val) { + while (true) { + let v = val & 0xff; + val = val >>> 7; + if (val == 0) { + this.push(v); + break; + } + this.push(v | 0x80); + } + } + + emit_bytes(data) { + for (let i = 0; i < data.length; i++) { + this.push(data[i] & 0xff); + } + } + + emit_string(string) { + // When testing illegal names, we pass a byte array directly. + if (string instanceof Array) { + this.emit_varint(string.length); + this.emit_bytes(string); + return; + } + + // This is the hacky way to convert a JavaScript string to a UTF8 encoded + // string only containing single-byte characters. + let string_utf8 = unescape(encodeURIComponent(string)); + this.emit_varint(string_utf8.length); + for (let i = 0; i < string_utf8.length; i++) { + this.emit_u8(string_utf8.charCodeAt(i)); + } + } + + emit_header() { + this.push(kWasmH0, kWasmH1, kWasmH2, kWasmH3, + kWasmV0, kWasmV1, kWasmV2, kWasmV3); + } + + emit_section(section_code, content_generator) { + // Emit section name. + this.emit_string(section_names[section_code]); + // Emit the section to a temporary buffer: its full length isn't know yet. + let section = new Binary; + content_generator(section); + // Emit section length. + this.emit_varint(section.length); + // Copy the temporary buffer. + this.push(...section); + } +} + +class WasmFunctionBuilder { + constructor(name, type_index) { this.name = name; - this.sig_index = sig_index; + this.type_index = type_index; this.exports = []; -} + } -WasmFunctionBuilder.prototype.exportAs = function(name) { + exportAs(name) { this.exports.push(name); return this; -} + } -WasmFunctionBuilder.prototype.exportFunc = function() { - this.exports.push(this.name); - return this; -} + exportFunc() { + this.exports.push(this.name); + return this; + } -WasmFunctionBuilder.prototype.addBody = function(body) { + addBody(body) { this.body = body; return this; -} + } -WasmFunctionBuilder.prototype.addLocals = function(locals) { + addLocals(locals) { this.locals = locals; return this; + } } -function WasmModuleBuilder() { - this.signatures = []; +class WasmModuleBuilder { + constructor() { + this.types = []; this.imports = []; this.functions = []; this.exports = []; - this.function_table = []; - this.data_segments = []; + this.table = []; + this.segments = []; this.explicit = []; + this.pad = null; return this; -} + } -WasmModuleBuilder.prototype.addStart = function(start_index) { + addStart(start_index) { this.start_index = start_index; -} + } -WasmModuleBuilder.prototype.addMemory = function(min, max, exp) { + addMemory(min, max, exp) { this.memory = {min: min, max: max, exp: exp}; return this; -} + } -WasmModuleBuilder.prototype.addExplicitSection = function(bytes) { - this.explicit.push(bytes); - return this; -} + addPadFunctionTable(size) { + this.pad = size; + return this; + } -// Add a signature; format is [rettype, param0, param1, ...] -WasmModuleBuilder.prototype.addSignature = function(sig) { - // TODO: canonicalize signatures? - this.signatures.push(sig); - return this.signatures.length - 1; -} + addExplicitSection(bytes) { + this.explicit.push(bytes); + return this; + } -WasmModuleBuilder.prototype.addFunction = function(name, sig) { - var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); - var func = new WasmFunctionBuilder(name, sig_index); + addType(type) { + // TODO: canonicalize types? + this.types.push(type); + return this.types.length - 1; + } + + addFunction(name, type) { + let type_index = (typeof type) == "number" ? type : this.addType(type); + let func = new WasmFunctionBuilder(name, type_index); func.index = this.functions.length; this.functions.push(func); return func; -} + } -WasmModuleBuilder.prototype.addImportWithModule = function(module, name, sig) { - var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); - this.imports.push({module: module, name: name, sig_index: sig_index}); - return this.imports.length - 1; -} + addImportWithModule(module, name, type) { + let type_index = (typeof type) == "number" ? type : this.addType(type); + this.imports.push({module: module, name: name, type: type_index}); + return this.imports.length - 1; + } -WasmModuleBuilder.prototype.addImport = function(name, sig) { - var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); - this.imports.push({module: name, name: undefined, sig_index: sig_index}); - return this.imports.length - 1; -} + addImport(name, type) { + return this.addImportWithModule(name, undefined, type); + } -WasmModuleBuilder.prototype.addDataSegment = function(addr, data, init) { - this.data_segments.push({addr: addr, data: data, init: init}); - return this.data_segments.length - 1; -} + addDataSegment(addr, data, init) { + this.segments.push({addr: addr, data: data, init: init}); + return this.segments.length - 1; + } -WasmModuleBuilder.prototype.appendToFunctionTable = function(array) { - this.function_table = this.function_table.concat(array); + appendToTable(array) { + this.table.push(...array); return this; -} - -function emit_u8(bytes, val) { - bytes.push(val & 0xff); -} - -function emit_u16(bytes, val) { - bytes.push(val & 0xff); - bytes.push((val >> 8) & 0xff); -} - -function emit_u32(bytes, val) { - bytes.push(val & 0xff); - bytes.push((val >> 8) & 0xff); - bytes.push((val >> 16) & 0xff); - bytes.push((val >> 24) & 0xff); -} + } -function emit_string(bytes, string) { - emit_varint(bytes, string.length); - for (var i = 0; i < string.length; i++) { - emit_u8(bytes, string.charCodeAt(i)); + toArray(debug) { + let binary = new Binary; + let wasm = this; + + // Add header + binary.emit_header(); + + // Add type section + if (wasm.types.length > 0) { + if (debug) print("emitting types @ " + binary.length); + binary.emit_section(kDeclTypes, section => { + section.emit_varint(wasm.types.length); + for (let type of wasm.types) { + section.emit_u8(kWasmFunctionTypeForm); + section.emit_varint(type.params.length); + for (let param of type.params) { + section.emit_u8(param); + } + section.emit_varint(type.results.length); + for (let result of type.results) { + section.emit_u8(result); + } + } + }); } -} -function emit_varint(bytes, val) { - while (true) { - var v = val & 0xff; - val = val >>> 7; - if (val == 0) { - bytes.push(v); - break; + // Add imports section + if (wasm.imports.length > 0) { + if (debug) print("emitting imports @ " + binary.length); + binary.emit_section(kDeclImports, section => { + section.emit_varint(wasm.imports.length); + for (let imp of wasm.imports) { + section.emit_varint(imp.type); + section.emit_string(imp.module); + section.emit_string(imp.name || ''); } - bytes.push(v | 0x80); + }); } -} - -function emit_bytes(bytes, data) { - for (var i = 0; i < data.length; i++) { - bytes.push(data[i] & 0xff); - } -} - -function emit_section(bytes, section_code, content_generator) { - // Start the section in a temporary buffer: its full length isn't know yet. - var tmp_bytes = []; - emit_string(tmp_bytes, section_names[section_code]); - content_generator(tmp_bytes); - // Now that we know the section length, emit it and copy the section. - emit_varint(bytes, tmp_bytes.length); - Array.prototype.push.apply(bytes, tmp_bytes); -} -WasmModuleBuilder.prototype.toArray = function(debug) { - // Add header bytes - var bytes = []; - bytes = bytes.concat([kWasmH0, kWasmH1, kWasmH2, kWasmH3, - kWasmV0, kWasmV1, kWasmV2, kWasmV3]); + // Add functions declarations + let has_names = false; + let names = false; + let exports = 0; + if (wasm.functions.length > 0) { + if (debug) print("emitting function decls @ " + binary.length); + binary.emit_section(kDeclFunctions, section => { + section.emit_varint(wasm.functions.length); + for (let func of wasm.functions) { + has_names = has_names || (func.name != undefined && + func.name.length > 0); + exports += func.exports.length; + section.emit_varint(func.type_index); + } + }); + } - var wasm = this; + // Add table. + if (wasm.table.length > 0) { + if (debug) print("emitting table @ " + binary.length); + binary.emit_section(kDeclTable, section => { + section.emit_varint(wasm.table.length); + if (wasm.pad !== null) { + if (debug) print("emitting table padding @ " + binary.length); + section.emit_varint(wasm.pad); + } + for (let index of wasm.table) { + section.emit_varint(index); + } + }); + } // Add memory section if (wasm.memory != undefined) { - if (debug) print("emitting memory @ " + bytes.length); - emit_section(bytes, kDeclMemory, function(bytes) { - emit_varint(bytes, wasm.memory.min); - emit_varint(bytes, wasm.memory.max); - emit_u8(bytes, wasm.memory.exp ? 1 : 0); - }); + if (debug) print("emitting memory @ " + binary.length); + binary.emit_section(kDeclMemory, section => { + section.emit_varint(wasm.memory.min); + section.emit_varint(wasm.memory.max); + section.emit_u8(wasm.memory.exp ? 1 : 0); + }); } - // Add signatures section - if (wasm.signatures.length > 0) { - if (debug) print("emitting signatures @ " + bytes.length); - emit_section(bytes, kDeclSignatures, function(bytes) { - emit_varint(bytes, wasm.signatures.length); - for (sig of wasm.signatures) { - var params = sig.length - 1; - emit_varint(bytes, params); - for (var j = 0; j < sig.length; j++) { - emit_u8(bytes, sig[j]); - } - } - }); + + // Add export table. + if (exports > 0) { + if (debug) print("emitting exports @ " + binary.length); + binary.emit_section(kDeclExports, section => { + section.emit_varint(exports); + for (let func of wasm.functions) { + for (let exp of func.exports) { + section.emit_varint(func.index); + section.emit_string(exp); + } + } + }); } - // Add imports section - if (wasm.imports.length > 0) { - if (debug) print("emitting imports @ " + bytes.length); - emit_section(bytes, kDeclImportTable, function(bytes) { - emit_varint(bytes, wasm.imports.length); - for (imp of wasm.imports) { - emit_varint(bytes, imp.sig_index); - emit_string(bytes, imp.module); - emit_string(bytes, imp.name || ''); - } - }); + // Add start function section. + if (wasm.start_index != undefined) { + if (debug) print("emitting start function @ " + binary.length); + binary.emit_section(kDeclStart, section => { + section.emit_varint(wasm.start_index); + }); } - // Add functions section - var names = false; - var exports = 0; + // Add function bodies. if (wasm.functions.length > 0) { - var has_names = false; - - // emit function signatures - if (debug) print("emitting function sigs @ " + bytes.length); - emit_section(bytes, kDeclFunctionSignatures, function(bytes) { - emit_varint(bytes, wasm.functions.length); - for (func of wasm.functions) { - has_names = has_names || (func.name != undefined && - func.name.length > 0); - exports += func.exports.length; - - emit_varint(bytes, func.sig_index); + // emit function bodies + if (debug) print("emitting code @ " + binary.length); + binary.emit_section(kDeclCode, section => { + section.emit_varint(wasm.functions.length); + for (let func of wasm.functions) { + // Function body length will be patched later. + let local_decls = []; + let l = func.locals; + if (l != undefined) { + let local_decls_count = 0; + if (l.i32_count > 0) { + local_decls.push({count: l.i32_count, type: kAstI32}); } - }); - - // emit function bodies - if (debug) print("emitting function bodies @ " + bytes.length); - emit_section(bytes, kDeclFunctionBodies, function(bytes) { - emit_varint(bytes, wasm.functions.length); - for (func of wasm.functions) { - // Function body length will be patched later. - var local_decls = []; - var l = func.locals; - if (l != undefined) { - var local_decls_count = 0; - if (l.i32_count > 0) { - local_decls.push({count: l.i32_count, type: kAstI32}); - } - if (l.i64_count > 0) { - local_decls.push({count: l.i64_count, type: kAstI64}); - } - if (l.f32_count > 0) { - local_decls.push({count: l.f32_count, type: kAstF32}); - } - if (l.f64_count > 0) { - local_decls.push({count: l.f64_count, type: kAstF64}); - } - } - var header = new Array(); - - emit_varint(header, local_decls.length); - for (decl of local_decls) { - emit_varint(header, decl.count); - emit_u8(header, decl.type); - } - - emit_varint(bytes, header.length + func.body.length); - emit_bytes(bytes, header); - emit_bytes(bytes, func.body); + if (l.i64_count > 0) { + local_decls.push({count: l.i64_count, type: kAstI64}); } - }); - } - - // emit function names - if (has_names) { - if (debug) print("emitting names @ " + bytes.length); - emit_section(bytes, kDeclNames, function(bytes) { - emit_varint(bytes, wasm.functions.length); - for (func of wasm.functions) { - var name = func.name == undefined ? "" : func.name; - emit_string(bytes, name); - emit_u8(bytes, 0); // local names count == 0 + if (l.f32_count > 0) { + local_decls.push({count: l.f32_count, type: kAstF32}); } - }); - } - - // Add start function section. - if (wasm.start_index != undefined) { - if (debug) print("emitting start function @ " + bytes.length); - emit_section(bytes, kDeclStartFunction, function(bytes) { - emit_varint(bytes, wasm.start_index); - }); - } - - if (wasm.function_table.length > 0) { - if (debug) print("emitting function table @ " + bytes.length); - emit_section(bytes, kDeclFunctionTable, function(bytes) { - emit_varint(bytes, wasm.function_table.length); - for (index of wasm.function_table) { - emit_varint(bytes, index); + if (l.f64_count > 0) { + local_decls.push({count: l.f64_count, type: kAstF64}); } - }); + } + + let header = new Binary; + header.emit_varint(local_decls.length); + for (let decl of local_decls) { + header.emit_varint(decl.count); + header.emit_u8(decl.type); + } + + section.emit_varint(header.length + func.body.length); + section.emit_bytes(header); + section.emit_bytes(func.body); + } + }); } - if (exports > 0) { - if (debug) print("emitting exports @ " + bytes.length); - emit_section(bytes, kDeclExportTable, function(bytes) { - emit_varint(bytes, exports); - for (func of wasm.functions) { - for (exp of func.exports) { - emit_varint(bytes, func.index); - emit_string(bytes, exp); - } - } - }); + // Add data segments. + if (wasm.segments.length > 0) { + if (debug) print("emitting data segments @ " + binary.length); + binary.emit_section(kDeclData, section => { + section.emit_varint(wasm.segments.length); + for (let seg of wasm.segments) { + section.emit_varint(seg.addr); + section.emit_varint(seg.data.length); + section.emit_bytes(seg.data); + } + }); } - if (wasm.data_segments.length > 0) { - if (debug) print("emitting data segments @ " + bytes.length); - emit_section(bytes, kDeclDataSegments, function(bytes) { - emit_varint(bytes, wasm.data_segments.length); - for (seg of wasm.data_segments) { - emit_varint(bytes, seg.addr); - emit_varint(bytes, seg.data.length); - emit_bytes(bytes, seg.data); - } - }); + // Add any explicitly added sections + for (let exp of wasm.explicit) { + if (debug) print("emitting explicit @ " + binary.length); + binary.emit_bytes(exp); } - // Emit any explicitly added sections - for (exp of wasm.explicit) { - if (debug) print("emitting explicit @ " + bytes.length); - emit_bytes(bytes, exp); + // Add function names. + if (has_names) { + if (debug) print("emitting names @ " + binary.length); + binary.emit_section(kDeclNames, section => { + section.emit_varint(wasm.functions.length); + for (let func of wasm.functions) { + var name = func.name == undefined ? "" : func.name; + section.emit_string(name); + section.emit_u8(0); // local names count == 0 + } + }); } - // End the module. - if (debug) print("emitting end @ " + bytes.length); - emit_section(bytes, kDeclEnd, function(bytes) {}); - - return bytes; -} + return binary; + } -WasmModuleBuilder.prototype.toBuffer = function(debug) { - var bytes = this.toArray(debug); - var buffer = new ArrayBuffer(bytes.length); - var view = new Uint8Array(buffer); - for (var i = 0; i < bytes.length; i++) { - var val = bytes[i]; - if ((typeof val) == "string") val = val.charCodeAt(0); - view[i] = val | 0; + toBuffer(debug) { + let bytes = this.toArray(debug); + let buffer = new ArrayBuffer(bytes.length); + let view = new Uint8Array(buffer); + for (let i = 0; i < bytes.length; i++) { + let val = bytes[i]; + if ((typeof val) == "string") val = val.charCodeAt(0); + view[i] = val | 0; } return buffer; -} + } -WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { - var buffer = this.toBuffer(); - if (memory != undefined) { - return Wasm.instantiateModule(buffer, ffi, memory); - } else { - return Wasm.instantiateModule(buffer, ffi); - } + instantiate(...args) { + let module = new WebAssembly.Module(this.toBuffer()); + let instance = new WebAssembly.Instance(module, ...args); + return instance; + } } diff --git a/deps/v8/test/mjsunit/wasm/wasm-object-api.js b/deps/v8/test/mjsunit/wasm/wasm-object-api.js index 2f25c66fce..4e1df8cf14 100644 --- a/deps/v8/test/mjsunit/wasm/wasm-object-api.js +++ b/deps/v8/test/mjsunit/wasm/wasm-object-api.js @@ -9,4 +9,9 @@ assertFalse(undefined == Wasm); assertEquals("function", typeof Wasm.verifyModule); assertEquals("function", typeof Wasm.verifyFunction); assertEquals("function", typeof Wasm.instantiateModule); -assertEquals("function", typeof Wasm.instantiateModuleFromAsm); +assertFalse(undefined == Wasm.experimentalVersion); + +assertEquals('object', typeof WebAssembly); +assertEquals('function', typeof WebAssembly.Module); +assertEquals('function', typeof WebAssembly.Instance); +assertEquals('function', typeof WebAssembly.compile); |