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

santagada at codespeak.net santagada at codespeak.net
Thu Mar 1 12:40:50 CET 2007


Author: santagada
Date: Thu Mar  1 12:40:47 2007
New Revision: 39624

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
strict equality

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:40:47 2007
@@ -595,6 +595,44 @@
     def decision(self, ctx, op1, op2):
         return W_Boolean(not AEC(op1, op2))
 
+def SEC(x,y):
+    """
+    Implements the Strict Equality Comparison x === y
+    trying to be fully to the spec
+    """
+    type1 = x.type()
+    type2 = y.type()
+    if type1 != type2:
+        return False
+    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
+    if type1 == "string":
+        return x.ToString() == y.ToString()
+    if type1 == "boolean":
+        return x.ToBoolean() == x.ToBoolean()
+    return x == y
+
+class StrictEq(BinaryComparisonOp):
+    opcode = 'STRICT_EQ'
+    
+    def decision(self, ctx, op1, op2):
+        return W_Boolean(SEC(op1, op2))
+
+class StrictNe(BinaryComparisonOp):
+    opcode = 'STRICT_NE'
+    
+    def decision(self, ctx, op1, op2):
+        return W_Boolean(not SEC(op1, op2))
+    
 
 class In(BinaryComparisonOp):
     opcode = 'IN'

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Thu Mar  1 12:40:47 2007
@@ -470,3 +470,11 @@
             print(y)
         }
         """, ['5',])
+
+    def test_stricteq(self):
+        self.assert_prints("""
+        print(2 === 2)
+        print(2 === 3)
+        print(2 !== 3)
+        print(2 !== 2)    
+        """, ['true', 'false', 'true', 'false'])



More information about the Pypy-commit mailing list