]> code.delx.au - gnu-emacs-elpa/commitdiff
Ignore integer overflow
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 4 Aug 2014 01:25:51 +0000 (05:25 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 4 Aug 2014 01:26:18 +0000 (05:26 +0400)
Fixes #154

js2-mode.el
tests/parser.el

index 94c1e9dbc75413ab22fae48d53abf5aaa7ebdcdb..e93925820378e26bc32e5111ff2b8cda910a433f 100644 (file)
@@ -5442,7 +5442,7 @@ During operation, creates an instance of `js2-token' struct, sets
 its relevant fields and puts it into `js2-ti-tokens'."
   (let (c c1 identifier-start is-unicode-escape-start
         contains-escape escape-val str result base
-        is-integer quote-char val look-for-slash continue tt
+        quote-char val look-for-slash continue tt
         (token (js2-new-token 0)))
    (setq
     tt
@@ -5598,9 +5598,7 @@ its relevant fields and puts it into `js2-ti-tokens'."
               (setq c (js2-get-char)))
             (when (eq base 'maybe-8)
               (setq base 8))))
-          (setq is-integer t)
           (when (and (eq base 10) (memq c '(?. ?e ?E)))
-            (setq is-integer nil)
             (when (eq c ?.)
               (loop do
                     (js2-add-to-string c)
@@ -5621,10 +5619,7 @@ its relevant fields and puts it into `js2-ti-tokens'."
           (js2-unget-char)
           (let ((str (js2-set-string-from-buffer token)))
             (setf (js2-token-number token)
-                  (if (and (eq base 10) (not is-integer))
-                      (string-to-number str)
-                    ;; TODO:  Maybe port ScriptRuntime.stringToNumber.
-                    (string-to-number str base))))
+                  (js2-string-to-number str base)))
           (throw 'return js2-NUMBER))
         ;; is it a string?
         (when (memq c '(?\" ?\'))
@@ -5896,6 +5891,12 @@ its relevant fields and puts it into `js2-ti-tokens'."
    (setf (js2-token-type token) tt)
    token))
 
+(defsubst js2-string-to-number (str base)
+  ;; TODO:  Maybe port ScriptRuntime.stringToNumber.
+  (condition-case nil
+      (string-to-number str base)
+    (overflow-error -1)))
+
 (defun js2-read-regexp (start-tt)
   "Called by parser when it gets / or /= in literal context."
   (let (c err
index 21d14a18560aa80bd697b0c4d23cb3073354da50..2e492a2fe19e86a89f3ca72524c1dd383958f66b 100644 (file)
@@ -281,6 +281,8 @@ the test."
 
 (js2-deftest-parse decimal-starting-with-zero "081;" :reference "81;")
 
+(js2-deftest-parse huge-hex "0x0123456789abcdefABCDEF;" :reference "-1;")
+
 (js2-deftest-parse octal-without-o "071;" :reference "57;")
 
 (js2-deftest-parse hex-number-okay "0x123;" :reference "291;")