[pypy-svn] r39622 - in pypy/dist/pypy/lang/js: . js test/ecma

santagada at codespeak.net santagada at codespeak.net
Thu Mar 1 12:11:29 CET 2007


Author: santagada
Date: Thu Mar  1 12:11:27 2007
New Revision: 39622

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/js/jsparse.js
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/test/ecma/conftest.py
   pypy/dist/pypy/lang/js/test/ecma/shell.js
Log:
parser corrections, equality operator fully to the spec, py.test runner that reports why test failed, and some other misc changes

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Thu Mar  1 12:11:27 2007
@@ -184,6 +184,7 @@
         #Math
         w_math = W_Object(Class='Math')
         w_Global.Put('Math', w_math)
+        w_math.Put('__proto__',  w_ObjPrototype)
         w_math.Put('abs', W_Builtin(absjs, Class='function'))
         w_math.Put('floor', W_Builtin(floorjs, Class='function'))
         w_math.Put('E', W_Number(math.e))
@@ -528,8 +529,49 @@
 def AEC(x, y):
     """
     Implements the Abstract Equality Comparison x == y
-    not following the specs yet
+    trying to be fully to the spec
     """
+    type1 = x.type()
+    type2 = y.type()
+    if type1 == type2:
+        if type1 == "undefined" or type1 == "null":
+            return True
+        if type1 == "number":
+            n1 = x.ToNumber()
+            n2 = y.ToNumber()
+            nan_string = str(NaN)
+            if str(n1) == nan_string or str(n2) == nan_string:
+                return False
+            if n1 == n2:
+                return True
+            return False
+        elif type1 == "string":
+            return x.ToString() == y.ToString()
+        elif type1 == "boolean":
+            return x.ToBoolean() == x.ToBoolean()
+        return x == y
+    else:
+        #step 14
+        if (type1 == "undefined" and type2 == "null") or \
+           (type1 == "null" and type2 == "undefined"):
+            return True
+        if type1 == "number" and type2 == "string":
+            return AEC(x, W_Number(y.ToNumber()))
+        if type1 == "string" and type2 == "number":
+            return AEC(W_Number(x.ToNumber()), y)
+        if type1 == "boolean":
+            return AEC(W_Number(x.ToNumber()), y)
+        if type2 == "boolean":
+            return AEC(x, W_Number(y.ToNumber()))
+        if (type1 == "string" or type1 == "number") and \
+            type2 == "object":
+            return AEC(x, y.ToPrimitive())
+        if (type2 == "string" or type2 == "number") and \
+            type1 == "object":
+            return AEC(x.ToPrimitive(), y)
+        return False
+            
+        
     objtype = x.GetValue().type()
     if objtype == y.GetValue().type():
         if objtype == "undefined" or objtype == "null":

Modified: pypy/dist/pypy/lang/js/js/jsparse.js
==============================================================================
--- pypy/dist/pypy/lang/js/js/jsparse.js	(original)
+++ pypy/dist/pypy/lang/js/js/jsparse.js	Thu Mar  1 12:11:27 2007
@@ -297,7 +297,7 @@
         }
         
         if(typeof a[i].value == 'string'){
-            val = a[i].value.replace(/'/g, "\\'")
+            val = a[i].value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")
         } else {
             val = a[i].value+ "";
         }

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Thu Mar  1 12:11:27 2007
@@ -202,12 +202,12 @@
 
     def internal_def_value(self, ctx, tryone, trytwo):
         t1 = self.Get(tryone)
-        if isinstance(t1, W_Object):
+        if isinstance(t1, W_PrimitiveObject):
             val = t1.Call(ctx, this=self)
             if isinstance(val, W_Primitive):
                 return val
         t2 = self.Get(trytwo)
-        if isinstance(t2, W_Object):
+        if isinstance(t2, W_PrimitiveObject):
             val = t2.Call(ctx, this=self)
             if isinstance(val, W_Primitive):
                 return val

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Thu Mar  1 12:11:27 2007
@@ -44,12 +44,15 @@
     retval = pipe.read()
     if not retval.startswith("{"):
         raise JsSyntaxError(retval)
+    if DEBUG:
+        print "received back:"
+        print retval
     return retval
 
 def unquote(t):
     if isinstance(t, Symbol):
         if t.symbol == "QUOTED_STRING":
-            t.additional_info = t.additional_info.strip("'").replace("\\'", "'")
+            t.additional_info = t.additional_info[1:-1].replace("\\'", "'").replace("\\\\", "\\")
     else:
         for i in t.children:
             unquote(i)
@@ -68,7 +71,7 @@
     return tree
 
 regexs, rules, ToAST = parse_ebnf(r"""
-    QUOTED_STRING: "'([^\']|\\\')*'";"""+"""
+    QUOTED_STRING: "'([^\\\']|\\[\\\'])*'";"""+"""
     IGNORE: " |\n";
     data: <dict> | <QUOTED_STRING> | <list>;
     dict: ["{"] (dictentry [","])* dictentry ["}"];

Modified: pypy/dist/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/conftest.py	(original)
+++ pypy/dist/pypy/lang/js/test/ecma/conftest.py	Thu Mar  1 12:11:27 2007
@@ -77,9 +77,13 @@
     def run(self):
         ctx = JSTestFile.interp.global_context
         r3 = ctx.resolve_identifier('run_test').GetValue()
-        result = r3.Call(ctx=ctx, args=[W_Number(self.number),]).ToNumber()
+        w_test_array = ctx.resolve_identifier('testcases').GetValue()
+        w_test_number = W_Number(self.number)
+        result = r3.Call(ctx=ctx, args=[w_test_number,]).ToNumber()
         if result == 0:
-            raise Failed(msg="Results don't match")
+            w_test = w_test_array.Get(str(self.number)).GetValue()
+            w_reason = w_test.Get('reason').GetValue()
+            raise Failed(msg=w_reason.ToString())
         elif result == -1:
             py.test.skip()
 

Modified: pypy/dist/pypy/lang/js/test/ecma/shell.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/shell.js	(original)
+++ pypy/dist/pypy/lang/js/test/ecma/shell.js	Thu Mar  1 12:11:27 2007
@@ -196,7 +196,8 @@
 function run_test(tc) {
     // try {
         getTestCaseResult(testcases[tc].expect, testcases[tc].actual)
-        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
+        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value expected: "
+                                +testcases[tc].expect+" but got: "+ testcases[tc].actual;
         return testcases[tc].passed? 1:0;
     // }
     // catch(e) {



More information about the Pypy-commit mailing list