[webkit-changes] cvs commit: JavaScriptCore/kjs string_object.cpp

Timothy thatcher at opensource.apple.com
Fri Nov 11 11:18:53 PST 2005


thatcher    05/11/11 11:18:52

  Modified:    .        Tag: Safari-1-3-branch ChangeLog
               kjs      Tag: Safari-1-3-branch string_object.cpp
  Log:
          Merges fixes from TOT to Safari-1-3-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.4.6 +11 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.677.4.5
  retrieving revision 1.677.4.6
  diff -u -r1.677.4.5 -r1.677.4.6
  --- ChangeLog	5 Nov 2005 00:05:06 -0000	1.677.4.5
  +++ ChangeLog	11 Nov 2005 19:18:49 -0000	1.677.4.6
  @@ -1,3 +1,14 @@
  +2005-11-11  Timothy Hatcher  <timothy at apple.com>
  +
  +        Merges fixes from TOT to Safari-1-3-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.
  +
   === JavaScriptCore-312.1.1 ===
   
   2005-11-4  Timothy Hatcher  <timothy at apple.com>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.31.6.1  +40 -4     JavaScriptCore/kjs/string_object.cpp
  
  Index: string_object.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/string_object.cpp,v
  retrieving revision 1.31
  retrieving revision 1.31.6.1
  diff -u -r1.31 -r1.31.6.1
  --- string_object.cpp	17 Dec 2004 00:10:25 -0000	1.31
  +++ string_object.cpp	11 Nov 2005 19:18:51 -0000	1.31.6.1
  @@ -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);
   
  @@ -325,9 +351,19 @@
       // Do the replacement
       if (matchPos == -1)
         return String(source);
  -    else {
  -      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));
     }
   }
   
  
  
  



More information about the webkit-changes mailing list