From 0422e2230dda50bd0d66f2ed9862597b3cddff82 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 29 Jun 2015 23:42:49 +0300 Subject: [PATCH] Fix syntax check for case 'eval' or 'arguments' identifiers are used for name of function in strict mode. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- jerry-core/parser/js/parser.cpp | 4 ++++ tests/jerry/func-decl.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 5d93fad7c..ff9767d8d 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -631,6 +631,8 @@ parse_function_declaration (void) token_after_newlines_must_be (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); + skip_newlines (); STACK_PUSH (scopes, scopes_tree_init (STACK_TOP (scopes))); serializer_set_scope (STACK_TOP (scopes)); @@ -678,6 +680,8 @@ parse_function_expression (void) 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); + skip_newlines (); res = parse_argument_list (VARG_FUNC_EXPR, name, NULL, NULL); } diff --git a/tests/jerry/func-decl.js b/tests/jerry/func-decl.js index e3d725575..97d0ace93 100644 --- a/tests/jerry/func-decl.js +++ b/tests/jerry/func-decl.js @@ -23,3 +23,16 @@ assert ((function() { } return f(); })() === 'bar'); + +function check_syntax_error (s) { + try { + eval (s); + assert (false); + } + catch (e) { + assert (e instanceof SyntaxError); + } +} + +check_syntax_error ("'use strict'; function arguments () {}"); +check_syntax_error ("'use strict'; var l = function arguments () {}");