diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Iterator/prototype/toArray | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
10 files changed, 175 insertions, 0 deletions
diff --git a/js/src/tests/non262/Iterator/prototype/toArray/create-in-current-realm.js b/js/src/tests/non262/Iterator/prototype/toArray/create-in-current-realm.js new file mode 100644 index 0000000000..850729e5e3 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/create-in-current-realm.js @@ -0,0 +1,14 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +const otherGlobal = newGlobal({newCompartment: true}); + +let array = [1, 2, 3].values().toArray(); +assertEq(array instanceof Array, true); +assertEq(array instanceof otherGlobal.Array, false); + +array = otherGlobal.Iterator.prototype.toArray.call([1, 2, 3].values()); +assertEq(array instanceof Array, false); +assertEq(array instanceof otherGlobal.Array, true); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/descriptor.js b/js/src/tests/non262/Iterator/prototype/toArray/descriptor.js new file mode 100644 index 0000000000..8daa56fd4a --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/descriptor.js @@ -0,0 +1,13 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally +/*--- + Descriptor property of Iterator.prototype.toArray +---*/ + +const propDesc = Reflect.getOwnPropertyDescriptor(Iterator.prototype, 'toArray'); +assertEq(typeof propDesc.value, 'function'); +assertEq(propDesc.writable, true); +assertEq(propDesc.enumerable, false); +assertEq(propDesc.configurable, true); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/iterator-empty.js b/js/src/tests/non262/Iterator/prototype/toArray/iterator-empty.js new file mode 100644 index 0000000000..97c14f0d06 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/iterator-empty.js @@ -0,0 +1,10 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +const iter = [].values(); +const array = iter.toArray(); + +assertEq(Array.isArray(array), true); +assertEq(array.length, 0); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/length.js b/js/src/tests/non262/Iterator/prototype/toArray/length.js new file mode 100644 index 0000000000..493a225ce7 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/length.js @@ -0,0 +1,17 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally +/*--- + The `length` property of Iterator.prototype.toArray. +info: | + ES7 section 17: Unless otherwise specified, the length property of a built-in + Function object has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +---*/ + +const propDesc = Reflect.getOwnPropertyDescriptor(Iterator.prototype.toArray, 'length'); +assertEq(propDesc.value, 0); +assertEq(propDesc.writable, false); +assertEq(propDesc.enumerable, false); +assertEq(propDesc.configurable, true); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/name.js b/js/src/tests/non262/Iterator/prototype/toArray/name.js new file mode 100644 index 0000000000..b382c3a3a6 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/name.js @@ -0,0 +1,13 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally +/*--- + `name` property of Iterator.prototype.toArray. +---*/ + +const propDesc = Reflect.getOwnPropertyDescriptor(Iterator.prototype.toArray, 'name'); +assertEq(propDesc.value, 'toArray'); +assertEq(propDesc.writable, false); +assertEq(propDesc.enumerable, false); +assertEq(propDesc.configurable, true); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/next-throws.js b/js/src/tests/non262/Iterator/prototype/toArray/next-throws.js new file mode 100644 index 0000000000..c93ecdd324 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/next-throws.js @@ -0,0 +1,14 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +class TestIterator extends Iterator { + next() { + throw new Error(); + } +} + +const iter = new TestIterator(); + +assertThrowsInstanceOf(() => iter.toArray(), Error); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/proxy.js b/js/src/tests/non262/Iterator/prototype/toArray/proxy.js new file mode 100644 index 0000000000..83024eeb8a --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/proxy.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally +// +// This test checks that %Iterator.prototype%.toArray only gets the `next` method off of the +// iterator once, and never accesses the @@iterator property. +const log = []; +const handlerProxy = new Proxy({}, { + get: (target, key, receiver) => (...args) => { + log.push(`${key}: ${args[1]?.toString()}`); + return Reflect[key](...args); + }, +}); + +class Counter extends Iterator { + value = 0; + next() { + const value = this.value; + if (value < 2) { + this.value = value + 1; + return {done: false, value}; + } + return {done: true}; + } +} + +const iter = new Proxy(new Counter(), handlerProxy); +const array = iter.toArray(); + +assertEq( + log.join('\n'), + `get: toArray +get: next +get: value +set: value +getOwnPropertyDescriptor: value +defineProperty: value +get: value +set: value +getOwnPropertyDescriptor: value +defineProperty: value +get: value` +); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/this-not-iterator-throws.js b/js/src/tests/non262/Iterator/prototype/toArray/this-not-iterator-throws.js new file mode 100644 index 0000000000..1442d22557 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/this-not-iterator-throws.js @@ -0,0 +1,8 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +assertThrowsInstanceOf(Iterator.prototype.toArray.bind(undefined), TypeError); +assertThrowsInstanceOf(Iterator.prototype.toArray.bind({}), TypeError); +assertThrowsInstanceOf(Iterator.prototype.toArray.bind({next: 0}), TypeError); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/toArray.js b/js/src/tests/non262/Iterator/prototype/toArray/toArray.js new file mode 100644 index 0000000000..29c99525fb --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/toArray.js @@ -0,0 +1,17 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +const iter = [1, 2, 3].values(); +assertEq(Array.isArray(iter), false); + +const array = iter.toArray(); +assertEq(Array.isArray(array), true); +assertEq(array.length, 3); + +const expected = [1, 2, 3]; +for (const item of array) { + const expect = expected.shift(); + assertEq(item, expect); +} + +if (typeof reportCompare === 'function') + reportCompare(0, 0); diff --git a/js/src/tests/non262/Iterator/prototype/toArray/value-throws-iterator-not-closed.js b/js/src/tests/non262/Iterator/prototype/toArray/value-throws-iterator-not-closed.js new file mode 100644 index 0000000000..ca56de8a66 --- /dev/null +++ b/js/src/tests/non262/Iterator/prototype/toArray/value-throws-iterator-not-closed.js @@ -0,0 +1,25 @@ +// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally + +class TestError extends Error {} +class TestIterator extends Iterator { + next() { + return new Proxy({done: false}, {get: (target, key, receiver) => { + if (key === 'value') + throw new TestError(); + return 0; + }}); + } + + closed = false; + return() { + closed = true; + } +} + +const iterator = new TestIterator(); +assertEq(iterator.closed, false, 'iterator starts unclosed'); +assertThrowsInstanceOf(() => iterator.toArray(), TestError); +assertEq(iterator.closed, false, 'iterator remains unclosed'); + +if (typeof reportCompare === 'function') + reportCompare(0, 0); |