[pypy-svn] r44109 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Fri Jun 8 13:53:53 CEST 2007
Author: santagada
Date: Fri Jun 8 13:53:51 2007
New Revision: 44109
Modified:
pypy/dist/pypy/lang/js/astbuilder.py
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/operations.py
pypy/dist/pypy/lang/js/test/test_interp.py
pypy/dist/pypy/lang/js/test/test_parser.py
Log:
a new number and string Objects, so now autboxing is complete (I still need to work on more string methods and the array object). Now to string needs the context, probably ToNumber will follow.
Modified: pypy/dist/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/astbuilder.py (original)
+++ pypy/dist/pypy/lang/js/astbuilder.py Fri Jun 8 13:53:51 2007
@@ -155,7 +155,7 @@
pos = self.get_pos(op)
l = [self.dispatch(child) for child in node.children[1:]]
return self.LISTOP_TO_CLS[op.additional_info](pos, l)
- visit_arrayliteral = listop # XXX elision
+ visit_arrayliteral = listop # elision
visit_objectliteral = listop
def visit_block(self, node):
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Fri Jun 8 13:53:51 2007
@@ -22,12 +22,13 @@
f.close()
return t
-class W_ObjectObject(W_Object):
- def __init__(self, ctx=None, Prototype=None, Class='Object',
+class W_NativeObject(W_Object):
+ def __init__(self, Class, Prototype, ctx=None,
Value=w_Undefined, callfunc=None):
W_Object.__init__(self, ctx, Prototype,
Class, Value, callfunc)
-
+
+class W_ObjectObject(W_NativeObject):
def Call(self, ctx, args=[], this=None):
if len(args) >= 1 and not isnull_or_undefined(args[0]):
return args[0].ToObject(ctx)
@@ -35,17 +36,13 @@
return self.Construct(ctx)
def Construct(self, ctx, args=[]):
- if len(args) >= 1 and not (isinstance(args[0], W_Undefined) or isinstance(args[0], W_Null)):
+ if len(args) >= 1 and not (isinstance(args[0], W_Undefined) \
+ or isinstance(args[0], W_Null)):
# XXX later we could separate builtins and normal objects
return args[0].ToObject(ctx)
return create_object(ctx, 'Object')
-class W_BooleanObject(W_Object):
- def __init__(self, ctx=None, Prototype=None, Class='Boolean',
- Value=w_Undefined, callfunc=None):
- W_Object.__init__(self, ctx, Prototype,
- Class, Value, callfunc)
-
+class W_BooleanObject(W_NativeObject):
def Call(self, ctx, args=[], this=None):
if len(args) >= 1 and not isnull_or_undefined(args[0]):
return W_Boolean(args[0].ToBoolean())
@@ -58,6 +55,32 @@
return create_object(ctx, 'Boolean', Value = Value)
return create_object(ctx, 'Boolean', Value = W_Boolean(False))
+class W_NumberObject(W_NativeObject):
+ def Call(self, ctx, args=[], this=None):
+ if len(args) >= 1 and not isnull_or_undefined(args[0]):
+ return W_Number(args[0].ToNumber())
+ else:
+ return W_Number(0.0)
+
+ def Construct(self, ctx, args=[]):
+ if len(args) >= 1 and not isnull_or_undefined(args[0]):
+ Value = W_Number(args[0].ToNumber())
+ return create_object(ctx, 'Number', Value = Value)
+ return create_object(ctx, 'Number', Value = W_Number(0.0))
+
+class W_StringObject(W_NativeObject):
+ def Call(self, ctx, args=[], this=None):
+ if len(args) >= 1 and not isnull_or_undefined(args[0]):
+ return W_String(args[0].ToString(ctx))
+ else:
+ return W_String('')
+
+ def Construct(self, ctx, args=[]):
+ if len(args) >= 1 and not isnull_or_undefined(args[0]):
+ Value = W_String(args[0].ToString(ctx))
+ return create_object(ctx, 'String', Value = Value)
+ return create_object(ctx, 'String', Value = W_String(''))
+
TEST = False
def evaljs(ctx, args, this):
@@ -69,7 +92,7 @@
else:
code = W_String('')
try:
- node = load_source(code.ToString())
+ node = load_source(code.ToString(ctx))
except ParseError, e:
raise ThrowException(W_String('SintaxError: '+str(e)))
@@ -84,7 +107,7 @@
def parseIntjs(ctx, args, this):
if len(args) < 1:
return W_Number(NaN)
- s = args[0].ToString().strip(" ")
+ s = args[0].ToString(ctx).strip(" ")
if len(args) > 1:
radix = args[1].ToInt32()
else:
@@ -103,7 +126,7 @@
def parseFloatjs(ctx, args, this):
if len(args) < 1:
return W_Number(NaN)
- s = args[0].ToString().strip(" ")
+ s = args[0].ToString(ctx).strip(" ")
try:
n = float(s)
except ValueError:
@@ -112,7 +135,7 @@
def printjs(ctx, args, this):
- writer(",".join([i.GetValue().ToString() for i in args]))
+ writer(",".join([i.GetValue().ToString(ctx) for i in args]))
return w_Undefined
def isnanjs(ctx, args, this):
@@ -136,7 +159,7 @@
def stringjs(ctx, args, this):
if len(args) > 0:
- return W_String(args[0].ToString())
+ return W_String(args[0].ToString(ctx))
return W_String('')
def arrayjs(ctx, args, this):
@@ -177,7 +200,7 @@
class W_HasOwnProperty(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
if len(args) >= 1:
- propname = args[0].ToString()
+ propname = args[0].ToString(ctx)
if propname in this.propdict:
return W_Boolean(True)
return W_Boolean(False)
@@ -196,7 +219,7 @@
class W_PropertyIsEnumerable(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
if len(args) >= 1:
- propname = args[0].ToString()
+ propname = args[0].ToString(ctx)
if propname in this.propdict and not this.propdict[propname].de:
return W_Boolean(True)
return W_Boolean(False)
@@ -205,10 +228,10 @@
def Call(self, ctx, args=[], this=None):
tam = len(args)
if tam >= 1:
- fbody = args[tam-1].GetValue().ToString()
+ fbody = args[tam-1].GetValue().ToString(ctx)
argslist = []
for i in range(tam-1):
- argslist.append(args[i].GetValue().ToString())
+ argslist.append(args[i].GetValue().ToString(ctx))
fargs = ','.join(argslist)
functioncode = "function (%s) {%s}"%(fargs, fbody)
else:
@@ -220,10 +243,13 @@
def Construct(self, ctx, args=[]):
return self.Call(ctx, args, this=None)
+functionstring= 'function (arguments go here!) {\n'+ \
+ ' [lots of stuff :)]\n'+ \
+ '}'
class W_FToString(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
if this.Class == 'Function':
- return W_String('function (arguments go here!) {\n [lots of stuff :)]\n}')
+ return W_String(functionstring)
else:
raise JsTypeError('this is not a function object')
@@ -241,7 +267,8 @@
arrayArgs = args[1]
if isinstance(arrayArgs, W_ListObject):
callargs = arrayArgs.tolist()
- elif isinstance(arrayArgs, W_Undefined) or isinstance(arrayArgs, W_Null):
+ elif isinstance(arrayArgs, W_Undefined) \
+ or isinstance(arrayArgs, W_Null):
callargs = []
else:
raise JsTypeError('arrayArgs is not an Array or Arguments object')
@@ -265,13 +292,31 @@
class W_ValueToString(W_NewBuiltin):
"this is the toString function for objects with Value"
def Call(self, ctx, args=[], this=None):
- return W_String(this.Value.ToString())
+ return W_String(this.Value.ToString(ctx))
class W_ValueValueOf(W_NewBuiltin):
"this is the valueOf function for objects with Value"
def Call(self, ctx, args=[], this=None):
return this.Value
+class W_CharAt(W_NewBuiltin):
+ def Call(self, ctx, args=[], this=None):
+ string = this.ToString(ctx)
+ if len(args)>=1:
+ pos = args[0].ToInt32()
+ if (not pos >=0) or (pos > len(string) - 1):
+ return W_String('')
+ else:
+ return W_String('')
+ return W_String(string[pos])
+
+class W_Concat(W_NewBuiltin):
+ def Call(self, ctx, args=[], this=None):
+ string = this.ToString(ctx)
+ others = [obj.ToString(ctx) for obj in args]
+ string += ''.join(others)
+ return W_String(string)
+
class W_DateFake(W_NewBuiltin): # XXX This is temporary
def Call(self, ctx, args=[], this=None):
return create_object(ctx, 'Object')
@@ -293,7 +338,7 @@
w_Global.Put('Function', w_Function)
- w_Object = W_ObjectObject(Prototype=w_Function)
+ w_Object = W_ObjectObject('Object', w_Function)
w_Object.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True)
w_Global.Put('Object', w_Object)
@@ -320,15 +365,35 @@
w_FncPrototype.Put('apply', W_Apply(ctx))
w_FncPrototype.Put('call', W_Call(ctx))
- w_Boolean = W_BooleanObject(Prototype=w_FncPrototype)
+ w_Boolean = W_BooleanObject('Boolean', w_FncPrototype)
w_Boolean.Put('constructor', w_FncPrototype)
+
w_BoolPrototype = create_object(ctx, 'Object', Value=W_Boolean(False))
w_BoolPrototype.Class = 'Boolean'
- w_Boolean.Put('prototype', w_BoolPrototype)
w_BoolPrototype.Put('constructor', w_FncPrototype)
w_BoolPrototype.Put('toString', W_ValueToString(ctx))
w_BoolPrototype.Put('valueOf', W_ValueValueOf(ctx))
+
+ w_Boolean.Put('prototype', w_BoolPrototype)
+
w_Global.Put('Boolean', w_Boolean)
+
+ #Number
+ w_Number = W_NumberObject('Number', w_FncPrototype)
+ w_Number.Put('constructor', w_FncPrototype)
+
+ w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0))
+ w_NumPrototype.Class = 'Number'
+ w_NumPrototype.Put('constructor', w_FncPrototype)
+ w_NumPrototype.Put('toString', W_ValueToString(ctx))
+ w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx))
+
+ w_Number.Put('prototype', w_NumPrototype)
+ w_Number.Put('NaN', W_Number(NaN))
+ w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity))
+ w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity))
+
+ w_Global.Put('Number', w_Number)
#Math
@@ -358,12 +423,35 @@
w_Global.Put('Date', w_Date)
#Number
- w_Number = W_Builtin(numberjs, Class="Number")
+ w_Number = W_NumberObject('Number', w_FncPrototype)
+
+ w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0))
+ w_NumPrototype.Class = 'Number'
+ w_NumPrototype.Put('constructor', w_FncPrototype)
+ w_NumPrototype.Put('toString', W_ValueToString(ctx))
+ w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx))
+
+ w_Number.Put('prototype', w_NumPrototype)
w_Number.Put('NaN', W_Number(NaN))
w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity))
w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity))
+
w_Global.Put('Number', w_Number)
+ #String
+ w_String = W_StringObject('String', w_FncPrototype)
+ w_StrPrototype = create_object(ctx, 'Object', Value=W_String(''))
+ w_StrPrototype.Class = 'String'
+ w_StrPrototype.Put('constructor', w_FncPrototype)
+ w_StrPrototype.Put('toString', W_ValueToString(ctx))
+ w_StrPrototype.Put('valueOf', W_ValueValueOf(ctx))
+ w_StrPrototype.Put('charAt', W_CharAt(ctx))
+ w_StrPrototype.Put('concat', W_Concat(ctx))
+
+ w_String.Put('prototype', w_StrPrototype)
+
+ w_Global.Put('String', w_String)
+
w_Global.Put('NaN', W_Number(NaN))
w_Global.Put('Infinity', W_Number(Infinity))
@@ -394,7 +482,8 @@
res.append(arg)
elif isinstance(arg, str):
res.append(W_String(arg))
- elif isinstance(arg, int) or isinstance(arg, float) or isinstance(arg, long):
+ elif isinstance(arg, int) or isinstance(arg, float) \
+ or isinstance(arg, long):
res.append(W_Number(arg))
elif isinstance(arg, bool):
res.append(W_Boolean(arg))
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Fri Jun 8 13:53:51 2007
@@ -54,7 +54,7 @@
def ToPrimitive(self, ctx, hint=""):
return self
- def ToString(self):
+ def ToString(self, ctx):
return ''
def ToObject(self, ctx):
@@ -85,12 +85,12 @@
raise NotImplementedError
def __str__(self):
- return self.ToString()
+ return self.ToString(ctx=None)
def type(self):
raise NotImplementedError
-
- def delete(self):
+
+ def GetPropertyName(self):
raise NotImplementedError
class W_Undefined(W_Root):
@@ -103,7 +103,7 @@
def ToBoolean(self):
return False
- def ToString(self):
+ def ToString(self, ctx = None):
return "undefined"
def type(self):
@@ -169,7 +169,8 @@
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
+ 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')
try: #this is a hack to be compatible to spidermonkey
self.Call(ctx, args, this=obj)
@@ -233,8 +234,12 @@
ToPrimitive = DefaultValue
- def ToString(self):
- return "[object %s]"%(self.Class,)
+ def ToString(self, ctx):
+ try:
+ res = self.ToPrimitive(ctx, 'String')
+ except JsTypeError:
+ return "[object %s]"%(self.Class,)
+ return res.ToString(ctx)
def __str__(self):
return "<Object class: %s>" % self.Class
@@ -246,7 +251,7 @@
return 'object'
def str_builtin(ctx, args, this):
- return W_String(this.ToString())
+ return W_String(this.ToString(ctx))
class W_Object(W_PrimitiveObject):
def __init__(self, ctx=None, Prototype=None, Class='Object',
@@ -264,7 +269,7 @@
W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc)
def Call(self, ctx, args=[], this = None):
- return NotImplementedError
+ raise NotImplementedError
def type(self):
return 'builtin'
@@ -360,11 +365,12 @@
self.propdict['length'].value = W_Number(index+1)
return
- def ToString(self):
- return ','.join([self.Get(str(index)).ToString() for index in range(self.length)])
+ def ToString(self, ctx):
+ return ','.join([self.Get(str(index)).ToString(ctx)
+ for index in range(self.length)])
def array_str_builtin(ctx, args, this):
- return W_String(this.ToString())
+ return W_String(this.ToString(ctx))
@@ -375,7 +381,7 @@
def ToObject(self, ctx):
return create_object(ctx, 'Boolean', Value=self)
- def ToString(self):
+ def ToString(self, ctx=None):
if self.boolval == True:
return "true"
return "false"
@@ -401,7 +407,10 @@
def __str__(self):
return self.strval+"W"
- def ToString(self):
+ def ToObject(self, ctx):
+ return create_object(ctx, 'String', Value=self)
+
+ def ToString(self, ctx=None):
return self.strval
def ToBoolean(self):
@@ -417,14 +426,18 @@
def __init__(self, floatval):
try:
self.floatval = float(floatval)
- except OverflowError: # XXX this should not be happening, there is an error somewhere else
+ except OverflowError:
+ # XXX this should not be happening, there is an error somewhere else
#an ecma test to stress this is GlobalObject/15.1.2.2-2.js
self.floatval = Infinity
def __str__(self):
return str(self.floatval)+"W"
+
+ def ToObject(self, ctx):
+ return create_object(ctx, 'Number', Value=self)
- def ToString(self):
+ def ToString(self, ctx = None):
floatstr = str(self.floatval)
if floatstr == str(NaN):
return 'NaN'
@@ -473,12 +486,12 @@
def GetPropertyName(self):
return self.ToString()
-
+
class W_List(W_Root):
def __init__(self, list_w):
self.list_w = list_w
- def ToString(self):
+ def ToString(self, ctx = None):
raise SeePage(42)
def ToBoolean(self):
@@ -491,7 +504,8 @@
return str(self.list_w)
class ExecutionContext(object):
- def __init__(self, scope, this=None, variable=None, debug=False, jsproperty=None):
+ def __init__(self, scope, this=None, variable=None,
+ debug=False, jsproperty=None):
assert scope is not None
self.scope = scope
if this is None:
@@ -505,7 +519,8 @@
self.variable = variable
self.debug = debug
if jsproperty is None:
- self.property = Property('',w_Undefined) #Attribute flags for new vars
+ #Attribute flags for new vars
+ self.property = Property('',w_Undefined)
else:
self.property = jsproperty
@@ -520,6 +535,7 @@
def push_object(self, obj):
"""push object into scope stack"""
+ assert isinstance(obj, W_PrimitiveObject)
self.scope.insert(0, obj)
self.variable = obj
@@ -529,6 +545,7 @@
def resolve_identifier(self, identifier):
for obj in self.scope:
+ assert isinstance(obj, W_PrimitiveObject)
if obj.HasProperty(identifier):
return W_Reference(identifier, obj)
@@ -536,6 +553,7 @@
def global_context(w_global):
+ assert isinstance(w_global, W_PrimitiveObject)
ctx = ExecutionContext([w_global],
this = w_global,
variable = w_global,
@@ -594,9 +612,10 @@
def __str__(self):
return "<" + str(self.base) + " -> " + str(self.property_name) + ">"
-def create_object(ctx, prototypename, callfunc=None, Value=None):
+def create_object(ctx, prototypename, callfunc=None, Value=w_Undefined):
proto = ctx.get_global().Get(prototypename).Get('prototype')
- obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class = proto.Class, Value = Value)
+ obj = W_Object(ctx, callfunc = callfunc,Prototype=proto,
+ Class = proto.Class, Value = Value)
return obj
def isnull_or_undefined(obj):
Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py (original)
+++ pypy/dist/pypy/lang/js/operations.py Fri Jun 8 13:53:51 2007
@@ -67,7 +67,7 @@
class UnaryOp(Expression):
def __init__(self, pos, expr, postfix=False):
self.pos = pos
- assert isinstance(expr, Node)
+ #assert isinstance(expr, Node)
self.expr = expr
self.postfix = postfix
@@ -212,7 +212,7 @@
r1 = self.left.eval(ctx)
r2 = self.right.eval(ctx)
r3 = r1.GetValue()
- if not isinstance(r3, W_PrimitiveObject): # TODO: review this on the spec
+ if not isinstance(r3, W_PrimitiveObject):
raise ThrowException(W_String("it is not a callable"))
if isinstance(r1, W_Reference):
@@ -251,13 +251,15 @@
class Member(BinaryOp):
+ "this is for object[name]"
def eval(self, ctx):
w_obj = self.left.eval(ctx).GetValue().ToObject(ctx)
- name = self.right.eval(ctx).GetValue().ToString()
+ name = self.right.eval(ctx).GetValue().ToString(ctx)
return W_Reference(name, w_obj)
class MemberDot(BinaryOp):
+ "this is for object.name"
def eval(self, ctx):
w_obj = self.left.eval(ctx).GetValue().ToObject(ctx)
name = self.right.get_literal()
@@ -341,8 +343,8 @@
else:
return 0
else:
- s4 = s1.ToString()
- s5 = s2.ToString()
+ s4 = s1.ToString(ctx)
+ s5 = s2.ToString(ctx)
if s4 < s5:
return 1
if s4 == s5:
@@ -454,7 +456,7 @@
return True
return False
elif type1 == "string":
- return x.ToString() == y.ToString()
+ return x.ToString(ctx) == y.ToString(ctx)
elif type1 == "boolean":
return x.ToBoolean() == x.ToBoolean()
return x == y
@@ -486,7 +488,7 @@
return True
if isinstance(x, W_String) and isinstance(y, W_String):
- r = x.ToString() == y.ToString()
+ r = x.ToString(ctx) == y.ToString(ctx)
else:
r = x.ToNumber() == y.ToNumber()
return r
@@ -507,7 +509,7 @@
#
##############################################################################
-def SEC(x,y):
+def SEC(ctx, x, y):
"""
Implements the Strict Equality Comparison x === y
trying to be fully to the spec
@@ -528,18 +530,18 @@
return True
return False
if type1 == "string":
- return x.ToString() == y.ToString()
+ return x.ToString(ctx) == y.ToString(ctx)
if type1 == "boolean":
return x.ToBoolean() == x.ToBoolean()
return x == y
class StrictEq(BinaryComparisonOp):
def decision(self, ctx, op1, op2):
- return W_Boolean(SEC(op1, op2))
+ return W_Boolean(SEC(ctx, op1, op2))
class StrictNe(BinaryComparisonOp):
def decision(self, ctx, op1, op2):
- return W_Boolean(not SEC(op1, op2))
+ return W_Boolean(not SEC(ctx, op1, op2))
class In(BinaryComparisonOp):
@@ -549,7 +551,7 @@
def decision(self, ctx, op1, op2):
if not isinstance(op2, W_Object):
raise ThrowException(W_String("TypeError"))
- name = op1.ToString()
+ name = op1.ToString(ctx)
return W_Boolean(op2.HasProperty(name))
class Delete(UnaryOp):
@@ -600,7 +602,7 @@
class Index(BinaryOp):
def eval(self, ctx):
w_obj = self.left.eval(ctx).GetValue().ToObject(ctx)
- name= self.right.eval(ctx).GetValue().ToString()
+ name= self.right.eval(ctx).GetValue().ToString(ctx)
return W_Reference(name, w_obj)
class ArgumentList(ListOp):
@@ -626,8 +628,8 @@
def plus(ctx, nleft, nright):
if isinstance(nleft, W_String) or isinstance(nright, W_String):
- sleft = nleft.ToString()
- sright = nright.ToString()
+ sleft = nleft.ToString(ctx)
+ sright = nright.ToString(ctx)
return W_String(sleft + sright)
else:
fleft = nleft.ToNumber()
@@ -988,7 +990,7 @@
class ForIn(Statement):
def __init__(self, pos, iterator, lobject, body):
self.pos = pos
- assert isinstance(iterator, Node)
+ #assert isinstance(iterator, Node)
self.iterator = iterator
self.object = lobject
self.body = body
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 Fri Jun 8 13:53:51 2007
@@ -17,10 +17,11 @@
l = []
interpreter.writer = l.append
jsint = interpreter.Interpreter()
+ ctx = jsint.w_Global
try:
jsint.run(interpreter.load_source(code))
except ThrowException, excpt:
- l.append("uncaught exception: "+str(excpt.exception.ToString()))
+ l.append("uncaught exception: "+str(excpt.exception.ToString(ctx)))
print l, prints
if isinstance(prints, list):
assert l == prints
@@ -29,6 +30,7 @@
def assertv(code, value):
jsint = interpreter.Interpreter()
+ ctx = jsint.w_Global
try:
code_val = jsint.run(interpreter.load_source(code)).GetValue()
except ThrowException, excpt:
@@ -43,7 +45,7 @@
elif isinstance(value, float):
assert code_val.ToNumber() == value
else:
- assert code_val.ToString() == value
+ assert code_val.ToString(ctx) == value
def asserte(code, value):
jsint = interpreter.Interpreter()
@@ -232,6 +234,8 @@
yield assertv, "0==1;", False
yield assertv, "0!=1;", True
yield assertv, "1!=1;", False
+ yield assertv, "1===1;", True
+ yield assertv, "1!==1;", False
def test_string_compare():
yield assertv, "'aaa' > 'a';", True
@@ -575,10 +579,9 @@
};""", 15
def test_autoboxing():
- py.test.skip("not ready yet")
- yield assertv, "'abc'.charAt(0)", 0
+ yield assertv, "'abc'.charAt(0)", 'a'
yield assertv, "true.toString()", 'true'
- yield assertv, "5.toString()", '5'
+ yield assertv, "x=5; x.toString();", '5'
def test_proper_prototype_inheritance():
yield assertv, """
Modified: pypy/dist/pypy/lang/js/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_parser.py (original)
+++ pypy/dist/pypy/lang/js/test/test_parser.py Fri Jun 8 13:53:51 2007
@@ -4,7 +4,7 @@
from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
from pypy.rlib.parsing.parsing import ParseError, Rule
from pypy.rlib.parsing.tree import RPythonVisitor
-from pypy.lang.js.jsobj import W_Object, global_context, ThrowException
+from pypy.lang.js.jsobj import W_Object, global_context, ThrowException, empty_context
from pypy.lang.js.astbuilder import ASTBuilder
from pypy import conftest
import sys
@@ -279,6 +279,7 @@
class TestToASTExpr(BaseGrammarTest):
def setup_class(cls):
cls.parse = parse_func('expression')
+ cls.ctx = empty_context()
def to_ast(self, s):
return ASTBuilder().dispatch(self.parse(s))
@@ -309,11 +310,11 @@
w_num = self.eval_expr('((((6))))')
assert w_num.ToNumber() == 6
w_array = self.eval_expr('[1,2,3]')
- assert w_array.ToString() == '1,2,3'
+ assert w_array.ToString(self.ctx) == '1,2,3'
w_identifier = self.eval_expr('x')
py.test.raises(ThrowException, w_identifier.GetValue)
w_object = self.eval_expr('{x:1}')
- assert w_object.ToString() == '[object Object]'
+ assert w_object.ToString(self.ctx) == '[object Object]'
assert w_object.Get('x').ToNumber() == 1
def test_expression(self):
@@ -326,7 +327,7 @@
w_num = self.eval_expr('--5')
assert w_num.ToNumber() == 4
w_str = self.eval_expr('"hello "+\'world\'')
- assert w_str.ToString() == 'hello world'
+ assert w_str.ToString(self.ctx) == 'hello world'
from pypy.lang.js.jsparser import parse
More information about the pypy-svn
mailing list