diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 3babf7d87e..2a9cf0f533 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -65,6 +65,7 @@ static void parse_statement (void); static operand parse_assignment_expression (bool); static void parse_source_element_list (bool); static operand parse_argument_list (varg_list_type, operand, uint8_t *, operand *); +static void process_keyword_names (void); static void skip_braces (void); static void skip_parens (void); @@ -2463,62 +2464,70 @@ skip_optional_name_and_parens (void) } } -static void -skip_braces (void) +static void process_keyword_names () { - current_token_must_be (TOK_OPEN_BRACE); - - uint8_t nesting_level = 1; - while (nesting_level > 0) + if (token_is (TOK_KEYWORD)) { + keyword kw = (keyword) token_data (); skip_newlines (); - if (token_is (TOK_OPEN_BRACE)) + if (token_is (TOK_COLON)) { - nesting_level++; + lexer_add_keyword_or_numeric_literal_if_not_present ( + create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); } - else if (token_is (TOK_CLOSE_BRACE)) + else { - nesting_level--; + lexer_save_token (tok); } - else if (token_is (TOK_KEYWORD)) + } + else if (token_is (TOK_NAME)) + { + if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get") + || literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set")) { - keyword kw = (keyword) token_data (); skip_newlines (); - if (token_is (TOK_COLON)) - { - lexer_add_keyword_or_numeric_literal_if_not_present ( - create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); - } - else - { - lexer_save_token (tok); - } - } - else if (token_is (TOK_NAME)) - { - if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get") - || literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set")) + if (token_is (TOK_KEYWORD)) { + keyword kw = (keyword) token_data (); skip_newlines (); - if (token_is (TOK_KEYWORD)) + if (token_is (TOK_OPEN_PAREN)) { - keyword kw = (keyword) token_data (); - skip_newlines (); - if (token_is (TOK_OPEN_PAREN)) - { - lexer_add_keyword_or_numeric_literal_if_not_present ( - create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); - } - else - { - lexer_save_token (tok); - } + lexer_add_keyword_or_numeric_literal_if_not_present ( + create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); } else { lexer_save_token (tok); } } + else + { + lexer_save_token (tok); + } + } + } +} + +static void +skip_braces (void) +{ + current_token_must_be (TOK_OPEN_BRACE); + + uint8_t nesting_level = 1; + while (nesting_level > 0) + { + skip_newlines (); + if (token_is (TOK_OPEN_BRACE)) + { + nesting_level++; + } + else if (token_is (TOK_CLOSE_BRACE)) + { + nesting_level--; + } + else + { + process_keyword_names (); } } } @@ -2649,9 +2658,18 @@ preparse_scope (bool is_global) dump_reg_var_decl_for_rewrite (); - while (!token_is (end_tt)) + size_t nesting_level = 0; + while (nesting_level > 0 || !token_is (end_tt)) { - if (is_keyword (KW_VAR)) + if (token_is (TOK_OPEN_BRACE)) + { + nesting_level++; + } + else if (token_is (TOK_CLOSE_BRACE)) + { + nesting_level--; + } + else if (is_keyword (KW_VAR)) { preparse_var_decls (); } @@ -2663,6 +2681,10 @@ preparse_scope (bool is_global) { skip_braces (); } + else + { + process_keyword_names (); + } skip_newlines (); } diff --git a/jerry-core/vm/opcodes-native-call.cpp b/jerry-core/vm/opcodes-native-call.cpp index 11462ec20c..524c41ecda 100644 --- a/jerry-core/vm/opcodes-native-call.cpp +++ b/jerry-core/vm/opcodes-native-call.cpp @@ -67,39 +67,49 @@ opfunc_native_call (opcode_t opdata, /**< operation data */ case OPCODE_NATIVE_CALL_PRINT: { - JERRY_ASSERT (args_number == 1); - - ECMA_TRY_CATCH (str_value, - ecma_op_to_string (arg_values[0]), - ret_value); + for (ecma_length_t arg_index = 0; + arg_index < args_read; + arg_index++) + { + ECMA_TRY_CATCH (str_value, + ecma_op_to_string (arg_values[arg_index]), + ret_value); - ecma_string_t *str_p = ecma_get_string_from_value (str_value); + ecma_string_t *str_p = ecma_get_string_from_value (str_value); - int32_t chars = ecma_string_get_length (str_p); - JERRY_ASSERT (chars >= 0); + int32_t chars = ecma_string_get_length (str_p); + JERRY_ASSERT (chars >= 0); - ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1); - ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size, - MEM_HEAP_ALLOC_SHORT_TERM); - if (zt_str_p == NULL) - { - jerry_fatal (ERR_OUT_OF_MEMORY); - } + ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1); + ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size, + MEM_HEAP_ALLOC_SHORT_TERM); + if (zt_str_p == NULL) + { + jerry_fatal (ERR_OUT_OF_MEMORY); + } - ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size); + ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size); #if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII - printf ("%s\n", (char*) zt_str_p); + if (arg_index < args_read - 1) + { + printf ("%s ", (char*) zt_str_p); + } + else + { + printf ("%s", (char*) zt_str_p); + } #elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 - JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented."); + JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented."); #endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */ - mem_heap_free_block (zt_str_p); - - ret_value = ecma_make_empty_completion_value (); + mem_heap_free_block (zt_str_p); - ECMA_FINALIZE (str_value); + ret_value = ecma_make_empty_completion_value (); + ECMA_FINALIZE (str_value); + } + printf ("\n"); break; } diff --git a/tests/jerry/var_decl.js b/tests/jerry/var_decl.js new file mode 100644 index 0000000000..021f24b0e4 --- /dev/null +++ b/tests/jerry/var_decl.js @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +{ + var y; +} +var x = y; +assert (x === undefined);