diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/keys | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/keys')
11 files changed, 260 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/browser.js b/js/src/tests/test262/built-ins/Array/prototype/keys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/iteration-mutable.js b/js/src/tests/test262/built-ins/Array/prototype/keys/iteration-mutable.js new file mode 100644 index 0000000000..e1eee7e83c --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/iteration-mutable.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + New items in the array are accessible via iteration until iterator is "done". +info: | + When an item is added to the array after the iterator is created but + before the iterator is "done" (as defined by 22.1.5.2.1), the new item's + key should be accessible via iteration. When an item is added to the + array after the iterator is "done", the new item's key should not be + accessible via iteration. +---*/ + +var array = []; +var iterator = array.keys(); +var result; + +array.push('a'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value, 0, 'First result `value`'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); + +array.push('b'); + +result = iterator.next(); +assert.sameValue( + result.done, true, + 'Exhausted result `done` flag (after push)' +); +assert.sameValue( + result.value, undefined, + 'Exhausted result `value` (after push)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/iteration.js b/js/src/tests/test262/built-ins/Array/prototype/keys/iteration.js new file mode 100644 index 0000000000..32e0530717 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/iteration.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + The return is a valid iterator with the array's numeric properties. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +---*/ + +var array = ['a', 'b', 'c']; +var iterator = array.keys(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 0, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 1, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 2, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/length.js b/js/src/tests/test262/built-ins/Array/prototype/keys/length.js new file mode 100644 index 0000000000..6d997e5972 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/length.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + Array.prototype.keys.length value and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.keys.length, 0, + 'The value of `Array.prototype.keys.length` is `0`' +); + +verifyNotEnumerable(Array.prototype.keys, 'length'); +verifyNotWritable(Array.prototype.keys, 'length'); +verifyConfigurable(Array.prototype.keys, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/name.js b/js/src/tests/test262/built-ins/Array/prototype/keys/name.js new file mode 100644 index 0000000000..11ea5c508f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + Array.prototype.keys.name value and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.keys.name, 'keys', + 'The value of `Array.prototype.keys.name` is `"keys"`' +); + +verifyNotEnumerable(Array.prototype.keys, 'name'); +verifyNotWritable(Array.prototype.keys, 'name'); +verifyConfigurable(Array.prototype.keys, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/keys/not-a-constructor.js new file mode 100644 index 0000000000..8d0b5db966 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.keys does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(Array.prototype.keys), false, 'isConstructor(Array.prototype.keys) must return false'); + +assert.throws(TypeError, () => { + new Array.prototype.keys(); +}, '`new Array.prototype.keys()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/keys/prop-desc.js new file mode 100644 index 0000000000..6230d94566 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + Property type and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Array.prototype.keys, + 'function', + '`typeof Array.prototype.keys` is `function`' +); + +verifyNotEnumerable(Array.prototype, 'keys'); +verifyWritable(Array.prototype, 'keys'); +verifyConfigurable(Array.prototype, 'keys'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/Array/prototype/keys/return-abrupt-from-this.js new file mode 100644 index 0000000000..0885de5532 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/return-abrupt-from-this.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + Array.prototype.keys.call(undefined); +}); + +assert.throws(TypeError, function() { + Array.prototype.keys.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator-from-object.js b/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator-from-object.js new file mode 100644 index 0000000000..d48cc27f94 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator-from-object.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + Creates an iterator from a custom object. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = Array.prototype.keys.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator.js b/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000..56ba5b5af5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/returns-iterator.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.keys +description: > + The method should return an Iterator instance. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). + + 22.1.5.1 CreateArrayIterator Abstract Operation + + ... + 2. Let iterator be ObjectCreate(%ArrayIteratorPrototype%, «[[IteratedObject]], + [[ArrayIteratorNextIndex]], [[ArrayIterationKind]]»). + ... + 6. Return iterator. +features: [Symbol.iterator] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].keys(); + +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/keys/shell.js b/js/src/tests/test262/built-ins/Array/prototype/keys/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/keys/shell.js |