[pypy-svn] r64850 - pypy/branch/js-refactoring/pypy/lang/js

jandem at codespeak.net jandem at codespeak.net
Thu Apr 30 12:34:38 CEST 2009


Author: jandem
Date: Thu Apr 30 12:34:34 2009
New Revision: 64850

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
Log:
Implement String.prototype.charCodeAt, it passes all ecma tests.


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	Thu Apr 30 12:34:34 2009
@@ -384,6 +384,18 @@
             return W_String('')
         return W_String(string[pos])
 
+class W_CharCodeAt(W_NewBuiltin):
+    def Call(self, ctx, args=[], this=None):
+        string = this.ToString(ctx)
+        if len(args)>=1:
+            pos = args[0].ToInt32(ctx)
+            if pos < 0 or pos > len(string) - 1:
+                return W_FloatNumber(NAN)
+        else:
+            return W_FloatNumber(NAN)
+        char = string[pos]
+        return W_IntNumber(ord(char))
+
 class W_Concat(W_NewBuiltin):
     def Call(self, ctx, args=[], this=None):
         string = this.ToString(ctx)
@@ -635,6 +647,7 @@
             'toString': W_StringValueToString(ctx),
             'valueOf': get_value_of('String')(ctx),
             'charAt': w_CharAt,
+            'charCodeAt': W_CharCodeAt(ctx),
             'concat': W_Concat(ctx),
             'indexOf': w_IndexOf,
             'substring': W_Substring(ctx),



More information about the Pypy-commit mailing list