Skip to content

Commit f4d4a44

Browse files
committed
[GR-42335] Backport GR-42288 to 22.3: Returning void await this in async function.
PullRequest: js/2644
2 parents 10aa178 + 393737a commit f4d4a44

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

common.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local common_json = (import "common.json");
3434

3535
local common = {
3636
packages+: {
37-
'mx': 'HEAD',
37+
'mx': '6.9.1',
3838
'python3': '==3.8.10',
3939
'pip:pylint': '==2.4.4',
4040
'pip:ninja_syntax': '==1.7.2',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* [Bug]: Returning void await this in async function with parameter.
10+
* https://github.com/oracle/graaljs/issues/672
11+
*
12+
* @option unhandled-rejections=throw
13+
*/
14+
15+
load('assert.js');
16+
17+
let f = async (x) => void await this;
18+
f();

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/control/ReturnNode.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -53,7 +53,7 @@
5353
* 12.9 The return Statement.
5454
*/
5555
@NodeInfo(shortName = "return")
56-
public class ReturnNode extends StatementNode {
56+
public abstract class ReturnNode extends StatementNode {
5757

5858
@Child protected JavaScriptNode expression;
5959

@@ -66,7 +66,7 @@ public static ReturnNode create(JavaScriptNode expression) {
6666
return new ConstantReturnNode(expression);
6767
} else {
6868
assert !(expression instanceof EmptyNode);
69-
return new ReturnNode(expression);
69+
return new ReturnValueInExceptionNode(expression);
7070
}
7171
}
7272

@@ -92,14 +92,10 @@ public static ReturnNode createTerminalPositionReturn(JavaScriptNode expression)
9292
}
9393

9494
@Override
95-
public Object execute(VirtualFrame frame) {
96-
throw new ReturnException(expression.execute(frame));
97-
}
95+
public abstract Object execute(VirtualFrame frame);
9896

9997
@Override
100-
public void executeVoid(VirtualFrame frame) {
101-
throw new ReturnException(expression.execute(frame));
102-
}
98+
public abstract void executeVoid(VirtualFrame frame);
10399

104100
@Override
105101
protected JavaScriptNode copyUninitialized(Set<Class<? extends Tag>> materializedTags) {
@@ -113,6 +109,23 @@ public boolean isResultAlwaysOfType(Class<?> clazz) {
113109
return expression.isResultAlwaysOfType(clazz);
114110
}
115111

112+
private static class ReturnValueInExceptionNode extends ReturnNode {
113+
114+
protected ReturnValueInExceptionNode(JavaScriptNode expression) {
115+
super(expression);
116+
}
117+
118+
@Override
119+
public Object execute(VirtualFrame frame) {
120+
throw new ReturnException(expression.execute(frame));
121+
}
122+
123+
@Override
124+
public void executeVoid(VirtualFrame frame) {
125+
throw new ReturnException(expression.execute(frame));
126+
}
127+
}
128+
116129
private static class ConstantReturnNode extends ReturnNode {
117130

118131
private final ReturnException exception;
@@ -164,6 +177,11 @@ protected TerminalPositionReturnNode(JavaScriptNode expression) {
164177
public Object execute(VirtualFrame frame) {
165178
return expression.execute(frame);
166179
}
180+
181+
@Override
182+
public void executeVoid(VirtualFrame frame) {
183+
expression.executeVoid(frame);
184+
}
167185
}
168186

169187
}

0 commit comments

Comments
 (0)