[pypy-commit] lang-js default: wip

stepahn noreply at buildbot.pypy.org
Fri Dec 28 11:33:21 CET 2012


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r181:6e4db30d5bf7
Date: 2012-05-02 12:04 +0200
http://bitbucket.org/pypy/lang-js/changeset/6e4db30d5bf7/

Log:	wip

diff too long, truncating to 2000 out of 2058 lines

diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -223,7 +223,7 @@
 
     def declare_parameter(self, symbol):
         idx = self.scopes[-1].add_parameter(symbol)
-        print 'parameter declaration "%s"@%d in scope %d' % (symbol, idx, self.depth,)
+        #print 'parameter declaration "%s"@%d in scope %d' % (symbol, idx, self.depth,)
         return idx
 
     def exit_scope(self):
diff --git a/js/baseop.py b/js/baseop.py
--- a/js/baseop.py
+++ b/js/baseop.py
@@ -12,8 +12,8 @@
 
 def plus(ctx, nleft, nright):
     if isinstance(nleft, W_String) or isinstance(nright, W_String):
-        sleft = nleft.ToString()
-        sright = nright.ToString()
+        sleft = nleft.to_string()
+        sright = nright.to_string()
         return W_String(sleft + sright)
     # hot path
     if isinstance(nleft, W_IntNumber) and isinstance(nright, W_IntNumber):
@@ -102,8 +102,8 @@
             return False
         return s4 > s5
     else:
-        s4 = s1.ToString()
-        s5 = s2.ToString()
+        s4 = s1.to_string()
+        s5 = s2.to_string()
         return s4 > s5
 
 def compare_e(ctx, x, y):
@@ -122,8 +122,8 @@
             return False
         return s4 >= s5
     else:
-        s4 = s1.ToString()
-        s5 = s2.ToString()
+        s4 = s1.to_string()
+        s5 = s2.to_string()
         return s4 >= s5
 
 def AbstractEC(ctx, x, y):
@@ -151,11 +151,11 @@
                 return True
             return False
         elif type1 == "string":
-            return x.ToString() == y.ToString()
+            return x.to_string() == y.to_string()
         elif type1 == "boolean":
             return x.ToBoolean() == x.ToBoolean()
         # XXX rethink it here
-        return x.ToString() == y.ToString()
+        return x.to_string() == y.to_string()
     else:
         #step 14
         if (type1 == "undefined" and type2 == "null") or \
@@ -184,7 +184,7 @@
             return True
 
     if isinstance(x, W_String) and isinstance(y, W_String):
-        r = x.ToString() == y.ToString()
+        r = x.to_string() == y.to_string()
     else:
         r = x.ToNumber() == y.ToNumber()
     return r
@@ -209,7 +209,7 @@
             return True
         return False
     if type1 == "string":
-        return x.ToString() == y.ToString()
+        return x.to_string() == y.to_string()
     if type1 == "boolean":
         return x.ToBoolean() == x.ToBoolean()
     return x == y
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -262,29 +262,29 @@
     #def Construct(self, args=[]):
         #return self.Call(args)
 
-def new_native_function(ctx, function, name = None):
-    from js.jscode import Js_NativeFunction
+def new_native_function(function, name = None):
+    from js.functions import JsNativeFunction
     from js.jsobj import W__Function
-    return W__Function(ctx, Js_NativeFunction(function, name))
 
-def setup(w_global):
-    pass
+    scope = None
+    jsfunc = JsNativeFunction(function, name)
+    return W__Function(jsfunc, scope)
 
-def setup_builtins(interp):
-    def put_native_function(obj, name, func):
-        obj.Put(name, new_native_function(ctx, func, name))
+def setup_builtins(global_object):
+    def put_native_function(obj, name, func, writable = False, configurable = False, enumerable = False):
+        jsfunc = new_native_function(func, name)
+        put_property(obj, name, jsfunc, writable = writable, configurable = configurable, enumerable = enumerable)
 
-    allon = DONT_ENUM | DONT_DELETE | READ_ONLY
-    from js.jsexecution_context import make_global_context
-
-    ctx = make_global_context()
-    w_Global = ctx.to_context_object()
+    # 15
+    def put_property(obj, name, value, writable = True, configurable = False, enumerable = True):
+        from js.jsobj import put_property as _put_property
+        _put_property(obj, name, value, writable, configurable, enumerable)
 
     # Forward declaration
     # 15.2.3
     from js.jsobj import W_ObjectConstructor
     w_Object = W_ObjectConstructor()
-    w_Global.Put('Object', w_Object)
+    put_property(global_object, 'Object', w_Object)
 
     # 15.2.4
     from js.jsobj import W_BasicObject
@@ -292,15 +292,15 @@
 
     # 15.3.2
     from js.jsobj import W_FunctionConstructor
-    w_Function = W_FunctionConstructor(ctx)
-    w_Global.Put('Function', w_Function)
+    w_Function = W_FunctionConstructor()
+    put_property(global_object, 'Function', w_Function)
 
     # 15.3.4
     import js.builtins_function as function_builtins
-    w_FunctionPrototype = new_native_function(ctx, function_builtins.empty, 'Empty')
+    w_FunctionPrototype = new_native_function(function_builtins.empty, 'Empty')
 
     # 15.2.4 Properties of the Object Prototype Object
-    w_ObjectPrototype._prototype_ = w_Null
+    w_ObjectPrototype._prototype_ = w_Undefined
 
     # 15.3.4 Properties of the Function Prototype Object
     w_FunctionPrototype._prototype_ = w_ObjectPrototype
@@ -314,13 +314,13 @@
     # 15.2.3 Properties of the Object Constructor
     w_Object._prototype_ = w_FunctionPrototype
 
-    w_Object.Put('length', _w(1), flags = allon)
+    put_property(w_Object, 'length', _w(1))
 
     # 15.2.3.1 Object.prototype
-    w_Object.Put('prototype', w_ObjectPrototype, flags = allon)
+    put_property(w_Object, 'prototype', w_ObjectPrototype, writable = False, configurable = False, enumerable = False)
 
     # 14.2.4.1 Object.prototype.constructor
-    w_ObjectPrototype.Put('constructor', w_Object)
+    put_property(w_ObjectPrototype, 'constructor', w_Object)
 
     import js.builtins_object as object_builtins
     # 15.2.4.2 Object.prototype.toString()
@@ -334,13 +334,13 @@
     # 15.3.3 Properties of the Function Constructor
 
     # 15.3.3.1 Function.prototype
-    w_Function.Put('prototype', w_FunctionPrototype, flags = allon)
+    put_property(w_Function, 'prototype', w_FunctionPrototype, writable = False, configurable = False, enumerable = False)
 
     # 15.3.3.2 Function.length
-    w_Function.Put('length', _w(1), flags = allon)
+    put_property(w_Function, 'length', _w(1), writable = False, configurable = False, enumerable = False)
 
     # 14.3.4.1 Function.prototype.constructor
-    w_FunctionPrototype.Put('constructor', w_Function)
+    put_property(w_FunctionPrototype, 'constructor', w_Function)
 
     # 15.3.4.2 Function.prototype.toString()
     import js.builtins_function as function_builtins
@@ -352,25 +352,13 @@
     # 15.3.4.4 Function.prototype.call
     put_native_function(w_FunctionPrototype, 'call', function_builtins.call)
 
-    # XXXXXXXX
-    #put_values(w_ObjPrototype, {
-        #'constructor': w_Object,
-        #'__proto__': w_Null,
-        #'toString': toString,
-        #'toLocaleString': toString,
-        #'valueOf': W_ValueOf(),
-        #'hasOwnProperty': W_HasOwnProperty(),
-        #'isPrototypeOf': W_IsPrototypeOf(),
-        #'propertyIsEnumerable': W_PropertyIsEnumerable(),
-    #})
-
     # 15.6.2
     from js.jsobj import W_BooleanConstructor
-    w_Boolean = W_BooleanConstructor(ctx)
-    w_Global.Put('Boolean', w_Boolean)
+    w_Boolean = W_BooleanConstructor()
+    put_property(global_object, 'Boolean', w_Boolean)
 
     # 15.6.3
-    w_Boolean.Put('length', _w(1), flags = allon)
+    put_property(w_Boolean, 'length', _w(1), writable = False, enumerable = False, configurable = False)
 
     # 15.6.4
     from js.jsobj import W_BooleanObject
@@ -378,10 +366,10 @@
     w_BooleanPrototype._prototype_ = W__Object._prototype_
 
     # 15.6.3.1
