Skip to content

Commit d5fd0b0

Browse files
committed
Properly process Use Strict which contains EscapeSeqence or LineContinuation.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov [email protected]
1 parent 17cdc35 commit d5fd0b0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

jerry-core/parser/js/lexer.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,42 @@ lexer_are_tokens_with_same_identifier (token id1, /**< identifier token (TOK_NAM
17611761
return (id1.uid == id2.uid);
17621762
} /* lexer_are_tokens_with_same_identifier */
17631763

1764+
/**
1765+
* Checks that TOK_STRING doesn't contain EscapeSequence or LineContinuation
1766+
*
1767+
* @return true, if token's string in source buffer doesn't contain backslash
1768+
* false, otherwise
1769+
*/
1770+
bool
1771+
lexer_is_no_escape_sequences_in_token_string (token tok) /**< token of type TOK_STRING */
1772+
{
1773+
JERRY_ASSERT (tok.type == TOK_STRING);
1774+
1775+
lit_utf8_iterator_t iter = src_iter;
1776+
lit_utf8_iterator_seek (&iter, tok.loc);
1777+
1778+
JERRY_ASSERT (!lit_utf8_iterator_is_eos (&iter));
1779+
ecma_char_t c = lit_utf8_iterator_read_next (&iter);
1780+
JERRY_ASSERT (c == LIT_CHAR_SINGLE_QUOTE
1781+
|| c == LIT_CHAR_DOUBLE_QUOTE);
1782+
1783+
const ecma_char_t end_char = c;
1784+
1785+
do
1786+
{
1787+
JERRY_ASSERT (!lit_utf8_iterator_is_eos (&iter));
1788+
c = lit_utf8_iterator_read_next (&iter);
1789+
1790+
if (c == LIT_CHAR_BACKSLASH)
1791+
{
1792+
return false;
1793+
}
1794+
}
1795+
while (c != end_char);
1796+
1797+
return true;
1798+
} /* lexer_is_no_escape_sequences_in_token_string */
1799+
17641800
/**
17651801
* Initialize lexer to start parsing of a new source
17661802
*/

jerry-core/parser/js/lexer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,6 @@ void lexer_set_strict_mode (bool);
187187

188188
extern bool lexer_are_tokens_with_same_identifier (token id1, token id2);
189189

190+
extern bool lexer_is_no_escape_sequences_in_token_string (token);
191+
190192
#endif

jerry-core/parser/js/parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2886,7 +2886,8 @@ preparse_scope (bool is_global)
28862886
*/
28872887
while (token_is (TOK_STRING))
28882888
{
2889-
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "use strict"))
2889+
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "use strict")
2890+
&& lexer_is_no_escape_sequences_in_token_string (tok))
28902891
{
28912892
scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
28922893
is_use_strict = true;

0 commit comments

Comments
 (0)