Author: Stephan <[email protected]>
Branch: 
Changeset: r185:78c4a300e000
Date: 2012-05-10 15:24 +0200
http://bitbucket.org/pypy/lang-js/changeset/78c4a300e000/

Log:    wip

diff --git a/js/baseop.py b/js/baseop.py
--- a/js/baseop.py
+++ b/js/baseop.py
@@ -215,17 +215,6 @@
     return x == y
 
 
-def commonnew(ctx, obj, args):
-    from js.jsobj import W_BasicObject
-    if not isinstance(obj, W_BasicObject):
-        raise ThrowException(W_String('it is not a constructor'))
-    try:
-        res = obj.Construct(args=args)
-        return res
-    except JsTypeError:
-        raise ThrowException(W_String('it is not a constructor'))
-    return res
-
 def uminus(obj, ctx):
     if isinstance(obj, W_IntNumber):
         return W_IntNumber(-obj.ToInteger())
diff --git a/js/js_interactive.py b/js/js_interactive.py
--- a/js/js_interactive.py
+++ b/js/js_interactive.py
@@ -8,7 +8,7 @@
 import getopt
 from js.interpreter import load_source, Interpreter, load_file
 from js.jsparser import parse, ParseError
-from js.jsobj import W_String, ThrowException, w_Undefined, W_Boolean
+from js.jsobj import W_String, w_Undefined, W_Boolean
 from pypy.rlib.streamio import open_file_as_stream
 
 #sys.setrecursionlimit(100)
