From e3b12065b2c4ef2ef204a61d1fd09ac3a94a7e21 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 22 Sep 2020 16:39:41 -0400 Subject: [PATCH] Coverage: Array.prototype.item, String.prototype.item, TypedArray.prototype.item. Closes gh-2809, gh-2810, gh-2811 --- features.txt | 6 +++ .../item/index-argument-tointeger.js | 27 ++++++++++ ...-non-numeric-argument-tointeger-invalid.js | 20 ++++++++ .../index-non-numeric-argument-tointeger.js | 26 ++++++++++ test/built-ins/Array/prototype/item/length.js | 24 +++++++++ test/built-ins/Array/prototype/item/name.js | 24 +++++++++ .../Array/prototype/item/prop-desc.js | 24 +++++++++ .../prototype/item/return-abrupt-from-this.js | 22 ++++++++ .../item/returns-item-relative-index.js | 30 +++++++++++ .../Array/prototype/item/returns-item.js | 31 ++++++++++++ ...ns-undefined-for-holes-in-sparse-arrays.js | 43 ++++++++++++++++ ...eturns-undefined-for-out-of-range-index.js | 20 ++++++++ .../item/index-argument-tointeger.js | 27 ++++++++++ ...-non-numeric-argument-tointeger-invalid.js | 20 ++++++++ .../index-non-numeric-argument-tointeger.js | 26 ++++++++++ .../built-ins/String/prototype/item/length.js | 24 +++++++++ test/built-ins/String/prototype/item/name.js | 24 +++++++++ .../String/prototype/item/prop-desc.js | 24 +++++++++ .../prototype/item/return-abrupt-from-this.js | 22 ++++++++ .../prototype/item/returns-code-unit.js | 30 +++++++++++ .../item/returns-item-relative-index.js | 29 +++++++++++ .../String/prototype/item/returns-item.js | 30 +++++++++++ ...eturns-undefined-for-out-of-range-index.js | 20 ++++++++ .../item/index-argument-tointeger.js | 35 +++++++++++++ ...-non-numeric-argument-tointeger-invalid.js | 28 +++++++++++ .../index-non-numeric-argument-tointeger.js | 35 +++++++++++++ .../TypedArray/prototype/item/length.js | 28 +++++++++++ .../TypedArray/prototype/item/name.js | 28 +++++++++++ .../TypedArray/prototype/item/prop-desc.js | 22 ++++++++ .../prototype/item/return-abrupt-from-this.js | 40 +++++++++++++++ .../item/returns-item-relative-index.js | 37 ++++++++++++++ .../TypedArray/prototype/item/returns-item.js | 38 ++++++++++++++ ...ns-undefined-for-holes-in-sparse-arrays.js | 50 +++++++++++++++++++ ...eturns-undefined-for-out-of-range-index.js | 28 +++++++++++ 34 files changed, 942 insertions(+) create mode 100644 test/built-ins/Array/prototype/item/index-argument-tointeger.js create mode 100644 test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger-invalid.js create mode 100644 test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger.js create mode 100644 test/built-ins/Array/prototype/item/length.js create mode 100644 test/built-ins/Array/prototype/item/name.js create mode 100644 test/built-ins/Array/prototype/item/prop-desc.js create mode 100644 test/built-ins/Array/prototype/item/return-abrupt-from-this.js create mode 100644 test/built-ins/Array/prototype/item/returns-item-relative-index.js create mode 100644 test/built-ins/Array/prototype/item/returns-item.js create mode 100644 test/built-ins/Array/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js create mode 100644 test/built-ins/Array/prototype/item/returns-undefined-for-out-of-range-index.js create mode 100644 test/built-ins/String/prototype/item/index-argument-tointeger.js create mode 100644 test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger-invalid.js create mode 100644 test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger.js create mode 100644 test/built-ins/String/prototype/item/length.js create mode 100644 test/built-ins/String/prototype/item/name.js create mode 100644 test/built-ins/String/prototype/item/prop-desc.js create mode 100644 test/built-ins/String/prototype/item/return-abrupt-from-this.js create mode 100644 test/built-ins/String/prototype/item/returns-code-unit.js create mode 100644 test/built-ins/String/prototype/item/returns-item-relative-index.js create mode 100644 test/built-ins/String/prototype/item/returns-item.js create mode 100644 test/built-ins/String/prototype/item/returns-undefined-for-out-of-range-index.js create mode 100644 test/built-ins/TypedArray/prototype/item/index-argument-tointeger.js create mode 100644 test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger-invalid.js create mode 100644 test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger.js create mode 100644 test/built-ins/TypedArray/prototype/item/length.js create mode 100644 test/built-ins/TypedArray/prototype/item/name.js create mode 100644 test/built-ins/TypedArray/prototype/item/prop-desc.js create mode 100644 test/built-ins/TypedArray/prototype/item/return-abrupt-from-this.js create mode 100644 test/built-ins/TypedArray/prototype/item/returns-item-relative-index.js create mode 100644 test/built-ins/TypedArray/prototype/item/returns-item.js create mode 100644 test/built-ins/TypedArray/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js create mode 100644 test/built-ins/TypedArray/prototype/item/returns-undefined-for-out-of-range-index.js diff --git a/features.txt b/features.txt index 3c260720d4..a3746dd5b5 100644 --- a/features.txt +++ b/features.txt @@ -182,6 +182,12 @@ logical-assignment-operators # https://github.com/tc39/proposal-atomics-wait-async Atomics.waitAsync +# Item Method +# https://github.com/tc39/proposal-item-method +Array.prototype.item +String.prototype.item +TypedArray.prototype.item + ## Standard language features # # Language features that have been included in a published version of the diff --git a/test/built-ins/Array/prototype/item/index-argument-tointeger.js b/test/built-ins/Array/prototype/item/index-argument-tointeger.js new file mode 100644 index 0000000000..3e8e988ac1 --- /dev/null +++ b/test/built-ins/Array/prototype/item/index-argument-tointeger.js @@ -0,0 +1,27 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Property type and descriptor. +info: | + Array.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let valueOfCallCount = 0; +let index = { + valueOf() { + valueOfCallCount++; + return 1; + } +}; + +let a = [0,1,2,3]; + +assert.sameValue(a.item(index), 1, 'a.item({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); +assert.sameValue(valueOfCallCount, 1, 'The value of `valueOfCallCount` is 1'); diff --git a/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger-invalid.js b/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000..a1f7d7826e --- /dev/null +++ b/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Property type and descriptor. +info: | + Array.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let a = [0,1,2,3]; + +assert.throws(TypeError, () => { + a.item(Symbol()); +}, '`a.item(Symbol())` throws TypeError'); diff --git a/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger.js b/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000..ea388fc02f --- /dev/null +++ b/test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Property type and descriptor. +info: | + Array.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let a = [0,1,2,3]; + +assert.sameValue(a.item(false), 0, 'a.item(false) must return 0'); +assert.sameValue(a.item(null), 0, 'a.item(null) must return 0'); +assert.sameValue(a.item(undefined), 0, 'a.item(undefined) must return 0'); +assert.sameValue(a.item(""), 0, 'a.item("") must return 0'); +assert.sameValue(a.item(function() {}), 0, 'a.item(function() {}) must return 0'); +assert.sameValue(a.item([]), 0, 'a.item([]) must return 0'); + +assert.sameValue(a.item(true), 1, 'a.item(true) must return 1'); +assert.sameValue(a.item("1"), 1, 'a.item("1") must return 1'); diff --git a/test/built-ins/Array/prototype/item/length.js b/test/built-ins/Array/prototype/item/length.js new file mode 100644 index 0000000000..0e7d194786 --- /dev/null +++ b/test/built-ins/Array/prototype/item/length.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Array.prototype.item.length value and descriptor. +info: | + Array.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +assert.sameValue( + Array.prototype.item.length, 1, + 'The value of Array.prototype.item.length is 1' +); + +verifyNotEnumerable(Array.prototype.item, 'length'); +verifyNotWritable(Array.prototype.item, 'length'); +verifyConfigurable(Array.prototype.item, 'length'); diff --git a/test/built-ins/Array/prototype/item/name.js b/test/built-ins/Array/prototype/item/name.js new file mode 100644 index 0000000000..a324d88b78 --- /dev/null +++ b/test/built-ins/Array/prototype/item/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Array.prototype.item.name value and descriptor. +info: | + Array.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +assert.sameValue( + Array.prototype.item.name, 'item', + 'The value of Array.prototype.item.name is "item"' +); + +verifyNotEnumerable(Array.prototype.item, 'name'); +verifyNotWritable(Array.prototype.item, 'name'); +verifyConfigurable(Array.prototype.item, 'name'); diff --git a/test/built-ins/Array/prototype/item/prop-desc.js b/test/built-ins/Array/prototype/item/prop-desc.js new file mode 100644 index 0000000000..e29a3fbca7 --- /dev/null +++ b/test/built-ins/Array/prototype/item/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Property type and descriptor. +info: | + Array.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +assert.sameValue( + typeof Array.prototype.item, + 'function', + 'The value of `typeof Array.prototype.item` is "function"' +); + +verifyNotEnumerable(Array.prototype, 'item'); +verifyWritable(Array.prototype, 'item'); +verifyConfigurable(Array.prototype, 'item'); diff --git a/test/built-ins/Array/prototype/item/return-abrupt-from-this.js b/test/built-ins/Array/prototype/item/return-abrupt-from-this.js new file mode 100644 index 0000000000..3bb4670903 --- /dev/null +++ b/test/built-ins/Array/prototype/item/return-abrupt-from-this.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Return abrupt from ToObject(this value). +info: | + Array.prototype.item( index ) + + Let O be ? ToObject(this value). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +assert.throws(TypeError, () => { + Array.prototype.item.call(undefined); +}, '`Array.prototype.item.call(undefined)` throws TypeError'); + +assert.throws(TypeError, () => { + Array.prototype.item.call(null); +}, '`Array.prototype.item.call(null)` throws TypeError'); diff --git a/test/built-ins/Array/prototype/item/returns-item-relative-index.js b/test/built-ins/Array/prototype/item/returns-item-relative-index.js new file mode 100644 index 0000000000..7f71a49ce7 --- /dev/null +++ b/test/built-ins/Array/prototype/item/returns-item-relative-index.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Returns the item value at the specified relative index +info: | + Array.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let a = [1, 2, 3, 4, ,5]; + +assert.sameValue(a.item(0), 1, 'a.item(0) must return 1'); +assert.sameValue(a.item(-1), 5, 'a.item(-1) must return 5'); +assert.sameValue(a.item(-2), undefined, 'a.item(-2) must return undefined'); +assert.sameValue(a.item(-3), 4, 'a.item(-3) must return 4'); +assert.sameValue(a.item(-4), 3, 'a.item(-4) must return 3'); diff --git a/test/built-ins/Array/prototype/item/returns-item.js b/test/built-ins/Array/prototype/item/returns-item.js new file mode 100644 index 0000000000..247a8ffc88 --- /dev/null +++ b/test/built-ins/Array/prototype/item/returns-item.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-array.prototype.item +description: > + Returns the item value at the specified index +info: | + Array.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let a = [1, 2, 3, 4,,5]; + +assert.sameValue(a.item(0), 1, 'a.item(0) must return 1'); +assert.sameValue(a.item(1), 2, 'a.item(1) must return 2'); +assert.sameValue(a.item(2), 3, 'a.item(2) must return 3'); +assert.sameValue(a.item(3), 4, 'a.item(3) must return 4'); +assert.sameValue(a.item(4), undefined, 'a.item(4) must return undefined'); +assert.sameValue(a.item(5), 5, 'a.item(5) must return 5'); diff --git a/test/built-ins/Array/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js b/test/built-ins/Array/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js new file mode 100644 index 0000000000..5b9ee3af06 --- /dev/null +++ b/test/built-ins/Array/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Returns the item value at the specified index, respecting holes in sparse arrays. +info: | + Array.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [Array.prototype.item] +---*/ +assert.sameValue( + typeof Array.prototype.item, + 'function', + 'The value of `typeof Array.prototype.item` is "function"' +); + +let a = [0, 1, , 3, 4, , 6]; + +assert.sameValue(a.item(0), 0, 'a.item(0) must return 0'); +assert.sameValue(a.item(1), 1, 'a.item(1) must return 1'); +assert.sameValue(a.item(2), undefined, 'a.item(2) must return undefined'); +assert.sameValue(a.item(3), 3, 'a.item(3) must return 3'); +assert.sameValue(a.item(4), 4, 'a.item(4) must return 4'); +assert.sameValue(a.item(5), undefined, 'a.item(5) must return undefined'); +assert.sameValue(a.item(6), 6, 'a.item(6) must return 6'); +assert.sameValue(a.item(-0), 0, 'a.item(-0) must return 0'); +assert.sameValue(a.item(-1), 6, 'a.item(-1) must return 6'); +assert.sameValue(a.item(-2), undefined, 'a.item(-2) must return undefined'); +assert.sameValue(a.item(-3), 4, 'a.item(-3) must return 4'); +assert.sameValue(a.item(-4), 3, 'a.item(-4) must return 3'); +assert.sameValue(a.item(-5), undefined, 'a.item(-5) must return undefined'); +assert.sameValue(a.item(-6), 1, 'a.item(-6) must return 1'); diff --git a/test/built-ins/Array/prototype/item/returns-undefined-for-out-of-range-index.js b/test/built-ins/Array/prototype/item/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000..b866a511ac --- /dev/null +++ b/test/built-ins/Array/prototype/item/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.item +description: > + Returns undefined if the specified index less than or greater than the available index range. +info: | + Array.prototype.item( index ) + + If k < 0 or k ≥ len, then return undefined. +features: [Array.prototype.item] +---*/ +assert.sameValue(typeof Array.prototype.item, 'function'); + +let a = []; + +assert.sameValue(a.item(-2), undefined, 'a.item(-2) must return undefined'); // wrap around the end +assert.sameValue(a.item(0), undefined, 'a.item(0) must return undefined'); +assert.sameValue(a.item(1), undefined, 'a.item(1) must return undefined'); + diff --git a/test/built-ins/String/prototype/item/index-argument-tointeger.js b/test/built-ins/String/prototype/item/index-argument-tointeger.js new file mode 100644 index 0000000000..49cb3434b3 --- /dev/null +++ b/test/built-ins/String/prototype/item/index-argument-tointeger.js @@ -0,0 +1,27 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Property type and descriptor. +info: | + String.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let valueOfCallCount = 0; +let index = { + valueOf() { + valueOfCallCount++; + return 1; + } +}; + +let s = "01"; + +assert.sameValue(s.item(index), '1', 's.item({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); +assert.sameValue(valueOfCallCount, 1, 'The value of `valueOfCallCount` is 1'); diff --git a/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger-invalid.js b/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000..c40d44b823 --- /dev/null +++ b/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Property type and descriptor. +info: | + String.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = "01"; + +assert.throws(TypeError, () => { + s.item(Symbol()); +}, '`s.item(Symbol())` throws TypeError'); diff --git a/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger.js b/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000..00444f1c39 --- /dev/null +++ b/test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Property type and descriptor. +info: | + String.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = "01"; + +assert.sameValue(s.item(false), '0', 's.item(false) must return 0'); +assert.sameValue(s.item(null), '0', 's.item(null) must return 0'); +assert.sameValue(s.item(undefined), '0', 's.item(undefined) must return 0'); +assert.sameValue(s.item(""), '0', 's.item("") must return 0'); +assert.sameValue(s.item(function() {}), '0', 's.item(function() {}) must return 0'); +assert.sameValue(s.item([]), '0', 's.item([]) must return 0'); + +assert.sameValue(s.item(true), '1', 's.item(true) must return 1'); +assert.sameValue(s.item("1"), '1', 's.item("1") must return 1'); diff --git a/test/built-ins/String/prototype/item/length.js b/test/built-ins/String/prototype/item/length.js new file mode 100644 index 0000000000..7436b943f8 --- /dev/null +++ b/test/built-ins/String/prototype/item/length.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + String.prototype.item.length value and descriptor. +info: | + String.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +assert.sameValue( + String.prototype.item.length, 1, + 'The value of String.prototype.item.length is 1' +); + +verifyNotEnumerable(String.prototype.item, 'length'); +verifyNotWritable(String.prototype.item, 'length'); +verifyConfigurable(String.prototype.item, 'length'); diff --git a/test/built-ins/String/prototype/item/name.js b/test/built-ins/String/prototype/item/name.js new file mode 100644 index 0000000000..9b634303db --- /dev/null +++ b/test/built-ins/String/prototype/item/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + String.prototype.item.name value and descriptor. +info: | + String.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +assert.sameValue( + String.prototype.item.name, 'item', + 'The value of String.prototype.item.name is "item"' +); + +verifyNotEnumerable(String.prototype.item, 'name'); +verifyNotWritable(String.prototype.item, 'name'); +verifyConfigurable(String.prototype.item, 'name'); diff --git a/test/built-ins/String/prototype/item/prop-desc.js b/test/built-ins/String/prototype/item/prop-desc.js new file mode 100644 index 0000000000..2e0206640c --- /dev/null +++ b/test/built-ins/String/prototype/item/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Property type and descriptor. +info: | + String.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +assert.sameValue( + typeof String.prototype.item, + 'function', + 'The value of `typeof String.prototype.item` is "function"' +); + +verifyNotEnumerable(String.prototype, 'item'); +verifyWritable(String.prototype, 'item'); +verifyConfigurable(String.prototype, 'item'); diff --git a/test/built-ins/String/prototype/item/return-abrupt-from-this.js b/test/built-ins/String/prototype/item/return-abrupt-from-this.js new file mode 100644 index 0000000000..d2841c1311 --- /dev/null +++ b/test/built-ins/String/prototype/item/return-abrupt-from-this.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Return abrupt from RequireObjectCoercible(this value). +info: | + String.prototype.item( index ) + + Let O be ? RequireObjectCoercible(this value). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +assert.throws(TypeError, () => { + String.prototype.item.call(undefined); +}, '`String.prototype.item.call(undefined)` throws TypeError'); + +assert.throws(TypeError, () => { + String.prototype.item.call(null); +}, '`String.prototype.item.call(null)` throws TypeError'); diff --git a/test/built-ins/String/prototype/item/returns-code-unit.js b/test/built-ins/String/prototype/item/returns-code-unit.js new file mode 100644 index 0000000000..5bfcc7226a --- /dev/null +++ b/test/built-ins/String/prototype/item/returns-code-unit.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototype.item +description: > + The method should return an Iterator instance. +info: | + String.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = "12\uD80034"; + +assert.sameValue(s.item(0), "1", 's.item(0) must return "1"'); +assert.sameValue(s.item(1), "2", 's.item(1) must return "2"'); +assert.sameValue(s.item(2), "\uD800", 's.item(2) must return "\\uD800"'); +assert.sameValue(s.item(3), "3", 's.item(3) must return "3"'); +assert.sameValue(s.item(4), "4", 's.item(4) must return "4"'); diff --git a/test/built-ins/String/prototype/item/returns-item-relative-index.js b/test/built-ins/String/prototype/item/returns-item-relative-index.js new file mode 100644 index 0000000000..0509bf2e2c --- /dev/null +++ b/test/built-ins/String/prototype/item/returns-item-relative-index.js @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototypeitem +description: > + Returns the item value at the specified relative index +info: | + String.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = "12345"; + +assert.sameValue(s.item(0), "1", 's.item(0) must return "1"'); +assert.sameValue(s.item(-1), "5", 's.item(-1) must return "5"'); +assert.sameValue(s.item(-3), "3", 's.item(-3) must return "3"'); +assert.sameValue(s.item(-4), "2", 's.item(-4) must return "2"'); diff --git a/test/built-ins/String/prototype/item/returns-item.js b/test/built-ins/String/prototype/item/returns-item.js new file mode 100644 index 0000000000..d14db0f4ca --- /dev/null +++ b/test/built-ins/String/prototype/item/returns-item.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototypeitem +description: > + Returns the item value at the specified index +info: | + String.prototypeitem ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = "12345"; + +assert.sameValue(s.item(0), "1", 's.item(0) must return "1"'); +assert.sameValue(s.item(1), "2", 's.item(1) must return "2"'); +assert.sameValue(s.item(2), "3", 's.item(2) must return "3"'); +assert.sameValue(s.item(3), "4", 's.item(3) must return "4"'); +assert.sameValue(s.item(4), "5", 's.item(4) must return "5"'); diff --git a/test/built-ins/String/prototype/item/returns-undefined-for-out-of-range-index.js b/test/built-ins/String/prototype/item/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000..bf77360f7b --- /dev/null +++ b/test/built-ins/String/prototype/item/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.item +description: > + Creates an iterator from a custom object. +info: | + String.prototype.item( index ) + + If k < 0 or k ≥ len, then return undefined. +features: [String.prototype.item] +---*/ +assert.sameValue(typeof String.prototype.item, 'function'); + +let s = ""; + +assert.sameValue(s.item(-2), undefined, 's.item(-2) must return undefined'); // wrap around the end +assert.sameValue(s.item(0), undefined, 's.item(0) must return undefined'); +assert.sameValue(s.item(1), undefined, 's.item(1) must return undefined'); + diff --git a/test/built-ins/TypedArray/prototype/item/index-argument-tointeger.js b/test/built-ins/TypedArray/prototype/item/index-argument-tointeger.js new file mode 100644 index 0000000000..1c7c95f720 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/index-argument-tointeger.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-%typedarray%.prototype.item +description: > + Property type and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [testTypedArray.js] +features: [TypedArray, TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + let valueOfCallCount = 0; + let index = { + valueOf() { + valueOfCallCount++; + return 1; + } + }; + + let a = new TA([0,1,2,3]); + + assert.sameValue(a.item(index), 1, 'a.item({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); + assert.sameValue(valueOfCallCount, 1, 'The value of `valueOfCallCount` is 1'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger-invalid.js b/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000..96bd375d7b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Property type and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [testTypedArray.js] +features: [TypedArray, TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + let a = new TA([0,1,2,3]); + + assert.throws(TypeError, () => { + a.item(Symbol()); + }, '`a.item(Symbol())` throws TypeError'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger.js b/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000..f387f22cae --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/index-non-numeric-argument-tointeger.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-%typedarray%.prototype.item +description: > + Property type and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [testTypedArray.js] +features: [TypedArray, TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + + let a = new TA([0,1,2,3]); + + assert.sameValue(a.item(false), 0, 'a.item(false) must return 0'); + assert.sameValue(a.item(null), 0, 'a.item(null) must return 0'); + assert.sameValue(a.item(undefined), 0, 'a.item(undefined) must return 0'); + assert.sameValue(a.item(""), 0, 'a.item("") must return 0'); + assert.sameValue(a.item(function() {}), 0, 'a.item(function() {}) must return 0'); + assert.sameValue(a.item([]), 0, 'a.item([]) must return 0'); + + assert.sameValue(a.item(true), 1, 'a.item(true) must return 1'); + assert.sameValue(a.item("1"), 1, 'a.item("1") must return 1'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/length.js b/test/built-ins/TypedArray/prototype/item/length.js new file mode 100644 index 0000000000..997421a73a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/length.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + TypedArray.prototype.item.length value and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +assert.sameValue( + TypedArray.prototype.item.length, 1, + 'The value of TypedArray.prototype.item.length is 1' +); + +verifyNotEnumerable(TypedArray.prototype.item, 'length'); +verifyNotWritable(TypedArray.prototype.item, 'length'); +verifyConfigurable(TypedArray.prototype.item, 'length'); diff --git a/test/built-ins/TypedArray/prototype/item/name.js b/test/built-ins/TypedArray/prototype/item/name.js new file mode 100644 index 0000000000..42163bc095 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + %TypedArray%.prototype.item.name value and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +assert.sameValue( + TypedArray.prototype.item.name, 'item', + 'The value of TypedArray.prototype.item.name is "item"' +); + +verifyNotEnumerable(TypedArray.prototype.item, 'name'); +verifyNotWritable(TypedArray.prototype.item, 'name'); +verifyConfigurable(TypedArray.prototype.item, 'name'); diff --git a/test/built-ins/TypedArray/prototype/item/prop-desc.js b/test/built-ins/TypedArray/prototype/item/prop-desc.js new file mode 100644 index 0000000000..48b53c695e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/prop-desc.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Property type and descriptor. +info: | + %TypedArray%.prototype.item( index ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +verifyNotEnumerable(TypedArray.prototype, 'item'); +verifyWritable(TypedArray.prototype, 'item'); +verifyConfigurable(TypedArray.prototype, 'item'); diff --git a/test/built-ins/TypedArray/prototype/item/return-abrupt-from-this.js b/test/built-ins/TypedArray/prototype/item/return-abrupt-from-this.js new file mode 100644 index 0000000000..69754a600f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/return-abrupt-from-this.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Return abrupt from ToObject(this value). +info: | + %TypedArray%.prototype.item( index ) + + Let O be the this value. + Perform ? ValidateTypedArray(O). + +includes: [testTypedArray.js] +features: [TypedArray,TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +assert.throws(TypeError, () => { + TypedArray.prototype.item.call(undefined); +}, '`TypedArray.prototype.item.call(undefined)` throws TypeError'); + +assert.throws(TypeError, () => { + TypedArray.prototype.item.call(null); +}, '`TypedArray.prototype.item.call(null)` throws TypeError'); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + + assert.throws(TypeError, () => { + TA.prototype.item.call(undefined); + }, '`TA.prototype.item.call(undefined)` throws TypeError'); + + assert.throws(TypeError, () => { + TA.prototype.item.call(null); + }, '`TA.prototype.item.call(null)` throws TypeError'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/returns-item-relative-index.js b/test/built-ins/TypedArray/prototype/item/returns-item-relative-index.js new file mode 100644 index 0000000000..140df5d3d6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/returns-item-relative-index.js @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Returns the item value at the specified relative index +info: | + %TypedArray%.prototype.item( index ) + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [testTypedArray.js] +features: [TypedArray,TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + let a = new TA([1, 2, 3, 4, 5]); + assert.sameValue(a.item(0), 1, 'a.item(0) must return 1'); + assert.sameValue(a.item(-1), 5, 'a.item(-1) must return 5'); + assert.sameValue(a.item(-2), 4, 'a.item(-2) must return 4'); + assert.sameValue(a.item(-3), 3, 'a.item(-3) must return 3'); + assert.sameValue(a.item(-4), 2, 'a.item(-4) must return 2'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/returns-item.js b/test/built-ins/TypedArray/prototype/item/returns-item.js new file mode 100644 index 0000000000..fdbe04a00f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/returns-item.js @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Returns the item value at the specified index +info: | + %TypedArray%.prototype.item( index ) + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [testTypedArray.js] +features: [TypedArray,TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + let a = new TA([1, 2, 3, 4]); + + assert.sameValue(a.item(0), 1, 'a.item(0) must return 1'); + assert.sameValue(a.item(1), 2, 'a.item(1) must return 2'); + assert.sameValue(a.item(2), 3, 'a.item(2) must return 3'); + assert.sameValue(a.item(3), 4, 'a.item(3) must return 4'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js b/test/built-ins/TypedArray/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js new file mode 100644 index 0000000000..447ef50c2d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js @@ -0,0 +1,50 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Returns the item value at the specified index, holes are filled in sparse arrays. +info: | + %TypedArray%.prototype.item( index ) + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [testTypedArray.js] +features: [TypedArray, TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + let a = new TA([0, 1, , 3, 4, , 6]); + let filler = 0; + if (TA.name.startsWith('Float')) { + filler = NaN; + } + assert.sameValue(a.item(0), 0, 'a.item(0) must return 0'); + assert.sameValue(a.item(1), 1, 'a.item(1) must return 1'); + assert.sameValue(a.item(2), filler, 'a.item(2) must return the value of filler'); + assert.sameValue(a.item(3), 3, 'a.item(3) must return 3'); + assert.sameValue(a.item(4), 4, 'a.item(4) must return 4'); + assert.sameValue(a.item(5), filler, 'a.item(5) must return the value of filler'); + assert.sameValue(a.item(6), 6, 'a.item(6) must return 6'); + assert.sameValue(a.item(-0), 0, 'a.item(-0) must return 0'); + assert.sameValue(a.item(-1), 6, 'a.item(-1) must return 6'); + assert.sameValue(a.item(-2), filler, 'a.item(-2) must return the value of filler'); + assert.sameValue(a.item(-3), 4, 'a.item(-3) must return 4'); + assert.sameValue(a.item(-4), 3, 'a.item(-4) must return 3'); + assert.sameValue(a.item(-5), filler, 'a.item(-5) must return the value of filler'); + assert.sameValue(a.item(-6), 1, 'a.item(-6) must return 1'); +}); diff --git a/test/built-ins/TypedArray/prototype/item/returns-undefined-for-out-of-range-index.js b/test/built-ins/TypedArray/prototype/item/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000..01384d95f0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/item/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.item +description: > + Returns undefined if the specified index less than or greater than the available index range. +info: | + %TypedArray%.prototype.item( index ) + + If k < 0 or k ≥ len, then return undefined. + +includes: [testTypedArray.js] +features: [TypedArray,TypedArray.prototype.item] +---*/ +assert.sameValue( + typeof TypedArray.prototype.item, + 'function', + 'The value of `typeof TypedArray.prototype.item` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.item, 'function', 'The value of `typeof TA.prototype.item` is "function"'); + let a = new TA([]); + + assert.sameValue(a.item(-2), undefined, 'a.item(-2) must return undefined'); // wrap around the end + assert.sameValue(a.item(0), undefined, 'a.item(0) must return undefined'); + assert.sameValue(a.item(1), undefined, 'a.item(1) must return undefined'); +});