Source/JavaScriptCore:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Aug 2015 23:23:56 +0000 (23:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Aug 2015 23:23:56 +0000 (23:23 +0000)
The JSONP parser incorrectly parsers -0 as +0.
https://bugs.webkit.org/show_bug.cgi?id=147590

Patch by Keith Miller <keith_miller@apple.com> on 2015-08-06
Reviewed by Michael Saboff.

In the LiteralParser we should use a double to store the accumulator for numerical tokens
rather than an int. Using an int means that -0 is, incorrectly, parsed as +0.

* runtime/LiteralParser.cpp:
(JSC::LiteralParser<CharType>::Lexer::lexNumber):

LayoutTests:
The JSONP parser incorrectly parses -0 as +0.
https://bugs.webkit.org/show_bug.cgi?id=147590

Patch by Keith Miller <keith_miller@apple.com> on 2015-08-06
Reviewed by Michael Saboff.

A simple test that attempts loads a JSONP that sets a variable to 0.

* js/regress/JSONP-negative-0-expected.txt: Added.
* js/regress/JSONP-negative-0.html: Added.
* js/regress/script-tests/JSONP-negative-0.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/js/regress/JSONP-negative-0-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/JSONP-negative-0.html [new file with mode: 0644]
LayoutTests/js/regress/script-tests/JSONP-negative-0.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/LiteralParser.cpp

index f088635..99976cd 100644 (file)
@@ -1,3 +1,16 @@
+2015-08-06  Keith Miller  <keith_miller@apple.com>
+
+        The JSONP parser incorrectly parses -0 as +0.
+        https://bugs.webkit.org/show_bug.cgi?id=147590
+
+        Reviewed by Michael Saboff.
+
+        A simple test that attempts loads a JSONP that sets a variable to 0.
+
+        * js/regress/JSONP-negative-0-expected.txt: Added.
+        * js/regress/JSONP-negative-0.html: Added.
+        * js/regress/script-tests/JSONP-negative-0.js: Added.
+
 2015-08-06  Chris Dumez  <cdumez@apple.com>
 
         Toggle GPS state based on page visibility to save battery
diff --git a/LayoutTests/js/regress/JSONP-negative-0-expected.txt b/LayoutTests/js/regress/JSONP-negative-0-expected.txt
new file mode 100644 (file)
index 0000000..f329329
--- /dev/null
@@ -0,0 +1,11 @@
+JSRegress/JSONP-negative-0
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.is(-0,x) is true
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/JSONP-negative-0.html b/LayoutTests/js/regress/JSONP-negative-0.html
new file mode 100644 (file)
index 0000000..096dfa8
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/JSONP-negative-0.js"></script>
+<script>
+shouldBeTrue("Object.is(-0,x)");
+</script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/js/regress/script-tests/JSONP-negative-0.js b/LayoutTests/js/regress/script-tests/JSONP-negative-0.js
new file mode 100644 (file)
index 0000000..0beb0ae
--- /dev/null
@@ -0,0 +1 @@
+x = -0
index 09d7856..757d71f 100644 (file)
@@ -1,3 +1,16 @@
+2015-08-06  Keith Miller  <keith_miller@apple.com>
+
+        The JSONP parser incorrectly parsers -0 as +0.
+        https://bugs.webkit.org/show_bug.cgi?id=147590
+
+        Reviewed by Michael Saboff.
+
+        In the LiteralParser we should use a double to store the accumulator for numerical tokens
+        rather than an int. Using an int means that -0 is, incorrectly, parsed as +0.
+
+        * runtime/LiteralParser.cpp:
+        (JSC::LiteralParser<CharType>::Lexer::lexNumber):
+
 2015-08-06  Filip Pizlo  <fpizlo@apple.com>
 
         Structures used for tryGetConstantProperty() should be registered first
index 9d9fe2f..e7bf9db 100644 (file)
@@ -497,7 +497,7 @@ TokenType LiteralParser<CharType>::Lexer::lexNumber(LiteralParserToken<CharType>
         while (m_ptr < m_end && isASCIIDigit(*m_ptr))
             ++m_ptr;
     } else if (m_ptr < m_end && (*m_ptr != 'e' && *m_ptr != 'E') && (m_ptr - token.start) < 10) {
-        int result = 0;
+        double result = 0;
         token.type = TokNumber;
         token.end = m_ptr;
         const CharType* digit = token.start;