Skip to content

Commit f44a85c

Browse files
committed
Async iterator's methods should not pass undefined to sync iterator when value is absent.
1 parent 27c54d8 commit f44a85c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 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;
@@ -146,6 +147,8 @@ private abstract static class AsyncFromSyncBaseNode extends JSBuiltinNode {
146147
@Child protected PropertyGetNode getSyncIteratorRecordNode;
147148
@Child private PropertySetNode setDoneNode;
148149

150+
protected ConditionProfile valuePresenceProfile = ConditionProfile.createBinaryProfile();
151+
149152
AsyncFromSyncBaseNode(JSContext context, JSBuiltin builtin) {
150153
super(context, builtin);
151154
this.newPromiseCapabilityNode = NewPromiseCapabilityNode.create(context);
@@ -255,7 +258,7 @@ public AsyncFromSyncNext(JSContext context, JSBuiltin builtin) {
255258
}
256259

257260
@Specialization(guards = "isObject(thisObj)")
258-
protected Object next(DynamicObject thisObj, Object value) {
261+
protected Object next(VirtualFrame frame, DynamicObject thisObj, Object value) {
259262
PromiseCapabilityRecord promiseCapability = createPromiseCapability();
260263
if (!isAsyncFromSyncIterator(thisObj)) {
261264
JSException typeError = Errors.createTypeErrorIncompatibleReceiver(thisObj);
@@ -265,7 +268,11 @@ protected Object next(DynamicObject thisObj, Object value) {
265268
DynamicObject nextResult;
266269
IteratorRecord syncIteratorRecord = (IteratorRecord) getSyncIteratorRecordNode.getValue(thisObj);
267270
try {
268-
nextResult = iteratorNextNode.execute(syncIteratorRecord, value);
271+
if (valuePresenceProfile.profile(JSArguments.getUserArgumentCount(frame.getArguments()) == 0)) {
272+
nextResult = iteratorNextNode.execute(syncIteratorRecord);
273+
} else {
274+
nextResult = iteratorNextNode.execute(syncIteratorRecord, value);
275+
}
269276
} catch (GraalJSException e) {
270277
promiseCapabilityReject(promiseCapability, e);
271278
return promiseCapability.getPromise();
@@ -303,7 +310,11 @@ protected Object doMethod(VirtualFrame frame, DynamicObject thisObj, Object valu
303310
}
304311
Object returnResult;
305312
try {
306-
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method, value));
313+
if (valuePresenceProfile.profile(JSArguments.getUserArgumentCount(frame.getArguments()) == 0)) {
314+
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method));
315+
} else {
316+
returnResult = executeReturnMethod.executeCall(JSArguments.create(syncIterator, method, value));
317+
}
307318
} catch (GraalJSException e) {
308319
promiseCapabilityReject(promiseCapability, e);
309320
return promiseCapability.getPromise();

0 commit comments

Comments
 (0)