-    w_Boolean.Put('prototype', w_BooleanPrototype, flags = allon)
+    put_property(w_Boolean, 'prototype', w_BooleanPrototype, writable = False, enumerable = False, configurable = False)
 
     # 15.6.4.1
-    w_BooleanPrototype.Put('constructor', w_Boolean)
+    put_property(w_BooleanPrototype, 'constructor', w_Boolean)
 
     import js.builtins_boolean as boolean_builtins
     # 15.6.4.2
@@ -393,17 +381,10 @@
     # 15.6.3.1
     W_BooleanObject._prototype_ = w_BooleanPrototype
 
-    #put_values(w_BoolPrototype, {
-        #'constructor': w_FncPrototype,
-        #'__proto__': w_ObjPrototype,
-        #'toString': W_BooleanValueToString(),
-        #'valueOf': get_value_of('Boolean')(),
-    #})
-
     # 15.7.2
     from js.jsobj import W_NumberConstructor
-    w_Number = W_NumberConstructor(ctx)
-    w_Global.Put('Number', w_Number)
+    w_Number = W_NumberConstructor()
+    put_property(global_object, 'Number', w_Number)
 
     # 15.7.4
     from js.jsobj import W_NumericObject
@@ -411,39 +392,39 @@
     w_NumberPrototype._prototype_ = W__Object._prototype_
 
     # 15.7.4.1
-    w_NumberPrototype.Put('constructor', w_NumberPrototype)
+    put_property(w_NumberPrototype, 'constructor', w_NumberPrototype)
 
     import js.builtins_number as number_builtins
     # 15.7.4.2
     put_native_function(w_NumberPrototype, 'toString', number_builtins.to_string)
 
     # 15.7.3.1
-    w_Number.Put('prototype', w_NumberPrototype)
+    put_property(w_Number, 'prototype', w_NumberPrototype)
     W_NumericObject._prototype_ = w_NumberPrototype
 
     # 15.7.3.2
-    w_Number.Put('MAX_VALUE', _w(1.7976931348623157e308), flags = READ_ONLY | DONT_DELETE)
+    put_property(w_Number, 'MAX_VALUE', _w(1.7976931348623157e308), writable = False, configurable = False)
 
     # 15.7.3.3
-    w_Number.Put('MIN_VALUE', _w(5e-320), flags = READ_ONLY | DONT_DELETE)
+    put_property(w_Number, 'MIN_VALUE', _w(5e-320), writable = False, configurable = False)
 
     # 15.7.3.4
     w_NAN = _w(NAN)
-    w_Number.Put('NaN', w_NAN, flags = READ_ONLY | DONT_DELETE)
+    put_property(w_Number, 'NaN', w_NAN, writable = False, configurable = False)
 
     # 15.7.3.5
     w_POSITIVE_INFINITY = _w(INFINITY)
-    w_Number.Put('POSITIVE_INFINITY', w_POSITIVE_INFINITY, flags = READ_ONLY | DONT_DELETE)
+    put_property(w_Number, 'POSITIVE_INFINITY', w_POSITIVE_INFINITY, writable = False, configurable = False)
 
     # 15.7.3.6
     w_NEGATIVE_INFINITY = _w(-INFINITY)
-    w_Number.Put('NEGATIVE_INFINITY', w_NEGATIVE_INFINITY, flags = READ_ONLY | DONT_DELETE)
+    put_property(w_Number, 'NEGATIVE_INFINITY', w_NEGATIVE_INFINITY, writable = False, configurable = False)
 
     #String
     # 15.5.1
     from js.jsobj import W_StringConstructor
-    w_String = W_StringConstructor(ctx)
-    w_Global.Put('String', w_String)
+    w_String = W_StringConstructor()
+    put_property(global_object, 'String', w_String)
 
     import js.builtins_string as string_builtins
     # 15.5.3.2
@@ -458,7 +439,7 @@
     W_StringObject._prototype_ = w_StringPrototype
 
     # 15.5.4.1
-    w_StringPrototype.Put('constructor', w_String)
+    put_property(w_StringPrototype, 'constructor', w_String)
 
     # 15.5.4.4
     put_native_function(w_StringPrototype, 'charAt', string_builtins.char_at)
@@ -489,19 +470,19 @@
 
     from js.jsobj import W_ArrayConstructor, W__Array
     w_Array = W_ArrayConstructor()
-    w_Global.Put('Array', w_Array)
+    put_property(global_object, 'Array', w_Array)
 
     # 15.4.4
     w_ArrayPrototype = W__Array()
 
     w_ArrayPrototype._prototype_ = W__Object._prototype_
-    w_ArrayPrototype.Put('__proto__', w_ArrayPrototype._prototype_)
+    put_property(w_ArrayPrototype, '__proto__', w_ArrayPrototype._prototype_)
 
     # 15.4.3.1
     W__Array._prototype_ = w_ArrayPrototype
 
     # 15.4.4.1
-    w_ArrayPrototype.Put('constructor', w_Array)
+    put_property(w_ArrayPrototype, 'constructor', w_Array)
 
     import js.builtins_array as array_builtins
     # 15.4.4.2
@@ -519,7 +500,7 @@
     from js.jsobj import W_Math
     # 15.8
     w_Math = W_Math()
-    w_Global.Put('Math', w_Math)
+    put_property(global_object, 'Math', w_Math)
 
     #w_math.Put('__proto__',  w_ObjPrototype)
 
@@ -537,28 +518,28 @@
     # 15.8.1
 
     # 15.8.1.1
