Skip to content

Commit a44d584

Browse files
authored
Fix 'eval' checking in import/export statements. (#2978)
Fixes #2975 JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
1 parent 329b1fd commit a44d584

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

jerry-core/ecma/base/ecma-globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef enum
105105
ECMA_PARSE_HAS_SUPER = (1u << 3), /**< the current context has super reference */
106106
ECMA_PARSE_HAS_IMPL_SUPER = (1u << 4), /**< the current context has implicit parent class */
107107
ECMA_PARSE_HAS_STATIC_SUPER = (1u << 5), /**< the current context is a static class method */
108+
ECMA_PARSE_EVAL = (1u << 6), /**< eval is called */
108109
} ecma_parse_opts_t;
109110

110111
/**

jerry-core/ecma/operations/ecma-eval.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
9191
parse_opts &= (uint32_t) ~ECMA_PARSE_STRICT_MODE;
9292
}
9393

94+
parse_opts |= ECMA_PARSE_EVAL;
95+
9496
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
9597
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
9698
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */

jerry-core/parser/js/js-parser-internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ typedef enum
8282
#endif /* ENABLED (JERRY_ES2015_CLASS) */
8383
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
8484
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 25), /**< parsing a function or class default export */
85-
PARSER_MODULE_STORE_IDENT = (1u << 26), /**< store identifier of the current export statement */
85+
PARSER_MODULE_STORE_IDENT = (1u << 26), /**< store identifier of the current export statement */
86+
PARSER_IS_EVAL = (1u << 27), /**< eval code */
8687
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
8788
} parser_general_flags_t;
8889

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ parser_module_check_request_place (parser_context_t *context_p) /**< parser cont
493493
{
494494
if (context_p->last_context_p != NULL
495495
|| context_p->stack_top_uint8 != 0
496-
|| (JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL) != 0
497-
|| (context_p->status_flags & PARSER_IS_FUNCTION) != 0)
496+
|| (context_p->status_flags & (PARSER_IS_EVAL | PARSER_IS_FUNCTION)) != 0)
498497
{
499498
parser_raise_error (context_p, PARSER_ERR_MODULE_UNEXPECTED);
500499
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,11 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
23972397
context.status_flags |= parse_opts & PARSER_STRICT_MODE_MASK;
23982398

23992399
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
2400+
if (parse_opts & ECMA_PARSE_EVAL)
2401+
{
2402+
context.status_flags |= PARSER_IS_EVAL;
2403+
}
2404+
24002405
context.module_current_node_p = NULL;
24012406
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
24022407

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/export statements must be in the global scope. */
17+
var eval = eval.bind();
18+
try {
19+
eval('import { c } from "tests/jerry/es2015/module-export-01.js";');
20+
assert (false);
21+
} catch (e) {
22+
assert (e instanceof SyntaxError);
23+
}

0 commit comments

Comments
 (0)