Skip to content

Commit 25bb508

Browse files
author
Peter Marki
authored
Fix await parsing in modules (#4266)
Fixes #4189 JerryScript-DCO-1.0-Signed-off-by: Peter Marki [email protected]
1 parent b2084e0 commit 25bb508

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,14 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
19071907
#if ENABLED (JERRY_ESNEXT)
19081908
case LEXER_KEYW_AWAIT:
19091909
{
1910+
#if ENABLED (JERRY_MODULE_SYSTEM)
1911+
if ((context_p->global_status_flags & ECMA_PARSE_MODULE)
1912+
&& !(context_p->status_flags & PARSER_IS_ASYNC_FUNCTION))
1913+
{
1914+
parser_raise_error (context_p, PARSER_ERR_AWAIT_NOT_ALLOWED);
1915+
}
1916+
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
1917+
19101918
if (JERRY_UNLIKELY (context_p->token.lit_location.has_escape))
19111919
{
19121920
parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD);

jerry-core/parser/js/js-parser.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,12 +3170,6 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
31703170

31713171
if (JERRY_UNLIKELY (bytecode_p == NULL))
31723172
{
3173-
#if ENABLED (JERRY_MODULE_SYSTEM)
3174-
if (JERRY_CONTEXT (module_top_context_p) != NULL)
3175-
{
3176-
ecma_module_cleanup ();
3177-
}
3178-
#endif
31793173
#if ENABLED (JERRY_DEBUGGER)
31803174
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
31813175
{
@@ -3222,6 +3216,12 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
32223216
resource_name,
32233217
line_str_val,
32243218
col_str_val);
3219+
#if ENABLED (JERRY_MODULE_SYSTEM)
3220+
if (JERRY_CONTEXT (module_top_context_p) != NULL)
3221+
{
3222+
ecma_module_cleanup ();
3223+
}
3224+
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
32253225

32263226
ecma_free_value (col_str_val);
32273227
ecma_free_value (line_str_val);

tests/jerry/fail/module-036.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import "./module-export-001.js"

tests/jerry/fail/module-037.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import "./module-await-001.js"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
await
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
export default await 1;

0 commit comments

Comments
 (0)