[pypy-svn] r64939 - pypy/branch/js-refactoring/pypy/lang/js
jandem at codespeak.net
jandem at codespeak.net
Fri May 1 14:08:14 CEST 2009
Author: jandem
Date: Fri May 1 14:08:13 2009
New Revision: 64939
Modified:
pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
Log:
Implement String.prototype.lastIndexOf
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 1 14:08:13 2009
@@ -419,6 +419,26 @@
pos = min(max(pos, 0), size)
return W_IntNumber(string.find(substr, pos))
+class W_LastIndexOf(W_NewBuiltin):
+ length = 1
+ def Call(self, ctx, args=[], this=None):
+ string = this.ToString(ctx)
+ if len(args) < 1:
+ return W_IntNumber(-1)
+ substr = args[0].ToString(ctx)
+ if len(args) < 2:
+ pos = INFINITY
+ else:
+ val = args[1].ToNumber(ctx)
+ if isnan(val):
+ pos = INFINITY
+ else:
+ pos = args[1].ToInteger(ctx)
+ size = len(string)
+ pos = min(max(pos, 0), size)
+ subsize = len(substr)
+ return W_IntNumber(string.rfind(substr, 0, pos+subsize))
+
class W_Substring(W_NewBuiltin):
length = 2
def Call(self, ctx, args=[], this=None):
@@ -655,6 +675,7 @@
'charCodeAt': W_CharCodeAt(ctx),
'concat': W_Concat(ctx),
'indexOf': W_IndexOf(ctx),
+ 'lastIndexOf': W_LastIndexOf(ctx),
'substring': W_Substring(ctx),
'split': W_Split(ctx),
'toLowerCase': W_ToLowerCase(ctx),
More information about the Pypy-commit
mailing list