From b45302ee0756469e874a41eb216d69e9f9e7f1e1 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 29 Jun 2015 23:59:13 +0300 Subject: [PATCH] Fix propagation of strict mode. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- jerry-core/parser/js/parser.cpp | 12 +++++++++++- tests/jerry/func-decl.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index f4e60ba9b..1d46a15fd 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -373,6 +373,8 @@ parse_property_assignment (void) return; } + bool is_outer_scope_strict = is_strict_mode (); + const operand name = parse_property_name (); syntax_add_prop_name (name, is_setter ? PROP_SET : PROP_GET); @@ -405,6 +407,9 @@ parse_property_assignment (void) inside_function = was_in_function; + scopes_tree_set_strict_mode (STACK_TOP (scopes), is_outer_scope_strict); + lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); + if (is_setter) { dump_prop_setter_decl (name, func); @@ -675,13 +680,15 @@ parse_function_expression (void) operand res; + bool is_outer_scope_strict = is_strict_mode (); + syntax_start_checking_of_vargs (); skip_newlines (); if (token_is (TOK_NAME)) { const operand name = literal_operand (token_data_as_lit_cp ()); - syntax_check_for_eval_and_arguments_in_strict_mode (name, is_strict_mode (), tok.loc); + syntax_check_for_eval_and_arguments_in_strict_mode (name, is_outer_scope_strict, tok.loc); skip_newlines (); res = parse_argument_list (VARG_FUNC_EXPR, name, NULL, NULL); @@ -717,6 +724,9 @@ parse_function_expression (void) syntax_check_for_syntax_errors_in_formal_param_list (is_strict_mode (), tok.loc); + scopes_tree_set_strict_mode (STACK_TOP (scopes), is_outer_scope_strict); + lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); + return res; } diff --git a/tests/jerry/func-decl.js b/tests/jerry/func-decl.js index 163842e26..193d24c22 100644 --- a/tests/jerry/func-decl.js +++ b/tests/jerry/func-decl.js @@ -38,3 +38,18 @@ check_syntax_error ("'use strict'; function arguments () {}"); check_syntax_error ("'use strict'; var l = function arguments () {}"); check_syntax_error ("function f__strict_mode_duplicate_parameters (p, p) { 'use strict'; }"); + +function test_strict_mode_propagation_in_func_expr_and_getters_setters () { + var p = function () { + 'use strict'; + + return true; + } + + var o = { get prop () { 'use strict'; return true; }, set prop (v) { 'use strict'; } }; + + function test () { + tmp_eval = eval; + eval = tmp_eval; + } +}