这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit a9b3c90

Browse files
committed
[JSC] %WrapForValidIteratorPrototype%.return should not throw TypeError when underlying iterator's return method is null
https://bugs.webkit.org/show_bug.cgi?id=288714 Reviewed by Yusuke Suzuki. According to the spec[1], `%WrapForValidIteratorPrototype%.return` returns `{ done: true, value: undefined }` if the underlying iterator's `return` method is `null` or `undefined`. However, our JSC throws `TypeError` if the underlying iterator's `return` method is `null`. This patch fixes it to comply with the spec. [1]: https://tc39.es/ecma262/#sec-%wrapforvaliditeratorprototype%.return * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/builtins/WrapForValidIteratorPrototype.js: (return): Canonical link: https://commits.webkit.org/291302@main
1 parent ebd79f4 commit a9b3c90

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function shouldBe(a, b) {
2+
if (a !== b)
3+
throw new Error(`Expected ${b} but got ${a}`);
4+
}
5+
6+
const iter = {
7+
next() { return { done: false, value: 1 } },
8+
return(value) { return { done: true, value } },
9+
};
10+
const wrap = Iterator.from(iter);
11+
12+
iter.return = null;
13+
const returnResult = wrap.return("ignored");
14+
shouldBe(returnResult.done, true);
15+
shouldBe(returnResult.value, undefined);

JSTests/test262/expectations.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,6 @@ test/staging/sm/Function/function-name-assignment.js:
13321332
default: 'Test262Error: Expected SameValue(«"inParen"», «""») to be true'
13331333
test/staging/sm/Function/function-toString-builtin-name.js:
13341334
default: 'Test262Error: Incorrect match for undefined Expected SameValue(«"fn"», «undefined») to be true'
1335-
test/staging/sm/Iterator/from/modify-return.js:
1336-
default: 'TypeError: null is not a function'
13371335
test/staging/sm/Iterator/prototype/every/check-fn-after-getting-iterator.js:
13381336
default: 'Test262Error: Actual [get: every, get: return] and expected [get: every] should have the same contents. '
13391337
test/staging/sm/Iterator/prototype/find/check-fn-after-getting-iterator.js:

Source/JavaScriptCore/builtins/WrapForValidIteratorPrototype.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function return()
5757
var returnMethod = iterator.return;
5858
// 6. If returnMethod is undefined, then
5959
// a. Return CreateIterResultObject(undefined, true).
60-
if (returnMethod === @undefined)
60+
if (@isUndefinedOrNull(returnMethod))
6161
return { value: @undefined, done: true };
6262
// 7. Return ? Call(returnMethod, iterator).
6363
return returnMethod.@call(iterator);

0 commit comments

Comments
 (0)