-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for "iterator helpers close receiver on argument validation…
… failure"
- Loading branch information
Showing
10 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
test/built-ins/Iterator/prototype/drop/underlying-iterator-closed-when-argument-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,46 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.drop | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.drop ( limit ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(RangeError, function() { | ||
closable.drop(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(RangeError, function() { | ||
closable.drop(NaN); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(RangeError, function() { | ||
closable.drop(-1); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(Test262Error, function() { | ||
closable.drop({ get valueOf() { throw new Test262Error(); }}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/every/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.every | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.every ( predicate ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.every(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.every({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/filter/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.filter | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.filter ( predicate ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.filter(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.filter({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/find/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.find | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.find ( predicate ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.find(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.find({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
.../built-ins/Iterator/prototype/flatMap/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.flatMap | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.flatMap ( mapper ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.flatMap(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.flatMap({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
.../built-ins/Iterator/prototype/forEach/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.forEach | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.forEach ( predicate ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.forEach(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.forEach({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/map/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.map | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.map ( mapper ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.map(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.map({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/reduce/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.reduce | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.reduce ( reducer, [ initialValue ] ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.reduce(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.reduce({}); | ||
}); | ||
assert.sameValue(closed, true); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Iterator/prototype/some/underlying-iterator-closed-when-argument-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,34 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.some | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.some ( predicate ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(TypeError, function() { | ||
closable.some(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(TypeError, function() { | ||
closable.some({}); | ||
}); | ||
assert.sameValue(closed, true); |
46 changes: 46 additions & 0 deletions
46
test/built-ins/Iterator/prototype/take/underlying-iterator-closed-when-argument-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,46 @@ | ||
// Copyright (C) 2024 Kevin Gibbons. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iteratorprototype.take | ||
description: > | ||
Underlying iterator is closed when argument validation fails | ||
info: | | ||
%Iterator.prototype%.take ( limit ) | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let closed = false; | ||
let closable = { | ||
__proto__: Iterator.prototype, | ||
get next() { | ||
throw new Test262Error('next should not be read'); | ||
}, | ||
return() { | ||
closed = true; | ||
}, | ||
}; | ||
|
||
assert.throws(RangeError, function() { | ||
closable.take(); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(RangeError, function() { | ||
closable.take(NaN); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(RangeError, function() { | ||
closable.take(-1); | ||
}); | ||
assert.sameValue(closed, true); | ||
|
||
closed = false; | ||
assert.throws(Test262Error, function() { | ||
closable.take({ get valueOf() { throw new Test262Error(); }}); | ||
}); | ||
assert.sameValue(closed, true); |