diff --git a/jerry-core/parser/js/lexer.cpp b/jerry-core/parser/js/lexer.cpp index b7cdbc1c7..b185139b6 100644 --- a/jerry-core/parser/js/lexer.cpp +++ b/jerry-core/parser/js/lexer.cpp @@ -1761,6 +1761,42 @@ lexer_are_tokens_with_same_identifier (token id1, /**< identifier token (TOK_NAM return (id1.uid == id2.uid); } /* lexer_are_tokens_with_same_identifier */ +/** + * Checks that TOK_STRING doesn't contain EscapeSequence or LineContinuation + * + * @return true, if token's string in source buffer doesn't contain backslash + * false, otherwise + */ +bool +lexer_is_no_escape_sequences_in_token_string (token tok) /**< token of type TOK_STRING */ +{ + JERRY_ASSERT (tok.type == TOK_STRING); + + lit_utf8_iterator_t iter = src_iter; + lit_utf8_iterator_seek (&iter, tok.loc); + + JERRY_ASSERT (!lit_utf8_iterator_is_eos (&iter)); + ecma_char_t c = lit_utf8_iterator_read_next (&iter); + JERRY_ASSERT (c == LIT_CHAR_SINGLE_QUOTE + || c == LIT_CHAR_DOUBLE_QUOTE); + + const ecma_char_t end_char = c; + + do + { + JERRY_ASSERT (!lit_utf8_iterator_is_eos (&iter)); + c = lit_utf8_iterator_read_next (&iter); + + if (c == LIT_CHAR_BACKSLASH) + { + return false; + } + } + while (c != end_char); + + return true; +} /* lexer_is_no_escape_sequences_in_token_string */ + /** * Initialize lexer to start parsing of a new source */ diff --git a/jerry-core/parser/js/lexer.h b/jerry-core/parser/js/lexer.h index 8de1a90d3..34c434174 100644 --- a/jerry-core/parser/js/lexer.h +++ b/jerry-core/parser/js/lexer.h @@ -187,4 +187,6 @@ void lexer_set_strict_mode (bool); extern bool lexer_are_tokens_with_same_identifier (token id1, token id2); +extern bool lexer_is_no_escape_sequences_in_token_string (token); + #endif diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 68fe1f5ea..7664dd702 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -2886,7 +2886,8 @@ preparse_scope (bool is_global) */ while (token_is (TOK_STRING)) { - if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "use strict")) + if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "use strict") + && lexer_is_no_escape_sequences_in_token_string (tok)) { scopes_tree_set_strict_mode (STACK_TOP (scopes), true); is_use_strict = true;