@@ -69,6 +69,7 @@
         exception occurs, self.showtraceback() is called to display a
         traceback.
         """
+        from js.execution import JsException
         try:
             res = self.interpreter.run_ast(ast)
             #if DEBUG:
@@ -77,11 +78,11 @@
                 #if DEBUG:
                     #print repr(res)
                 print res.to_string()
-            except ThrowException, exc:
+            except JsException, exc:
                 print exc.exception.to_string()
         except SystemExit:
             raise
-        except ThrowException, exc:
+        except JsException, exc:
             self.showtraceback(exc)
         else:
             if code.softspace(sys.stdout, 0):
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -92,8 +92,8 @@
             self.get = getter
         if setter is not None:
             self.setter = setter
-        if writable is not None:
-            self.writable = writable
+        if enumerable is not None:
+            self.enumerable = enumerable
         if configurable is not None:
             self.configurable = configurable
 
@@ -598,12 +598,10 @@
             obj._prototype_ = W__Object._prototype_
 
 
-        try: #this is a hack to be compatible to spidermonkey
-            self.Call(args, this=obj)
-        except ReturnException, e:
-            result = e.value
-            if isinstance(result, W_BasicObject):
-                return result
+        result = self.Call(args, this=obj)
+        if isinstance(result, W__Object):
+            return result
+
         return obj
 
     def is_callable(self):
@@ -613,6 +611,7 @@
     def to_string(self):
         return "function Function() { [native code] }"
 
+    # 15.3.2.1
     def Call(self, args = [], this = None, calling_context = None):
         arg_count = len(args)
         p = ''
@@ -711,6 +710,21 @@
         self._params_ = formal_parameter_list
         self._strict_ = strict
 
+        # 13.2 Creating Function Objects
+        # 14.
+        _len = len(formal_parameter_list)
+        # 15.
+        put_property(self, 'length', _w(_len), writable = False, enumerable = 
False, configurable = False)
+        # 16.
+        proto = W__Object()
+        # 17.
+        put_property(proto, 'constructor', self, writable = True, enumerable = 
False, configurable = True)
+        # 18.
+        put_property(self, 'prototype', self, writable = True, enumerable = 
False, configurable = False)
+
+        if strict is True:
+            raise NotImplementedError()
+
     def code(self):
         return self._function_
 
@@ -1193,13 +1207,24 @@
         return w_True
     return w_False
 
-class W_List(object):
+class W_List(W_Root):
     def __init__(self, values):
         self.values = values
 
     def to_list(self):
         return self.values
 
+class W_Iterator(W_Root):
+    def __init__(self, elements_w):
+        self.elements_w = elements_w
+
+    def next(self):
+        if self.elements_w:
+            return self.elements_w.pop()
+
+    def empty(self):
+        return len(self.elements_w) == 0
+
 from pypy.rlib.objectmodel import specialize
 
 @specialize.argtype(0)
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -3,7 +3,7 @@
      w_True, w_False, w_Null, W_Root, W__Function, _w
 from js.execution import JsTypeError, ReturnException, ThrowException
 from js.baseop import plus, sub, compare, AbstractEC, StrictEC,\
-     compare_e, increment, decrement, commonnew, mult, division, uminus, mod
+     compare_e, increment, decrement, mult, division, uminus, mod
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib import jit
 
@@ -163,24 +163,15 @@
     def __init__(self, funcobj):
         self.funcobj = funcobj
 
+    # 13.2 Creating Function Objects
     def eval(self, ctx):
-        #proto = ctx.get_global().Get('Function').Get('prototype')
-        #from js.builtins import get_builtin_prototype
-        #proto = get_builtin_prototype('Function')
-
-        # 13.2 Creating Function Objects
-
+        from js.jsobj import W__Object
         func = self.funcobj
         scope = ctx.lexical_environment()
         params = func.params()
         strict = func.strict
         w_func = W__Function(func, formal_parameter_list = params, scope = 
scope, strict = strict)
 
-        #w_func = W_CallableObject(ctx, proto, self.funcobj)
-        #w_func.Put('length', W_IntNumber(len(self.funcobj.params)))
-        #w_obj = create_object('Object')
-        #w_obj.Put('constructor', w_func, flags = jsobj.DONT_ENUM)
-        #w_func.Put('prototype', w_obj)
         ctx.stack_append(w_func)
 
     #def __repr__(self):
@@ -595,6 +586,17 @@
 
         ctx.stack_append(f)
 
+def commonnew(ctx, obj, args):
+    from js.jsobj import W_BasicObject
+    if not isinstance(obj, W_BasicObject):
+        raise ThrowException(W_String('it is not a constructor'))
+    try:
+        res = obj.Construct(args=args)
+        return res
+    except JsTypeError:
+        raise ThrowException(W_String('it is not a constructor'))
+    return res
+
 class NEW(Opcode):
     _stack_change = 0
     def eval(self, ctx):
@@ -616,22 +618,28 @@
 class LOAD_ITERATOR(Opcode):
     _stack_change = 0
     def eval(self, ctx):
-        obj = ctx.stack_pop().ToObject()
+        exper_value = ctx.stack_pop()
+        obj = exper_value.ToObject()
         props = []
+
         from js.jsobj import W_BasicObject
         assert isinstance(obj, W_BasicObject)
 
-        for prop in obj._get_property_keys():
-            if not obj._get_property_flags(prop) & jsobj.DONT_ENUM:
-                props.append(obj._get_property_value(prop))
+        for prop in obj._properties_.values():
+            if prop.enumerable is True:
+                props.append(prop.value)
 
-        ctx.stack_append(W_Iterator(props))
+        from js.jsobj import W_Iterator
+        iterator = W_Iterator(props)
+
+        ctx.stack_append(iterator)
 
 class JUMP_IF_ITERATOR_EMPTY(BaseJump):
     def eval(self, ctx):
         pass
 
     def do_jump(self, ctx, pos):
+        from js.jsobj import W_Iterator
         iterator = ctx.stack_top()
         assert isinstance(iterator, W_Iterator)
         if iterator.empty():
@@ -644,9 +652,13 @@
         self.name = name
 
     def eval(self, ctx):
+        from js.jsobj import W_Iterator
+
         iterator = ctx.stack_top()
         assert isinstance(iterator, W_Iterator)
-        ctx.assign(self.name, iterator.next())
+        next_el = iterator.next()
+        ref = ctx.get_ref(self.name)
+        ref.put_value(next_el)
 
 # ---------------- with support ---------------------
 
diff --git a/js/test/test_interp.py b/js/test/test_interp.py
--- a/js/test/test_interp.py
+++ b/js/test/test_interp.py
@@ -528,7 +528,6 @@
     print(x.y);
     """, 'undefined', capsys)
 
-@xfail
 def test_forin(capsys):
     assertp("""
     var x = {a:5};
@@ -537,7 +536,6 @@
     }
     """, '5', capsys)
 
-@xfail
 def test_forinvar(capsys):
     assertp("""
     var x = {a:5};
@@ -598,7 +596,6 @@
     fact(3);
     """, 6)
 
-@xfail
 def test_function_prototype(capsys):
     assertp("""
     function foo() {}; foo.prototype.bar = function() {};
@@ -606,7 +603,10 @@
 
 def test_function_this(capsys):
     assertp("""
-    function foo() {print("debug");this.bar = function() {};};
+    function foo() {
+        print("debug");
+        this.bar = function() {};
+    };
     var f = new foo();
     f.bar();
     """, 'debug', capsys)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to