Ignore:
Timestamp:
Nov 19, 2008, 1:08:40 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-11-19 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.


https://bugs.webkit.org/show_bug.cgi?id=22361
A little more RegExp refactoring.


Consistently named variables holding the starting position at which
regexp matching should begin to "startOffset".


A few more "regExpObject" => "regExpConstructor" changes.


Refactored RegExpObject::match for clarity, and replaced a slow "get"
of the "global" property with a fast access to the global bit.


Made the error message you see when RegExpObject::match has no input a
little more informative, as in Firefox.

  • runtime/RegExp.cpp: (JSC::RegExp::match):
  • runtime/RegExp.h:
  • runtime/RegExpObject.cpp: (JSC::RegExpObject::match):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncReplace): (JSC::stringProtoFuncMatch): (JSC::stringProtoFuncSearch):

LayoutTests:

2008-11-19 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.


Test for https://bugs.webkit.org/show_bug.cgi?id=22361
A little more RegExp refactoring

  • fast/js/regexp-test-null-string.html: Added.
  • fast/js/regexp-test-null-expected.txt: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/RegExpObject.cpp

    r38575 r38603  
    107107}
    108108
    109 bool RegExpObject::match(ExecState* exec, const ArgList& args)
    110 {
    111     RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
    112 
    113     UString input;
    114     if (!args.isEmpty())
    115         input = args.at(exec, 0)->toString(exec);
    116     else {
    117         input = regExpConstructor->input();
    118         if (input.isNull()) {
    119             throwError(exec, GeneralError, "No input.");
    120             return false;
    121         }
    122     }
    123 
    124     bool global = get(exec, exec->propertyNames().global)->toBoolean(exec);
    125     int lastIndex = 0;
    126     if (global) {
    127         if (d->lastIndex < 0 || d->lastIndex > input.size()) {
    128             d->lastIndex = 0;
    129             return false;
    130         }
    131         lastIndex = static_cast<int>(d->lastIndex);
    132     }
    133 
    134     int foundIndex;
    135     int foundLength;
    136     regExpConstructor->performMatch(d->regExp.get(), input, lastIndex, foundIndex, foundLength);
    137 
    138     if (global) {
    139         lastIndex = foundIndex < 0 ? 0 : foundIndex + foundLength;
    140         d->lastIndex = lastIndex;
    141     }
    142 
    143     return foundIndex >= 0;
    144 }
    145 
    146109JSValue* RegExpObject::test(ExecState* exec, const ArgList& args)
    147110{
     
    167130}
    168131
     132// Shared implementation used by test and exec.
     133bool RegExpObject::match(ExecState* exec, const ArgList& args)
     134{
     135    RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
     136
     137    UString input = args.isEmpty() ? regExpConstructor->input() : args.at(exec, 0)->toString(exec);
     138    if (input.isNull()) {
     139        throwError(exec, GeneralError, "No input to " + toString(exec) + ".");
     140        return false;
     141    }
     142
     143    if (!regExp()->global()) {
     144        int position;
     145        int length;
     146        regExpConstructor->performMatch(d->regExp.get(), input, 0, position, length);
     147        return position >= 0;
     148    }
     149
     150    if (d->lastIndex < 0 || d->lastIndex > input.size()) {
     151        d->lastIndex = 0;
     152        return false;
     153    }
     154
     155    int position;
     156    int length;
     157    regExpConstructor->performMatch(d->regExp.get(), input, static_cast<int>(d->lastIndex), position, length);
     158    if (position < 0) {
     159        d->lastIndex = 0;
     160        return false;
     161    }
     162
     163    d->lastIndex = position + length;
     164    return true;
     165}
     166
    169167} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.