diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/values')
11 files changed, 264 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/browser.js b/js/src/tests/test262/built-ins/Array/prototype/values/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/iteration-mutable.js b/js/src/tests/test262/built-ins/Array/prototype/values/iteration-mutable.js new file mode 100644 index 0000000000..02a7bce3b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/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.values +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 + value should be accessible via iteration. When an item is added to the + array after the iterator is "done", the new item should not be + accessible via iteration. +---*/ + +var array = []; +var iterator = array.values(); +var result; + +array.push('a'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value, 'a', '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/values/iteration.js b/js/src/tests/test262/built-ins/Array/prototype/values/iteration.js new file mode 100644 index 0000000000..c5e6f232a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/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.values +description: > + The return is a valid iterator with the array's numeric properties. +info: | + 22.1.3.29 Array.prototype.values ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). +---*/ + +var array = ['a', 'b', 'c']; +var iterator = array.values(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'a', 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 'b', 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 'c', '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/values/length.js b/js/src/tests/test262/built-ins/Array/prototype/values/length.js new file mode 100644 index 0000000000..c87379d29f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/length.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.values +description: Array.prototype.values `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Array.prototype.values.length, 0); + +verifyNotEnumerable(Array.prototype.values, 'length'); +verifyNotWritable(Array.prototype.values, 'length'); +verifyConfigurable(Array.prototype.values, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/name.js b/js/src/tests/test262/built-ins/Array/prototype/values/name.js new file mode 100644 index 0000000000..71eb0fb243 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/name.js @@ -0,0 +1,28 @@ +// 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.values +description: Array.prototype.values `name` property +info: | + ES6 Section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Array.prototype.values.name, 'values'); + +verifyNotEnumerable(Array.prototype.values, 'name'); +verifyNotWritable(Array.prototype.values, 'name'); +verifyConfigurable(Array.prototype.values, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000..2afdde1e37 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/not-a-constructor.js @@ -0,0 +1,35 @@ +// 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.values 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, Array.prototype.values, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Array.prototype.values), + false, + 'isConstructor(Array.prototype.values) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.values(); +}, '`new Array.prototype.values()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/values/prop-desc.js new file mode 100644 index 0000000000..111d637b8e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/prop-desc.js @@ -0,0 +1,19 @@ +// 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.values +description: Array.prototype.values property descriptor +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof Array.prototype.values, 'function'); + +verifyNotEnumerable(Array.prototype, 'values'); +verifyWritable(Array.prototype, 'values'); +verifyConfigurable(Array.prototype, 'values'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/returns-iterator-from-object.js b/js/src/tests/test262/built-ins/Array/prototype/values/returns-iterator-from-object.js new file mode 100644 index 0000000000..8bf0aa1d06 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/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.values +description: > + Creates an iterator from a custom object. +info: | + 22.1.3.29 Array.prototype.values ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = Array.prototype.values.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].values() is %ArrayIteratorPrototype%' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/returns-iterator.js b/js/src/tests/test262/built-ins/Array/prototype/values/returns-iterator.js new file mode 100644 index 0000000000..f3cabffaea --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/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.values +description: > + The method should return an Iterator instance. +info: | + 22.1.3.29 Array.prototype.values ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). + + 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 = [].values(); + +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].values() is %ArrayIteratorPrototype%' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/shell.js b/js/src/tests/test262/built-ins/Array/prototype/values/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/values/this-val-non-obj-coercible.js b/js/src/tests/test262/built-ins/Array/prototype/values/this-val-non-obj-coercible.js new file mode 100644 index 0000000000..843a6274ba --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/values/this-val-non-obj-coercible.js @@ -0,0 +1,20 @@ +// 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.values +description: > + `this` value not object coercible +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + Array.prototype.values.call(undefined); +}); + +assert.throws(TypeError, function() { + Array.prototype.values.call(null); +}); + +reportCompare(0, 0); |