Author: Stephan <[email protected]>
Branch:
Changeset: r150:58f74d330039
Date: 2011-11-02 13:40 +0100
http://bitbucket.org/pypy/lang-js/changeset/58f74d330039/
Log: no ctx argument for
* Put
* ToInt32
* ToUInt32
diff --git a/js/baseop.py b/js/baseop.py
--- a/js/baseop.py
+++ b/js/baseop.py
@@ -44,8 +44,8 @@
def sub(ctx, nleft, nright):
if isinstance(nleft, W_IntNumber) and isinstance(nright, W_IntNumber):
# XXX fff
- ileft = nleft.ToInt32(ctx)
- iright = nright.ToInt32(ctx)
+ ileft = nleft.ToInt32()
+ iright = nright.ToInt32()
try:
return W_IntNumber(ovfcheck(ileft - iright))
except OverflowError:
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -78,7 +78,7 @@
return W_FloatNumber(NAN)
s = args[0].ToString(ctx).strip(" ")
if len(args) > 1:
- radix = args[1].ToInt32(ctx)
+ radix = args[1].ToInt32()
else:
radix = 10
if len(s) >= 2 and (s.startswith('0x') or s.startswith('0X')) :
@@ -109,7 +109,7 @@
def Call(self, ctx, args=[], this=None):
temp = []
for arg in args:
- i = arg.ToInt32(ctx) % 65536 # XXX should be uint16
+ i = arg.ToInt32() % 65536 # XXX should be uint16
temp.append(chr(i))
return W_String(''.join(temp))
@@ -118,7 +118,7 @@
def Call(self, ctx, args=[], this=None):
string = this.ToString(ctx)
if len(args)>=1:
- pos = args[0].ToInt32(ctx)
+ pos = args[0].ToInt32()
if (not pos >=0) or (pos > len(string) - 1):
return W_String('')
else:
@@ -129,7 +129,7 @@
def Call(self, ctx, args=[], this=None):
string = this.ToString(ctx)
if len(args)>=1:
- pos = args[0].ToInt32(ctx)
+ pos = args[0].ToInt32()
if pos < 0 or pos > len(string) - 1:
return W_FloatNumber(NAN)
else:
@@ -213,7 +213,7 @@
separator = args[0].ToString(ctx)
if len(args) >= 2:
- limit = args[1].ToUInt32(ctx)
+ limit = args[1].ToUInt32()
raise ThrowException(W_String("limit not implemented"))
# array = string.split(separator, limit)
else:
@@ -223,7 +223,7 @@
i = 0
while i < len(array):
w_str = W_String(array[i])
- w_array.Put(ctx, str(i), w_str)
+ w_array.Put(str(i), w_str)
i += 1
return w_array
@@ -381,17 +381,17 @@
class W_ArrayPush(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
- n = this.Get('length').ToUInt32(ctx)
+ n = this.Get('length').ToUInt32()
for arg in args:
- this.Put(ctx, str(n), arg)
+ this.Put(str(n), arg)
n += 1
j = W_IntNumber(n)
- this.Put(ctx, 'length', j);
+ this.Put('length', j);
return j
class W_ArrayPop(W_NewBuiltin):
def Call(self, ctx, args=[], this=None):
- len = this.Get('length').ToUInt32(ctx)
+ len = this.Get('length').ToUInt32()
if(len == 0):
return w_Undefined
else:
@@ -399,13 +399,13 @@
indxstr = str(indx)
element = this.Get(indxstr)
this.Delete(indxstr)
- this.Put(ctx, 'length', W_IntNumber(indx))
+ this.Put('length', W_IntNumber(indx))
return element
class W_ArrayReverse(W_NewBuiltin):
length = 0
def Call(self, ctx, args=[], this=None):
- r2 = this.Get('length').ToUInt32(ctx)
+ r2 = this.Get('length').ToUInt32()
k = r_uint(0)
r3 = r_uint(math.floor( float(r2)/2.0 ))
if r3 == k:
@@ -419,8 +419,8 @@
r9 = this.Get(r7)
r10 = this.Get(r8)
- this.Put(ctx, r7, r10)
- this.Put(ctx, r8, r9)
+ this.Put(r7, r10)
+ this.Put(r8, r9)
k += 1
return this
@@ -429,7 +429,7 @@
length = 1
#XXX: further optimize this function
def Call(self, ctx, args=[], this=None):
- length = this.Get('length').ToUInt32(ctx)
+ length = this.Get('length').ToUInt32()
# According to ECMA-262 15.4.4.11, non-existing properties always come
after
# existing values. Undefined is always greater than any other value.
@@ -458,13 +458,13 @@
# put sorted values back
values = sorter.list
for i in range(len(values)):
- this.Put(ctx, str(i), values[i])
+ this.Put(str(i), values[i])
# append undefined values
newlength = len(values)
while undefs > 0:
undefs -= 1
- this.Put(ctx, str(newlength), w_Undefined)
+ this.Put(str(newlength), w_Undefined)
newlength += 1
# delete non-existing elements on the end
@@ -499,7 +499,7 @@
def put_values(ctx, obj, dictvalues):
for key,value in dictvalues.iteritems():
- obj.Put(ctx, key, value)
+ obj.Put(key, value)
@specialize.memo()
def get_value_of(type):
@@ -513,7 +513,7 @@
return W_ValueValueOf
def common_join(ctx, this, sep=','):
- length = this.Get('length').ToUInt32(ctx)
+ length = this.Get('length').ToUInt32()
l = []
i = 0
while i < length:
@@ -535,7 +535,7 @@
def lt(self, a, b):
if self.compare_fn:
- result = self.compare_fn.Call(self.ctx, [a, b]).ToInt32(self.ctx)
+ result = self.compare_fn.Call(self.ctx, [a, b]).ToInt32()
return result == -1
return a.ToString(self.ctx) < b.ToString(self.ctx)
@@ -707,7 +707,7 @@
array = W_Array(ctx, Prototype=proto, Class = proto.Class)
i = 0
while i < len(elements):
- array.Put(ctx, str(i), elements[i])
+ array.Put(str(i), elements[i])
i += 1
return array
@@ -716,7 +716,7 @@
def Call(self, ctx, args=[], this=None):
if len(args) == 1 and isinstance(args[0], W_BaseNumber):
array = create_array(ctx)
- array.Put(ctx, 'length', args[0])
+ array.Put('length', args[0])
else:
array = create_array(ctx, args)
return array
@@ -735,19 +735,19 @@
w_Function = W_Function(ctx, Class='Function', Prototype=w_ObjPrototype)
w_FncPrototype = W_Function(ctx, Class='Function',
Prototype=w_ObjPrototype)#W_Object(Prototype=None, Class='Function')
- w_Function.Put(ctx, 'length', W_IntNumber(1), flags = allon)
- w_Global.Put(ctx, 'Function', w_Function)
+ w_Function.Put('length', W_IntNumber(1), flags = allon)
+ w_Global.Put('Function', w_Function)
w_Object = W_ObjectObject('Object', w_FncPrototype)
- w_Object.Put(ctx, 'prototype', w_ObjPrototype, flags = allon)
- w_Object.Put(ctx, 'length', W_IntNumber(1), flags = allon)
+ w_Object.Put('prototype', w_ObjPrototype, flags = allon)
+ w_Object.Put('length', W_IntNumber(1), flags = allon)
w_Global.Prototype = w_ObjPrototype
- w_Object.Put(ctx, 'prototype', w_ObjPrototype, flags = allon)
- w_Global.Put(ctx, 'Object', w_Object)
+ w_Object.Put('prototype', w_ObjPrototype, flags = allon)
+ w_Global.Put('Object', w_Object)
- w_Function.Put(ctx, 'prototype', w_FncPrototype, flags = allon)
- w_Function.Put(ctx, 'constructor', w_Function, flags=allon)
+ w_Function.Put('prototype', w_FncPrototype, flags = allon)
+ w_Function.Put('constructor', w_Function, flags=allon)
toString = W_ToString(ctx)
@@ -774,8 +774,8 @@
})
w_Boolean = W_BooleanObject('Boolean', w_FncPrototype)
- w_Boolean.Put(ctx, 'constructor', w_FncPrototype, flags = allon)
- w_Boolean.Put(ctx, 'length', W_IntNumber(1), flags = allon)
+ w_Boolean.Put('constructor', w_FncPrototype, flags = allon)
+ w_Boolean.Put('length', W_IntNumber(1), flags = allon)
w_BoolPrototype = create_object(ctx, 'Object', Value=newbool(False))
w_BoolPrototype.Class = 'Boolean'
@@ -787,8 +787,8 @@
'valueOf': get_value_of('Boolean')(ctx),
})
- w_Boolean.Put(ctx, 'prototype', w_BoolPrototype, flags = allon)
- w_Global.Put(ctx, 'Boolean', w_Boolean)
+ w_Boolean.Put('prototype', w_BoolPrototype, flags = allon)
+ w_Global.Put('Boolean', w_Boolean)
#Number
w_Number = W_NumberObject('Number', w_FncPrototype)
@@ -812,15 +812,15 @@
})
f = w_Number._get_property_flags('prototype') | READ_ONLY
w_Number._set_property_flags('prototype', f)
- w_Number.Put(ctx, 'MAX_VALUE', W_FloatNumber(1.7976931348623157e308),
flags = READ_ONLY | DONT_DELETE)
- w_Number.Put(ctx, 'MIN_VALUE', W_FloatNumber(0), flags = READ_ONLY |
DONT_DELETE)
- w_Number.Put(ctx, 'NaN', W_FloatNumber(NAN), flags = READ_ONLY |
DONT_DELETE)
+ w_Number.Put('MAX_VALUE', W_FloatNumber(1.7976931348623157e308), flags =
READ_ONLY | DONT_DELETE)
+ w_Number.Put('MIN_VALUE', W_FloatNumber(0), flags = READ_ONLY |
DONT_DELETE)
+ w_Number.Put('NaN', W_FloatNumber(NAN), flags = READ_ONLY | DONT_DELETE)
# ^^^ this is exactly in test case suite
- w_Number.Put(ctx, 'POSITIVE_INFINITY', W_FloatNumber(INFINITY), flags =
READ_ONLY | DONT_DELETE)
- w_Number.Put(ctx, 'NEGATIVE_INFINITY', W_FloatNumber(-INFINITY), flags =
READ_ONLY | DONT_DELETE)
+ w_Number.Put('POSITIVE_INFINITY', W_FloatNumber(INFINITY), flags =
READ_ONLY | DONT_DELETE)
+ w_Number.Put('NEGATIVE_INFINITY', W_FloatNumber(-INFINITY), flags =
READ_ONLY | DONT_DELETE)
- w_Global.Put(ctx, 'Number', w_Number)
+ w_Global.Put('Number', w_Number)
#String
@@ -828,7 +828,7 @@
w_StrPrototype = create_object(ctx, 'Object', Value=W_String(''))
w_StrPrototype.Class = 'String'
- w_StrPrototype.Put(ctx, 'length', W_IntNumber(0))
+ w_StrPrototype.Put('length', W_IntNumber(0))
put_values(ctx, w_StrPrototype, {
'constructor': w_String,
@@ -846,9 +846,9 @@
'toUpperCase': W_ToUpperCase(ctx)
})
- w_String.Put(ctx, 'prototype', w_StrPrototype, flags=allon)
- w_String.Put(ctx, 'fromCharCode', W_FromCharCode(ctx))
- w_Global.Put(ctx, 'String', w_String)
+ w_String.Put('prototype', w_StrPrototype, flags=allon)
+ w_String.Put('fromCharCode', W_FromCharCode(ctx))
+ w_Global.Put('String', w_String)
w_Array = W_ArrayObject('Array', w_FncPrototype)
@@ -865,36 +865,36 @@
'pop': W_ArrayPop(ctx),
})
- w_Array.Put(ctx, 'prototype', w_ArrPrototype, flags = allon)
- w_Array.Put(ctx, '__proto__', w_FncPrototype, flags = allon)
- w_Array.Put(ctx, 'length', W_IntNumber(1), flags = allon)
- w_Global.Put(ctx, 'Array', w_Array)
+ w_Array.Put('prototype', w_ArrPrototype, flags = allon)
+ w_Array.Put('__proto__', w_FncPrototype, flags = allon)
+ w_Array.Put('length', W_IntNumber(1), flags = allon)
+ w_Global.Put('Array', w_Array)
#Math
w_math = W_Object(Class='Math')
- w_Global.Put(ctx, 'Math', w_math)
- w_math.Put(ctx, '__proto__', w_ObjPrototype)
- w_math.Put(ctx, 'prototype', w_ObjPrototype, flags = allon)
- w_math.Put(ctx, 'abs', W_Builtin(absjs, Class='function'))
- w_math.Put(ctx, 'floor', W_Builtin(floorjs, Class='function'))
- w_math.Put(ctx, 'round', W_Builtin(roundjs, Class='function'))
- w_math.Put(ctx, 'pow', W_Builtin(powjs, Class='function'))
- w_math.Put(ctx, 'sqrt', W_Builtin(sqrtjs, Class='function'))
- w_math.Put(ctx, 'log', W_Builtin(logjs, Class='function'))
- w_math.Put(ctx, 'E', W_FloatNumber(math.e), flags=allon)
- w_math.Put(ctx, 'LN2', W_FloatNumber(math.log(2)), flags=allon)
- w_math.Put(ctx, 'LN10', W_FloatNumber(math.log(10)), flags=allon)
+ w_Global.Put('Math', w_math)
+ w_math.Put('__proto__', w_ObjPrototype)
+ w_math.Put('prototype', w_ObjPrototype, flags = allon)
+ w_math.Put('abs', W_Builtin(absjs, Class='function'))
+ w_math.Put('floor', W_Builtin(floorjs, Class='function'))
+ w_math.Put('round', W_Builtin(roundjs, Class='function'))
+ w_math.Put('pow', W_Builtin(powjs, Class='function'))
+ w_math.Put('sqrt', W_Builtin(sqrtjs, Class='function'))
+ w_math.Put('log', W_Builtin(logjs, Class='function'))
+ w_math.Put('E', W_FloatNumber(math.e), flags=allon)
+ w_math.Put('LN2', W_FloatNumber(math.log(2)), flags=allon)
+ w_math.Put('LN10', W_FloatNumber(math.log(10)), flags=allon)
log2e = math.log(math.e) / math.log(2) # rpython supports log with one
argument only
- w_math.Put(ctx, 'LOG2E', W_FloatNumber(log2e), flags=allon)
- w_math.Put(ctx, 'LOG10E', W_FloatNumber(math.log10(math.e)), flags=allon)
- w_math.Put(ctx, 'PI', W_FloatNumber(math.pi), flags=allon)
- w_math.Put(ctx, 'SQRT1_2', W_FloatNumber(math.sqrt(0.5)), flags=allon)
- w_math.Put(ctx, 'SQRT2', W_FloatNumber(math.sqrt(2)), flags=allon)
- w_math.Put(ctx, 'random', W_Builtin(randomjs, Class='function'))
- w_math.Put(ctx, 'min', W_Builtin(minjs, Class='function'))
- w_math.Put(ctx, 'max', W_Builtin(maxjs, Class='function'))
- w_Global.Put(ctx, 'version', W_Builtin(versionjs), flags=allon)
+ w_math.Put('LOG2E', W_FloatNumber(log2e), flags=allon)
+ w_math.Put('LOG10E', W_FloatNumber(math.log10(math.e)), flags=allon)
+ w_math.Put('PI', W_FloatNumber(math.pi), flags=allon)
+ w_math.Put('SQRT1_2', W_FloatNumber(math.sqrt(0.5)), flags=allon)
+ w_math.Put('SQRT2', W_FloatNumber(math.sqrt(2)), flags=allon)
+ w_math.Put('random', W_Builtin(randomjs, Class='function'))
+ w_math.Put('min', W_Builtin(minjs, Class='function'))
+ w_math.Put('max', W_Builtin(maxjs, Class='function'))
+ w_Global.Put('version', W_Builtin(versionjs), flags=allon)
#Date
w_Date = W_DateObject('Date', w_FncPrototype)
@@ -908,28 +908,28 @@
'getTime': get_value_of('Date')(ctx)
})
- w_Date.Put(ctx, 'prototype', w_DatePrototype, flags=allon)
+ w_Date.Put('prototype', w_DatePrototype, flags=allon)
- w_Global.Put(ctx, 'Date', w_Date)
+ w_Global.Put('Date', w_Date)
- w_Global.Put(ctx, 'NaN', W_FloatNumber(NAN), flags = DONT_ENUM |
DONT_DELETE)
- w_Global.Put(ctx, 'Infinity', W_FloatNumber(INFINITY), flags = DONT_ENUM |
DONT_DELETE)
- w_Global.Put(ctx, 'undefined', w_Undefined, flags = DONT_ENUM |
DONT_DELETE)
- w_Global.Put(ctx, 'eval', W_Eval(ctx))
- w_Global.Put(ctx, 'parseInt', W_ParseInt(ctx))
- w_Global.Put(ctx, 'parseFloat', W_ParseFloat(ctx))
- w_Global.Put(ctx, 'isNaN', W_Builtin(isnanjs))
- w_Global.Put(ctx, 'isFinite', W_Builtin(isfinitejs))
- w_Global.Put(ctx, 'print', W_Builtin(printjs))
- w_Global.Put(ctx, 'alert', W_Builtin(noop))
- w_Global.Put(ctx, 'unescape', W_Builtin(unescapejs))
+ w_Global.Put('NaN', W_FloatNumber(NAN), flags = DONT_ENUM | DONT_DELETE)
+ w_Global.Put('Infinity', W_FloatNumber(INFINITY), flags = DONT_ENUM |
DONT_DELETE)
+ w_Global.Put('undefined', w_Undefined, flags = DONT_ENUM | DONT_DELETE)
+ w_Global.Put('eval', W_Eval(ctx))
+ w_Global.Put('parseInt', W_ParseInt(ctx))
+ w_Global.Put('parseFloat', W_ParseFloat(ctx))
+ w_Global.Put('isNaN', W_Builtin(isnanjs))
+ w_Global.Put('isFinite', W_Builtin(isfinitejs))
+ w_Global.Put('print', W_Builtin(printjs))
+ w_Global.Put('alert', W_Builtin(noop))
+ w_Global.Put('unescape', W_Builtin(unescapejs))
- w_Global.Put(ctx, 'this', w_Global)
+ w_Global.Put('this', w_Global)
# debugging
if not we_are_translated():
- w_Global.Put(ctx, 'pypy_repr', W_Builtin(pypy_repr))
+ w_Global.Put('pypy_repr', W_Builtin(pypy_repr))
- w_Global.Put(ctx, 'load', W_Builtin(make_loadjs(interp)))
+ w_Global.Put('load', W_Builtin(make_loadjs(interp)))
return (ctx, w_Global, w_Object)
diff --git a/js/console.py b/js/console.py
--- a/js/console.py
+++ b/js/console.py
@@ -32,7 +32,7 @@
def __init__(self, ctx, interpreter):
W_NewBuiltin.__init__(self, ctx)
self.interpreter = interpreter
-
+
def Call(self, ctx, args=[], this=None):
if len(args) >= 1:
filename = args[0].ToString(self.interpreter.global_context)
@@ -56,13 +56,13 @@
def __init__(self):
interp = Interpreter()
ctx = interp.global_context
-
- interp.w_Global.Put(ctx, 'quit', W_Quit(ctx))
- interp.w_Global.Put(ctx, 'load', W_Load(ctx, interp))
- interp.w_Global.Put(ctx, 'readline', W_ReadLine(ctx))
-
+
+ interp.w_Global.Put('quit', W_Quit(ctx))
+ interp.w_Global.Put('load', W_Load(ctx, interp))
+ interp.w_Global.Put('readline', W_ReadLine(ctx))
+
self.interpreter = interp
-
+
def runsource(self, source, filename='<input>'):
try:
ast = load_source(source, filename)
@@ -74,11 +74,11 @@
# syntax error
self.showsyntaxerror(filename, exc)
return False
-
+
# execute it
self.runcode(ast)
return False
-
+
def runcode(self, ast):
"""Run the javascript code in the AST. All exceptions raised
by javascript code must be caught and handled here. When an
@@ -97,36 +97,36 @@
raise
except ThrowException, exc:
self.showtraceback(exc)
-
+
def showtraceback(self, exc):
printmessage(exc.exception.ToString(self.interpreter.global_context))
printmessage('\n')
-
+
def showsyntaxerror(self, filename, exc):
printmessage(' ' * 4 + \
' ' * exc.source_pos.columnno + \
'^\n')
printmessage('Syntax Error\n')
-
+
def interact(self):
printmessage('PyPy JavaScript Interpreter\n')
printmessage(self.prompt_ok)
-
+
# input for the current statement
lines = []
-
+
while True:
try:
line = readline()
except SystemExit, e:
printmessage('\n')
return
-
+
lines.append(line)
-
+
source = ''.join(lines)
need_more = self.runsource(source)
-
+
if need_more:
printmessage(self.prompt_more)
else:
diff --git a/js/js_interactive.py b/js/js_interactive.py
--- a/js/js_interactive.py
+++ b/js/js_interactive.py
@@ -52,9 +52,9 @@
code.InteractiveConsole.__init__(self, locals, filename)
self.interpreter = Interpreter()
ctx = self.interpreter.global_context
- self.interpreter.w_Global.Put(ctx, 'quit', W_Builtin(quitjs))
- self.interpreter.w_Global.Put(ctx, 'trace', W_Builtin(tracejs))
- self.interpreter.w_Global.Put(ctx, 'debug', W_Builtin(debugjs))
+ self.interpreter.w_Global.Put('quit', W_Builtin(quitjs))
+ self.interpreter.w_Global.Put('trace', W_Builtin(tracejs))
+ self.interpreter.w_Global.Put('debug', W_Builtin(debugjs))
def runcodefromfile(self, filename):
f = open_file_as_stream(filename)
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -42,22 +42,22 @@
# XXX should raise not implemented
return self
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
return 0.0
def ToInteger(self, ctx):
- return int(self.ToNumber(ctx))
+ return int(self.ToNumber(ctx = None))
- def ToInt32(self, ctx):
- return r_int32(int(self.ToNumber(ctx)))
+ def ToInt32(self):
+ return r_int32(int(self.ToNumber()))
- def ToUInt32(self, ctx):
+ def ToUInt32(self):
return r_uint32(0)
def Get(self, P):
raise NotImplementedError(self.__class__)
- def Put(self, ctx, P, V, flags = 0):
+ def Put(self, P, V, flags = 0):
raise NotImplementedError(self.__class__)
def PutValue(self, w, ctx):
@@ -91,7 +91,7 @@
def ToInteger(self, ctx):
return 0
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
return NAN
def ToBoolean(self):
@@ -139,7 +139,7 @@
from js.jsobj import w_Undefined
return w_Undefined
- def Put(self, ctx, P, V, flags = 0):
+ def Put(self, P, V, flags = 0):
self.context.put(P, V)
def Delete(self, name):
@@ -249,7 +249,7 @@
if self.Prototype is None: return True
return self.Prototype.CanPut(P)
- def Put(self, ctx, P, V, flags = 0):
+ 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
@@ -316,7 +316,7 @@
def __init__(self, ctx=None, Prototype=None, Class='Object',
Value=w_Undefined):
W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value)
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
return self.Get('valueOf').Call(ctx, args=[], this=self).ToNumber(ctx)
class W_CallableObject(W_Object):
@@ -371,7 +371,7 @@
W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value)
if self.length != -1:
- self.Put(ctx, 'length', W_IntNumber(self.length), flags =
DONT_ENUM|DONT_DELETE|READ_ONLY)
+ self.Put('length', W_IntNumber(self.length), flags =
DONT_ENUM|DONT_DELETE|READ_ONLY)
def Call(self, ctx, args=[], this = None):
@@ -409,11 +409,10 @@
def __init__(self, callee, args):
W_PrimitiveObject.__init__(self, Class='Arguments')
self._delete_property('prototype')
- # XXX None can be dangerous here
- self.Put(None, 'callee', callee)
- self.Put(None, 'length', W_IntNumber(len(args)))
+ self.Put('callee', callee)
+ self.Put('length', W_IntNumber(len(args)))
for i in range(len(args)):
- self.Put(None, str(i), args[i])
+ self.Put(str(i), args[i])
self.length = len(args)
class ActivationObject(W_PrimitiveObject):
@@ -428,7 +427,7 @@
class W_Array(W_ListObject):
def __init__(self, ctx=None, Prototype=None, Class='Array',
Value=w_Undefined):
W_ListObject.__init__(self, ctx, Prototype, Class, Value)
- self.Put(ctx, 'length', W_IntNumber(0), flags = DONT_DELETE)
+ self.Put('length', W_IntNumber(0), flags = DONT_DELETE)
self.length = r_uint(0)
def set_length(self, newlength):
@@ -443,7 +442,7 @@
self.length = newlength
self._set_property_value('length', W_FloatNumber(newlength))
- def Put(self, ctx, P, V, flags = 0):
+ def Put(self, P, V, flags = 0):
if not self.CanPut(P): return
if not self._has_property(P):
self._set_property(P,V,flags)
@@ -451,8 +450,8 @@
if P != 'length':
self._set_property_value(P, V)
else:
- length = V.ToUInt32(ctx)
- if length != V.ToNumber(ctx):
+ length = V.ToUInt32()
+ if length != V.ToNumber():
raise RangeError()
self.set_length(length)
@@ -483,7 +482,7 @@
return "true"
return "false"
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
if self.boolval:
return 1.0
return 0.0
@@ -508,7 +507,7 @@
def ToObject(self, ctx):
o = create_object(ctx, 'String', Value=self)
- o.Put(ctx, 'length', W_IntNumber(len(self.strval)), flags = READ_ONLY
| DONT_DELETE | DONT_ENUM)
+ o.Put('length', W_IntNumber(len(self.strval)), flags = READ_ONLY |
DONT_DELETE | DONT_ENUM)
return o
def ToString(self, ctx=None):
@@ -526,7 +525,7 @@
def GetPropertyName(self):
return self.ToString()
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
if not self.strval:
return 0.0
try:
@@ -569,14 +568,14 @@
def ToBoolean(self):
return bool(self.intval)
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
# XXX
return float(self.intval)
- def ToInt32(self, ctx):
+ def ToInt32(self):
return r_int32(self.intval)
- def ToUInt32(self, ctx):
+ def ToUInt32(self):
return r_uint32(self.intval)
def GetPropertyName(self):
@@ -625,7 +624,7 @@
return False
return bool(self.floatval)
- def ToNumber(self, ctx):
+ def ToNumber(self, ctx = None):
return self.floatval
def ToInteger(self, ctx):
@@ -637,12 +636,12 @@
return intmask(int(self.floatval))
- def ToInt32(self, ctx):
+ def ToInt32(self):
if isnan(self.floatval) or isinf(self.floatval):
return 0
return r_int32(int(self.floatval))
- def ToUInt32(self, ctx):
+ def ToUInt32(self):
if isnan(self.floatval) or isinf(self.floatval):
return r_uint(0)
return r_uint32(int(self.floatval))
@@ -685,7 +684,7 @@
# TODO get Object prototype from interp.w_Object
assert isinstance(proto, W_PrimitiveObject)
obj = W_Object(ctx, Prototype=proto, Class = proto.Class, Value = Value)
- obj.Put(ctx, '__proto__', proto, DONT_ENUM | DONT_DELETE | READ_ONLY)
+ obj.Put('__proto__', proto, DONT_ENUM | DONT_DELETE | READ_ONLY)
return obj
def isnull_or_undefined(obj):
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -38,8 +38,8 @@
class BaseBinaryBitwiseOp(Opcode):
_stack_change = 0
def eval(self, ctx):
- s5 = ctx.pop().ToInt32(ctx)
- s6 = ctx.pop().ToInt32(ctx)
+ s5 = ctx.pop().ToInt32()
+ s6 = ctx.pop().ToInt32()
ctx.append(self.operation(ctx, s5, s6))
def operation(self, ctx, op1, op2):
@@ -131,7 +131,7 @@
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())
+ array.Put(str(self.counter - i - 1), ctx.pop())
ctx.append(array)
def stack_change(self):
@@ -162,10 +162,10 @@
def eval(self, ctx):
proto = ctx.get_global().Get('Function').Get('prototype')
w_func = W_CallableObject(ctx, proto, self.funcobj)
- w_func.Put(ctx, 'length', W_IntNumber(len(self.funcobj.params)))
+ w_func.Put('length', W_IntNumber(len(self.funcobj.params)))
w_obj = create_object(ctx, 'Object')
- w_obj.Put(ctx, 'constructor', w_func, flags = jsobj.DONT_ENUM)
- w_func.Put(ctx, 'prototype', w_obj)
+ w_obj.Put('constructor', w_func, flags = jsobj.DONT_ENUM)
+ w_func.Put('prototype', w_obj)
ctx.append(w_func)
def __repr__(self):
@@ -194,7 +194,7 @@
for _ in range(self.counter):
name = ctx.pop().ToString(ctx)
w_elem = ctx.pop()
- w_obj.Put(ctx, name, w_elem)
+ w_obj.Put(name, w_elem)
ctx.append(w_obj)
def __repr__(self):
@@ -266,26 +266,26 @@
class BITNOT(BaseUnaryOperation):
def eval(self, ctx):
- op = ctx.pop().ToInt32(ctx)
+ op = ctx.pop().ToInt32()
ctx.append(W_IntNumber(~op))
class URSH(BaseBinaryBitwiseOp):
def eval(self, ctx):
- op2 = ctx.pop().ToUInt32(ctx)
- op1 = ctx.pop().ToUInt32(ctx)
+ op2 = ctx.pop().ToUInt32()
+ op1 = ctx.pop().ToUInt32()
# XXX check if it could fit into int
ctx.append(W_FloatNumber(op1 >> (op2 & 0x1F)))
class RSH(BaseBinaryBitwiseOp):
def eval(self, ctx):
- op2 = ctx.pop().ToUInt32(ctx)
- op1 = ctx.pop().ToInt32(ctx)
+ op2 = ctx.pop().ToUInt32()
+ op1 = ctx.pop().ToInt32()
ctx.append(W_IntNumber(op1 >> intmask(op2 & 0x1F)))
class LSH(BaseBinaryBitwiseOp):
def eval(self, ctx):
- op2 = ctx.pop().ToUInt32(ctx)
- op1 = ctx.pop().ToInt32(ctx)
+ op2 = ctx.pop().ToUInt32()
+ op1 = ctx.pop().ToInt32()
ctx.append(W_IntNumber(op1 << intmask(op2 & 0x1F)))
class MUL(BaseBinaryOperation):
@@ -367,7 +367,7 @@
member = ctx.pop()
value = ctx.pop()
name = member.ToString(ctx)
- left.ToObject(ctx).Put(ctx, name, value)
+ left.ToObject(ctx).Put(name, value)
ctx.append(value)
class STORE(Opcode):
@@ -456,10 +456,10 @@
# function declaration actyally don't run anything
proto = ctx.get_global().Get('Function').Get('prototype')
w_func = W_CallableObject(ctx, proto, self.funcobj)
- w_func.Put(ctx, 'length', W_IntNumber(len(self.funcobj.params)))
+ w_func.Put('length', W_IntNumber(len(self.funcobj.params)))
w_obj = create_object(ctx, 'Object')
- w_obj.Put(ctx, 'constructor', w_func, flags = jsobj.DONT_ENUM)
- w_func.Put(ctx, 'prototype', w_obj)
+ w_obj.Put('constructor', w_func, flags = jsobj.DONT_ENUM)
+ w_func.Put('prototype', w_obj)
if self.funcobj.name is not None:
ctx.put(self.funcobj.name, w_func)
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
@@ -49,9 +49,9 @@
elif isinstance(value, bool):
assert code_val.ToBoolean() == value
elif isinstance(value, int):
- assert code_val.ToInt32(jsint.global_context) == value
+ assert code_val.ToInt32() == value
elif isinstance(value, float):
- assert code_val.ToNumber(jsint.global_context) == value
+ assert code_val.ToNumber() == value
else:
assert code_val.ToString(jsint.global_context) == value
diff --git a/js/test/test_jsobj.py b/js/test/test_jsobj.py
--- a/js/test/test_jsobj.py
+++ b/js/test/test_jsobj.py
@@ -1,20 +1,15 @@
import pytest
from js.jsobj import W_IntNumber, W_FloatNumber, W_Null
-from js import interpreter
def test_intnumber():
n = W_IntNumber(0x80000000)
- jsint = interpreter.Interpreter()
- ctx = jsint.w_Global
- assert n.ToInt32(ctx) == -0x80000000
- assert n.ToUInt32(ctx) == 0x80000000
+ assert n.ToInt32() == -0x80000000
+ assert n.ToUInt32() == 0x80000000
def test_floatnumber():
n = W_FloatNumber(0x80000000)
- jsint = interpreter.Interpreter()
- ctx = jsint.w_Global
- assert n.ToInt32(ctx) == -0x80000000
- assert n.ToUInt32(ctx) == 0x80000000
+ assert n.ToInt32() == -0x80000000
+ assert n.ToUInt32() == 0x80000000
def test_type_null():
assert W_Null().type() == 'null'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit