diff --git a/test/mjsunit/es6/array-concat-arraylike-string-length.js b/test/mjsunit/es6/array-concat-arraylike-string-length.js index 471dcb99eb..0263113019 100644 --- a/test/mjsunit/es6/array-concat-arraylike-string-length.js +++ b/test/mjsunit/es6/array-concat-arraylike-string-length.js @@ -12,6 +12,6 @@ var obj = { obj[Symbol.isConcatSpreadable] = true; var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" }; var arr = ["X", "Y", "Z"]; -assertEquals([void 0, "A", void 0, "B", void 0, "C", +assertEquals([, "A", , "B", , "C", { "length": 3, "0": "0", "1": "1", "2": "2" }, "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr)); diff --git a/test/mjsunit/es6/array-concat-arraylike.js b/test/mjsunit/es6/array-concat-arraylike.js index 0ad3eb5293..371d0f6e21 100644 --- a/test/mjsunit/es6/array-concat-arraylike.js +++ b/test/mjsunit/es6/array-concat-arraylike.js @@ -12,6 +12,6 @@ var obj = { obj[Symbol.isConcatSpreadable] = true; var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" }; var arr = ["X", "Y", "Z"]; -assertEquals([void 0, "A", void 0, "B", void 0, "C", +assertEquals([, "A", , "B", , "C", { "length": 3, "0": "0", "1": "1", "2": "2" }, "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr)); diff --git a/test/mjsunit/es6/array-concat-holey-array.js b/test/mjsunit/es6/array-concat-holey-array.js index 31c2ba1bd9..19989b42c7 100644 --- a/test/mjsunit/es6/array-concat-holey-array.js +++ b/test/mjsunit/es6/array-concat-holey-array.js @@ -7,5 +7,5 @@ var arr = []; arr[4] = "Item 4"; arr[8] = "Item 8"; var arr2 = [".", "!", "?"]; -assertEquals([void 0, void 0, void 0, void 0, "Item 4", void 0, void 0, - void 0, "Item 8", ".", "!", "?"], arr.concat(arr2)); +assertEquals( + [, , , , 'Item 4', , , , 'Item 8', '.', '!', '?'], arr.concat(arr2)); diff --git a/test/mjsunit/es6/array-concat-sloppy-arguments-holey.js b/test/mjsunit/es6/array-concat-sloppy-arguments-holey.js index ac160fc1f3..711a450bdf 100644 --- a/test/mjsunit/es6/array-concat-sloppy-arguments-holey.js +++ b/test/mjsunit/es6/array-concat-sloppy-arguments-holey.js @@ -5,4 +5,4 @@ var args = (function(a) { return arguments; })(1,2,3); delete args[1]; args[Symbol.isConcatSpreadable] = true; -assertEquals([1, void 0, 3, 1, void 0, 3], [].concat(args, args)); +assertEquals([1, , 3, 1, , 3], [].concat(args, args)); diff --git a/test/mjsunit/es6/array-concat-sloppy-arguments-with-dupes.js b/test/mjsunit/es6/array-concat-sloppy-arguments-with-dupes.js index 4634cac705..fed914780a 100644 --- a/test/mjsunit/es6/array-concat-sloppy-arguments-with-dupes.js +++ b/test/mjsunit/es6/array-concat-sloppy-arguments-with-dupes.js @@ -7,4 +7,4 @@ args[Symbol.isConcatSpreadable] = true; assertEquals([1, 2, 3, 1, 2, 3], [].concat(args, args)); Object.defineProperty(args, "length", { value: 6 }); -assertEquals([1, 2, 3, void 0, void 0, void 0], [].concat(args)); +assertEquals([1, 2, 3, , , ,], [].concat(args)); diff --git a/test/mjsunit/es6/array-concat-sloppy-arguments.js b/test/mjsunit/es6/array-concat-sloppy-arguments.js index b77833f885..346d07e870 100644 --- a/test/mjsunit/es6/array-concat-sloppy-arguments.js +++ b/test/mjsunit/es6/array-concat-sloppy-arguments.js @@ -7,4 +7,4 @@ args[Symbol.isConcatSpreadable] = true; assertEquals([1, 2, 3, 1, 2, 3], [].concat(args, args)); Object.defineProperty(args, "length", { value: 6 }); -assertEquals([1, 2, 3, void 0, void 0, void 0], [].concat(args)); +assertEquals([1, 2, 3, , ,, ], [].concat(args)); diff --git a/test/mjsunit/es6/array-concat-spreadable-function.js b/test/mjsunit/es6/array-concat-spreadable-function.js index 9b64fc63aa..1fea92b7e2 100644 --- a/test/mjsunit/es6/array-concat-spreadable-function.js +++ b/test/mjsunit/es6/array-concat-spreadable-function.js @@ -14,7 +14,7 @@ assertEquals([1, 2, 3], [].concat(fn)); Function.prototype[Symbol.isConcatSpreadable] = true; // Functions may be concat-spreadable -assertEquals([void 0, void 0, void 0], [].concat(function(a,b,c) {})); +assertEquals(new Array(3), [].concat(function(a,b,c) {})); Function.prototype[0] = 1; Function.prototype[1] = 2; Function.prototype[2] = 3; diff --git a/test/mjsunit/es6/array-concat-spreadable-nonarraylike-proxy.js b/test/mjsunit/es6/array-concat-spreadable-nonarraylike-proxy.js index ecbe4488d7..f32c0e1d9b 100644 --- a/test/mjsunit/es6/array-concat-spreadable-nonarraylike-proxy.js +++ b/test/mjsunit/es6/array-concat-spreadable-nonarraylike-proxy.js @@ -36,7 +36,7 @@ assertEquals(["get", target, "length", obj], log[1]); target.length = 3; log.length = 0; -assertEquals(["a", "b", undefined], [].concat(obj)); +assertEquals(["a", "b", ,], [].concat(obj)); assertEquals(7, log.length); for (var i in log) assertSame(target, log[i][1]); assertEquals(["get", target, Symbol.isConcatSpreadable, obj], log[0]); @@ -48,7 +48,7 @@ assertEquals(["get", target, "1", obj], log[5]); assertEquals(["has", target, "2"], log[6]); log.length = 0; -assertEquals(["a", "b", undefined], Array.prototype.concat.apply(obj)); +assertEquals(["a", "b", ,], Array.prototype.concat.apply(obj)); assertEquals(7, log.length); for (var i in log) assertSame(target, log[i][1]); assertEquals(["get", target, Symbol.isConcatSpreadable, obj], log[0]); diff --git a/test/mjsunit/es6/array-concat-spreadable-regexp.js b/test/mjsunit/es6/array-concat-spreadable-regexp.js index 73a61e4d88..54b9372caf 100644 --- a/test/mjsunit/es6/array-concat-spreadable-regexp.js +++ b/test/mjsunit/es6/array-concat-spreadable-regexp.js @@ -16,7 +16,7 @@ assertEquals([1, 2, 3], [].concat(re)); RegExp.prototype[Symbol.isConcatSpreadable] = true; RegExp.prototype.length = 3; -assertEquals([void 0, void 0, void 0], [].concat(/abc/)); +assertEquals(new Array(3), [].concat(/abc/)); RegExp.prototype[0] = 1; RegExp.prototype[1] = 2; RegExp.prototype[2] = 3; diff --git a/test/mjsunit/es6/array-concat-spreadable-sparse-object.js b/test/mjsunit/es6/array-concat-spreadable-sparse-object.js index c10b002403..5227e7d6b7 100644 --- a/test/mjsunit/es6/array-concat-spreadable-sparse-object.js +++ b/test/mjsunit/es6/array-concat-spreadable-sparse-object.js @@ -5,7 +5,7 @@ "use strict"; var obj = { length: 5 }; obj[Symbol.isConcatSpreadable] = true; -assertEquals([void 0, void 0, void 0, void 0, void 0], [].concat(obj)); +assertEquals(new Array(5), [].concat(obj)); obj.length = 4000; assertEquals(new Array(4000), [].concat(obj)); diff --git a/test/mjsunit/es6/array-concat-strict-arguments.js b/test/mjsunit/es6/array-concat-strict-arguments.js index 4180a94a2e..106883168c 100644 --- a/test/mjsunit/es6/array-concat-strict-arguments.js +++ b/test/mjsunit/es6/array-concat-strict-arguments.js @@ -7,4 +7,4 @@ args[Symbol.isConcatSpreadable] = true; assertEquals([1, 2, 3, 1, 2, 3], [].concat(args, args)); Object.defineProperty(args, "length", { value: 6 }); -assertEquals([1, 2, 3, void 0, void 0, void 0], [].concat(args)); +assertEquals([1, 2, 3, , , ,], [].concat(args)); diff --git a/test/mjsunit/es6/array-spread-holey.js b/test/mjsunit/es6/array-spread-holey.js index 7d95e51b29..bea58e4952 100644 --- a/test/mjsunit/es6/array-spread-holey.js +++ b/test/mjsunit/es6/array-spread-holey.js @@ -6,7 +6,7 @@ var a = [, 2]; -assertEquals([, 2], [...a]); +assertEquals([undefined, 2], [...a]); assertTrue([...a].hasOwnProperty(0)); assertTrue([2, ...a].hasOwnProperty(1)); diff --git a/test/mjsunit/harmony/array-prototype-groupby.js b/test/mjsunit/harmony/array-prototype-groupby.js index cd6496f944..fdabfe831e 100644 --- a/test/mjsunit/harmony/array-prototype-groupby.js +++ b/test/mjsunit/harmony/array-prototype-groupby.js @@ -142,7 +142,7 @@ var group = () => { } assertEquals(group(), [ - ['undefined', [,]], + ['undefined', [undefined]], ]); array.__proto__.push(6); diff --git a/test/mjsunit/harmony/array-prototype-groupbytomap.js b/test/mjsunit/harmony/array-prototype-groupbytomap.js index 265e84181f..84ac13cf8a 100644 --- a/test/mjsunit/harmony/array-prototype-groupbytomap.js +++ b/test/mjsunit/harmony/array-prototype-groupbytomap.js @@ -147,7 +147,7 @@ var groupToMap = () => { } assertEquals(groupToMap(), [ - [undefined, [,]], + [undefined, [undefined]], ]); array.__proto__.push(6); assertEquals(groupToMap(), [ diff --git a/test/mjsunit/harmony/array-to-sorted.js b/test/mjsunit/harmony/array-to-sorted.js index e5ea813fb8..d32523a7fa 100644 --- a/test/mjsunit/harmony/array-to-sorted.js +++ b/test/mjsunit/harmony/array-to-sorted.js @@ -7,32 +7,39 @@ assertEquals(1, Array.prototype.toSorted.length); assertEquals("toSorted", Array.prototype.toSorted.name); -function TerribleCopy(input) { +function TerribleCopy(input, fillHoles) { let copy; if (Array.isArray(input)) { - copy = [...input]; + copy = new Array(input.length); } else { copy = { length: input.length }; - for (let i = 0; i < input.length; i++) { + } + for (let i = 0; i < input.length; ++i) { + if (i in input) { copy[i] = input[i]; + } else if (fillHoles) { + copy[i] = undefined; } } return copy; } function AssertToSortedAndSortSameResult(input, ...args) { - const orig = TerribleCopy(input); + const orig = TerribleCopy(input, false); const s = Array.prototype.toSorted.apply(input, args); - const copy = TerribleCopy(input); + const copy = TerribleCopy(input, true); Array.prototype.sort.apply(copy, args); // The in-place sorted version should be pairwise equal to the toSorted, - // modulo being an actual Array if the input is generic. + // modulo being an actual Array if the input is generic, and holes should + // be filled with undefined. if (Array.isArray(input)) { assertEquals(copy, s); } else { assertEquals(copy.length, s.length); for (let i = 0; i < copy.length; i++) { + assertTrue(i in copy); + assertTrue(i in s); assertEquals(copy[i], s[i]); } } diff --git a/test/mjsunit/keyed-store-array-literal.js b/test/mjsunit/keyed-store-array-literal.js index 000385b9d3..d2bf5beec6 100644 --- a/test/mjsunit/keyed-store-array-literal.js +++ b/test/mjsunit/keyed-store-array-literal.js @@ -8,7 +8,7 @@ function f1() { const x = [,]; x[1] = 42; - assertEquals([undefined, 42], x); + assertEquals([, 42], x); } %PrepareFunctionForOptimization(f1); diff --git a/test/mjsunit/mjsunit-assert-equals.js b/test/mjsunit/mjsunit-assert-equals.js index 08154827d5..4f686df9fe 100644 --- a/test/mjsunit/mjsunit-assert-equals.js +++ b/test/mjsunit/mjsunit-assert-equals.js @@ -70,6 +70,8 @@ function testAssertEquals(a, b) { testAssertEquals(new Array(1), new Array(1)); testAssertNotEquals(new Array(1), new Array(2)); testAssertEquals([,,], new Array(2)); + // The difference between empty and undefined is not ignored. + testAssertNotEquals([undefined], new Array(1)); })(); (function TestAssertEqualsArraysNested() { @@ -80,9 +82,7 @@ function testAssertEquals(a, b) { })(); (function TestAssertEqualsArrayProperties() { - // Difference between empty and undefined is ignored by the assert - // implementation as well as additional properties. - testAssertEquals([undefined], new Array(1)); + // Array properties are ignored. let arrWithProp = new Array(); arrWithProp.myProperty = 'Additional property'; testAssertEquals([], arrWithProp); diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js index 43298b3b7d..a8cba41f8c 100644 --- a/test/mjsunit/mjsunit.js +++ b/test/mjsunit/mjsunit.js @@ -432,6 +432,7 @@ var prettyPrinted; return false; } for (var i = 0; i < a.length; i++) { + if ((i in a) !== (i in b)) return false; if (!deepEquals(a[i], b[i])) return false; } return true; diff --git a/test/mjsunit/regress/regress-165637.js b/test/mjsunit/regress/regress-165637.js index 2a7fc4421f..60ca8d2e69 100644 --- a/test/mjsunit/regress/regress-165637.js +++ b/test/mjsunit/regress/regress-165637.js @@ -4,7 +4,7 @@ // Make sure that packed and unpacked array slices are still properly handled var holey_array = [1, 2, 3, 4, 5,,,,,,]; -assertEquals([undefined], holey_array.slice(6, 7)); +assertEquals(new Array(1), holey_array.slice(6, 7)); assertEquals(undefined, holey_array.slice(6, 7)[0]); assertEquals([], holey_array.slice(2, 1)); assertEquals(3, holey_array.slice(2, 3)[0]); diff --git a/test/mjsunit/regress/regress-804177.js b/test/mjsunit/regress/regress-804177.js index b100480599..685bed1c03 100644 --- a/test/mjsunit/regress/regress-804177.js +++ b/test/mjsunit/regress/regress-804177.js @@ -25,7 +25,7 @@ } b = Array.of.call(f,1,2); b[4] = 1; - assertEquals(b, [1, 2, undefined, undefined, 1]); + assertEquals(b, [1, 2, , , 1]); })(); // Tests that using Array.of with a constructor returning an object with an diff --git a/test/mjsunit/typedarray-resizablearraybuffer-array-methods.js b/test/mjsunit/typedarray-resizablearraybuffer-array-methods.js index ee42e097b9..f6c31297ca 100644 --- a/test/mjsunit/typedarray-resizablearraybuffer-array-methods.js +++ b/test/mjsunit/typedarray-resizablearraybuffer-array-methods.js @@ -373,8 +373,7 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js'); const fixedLength = new ctor(rab, 0, 4); const evil = { valueOf: () => { rab.resize(2 * ctor.BYTES_PER_ELEMENT); return 0; }}; - assertEquals([undefined, undefined, undefined, undefined], - sliceHelper(fixedLength, evil)); + assertEquals(new Array(4), sliceHelper(fixedLength, evil)); assertEquals(2 * ctor.BYTES_PER_ELEMENT, rab.byteLength); } for (let ctor of ctors) { @@ -401,8 +400,7 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js'); const fixedLength = new ctor(rab, 0, 4); const evil = { valueOf: () => { %ArrayBufferDetach(rab); return 0; }}; - assertEquals([undefined, undefined, undefined, undefined], - sliceHelper(fixedLength, evil)); + assertEquals(new Array(4), sliceHelper(fixedLength, evil)); assertEquals(0, rab.byteLength); } for (let ctor of ctors) { @@ -414,8 +412,9 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js'); } const evil = { valueOf: () => { %ArrayBufferDetach(rab); return 0; }}; - assertEquals([undefined, undefined, undefined, undefined], - ToNumbers(sliceHelper(lengthTracking, evil))); + assertEquals( + [undefined, undefined, undefined, undefined], + ToNumbers(sliceHelper(lengthTracking, evil))); assertEquals(0, rab.byteLength); } })();