Changeset 34580 in webkit for trunk/JavaScriptCore/kjs/regexp_object.cpp
- Timestamp:
- Jun 15, 2008, 8:02:57 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp_object.cpp
r34578 r34580 62 62 JSValue* regExpProtoFuncTest(ExecState* exec, JSObject* thisObj, const List& args) 63 63 { 64 if (!thisObj->inherits(&RegExp Imp::info))64 if (!thisObj->inherits(&RegExpObject::info)) 65 65 return throwError(exec, TypeError); 66 66 67 return static_cast<RegExp Imp*>(thisObj)->test(exec, args);67 return static_cast<RegExpObject*>(thisObj)->test(exec, args); 68 68 } 69 69 70 70 JSValue* regExpProtoFuncExec(ExecState* exec, JSObject* thisObj, const List& args) 71 71 { 72 if (!thisObj->inherits(&RegExp Imp::info))72 if (!thisObj->inherits(&RegExpObject::info)) 73 73 return throwError(exec, TypeError); 74 74 75 return static_cast<RegExp Imp*>(thisObj)->exec(exec, args);75 return static_cast<RegExpObject*>(thisObj)->exec(exec, args); 76 76 } 77 77 78 78 JSValue* regExpProtoFuncCompile(ExecState* exec, JSObject* thisObj, const List& args) 79 79 { 80 if (!thisObj->inherits(&RegExp Imp::info))80 if (!thisObj->inherits(&RegExpObject::info)) 81 81 return throwError(exec, TypeError); 82 82 … … 85 85 JSValue* arg1 = args[1]; 86 86 87 if (arg0->isObject(&RegExp Imp::info)) {87 if (arg0->isObject(&RegExpObject::info)) { 88 88 if (!arg1->isUndefined()) 89 89 return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another."); 90 regExp = static_cast<RegExp Imp*>(arg0)->regExp();90 regExp = static_cast<RegExpObject*>(arg0)->regExp(); 91 91 } else { 92 92 UString pattern = args.isEmpty() ? UString("") : arg0->toString(exec); … … 98 98 return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage())); 99 99 100 static_cast<RegExp Imp*>(thisObj)->setRegExp(regExp.release());101 static_cast<RegExp Imp*>(thisObj)->setLastIndex(0);100 static_cast<RegExpObject*>(thisObj)->setRegExp(regExp.release()); 101 static_cast<RegExpObject*>(thisObj)->setLastIndex(0); 102 102 return jsUndefined(); 103 103 } … … 105 105 JSValue* regExpProtoFuncToString(ExecState* exec, JSObject* thisObj, const List&) 106 106 { 107 if (!thisObj->inherits(&RegExp Imp::info)) {107 if (!thisObj->inherits(&RegExpObject::info)) { 108 108 if (thisObj->inherits(&RegExpPrototype::info)) 109 109 return jsString("//"); … … 121 121 } 122 122 123 // ------------------------------ RegExp Imp------------------------------------124 125 const ClassInfo RegExp Imp::info = { "RegExp", 0, 0, ExecState::RegExpImpTable };123 // ------------------------------ RegExpObject ------------------------------------ 124 125 const ClassInfo RegExpObject::info = { "RegExp", 0, 0, ExecState::regExpTable }; 126 126 127 127 /* Source for regexp_object.lut.h 128 @begin RegExpImpTable 5129 global RegExp Imp::Global DontDelete|ReadOnly|DontEnum130 ignoreCase RegExp Imp::IgnoreCase DontDelete|ReadOnly|DontEnum131 multiline RegExp Imp::Multiline DontDelete|ReadOnly|DontEnum132 source RegExp Imp::Source DontDelete|ReadOnly|DontEnum133 lastIndex RegExp Imp::LastIndex DontDelete|DontEnum128 @begin regExpTable 5 129 global RegExpObject::Global DontDelete|ReadOnly|DontEnum 130 ignoreCase RegExpObject::IgnoreCase DontDelete|ReadOnly|DontEnum 131 multiline RegExpObject::Multiline DontDelete|ReadOnly|DontEnum 132 source RegExpObject::Source DontDelete|ReadOnly|DontEnum 133 lastIndex RegExpObject::LastIndex DontDelete|DontEnum 134 134 @end 135 135 */ 136 136 137 RegExp Imp::RegExpImp(RegExpPrototype* regexpProto, PassRefPtr<RegExp> regExp)137 RegExpObject::RegExpObject(RegExpPrototype* regexpProto, PassRefPtr<RegExp> regExp) 138 138 : JSObject(regexpProto) 139 139 , m_regExp(regExp) … … 142 142 } 143 143 144 RegExp Imp::~RegExpImp()145 { 146 } 147 148 bool RegExp Imp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)149 { 150 return getStaticValueSlot<RegExp Imp, JSObject>(exec, ExecState::RegExpImpTable(exec), this, propertyName, slot);151 } 152 153 JSValue* RegExp Imp::getValueProperty(ExecState*, int token) const144 RegExpObject::~RegExpObject() 145 { 146 } 147 148 bool RegExpObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 149 { 150 return getStaticValueSlot<RegExpObject, JSObject>(exec, ExecState::regExpTable(exec), this, propertyName, slot); 151 } 152 153 JSValue* RegExpObject::getValueProperty(ExecState*, int token) const 154 154 { 155 155 switch (token) { … … 170 170 } 171 171 172 void RegExp Imp::put(ExecState* exec, const Identifier& propertyName, JSValue* value)173 { 174 lookupPut<RegExp Imp, JSObject>(exec, propertyName, value, ExecState::RegExpImpTable(exec), this);175 } 176 177 void RegExp Imp::putValueProperty(ExecState* exec, int token, JSValue* value)172 void RegExpObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value) 173 { 174 lookupPut<RegExpObject, JSObject>(exec, propertyName, value, ExecState::regExpTable(exec), this); 175 } 176 177 void RegExpObject::putValueProperty(ExecState* exec, int token, JSValue* value) 178 178 { 179 179 UNUSED_PARAM(token); … … 182 182 } 183 183 184 bool RegExp Imp::match(ExecState* exec, const List& args)185 { 186 RegExp ObjectImp* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();184 bool RegExpObject::match(ExecState* exec, const List& args) 185 { 186 RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor(); 187 187 188 188 UString input; … … 219 219 } 220 220 221 JSValue* RegExp Imp::test(ExecState* exec, const List& args)221 JSValue* RegExpObject::test(ExecState* exec, const List& args) 222 222 { 223 223 return jsBoolean(match(exec, args)); 224 224 } 225 225 226 JSValue* RegExp Imp::exec(ExecState* exec, const List& args)226 JSValue* RegExpObject::exec(ExecState* exec, const List& args) 227 227 { 228 228 return match(exec, args) … … 231 231 } 232 232 233 CallType RegExp Imp::getCallData(CallData&)233 CallType RegExpObject::getCallData(CallData&) 234 234 { 235 235 return CallTypeNative; 236 236 } 237 237 238 JSValue* RegExp Imp::callAsFunction(ExecState* exec, JSObject*, const List& args)239 { 240 return RegExp Imp::exec(exec, args);241 } 242 243 // ------------------------------ RegExp ObjectImp------------------------------244 245 const ClassInfo RegExp ObjectImp::info = { "Function", &InternalFunctionImp::info, 0, ExecState::RegExpObjectImpTable };238 JSValue* RegExpObject::callAsFunction(ExecState* exec, JSObject*, const List& args) 239 { 240 return RegExpObject::exec(exec, args); 241 } 242 243 // ------------------------------ RegExpConstructor ------------------------------ 244 245 const ClassInfo RegExpConstructor::info = { "Function", &InternalFunction::info, 0, ExecState::regExpConstructorTable }; 246 246 247 247 /* Source for regexp_object.lut.h 248 @begin RegExpObjectImpTable 21249 input RegExp ObjectImp::Input None250 $_ RegExp ObjectImp::Input DontEnum251 multiline RegExp ObjectImp::Multiline None252 $* RegExp ObjectImp::Multiline DontEnum253 lastMatch RegExp ObjectImp::LastMatch DontDelete|ReadOnly254 $& RegExp ObjectImp::LastMatch DontDelete|ReadOnly|DontEnum255 lastParen RegExp ObjectImp::LastParen DontDelete|ReadOnly256 $+ RegExp ObjectImp::LastParen DontDelete|ReadOnly|DontEnum257 leftContext RegExp ObjectImp::LeftContext DontDelete|ReadOnly258 $` RegExp ObjectImp::LeftContext DontDelete|ReadOnly|DontEnum259 rightContext RegExp ObjectImp::RightContext DontDelete|ReadOnly260 $' RegExp ObjectImp::RightContext DontDelete|ReadOnly|DontEnum261 $1 RegExp ObjectImp::Dollar1 DontDelete|ReadOnly262 $2 RegExp ObjectImp::Dollar2 DontDelete|ReadOnly263 $3 RegExp ObjectImp::Dollar3 DontDelete|ReadOnly264 $4 RegExp ObjectImp::Dollar4 DontDelete|ReadOnly265 $5 RegExp ObjectImp::Dollar5 DontDelete|ReadOnly266 $6 RegExp ObjectImp::Dollar6 DontDelete|ReadOnly267 $7 RegExp ObjectImp::Dollar7 DontDelete|ReadOnly268 $8 RegExp ObjectImp::Dollar8 DontDelete|ReadOnly269 $9 RegExp ObjectImp::Dollar9 DontDelete|ReadOnly248 @begin regExpConstructorTable 21 249 input RegExpConstructor::Input None 250 $_ RegExpConstructor::Input DontEnum 251 multiline RegExpConstructor::Multiline None 252 $* RegExpConstructor::Multiline DontEnum 253 lastMatch RegExpConstructor::LastMatch DontDelete|ReadOnly 254 $& RegExpConstructor::LastMatch DontDelete|ReadOnly|DontEnum 255 lastParen RegExpConstructor::LastParen DontDelete|ReadOnly 256 $+ RegExpConstructor::LastParen DontDelete|ReadOnly|DontEnum 257 leftContext RegExpConstructor::LeftContext DontDelete|ReadOnly 258 $` RegExpConstructor::LeftContext DontDelete|ReadOnly|DontEnum 259 rightContext RegExpConstructor::RightContext DontDelete|ReadOnly 260 $' RegExpConstructor::RightContext DontDelete|ReadOnly|DontEnum 261 $1 RegExpConstructor::Dollar1 DontDelete|ReadOnly 262 $2 RegExpConstructor::Dollar2 DontDelete|ReadOnly 263 $3 RegExpConstructor::Dollar3 DontDelete|ReadOnly 264 $4 RegExpConstructor::Dollar4 DontDelete|ReadOnly 265 $5 RegExpConstructor::Dollar5 DontDelete|ReadOnly 266 $6 RegExpConstructor::Dollar6 DontDelete|ReadOnly 267 $7 RegExpConstructor::Dollar7 DontDelete|ReadOnly 268 $8 RegExpConstructor::Dollar8 DontDelete|ReadOnly 269 $9 RegExpConstructor::Dollar9 DontDelete|ReadOnly 270 270 @end 271 271 */ 272 272 273 struct RegExp ObjectImpPrivate {273 struct RegExpConstructorPrivate { 274 274 // Global search cache / settings 275 RegExp ObjectImpPrivate() : lastNumSubPatterns(0), multiline(false) { }275 RegExpConstructorPrivate() : lastNumSubPatterns(0), multiline(false) { } 276 276 UString lastInput; 277 277 OwnArrayPtr<int> lastOvector; … … 280 280 }; 281 281 282 RegExp ObjectImp::RegExpObjectImp(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto)283 : InternalFunction Imp(funcProto, "RegExp")284 , d(new RegExp ObjectImpPrivate)282 RegExpConstructor::RegExpConstructor(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto) 283 : InternalFunction(funcProto, "RegExp") 284 , d(new RegExpConstructorPrivate) 285 285 { 286 286 // ECMA 15.10.5.1 RegExp.prototype … … 296 296 e.g., RegExp.lastMatch and RegExp.leftParen. 297 297 */ 298 void RegExp ObjectImp::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector)298 void RegExpConstructor::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector) 299 299 { 300 300 OwnArrayPtr<int> tmpOvector; … … 317 317 class RegExpMatchesArray : public JSArray { 318 318 public: 319 RegExpMatchesArray(ExecState*, RegExp ObjectImpPrivate*);319 RegExpMatchesArray(ExecState*, RegExpConstructorPrivate*); 320 320 321 321 virtual ~RegExpMatchesArray(); … … 333 333 }; 334 334 335 RegExpMatchesArray::RegExpMatchesArray(ExecState* exec, RegExp ObjectImpPrivate* data)335 RegExpMatchesArray::RegExpMatchesArray(ExecState* exec, RegExpConstructorPrivate* data) 336 336 : JSArray(exec->lexicalGlobalObject()->arrayPrototype(), data->lastNumSubPatterns + 1) 337 337 { 338 RegExp ObjectImpPrivate* d = new RegExpObjectImpPrivate;338 RegExpConstructorPrivate* d = new RegExpConstructorPrivate; 339 339 d->lastInput = data->lastInput; 340 340 d->lastNumSubPatterns = data->lastNumSubPatterns; … … 349 349 RegExpMatchesArray::~RegExpMatchesArray() 350 350 { 351 delete static_cast<RegExp ObjectImpPrivate*>(lazyCreationData());351 delete static_cast<RegExpConstructorPrivate*>(lazyCreationData()); 352 352 } 353 353 354 354 void RegExpMatchesArray::fillArrayInstance(ExecState* exec) 355 355 { 356 RegExp ObjectImpPrivate* d = static_cast<RegExpObjectImpPrivate*>(lazyCreationData());356 RegExpConstructorPrivate* d = static_cast<RegExpConstructorPrivate*>(lazyCreationData()); 357 357 ASSERT(d); 358 358 … … 371 371 } 372 372 373 JSObject* RegExp ObjectImp::arrayOfMatches(ExecState* exec) const373 JSObject* RegExpConstructor::arrayOfMatches(ExecState* exec) const 374 374 { 375 375 return new RegExpMatchesArray(exec, d.get()); 376 376 } 377 377 378 JSValue* RegExp ObjectImp::getBackref(unsigned i) const378 JSValue* RegExpConstructor::getBackref(unsigned i) const 379 379 { 380 380 if (d->lastOvector && i <= d->lastNumSubPatterns) … … 383 383 } 384 384 385 JSValue* RegExp ObjectImp::getLastParen() const385 JSValue* RegExpConstructor::getLastParen() const 386 386 { 387 387 unsigned i = d->lastNumSubPatterns; … … 393 393 } 394 394 395 JSValue *RegExp ObjectImp::getLeftContext() const395 JSValue *RegExpConstructor::getLeftContext() const 396 396 { 397 397 if (d->lastOvector) … … 400 400 } 401 401 402 JSValue *RegExp ObjectImp::getRightContext() const402 JSValue *RegExpConstructor::getRightContext() const 403 403 { 404 404 if (d->lastOvector) { … … 409 409 } 410 410 411 bool RegExp ObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)412 { 413 return getStaticValueSlot<RegExp ObjectImp, InternalFunctionImp>(exec, ExecState::RegExpObjectImpTable(exec), this, propertyName, slot);414 } 415 416 JSValue *RegExp ObjectImp::getValueProperty(ExecState*, int token) const411 bool RegExpConstructor::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) 412 { 413 return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec), this, propertyName, slot); 414 } 415 416 JSValue *RegExpConstructor::getValueProperty(ExecState*, int token) const 417 417 { 418 418 switch (token) { … … 454 454 } 455 455 456 void RegExp ObjectImp::put(ExecState *exec, const Identifier &propertyName, JSValue *value)457 { 458 lookupPut<RegExp ObjectImp, InternalFunctionImp>(exec, propertyName, value, ExecState::RegExpObjectImpTable(exec), this);459 } 460 461 void RegExp ObjectImp::putValueProperty(ExecState *exec, int token, JSValue *value)456 void RegExpConstructor::put(ExecState *exec, const Identifier &propertyName, JSValue *value) 457 { 458 lookupPut<RegExpConstructor, InternalFunction>(exec, propertyName, value, ExecState::regExpConstructorTable(exec), this); 459 } 460 461 void RegExpConstructor::putValueProperty(ExecState *exec, int token, JSValue *value) 462 462 { 463 463 switch (token) { … … 473 473 } 474 474 475 ConstructType RegExp ObjectImp::getConstructData(ConstructData&)475 ConstructType RegExpConstructor::getConstructData(ConstructData&) 476 476 { 477 477 return ConstructTypeNative; … … 479 479 480 480 // ECMA 15.10.4 481 JSObject *RegExp ObjectImp::construct(ExecState *exec, const List &args)481 JSObject *RegExpConstructor::construct(ExecState *exec, const List &args) 482 482 { 483 483 JSValue* arg0 = args[0]; 484 484 JSValue* arg1 = args[1]; 485 485 486 if (arg0->isObject(&RegExp Imp::info)) {486 if (arg0->isObject(&RegExpObject::info)) { 487 487 if (!arg1->isUndefined()) 488 488 return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another."); … … 495 495 RefPtr<RegExp> regExp = RegExp::create(pattern, flags); 496 496 return regExp->isValid() 497 ? new RegExp Imp(exec->lexicalGlobalObject()->regExpPrototype(), regExp.release())497 ? new RegExpObject(exec->lexicalGlobalObject()->regExpPrototype(), regExp.release()) 498 498 : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage())); 499 499 } 500 500 501 501 // ECMA 15.10.3 502 JSValue *RegExp ObjectImp::callAsFunction(ExecState *exec, JSObject * /*thisObj*/, const List &args)502 JSValue *RegExpConstructor::callAsFunction(ExecState *exec, JSObject * /*thisObj*/, const List &args) 503 503 { 504 504 return construct(exec, args); 505 505 } 506 506 507 const UString& RegExp ObjectImp::input() const507 const UString& RegExpConstructor::input() const 508 508 { 509 509 // Can detect a distinct initial state that is invisible to JavaScript, by checking for null
Note:
See TracChangeset
for help on using the changeset viewer.