From 019dd03fccd33f28802ba762fe5988bb64c69c41 Mon Sep 17 00:00:00 2001 From: Szilagyi Adam Date: Tue, 4 Aug 2020 16:56:08 +0200 Subject: [PATCH] Implement JSON superset (#4099) JSON strings can contain unescaped LINE SEPARATOR and PARAGRAPH SEPARATOR in ES11 JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu --- jerry-core/parser/js/js-lexer.c | 22 ++++++++++++---------- tests/jerry/es.next/json-superset.js | 16 ++++++++++++++++ tests/jerry/es5.1/json-superset.js | 27 +++++++++++++++++++++++++++ tests/test262-es6-excludelist.xml | 2 ++ tests/test262-esnext-excludelist.xml | 4 ---- 5 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 tests/jerry/es.next/json-superset.js create mode 100644 tests/jerry/es5.1/json-superset.js diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index d7895e2a9..c5257bdaa 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -1185,6 +1185,14 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ column--; } #if ENABLED (JERRY_ESNEXT) + else if (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + { + source_p += 3; + length += 3; + line++; + column = 1; + continue; + } else if (str_end_character == LIT_CHAR_GRAVE_ACCENT) { /* Newline (without backslash) is part of the string. @@ -1212,19 +1220,13 @@ lexer_parse_string (parser_context_t *context_p, /**< context */ column = 1; continue; } - else if (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) - { - source_p += 3; - length += 3; - line++; - column = 1; - continue; - } } #endif /* ENABLED (JERRY_ESNEXT) */ else if (*source_p == LIT_CHAR_CR - || *source_p == LIT_CHAR_LF - || (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p))) +#if !ENABLED (JERRY_ESNEXT) + || (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) +#endif /* !ENABLED (JERRY_ESNEXT) */ + || *source_p == LIT_CHAR_LF) { context_p->token.line = line; context_p->token.column = column; diff --git a/tests/jerry/es.next/json-superset.js b/tests/jerry/es.next/json-superset.js new file mode 100644 index 000000000..bf124c287 --- /dev/null +++ b/tests/jerry/es.next/json-superset.js @@ -0,0 +1,16 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// 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. + +assert(eval("'\u2028'") === "\u2028"); +assert(eval("'\u2029'") === "\u2029"); diff --git a/tests/jerry/es5.1/json-superset.js b/tests/jerry/es5.1/json-superset.js new file mode 100644 index 000000000..4b403afaa --- /dev/null +++ b/tests/jerry/es5.1/json-superset.js @@ -0,0 +1,27 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// 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("'\u2028'"); + assert(false); +} catch (e) { + assert(e instanceof SyntaxError); +} + +try { + eval("'\u2029'"); + assert(false); +} catch (e) { + assert(e instanceof SyntaxError); +} diff --git a/tests/test262-es6-excludelist.xml b/tests/test262-es6-excludelist.xml index 4cde487a4..01ecd2ad9 100644 --- a/tests/test262-es6-excludelist.xml +++ b/tests/test262-es6-excludelist.xml @@ -320,6 +320,8 @@ + No longer a SyntaxError in ES11 + No longer a SyntaxError in ES11 diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 414fe6a0a..cd09b968b 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -6979,10 +6979,6 @@ - - - -