Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing var_decl. #13

Merged
merged 1 commit into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 62 additions & 40 deletions jerry-core/parser/js/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 ();
}
}
}
Expand Down Expand Up @@ -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 ();
}
Expand All @@ -2663,6 +2681,10 @@ preparse_scope (bool is_global)
{
skip_braces ();
}
else
{
process_keyword_names ();
}
skip_newlines ();
}

Expand Down
19 changes: 19 additions & 0 deletions tests/jerry/var_decl.js
Original file line number Diff line number Diff line change
@@ -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);