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

santagada at codespeak.net santagada at codespeak.net
Sun Feb 18 18:25:58 CET 2007


Author: santagada
Date: Sun Feb 18 18:25:57 2007
New Revision: 39166

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
delete operator

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Sun Feb 18 18:25:57 2007
@@ -511,6 +511,17 @@
         name = op1.ToString()
         return W_Boolean(op2.HasProperty(name))
 
+class Delete(UnaryOp):
+    opcode = 'DELETE'
+    
+    def eval(self, ctx):
+        r1 = self.expr.eval(ctx)
+        if not isinstance(r1, W_Reference):
+            return W_Boolean(True)
+        r3 = r1.GetBase()
+        r4 = r1.GetPropertyName()
+        return r3.Delete(r4)
+
 class Increment(UnaryOp):
     opcode = 'INCREMENT'
         

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Sun Feb 18 18:25:57 2007
@@ -189,7 +189,7 @@
         if self.Prototype is None: return False
         return self.Prototype.HasProperty(P) 
     
-    def Delete(P):
+    def Delete(self, P):
         if P in self.propdict:
             if self.propdict[P].dd: return False
             del self.propdict[P]

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	Sun Feb 18 18:25:57 2007
@@ -454,3 +454,11 @@
     
     def test_unary_plus(self):
         self.assert_prints("print(+1)", ['1'])
+
+    def test_delete(self):
+        self.assert_prints("""
+        var x = {}
+        x.y = 1;
+        delete x.y
+        print(x.y)
+        """, ['undefined'])



More information about the Pypy-commit mailing list