[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 25/46: Ignore integer overflow
From: |
Dmitry Gutov |
Subject: |
[elpa] 25/46: Ignore integer overflow |
Date: |
Sat, 15 Nov 2014 20:58:05 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 817ea31e9b2db28d60b6f7c85ef62c4e8db4a880
Author: Dmitry Gutov <address@hidden>
Date: Mon Aug 4 05:25:51 2014 +0400
Ignore integer overflow
Fixes #154
---
js2-mode.el | 15 ++++++++-------
tests/parser.el | 2 ++
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 94c1e9d..e939258 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -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
diff --git a/tests/parser.el b/tests/parser.el
index 21d14a1..2e492a2 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -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;")
- [elpa] 11/46: Support yield*, (continued)
- [elpa] 11/46: Support yield*, Dmitry Gutov, 2014/11/15
- [elpa] 16/46: Support Unicode Identifiers, Dmitry Gutov, 2014/11/15
- [elpa] 17/46: Check if buffer is alive before reparsing., Dmitry Gutov, 2014/11/15
- [elpa] 19/46: Better docstrings, Dmitry Gutov, 2014/11/15
- [elpa] 14/46: Support ES6 generator comprehensions, Dmitry Gutov, 2014/11/15
- [elpa] 13/46: Support ES6 array comprehensions, Dmitry Gutov, 2014/11/15
- [elpa] 12/46: Add `.' to electric-indent-chars for method continuations, Dmitry Gutov, 2014/11/15
- [elpa] 15/46: Add Contributing section, Dmitry Gutov, 2014/11/15
- [elpa] 24/46: Small tweak, Dmitry Gutov, 2014/11/15
- [elpa] 23/46: Add js2-language-version checks, Dmitry Gutov, 2014/11/15
- [elpa] 25/46: Ignore integer overflow,
Dmitry Gutov <=
- [elpa] 26/46: Allow 'in' operator inside 'for' init when unambiguous, Dmitry Gutov, 2014/11/15
- [elpa] 27/46: Fix parsing of let expressions, Dmitry Gutov, 2014/11/15
- [elpa] 18/46: Merge pull request #149 from lewang/dont-parse-killed-buffer, Dmitry Gutov, 2014/11/15
- [elpa] 28/46: js2-parse-let: Simplify, Dmitry Gutov, 2014/11/15
- [elpa] 22/46: Support ES6 number literals, Dmitry Gutov, 2014/11/15
- [elpa] 21/46: js2-get-token-internal-1: add a FIXME, Dmitry Gutov, 2014/11/15
- [elpa] 20/46: js2-read-unicode-escape: use a stricter regexp, Dmitry Gutov, 2014/11/15
- [elpa] 29/46: Fontify negation operator, Dmitry Gutov, 2014/11/15
- [elpa] 32/46: Fix #171, Dmitry Gutov, 2014/11/15
- [elpa] 31/46: js2-mode-find-enclosing-node: Make docstring and impl consistent with name, Dmitry Gutov, 2014/11/15