Skip to content

Commit 393737a

Browse files
committed
Fix TerminalPositionReturnNode.executeVoid().
1 parent 18f4742 commit 393737a

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed
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)