diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 0dfbb5906..9ac3f5453 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -3161,8 +3161,6 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer jsp_mm_init (); jsp_label_init (); - lexer_init (source_p, source_size, parser_show_opcodes); - serializer_set_show_opcodes (parser_show_opcodes); dumper_init (); syntax_init (); @@ -3171,13 +3169,20 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer STACK_PUSH (scopes, scopes_tree_init (NULL)); serializer_set_scope (STACK_TOP (scopes)); scopes_tree_set_strict_mode (STACK_TOP (scopes), is_strict); - lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); jmp_buf *syntax_error_label_p = syntax_get_syntax_error_longjmp_label (); int r = setjmp (*syntax_error_label_p); if (r == 0) { + /* + * Note: + * Operations that could raise an early error can be performed only during execution of the block. + */ + + lexer_init (source_p, source_size, parser_show_opcodes); + lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); + skip_newlines (); parse_source_element_list (true); diff --git a/tests/jerry/regression-test-issue-341.js b/tests/jerry/regression-test-issue-341.js new file mode 100644 index 000000000..e51421d80 --- /dev/null +++ b/tests/jerry/regression-test-issue-341.js @@ -0,0 +1,24 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try +{ + eval ('\xbf\x0a\x0a'); + assert (false); +} +catch (e) +{ + assert (e instanceof SyntaxError); +}