Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/regexp_object.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp_object.cpp
r10076 r10084 46 46 : ObjectImp(objProto) 47 47 { 48 Value protect(this);49 48 setInternalValue(String("")); 50 49 … … 64 63 : InternalFunctionImp(funcProto), id(i) 65 64 { 66 Value protect(this);67 65 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 68 66 } … … 73 71 } 74 72 75 Value RegExpProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)76 { 77 if (!thisObj .inherits(&RegExpImp::info)) {78 if (thisObj .inherits(&RegExpPrototypeImp::info)) {73 ValueImp *RegExpProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 74 { 75 if (!thisObj->inherits(&RegExpImp::info)) { 76 if (thisObj->inherits(&RegExpPrototypeImp::info)) { 79 77 switch (id) { 80 78 case ToString: return String("//"); 81 79 } 82 80 } 83 Object 81 ObjectImp *err = Error::create(exec,TypeError); 84 82 exec->setException(err); 85 83 return err; 86 84 } 87 85 88 RegExpImp *reimp = static_cast<RegExpImp*>(thisObj .imp());86 RegExpImp *reimp = static_cast<RegExpImp*>(thisObj); 89 87 RegExp *re = reimp->regExp(); 90 String s;88 UString s; 91 89 UString str; 92 90 switch (id) { … … 94 92 case Test: 95 93 { 96 s = args[0] .toString(exec);97 int length = s. value().size();98 Value lastIndex = thisObj.get(exec,"lastIndex");99 int i = lastIndex .isNull() ? 0 : lastIndex.toInt32(exec);100 bool globalFlag = thisObj .get(exec,"global").toBoolean(exec);94 s = args[0]->toString(exec); 95 int length = s.size(); 96 ValueImp *lastIndex = thisObj->get(exec,"lastIndex"); 97 int i = lastIndex->toInt32(exec); 98 bool globalFlag = thisObj->get(exec,"global")->toBoolean(exec); 101 99 if (!globalFlag) 102 100 i = 0; 103 101 if (i < 0 || i > length) { 104 thisObj .put(exec,"lastIndex", Number(0), DontDelete | DontEnum);102 thisObj->put(exec,"lastIndex", Number(0), DontDelete | DontEnum); 105 103 if (id == Test) 106 104 return Boolean(false); … … 108 106 return Null(); 109 107 } 110 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp() .imp());111 int **ovector = regExpObj->registerRegexp( re, s .value());112 113 str = re->match(s .value(), i, 0L, ovector);108 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 109 int **ovector = regExpObj->registerRegexp( re, s ); 110 111 str = re->match(s, i, 0L, ovector); 114 112 regExpObj->setSubPatterns(re->subPatterns()); 115 113 … … 120 118 { 121 119 if (globalFlag) 122 thisObj .put(exec,"lastIndex",Number(0), DontDelete | DontEnum);120 thisObj->put(exec,"lastIndex",Number(0), DontDelete | DontEnum); 123 121 return Null(); 124 122 } … … 126 124 { 127 125 if (globalFlag) 128 thisObj .put(exec,"lastIndex",Number( (*ovector)[1] ), DontDelete | DontEnum);126 thisObj->put(exec,"lastIndex",Number( (*ovector)[1] ), DontDelete | DontEnum); 129 127 return regExpObj->arrayOfMatches(exec,str); 130 128 } … … 132 130 break; 133 131 case ToString: 134 s = thisObj .get(exec,"source").toString(exec);132 s = thisObj->get(exec,"source")->toString(exec); 135 133 str = "/"; 136 str += s .value();134 str += s; 137 135 str += "/"; 138 if (thisObj .get(exec,"global").toBoolean(exec)) {136 if (thisObj->get(exec,"global")->toBoolean(exec)) { 139 137 str += "g"; 140 138 } 141 if (thisObj .get(exec,"ignoreCase").toBoolean(exec)) {139 if (thisObj->get(exec,"ignoreCase")->toBoolean(exec)) { 142 140 str += "i"; 143 141 } 144 if (thisObj .get(exec,"multiline").toBoolean(exec)) {142 if (thisObj->get(exec,"multiline")->toBoolean(exec)) { 145 143 str += "m"; 146 144 } … … 173 171 : InternalFunctionImp(funcProto), lastOvector(0L), lastNrSubPatterns(0) 174 172 { 175 Value protect(this);176 173 // ECMA 15.10.5.1 RegExp.prototype 177 174 putDirect(prototypePropertyName, regProto, DontEnum|DontDelete|ReadOnly); 178 175 179 176 // no. of arguments for constructor 180 putDirect(lengthPropertyName, NumberImp::two(), ReadOnly|DontDelete|DontEnum);177 putDirect(lengthPropertyName, jsTwo(), ReadOnly|DontDelete|DontEnum); 181 178 } 182 179 … … 195 192 } 196 193 197 Object 194 ObjectImp *RegExpObjectImp::arrayOfMatches(ExecState *exec, const UString &result) const 198 195 { 199 196 List list; … … 205 202 int start = lastOvector[2*i]; 206 203 if (start == -1) 207 list.append( UndefinedImp::staticUndefined);204 list.append(jsUndefined()); 208 205 else { 209 206 UString substring = lastString.substr( start, lastOvector[2*i+1] - start ); … … 211 208 } 212 209 } 213 Object arr = exec->lexicalInterpreter()->builtinArray().construct(exec, list);214 arr .put(exec, "index", Number(lastOvector[0]));215 arr .put(exec, "input", String(lastString));210 ObjectImp *arr = exec->lexicalInterpreter()->builtinArray()->construct(exec, list); 211 arr->put(exec, "index", Number(lastOvector[0])); 212 arr->put(exec, "input", String(lastString)); 216 213 return arr; 217 214 } 218 215 219 Value 216 ValueImp *RegExpObjectImp::backrefGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 220 217 { 221 218 RegExpObjectImp *thisObj = static_cast<RegExpObjectImp *>(slot.slotBase()); … … 254 251 255 252 // ECMA 15.10.4 256 Object 257 { 258 Object o = Object::dynamicCast(args[0]);259 if ( !o.isNull() && o.inherits(&RegExpImp::info)) {260 if ( args[1].type() != UndefinedType) {261 Object 253 ObjectImp *RegExpObjectImp::construct(ExecState *exec, const List &args) 254 { 255 ObjectImp *o = args[0]->getObject(); 256 if (o && o->inherits(&RegExpImp::info)) { 257 if (!args[1]->isUndefined()) { 258 ObjectImp *err = Error::create(exec,TypeError); 262 259 exec->setException(err); 263 260 return err; … … 266 263 } 267 264 268 UString p = args[0] .type() == UndefinedType ? UString("") : args[0].toString(exec);269 UString flags = args[1] .type() == UndefinedType ? UString("") : args[1].toString(exec);270 271 RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->lexicalInterpreter()->builtinRegExpPrototype() .imp());265 UString p = args[0]->isUndefined() ? UString("") : args[0]->toString(exec); 266 UString flags = args[1]->isUndefined() ? UString("") : args[1]->toString(exec); 267 268 RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->lexicalInterpreter()->builtinRegExpPrototype()); 272 269 RegExpImp *dat = new RegExpImp(proto); 273 Object obj(dat); // protect from GC274 270 275 271 bool global = (flags.find("g") >= 0); … … 278 274 // TODO: throw a syntax error on invalid flags 279 275 280 dat->putDirect("global", global ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);281 dat->putDirect("ignoreCase", ignoreCase ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);282 dat->putDirect("multiline", multiline ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);283 284 dat->putDirect("source", new StringImp(p), DontDelete | ReadOnly | DontEnum);285 dat->putDirect("lastIndex", NumberImp::zero(), DontDelete | DontEnum);276 dat->putDirect("global", jsBoolean(global), DontDelete | ReadOnly | DontEnum); 277 dat->putDirect("ignoreCase", jsBoolean(ignoreCase), DontDelete | ReadOnly | DontEnum); 278 dat->putDirect("multiline", jsBoolean(multiline), DontDelete | ReadOnly | DontEnum); 279 280 dat->putDirect("source", jsString(p), DontDelete | ReadOnly | DontEnum); 281 dat->putDirect("lastIndex", jsZero(), DontDelete | DontEnum); 286 282 287 283 int reflags = RegExp::None; … … 294 290 dat->setRegExp(new RegExp(p, reflags)); 295 291 296 return obj;292 return dat; 297 293 } 298 294 … … 303 299 304 300 // ECMA 15.10.3 305 Value RegExpObjectImp::call(ExecState *exec, Object &/*thisObj*/,301 ValueImp *RegExpObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, 306 302 const List &args) 307 303 {
Note:
See TracChangeset
for help on using the changeset viewer.