[webkit-changes] cvs commit: JavaScriptCore/kjs string_object.cpp
Timothy
thatcher at opensource.apple.com
Fri Nov 11 11:09:05 PST 2005
thatcher 05/11/11 11:09:05
Modified: . Tag: Safari-2-0-branch ChangeLog
kjs Tag: Safari-2-0-branch string_object.cpp
Log:
Merges fixes from TOT to Safari-2-0-branch
2005-06-20 Anders Carlsson <andersca at mac.com>
Fixed: <http://bugzilla.opendarwin.org/show_bug.cgi?id=3294>
* kjs/string_object.cpp:
(replace): Handle the second argument of replace being a function.
Revision Changes Path
No revision
No revision
1.677.6.54 +11 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.677.6.53
retrieving revision 1.677.6.54
diff -u -r1.677.6.53 -r1.677.6.54
--- ChangeLog 10 Nov 2005 17:36:30 -0000 1.677.6.53
+++ ChangeLog 11 Nov 2005 19:09:02 -0000 1.677.6.54
@@ -1,3 +1,14 @@
+2005-11-11 Timothy Hatcher <timothy at apple.com>
+
+ Merges fixes from TOT to Safari-2-0-branch
+
+ 2005-06-20 Anders Carlsson <andersca at mac.com>
+
+ Fixed: <http://bugzilla.opendarwin.org/show_bug.cgi?id=3294>
+
+ * kjs/string_object.cpp:
+ (replace): Handle the second argument of replace being a function.
+
2005-11-10 Timothy Hatcher <timothy at apple.com>
Merges fixes from Ti-2005-009-branch to Safari-2-0-branch
No revision
No revision
1.31.8.5 +41 -3 JavaScriptCore/kjs/string_object.cpp
Index: string_object.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/string_object.cpp,v
retrieving revision 1.31.8.4
retrieving revision 1.31.8.5
diff -u -r1.31.8.4 -r1.31.8.5
--- string_object.cpp 16 Sep 2005 02:34:04 -0000 1.31.8.4
+++ string_object.cpp 11 Nov 2005 19:09:04 -0000 1.31.8.5
@@ -264,6 +264,14 @@
static Value replace(ExecState *exec, const UString &source, const Value &pattern, const Value &replacement)
{
+ ObjectImp *replacementFunction = 0;
+ UString replacementString;
+
+ if (replacement.type() == ObjectType && replacement.toObject(exec).implementsCall())
+ replacementFunction = replacement.toObject(exec).imp();
+ else
+ replacementString = replacement.toString(exec);
+
if (pattern.type() == ObjectType && pattern.toObject(exec).inherits(&RegExpImp::info)) {
RegExpImp* imp = static_cast<RegExpImp *>( pattern.toObject(exec).imp() );
RegExp *reg = imp->regExp();
@@ -271,8 +279,6 @@
RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp().imp());
- UString replacementString = replacement.toString(exec);
-
int matchIndex = 0;
int lastIndex = 0;
int startPosition = 0;
@@ -295,6 +301,26 @@
pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex));
+ if (replacementFunction) {
+ int completeMatchStart = (*ovector)[0];
+ List args;
+
+ args.append(Value(matchString));
+
+ for (unsigned i = 0; i < reg->subPatterns(); i++) {
+ int matchStart = (*ovector)[(i + 1) * 2];
+ int matchLen = (*ovector)[(i + 1) * 2 + 1] - matchStart;
+
+ args.append(Value(source.substr(matchStart, matchLen)));
+ }
+
+ args.append(Value(completeMatchStart));
+ args.append(Value(source));
+
+ replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
+ args).toString(exec);
+ }
+
UString substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
pushReplacement(replacements, replacementCount, replacementCapacity, substitutedReplacement);
@@ -327,7 +353,19 @@
// Do the replacement
if (matchPos == -1)
return String(source);
- return String(source.substr(0, matchPos) + replacement.toString(exec) + source.substr(matchPos + matchLen));
+
+ if (replacementFunction) {
+ List args;
+
+ args.append(Value(source.substr(matchPos, matchLen)));
+ args.append(Value(matchPos));
+ args.append(Value(source));
+
+ replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
+ args).toString(exec);
+ }
+
+ return String(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
}
// ECMA 15.5.4.2 - 15.5.4.20
More information about the webkit-changes
mailing list