Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
898 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
test/suite/es7/Array.prototype.contains/Array.prototype.contains_adding-getter.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) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains sees a new element added by a getter that is hit during iteration | ||
author: Domenic Denicola | ||
---*/ | ||
|
||
var arrayLike = { | ||
length: 5, | ||
0: 'a', | ||
get 1() { | ||
this[2] = 'c'; | ||
return 'b'; | ||
} | ||
}; | ||
|
||
var result = Array.prototype.contains.call(arrayLike, 'c'); | ||
|
||
if (result !== true) { | ||
$ERROR('Expected array-like to contain "c", which was added by the getter for the 1st element'); | ||
} |
31 changes: 31 additions & 0 deletions
31
test/suite/es7/Array.prototype.contains/Array.prototype.contains_array-like.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,31 @@ | ||
// Copyright (C) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains works on array-like objects | ||
author: Domenic Denicola | ||
---*/ | ||
|
||
var arrayLike1 = { length: 5, 0: "a", 1: "b" }; | ||
|
||
var result1 = Array.prototype.contains.call(arrayLike1, "a"); | ||
if (result1 !== true) { | ||
$ERROR('Expected array-like to contain "a"'); | ||
} | ||
|
||
var result2 = Array.prototype.contains.call(arrayLike1, "c"); | ||
if (result2 !== false) { | ||
$ERROR('Expected array-like not to contain "c"'); | ||
} | ||
|
||
var arrayLike2 = { length: 2, 0: "a", 1: "b", 2: "c" }; | ||
|
||
var result3 = Array.prototype.contains.call(arrayLike2, "b"); | ||
if (result3 !== true) { | ||
$ERROR('Expected array-like to contain "b"'); | ||
} | ||
|
||
var result4 = Array.prototype.contains.call(arrayLike2, "c"); | ||
if (result4 !== false) { | ||
$ERROR('Expected array-like to not contain "c"'); | ||
} |
20 changes: 20 additions & 0 deletions
20
test/suite/es7/Array.prototype.contains/Array.prototype.contains_exception-before-match.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) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if getting an index throws an exception | ||
negative: Test262Error | ||
includes: [Test262Error.js] | ||
---*/ | ||
|
||
var trappedZero = { | ||
length: 2, | ||
get 0() { | ||
throw new Test262Error('This error should be re-thrown'); | ||
}, | ||
get 1() { | ||
$ERROR('Should not try to get the first element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(trappedZero, 'a'); |
16 changes: 16 additions & 0 deletions
16
...uite/es7/Array.prototype.contains/Array.prototype.contains_exception-from-index-symbol.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,16 @@ | ||
// Copyright (C) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if ToNumber ends up being called on a symbol fromIndex | ||
negative: TypeError | ||
---*/ | ||
|
||
var trappedZero = { | ||
length: 1, | ||
get 0() { | ||
$ERROR('Should not try to get the zeroth element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(trappedZero, 'a', Symbol()); |
23 changes: 23 additions & 0 deletions
23
...ray.prototype.contains/Array.prototype.contains_exception-from-index-throwing-value-of.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,23 @@ | ||
// Copyright (C) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if an exception occurs converting the fromIndex to a number | ||
negative: Test262Error | ||
includes: [Test262Error.js] | ||
---*/ | ||
|
||
var fromIndex = { | ||
valueOf: function () { | ||
throw new Test262Error('This error should be re-thrown'); | ||
} | ||
}; | ||
|
||
var trappedZero = { | ||
length: 1, | ||
get 0() { | ||
$ERROR('Should not try to get the zeroth element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(trappedZero, 'a', fromIndex); |
25 changes: 25 additions & 0 deletions
25
test/suite/es7/Array.prototype.contains/Array.prototype.contains_exception-get-length.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,25 @@ | ||
// Copyright (C) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if an exception occurs getting the length | ||
negative: Test262Error | ||
includes: [Test262Error.js] | ||
---*/ | ||
|
||
var fromIndexTrap = { | ||
valueOf: function () { | ||
$ERROR('Should not try to call ToInteger on valueOf'); | ||
} | ||
} | ||
|
||
var throwingLength = { | ||
get length() { | ||
throw new Test262Error('This error should be re-thrown'); | ||
}, | ||
get 0() { | ||
$ERROR('Should not try to get the zeroth element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(throwingLength, 'a', fromIndexTrap); |
22 changes: 22 additions & 0 deletions
22
...suite/es7/Array.prototype.contains/Array.prototype.contains_exception-to-length-symbol.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) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if ToLength ends up being called on a symbol length | ||
negative: TypeError | ||
---*/ | ||
|
||
var fromIndexTrap = { | ||
valueOf: function () { | ||
$ERROR('Should not try to call ToInteger on valueOf'); | ||
} | ||
}; | ||
|
||
var badLength = { | ||
length: Symbol(), | ||
get 0() { | ||
$ERROR('Should not try to get the zeroth element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(badLength, 'a', fromIndexTrap); |
27 changes: 27 additions & 0 deletions
27
...rray.prototype.contains/Array.prototype.contains_exception-to-length-throwing-value-of.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) 2014 Domenic Denicola. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should terminate if an exception occurs converting the length to a number | ||
negative: Test262Error | ||
includes: [Test262Error.js] | ||
---*/ | ||
|
||
var fromIndexTrap = { | ||
valueOf: function () { | ||
$ERROR('Should not try to call ToInteger on valueOf'); | ||
} | ||
}; | ||
|
||
var badLength = { | ||
length: { | ||
valueOf: function () { | ||
throw new Test262Error('This error should be re-thrown'); | ||
} | ||
}, | ||
get 0() { | ||
$ERROR('Should not try to get the zeroth element'); | ||
} | ||
}; | ||
|
||
Array.prototype.contains.call(badLength, 'a', fromIndexTrap); |
34 changes: 34 additions & 0 deletions
34
test/suite/es7/Array.prototype.contains/Array.prototype.contains_from-index-default.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,34 @@ | ||
// Copyright (C) 2014 Robert Kowalski. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should search the whole array, as | ||
the optional second argument fromIndex defaults to 0 | ||
author: Robert Kowalski | ||
---*/ | ||
|
||
if ([10, 11].contains(10) !== true) { | ||
$ERROR('Expected that the whole array was searched'); | ||
} | ||
|
||
if ([10, 11].contains(11) !== true) { | ||
$ERROR('Expected that the whole array was searched'); | ||
} | ||
|
||
var arrayLike = { | ||
length: 2, | ||
get 0() { | ||
return '1'; | ||
}, | ||
get 1() { | ||
return '2'; | ||
} | ||
}; | ||
|
||
if (Array.prototype.contains.call(arrayLike, '1') !== true) { | ||
$ERROR('Expected that the whole array-like was searched'); | ||
} | ||
|
||
if (Array.prototype.contains.call(arrayLike, '2') !== true) { | ||
$ERROR('Expected that the whole array-like was searched'); | ||
} |
34 changes: 34 additions & 0 deletions
34
.../es7/Array.prototype.contains/Array.prototype.contains_from-index-greater-equal-length.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,34 @@ | ||
// Copyright (C) 2014 Robert Kowalski. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains returns false if fromIndex | ||
is greater or equal to the length of the array | ||
author: Robert Kowalski | ||
---*/ | ||
|
||
if ([1, 2].contains(2, 3) !== false) { | ||
$ERROR('Expected that the array was not searched'); | ||
} | ||
|
||
if ([1, 2].contains(2, 2) !== false) { | ||
$ERROR('Expected that the array was not searched'); | ||
} | ||
|
||
var arrayLikeWithTrap = { | ||
length: 2, | ||
get 0() { | ||
$ERROR('Getter for 0 was called'); | ||
}, | ||
get 1() { | ||
$ERROR('Getter for 1 was called'); | ||
} | ||
}; | ||
|
||
if (Array.prototype.contains.call(arrayLikeWithTrap, 'c', 2) !== false) { | ||
$ERROR('Expected that the array was not searched'); | ||
} | ||
|
||
if (Array.prototype.contains.call(arrayLikeWithTrap, 'c', 3) !== false) { | ||
$ERROR('Expected that the array was not searched'); | ||
} |
33 changes: 33 additions & 0 deletions
33
...7/Array.prototype.contains/Array.prototype.contains_from-index-negative-computed-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,33 @@ | ||
// Copyright (C) 2014 Robert Kowalski. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains searches the whole array | ||
if the computed index from the given negative fromIndex | ||
argument is less than 0 | ||
author: Robert Kowalski | ||
---*/ | ||
|
||
if ([1, 3].contains(1, -4) !== true) { | ||
$ERROR('Expected that the whole array was searched'); | ||
} | ||
|
||
if ([1, 3].contains(3, -4) !== true) { | ||
$ERROR('Expected that the whole array was searched'); | ||
} | ||
|
||
var arrayLike = { | ||
length: 2, | ||
0: 'a', | ||
get 1() { | ||
return 'b'; | ||
} | ||
}; | ||
|
||
if (Array.prototype.contains.call(arrayLike, 'a', -4) !== true) { | ||
$ERROR('Expected that the whole array-like was searched'); | ||
} | ||
|
||
if (Array.prototype.contains.call(arrayLike, 'b', -4) !== true) { | ||
$ERROR('Expected that the whole array-like was searched'); | ||
} |
42 changes: 42 additions & 0 deletions
42
.../suite/es7/Array.prototype.contains/Array.prototype.contains_from-index-negative-value.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,42 @@ | ||
// Copyright (C) 2014 Robert Kowalski. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Array.prototype.contains should use a negative value | ||
as the offset from the end of the array to compute fromIndex | ||
author: Robert Kowalski | ||
---*/ | ||
|
||
if ([12, 13].contains(13, -1) !== true) { | ||
$ERROR('Expected to find 13'); | ||
} | ||
|
||
if ([12, 13].contains(12, -1) !== false) { | ||
$ERROR('Should not find 12'); | ||
} | ||
|
||
if ([12, 13].contains(12, -2) !== true) { | ||
$ERROR('Should find 12'); | ||
} | ||
|
||
var arrayLike = { | ||
length: 2, | ||
get 0() { | ||
return 'a'; | ||
}, | ||
get 1() { | ||
return 'b'; | ||
} | ||
}; | ||
|
||
if (Array.prototype.contains.call(arrayLike, 'b', -1) !== true) { | ||
$ERROR('Expected to find b'); | ||
} | ||
|
||
if (Array.prototype.contains.call(arrayLike, 'a', -1) !== false) { | ||
$ERROR('Should not find a'); | ||
} | ||
|
||
if (Array.prototype.contains.call(arrayLike, 'a', -2) !== true) { | ||
$ERROR('Should find a'); | ||
} |
Oops, something went wrong.