Skip to content

Commit 2ce4ba6

Browse files
hachim-hassanielkorchi
authored andcommitted
[GR-59077] Backport to 24.1: Fix of top-level for-await-of in a module.
PullRequest: js/3338
2 parents 293dfbd + 58e33f2 commit 2ce4ba6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/Parser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,13 @@ private void forStatement(boolean yield, boolean await) {
29572957
if (!await) {
29582958
throw error(AbstractParser.message(MSG_INVALID_FOR_AWAIT_OF), token);
29592959
}
2960+
if (isModule) {
2961+
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
2962+
if (currentFunction.isModule()) {
2963+
// Top-level for-await: mark the module function as async.
2964+
currentFunction.setFlag(FunctionNode.IS_ASYNC);
2965+
}
2966+
}
29602967
isForAwaitOf = true;
29612968
next();
29622969
}

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/ParserContextFunctionNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, 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
@@ -167,7 +167,7 @@ public boolean isStrict() {
167167
}
168168

169169
/**
170-
* @return if function in strict mode
170+
* @return true if the function is a module.
171171
*/
172172
public boolean isModule() {
173173
return getFlag(FunctionNode.IS_MODULE) != 0;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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+
* Regression test of the usage of for-await-of in the body of a module.
10+
*/
11+
12+
let sum = 0;
13+
for await (let x of [42, 211]) sum += x;
14+
if (sum !== 42 + 211) {
15+
throw new Error("Sum of 24 and 211 is not " + sum);
16+
}

0 commit comments

Comments
 (0)