[pypy-svn] r55150 - in pypy/branch/js-refactoring/pypy/lang/js: . test/ecma

fijal at codespeak.net fijal at codespeak.net
Fri May 23 16:41:32 CEST 2008


Author: fijal
Date: Fri May 23 16:41:31 2008
New Revision: 55150

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/baseop.py
   pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
   pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
Log:
* Use overloaded eval for tests
* Fix few bugs
* *All* Number tests passes these days.


Modified: pypy/branch/js-refactoring/pypy/lang/js/baseop.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/baseop.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/baseop.py	Fri May 23 16:41:31 2008
@@ -144,7 +144,8 @@
             return x.ToString(ctx) == y.ToString(ctx)
         elif type1 == "boolean":
             return x.ToBoolean() == x.ToBoolean()
-        return x == y
+        # XXX rethink it here
+        return x.ToString(ctx) == y.ToString(ctx)
     else:
         #step 14
         if (type1 == "undefined" and type2 == "null") or \

Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	Fri May 23 16:41:31 2008
@@ -81,7 +81,7 @@
 
 class W_StringObject(W_NativeObject):
     def Call(self, ctx, args=[], this=None):
-        if len(args) >= 1 and not isnull_or_undefined(args[0]):
+        if len(args) >= 1:
             return W_String(args[0].ToString(ctx))
         else:
             return W_String('')
@@ -97,7 +97,7 @@
         proto = ctx.get_global().Get('Array').Get('prototype')
         array = W_Array(ctx, Prototype=proto, Class = proto.Class)
         for i in range(len(args)):
-            array.Put(str(i), args[0])
+            array.Put(str(i), args[i])
         return array
 
     def Construct(self, ctx, args=[]):
@@ -317,13 +317,19 @@
 class W_ValueToString(W_NewBuiltin):
     "this is the toString function for objects with Value"
     def Call(self, ctx, args=[], this=None):
+        if this.Value.type() != 'number':
+            raise JsTypeError('Wrong type')
         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
 
+def get_value_of(type, ctx):
+    class W_ValueValueOf(W_NewBuiltin):
+        "this is the valueOf function for objects with Value"
+        def Call(self, ctx, args=[], this=None):
+            if type != this.Class:
+                raise JsTypeError('%s.prototype.valueOf called with incompatible type' % self.type())
+            return this.Value
+    return W_ValueValueOf(ctx)
+        
 class W_CharAt(W_NewBuiltin):
     def Call(self, ctx, args=[], this=None):
         string = this.ToString(ctx)
@@ -452,7 +458,7 @@
             'constructor': w_FncPrototype,
             '__proto__': w_BoolPrototype,
             'toString': W_ValueToString(ctx),
-            'valueOf': W_ValueValueOf(ctx),
+            'valueOf': get_value_of('Boolean', ctx)
         })
 
         w_Boolean.Put('prototype', w_BoolPrototype)
@@ -462,18 +468,22 @@
         #Number
         w_Number = W_NumberObject('Number', w_FncPrototype)
 
