-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coverage: Array.prototype.item, String.prototype.item, TypedArray.pro…
- Loading branch information
Showing
34 changed files
with
942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/built-ins/Array/prototype/item/index-argument-tointeger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
20 changes: 20 additions & 0 deletions
20
test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/Array/prototype/item/index-non-numeric-argument-tointeger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Array/prototype/item/return-abrupt-from-this.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
30 changes: 30 additions & 0 deletions
30
test/built-ins/Array/prototype/item/returns-item-relative-index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
43 changes: 43 additions & 0 deletions
43
test/built-ins/Array/prototype/item/returns-undefined-for-holes-in-sparse-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
20 changes: 20 additions & 0 deletions
20
test/built-ins/Array/prototype/item/returns-undefined-for-out-of-range-index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
|
27 changes: 27 additions & 0 deletions
27
test/built-ins/String/prototype/item/index-argument-tointeger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
20 changes: 20 additions & 0 deletions
20
test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/String/prototype/item/index-non-numeric-argument-tointeger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
Oops, something went wrong.