Title: [247845] trunk
Revision
247845
Author
[email protected]
Date
2019-07-25 16:55:45 -0700 (Thu, 25 Jul 2019)

Log Message

Legacy numeric literals should not permit separators or BigInt
https://bugs.webkit.org/show_bug.cgi?id=199984

Reviewed by Keith Miller.

JSTests:

* stress/big-int-literals.js:
* stress/numeric-literal-separators.js:

Source/_javascript_Core:

* parser/Lexer.cpp:
(JSC::Lexer<T>::parseOctal):
(JSC::Lexer<T>::parseDecimal):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (247844 => 247845)


--- trunk/JSTests/ChangeLog	2019-07-25 23:15:57 UTC (rev 247844)
+++ trunk/JSTests/ChangeLog	2019-07-25 23:55:45 UTC (rev 247845)
@@ -1,5 +1,15 @@
 2019-07-25  Ross Kirsling  <[email protected]>
 
+        Legacy numeric literals should not permit separators or BigInt
+        https://bugs.webkit.org/show_bug.cgi?id=199984
+
+        Reviewed by Keith Miller.
+
+        * stress/big-int-literals.js:
+        * stress/numeric-literal-separators.js:
+
+2019-07-25  Ross Kirsling  <[email protected]>
+
         [ESNext] Implement nullish coalescing
         https://bugs.webkit.org/show_bug.cgi?id=200072
 

Modified: trunk/JSTests/stress/big-int-literals.js (247844 => 247845)


--- trunk/JSTests/stress/big-int-literals.js	2019-07-25 23:15:57 UTC (rev 247844)
+++ trunk/JSTests/stress/big-int-literals.js	2019-07-25 23:55:45 UTC (rev 247845)
@@ -18,9 +18,6 @@
 let n = 0n;
 assert(n === 0n);
 
-n = 00n;
-assert(n === 0n);
-
 // Binary representation
 
 n = 0b1111n;
@@ -105,3 +102,6 @@
 assertThrowSyntaxError("1a0nn");
 assertThrowSyntaxError("10E20n");
 assertThrowSyntaxError("--10n");
+assertThrowSyntaxError("00n");
+assertThrowSyntaxError("01n");
+assertThrowSyntaxError("09n");

Modified: trunk/JSTests/stress/numeric-literal-separators.js (247844 => 247845)


--- trunk/JSTests/stress/numeric-literal-separators.js	2019-07-25 23:15:57 UTC (rev 247844)
+++ trunk/JSTests/stress/numeric-literal-separators.js	2019-07-25 23:55:45 UTC (rev 247845)
@@ -94,3 +94,13 @@
 shouldThrow('1e-_2', SyntaxError);
 shouldThrow('1e-2_', SyntaxError);
 shouldThrow('1e-2__2', SyntaxError);
+
+shouldThrow('01_1', SyntaxError);
+shouldThrow('01_9', SyntaxError);
+shouldThrow('09_1', SyntaxError);
+shouldThrow('0100_001', SyntaxError);
+shouldThrow('0100_009', SyntaxError);
+shouldThrow('0900_001', SyntaxError);
+shouldThrow('010000000000_1', SyntaxError);
+shouldThrow('010000000000_9', SyntaxError);
+shouldThrow('090000000000_1', SyntaxError);

Modified: trunk/Source/_javascript_Core/ChangeLog (247844 => 247845)


--- trunk/Source/_javascript_Core/ChangeLog	2019-07-25 23:15:57 UTC (rev 247844)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-07-25 23:55:45 UTC (rev 247845)
@@ -1,3 +1,14 @@
+2019-07-25  Ross Kirsling  <[email protected]>
+
+        Legacy numeric literals should not permit separators or BigInt
+        https://bugs.webkit.org/show_bug.cgi?id=199984
+
+        Reviewed by Keith Miller.
+
+        * parser/Lexer.cpp:
+        (JSC::Lexer<T>::parseOctal):
+        (JSC::Lexer<T>::parseDecimal):
+
 2019-07-25  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, build fix due to C++17's std::invoke_result_t

Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (247844 => 247845)


--- trunk/Source/_javascript_Core/parser/Lexer.cpp	2019-07-25 23:15:57 UTC (rev 247844)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp	2019-07-25 23:55:45 UTC (rev 247845)
@@ -1625,6 +1625,8 @@
 ALWAYS_INLINE auto Lexer<T>::parseOctal() -> Optional<NumberParseResult>
 {
     ASSERT(isASCIIOctalDigit(m_current));
+    ASSERT(!m_buffer8.size() || (m_buffer8.size() == 1 && m_buffer8[0] == '0'));
+    bool isLegacyLiteral = m_buffer8.size();
 
     // Optimization: most octal values fit into 4 bytes.
     uint32_t octalValue = 0;
@@ -1636,7 +1638,7 @@
 
     do {
         if (m_current == '_') {
-            if (UNLIKELY(!isASCIIOctalDigit(peek(1))))
+            if (UNLIKELY(!isASCIIOctalDigit(peek(1)) || isLegacyLiteral))
                 return WTF::nullopt;
 
             shift();
@@ -1656,7 +1658,7 @@
 
     while (isASCIIOctalDigitOrSeparator(m_current)) {
         if (m_current == '_') {
-            if (UNLIKELY(!isASCIIOctalDigit(peek(1))))
+            if (UNLIKELY(!isASCIIOctalDigit(peek(1)) || isLegacyLiteral))
                 return WTF::nullopt;
 
             shift();
@@ -1666,7 +1668,7 @@
         shift();
     }
 
-    if (UNLIKELY(Options::useBigInt() && m_current == 'n'))
+    if (UNLIKELY(Options::useBigInt() && m_current == 'n') && !isLegacyLiteral)
         return NumberParseResult { makeIdentifier(m_buffer8.data(), m_buffer8.size()) };
 
     if (isASCIIDigit(m_current))
@@ -1679,6 +1681,7 @@
 ALWAYS_INLINE auto Lexer<T>::parseDecimal() -> Optional<NumberParseResult>
 {
     ASSERT(isASCIIDigit(m_current) || m_buffer8.size());
+    bool isLegacyLiteral = m_buffer8.size() && isASCIIDigitOrSeparator(m_current);
 
     // Optimization: most decimal values fit into 4 bytes.
     uint32_t decimalValue = 0;
@@ -1694,7 +1697,7 @@
 
         do {
             if (m_current == '_') {
-                if (UNLIKELY(!isASCIIDigit(peek(1))))
+                if (UNLIKELY(!isASCIIDigit(peek(1)) || isLegacyLiteral))
                     return WTF::nullopt;
 
                 shift();
@@ -1715,7 +1718,7 @@
 
     while (isASCIIDigitOrSeparator(m_current)) {
         if (m_current == '_') {
-            if (UNLIKELY(!isASCIIDigit(peek(1))))
+            if (UNLIKELY(!isASCIIDigit(peek(1)) || isLegacyLiteral))
                 return WTF::nullopt;
 
             shift();
@@ -1725,7 +1728,7 @@
         shift();
     }
     
-    if (UNLIKELY(Options::useBigInt() && m_current == 'n'))
+    if (UNLIKELY(Options::useBigInt() && m_current == 'n' && !isLegacyLiteral))
         return NumberParseResult { makeIdentifier(m_buffer8.data(), m_buffer8.size()) };
 
     return WTF::nullopt;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to