[pypy-svn] r53311 - in pypy/branch/js-refactoring/pypy/lang/js: . test

fijal at codespeak.net fijal at codespeak.net
Fri Apr 4 05:35:24 CEST 2008


Author: fijal
Date: Fri Apr  4 05:35:24 2008
New Revision: 53311

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/jscode.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
   pypy/branch/js-refactoring/pypy/lang/js/operations.py
   pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
Log:
Good, test_interp passes :) this means that we don't have enough tests,
but well...


Modified: pypy/branch/js-refactoring/pypy/lang/js/jscode.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jscode.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jscode.py	Fri Apr  4 05:35:24 2008
@@ -812,6 +812,29 @@
     def eval(self, ctx, stack):
         ctx.pop_object()
 
+# ------------------ delete -------------------------
+
+class DELETE(Opcode):
+    def __init__(self, name):
+        self.name = name
+
+    def eval(self, ctx, stack):
+        stack.append(newbool(ctx.delete_identifier(self.name)))
+
+class DELETE_MEMBER(Opcode):
+    def eval(self, ctx, stack):
+        what = stack.pop().ToString()
+        obj = stack.pop().ToObject(ctx)
+        try:
+            P = obj.propdict[what]
+            if P.ro:
+                stack.append(newbool(False))
+                return
+            del obj.propdict[what]
+            stack.append(newbool(True))
+        except KeyError:
+            stack.append(newbool(False))
+
 OpcodeMap = {}
 
 for name, value in locals().items():

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	Fri Apr  4 05:35:24 2008
@@ -531,6 +531,19 @@
         # if not, we need to put this thing in current scope
         self.variable.Put(name, value)
 
+    def delete_identifier(self, name):
+        for obj in self.scope:
+            assert isinstance(obj, W_PrimitiveObject)
+            try:
+                P = obj.propdict[name]
+                if P.ro:
+                    return False
+                del obj.propdict[name]
+                return True
+            except KeyError:
+                pass
+        return False
+
     def put(self, name, value):
         assert name is not None
         self.variable.Put(name, value)

Modified: pypy/branch/js-refactoring/pypy/lang/js/operations.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/operations.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/operations.py	Fri Apr  4 05:35:24 2008
@@ -489,6 +489,23 @@
         self.pos = pos
         self.what = what
 
+    def emit(self, bytecode):
+        what = self.what
+        if isinstance(what, Identifier):
+            bytecode.emit('DELETE', what.name)
+        elif isinstance(what, MemberDot):
+            what.left.emit(bytecode)
+            # XXX optimize
+            bytecode.emit('LOAD_STRINGCONSTANT', what.name)
+            bytecode.emit('DELETE_MEMBER')
+        elif isinstance(what, Member):
+            what.left.emit(bytecode)
+            what.right.emit(bytecode)
+            bytecode.emit('DELETE_MEMBER')
+        else:
+            what.left.emit(bytecode)
+            bytecode.emit('LOAD_BOOLCONSTANT', True)
+
     #def emit(self, bytecode):
     #    
 

Modified: pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	Fri Apr  4 05:35:24 2008
@@ -466,7 +466,11 @@
     assertp("print(+1);", '1')
 
 def test_delete():
-    py.test.skip("Unsupported")
+    assertp("""
+    x = 0;
+    delete x;
+    print(this.x)
+    """, 'undefined')
     assertp("""
     var x = {};
     x.y = 1;



More information about the Pypy-commit mailing list