-
Notifications
You must be signed in to change notification settings - Fork 464
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
%WrapForValidIteratorPrototype%.return()
- Loading branch information
1 parent
d62fa93
commit f617443
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
test/built-ins/Iterator/from/get-return-method-when-call-return.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,29 @@ | ||
// Copyright (C) 2024 Sosuke Suzuki. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iterator.from | ||
description: > | ||
Gets the base iterator return method when the wrapper return method is called. | ||
info: | | ||
%WrapForValidIteratorPrototype%.return ( ) | ||
... | ||
5. Let returnMethod be ? GetMethod(iterator, "return"). | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let returnGetCount = 0; | ||
const iter = { | ||
get return() { | ||
returnGetCount++; | ||
return function () { | ||
return { value: 5, done: true }; | ||
}; | ||
}, | ||
}; | ||
const wrapper = Iterator.from(iter); | ||
assert.sameValue(returnGetCount, 0); | ||
|
||
wrapper.return(); | ||
assert.sameValue(returnGetCount, 1); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Iterator/from/return-method-calls-base-return-method.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,29 @@ | ||
// Copyright (C) 2024 Sosuke Suzuki. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iterator.from | ||
description: > | ||
%WrapForValidIteratorPrototype%.return() call base iterator's return method when it exists. | ||
info: | | ||
%WrapForValidIteratorPrototype%.return ( ) | ||
5. Let returnMethod be ? GetMethod(iterator, "return"). | ||
6. If returnMethod is undefined, then | ||
... | ||
7. Return ? Call(returnMethod, iterator). | ||
includes: [deepEqual.js] | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
let returnCallCount = 0; | ||
const iter = { | ||
return () { | ||
returnCallCount++; | ||
return { value: 5, done: true }; | ||
}, | ||
}; | ||
const wrapper = Iterator.from(iter); | ||
|
||
assert.deepEqual(wrapper.return(), { value: 5, done: true }); | ||
assert.sameValue(returnCallCount, 1); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Iterator/from/return-method-returns-iterator-result.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) 2024 Sosuke Suzuki. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iterator.from | ||
description: > | ||
%WrapForValidIteratorPrototype%.return() should return an iterator result object that value is undefined when base object does not have return method. | ||
info: | | ||
%WrapForValidIteratorPrototype%.return ( ) | ||
... | ||
5. Let returnMethod be ? GetMethod(iterator, "return"). | ||
6. If returnMethod is undefined, then | ||
a. Return CreateIterResultObject(undefined, true). | ||
includes: [deepEqual.js] | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
const iter = {}; | ||
const wrapper = Iterator.from(iter); | ||
|
||
assert.deepEqual(wrapper.return(), { value: undefined, done: true }); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/Iterator/from/return-method-throws-for-invalid-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,32 @@ | ||
// Copyright (C) 2024 Sosuke Suzuki. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-iterator.from | ||
description: > | ||
%WrapForValidIteratorPrototype%.return() requires [[iterated]] internal slot | ||
info: | | ||
%WrapForValidIteratorPrototype%.return ( ) | ||
... | ||
2. Perform ? RequireInternalSlot(O, [[Iterated]]). | ||
features: [iterator-helpers] | ||
flags: [] | ||
---*/ | ||
|
||
const iter = {}; | ||
const WrapForValidIteratorPrototype = Object.getPrototypeOf(Iterator.from(iter)); | ||
|
||
assert.throws(TypeError, function() { | ||
WrapForValidIteratorPrototype.return.call({}); | ||
}); | ||
|
||
let returnCallCount = 0; | ||
assert.throws(TypeError, function() { | ||
WrapForValidIteratorPrototype.return.call({ | ||
return () { | ||
returnCallCount++; | ||
return { value: 5, done: true }; | ||
} | ||
}); | ||
}); | ||
assert.sameValue(returnCallCount, 0); |