From ec6572d501e7c0739b2aab74fc7b413b1bcc5c44 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 21 Oct 2014 22:22:04 +0400 Subject: [PATCH] Add support of function expressions scopes. Uncomment tests. --- src/libcoreint/opcodes.c | 9 +++++++-- src/libjsparser/parser.c | 12 ++++++++++++ tests/jerry/N.func_expr_strict.js | 19 +++++++++++++++++++ tests/jerry/{N.delete.js => delete.js} | 0 tests/jerry/{N.this_arg.js => this_arg.js} | 0 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/jerry/N.func_expr_strict.js rename tests/jerry/{N.delete.js => delete.js} (100%) rename tests/jerry/{N.this_arg.js => this_arg.js} (100%) diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index d71656757..0847e785c 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -1663,12 +1663,17 @@ opfunc_meta (opcode_t opdata, /**< operation data */ { return ecma_make_meta_completion_value (); } + + case OPCODE_META_TYPE_STRICT_CODE: + { + FIXME (/* Handle in run_int_from_pos */); + return ecma_make_meta_completion_value (); + } + case OPCODE_META_TYPE_UNDEFINED: case OPCODE_META_TYPE_THIS_ARG: - case OPCODE_META_TYPE_FUNCTION_END: case OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER: - case OPCODE_META_TYPE_STRICT_CODE: { JERRY_UNREACHABLE (); } diff --git a/src/libjsparser/parser.c b/src/libjsparser/parser.c index c2b44b379..a1dcdbbf1 100644 --- a/src/libjsparser/parser.c +++ b/src/libjsparser/parser.c @@ -1331,6 +1331,7 @@ parse_function_expression (void) STACK_DECLARE_USAGE (IDX) STACK_DECLARE_USAGE (U16) STACK_DECLARE_USAGE (nestings) + STACK_DECLARE_USAGE (U8) assert_keyword (KW_FUNCTION); @@ -1353,11 +1354,17 @@ parse_function_expression (void) token_after_newlines_must_be (TOK_OPEN_BRACE); + STACK_PUSH (U8, scopes_tree_strict_mode (STACK_TOP (scopes)) ? 1 : 0); + scopes_tree_set_strict_mode (STACK_TOP (scopes), false); + skip_newlines (); push_nesting (NESTING_FUNCTION); parse_source_element_list (false); pop_nesting (NESTING_FUNCTION); + scopes_tree_set_strict_mode (STACK_TOP (scopes), STACK_TOP (U8) != 0); + STACK_DROP (U8, 1); + next_token_must_be (TOK_CLOSE_BRACE); DUMP_VOID_OPCODE (ret); @@ -1367,6 +1374,7 @@ parse_function_expression (void) STACK_DROP (IDX, 1); STACK_DROP (U16, 1); + STACK_CHECK_USAGE (U8); STACK_CHECK_USAGE (U16); STACK_CHECK_USAGE_LHS (); STACK_CHECK_USAGE (nestings); @@ -3837,10 +3845,14 @@ preparse_scope (bool is_global) } else if (is_keyword (KW_FUNCTION)) { + STACK_PUSH (U8, scopes_tree_strict_mode (STACK_TOP (scopes)) ? 1 : 0); + scopes_tree_set_strict_mode (STACK_TOP (scopes), false); skip_newlines (); skip_optional_name_and_parens (); skip_newlines (); skip_braces (); + scopes_tree_set_strict_mode (STACK_TOP (scopes), STACK_TOP (U8) != 0); + STACK_DROP (U8, 1); } skip_newlines (); } diff --git a/tests/jerry/N.func_expr_strict.js b/tests/jerry/N.func_expr_strict.js new file mode 100644 index 000000000..3cef21134 --- /dev/null +++ b/tests/jerry/N.func_expr_strict.js @@ -0,0 +1,19 @@ +// Copyright 2014 Samsung Electronics Co., Ltd. +// +// 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. + +"use strict"; + +(function () { + var let = 1; +})(); diff --git a/tests/jerry/N.delete.js b/tests/jerry/delete.js similarity index 100% rename from tests/jerry/N.delete.js rename to tests/jerry/delete.js diff --git a/tests/jerry/N.this_arg.js b/tests/jerry/this_arg.js similarity index 100% rename from tests/jerry/N.this_arg.js rename to tests/jerry/this_arg.js