Author: Stephan <[email protected]>
Branch: 
Changeset: r159:cce425fcf755
Date: 2011-12-13 15:33 +0100
http://bitbucket.org/pypy/lang-js/changeset/cce425fcf755/

Log:    commented obsolete code

diff --git a/js/baseop.py b/js/baseop.py
--- a/js/baseop.py
+++ b/js/baseop.py
@@ -2,8 +2,7 @@
 """ Base operations implementations
 """
 
-from js.jsobj import W_String, W_IntNumber, W_FloatNumber,\
-     W_PrimitiveObject
+from js.jsobj import W_String, W_IntNumber, W_FloatNumber
 from js.execution import ThrowException, JsTypeError
 
 from pypy.rlib.rarithmetic import r_uint, intmask, ovfcheck
@@ -218,7 +217,7 @@
 
 def commonnew(ctx, obj, args):
     from js.jsobj import W_BasicObject
-    if not (isinstance(obj, W_PrimitiveObject) or isinstance(obj, 
W_BasicObject)):
+    if not isinstance(obj, W_BasicObject):
         raise ThrowException(W_String('it is not a constructor'))
     try:
         res = obj.Construct(args=args)
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -1,9 +1,8 @@
 import time
 
-from js.jsobj import W_Object,\
-     w_Undefined, W_NewBuiltin, W_IntNumber, w_Null, create_object, W_Boolean,\
-     W_FloatNumber, W_String, W_Builtin, w_Null, newbool,\
-     isnull_or_undefined, W_PrimitiveObject, W_ListObject, W_Number,\
+from js.jsobj import w_Undefined, W_IntNumber, w_Null, create_object, 
W_Boolean,\
+     W_FloatNumber, W_String, newbool,\
+     isnull_or_undefined, W_Number,\
      DONT_DELETE, DONT_ENUM, READ_ONLY, INTERNAL, _w
 from js.execution import ThrowException, JsTypeError
 
@@ -71,346 +70,328 @@
         func = bytecode.make_js_function()
         return func.run(self._context_)
 
-class W_ParseInt(W_NewBuiltin):
-    length = 1
-    def Call(self, args=[], this=None):
-        if len(args) < 1:
-            return W_FloatNumber(NAN)
-        s = args[0].ToString().strip(" ")
-        if len(args) > 1:
-            radix = args[1].ToInt32()
-        else:
-            radix = 10
-        if len(s) >= 2 and (s.startswith('0x') or s.startswith('0X')) :
-            radix = 16
-            s = s[2:]
-        if s == '' or radix < 2 or radix > 36:
-            return W_FloatNumber(NAN)
-        try:
-            n = int(s, radix)
-        except ValueError:
-            return W_FloatNumber(NAN)
-        return W_IntNumber(n)
+#class W_ParseInt(W_NewBuiltin):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #if len(args) < 1:
+            #return W_FloatNumber(NAN)
+        #s = args[0].ToString().strip(" ")
+        #if len(args) > 1:
+            #radix = args[1].ToInt32()
+        #else:
+            #radix = 10
+        #if len(s) >= 2 and (s.startswith('0x') or s.startswith('0X')) :
+            #radix = 16
+            #s = s[2:]
+        #if s == '' or radix < 2 or radix > 36:
+            #return W_FloatNumber(NAN)
+        #try:
+            #n = int(s, radix)
+        #except ValueError:
+            #return W_FloatNumber(NAN)
+        #return W_IntNumber(n)
 
-class W_ParseFloat(W_NewBuiltin):
-    length = 1
-    def Call(self, args=[], this=None):
-        if len(args) < 1:
-            return W_FloatNumber(NAN)
-        s = args[0].ToString().strip(" ")
-        try:
-            n = float(s)
-        except ValueError:
-            n = NAN
-        return W_FloatNumber(n)
+#class W_ParseFloat(W_NewBuiltin):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #if len(args) < 1:
+            #return W_FloatNumber(NAN)
+        #s = args[0].ToString().strip(" ")
+        #try:
+            #n = float(s)
+        #except ValueError:
+            #n = NAN
+        #return W_FloatNumber(n)
 
-class W_FromCharCode(W_NewBuiltin):
-    length = 1
-    def Call(self, args=[], this=None):
-        temp = []
-        for arg in args:
-            i = arg.ToInt32() % 65536 # XXX should be uint16
-            temp.append(chr(i))
-        return W_String(''.join(temp))
+#class W_FromCharCode(W_NewBuiltin):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #temp = []
+        #for arg in args:
+            #i = arg.ToInt32() % 65536 # XXX should be uint16
+            #temp.append(chr(i))
+        #return W_String(''.join(temp))
 
