[pypy-svn] r37999 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Tue Feb 6 12:00:50 CET 2007


Author: santagada
Date: Tue Feb  6 12:00:47 2007
New Revision: 37999

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/js_interactive.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
Fixed a problem with for and the length property of arrays

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Tue Feb  6 12:00:47 2007
@@ -232,7 +232,16 @@
     def eval(self, ctx):
         v1 = self.left.eval(ctx)
         v3 = self.right.eval(ctx).GetValue()
-        v1.PutValue(v3, ctx)
+        op = self.value
+        if op == "=":
+            v1.PutValue(v3, ctx)
+        elif op == "*":
+            v1.PutValue(Mult().mathop(ctx, v1.GetValue(), v3), ctx)
+        elif op == "+":
+            v1.PutValue(Plus().mathop(ctx, v1.GetValue(), v3), ctx)
+        else:
+            print op
+            raise NotImplementedError()
         return v3
 
 class Block(Statement):
@@ -834,6 +843,7 @@
                 if e.type == 'break':
                     break
                 elif e.type == 'continue':
+                    self.update.eval(ctx)
                     continue
     
 class Boolean(Expression):

Modified: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/dist/pypy/lang/js/js_interactive.py	(original)
+++ pypy/dist/pypy/lang/js/js_interactive.py	Tue Feb  6 12:00:47 2007
@@ -51,6 +51,10 @@
     import pdb
     pdb.set_trace()
 
+def quitjs(ctx, args, this):
+    sys.exit(0)
+    
+    
 def main(argv=None):
     # XXX: note. This will not work when translated, because
     # globals cannot be modified (ie. interactive is always True).
@@ -84,11 +88,8 @@
         return 2
     
     interp = Interpreter()
-    #def quiter(ctx, args, this):
-    #    global interactive
-    #    interactive = False
         
-    #interp.w_Global.Put('quit', W_Builtin(quiter))
+    interp.w_Global.Put('quit', W_Builtin(quitjs))
     interp.w_Global.Put('load', W_Builtin(loadjs))
     interp.w_Global.Put('trace', W_Builtin(tracejs))
     for filename in filenames:

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Tue Feb  6 12:00:47 2007
@@ -292,8 +292,8 @@
             x = int(P)
             # print "puting", V, 'in', x
             if x > self.Get('length').ToNumber() - 1:
-                self.propdict['length'].value = W_Number(x)
                 currsize = len(self.array)
+                self.propdict['length'].value = W_Number(x+1)
                 for i in range(x-(currsize-1)):
                     self.array.append(w_Undefined)
             self.array[x]= V

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Tue Feb  6 12:00:47 2007
@@ -454,3 +454,4 @@
     
     def test_unary_plus(self):
         self.assert_prints("print(+1)", ['1'])
+



More information about the Pypy-commit mailing list