diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index f7d3e2959..09663068d 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -1907,6 +1907,14 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */ #if ENABLED (JERRY_ESNEXT) case LEXER_KEYW_AWAIT: { +#if ENABLED (JERRY_MODULE_SYSTEM) + if ((context_p->global_status_flags & ECMA_PARSE_MODULE) + && !(context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)) + { + parser_raise_error (context_p, PARSER_ERR_AWAIT_NOT_ALLOWED); + } +#endif /* ENABLED (JERRY_MODULE_SYSTEM) */ + if (JERRY_UNLIKELY (context_p->token.lit_location.has_escape)) { parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 29ba50bbd..75576c7d6 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -3170,12 +3170,6 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */ if (JERRY_UNLIKELY (bytecode_p == NULL)) { -#if ENABLED (JERRY_MODULE_SYSTEM) - if (JERRY_CONTEXT (module_top_context_p) != NULL) - { - ecma_module_cleanup (); - } -#endif #if ENABLED (JERRY_DEBUGGER) if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) { @@ -3222,6 +3216,12 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */ resource_name, line_str_val, col_str_val); +#if ENABLED (JERRY_MODULE_SYSTEM) + if (JERRY_CONTEXT (module_top_context_p) != NULL) + { + ecma_module_cleanup (); + } +#endif /* ENABLED (JERRY_MODULE_SYSTEM) */ ecma_free_value (col_str_val); ecma_free_value (line_str_val); diff --git a/tests/jerry/fail/module-036.js b/tests/jerry/fail/module-036.js new file mode 100644 index 000000000..8550de8ad --- /dev/null +++ b/tests/jerry/fail/module-036.js @@ -0,0 +1,16 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import "./module-export-001.js" diff --git a/tests/jerry/fail/module-037.js b/tests/jerry/fail/module-037.js new file mode 100644 index 000000000..29f3dba46 --- /dev/null +++ b/tests/jerry/fail/module-037.js @@ -0,0 +1,16 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import "./module-await-001.js" diff --git a/tests/jerry/fail/module-await-001.js b/tests/jerry/fail/module-await-001.js new file mode 100644 index 000000000..f13376e01 --- /dev/null +++ b/tests/jerry/fail/module-await-001.js @@ -0,0 +1,16 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +await diff --git a/tests/jerry/fail/module-export-001.js b/tests/jerry/fail/module-export-001.js new file mode 100644 index 000000000..9c8c12033 --- /dev/null +++ b/tests/jerry/fail/module-export-001.js @@ -0,0 +1,16 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default await 1;