-class W_CharCodeAt(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        if len(args)>=1:
-            pos = args[0].ToInt32()
-            if pos < 0 or pos > len(string) - 1:
-                return W_FloatNumber(NAN)
-        else:
-            return W_FloatNumber(NAN)
-        char = string[pos]
-        return W_IntNumber(ord(char))
+#class W_CharCodeAt(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #if len(args)>=1:
+            #pos = args[0].ToInt32()
+            #if pos < 0 or pos > len(string) - 1:
+                #return W_FloatNumber(NAN)
+        #else:
+            #return W_FloatNumber(NAN)
+        #char = string[pos]
+        #return W_IntNumber(ord(char))
 
-class W_Concat(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        others = [obj.ToString() for obj in args]
-        string += ''.join(others)
-        return W_String(string)
+#class W_Concat(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #others = [obj.ToString() for obj in args]
+        #string += ''.join(others)
+        #return W_String(string)
 
-class W_IndexOf(W_NewBuiltin):
-    length = 1
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        if len(args) < 1:
-            return W_IntNumber(-1)
-        substr = args[0].ToString()
-        size = len(string)
-        subsize = len(substr)
-        if len(args) < 2:
-            pos = 0
-        else:
-            pos = args[1].ToInteger()
-        pos = int(min(max(pos, 0), size))
-        assert pos >= 0
-        return W_IntNumber(string.find(substr, pos))
+#class W_IndexOf(W_NewBuiltin):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #if len(args) < 1:
+            #return W_IntNumber(-1)
+        #substr = args[0].ToString()
+        #size = len(string)
+        #subsize = len(substr)
+        #if len(args) < 2:
+            #pos = 0
+        #else:
+            #pos = args[1].ToInteger()
+        #pos = int(min(max(pos, 0), size))
+        #assert pos >= 0
+        #return W_IntNumber(string.find(substr, pos))
 
-class W_LastIndexOf(W_NewBuiltin):
-    length = 1
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        if len(args) < 1:
-            return W_IntNumber(-1)
-        substr = args[0].ToString()
-        if len(args) < 2:
-            pos = INFINITY
-        else:
-            val = args[1].ToNumber()
-            if isnan(val):
-                pos = INFINITY
-            else:
-                pos = args[1].ToInteger()
-        size = len(string)
-        pos = int(min(max(pos, 0), size))
-        subsize = len(substr)
-        endpos = pos+subsize
-        assert endpos >= 0
-        return W_IntNumber(string.rfind(substr, 0, endpos))
+#class W_LastIndexOf(W_NewBuiltin):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #if len(args) < 1:
+            #return W_IntNumber(-1)
+        #substr = args[0].ToString()
+        #if len(args) < 2:
+            #pos = INFINITY
+        #else:
+            #val = args[1].ToNumber()
+            #if isnan(val):
+                #pos = INFINITY
+            #else:
+                #pos = args[1].ToInteger()
+        #size = len(string)
+        #pos = int(min(max(pos, 0), size))
+        #subsize = len(substr)
+        #endpos = pos+subsize
+        #assert endpos >= 0
+        #return W_IntNumber(string.rfind(substr, 0, endpos))
 
-class W_Substring(W_NewBuiltin):
-    length = 2
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        size = len(string)
-        if len(args) < 1:
-            start = 0
-        else:
-            start = args[0].ToInteger()
-        if len(args) < 2:
-            end = size
-        else:
-            end = args[1].ToInteger()
-        tmp1 = min(max(start, 0), size)
-        tmp2 = min(max(end, 0), size)
-        start = min(tmp1, tmp2)
-        end = max(tmp1, tmp2)
-        return W_String(string[start:end])
+#class W_Substring(W_NewBuiltin):
+    #length = 2
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #size = len(string)
+        #if len(args) < 1:
+            #start = 0
+        #else:
+            #start = args[0].ToInteger()
+        #if len(args) < 2:
+            #end = size
+        #else:
+            #end = args[1].ToInteger()
+        #tmp1 = min(max(start, 0), size)
+        #tmp2 = min(max(end, 0), size)
+        #start = min(tmp1, tmp2)
+        #end = max(tmp1, tmp2)
+        #return W_String(string[start:end])
 
-class W_Split(W_NewBuiltin):
-    length = 2
-    def Call(self, args=[], this=None):
-        string = this.ToString()
+#class W_Split(W_NewBuiltin):
+    #length = 2
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
 
-        if len(args) < 1 or args[0] is w_Undefined:
-            return create_array([W_String(string)])
-        else:
-            separator = args[0].ToString()
+        #if len(args) < 1 or args[0] is w_Undefined:
+            #return create_array([W_String(string)])
+        #else:
+            #separator = args[0].ToString()
 
-        if len(args) >= 2:
-            limit = args[1].ToUInt32()
-            raise ThrowException(W_String("limit not implemented"))
-            # array = string.split(separator, limit)
-        else:
-            array = string.split(separator)
+        #if len(args) >= 2:
+            #limit = args[1].ToUInt32()
+            #raise ThrowException(W_String("limit not implemented"))
+            ## array = string.split(separator, limit)
+        #else:
+            #array = string.split(separator)
 
-        w_array = create_array()
-        i = 0
-        while i < len(array):
-            w_str = W_String(array[i])
-            w_array.Put(str(i), w_str)
-            i += 1
+        #w_array = create_array()
+        #i = 0
+        #while i < len(array):
+            #w_str = W_String(array[i])
+            #w_array.Put(str(i), w_str)
+            #i += 1
 
-        return w_array
+        #return w_array
 
-class W_ToLowerCase(W_NewBuiltin):
-    length = 0
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        return W_String(string.lower())
+#class W_ToLowerCase(W_NewBuiltin):
+    #length = 0
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #return W_String(string.lower())
 
-class W_ToUpperCase(W_NewBuiltin):
-    length = 0
-    def Call(self, args=[], this=None):
-        string = this.ToString()
-        return W_String(string.upper())
+#class W_ToUpperCase(W_NewBuiltin):
+    #length = 0
+    #def Call(self, args=[], this=None):
+        #string = this.ToString()
+        #return W_String(string.upper())
 
-class W_ToString(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        assert isinstance(this, W_PrimitiveObject)
-        return W_String("[object %s]"%this.Class)
+#class W_ToString(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #assert isinstance(this, W_PrimitiveObject)
+        #return W_String("[object %s]"%this.Class)
 
-class W_ValueOf(W_NewBuiltin):
-    length = 0
-    def Call(self, args=[], this=None):
-        return this
+#class W_ValueOf(W_NewBuiltin):
+    #length = 0
+    #def Call(self, args=[], this=None):
+        #return this
 
-class W_HasOwnProperty(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        if len(args) >= 1:
-            propname = args[0].ToString()
-            if propname in self._get_property_keys():
-                return newbool(True)
-        return newbool(False)
+#class W_HasOwnProperty(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #if len(args) >= 1:
+            #propname = args[0].ToString()
+            #if propname in self._get_property_keys():
+                #return newbool(True)
+        #return newbool(False)
 
-class W_IsPrototypeOf(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        w_obj = args[0]
-        if len(args) >= 1 and isinstance(w_obj, W_PrimitiveObject):
-            O = this
-            assert isinstance(w_obj, W_PrimitiveObject)
-            V = w_obj.Prototype
-            while V is not None:
-                if O == V:
-                    return newbool(True)
-                assert isinstance(V, W_PrimitiveObject)
-                V = V.Prototype
-        return newbool(False)
+#class W_IsPrototypeOf(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #w_obj = args[0]
+        #if len(args) >= 1 and isinstance(w_obj, W_PrimitiveObject):
+            #O = this
+            #assert isinstance(w_obj, W_PrimitiveObject)
+            #V = w_obj.Prototype
+            #while V is not None:
+                #if O == V:
+                    #return newbool(True)
+                #assert isinstance(V, W_PrimitiveObject)
+                #V = V.Prototype
+        #return newbool(False)
 
-class W_PropertyIsEnumerable(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        if len(args) >= 1:
-            propname = args[0].ToString()
-            if self._has_property(propname) and not 
self._get_property_flags(propname) & DONT_ENUM:
-                return newbool(True)
-        return newbool(False)
+#class W_PropertyIsEnumerable(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #if len(args) >= 1:
+            #propname = args[0].ToString()
+            #if self._has_property(propname) and not 
self._get_property_flags(propname) & DONT_ENUM:
+                #return newbool(True)
+        #return newbool(False)
 
-class W_Function(W_NewBuiltin):
-    def __init__(self, ctx, Prototype=None, Class='function', 
Value=w_Undefined):
-        W_NewBuiltin.__init__(self, Prototype, Class, Value)
-        self.ctx = ctx
+#class W_Function(W_NewBuiltin):
+    #def __init__(self, ctx, Prototype=None, Class='function', 
Value=w_Undefined):
+        #W_NewBuiltin.__init__(self, Prototype, Class, Value)
+        #self.ctx = ctx
 
-    def Call(self, args=[], this=None):
-        tam = len(args)
-        if tam >= 1:
-            fbody  = args[tam-1].ToString()
-            argslist = []
-            for i in range(tam-1):
-                argslist.append(args[i].ToString())
-            fargs = ','.join(argslist)
-            functioncode = "function (%s) {%s}"%(fargs, fbody)
-        else:
-            functioncode = "function () {}"
-        #remove program and sourcelements node
-        funcnode = parse(functioncode).children[0].children[0]
-        builder = make_ast_builder()
-        ast = builder.dispatch(funcnode)
-        bytecode = JsCode()
-        ast.emit(bytecode)
-        func = bytecode.make_js_function()
-        return func.run(self.ctx)
+    #def Call(self, args=[], this=None):
+        #tam = len(args)
+        #if tam >= 1:
+            #fbody  = args[tam-1].ToString()
+            #argslist = []
+            #for i in range(tam-1):
+                #argslist.append(args[i].ToString())
+            #fargs = ','.join(argslist)
+            #functioncode = "function (%s) {%s}"%(fargs, fbody)
+        #else:
+            #functioncode = "function () {}"
+        ##remove program and sourcelements node
+        #funcnode = parse(functioncode).children[0].children[0]
+        #builder = make_ast_builder()
+        #ast = builder.dispatch(funcnode)
+        #bytecode = JsCode()
+        #ast.emit(bytecode)
+        #func = bytecode.make_js_function()
+        #return func.run(self.ctx)
 
-    def Construct(self, args=[]):
-        return self.Call(args, this=None)
+    #def Construct(self, args=[]):
+        #return self.Call(args, this=None)
 
-functionstring= 'function (arguments go here!) {\n'+ \
-                '    [lots of stuff :)]\n'+ \
-                '}'
-class W_FToString(W_NewBuiltin):
-    def Call(self, args=[], this=None):
-        from js.jsobj import W__Function
-        if isinstance(this, W_PrimitiveObject):
-            if this.Class == 'Function':
-                return W_String(functionstring)
-        if isinstance(this, W__Function):
-            return W_String(functionstring)
+#functionstring= 'function (arguments go here!) {\n'+ \
+                #'    [lots of stuff :)]\n'+ \
+                #'}'
+#class W_FToString(W_NewBuiltin):
+    #def Call(self, args=[], this=None):
+        #from js.jsobj import W__Function
+        #if isinstance(this, W_PrimitiveObject):
+            #if this.Class == 'Function':
+                #return W_String(functionstring)
+        #if isinstance(this, W__Function):
+            #return W_String(functionstring)
 
-        raise JsTypeError('this is not a function object')
+        #raise JsTypeError('this is not a function object')
 
-class W_Apply(W_NewBuiltin):
-    def __init__(self, ctx):
-        W_NewBuiltin.__init__(self)
-        self.ctx = ctx
+#class W_Apply(W_NewBuiltin):
+    #def __init__(self, ctx):
+        #W_NewBuiltin.__init__(self)
+        #self.ctx = ctx
 
-    def Call(self, args=[], this=None):
-        try:
-            if isnull_or_undefined(args[0]):
-                thisArg = self.ctx.get_global()
-            else:
-                thisArg = args[0].ToObject()
-        except IndexError:
-            thisArg = self.ctx.get_global()
+    #def Call(self, args=[], this=None):
+        #try:
+            #if isnull_or_undefined(args[0]):
+                #thisArg = self.ctx.get_global()
+            #else:
+                #thisArg = args[0].ToObject()
+        #except IndexError:
+            #thisArg = self.ctx.get_global()
 
-        try:
-            arrayArgs = args[1]
-            callargs = arrayArgs.tolist()
-        except IndexError:
-            callargs = []
-        return this.Call(callargs, this=thisArg)
+        #try:
+            #arrayArgs = args[1]
+            #callargs = arrayArgs.tolist()
+        #except IndexError:
+            #callargs = []
+        #return this.Call(callargs, this=thisArg)
 
-class W_Call(W_NewBuiltin):
-    def __init__(self, ctx):
-        W_NewBuiltin.__init__(self)
-        self.ctx = ctx
+#class W_Call(W_NewBuiltin):
+    #def __init__(self, ctx):
+        #W_NewBuiltin.__init__(self)
+        #self.ctx = ctx
 
-    def Call(self, args=[], this=None):
-        if len(args) >= 1:
-            if isnull_or_undefined(args[0]):
-                thisArg = self.ctx.get_global()
-            else:
-                thisArg = args[0]
-            callargs = args[1:]
-        else:
-            thisArg = self.ctx.get_global()
-            callargs = []
-        return this.Call(callargs, this = thisArg)
+    #def Call(self, args=[], this=None):
+        #if len(args) >= 1:
+            #if isnull_or_undefined(args[0]):
+                #thisArg = self.ctx.get_global()
+            #else:
+                #thisArg = args[0]
+            #callargs = args[1:]
+        #else:
+            #thisArg = self.ctx.get_global()
+            #callargs = []
+        #return this.Call(callargs, this = thisArg)
 
-class W_ValueToString(W_NewBuiltin):
-    "this is the toString function for objects with Value"
-    mytype = ''
-    def Call(self, args=[], this=None):
-        assert isinstance(this, W_PrimitiveObject)
-        if this.Value.type() != self.mytype:
-            raise JsTypeError('Wrong type')
-        return W_String(this.Value.ToString())
+#class W_ValueToString(W_NewBuiltin):
+    #"this is the toString function for objects with Value"
+    #mytype = ''
+    #def Call(self, args=[], this=None):
+        #assert isinstance(this, W_PrimitiveObject)
+        #if this.Value.type() != self.mytype:
+            #raise JsTypeError('Wrong type')
+        #return W_String(this.Value.ToString())
 
-class W_NumberValueToString(W_ValueToString):
-    mytype = 'number'
+#class W_NumberValueToString(W_ValueToString):
+    #mytype = 'number'
 
-class W_BooleanValueToString(W_ValueToString):
-    mytype = 'boolean'
+#class W_BooleanValueToString(W_ValueToString):
+    #mytype = 'boolean'
 
-class W_StringValueToString(W_ValueToString):
-    mytype = 'string'
+#class W_StringValueToString(W_ValueToString):
+    #mytype = 'string'
 
-class W_NativeObject(W_Object):
-    def __init__(self, Class, Prototype, Value=w_Undefined):
-        W_Object.__init__(self, Prototype, Class, Value)
+#class W_NativeObject(W_Object):
+    #def __init__(self, Class, Prototype, Value=w_Undefined):
+        #W_Object.__init__(self, Prototype, Class, Value)
 
-class W_DateObject(W_NativeObject):
-    def Call(self, args=[], this=None):
-        return create_object('Object')
+#class W_DateObject(W_NativeObject):
+    #def Call(self, args=[], this=None):
+        #return create_object('Object')
 
-    def Construct(self, args=[]):
-        v = int(time.time()*1000)
-        return create_object('Date', Value = W_IntNumber(v))
+    #def Construct(self, args=[]):
+        #v = int(time.time()*1000)
+        #return create_object('Date', Value = W_IntNumber(v))
 
 def pypy_repr(this, *args):
     o = args[0]
     return W_String(repr(o))
 
-def put_values(obj, dictvalues):
-    for key,value in dictvalues.iteritems():
-        obj.Put(key, value)
+#@specialize.memo()
+#def get_value_of(type):
+    #class W_ValueValueOf(W_NewBuiltin):
+        #"this is the valueOf function for objects with Value"
+        #def Call(self, args=[], this=None):
+            #assert isinstance(this, W_PrimitiveObject)
+            #if type != this.Class:
+                #raise JsTypeError('%s.prototype.valueOf called with 
incompatible type' % self.type())
+            #return this.Value
+    #return W_ValueValueOf
 
[email protected]()
-def get_value_of(type):
-    class W_ValueValueOf(W_NewBuiltin):
-        "this is the valueOf function for objects with Value"
-        def Call(self, args=[], this=None):
-            assert isinstance(this, W_PrimitiveObject)
-            if type != this.Class:
-                raise JsTypeError('%s.prototype.valueOf called with 
incompatible type' % self.type())
-            return this.Value
-    return W_ValueValueOf
-
-def common_join(this, sep=','):
-    length = this.Get('length').ToUInt32()
-    l = []
-    i = 0
-    while i < length:
-        item = this.Get(str(i))
-        if isnull_or_undefined(item):
-            item_string = ''
-        else:
-            item_string = item.ToString()
-        l.append(item_string)
-        i += 1
-
-    return sep.join(l)
 
 class Sorter(TimSort):
     def __init__(self, list, listlength=None, compare_fn=None):
@@ -479,21 +460,21 @@
         res.append(ch)
     return W_String(''.join(res))
 
-class W_ObjectObject(W_NativeObject):
-    def __init__(self, Class, Prototype, Value=w_Undefined):
-        W_NativeObject.__init__(self, Class, Prototype, Value)
+#class W_ObjectObject(W_NativeObject):
+    #def __init__(self, Class, Prototype, Value=w_Undefined):
+        #W_NativeObject.__init__(self, Class, Prototype, Value)
 
-    def Call(self, args=[], this=None):
-        if len(args) >= 1 and not isnull_or_undefined(args[0]):
-            return args[0].ToObject()
-        else:
-            return self.Construct()
+    #def Call(self, args=[], this=None):
+        #if len(args) >= 1 and not isnull_or_undefined(args[0]):
+            #return args[0].ToObject()
+        #else:
+            #return self.Construct()
 
-    def Construct(self, args=[]):
-        if (len(args) >= 1 and not args[0] is w_Undefined and not args[0] is 
w_Null):
-            # XXX later we could separate builtins and normal objects
-            return args[0].ToObject()
-        return create_object('Object')
+    #def Construct(self, args=[]):
+        #if (len(args) >= 1 and not args[0] is w_Undefined and not args[0] is 
w_Null):
+            ## XXX later we could separate builtins and normal objects
+            #return args[0].ToObject()
+        #return create_object('Object')
 
 #class W_BooleanObject(W_NativeObject):
     #def Call(self, args=[], this=None):
@@ -526,20 +507,20 @@
             #return create_object('Number', Value = Value)
         #return create_object('Number', Value = W_FloatNumber(0.0))
 
-class W_StringObject(W_NativeObject):
-    length = 1
-    def Call(self, args=[], this=None):
-        if len(args) >= 1:
-            return W_String(args[0].ToString())
-        else:
-            return W_String('')
+#class W_StringObject(W_NativeObject):
+    #length = 1
+    #def Call(self, args=[], this=None):
+        #if len(args) >= 1:
+            #return W_String(args[0].ToString())
+        #else:
+            #return W_String('')
 
-    def Construct(self, args=[]):
-        if len(args) >= 1:
-            Value = W_String(args[0].ToString())
-        else:
-            Value = W_String('')
-        return Value.ToObject()
+    #def Construct(self, args=[]):
+        #if len(args) >= 1:
+            #Value = W_String(args[0].ToString())
+        #else:
+            #Value = W_String('')
+        #return Value.ToObject()
 
 def create_array(elements=[]):
     # TODO do not get array prototype from global context?
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -283,11 +283,6 @@
                 res = p.Call(this = self)
                 if isinstance(res, W__Primitive):
                     return res
-            # TODO: this is only for compability
-            if isinstance(p, W_PrimitiveObject):
-                res = p.Call(this = self)
-                if isinstance(res, W_Root):
-                    return res
 
         raise JsTypeError
 
@@ -512,253 +507,232 @@
     def ToString(self):
         return self._function_.ToString()
 
-class W_PrimitiveObject(W_Root):
-    _immutable_fields_ = ['Class', 'Prototype', 'Scope', 'Value']
-    def __init__(self, Prototype=None, Class='Object', Value=w_Undefined):
-        self.Prototype = Prototype
-        self.property_map = root_map()
-        self.property_values = []
-        if Prototype is None:
-            Prototype = w_Undefined
-        self._set_property('prototype', Prototype, DONT_ENUM | DONT_DELETE)
-        self.Class = Class
-        self.Scope = None
-        self.Value = Value
+#class W_PrimitiveObject(W_Root):
+    #_immutable_fields_ = ['Class', 'Prototype', 'Scope', 'Value']
+    #def __init__(self, Prototype=None, Class='Object', Value=w_Undefined):
+        #self.Prototype = Prototype
+        #self.property_map = root_map()
+        #self.property_values = []
+        #if Prototype is None:
+            #Prototype = w_Undefined
+        #self._set_property('prototype', Prototype, DONT_ENUM | DONT_DELETE)
+        #self.Class = Class
+        #self.Scope = None
+        #self.Value = Value
 
-    def _set_property(self, name, value, flags):
-        if self.property_map.lookup(name) == self.property_map.NOT_FOUND:
-            self.property_map = self.property_map.add(name, flags)
-        self._set_property_value(name, value)
-        self._set_property_flags(name, flags)
+    #def _set_property(self, name, value, flags):
+        #if self.property_map.lookup(name) == self.property_map.NOT_FOUND:
+            #self.property_map = self.property_map.add(name, flags)
+        #self._set_property_value(name, value)
+        #self._set_property_flags(name, flags)
 
-    def _set_property_value(self, name, value):
-        idx = self.property_map.lookup(name)
-        l = len(self.property_values)
+    #def _set_property_value(self, name, value):
+        #idx = self.property_map.lookup(name)
+        #l = len(self.property_values)
 
-        if l <= idx:
-            self.property_values = self.property_values + ([None] * (idx - l + 
1))
+        #if l <= idx:
+            #self.property_values = self.property_values + ([None] * (idx - l 
+ 1))
 
-        self.property_values[idx] = value
+        #self.property_values[idx] = value
 
-    def _set_property_flags(self, name, flags):
-        self.property_map = self.property_map.set_flags(name, flags)
+    #def _set_property_flags(self, name, flags):
+        #self.property_map = self.property_map.set_flags(name, flags)
 
-    def _get_property_value(self, name):
-        idx = self.property_map.lookup(name)
-        if idx == self.property_map.NOT_FOUND:
-            raise KeyError
-        return self.property_values[idx]
+    #def _get_property_value(self, name):
+        #idx = self.property_map.lookup(name)
+        #if idx == self.property_map.NOT_FOUND:
+            #raise KeyError
+        #return self.property_values[idx]
 
-    def _get_property_flags(self, name):
-        flag = self.property_map.lookup_flag(name)
-        if flag == self.property_map.NOT_FOUND:
-            raise KeyError
-        return flag
+    #def _get_property_flags(self, name):
+        #flag = self.property_map.lookup_flag(name)
+        #if flag == self.property_map.NOT_FOUND:
+            #raise KeyError
+        #return flag
 
-    def _has_property(self, name):
-        return self.property_map.lookup(name) != self.property_map.NOT_FOUND
+    #def _has_property(self, name):
+        #return self.property_map.lookup(name) != self.property_map.NOT_FOUND
 
-    @jit.unroll_safe
-    def _delete_property(self, name):
-        idx = self.property_map.lookup(name)
-        old_map = self.property_map
-        new_map = self.property_map.delete(name)
-        new_keys = new_map.keys()
-        new_values = [None] * len(new_keys)
-        old_values = self.property_values
+    #@jit.unroll_safe
+    #def _delete_property(self, name):
+        #idx = self.property_map.lookup(name)
+        #old_map = self.property_map
+        #new_map = self.property_map.delete(name)
+        #new_keys = new_map.keys()
+        #new_values = [None] * len(new_keys)
+        #old_values = self.property_values
 
-        for key in new_keys:
-            old_index = old_map.lookup(key)
-            new_index = new_map.lookup(key)
-            new_values[new_index] = old_values[old_index]
+        #for key in new_keys:
+            #old_index = old_map.lookup(key)
+            #new_index = new_map.lookup(key)
+            #new_values[new_index] = old_values[old_index]
 
-        self.property_values = new_values
-        self.property_map = new_map
+        #self.property_values = new_values
+        #self.property_map = new_map
 
-    def _get_property_keys(self):
-        return self.property_map.keys()
+    #def _get_property_keys(self):
+        #return self.property_map.keys()
 
-    def Call(self, args=[], this=None):
-        raise JsTypeError('not a function')
+    #def Call(self, args=[], this=None):
+        #raise JsTypeError('not a function')
 
-    def Construct(self, args=[]):
-        obj = W_Object(Class='Object')
-        prot = self.Get('prototype')
-        if isinstance(prot, W_PrimitiveObject):
-            obj.Prototype = prot
-        else: # would love to test this
-            #but I fail to find a case that falls into this
-            #obj.Prototype = ctx.get_global().Get('Object').Get('prototype')
-            from js.builtins import get_builtin_prototype
-            obj.Prototype = get_builtin_prototype('Object')
-        try: #this is a hack to be compatible to spidermonkey
-            self.Call(args, this=obj)
-            return obj
-        except ReturnException, e:
-            return e.value
+    #def Construct(self, args=[]):
+        #obj = W_Object(Class='Object')
+        #prot = self.Get('prototype')
+        #if isinstance(prot, W_PrimitiveObject):
+            #obj.Prototype = prot
+        #else: # would love to test this
+            ##but I fail to find a case that falls into this
+            ##obj.Prototype = ctx.get_global().Get('Object').Get('prototype')
+            #from js.builtins import get_builtin_prototype
+            #obj.Prototype = get_builtin_prototype('Object')
+        #try: #this is a hack to be compatible to spidermonkey
+            #self.Call(args, this=obj)
+            #return obj
+        #except ReturnException, e:
+            #return e.value
 
-    def Get(self, P):
-        try:
-            return self._get_property_value(P)
-        except KeyError:
-            if self.Prototype is None:
-                return w_Undefined
-        return self.Prototype.Get(P) # go down the prototype chain
+    #def Get(self, P):
+        #try:
+            #return self._get_property_value(P)
+        #except KeyError:
+            #if self.Prototype is None:
+                #return w_Undefined
+        #return self.Prototype.Get(P) # go down the prototype chain
 
-    def CanPut(self, P):
-        if self._has_property(P):
-            if self._get_property_flags(P) & READ_ONLY: return False
-            return True
-        if self.Prototype is None: return True
-        return self.Prototype.CanPut(P)
+    #def CanPut(self, P):
+        #if self._has_property(P):
+            #if self._get_property_flags(P) & READ_ONLY: return False
+            #return True
+        #if self.Prototype is None: return True
+        #return self.Prototype.CanPut(P)
 
-    def Put(self, P, V, flags = 0):
-        if self._has_property(P):
-            self._set_property_value(P, V)
-            f = self._get_property_flags(P) | flags
-            self._set_property_flags(P, f)
-            return
+    #def Put(self, P, V, flags = 0):
+        #if self._has_property(P):
+            #self._set_property_value(P, V)
+            #f = self._get_property_flags(P) | flags
+            #self._set_property_flags(P, f)
+            #return
 
-        if not self.CanPut(P): return
-        self._set_property(P, V, flags)
+        #if not self.CanPut(P): return
+        #self._set_property(P, V, flags)
 
-    def HasProperty(self, P):
-        if self._has_property(P): return True
-        if self.Prototype is None: return False
-        return self.Prototype.HasProperty(P)
+    #def HasProperty(self, P):
+        #if self._has_property(P): return True
+        #if self.Prototype is None: return False
+        #return self.Prototype.HasProperty(P)
 
-    def Delete(self, P):
-        if self._has_property(P):
-            if self._get_property_flags(P) & DONT_DELETE:
-                return False
-            self._delete_property(P)
-            return True
-        return True
+    #def Delete(self, P):
+        #if self._has_property(P):
+            #if self._get_property_flags(P) & DONT_DELETE:
+                #return False
+            #self._delete_property(P)
+            #return True
+        #return True
 
-    def internal_def_value(self, tryone, trytwo):
-        # XXX: redo this!
-        t1 = self.Get(tryone)
-        if isinstance(t1, W_PrimitiveObject):
-            val = t1.Call(this=self)
-            if isinstance(val, W__Primitive):
-                return val
-        t2 = self.Get(trytwo)
-        if isinstance(t2, W_PrimitiveObject):
-            val = t2.Call(this=self)
-            if isinstance(val, W__Primitive):
-                return val
-        raise JsTypeError
+    #def internal_def_value(self, tryone, trytwo):
+        ## XXX: redo this!
+        #t1 = self.Get(tryone)
+        #if isinstance(t1, W_PrimitiveObject):
+            #val = t1.Call(this=self)
+            #if isinstance(val, W__Primitive):
+                #return val
+        #t2 = self.Get(trytwo)
+        #if isinstance(t2, W_PrimitiveObject):
+            #val = t2.Call(this=self)
+            #if isinstance(val, W__Primitive):
+                #return val
+        #raise JsTypeError
 
-    def DefaultValue(self,  hint=""):
-        if hint == "String":
-            return self.internal_def_value("toString", "valueOf")
-        else: # hint can only be empty, String or Number
-            return self.internal_def_value("valueOf", "toString")
+    #def DefaultValue(self,  hint=""):
+        #if hint == "String":
+            #return self.internal_def_value("toString", "valueOf")
+        #else: # hint can only be empty, String or Number
+            #return self.internal_def_value("valueOf", "toString")
 
-    ToPrimitive = DefaultValue
+    #ToPrimitive = DefaultValue
 
-    def ToBoolean(self):
-        return True
+    #def ToBoolean(self):
+        #return True
 
-    def ToString(self):
-        try:
-            res = self.ToPrimitive('String')
-        except JsTypeError:
-            return "[object %s]"%(self.Class,)
-        return res.ToString()
+    #def ToString(self):
+        #try:
+            #res = self.ToPrimitive('String')
+        #except JsTypeError:
+            #return "[object %s]"%(self.Class,)
+        #return res.ToString()
 
-    def __str__(self):
-        return "<Object class: %s>" % self.Class
+    #def __str__(self):
+        #return "<Object class: %s>" % self.Class
 
-    def type(self):
-        return 'object'
+    #def type(self):
+        #return 'object'
 
-class W_Object(W_PrimitiveObject):
-    def __init__(self, Prototype=None, Class='Object', Value=w_Undefined):
-        W_PrimitiveObject.__init__(self, Prototype, Class, Value)
+#class W_Object(W_PrimitiveObject):
+    #def __init__(self, Prototype=None, Class='Object', Value=w_Undefined):
+        #W_PrimitiveObject.__init__(self, Prototype, Class, Value)
 
-    def ToNumber(self):
-        return self.Get('valueOf').Call(args=[], this=self).ToNumber()
+    #def ToNumber(self):
+        #return self.Get('valueOf').Call(args=[], this=self).ToNumber()
 
-class W_CallableObject(W_Object):
-    _immutable_fields_ = ['callfunc', 'ctx']
-    def __init__(self, ctx, Prototype, callfunc):
-        W_Object.__init__(self, Prototype, 'Function')
-        self.ctx = ctx
-        self.callfunc = callfunc
+#class W_CallableObject(W_Object):
+    #_immutable_fields_ = ['callfunc', 'ctx']
+    #def __init__(self, ctx, Prototype, callfunc):
+        #W_Object.__init__(self, Prototype, 'Function')
+        #self.ctx = ctx
+        #self.callfunc = callfunc
 
-    @jit.unroll_safe
-    def Call(self, args=[], this=None):
-        from js.jsexecution_context import make_activation_context, 
make_function_context
+    #@jit.unroll_safe
+    #def Call(self, args=[], this=None):
+        #from js.jsexecution_context import make_activation_context, 
make_function_context
 
-        w_Arguments = W_Arguments(self, args)
-        act = make_activation_context(self.ctx, this, w_Arguments)
-        newctx = make_function_context(act, self.callfunc)
+        #w_Arguments = W_Arguments(self, args)
+        #act = make_activation_context(self.ctx, this, w_Arguments)
+        #newctx = make_function_context(act, self.callfunc)
 
-        paramn = len(self.callfunc.params)
-        for i in range(paramn):
-            paramname = self.callfunc.params[i]
-            try:
-                value = args[i]
-            except IndexError:
-                value = w_Undefined
-            newctx.declare_variable(paramname)
-            newctx.assign(paramname, value)
+        #paramn = len(self.callfunc.params)
+        #for i in range(paramn):
+            #paramname = self.callfunc.params[i]
+            #try:
+                #value = args[i]
+            #except IndexError:
+                #value = w_Undefined
+            #newctx.declare_variable(paramname)
+            #newctx.assign(paramname, value)
 
-        val = self.callfunc.run(ctx=newctx, save_stack = False)
-        return val
+        #val = self.callfunc.run(ctx=newctx, save_stack = False)
+        #return val
 
-    def type(self):
-        return 'function'
+    #def type(self):
+        #return 'function'
 
-class W_NewBuiltin(W_PrimitiveObject):
-    length = -1
-    def __init__(self, Prototype=None, Class='function', Value=w_Undefined):
-        if Prototype is None:
-            #proto = ctx.get_global().Get('Function').Get('prototype')
-            from js.builtins import get_builtin_prototype
-            proto = get_builtin_prototype('Function')
-            Prototype = proto
+#class W_Builtin(W_PrimitiveObject):
+    #def __init__(self, builtin=None, Prototype=None, Class='function', 
Value=w_Undefined):
+        #W_PrimitiveObject.__init__(self, Prototype, Class, Value)
+        #self.set_builtin_call(builtin)
 
-        W_PrimitiveObject.__init__(self, Prototype, Class, Value)
+    #def set_builtin_call(self, callfuncbi):
+        #self.callfuncbi = callfuncbi
 
-        if self.length != -1:
-            self.Put('length', W_IntNumber(self.length), flags = 
DONT_ENUM|DONT_DELETE|READ_ONLY)
+    #def Call(self, args=[], this = None):
+        #return self.callfuncbi(args, this)
 
-    def Call(self, args=[], this = None):
-        raise NotImplementedError
+    #def Construct(self, args=[]):
+        #return self.callfuncbi(args, None)
 
-    def type(self):
-        return self.Class
+    #def type(self):
+        #return self.Class
 
-class W_Builtin(W_PrimitiveObject):
-    def __init__(self, builtin=None, Prototype=None, Class='function', 
Value=w_Undefined):
-        W_PrimitiveObject.__init__(self, Prototype, Class, Value)
-        self.set_builtin_call(builtin)
-
-    def set_builtin_call(self, callfuncbi):
-        self.callfuncbi = callfuncbi
-
-    def Call(self, args=[], this = None):
-        return self.callfuncbi(args, this)
-
-    def Construct(self, args=[]):
-        return self.callfuncbi(args, None)
-
-    def type(self):
-        return self.Class
-
-class W_ListObject(W_PrimitiveObject):
+class W_Arguments(W_BasicObject):
     def tolist(self):
         l = []
         for i in range(self.length):
             l.append(self._get_property_value(str(i)))
         return l
 
-class W_Arguments(W_ListObject):
     @jit.unroll_safe
     def __init__(self, callee, args):
-        W_PrimitiveObject.__init__(self, Class='Arguments')
+        W_BasicObject.__init__(self)
         self._delete_property('prototype')
         self.Put('callee', callee)
         self.Put('length', W_IntNumber(len(args)))
@@ -766,14 +740,14 @@
             self.Put(str(i), args[i])
         self.length = len(args)
 
-class ActivationObject(W_PrimitiveObject):
-    """The object used on function calls to hold arguments and this"""
-    def __init__(self):
-        W_PrimitiveObject.__init__(self, Class='Activation')
-        self._delete_property('prototype')
+#class ActivationObject(W_PrimitiveObject):
+    #"""The object used on function calls to hold arguments and this"""
+    #def __init__(self):
+        #W_PrimitiveObject.__init__(self, Class='Activation')
+        #self._delete_property('prototype')
 
-    def __repr__(self):
-        return str(self.property_map)
+    #def __repr__(self):
+        #return str(self.property_map)
 
 class W_ArrayConstructor(W_BasicObject):
     def IsCallable(self):
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -1,6 +1,5 @@
 from js.jsobj import W_IntNumber, W_FloatNumber, W_String,\
-     W_PrimitiveObject, ActivationObject,\
-     create_object, W_Object, w_Undefined, newbool,\
+     create_object, w_Undefined, newbool,\
      w_True, w_False, W_List, w_Null, W_Iterator, W_Root, W__Function
 import js.jsobj as jsobj
 from js.execution import JsTypeError, ReturnException, ThrowException
@@ -122,10 +121,6 @@
         self.counter = counter
 
     def eval(self, ctx):
-        #proto = ctx.get_global().Get('Array').Get('prototype')
-        # TODO get array prototype?
-        # builtins make_array??
-        #assert isinstance(proto, W_PrimitiveObject)
         from js.jsobj import W__Array
         array = W__Array()
         for i in range(self.counter):
@@ -210,7 +205,7 @@
 class IN(BaseBinaryOperation):
     def operation(self, ctx, left, right):
         from js.jsobj import W_BasicObject
-        if not (isinstance(right, W_Object) or isinstance(right, 
W_BasicObject)):
+        if not isinstance(right, W_BasicObject):
             raise ThrowException(W_String("TypeError: "+ repr(right)))
         name = left.ToString()
         return newbool(right.HasProperty(name))
@@ -492,7 +487,7 @@
 def common_call(ctx, r1, args, this, name):
     # TODO
     from js.jsobj import W_BasicFunction, W_BasicObject
-    if not (isinstance(r1, W_PrimitiveObject) or isinstance(r1, 
W_BasicFunction) or isinstance(r1, W_BasicObject)):
+    if not (isinstance(r1, W_BasicFunction) or isinstance(r1, W_BasicObject)):
         raise ThrowException(W_String("%s is not a callable 
(%s)"%(r1.ToString(), name.ToString())))
     jit.promote(r1)
     try:
@@ -584,7 +579,7 @@
         obj = ctx.pop().ToObject()
         props = []
         from js.jsobj import W_BasicObject
-        assert isinstance(obj, W_PrimitiveObject) or isinstance(obj, 
W_BasicObject)
+        assert isinstance(obj, W_BasicObject)
 
         for prop in obj._get_property_keys():
             if not obj._get_property_flags(prop) & jsobj.DONT_ENUM:
diff --git a/js/operations.py b/js/operations.py
--- a/js/operations.py
+++ b/js/operations.py
@@ -4,9 +4,9 @@
 Implements the javascript operations nodes for the interpretation tree
 """
 
-from js.jsobj import W_IntNumber, W_FloatNumber, W_Object,\
-     w_Undefined, W_NewBuiltin, W_String, create_object, W_List,\
-     W_PrimitiveObject, ActivationObject, W_Boolean,\
+from js.jsobj import W_IntNumber, W_FloatNumber, \
+     w_Undefined, W_String, create_object, W_List,\
+     W_Boolean,\
      w_Null, isnull_or_undefined
 from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal
 from js.execution import JsTypeError, ThrowException
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
@@ -1,7 +1,7 @@
 import py
 from js import interpreter
 from js.operations import IntNumber, FloatNumber, Position, Plus
-from js.jsobj import W_Object, W_Root, w_Null, W___Root
+from js.jsobj import W_Root, w_Null, W___Root
 from js.execution import ThrowException
 from js.jscode import JsCode
 from js.baseop import AbstractEC
diff --git a/js/test/test_parser.py b/js/test/test_parser.py
--- a/js/test/test_parser.py
+++ b/js/test/test_parser.py
@@ -7,7 +7,6 @@
 from pypy import conftest
 
 from js.astbuilder import FakeParseError
-from js.jsobj import W_Object, ThrowException
 from js.astbuilder import ASTBuilder
 from js.jscode import JsCode
 import sys
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to