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

santagada at codespeak.net santagada at codespeak.net
Sun Nov 5 13:39:46 CET 2006


Author: santagada
Date: Sun Nov  5 13:39:44 2006
New Revision: 34234

Modified:
   pypy/dist/pypy/lang/js/astgen.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(santagada, guido around) first version with prototypes


Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py	(original)
+++ pypy/dist/pypy/lang/js/astgen.py	Sun Nov  5 13:39:44 2006
@@ -120,7 +120,6 @@
         self.strval = strval
 
 class Throw(Node):
-    """The Throw class."""
     def __init__(self, exception):
         self.exception = exception
 

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Sun Nov  5 13:39:44 2006
@@ -25,8 +25,8 @@
 
 class __extend__(Assign):
     def call(self, context):
-        #print context.locals.keys(), "|||||", context.globals
-        #print context.globals['z']
+        print context.locals.keys(), "|||||", context.globals
+        print context.locals['this']
         val = self.expr.call(context)
         print val
         self.identifier.put(context,val)
@@ -67,14 +67,16 @@
         name = self.right.get_literal()
         return w_obj.Get(name)
         
-    def put(self, context, val, obj=None):
+    def put(self, context, val):
+        print self.left.name, self.right.name, val
         if isinstance(self.left,Identifier):
-            assobj = obj or context
-            assobj.assign(self.left.name,val)
+            obj = context.access(self.left.name)
+            print obj.Class
+            obj.dict_w[self.right.name] = val
         elif isinstance(self.left,Dot):
-            assobj = self.left.put(context, val, obj)
+            obj = self.left.put(context, val)
 
-        return assobj
+        return obj
 
         #w_obj = self.left.put(context).GetValue().ToObject()
         #name = self.right.get_literal()
@@ -91,7 +93,10 @@
         if self.initialiser is not None:
             context.assign(self.name, self.initialiser.call(context))
         try:
-            return context.access(self.name)
+            print "trying to access", self.name
+            value = context.access(self.name)
+            print "value", value
+            return value
         except NameError:
             return scope_manager.get_variable(self.name)
 
@@ -148,16 +153,18 @@
 
 class __extend__(New):
     def call(self, context=None):
-        obj = W_Object({})
-        obj.Class = 'Object'
         try:
             constructor = context.access(self.identifier)
         except NameError:
             constructor = scope_manager.get_variable(self.identifier)
+        obj = W_Object({})
+        obj.Class = 'Object'
         obj.dict_w['prototype'] = constructor.dict_w['prototype']
-        nctx = ExecutionContext(context)
-        nctx.assign('this',obj)
-        constructor.Call(nctx)
+        #nctx = ExecutionContext(context)
+        #nctx.assign('this',obj)
+        #print nctx.locals.keys()
+        constructor.Call(context, this = obj)
+        
 
         return obj
 
@@ -200,7 +207,7 @@
             return W_Number(num_left + num_right)
 
 class __extend__(Script):
-    def call(self, context=None, args=(), params=[], first = False):
+    def call(self, context=None, args=(), params=[], this=w_Undefined, first = False):
         ncontext = ExecutionContext(context)
         for i, item in enumerate(params):
             try:
@@ -218,6 +225,8 @@
         w_Arguments = W_Arguments(dict([(str(x),y) for x,y in enumerate(args)]))
         ncontext.assign('arguments', w_Arguments)
         
+        ncontext.assign('this', this)
+        
         try:
             last = w_Undefined
             for node in self.nodes:

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Sun Nov  5 13:39:44 2006
@@ -39,12 +39,16 @@
         self.function = function
         #self.class_ = None
 
-    def Call(self, context=None, args=[]):
+    def Call(self, context, args=[], this = None):
         if self.function:
             return self.function.body.call(context=context, 
-                                           args=args, 
-                                           params= self.function.params)
+                                           args=args,
+                                            
+                                           params= self.function.params,
+                                           this = this
+                                           )
         else:
+            print "returning common object"
             return W_Object({})
 
     def w_string(self):
@@ -60,14 +64,6 @@
             retval = valueof_meth.Call(this=self)
             # XXX: check primitiveness of retval
             return retval
-##    else:
-##            if isinstance(valueof_meth, W_Object):
-##                retval = valueof_meth.Call(this=self)
-##                # XXX: check primitiveness of retval
-##                return retval
-##            tostring_meth = self.Get("toString")
-##            if isinstance(tostring_meth, W_Object):
-##                return tostring_meth.Call(this=self)
         return w_Undefined
 
     def ToPrimitive(self, hint=""):
@@ -85,19 +81,15 @@
 
         return w_Undefined
 
-    #def ToPrimitive(self, hint=""):
-    #    return DefaultValue(hint)
-
-    #def ToString(self):
-    #    raise SeePage(42)
-
     def CanPut(self, name):
         return True
 
     def Put(self, name, w_obj):
         # INSANE - raise some exceptions in case of read only and such
+        print "We are insane"
         if not self.CanPut(name):
             return # AAAAAAAAAAAAaaaaaaaaaaaa
+        print name,"=", w_obj
         self.dict_w[name] = w_obj
 
     def __str__(self):

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 Nov  5 13:39:44 2006
@@ -221,11 +221,16 @@
         """), ["[object Object]"])
 
     def test_new_with_function(self):
-        self.assert_prints(parse_d("""
+        
+        
+        c= parse_d("""
         x = function() {this.info = 'hello';};
         o = new x();
         print(o.info);
-        """), ["hello"])
+        """)
+        print c
+        self.assert_prints(c
+        , ["hello"])
 
     def test_vars(self):
         self.assert_prints(parse_d("""



More information about the Pypy-commit mailing list