Changeset 38603 in webkit for trunk/JavaScriptCore/runtime/RegExpObject.cpp
- Timestamp:
- Nov 19, 2008, 1:08:40 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/RegExpObject.cpp
r38575 r38603 107 107 } 108 108 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 146 109 JSValue* RegExpObject::test(ExecState* exec, const ArgList& args) 147 110 { … … 167 130 } 168 131 132 // Shared implementation used by test and exec. 133 bool 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 169 167 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.