[pypy-svn] r64864 - pypy/branch/js-refactoring/pypy/lang/js
jandem at codespeak.net
jandem at codespeak.net
Thu Apr 30 16:16:05 CEST 2009
Author: jandem
Date: Thu Apr 30 16:16:04 2009
New Revision: 64864
Modified:
pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
Log:
Implement ToInteger and use it for substring. It handles Infinity values different than ToInt32, fixes substring tests.
Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py Thu Apr 30 16:16:04 2009
@@ -422,11 +422,11 @@
if len(args) < 1:
start = 0
else:
- start = args[0].ToInt32(ctx)
+ start = args[0].ToInteger(ctx)
if len(args) < 2:
end = size
else:
- end = args[1].ToInt32(ctx)
+ end = args[1].ToInteger(ctx)
tmp1 = min(max(start, 0), size)
tmp2 = min(max(end, 0), size)
start = min(tmp1, tmp2)
Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py Thu Apr 30 16:16:04 2009
@@ -44,6 +44,9 @@
def ToNumber(self, ctx):
return 0.0
+ def ToInteger(self, ctx):
+ return int(self.ToNumber(ctx))
+
def ToInt32(self, ctx):
return int(self.ToNumber(ctx))
@@ -498,6 +501,15 @@
def ToNumber(self, ctx):
return self.floatval
+ def ToInteger(self, ctx):
+ if isnan(self.floatval):
+ return 0
+
+ if self.floatval == 0 or isinf(self.floatval):
+ return self.floatval
+
+ return intmask(self.floatval)
+
def ToInt32(self, ctx):
if isnan(self.floatval) or isinf(self.floatval):
return 0
More information about the Pypy-commit
mailing list