Skip to content

Commit 0d853db

Browse files
committed
[GR-22253] Async iterator's methods should not pass undefined to sync iterator when value is absent.
PullRequest: js/1453
2 parents 27c54d8 + 381df0f commit 0d853db

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/AsyncFromSyncIteratorPrototypeBuiltins.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
4848
import com.oracle.truffle.api.nodes.UnexpectedResultException;
4949
import com.oracle.truffle.api.object.DynamicObject;
5050
import com.oracle.truffle.api.object.HiddenKey;
51+
import com.oracle.truffle.api.profiles.ConditionProfile;
5152
import com.oracle.truffle.js.builtins.AsyncFromSyncIteratorPrototypeBuiltinsFactory.AsyncFromSyncNextNodeGen;
5253
import com.oracle.truffle.js.builtins.AsyncFromSyncIteratorPrototypeBuiltinsFactory.AsyncFromSyncReturnNodeGen;
5354
import com.oracle.truffle.js.builtins.AsyncFromSyncIteratorPrototypeBuiltinsFactory.AsyncFromSyncThrowNodeGen;
@@ -132,7 +133,6 @@ private abstract static class AsyncFromSyncBaseNode extends JSBuiltinNode {
132133
static final HiddenKey DONE = new HiddenKey("Done");
133134

134135
@Child private PropertyGetNode getPromiseNode;
135-
@Child private PropertyGetNode getPromiseResolveNode;
136136

137137
@Child private JSFunctionCallNode executePromiseMethodNode;
138138
@Child private NewPromiseCapabilityNode newPromiseCapabilityNode;
@@ -146,6 +146,8 @@ private abstract static class AsyncFromSyncBaseNode extends JSBuiltinNode {
146146
@Child protected PropertyGetNode getSyncIteratorRecordNode;
147147
@Child private PropertySetNode setDoneNode;
148148

149+
protected ConditionProfile valuePresenceProfile = ConditionProfile.createBinaryProfile();
150+
149151
AsyncFromSyncBaseNode(JSContext context, JSBuiltin builtin) {
150152
super(context, builtin);
151153
this.newPromiseCapabilityNode = NewPromiseCapabilityNode.create(context);
@@ -255,7 +257,7 @@ public AsyncFromSyncNext(JSContext context, JSBuiltin builtin) {
255257
}
256258

257259
@Specialization(guards = "isObject(thisObj)")
258-
protected Object next(DynamicObject thisObj, Object value) {
260+
protected Object next(VirtualFrame frame, DynamicObject thisObj, Object value) {
259261
PromiseCapabilityRecord promiseCapability = createPromiseCapability();
260262
if (!isAsyncFromSyncIterator(thisObj)) {
261263
JSException typeError = Errors.createTypeErrorIncompatibleReceiver(thisObj);
@@ -265,7 +267,11 @@ protected Object next(DynamicObject thisObj, Object value) {
265267
DynamicObject nextResult;
266268
IteratorRecord syncIteratorRecord = (IteratorRecord) getSyncIteratorRecordNode.getValue(thisObj);
267269
try {
268-
nextResult = iteratorNextNode.execute(syncIteratorRecord, value);
270+
if (valuePresenceProfile.profile(JSArguments.getUserArgumentCount(frame.getArguments()) == 0)) {
271+
nextResult = iteratorNextNode.execute(syncIteratorRecord);
272+
} else {
273+
nextResult = iteratorNextNode.execute(syncIteratorRecord, value);
274+
}
269275
} catch (GraalJSException e) {
270276
promiseCapabilityReject(promiseCapability, e);
271277
return promiseCapability.getPromise();
@@ -303,7 +309,11 @@ protected Object doMethod(VirtualFrame frame, DynamicObject thisObj, Object valu
303309
}
304310
Object returnResult;
305311
try {
306-
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method, value));
312+
if (valuePresenceProfile.profile(JSArguments.getUserArgumentCount(frame.getArguments()) == 0)) {
313+
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method));
314+
} else {
315+
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method, value));
316+
}
307317
} catch (GraalJSException e) {
308318
promiseCapabilityReject(promiseCapability, e);
309319
return promiseCapability.getPromise();

graal-js/test/test262.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"testFiles" : [ {
33
"filePath" : "built-ins/AsyncFromSyncIteratorPrototype/next/absent-value-not-passed.js",
44
"status" : "FAIL",
5-
"comment" : "new failures update 2020-04-01"
5+
"comment" : "Incorrect test, see https://github.com/tc39/test262/pull/2551#issuecomment-609595231"
66
}, {
77
"filePath" : "built-ins/AsyncFromSyncIteratorPrototype/return/absent-value-not-passed.js",
88
"status" : "FAIL",
9-
"comment" : "new failures update 2020-04-01"
9+
"comment" : "Incorrect test, see https://github.com/tc39/test262/pull/2551#issuecomment-609595231"
1010
}, {
1111
"filePath" : "built-ins/AsyncFromSyncIteratorPrototype/throw/absent-value-not-passed.js",
1212
"status" : "FAIL",
13-
"comment" : "new failures update 2020-04-01"
13+
"comment" : "Incorrect test, see https://github.com/tc39/test262/pull/2551#issuecomment-609595231"
1414
}, {
1515
"filePath" : "built-ins/RegExp/property-escapes/generated/Alphabetic.js",
1616
"status" : "SKIP",

0 commit comments

Comments
 (0)