Skip to content

Commit

Permalink
Put lexer_init after setjmp in parser_parse_program, as lexer_init co…
Browse files Browse the repository at this point in the history
…uld raise an early error.

Related issues: #341

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
  • Loading branch information
ruben-ayrapetyan committed Jul 14, 2015
1 parent bc0ca7b commit 7f36e69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jerry-core/parser/js/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions tests/jerry/regression-test-issue-341.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 7f36e69

Please sign in to comment.