+        w_empty_fun = w_Function.Call(ctx, args=[W_String('')])
+
         w_NumPrototype = create_object(ctx, 'Object', Value=W_FloatNumber(0.0))
         w_NumPrototype.Class = 'Number'
         put_values(w_NumPrototype, {
-            'constructor': w_FncPrototype,
-            '__proto__': w_NumPrototype,
+            'constructor': w_Number,
+            '__proto__': w_empty_fun,
             'toString': W_ValueToString(ctx),
-            'valueOf': W_ValueValueOf(ctx),
+            'valueOf': get_value_of('Number', ctx),
         })
 
         put_values(w_Number, {
             'constructor': w_FncPrototype,
             'prototype': w_NumPrototype,
+            '__proto__': w_empty_fun,
+            'length'   : W_IntNumber(1),
         })
         w_Number.propdict['prototype'].ro = True
         w_Number.Put('MAX_VALUE', W_FloatNumber(1.7976931348623157e308),
@@ -500,7 +510,7 @@
             'constructor': w_FncPrototype,
             '__proto__': w_StrPrototype,
             'toString': W_ValueToString(ctx),
-            'valueOf': W_ValueValueOf(ctx),
+            'valueOf': get_value_of('String', ctx),
             'charAt': W_CharAt(ctx),
             'concat': W_Concat(ctx),
             'indexOf': W_IndexOf(ctx),

Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	Fri May 23 16:41:31 2008
@@ -59,7 +59,7 @@
     
     def Put(self, P, V, dd=False,
             ro=False, de=False, it=False):
-        raise NotImplementedError
+        pass
     
     def PutValue(self, w, ctx):
         pass
@@ -99,6 +99,9 @@
     def ToBoolean(self):
         return False
 
+    def ToString(self, ctx):
+        return "null"
+
     def type(self):
         return 'null'
 
@@ -261,7 +264,7 @@
         raise NotImplementedError
 
     def type(self):
-        return 'builtin'
+        return self.Class
 
 class W_Builtin(W_PrimitiveObject):
     def __init__(self, builtin=None, ctx=None, Prototype=None, Class='function',
@@ -612,37 +615,6 @@
                             jsproperty = Property('', w_Undefined))
     return ctx
 
-# class W_Reference(W_Root):
-#     """Reference Type"""
-#     def __init__(self, property_name, base=None):
-#         self.base = base
-#         self.property_name = property_name
-
-#     def check_empty(self):
-#         if self.base is None:
-#             exception = "ReferenceError: %s is not defined"%(self.property_name,)
-#             raise ThrowException(W_String(exception))        
-
-#     #def GetValue(self):
-#     #    self.check_empty()
-#     #    return self.base.Get(self.property_name)
-
-#     #def PutValue(self, w, ctx):
-#     #    base = self.base
-#     #    if base is None:
-#     #        base = ctx.scope[-1]
-#     #    base.Put(self.property_name, w)
-#     #    return w
-
-#     #def GetBase(self):
-#     #    return self.base
-
-#     #def GetPropertyName(self):
-#     #    return self.property_name
-
-#     def __str__(self):
-#         return "<" + str(self.base) + " -> " + str(self.property_name) + ">"
-
 class W_Iterator(W_Root):
     def __init__(self, elements_w):
         self.elements_w = elements_w

Modified: pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py	Fri May 23 16:41:31 2008
@@ -1,6 +1,6 @@
 import py
 from pypy.lang.js.interpreter import *
-from pypy.lang.js.jsobj import W_Array
+from pypy.lang.js.jsobj import W_Array, W_String
 from pypy.rlib.parsing.parsing import ParseError
 from py.__.test.outcome import Failed, ExceptionFailure
 import pypy.lang.js as js
@@ -12,6 +12,12 @@
 rootdir = py.magic.autopath().dirpath()
 exclusionlist = ['shell.js', 'browser.js']
 
+def overriden_evaljs(ctx, args, this):
+    try:
+        return evaljs(ctx, args, this)
+    except JsBaseExcept:
+        return W_String("error")
+
 class JSDirectory(py.test.collect.Directory):
 
     def filefilter(self, path):
@@ -27,8 +33,6 @@
         if p.check(file=1):
             return JSTestFile(p, parent=self)
 
-
-
 class JSTestFile(py.test.collect.Module):
     def init_interp(cls):
         if hasattr(cls, 'interp'):
@@ -42,6 +46,9 @@
         cls.interp.run(cls.shellfile)
         cls.testcases = cls.interp.global_context.resolve_identifier('testcases')
         cls.tc = cls.interp.global_context.resolve_identifier('tc')
+        # override eval
+        cls.interp.global_context.put('eval', W_Builtin(overriden_evaljs))
+        
     init_interp = classmethod(init_interp)
     
     def __init__(self, fspath, parent=None):



More information about the Pypy-commit mailing list