-    w_Math.Put('E', _w(math_builtins.E), flags = allon)
+    put_property(w_Math, 'E', _w(math_builtins.E), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.2
-    w_Math.Put('LN10', _w(math_builtins.LN10), flags = allon)
+    put_property(w_Math, 'LN10', _w(math_builtins.LN10), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.3
-    w_Math.Put('LN2', _w(math_builtins.LN2), flags = allon)
+    put_property(w_Math, 'LN2', _w(math_builtins.LN2), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.4
-    w_Math.Put('LOG2E', _w(math_builtins.LOG2E), flags = allon)
+    put_property(w_Math, 'LOG2E', _w(math_builtins.LOG2E), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.5
-    w_Math.Put('LOG10E', _w(math_builtins.LOG10E), flags = allon)
+    put_property(w_Math, 'LOG10E', _w(math_builtins.LOG10E), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.6
-    w_Math.Put('PI', _w(math_builtins.PI), flags = allon)
+    put_property(w_Math, 'PI', _w(math_builtins.PI), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.7
-    w_Math.Put('SQRT1_2', _w(math_builtins.SQRT1_2), flags = allon)
+    put_property(w_Math, 'SQRT1_2', _w(math_builtins.SQRT1_2), writable = False, enumerable = False, configurable = False)
 
     # 15.8.1.8
-    w_Math.Put('SQRT2', _w(math_builtins.SQRT2), flags = allon)
+    put_property(w_Math, 'SQRT2', _w(math_builtins.SQRT2), writable = False, enumerable = False, configurable = False)
 
     ##Date
 
@@ -575,51 +556,48 @@
     put_native_function(w_DatePrototype, 'getTime', date_builtins.get_time)
 
     # 15.9.3
-    w_Date = W_DateConstructor(ctx)
-    w_Global.Put('Date', w_Date)
+    w_Date = W_DateConstructor()
+    put_property(global_object, 'Date', w_Date)
 
     # 15.1.1.1
-    w_Global.Put('NaN', w_NAN, flags = DONT_ENUM | DONT_DELETE)
+    put_property(global_object, 'NaN', w_NAN, enumerable = False, configurable = False)
 
     # 15.1.1.2
-    w_Global.Put('Infinity', w_POSITIVE_INFINITY, flags = DONT_ENUM | DONT_DELETE)
+    put_property(global_object, 'Infinity', w_POSITIVE_INFINITY, enumerable = False, configurable = False)
 
     # 15.1.1.3
-    w_Global.Put('undefined', w_Undefined, flags = DONT_ENUM | DONT_DELETE)
+    put_property(global_object, 'undefined', w_Undefined, enumerable = False, configurable = False)
 
     # 15.1.2.1
-    w_Global.Put('eval', W__Eval(ctx))
+    put_property(global_object, 'eval', W__Eval())
 
     import js.builtins_global as global_builtins
 
     # 15.1.2.2
-    put_native_function(w_Global, 'parseInt', global_builtins.parse_int)
+    put_native_function(global_object, 'parseInt', global_builtins.parse_int)
 
     # 15.1.2.3
-    put_native_function(w_Global, 'parseFloat', global_builtins.parse_float)
+    put_native_function(global_object, 'parseFloat', global_builtins.parse_float)
 
     # 15.1.2.4
-    put_native_function(w_Global, 'isNaN', global_builtins.is_nan)
+    put_native_function(global_object, 'isNaN', global_builtins.is_nan)
 
     # 15.1.2.5
-    put_native_function(w_Global, 'isFinite', global_builtins.is_finite)
+    put_native_function(global_object, 'isFinite', global_builtins.is_finite)
 
-    put_native_function(w_Global, 'alert', global_builtins.alert)
+    put_native_function(global_object, 'alert', global_builtins.alert)
 
-    put_native_function(w_Global, 'print', global_builtins.printjs)
+    put_native_function(global_object, 'print', global_builtins.printjs)
 
-    put_native_function(w_Global, 'unescape', global_builtins.unescape)
+    put_native_function(global_object, 'unescape', global_builtins.unescape)
 
-    put_native_function(w_Global, 'version', global_builtins.version)
+    put_native_function(global_object, 'version', global_builtins.version)
 
-    w_Global.Put('this', w_Global)
+    #put_property(global_object, 'this', global_object)
 
     ## debugging
     if not we_are_translated():
-        put_native_function(w_Global, 'pypy_repr', global_builtins.pypy_repr)
-        put_native_function(w_Global, 'inspect', global_builtins.inspect)
+        put_native_function(global_object, 'pypy_repr', global_builtins.pypy_repr)
+        put_native_function(global_object, 'inspect', global_builtins.inspect)
 
-    put_native_function(w_Global, 'load', make_loadjs(interp))
-
-    #return (ctx, w_Global, w_Object)
-    return (ctx, w_Global, None)
+    #put_native_function(global_object, 'load', make_loadjs(interp))
diff --git a/js/builtins_array.py b/js/builtins_array.py
--- a/js/builtins_array.py
+++ b/js/builtins_array.py
@@ -20,9 +20,9 @@
     array = this.ToObject()
     func = array.Get('join')
     if func.IsCallable():
-        return func.Call(this = this).ToString()
+        return func.Call(this = this).to_string()
     else:
-        return this.ToString()
+        return this.to_string()
 
 # 15.4.4.5
 def join(this, args):
@@ -32,7 +32,7 @@
 
     sep = ','
     if (len(args) > 0):
-        sep = args[0].ToString()
+        sep = args[0].to_string()
 
     if length == 0:
         return ''
@@ -41,7 +41,7 @@
     if isnull_or_undefined(element0):
         return ''
 
-    r = element0.ToString()
+    r = element0.to_string()
 
     k = 1
 
@@ -51,7 +51,7 @@
         if isnull_or_undefined(element):
             n = ''
         else:
-            n = element.ToString()
+            n = element.to_string()
         r = s + n
         k = k + 1
 
diff --git a/js/builtins_boolean.py b/js/builtins_boolean.py
--- a/js/builtins_boolean.py
+++ b/js/builtins_boolean.py
@@ -1,6 +1,6 @@
 # 15.6.4.2
 def to_string(this, args):
-    return this.ToString()
+    return this.to_string()
 
 def value_of(this, args):
     return this.ToBoolean()
diff --git a/js/builtins_function.py b/js/builtins_function.py
--- a/js/builtins_function.py
+++ b/js/builtins_function.py
@@ -1,7 +1,7 @@
 from js.jsobj import isnull_or_undefined
 
 def to_string(this, args):
-    return this.ToString()
+    return this.to_string()
 
 def empty(this, args):
     from js.jsobj import w_Undefined
diff --git a/js/builtins_global.py b/js/builtins_global.py
--- a/js/builtins_global.py
+++ b/js/builtins_global.py
@@ -22,7 +22,7 @@
 def parse_int(this, args):
     if len(args) < 1:
         return NAN
-    s = args[0].ToString().strip(" ")
+    s = args[0].to_string().strip(" ")
     if len(args) > 1:
         radix = args[1].ToInt32()
     else:
@@ -42,7 +42,7 @@
 def parse_float(this, args):
     if len(args) < 1:
         return NAN
-    s = args[0].ToString().strip(" ")
+    s = args[0].to_string().strip(" ")
     try:
         n = float(s)
     except ValueError:
@@ -52,11 +52,8 @@
 def alert(this, args):
     pass
 
-def writer(x):
-    print x
-
 def printjs(this, args):
-    writer(",".join([i.ToString() for i in args]))
+    print ",".join([i.to_string() for i in args])
 
 def _ishex(ch):
     return ((ch >= 'a' and ch <= 'f') or (ch >= '0' and ch <= '9') or
@@ -69,7 +66,7 @@
     if not isinstance(w_string, W_String):
         raise JsTypeError(W_String("Expected string"))
     assert isinstance(w_string, W_String)
-    strval = w_string.ToString()
+    strval = w_string.to_string()
     lgt = len(strval)
     i = 0
     while i < lgt:
diff --git a/js/builtins_number.py b/js/builtins_number.py
--- a/js/builtins_number.py
+++ b/js/builtins_number.py
@@ -1,4 +1,4 @@
 # 15.7.4.2
 def to_string(this, args):
     # TODO radix, see 15.7.4.2
-    return this.ToString()
+    return this.to_string()
diff --git a/js/builtins_object.py b/js/builtins_object.py
--- a/js/builtins_object.py
+++ b/js/builtins_object.py
@@ -1,5 +1,7 @@
+from js.jsobj import _w
 def to_string(this, args):
-    return "[object %s]" % (this.Class(), )
+    s = "[object %s]" % (this.klass(), )
+    return _w(s)
 
 def value_of(this, args):
     return this
diff --git a/js/builtins_string.py b/js/builtins_string.py
--- a/js/builtins_string.py
+++ b/js/builtins_string.py
@@ -12,7 +12,7 @@
 
 # 15.5.4.4
 def char_at(this, args):
-    string = this.ToString()
+    string = this.to_string()
     if len(args)>=1:
         pos = args[0].ToInt32()
         if (not pos >=0) or (pos > len(string) - 1):
@@ -23,7 +23,7 @@
 
 #15.5.4.5
 def char_code_at(this, args):
-    string = this.ToString()
+    string = this.to_string()
     if len(args)>=1:
         pos = args[0].ToInt32()
         if pos < 0 or pos > len(string) - 1:
@@ -35,17 +35,17 @@
 
 #15.5.4.6
 def concat(this, args):
-    string = this.ToString()
-    others = [obj.ToString() for obj in args]
+    string = this.to_string()
+    others = [obj.to_string() for obj in args]
     string += ''.join(others)
     return string
 
 # 15.5.4.7
 def index_of(this, args):
-    string = this.ToString()
+    string = this.to_string()
     if len(args) < 1:
         return -1
-    substr = args[0].ToString()
+    substr = args[0].to_string()
     size = len(string)
     subsize = len(substr)
     if len(args) < 2:
@@ -58,10 +58,10 @@
 
 # 15.5.4.8
 def last_index_of(this, args):
-    string = this.ToString()
+    string = this.to_string()
     if len(args) < 1:
         return -1
-    substr = args[0].ToString()
+    substr = args[0].to_string()
     if len(args) < 2:
         pos = INFINITY
     else:
@@ -79,12 +79,12 @@
 
 # 15.5.4.14
 def split(this, args):
-    string = this.ToString()
+    string = this.to_string()
 
     if len(args) < 1 or args[0] is w_Undefined:
         return _create_array([_w(string)])
     else:
-        separator = args[0].ToString()
+        separator = args[0].to_string()
 
     if len(args) >= 2:
         limit = args[1].ToUInt32()
@@ -104,7 +104,7 @@
 
 # 15.5.4.15
 def substring(this, args):
-    string = this.ToString()
+    string = this.to_string()
     size = len(string)
     if len(args) < 1:
         start = 0
@@ -122,12 +122,12 @@
 
 # 15.5.4.16
 def to_lower_case(this, args):
-    string = this.ToString()
+    string = this.to_string()
     return string.lower()
 
 # 15.5.4.18
 def to_upper_case(this, args):
-    string = this.ToString()
+    string = this.to_string()
     return string.upper()
 
 def _create_array(elements=[]):
diff --git a/js/console.py b/js/console.py
--- a/js/console.py
+++ b/js/console.py
@@ -35,7 +35,7 @@
 
     def Call(self, ctx, args=[], this=None):
         if len(args) >= 1:
-            filename = args[0].ToString(self.interpreter.global_context)
+            filename = args[0].to_string(self.interpreter.global_context)
             try:
                 assert filename is not None
                 program = load_file(filename)
@@ -89,9 +89,9 @@
             res = self.interpreter.run(ast, interactive=True)
             if res is not None and res != w_Undefined:
                 try:
-                    printmessage(res.ToString(self.interpreter.global_context))
+                    printmessage(res.to_string(self.interpreter.global_context))
                 except ThrowException, exc:
-                    printmessage(exc.exception.ToString(self.interpreter.global_context))
+                    printmessage(exc.exception.to_string(self.interpreter.global_context))
                 printmessage('\n')
         except SystemExit:
             raise
@@ -99,7 +99,7 @@
             self.showtraceback(exc)
 
     def showtraceback(self, exc):
-        printmessage(exc.exception.ToString(self.interpreter.global_context))
+        printmessage(exc.exception.to_string(self.interpreter.global_context))
         printmessage('\n')
 
     def showsyntaxerror(self, filename, exc):
diff --git a/js/execution.py b/js/execution.py
--- a/js/execution.py
+++ b/js/execution.py
@@ -30,4 +30,5 @@
 class JsReferenceError(JsBaseExcept):
     pass
 
-class RangeError(JsBaseExcept): pass
+class JsRangeError(JsBaseExcept):
+    pass
diff --git a/js/execution_context.py b/js/execution_context.py
--- a/js/execution_context.py
+++ b/js/execution_context.py
@@ -13,6 +13,7 @@
         self._this_binding_ = None
 
     def declaration_binding_initialization(self, env, code, arguments = []):
+        strict = False
         configurable_bindings = code.configurable_bindings
 
         n = 0
@@ -30,6 +31,7 @@
                 env.create_mutuable_binding(arg_name, configurable_bindings)
             env.set_mutable_binding(arg_name, v)
 
+        # 5.
         func_declarations = code.functions()
         for fn in func_declarations:
             fo = None
@@ -40,6 +42,22 @@
                 pass #see 10.5 5.e
             env.set_mutable_binding(fn, fo)
 
+        arguments_already_declared = env.has_binding('arguments')
+        # 7.
+        from js.functions import JsFunction
+        if isinstance(code, JsFunction) and arguments_already_declared is False:
+            from js.jsobj import W_Arguments
+            # TODO get calling W_Function
+            func = None
+            args_obj = W_Arguments(func, names, arguments, env, strict)
+            if strict is True:
+                env.create_immutable_bining('arguments')
+                env.initialize_immutable_binding('arguments', args_obj)
+            else:
+                env.create_mutuable_binding('arguments', False) # TODO not sure if mutable binding is deletable
+                env.set_mutable_binding('arguments', args_obj, False)
+
+        # 8.
         var_declarations = code.variables()
         for dn in var_declarations:
             var_already_declared = env.has_binding(dn)
@@ -130,48 +148,53 @@
     pass
 
 class FunctionExecutionContext(ExecutionContext):
-    def __init__(self, function, this, argument_values, scope = None):
+    def __init__(self, formal_parameters = [], args = [], this = None):
         ExecutionContext.__init__(self)
-        self.function = function
-        self.arguments = argument_values
+        self._formal_parameters_ = formal_parameters
+        self._args_ = args
+        self._this_ = this
 
-        from js.lexical_environment import DeclarativeEnvironment
-        localEnv = DeclarativeEnvironment(scope)
-        self._lexical_environment_ = localEnv
-        self._variable_environment_ = localEnv
+        #self.function = function
+        #self.arguments = argument_values
 
-        self._this_binding_ = this
+        #from js.lexical_environment import DeclarativeEnvironment
+        #localEnv = DeclarativeEnvironment(scope)
+        #self._lexical_environment_ = localEnv
+        #self._variable_environment_ = localEnv
 
-        self.symbol_slots = {}
-        self.declaration_binding_initialization(self._variable_environment_.environment_record, self.function, self.arguments)
+        #from js.jsobj import isnull_or_undefined
+        #strict = False
+
+        #if strict:
+            #self._this_binding_ = this
+        #elif isnull_or_undefined(this):
+            #self._this_binding_ = get_global_object()
+        #elif this.klass() is not 'Object':
+            #self._this_binding_ = this.ToObject()
+        #else:
+            #self._this_binding_ = this
+
+        #self.symbol_slots = {}
+        #self.declaration_binding_initialization(self._variable_environment_.environment_record, self.function, self.arguments)
 
     def run(self):
-        self._bind_symbols()
-        return self.function.run(self)
+        pass
+        #self._bind_symbols()
+        #return self.function.run(self)
 
-    def _bind_symbols(self):
-        lex_env = self.variable_environment()
-        for symbol in self.function.symbols():
-            idx = self._index_for_symbol(symbol)
-            ref = lex_env.get_identifier_reference(symbol)
-            self.symbol_slots[idx] = ref
+    #def _bind_symbols(self):
+        #lex_env = self.variable_environment()
+        #for symbol in self.function.symbols():
+            #idx = self._index_for_symbol(symbol)
+            #ref = lex_env.get_identifier_reference(symbol)
+            #self.symbol_slots[idx] = ref
 
-    def _index_for_symbol(self, symbol):
-        return self.function.index_for_symbol(symbol)
+    #def _index_for_symbol(self, symbol):
+        #return self.function.index_for_symbol(symbol)
 
-    def get_ref(self, index):
-        ref = self.symbol_slots[index]
-        return ref
-
-    #def get_value(self, index):
-        #ref = self.get_ref(index)
-        #env_record = ref.base_value
-        #identifier = ref.referenced
-        #value = env_record.get_binding_value(identifier)
-        #return value
-
-    #def set_value(self, index, value):
-        #ref = self.symbol_slots[index]
-        #env_record = ref.base_value
-        #identifier = ref.referenced
-        #env_record.set_mutable_binding(identifier, value)
+    #def get_ref(self, index):
+        ## TODO pre-bind symbols does not work, see test_foo18
+        #symbol = self.function.symbol_for_index(index)
+        #lex_env = self.lexical_environment()
+        #ref = lex_env.get_identifier_reference(symbol)
+        #return ref
diff --git a/js/interpreter.py b/js/interpreter.py
--- a/js/interpreter.py
+++ b/js/interpreter.py
@@ -18,6 +18,8 @@
     def __init__(self):
         from js.jsobj import W_BasicObject
         self.global_object = W_BasicObject()
+        from js.builtins import setup_builtins
+        setup_builtins(self.global_object)
 
     def run_ast(self, ast):
         symbol_map = ast.symbol_map
diff --git a/js/js_interactive.py b/js/js_interactive.py
--- a/js/js_interactive.py
+++ b/js/js_interactive.py
@@ -76,9 +76,9 @@
             try:
                 #if DEBUG:
                     #print repr(res)
-                print res.ToString()
+                print res.to_string()
             except ThrowException, exc:
-                print exc.exception.ToString()
+                print exc.exception.to_string()
         except SystemExit:
             raise
         except ThrowException, exc:
@@ -112,7 +112,7 @@
 
     def showtraceback(self, exc):
         # XXX format exceptions nicier
-        print exc.exception.ToString()
+        print exc.exception.to_string()
 
     def showsyntaxerror(self, filename, exc):
         # XXX format syntax errors nicier
diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -191,10 +191,3 @@
     #def __repr__(self):
         #return "\n".join([repr(i) for i in self.opcodes])
 
-
-def _native_function(fn):
-    from js.jsobj import _w
-    def f(this, args):
-        res = fn(this, args)
-        return _w(res)
-    return f
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -2,7 +2,7 @@
 from pypy.rpython.lltypesystem import rffi
 from pypy.rlib.rarithmetic import r_uint, intmask, ovfcheck_float_to_int
 from pypy.rlib.rfloat import isnan, isinf, NAN, formatd
-from js.execution import ThrowException, JsTypeError, RangeError, ReturnException
+from js.execution import ThrowException, JsTypeError, JsRangeError, ReturnException
 
 from pypy.rlib.jit import hint
 from pypy.rlib import jit, debug
@@ -22,7 +22,10 @@
     _type_ = ''
 
     def __str__(self):
-        return self.ToString()
+        return self.to_string()
+
+    def to_string(self):
+        return ''
 
     #def type(self):
         #return self._type_
@@ -33,9 +36,6 @@
     #def ToPrimitive(self, hint = None):
         #return self
 
-    #def ToString(self):
-        #return ''
-
     #def ToObject(self):
         #raise JsTypeError
 
@@ -45,6 +45,9 @@
     #def ToInteger(self):
         #return int(self.ToNumber())
 
+    def is_callable(self):
+        return False
+
 
 class W_Primitive(W_Root):
     pass
@@ -57,7 +60,7 @@
     def ToNumber(self):
         return NAN
 
-    def ToString(self):
+    def to_string(self):
         return self._type_
 
 class W_Null(W_Primitive):
@@ -66,7 +69,7 @@
     def ToBoolean(self):
         return False
 
-    def ToString(self):
+    def to_string(self):
         return self._type_
 
 w_Undefined = W_Undefined()
@@ -390,14 +393,14 @@
     def _default_value_string_(self):
         to_string = self.get('toString')
         if to_string.is_callable():
-            _str = to_string.call(this = self)
+            _str = to_string.Call(this = self)
             if isinstance(_str, W_Primitive):
                 return _str
 
     def _default_value_number_(self):
         value_of = self.get('valueOf')
         if value_of.is_callable():
-            val = to_string.call(this = self)
+            val = value_of.Call(this = self)
             if isinstance(val, W_Primitive):
                 return val
 
@@ -505,11 +508,11 @@
     def ToNumber(self):
         return self.ToPrimitive('Number').ToNumber()
 
-    def ToString(self):
-        return self.ToPrimitive('String').ToString()
+    def to_string(self):
+        return self.ToPrimitive('String').to_string()
 
     def ToPrimitive(self, hint = None):
-        return self.DefaultValue(hint)
+        return self.default_value(hint)
 
     def ToObject(self):
         return self
@@ -522,8 +525,8 @@
     def PrimitiveValue(self):
         return self._primitive_value_
 
-    def ToString(self):
-        return self.PrimitiveValue().ToString()
+    def to_string(self):
+        return self.PrimitiveValue().to_string()
 
     def ToNumber(self):
         return self.PrimitiveValue().ToNumber()
@@ -538,28 +541,29 @@
     _class_ = 'String'
     def __init__(self, primitive_value):
         W__PrimitiveObject.__init__(self, primitive_value)
-        length = len(self._primitive_value_.ToString())
-        self._set_property('length', _w(length), DONT_ENUM | DONT_DELETE | READ_ONLY )
+        length = len(self._primitive_value_.to_string())
+        descr = PropertyDescriptor(value = _w(length), enumerable = False, configurable = False, writable = False)
+        self.define_own_property('length', descr)
 
 class W_DateObject(W__PrimitiveObject):
     _class_ = 'Date'
 
 class W__Object(W_BasicObject):
-    def ToString(self):
+    def to_string(self):
         try:
             res = self.ToPrimitive('String')
         except JsTypeError:
-            return "[object %s]" % (self.Class() ,)
-        return res.ToString()
+            return "[object %s]" % (self.klass() ,)
+        return res.to_string()
 
 class W_ObjectConstructor(W_BasicObject):
     def __init__(self):
         W_BasicObject.__init__(self)
 
-    def ToString(self):
+    def to_string(self):
         return "function Object() { [native code] }"
 
-    def IsCallable(self):
+    def is_callable(self):
         return True
 
     def Call(self, args=[], this=None):
@@ -603,17 +607,11 @@
                 return result
         return obj
 
-    def IsCallable(self):
+    def is_callable(self):
         return True
 
-    def Scope(self):
-        return self._context_
-
 class W_FunctionConstructor(W_BasicFunction):
-    def __init__(self, ctx):
-        W_BasicFunction.__init__(self, ctx)
-
-    def ToString(self):
+    def to_string(self):
         return "function Function() { [native code] }"
 
     def Call(self, args=[], this=None):
@@ -625,10 +623,10 @@
         functioncode = "function () { }"
         tam = len(args)
         if tam >= 1:
-            fbody  = args[tam-1].ToString()
+            fbody  = args[tam-1].to_string()
             argslist = []
             for i in range(tam-1):
-                argslist.append(args[i].ToString())
+                argslist.append(args[i].to_string())
             fargs = ','.join(argslist)
             functioncode = "return function (%s) {%s}"%(fargs, fbody)
         #remove program and sourcelements node
@@ -664,7 +662,7 @@
 class W_StringConstructor(W_BasicFunction):
     def Call(self, args=[], this=None):
         if len(args) >= 1:
-            return W_String(args[0].ToString())
+            return W_String(args[0].to_string())
         else:
             return W_String('')
 
@@ -694,44 +692,115 @@
 
 
 class W__Function(W_BasicFunction):
-    _immutable_fields_ = ['_function_']
+    #_immutable_fields_ = ['_function_']
 
-    def __init__(self, function, context):
+    def __init__(self, function_body, formal_parameter_list = [], scope = None, strict = False):
         W_BasicFunction.__init__(self)
-        self._function_ = function
-        self._context_ = context
+        self._function_ = function_body
+        self._scope_ = scope
+        self._params_ = formal_parameter_list
+        self._strict_ = strict
+
+    def code(self):
+        return self._function_
 
     def Call(self, args=[], this=None):
-        f = self._function_
-        scope = self.Scope()
+        pass
+        #f = self._function_
+        #scope = self._scope_
 
-        from js.execution_context import FunctionExecutionContext
-        ctx = FunctionExecutionContext(f, this, args, scope)
-        result = ctx.run()
-        return result
+        #from js.execution_context import FunctionExecutionContext
+        #ctx = FunctionExecutionContext(f, this, args, scope)
+        #result = ctx.run()
+        #return result
 
-    def ToString(self):
-        return self._function_.ToString()
+    # 15.3.5.4
+    def get(self, p):
+        v = W_BasicObject.get(self, p)
+        if p is 'caller' and isinstance(v, W__Function) and v.is_strict():
+            raise JsTypeError()
+        return v
 
+    def to_string(self):
+        return self._function_.to_string()
+
+    def scope(self):
+        return self._context_
+
+    def is_strict(self):
+        return self._strict_
+
+# 10.6
 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_ = 'Arguments'
+    _paramenter_map_ = None
 
-    @jit.unroll_safe
-    def __init__(self, callee, args):
+    def __init__(self, func, names, args, env, strict = False):
         W_BasicObject.__init__(self)
-        self._delete_property('prototype')
-        #self.Put('callee', callee)
-        self.Put('length', W_IntNumber(len(args)))
-        for i in range(len(args)):
-            self.Put(str(i), args[i])
-        self.length = len(args)
+        _len = len(args)
+        put_property(self, 'length', _w(_len), writable = True, enumerable = False, configurable = True)
+
+        _map = W__Object()
+        mapped_names = []
+        indx = _len - 1
+        while indx >= 0:
+            val = args[indx]
+            put_property(self, str(indx), val, writable = True, enumerable = True, configurable = True)
+            if indx < len(names):
+                name = names[indx]
+                if strict is False and name not in mapped_names:
+                    mapped_names.append(name)
+                    g = make_arg_getter(name, env)
+                    p = make_arg_setter(name, env)
+                    desc = PropertyDescriptor(setter = p, getter = g, configurable = True)
+                    _map.define_own_property(str(indx), desc, False)
+            indx = indx - 1
+
+        if mapped_names:
+            self._paramenter_map_ = _map
+
+        if strict is False:
+            # 10.6 13 callee
+            pass
+        else:
+            # 10.6 14 thrower
+            pass
+
+    def get(self, p):
+        if self._paramenter_map_ is None:
+            return W_BasicObject.get(self, p)
+
+        _map = self._paramenter_map_
+        is_mapped = _map.get_own_property(p)
+        if is_mapped is w_Undefined:
+            v = W_BasicObject.get(self, p)
+            return v
+        else:
+            return _map.get(p)
+
+    def get_own_property(self, p):
+        if self._paramenter_map_ is None:
+            return W_BasicObject.get_own_property(self, p)
+
+        raise NotImplementedError()
+
+    def delete(self, p, throw):
+        if self._paramenter_map_ is None:
+            return W_BasicObject.delete(self, p, throw)
+
+        raise NotImplementedError()
+
+def make_arg_getter(name, env):
+    code = 'return %s;' % (name)
+    pass
+
+def make_arg_setter(name, env):
+    param = '%s_arg' % (name)
+    code = '%s = %s;' % (name, param)
+    pass
 
 class W_ArrayConstructor(W_BasicObject):
-    def IsCallable(self):
+    def is_callable(self):
         return True
 
     def Call(self, args=[], this=None):
@@ -748,50 +817,129 @@
 
 class W__Array(W_BasicObject):
     _class_ = 'Array'
-    length = r_uint(0)
 
-    def __init__(self):
+    def __init__(self, length = 0):
         W_BasicObject.__init__(self)
-        self.Put('length', _w(0), flags = DONT_DELETE)
 
-    def set_length(self, newlength):
-        if newlength < self.length:
-            i = newlength
-            while i < self.length:
-                key = str(i)
-                if key in self._get_property_keys():
-                    self._delete_property(key)
-                i += 1
+        desc = PropertyDescriptor(value = _w(length), writable = True, enumerable = False, configurable = False)
+        W_BasicObject.define_own_property(self, 'length', desc)
 
-        self.length = intmask(newlength)
-        self._set_property_value('length', _w(self.length))
+    # 15.4.5.1
+    def define_own_property(self, p, desc, throw = False):
+        def reject():
+            if throw:
+                raise JsTypeError(self.__class__)
+            else:
+                return False
 
-    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)
-        else:
-            if P != 'length':
-                self._set_property_value(P, V)
+        old_len_desc = self.get_own_property('length')
+        assert old_len_desc is not w_Undefined
+        old_len = old_len_desc.value
+
+        # 3
+        if p == 'length':
+            if desc.value is None:
+                return W_BasicObject.define_own_property(self, 'length', desc, throw)
+            import copy
+            new_len_desc = copy.deepcopy(desc)
+            new_len = desc.value.ToUInt32()
+
+            if new_len != desc.value.ToNumber():
+                raise JsRangeError()
+
+            new_len_desc.value = _w(new_len)
+
+            if new_len >= old_len:
+                return W_BasicObject.define_own_property(self, 'length', new_len_desc, throw)
+            if old_len_desc.writable is False:
+                return reject()
+
+            if new_len_desc.writable is None or new_len_desc.writable is true:
+                new_writable = True
             else:
-                length = V.ToUInt32()
-                if length != V.ToNumber():
-                    raise RangeError()
+                new_len_desc.writable = True
+                new_writable = False
 
-                self.set_length(length)
-                return
+            succeeded = W_BasicObject.define_own_property(self, 'length', new_len_desc, throw)
+            if succeeded is False:
+                return False
 
-        try:
-            arrayindex = r_uint(to_array_index(P))
-        except ValueError:
-            return
+            while new_len < old_len:
+                old_len = old_len - 1
+                delete_succeeded = self.delete(str(old_len), False)
+                if delete_succeeded is False:
+                    new_len_desc.value = _w(old_len + 1)
+                    if new_writable is False:
+                        new_len_desc.writable = False
+                    W_BasicObject.define_own_property(self, 'length', new_len_desc, False)
+                    return reject()
 
-        if (arrayindex < self.length) or (arrayindex != float(P)):
-            return
-        else:
-            if (arrayindex + 1) == 0:
-                raise RangeError()
-            self.set_length(arrayindex+1)
+            if new_writable is False:
+                desc = PropertyDescriptor(writable = False)
+                res = W_BasicObject.define_own_property(self, 'length', desc, False)
+                assert res is True
+
+            return True
+
+        # 4
+        elif is_array_index(p):
+            index = p.ToUInt32()
+            if index >= old_len and old_len_desc.writable is False:
+                return reject()
+
+            succeeded = W_BasicObject.define_own_property(self, 'length', desc, False)
+            if succeeded is False:
+                return reject()
+
+            if index >= old_len:
+                old_len_desc.value = _w(index + 1)
+                res = W_BasicObject.define_own_property(self, 'length', old_len_desc, False)
+                assert res is True
+            return True
+        # 5
+        return W_BasicObject.define_own_property(self, 'length', desc, throw)
+
+def is_array_index(p):
+    return (isinstance(p, W_Number) or isinstance(p, W_NumericObject)) and str(p.ToUInt32()) == p
+
+    #def set_length(self, newlength):
+        #if newlength < self.length:
+            #i = newlength
+            #while i < self.length:
+                #key = str(i)
+                #if key in self._get_property_keys():
+                    #self._delete_property(key)
+                #i += 1
+
+        #self.length = intmask(newlength)
+        #self._set_property_value('length', _w(self.length))
+
+    #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)
+        #else:
+            #if P != 'length':
+                #self._set_property_value(P, V)
+            #else:
+                #length = V.ToUInt32()
+                #if length != V.ToNumber():
+                    #raise RangeError()
+
+                #self.set_length(length)
+                #return
+
+        #try:
+            #arrayindex = r_uint(to_array_index(P))
+        #except ValueError:
+            #return
+
+        #if (arrayindex < self.length) or (arrayindex != float(P)):
+            #return
+        #else:
+            #if (arrayindex + 1) == 0:
+                #raise RangeError()
+            #self.set_length(arrayindex+1)
 
 # 15.8
 class W_Math(W__Object):
@@ -811,7 +959,7 @@
     def ToObject(self):
         return W_BooleanObject(self)
 
-    def ToString(self):
+    def to_string(self):
         if self._boolval_ == True:
             return "true"
         return "false"
@@ -833,13 +981,17 @@
         W_Primitive.__init__(self)
         self._strval_ = strval
 
+    def __eq__(self, other):
+        other_string = other.to_string()
+        return self._strval_ == other_string
+
     def __repr__(self):
         return 'W_String(%s)' % (repr(self._strval_),)
 
     def ToObject(self):
         return W_StringObject(self)
 
-    def ToString(self):
+    def to_string(self):
         return self._strval_
 
     def ToBoolean(self):
@@ -902,7 +1054,7 @@
         # XXX
         return float(self._intval_)
 
-    def ToString(self):
+    def to_string(self):
         # XXX incomplete, this doesn't follow the 9.8.1 recommendation
         return str(self.ToInteger())
 
@@ -927,7 +1079,7 @@
     def __repr__(self):
         return 'W_FloatNumber(%s)' % (self._floatval_,)
 
-    def ToString(self):
+    def to_string(self):
         # XXX incomplete, this doesn't follow the 9.8.1 recommendation
         if isnan(self._floatval_):
             return 'NaN'
@@ -1025,3 +1177,6 @@
         return w_Null
     raise TypeError(value)
 
+def put_property(obj, name, value, writable = False, configurable = False, enumerable = False, throw = False):
+    descriptor = PropertyDescriptor(value = value, writable = writable, configurable = configurable, enumerable = enumerable)
+    obj.define_own_property(name, descriptor, throw)
diff --git a/js/lexical_environment.py b/js/lexical_environment.py
--- a/js/lexical_environment.py
+++ b/js/lexical_environment.py
@@ -1,4 +1,5 @@
 from js.jsobj import w_Undefined
+from js.execution import JsReferenceError
 
 def get_identifier_reference(lex, identifier, strict = False):
     if lex is None:
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -1,13 +1,14 @@
 from js.jsobj import W_IntNumber, W_FloatNumber, W_String,\
      w_Undefined, newbool, W__Object, \
      w_True, w_False, w_Null, W_Root, W__Function
-import js.jsobj as jsobj
 from js.execution import JsTypeError, ReturnException, ThrowException
 from js.baseop import plus, sub, compare, AbstractEC, StrictEC,\
      compare_e, increment, decrement, commonnew, mult, division, uminus, mod
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib import jit
 
+from js.jsobj import put_property
+
 class Opcode(object):
     _stack_change = 1
     def __init__(self):
@@ -95,7 +96,7 @@
         ctx.stack_append(self.w_stringvalue)
 
     #def __repr__(self):
-        #return 'LOAD_STRINGCONSTANT "%s"' % (self.w_stringvalue.ToString(),)
+        #return 'LOAD_STRINGCONSTANT "%s"' % (self.w_stringvalue.to_string(),)
 
 class LOAD_UNDEFINED(Opcode):
     def eval(self, ctx):
@@ -107,7 +108,7 @@
 
 class LOAD_VARIABLE(Opcode):
     #_immutable_fields_ = ['identifier']
-    def __init__(self, index):
+    def __init__(self, index, identifier):
         assert index is not None
         self.index = index
 
@@ -186,9 +187,9 @@
     def eval(self, ctx):
         w_obj = W__Object()
         for _ in range(self.counter):
-            name = ctx.stack_pop().ToString()
+            name = ctx.stack_pop().to_string()
             w_elem = ctx.stack_pop()
-            w_obj.Put(name, w_elem)
+            put_property(w_obj, name, w_elem, writable = True, configurable = True, enumerable = True)
         ctx.stack_append(w_obj)
 
     #def __repr__(self):
@@ -198,7 +199,7 @@
     _stack_change = -1
     def eval(self, ctx):
         w_obj = ctx.stack_pop().ToObject()
-        name = ctx.stack_pop().ToString()
+        name = ctx.stack_pop().to_string()
         value = w_obj.get(name)
         ctx.stack_append(value)
 
@@ -218,7 +219,7 @@
         from js.jsobj import W_BasicObject
         if not isinstance(right, W_BasicObject):
             raise ThrowException(W_String("TypeError: "+ repr(right)))
-        name = left.ToString()
+        name = left.to_string()
         return newbool(right.HasProperty(name))
 
 class TYPEOF(BaseUnaryOperation):
@@ -363,7 +364,7 @@
         left = ctx.stack_pop()
         member = ctx.stack_pop()
         value = ctx.stack_pop()
-        name = member.ToString()
+        name = member.to_string()
         left.ToObject().Put(name, value)
         ctx.stack_append(value)
 
@@ -514,12 +515,12 @@
     # TODO
     from js.jsobj import W_BasicFunction, 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:
-        res = r1.Call(args.ToList(), this)
-    except JsTypeError:
-        raise ThrowException(W_String("%s is not a function (%s)"%(r1.ToString(), name.ToString())))
+        raise ThrowException(W_String("%s is not a callable (%s)"%(r1.to_string(), name.to_string())))
+    #jit.promote(r1)
+    #try:
+    res = r1.Call(args.ToList(), this)
+    #except JsTypeError:
+        #raise ThrowException(W_String("%s is not a function (%s)"%(r1.to_string(), name.to_string())))
     return res
 
 class CALL(Opcode):
@@ -536,7 +537,7 @@
         method = ctx.stack_pop()
         what = ctx.stack_pop().ToObject()
         args = ctx.stack_pop()
-        name = method.ToString()
+        name = method.to_string()
         r1 = what.Get(name)
         ctx.stack_append(common_call(ctx, r1, args, what, method))
 
@@ -662,7 +663,7 @@
 class DELETE_MEMBER(Opcode):
     _stack_change = 0
     def eval(self, ctx):
-        what = ctx.stack_pop().ToString()
+        what = ctx.stack_pop().to_string()
         obj = ctx.stack_pop().ToObject()
         ctx.stack_append(newbool(obj.Delete(what)))
 
diff --git a/js/operations.py b/js/operations.py
--- a/js/operations.py
+++ b/js/operations.py
@@ -345,7 +345,7 @@
         return "Identifier '%s'@%d" % (self.name, self.index )
 
     def emit(self, bytecode):
-        bytecode.emit('LOAD_VARIABLE', self.index)
+        bytecode.emit('LOAD_VARIABLE', self.index, self.name)
 
     def get_literal(self):
         return self.name
@@ -551,7 +551,7 @@
 #class Index(BinaryOp):
 #    def eval(self, ctx):
 #        w_obj = self.left.eval(ctx).GetValue().ToObject(ctx)
-#        name= self.right.eval(ctx).GetValue().ToString(ctx)
+#        name= self.right.eval(ctx).GetValue().to_string(ctx)
 #        return W_Reference(name, w_obj)
 
 class ArgumentList(ListOp):
@@ -796,18 +796,20 @@
 #        return self.local
 
 class VariableIdentifier(Expression):
-    def __init__(self, identifier):
-        self.pos = pos
-        self.identifier = identifier
+    pass
+    #def __init__(self, index, identifier):
+        #self.pos = pos
+        #self.index = index
+        #self.identifier = identifier
 
-    def __repr__(self):
-        return "VariableIdentifier %s" % (self.identifier)
+    #def __repr__(self):
+        #return "VariableIdentifier %s" % (self.identifier)
 
-    def emit(self, bytecode):
-        bytecode.emit('LOAD_VARIABLE', self.identifier)
+    #def emit(self, bytecode):
+        #bytecode.emit('LOAD_VARIABLE', self.index, self.identifier)
 
-    def get_literal(self):
-        return self.identifier
+    #def get_literal(self):
+        #return self.identifier
 
 class VariableDeclList(Statement):
     def __init__(self, pos, nodes):
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
@@ -5,23 +5,34 @@
 #from js.execution import ThrowException
 #from js.jscode import JsCode
 #from js.baseop import AbstractEC
-from js.jscode import ExecutionContext
 
 def test_simple():
+    from js.jscode import JsCode
     bytecode = JsCode()
     bytecode.emit('LOAD_FLOATCONSTANT', 2)
     bytecode.emit('LOAD_FLOATCONSTANT', 4)
     bytecode.emit('ADD')
     bytecode.emit('POP')
 
+    from js.execution_context import ExecutionContext
+
+    from js.functions import JsExecutableCode
     f = JsExecutableCode(bytecode)
+
+    from js.execution_context import ExecutionContext
     ctx = ExecutionContext()
     res = f.run(ctx)
 
     assert res.ToNumber() == 6.0
 
-def assertp(code, prints):
-    pass
+def assertp(code, prints, captured):
+    out, err = captured.readouterr()
+
+    from js.interpreter import Interpreter
+    jsint = Interpreter()
+    jsint.run_src(code)
+    out, err = captured.readouterr()
+    assert out.strip() == prints.strip()
     #l = []
     #import js.builtins_global
     #js.builtins_global.writer = l.append
@@ -30,7 +41,7 @@
     #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.to_string()))
     #print l, prints
     #if isinstance(prints, list):
         #assert l == prints
@@ -60,17 +71,17 @@
     #elif isinstance(value, float):
         #assert code_val.ToNumber() == value
     #else:
-        #assert code_val.ToString() == value
+        #assert code_val.to_string() == value
 
 def asserte(code, value):
     pass
     #jsint = interpreter.Interpreter()
     #py.test.raises(value, 'jsint.run(interpreter.load_source(code, ""))')
 
-def test_interp_parse():
-    yield assertv, "1+1;", 2
-    yield assertp, "print(1+2+3); print(1);", ["6", "1"]
-    yield assertp, "print(1,2,3);\n", "1,2,3"
+def test_interp_parse(capsys):
+    assertv("1+1;", 2)
+    assertp("print(1+2+3); print(1);", "6\n1", capsys)
+    assertp("print(1,2,3);", "1,2,3", capsys)
 
 def test_var_assign():
     assertv("x=3;x;", 3)
@@ -80,38 +91,38 @@
     assertv("2-1;", 1)
 
 def test_string_var():
-    assertv('\"sss\";', 'sss')
+    assertv('"sss";', 'sss')
 
-def test_string_concat():
-    assertp('x="xxx"; y="yyy"; print(x+y);', "xxxyyy")
+def test_string_concat(capsys):
+    assertp('x="xxx"; y="yyy"; print(x+y);', "xxxyyy", capsys)
 
-def test_string_num_concat():
-    assertp('x=4; y="x"; print(x+y, y+x);', ["4x,x4"])
+def test_string_num_concat(capsys):
+    assertp('x=4; y="x"; print(x+y, y+x);', "4x,x4", capsys)
 
-def test_to_string():
-    assertp("x={}; print(x);", ["[object Object]"])
+def test_to_string(capsys):
+    assertp("x={}; print(x);", "[object Object]", capsys)
 
-def test_object_access():
-    yield assertp, "x={d:3}; print(x.d);", "3"
-    yield assertp, "x={d:3}; print(x.d.d);", "undefined"
-    yield assertp, "x={d:3, z:4}; print(x.d-x.z);", "-1"
+def test_object_access(capsys):
+    assertp("x={d:3}; print(x.d);", "3", capsys)
+    assertp("x={d:3}; print(x.d.d);", "undefined", capsys)
+    assertp("x={d:3, z:4}; print(x.d-x.z);", "-1", capsys)
 
-def test_object_access_index():
-    assertp('x={d:"x"}; print(x["d"]);', 'x')
+def test_object_access_index(capsys):
+    assertp('x={d:"x"}; print(x["d"]);', 'x', capsys)
 
-def test_function_prints():
-    assertp('x=function(){print(3);}; x();', '3')
+def test_function_prints(capsys):
+    assertp('x=function(){print(3);}; x();', '3', capsys)
 
-def test_function_returns():
-    yield assertv, 'x=function(){return 1;}; x()+x();', 2
-    yield assertp, 'function x() { return; };', []
-    yield assertv, 'function x() { d=2; return d;}; x()', 2
+def test_function_returns(capsys):
+    assertv('x=function(){return 1;}; x()+x();', 2)
+    assertp('function x() { return; };', '', capsys)
+    assertv('function x() { d=2; return d;}; x()', 2)
 
 def test_var_declaration():
-    yield assertv, 'var x = 3; x;', 3
-    yield assertv, 'var x = 3; x+x;', 6
+    assertv('var x = 3; x;', 3)
+    assertv('var x = 3; x+x;', 6)
 
-def test_var_scoping():
+def test_var_scoping(capsys):
     assertp("""
     var y;
     var p;
@@ -124,36 +135,36 @@
     };
     var z = 2;
     print(x(), y, p);
-    """, ["5,3,0"])
+    """, "5,3,0", capsys)
 
 def test_var_scoping_default_global():
-    yield assertv, 'd = 1; function x() { d=2;}; x(); d;', 2
-    yield assertv, 'd = 1; function x() { var d=2;}; x(); d;', 1
-    yield assertv, 'function x() { d=2;}; x(); d;', 2
-    yield assertv, 'var d = 1; function x() { d=2; }; x(); d;', 2
-    yield assertv, 'function x() { d=2;}; function y() { return d; }; x(); y();', 2
-    yield assertv, 'var d; function x() { d=2;}; function y() { return d; }; x(); y();', 2
+    assertv('d = 1; function x() { d=2;}; x(); d;', 2)
+    assertv('d = 1; function x() { var d=2;}; x(); d;', 1)
+    assertv('function x() { d=2;}; x(); d;', 2)
+    assertv('var d = 1; function x() { d=2; }; x(); d;', 2)
+    assertv('function x() { d=2;}; function y() { return d; }; x(); y();', 2)
+    assertv('var d; function x() { d=2;}; function y() { return d; }; x(); y();', 2)
 
 def test_function_args():
     assertv("""
     x = function (t,r) {
-           return t+r;
+       return t+r;
     };
     x(2,3);
     """, 5)
 
-def test_function_less_args():
+def test_function_less_args(capsys):
     assertp("""
     x = function (t, r) {
-            return t + r;
+        return t + r;
     };
     print(x(2));
-    """, "NaN")
+    """, "NaN", capsys)
 
 def test_function_more_args():
     assertv("""
     x = function (t, r) {
-            return t + r;
+        return t + r;
     };
     x(2,3,4);
     """, 5)
@@ -161,8 +172,8 @@
 def test_function_has_var():
     assertv("""
     x = function () {
-            var t = 'test';
-            return t;
+        var t = 'test';
+        return t;
     };
     x();
     """, 'test')
@@ -170,9 +181,9 @@
 def test_function_arguments():
     assertv("""
     x = function () {
-            r = arguments[0];
-            t = arguments[1];
-            return t + r;
+        r = arguments[0];
+        t = arguments[1];
+        return t + r;
     };
     x(2,3);
     """, 5)
@@ -184,15 +195,29 @@
     x[1];
     """, 'test')
 
-def test_array_initializer():
+def test_print_object(capsys):
+    assertp("""
+    x = {1:"test"};
+    print(x);
+    """, "[object Object]", capsys)
+    assertp("""
+    print(Object);
+    """, "function Object() { [native code] }", capsys)
+    assertp("""
+    print(Object.prototype);
+    """, "[object Object]", capsys)
+
+ at py.test.mark.xfail
+def test_array_initializer(capsys):
     assertp("""
     x = [];
     print(x);
     print(x.length)
-    """, ['', '0'])
+    """, '\n0', capsys)
 
-def test_throw():
-    assertp("throw(3);", "uncaught exception: 3")
+ at py.test.mark.xfail
+def test_throw(capsys):
+    assertp("throw(3);", "uncaught exception: 3", capsys)
 
 def test_group():
     assertv("(2+1);", 3)
@@ -200,20 +225,21 @@
 def test_comma():
     assertv("(500,3);", 3)
 
-def test_block():
-    yield assertp, "{print(5);}", '5'
-    yield assertp, "{3; print(5);}", '5'
+def test_block(capsys):
+    assertp("{print(5);}", '5', capsys)
+    assertp("{3; print(5);}", '5', capsys)
 
-def test_try_catch_finally():
-    yield assertp, """
+ at py.test.mark.xfail
+def test_try_catch_finally(capsys):
+    assertp("""
     try {
         throw(3);
     }
     catch (x) {
         print(x);
     }
-    """, "3"
-    yield assertp, """
+    """, "3", capsys)
+    assertp("""
     try {
         throw(3);
     }
@@ -223,53 +249,53 @@
     finally {
         print(5);
     }
-    """, ["3", "5"]
+    """, "3\n5", capsys)
 
-def test_if_then():
+def test_if_then(capsys):
     assertp("""
     if (1) {
         print(1);
     }
-    """, "1")
+    """, "1", capsys)
 
-def test_if_then_else():
+def test_if_then_else(capsys):
     assertp("""
     if (0) {
         print(1);
     } else {
         print(2);
     }
-    """, "2")
+    """, "2", capsys)
 
 def test_compare():
-    yield assertv, "1>0;", True
-    yield assertv, "0>1;", False
-    yield assertv, "0>0;", False
-    yield assertv, "1<0;", False
-    yield assertv, "0<1;", True
-    yield assertv, "0<0;", False
-    yield assertv, "1>=0;", True
-    yield assertv, "1>=1;", True
-    yield assertv, "1>=2;", False
-    yield assertv, "0<=1;", True
-    yield assertv, "1<=1;", True
-    yield assertv, "1<=0;", False
-    yield assertv, "0==0;", True
-    yield assertv, "1==1;", True
-    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
+    assertv("1>0;", True)
+    assertv("0>1;", False)
+    assertv("0>0;", False)
+    assertv("1<0;", False)
+    assertv("0<1;", True)
+    assertv("0<0;", False)
+    assertv("1>=0;", True)
+    assertv("1>=1;", True)
+    assertv("1>=2;", False)
+    assertv("0<=1;", True)
+    assertv("1<=1;", True)
+    assertv("1<=0;", False)
+    assertv("0==0;", True)
+    assertv("1==1;", True)
+    assertv("0==1;", False)
+    assertv("0!=1;", True)
+    assertv("1!=1;", False)
+    assertv("1===1;", True)
+    assertv("1!==1;", False)
 
 def test_string_compare():
-    yield assertv, "'aaa' > 'a';", True
-    yield assertv, "'aaa' < 'a';", False
-    yield assertv, "'a' > 'a';", False
+    assertv("'aaa' > 'a';", True)
+    assertv("'aaa' < 'a';", False)
+    assertv("'a' > 'a';", False)
 
-def test_binary_opb():
-    yield assertp, "print(0||0); print(1||0);", ["0", "1"]
-    yield assertp, "print(0&&1); print(1&&1);", ["0", "1"]
+def test_binary_opb(capsys):
+    assertp("print(0||0); print(1||0);", "0\n1", capsys)
+    assertp("print(0&&1); print(1&&1);", "0\n1", capsys)
 
 def test_while():
     assertp("""
diff --git a/js/test/test_jsfunciton.py b/js/test/test_jsfunciton.py
--- a/js/test/test_jsfunciton.py
+++ b/js/test/test_jsfunciton.py
@@ -30,9 +30,9 @@
         code.emit('RETURN')
 
         f = JsFunction('foo', code)
-        ctx = FunctionExecutionContext(f, None, [])
+        ctx = FunctionExecutionContext()
+        res = f.run(ctx)
 
-        res = ctx.run()
         assert res == _w(2)
 
 
@@ -302,7 +302,7 @@
         assert res == _w(55)
 
     def test_foo12(self):
-        def f(args, this):
+        def f(this, args):
             a = args[0].ToInteger()
             return _w(a + 1)
 
@@ -313,7 +313,7 @@
         assert res == _w(42)
 
     def test_foo13(self):
-        def f(args, this):
+        def f(this, args):
             a = args[0].ToInteger()
             return _w(a + 1)
 
@@ -380,6 +380,14 @@
         res = self.run_src(src)
         assert res == _w(42)
 
+    def test_foo18(self):
+        src = '''
+        function x() { d=2; return d;}; x();


More information about the pypy-commit mailing list