summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js')
-rw-r--r--js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js b/js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js
new file mode 100644
index 0000000000..461f61ebd3
--- /dev/null
+++ b/js/src/tests/non262/syntax/linefeed-at-eof-in-unterminated-string-or-template.js
@@ -0,0 +1,88 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 1476409;
+var summary =
+ "Properly handle the case of U+005C REVERSE SOLIDUS U+000D CARRIAGE RETURN " +
+ "at the end of source text being tokenized, in the middle of a string or " +
+ "template literal, where the next code point in memory (outside the bounds " +
+ "of the source text) is U+000A LINE FEED";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+function expectSyntaxError(code)
+{
+ try
+ {
+ eval(code);
+ throw new Error("didn't throw");
+ }
+ catch (e)
+ {
+ assertEq(e instanceof SyntaxError, true,
+ "got " + e.name + ", expected SyntaxError");
+ }
+}
+
+// The fundamental requirements of this test:
+//
+// 1. The computed string that is eval'd must be a Script that ends in a string
+// literal ending with the code points U+005C REVERSE SOLIDUS U+000D CARRIAGE
+// RETURN.
+// 2. The *memory* that is actually tokenized/parsed by eval must be
+// immediately followed by U+000A LINE FEED.
+//
+// There's only one way to guarantee a U+000A LINE FEED after the source text:
+// compute the source text as a dependent string, of a larger (linear) string.
+// A simple substr will do the trick -- just as long as the substring can't fit
+// in inline storage. 53 in the tests below comfortably exceeds all inline
+// storage limits.
+//
+// One final wrinkle: because we only tokenize/parse two-byte source text right
+// now, ensuring we directly tokenize/parse the dependent string's character
+// data means the dependent string must have two-byte character data, hence the
+// '\u1234' in the strings below.
+
+function singleQuote()
+{
+ var containsBadSingleQuoteLiteral =
+ "\u1234x'01234567890123456789012345678901234567890123456789\\\r\n0123456789";
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ expectSyntaxError(containsBadSingleQuoteLiteral.substr(2, 53));
+}
+singleQuote();
+
+function doubleQuote()
+{
+ var containsBadDoubleQuoteLiteral =
+ "\u1234x\"01234567890123456789012345678901234567890123456789\\\r\n0123456789";
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ expectSyntaxError(containsBadDoubleQuoteLiteral.substr(2, 53));
+}
+doubleQuote();
+
+function template()
+{
+ var containsBadTemplateLiteral =
+ "\u1234x`01234567890123456789012345678901234567890123456789\\\r\n0123456789";
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ expectSyntaxError(containsBadTemplateLiteral.substr(2, 53));
+}
+template();
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");