From 520d594933303f199c23187ccbd1f6906cd81510 Mon Sep 17 00:00:00 2001 From: tuchida Date: Wed, 30 Jun 2021 21:12:26 +0900 Subject: [PATCH] ref. #977 Support ES2019 JSON superset --- src/org/mozilla/javascript/TokenStream.java | 25 ++++++++++++++++--- .../javascript/tests/Test262SuiteTest.java | 1 - testsrc/test262.properties | 6 +---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/org/mozilla/javascript/TokenStream.java b/src/org/mozilla/javascript/TokenStream.java index e5b8e1255d..0cfbe278bb 100644 --- a/src/org/mozilla/javascript/TokenStream.java +++ b/src/org/mozilla/javascript/TokenStream.java @@ -914,11 +914,30 @@ final int getToken() throws IOException { quoteChar = c; stringBufferTop = 0; - c = getChar(false); + c = getCharIgnoreLineEnd(false); strLoop: while (c != quoteChar) { - if (c == '\n' || c == EOF_CHAR) { - ungetChar(c); + boolean unterminated = false; + if (c == EOF_CHAR) { + unterminated = true; + } else if (c == '\n') { + switch (lineEndChar) { + case '\n': + case '\r': + unterminated = true; + break; + case 0x2028: // + case 0x2029: // + // Line/Paragraph separators need to be included as is + c = lineEndChar; + break; + default: + break; + } + } + + if (unterminated) { + ungetCharIgnoreLineEnd(c); tokenEnd = cursor; parser.addError("msg.unterminated.string.lit"); return Token.ERROR; diff --git a/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java b/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java index c907ac10e7..fd12f0c2ae 100644 --- a/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java +++ b/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java @@ -117,7 +117,6 @@ public class Test262SuiteTest { "String.prototype.matchAll", "Symbol.matchAll", "tail-call-optimization", - "json-superset", "hashbang", "u180e")); diff --git a/testsrc/test262.properties b/testsrc/test262.properties index e4335cd99a..7059288b24 100644 --- a/testsrc/test262.properties +++ b/testsrc/test262.properties @@ -5170,7 +5170,7 @@ language/line-terminators 4/41 (9.76%) S7.3_A6_T3.js S7.3_A6_T4.js -language/literals 117/434 (26.96%) +language/literals 113/434 (26.04%) bigint/numeric-separators/numeric-separator-literal-nonoctal-08-err.js bigint/numeric-separators/numeric-separator-literal-nonoctal-09-err.js bigint/legacy-octal-like-invalid-00n.js @@ -5214,12 +5214,8 @@ language/literals 117/434 (26.96%) string/legacy-non-octal-escape-sequence-strict.js strict string/legacy-octal-escape-sequence-prologue-strict.js string/legacy-octal-escape-sequence-strict.js strict - string/line-separator.js {unsupported: [json-superset]} - string/line-separator-eval.js {unsupported: [json-superset]} string/mongolian-vowel-separator.js {unsupported: [u180e]} string/mongolian-vowel-separator-eval.js {unsupported: [u180e]} - string/paragraph-separator.js {unsupported: [json-superset]} - string/paragraph-separator-eval.js {unsupported: [json-superset]} string/S7.8.4_A4.3_T1.js strict string/S7.8.4_A4.3_T2.js strict string/S7.8.4_A7.1_T4.js