Author: Stephan <[email protected]>
Branch:
Changeset: r143:7b76aa64abd9
Date: 2011-11-02 11:52 +0100
http://bitbucket.org/pypy/lang-js/changeset/7b76aa64abd9/
Log: mark W_Root as settled
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -53,10 +53,11 @@
length = 1
def Call(self, ctx, args=[], this=None):
if len(args) >= 1:
- if isinstance(args[0], W_String):
- src = args[0].strval
+ arg0 = args[0]
+ if isinstance(arg0, W_String):
+ src = arg0.strval
else:
- return args[0]
+ return arg0
else:
return w_Undefined
@@ -241,6 +242,7 @@
class W_ToString(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
+ assert isinstance(this, W_PrimitiveObject)
return W_String("[object %s]"%this.Class)
class W_ValueOf(W_NewBuiltin):
@@ -258,12 +260,15 @@
class W_IsPrototypeOf(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
- if len(args) >= 1 and isinstance(args[0], W_PrimitiveObject):
+ w_obj = args[0]
+ if len(args) >= 1 and isinstance(w_obj, W_PrimitiveObject):
O = this
- V = args[0].Prototype
+ 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)
@@ -304,6 +309,7 @@
'}'
class W_FToString(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
+ assert isinstance(this, W_PrimitiveObject)
if this.Class == 'Function':
return W_String(functionstring)
else:
@@ -321,12 +327,7 @@
try:
arrayArgs = args[1]
- if isinstance(arrayArgs, W_ListObject):
- callargs = arrayArgs.tolist()
- elif isnull_or_undefined(arrayArgs):
- callargs = []
- else:
- raise JsTypeError('arrayArgs is not an Array or Arguments
object')
+ callargs = arrayArgs.tolist()
except IndexError:
callargs = []
return this.Call(ctx, callargs, this=thisArg)
@@ -348,6 +349,7 @@
"this is the toString function for objects with Value"
mytype = ''
def Call(self, ctx, args=[], this=None):
+ assert isinstance(this, W_PrimitiveObject)
if this.Value.type() != self.mytype:
raise JsTypeError('Wrong type')
return W_String(this.Value.ToString(ctx))
@@ -504,6 +506,7 @@
class W_ValueValueOf(W_NewBuiltin):
"this is the valueOf function for objects with Value"
def Call(self, ctx, 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
@@ -615,9 +618,11 @@
def unescapejs(ctx, args, this):
# XXX consider using StringBuilder here
res = []
- if not isinstance(args[0], W_String):
+ w_string = args[0]
+ if not isinstance(w_string, W_String):
raise JsTypeError(W_String("Expected string"))
- strval = args[0].strval
+ assert isinstance(w_string, W_String)
+ strval = w_string.strval
lgt = len(strval)
i = 0
while i < lgt:
@@ -697,6 +702,8 @@
def create_array(ctx, elements=[]):
proto = ctx.get_global().Get(ctx, 'Array').Get(ctx, 'prototype')
+ # TODO do not get array prototype from global context?
+ assert isinstance(proto, W_PrimitiveObject)
array = W_Array(ctx, Prototype=proto, Class = proto.Class)
i = 0
while i < len(elements):
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -34,9 +34,13 @@
return Property(name, value, True, True, True, True)
class W_Root(object):
- _immutable_fields_ = ['strval']
+ _settled_ = True
+ _attrs_ = []
def __init__(self):
pass
+
+ def tolist(self):
+ raise JsTypeError('arrayArgs is not an Array or Arguments object')
#def GetValue(self):
# return self
@@ -74,6 +78,9 @@
def PutValue(self, w, ctx):
pass
+ def CanPut(self, P):
+ return False
+
def Call(self, ctx, args=[], this=None):
raise NotImplementedError(self.__class__)
@@ -86,6 +93,21 @@
def GetPropertyName(self):
raise NotImplementedError(self.__class__)
+ def HasProperty(self, identifier):
+ return False
+
+ def Delete(self, name):
+ return False
+
+ def _get_property_keys(self):
+ raise NotImplementedError(self.__class__)
+
+ def _get_property_flags(self, prop):
+ raise NotImplementedError(self.__class__)
+
+ def _get_property_value(self, prop):
+ raise NotImplementedError(self.__class__)
+
class W_Undefined(W_Root):
def __str__(self):
return "w_undefined"
@@ -105,6 +127,9 @@
def type(self):
return 'undefined'
+ def tolist(self):
+ return []
+
class W_Null(W_Root):
def __str__(self):
return "null"
@@ -118,6 +143,9 @@
def type(self):
return 'null'
+ def tolist(self):
+ return []
+
w_Undefined = W_Undefined()
w_Null = W_Null()
@@ -148,6 +176,7 @@
return True
class W_PrimitiveObject(W_Root):
+ _immutable_fields_ = ['Class', 'callfunc', 'Property', 'ctx', 'Scope',
'Value']
def __init__(self, ctx=None, Prototype=None, Class='Object',
Value=w_Undefined, callfunc=None):
self.Prototype = Prototype
self.property_map = root_map()
@@ -196,6 +225,7 @@
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
@@ -215,7 +245,7 @@
def _get_property_keys(self):
return self.property_map.keys()
- #@jit.unroll_safe
+ @jit.unroll_safe
def Call(self, ctx, args=[], this=None):
if self.callfunc is None: # XXX Not sure if I should raise it here
raise JsTypeError('not a function')
@@ -397,6 +427,7 @@
return l
class W_Arguments(W_ListObject):
+ @jit.unroll_safe
def __init__(self, callee, args):
W_PrimitiveObject.__init__(self, Class='Arguments')
self._delete_property('prototype')
@@ -489,6 +520,7 @@
return "<W_Bool "+str(self.boolval)+" >"
class W_String(W_Primitive):
+ _immutable_fields_ = ['strval']
def __init__(self, strval):
W_Primitive.__init__(self)
self.strval = strval
@@ -672,6 +704,8 @@
def create_object(ctx, prototypename, callfunc=None, Value=w_Undefined):
proto = ctx.get_global().Get(ctx, prototypename).Get(ctx, 'prototype')
+ # TODO get Object prototype from interp.w_Object
+ assert isinstance(proto, W_PrimitiveObject)
obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class =
proto.Class, Value = Value)
obj.Put(ctx, '__proto__', proto, DONT_ENUM | DONT_DELETE | READ_ONLY)
return obj
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -141,6 +141,8 @@
def eval(self, ctx):
proto = ctx.get_global().Get(ctx, 'Array').Get(ctx, 'prototype')
+ # TODO get array prototype?
+ assert isinstance(proto, W_PrimitiveObject)
array = W_Array(ctx, Prototype=proto, Class = proto.Class)
for i in range(self.counter):
array.Put(ctx, str(self.counter - i - 1), ctx.pop())
@@ -509,6 +511,7 @@
def common_call(ctx, r1, args, this, name):
if not isinstance(r1, W_PrimitiveObject):
raise ThrowException(W_String("%s is not a callable
(%s)"%(r1.ToString(ctx), name)))
+ jit.promote(r1)
try:
res = r1.Call(ctx=ctx, args=args.tolist(), this=this)
except JsTypeError:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit