Properly process Use Strict which contains EscapeSeqence or LineContinuation.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
@@ -1761,6 +1761,42 @@ lexer_are_tokens_with_same_identifier (token id1, /**< identifier token (TOK_NAM
|
|||||||
return (id1.uid == id2.uid);
|
return (id1.uid == id2.uid);
|
||||||
} /* lexer_are_tokens_with_same_identifier */
|
} /* 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
|
* Initialize lexer to start parsing of a new source
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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_are_tokens_with_same_identifier (token id1, token id2);
|
||||||
|
|
||||||
|
extern bool lexer_is_no_escape_sequences_in_token_string (token);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2886,7 +2886,8 @@ preparse_scope (bool is_global)
|
|||||||
*/
|
*/
|
||||||
while (token_is (TOK_STRING))
|
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);
|
scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
|
||||||
is_use_strict = true;
|
is_use_strict = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user