diff --git a/test/built-ins/Array/prototype/sort/precise-01.js b/test/built-ins/Array/prototype/sort/precise-01.js new file mode 100644 index 0000000000..dfc79b8cac --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-01.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +Object.prototype[2] = 4; +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +array.sort(); + +assert.sameValue(array[0], 1); +assert.sameValue(array[1], 2); +assert.sameValue(array[2], 3); +assert.sameValue(array[3], 4); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue(array.length, 7); diff --git a/test/built-ins/Array/prototype/sort/precise-02.js b/test/built-ins/Array/prototype/sort/precise-02.js new file mode 100644 index 0000000000..d2c09a38ea --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-02.js @@ -0,0 +1,42 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const logs = []; + +Object.defineProperty(Object.prototype, '2', { + get() { + logs.push('get'); + return 4; + }, + set(v) { + logs.push(`set with ${v}`); + } +}); +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +array.sort(); + +assert.sameValue(logs[0], 'get'); +assert.sameValue(logs[1], 'set with 3'); +assert.sameValue(logs.length, 2); + +assert.sameValue(array[0], 1); +assert.sameValue(array[1], 2); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), false); +assert.sameValue(array[3], 4); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue(array.length, 7); diff --git a/test/built-ins/Array/prototype/sort/precise-03.js b/test/built-ins/Array/prototype/sort/precise-03.js new file mode 100644 index 0000000000..aa30de585f --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-03.js @@ -0,0 +1,52 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const logs = []; + +Object.defineProperty(Object.prototype, '2', { + get() { + logs.push('get'); + return 4; + }, + set(v) { + logs.push(`set with ${v}`); + } +}); +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +let count = 0; +try { + array.sort((a, b) => { + if (++count === 3) { + throw new Error('lolwat'); + } + return b - a; + }); +} catch (exception) { + logs.push(exception.message); +} + +assert.sameValue(logs[0], 'get'); +assert.sameValue(logs[1], 'lolwat'); +assert.sameValue(logs.length, 2); + +assert.sameValue(array[0], undefined); +assert.sameValue(array[1], 3); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), false); +assert.sameValue(array[3], 2); +assert.sameValue(array[4], undefined); +assert.sameValue('5' in array, false); +assert.sameValue(array.hasOwnProperty('5'), false); +assert.sameValue(array[6], 1); +assert.sameValue(array.length, 7); diff --git a/test/built-ins/Array/prototype/sort/precise-04.js b/test/built-ins/Array/prototype/sort/precise-04.js new file mode 100644 index 0000000000..525a56d02c --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-04.js @@ -0,0 +1,49 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + array.push('foo'); + array.push('bar'); + return this.foo; + }, + set(v) { + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), true); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array[8], 'foo'); +assert.sameValue(array[9], 'bar'); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); + +assert.sameValue(array[2], 'c'); +assert.sameValue(array[10], 'foo'); +assert.sameValue(array[11], 'bar'); +assert.sameValue(array.length, 12); +assert.sameValue(array.foo, 'c'); diff --git a/test/built-ins/Array/prototype/sort/precise-05.js b/test/built-ins/Array/prototype/sort/precise-05.js new file mode 100644 index 0000000000..0336070b43 --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-05.js @@ -0,0 +1,42 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.push('foo'); + array.push('bar'); + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array[8], 'foo'); +assert.sameValue(array[9], 'bar'); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); diff --git a/test/built-ins/Array/prototype/sort/precise-06.js b/test/built-ins/Array/prototype/sort/precise-06.js new file mode 100644 index 0000000000..c6e1c9c101 --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-06.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + array.length = array.length - 2; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'b'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], undefined); +assert.sameValue(array[4], undefined); +assert.sameValue('5' in array, false); +assert.sameValue(array.hasOwnProperty('5'), false); +assert.sameValue(array.length, 6); +assert.sameValue(array.foo, undefined); + +assert.sameValue(array[2], undefined); +assert.sameValue(array.length, 4); diff --git a/test/built-ins/Array/prototype/sort/precise-07.js b/test/built-ins/Array/prototype/sort/precise-07.js new file mode 100644 index 0000000000..243960ad0a --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-07.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.length = array.length - 2; + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue(array.length, 7); +assert.sameValue(array.foo, 'c'); diff --git a/test/built-ins/Array/prototype/sort/precise-08.js b/test/built-ins/Array/prototype/sort/precise-08.js new file mode 100644 index 0000000000..769fba1094 --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-08.js @@ -0,0 +1,43 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + delete array[1]; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); + +assert.sameValue(array[2], 'c'); +assert.sameValue('1' in array, false); +assert.sameValue(array.hasOwnProperty(1), false); +assert.sameValue(array.length, 8); diff --git a/test/built-ins/Array/prototype/sort/precise-09.js b/test/built-ins/Array/prototype/sort/precise-09.js new file mode 100644 index 0000000000..9bc9f00c25 --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-09.js @@ -0,0 +1,40 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + delete array[1]; + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue('1' in array, false); +assert.sameValue(array.hasOwnProperty(1), false); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); diff --git a/test/built-ins/Array/prototype/sort/precise-10.js b/test/built-ins/Array/prototype/sort/precise-10.js new file mode 100644 index 0000000000..7ecde4f7ce --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-10.js @@ -0,0 +1,44 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + delete array[3]; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], undefined); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'd'); + +assert.sameValue(array[2], 'd'); +assert.sameValue('3' in array, false); +assert.sameValue(array.hasOwnProperty(3), false); +assert.sameValue(array.length, 8); diff --git a/test/built-ins/Array/prototype/sort/precise-11.js b/test/built-ins/Array/prototype/sort/precise-11.js new file mode 100644 index 0000000000..687535cae6 --- /dev/null +++ b/test/built-ins/Array/prototype/sort/precise-11.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; + +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + delete array[3]; + this.foo = v; + } +}); + +array.sort(); + +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c');