Changeset 27303 in webkit for trunk/JavaScriptCore/kjs/regexp_object.cpp
- Timestamp:
- Oct 31, 2007, 1:29:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp_object.cpp
r27011 r27303 49 49 : JSObject(objProto) 50 50 { 51 static const Identifier* compilePropertyName = new Identifier("compile"); 51 52 static const Identifier* execPropertyName = new Identifier("exec"); 52 53 static const Identifier* testPropertyName = new Identifier("test"); 53 54 55 putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Compile, 0, *compilePropertyName), DontEnum); 54 56 putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Exec, 0, *execPropertyName), DontEnum); 55 57 putDirectFunction(new RegExpProtoFunc(exec, funcProto, RegExpProtoFunc::Test, 0, *testPropertyName), DontEnum); … … 120 122 } 121 123 break; 124 case Compile: 125 { 126 UString source; 127 bool global = false; 128 bool ignoreCase = false; 129 bool multiline = false; 130 if (args.size() > 0) { 131 if (args[0]->isObject(&RegExpImp::info)) { 132 if (args.size() != 1) 133 return throwError(exec, TypeError, "cannot supply flags when constructing one RegExp from another."); 134 135 // Flags are mirrored on the JS object and in the implementation, while source is only preserved on the JS object. 136 RegExp* rhsRegExp = static_cast<RegExpImp*>(args[0])->regExp(); 137 global = rhsRegExp->flags() & RegExp::Global; 138 ignoreCase = rhsRegExp->flags() & RegExp::IgnoreCase; 139 multiline = rhsRegExp->flags() & RegExp::Multiline; 140 source = static_cast<RegExpImp*>(args[0])->get(exec, exec->propertyNames().source)->toString(exec); 141 } else 142 source = args[0]->toString(exec); 143 144 if (!args[1]->isUndefined()) { 145 UString flags = args[1]->toString(exec); 146 147 global = (flags.find("g") >= 0); 148 ignoreCase = (flags.find("i") >= 0); 149 multiline = (flags.find("m") >= 0); 150 } 151 } 152 153 int reflags = RegExp::None; 154 if (global) 155 reflags |= RegExp::Global; 156 if (ignoreCase) 157 reflags |= RegExp::IgnoreCase; 158 if (multiline) 159 reflags |= RegExp::Multiline; 160 161 OwnPtr<RegExp> newRegExp(new RegExp(source, reflags)); 162 if (!newRegExp->isValid()) 163 return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(newRegExp->errorMessage())); 164 165 thisObj->putDirect(exec->propertyNames().global, jsBoolean(global), DontDelete | ReadOnly | DontEnum); 166 thisObj->putDirect(exec->propertyNames().ignoreCase, jsBoolean(ignoreCase), DontDelete | ReadOnly | DontEnum); 167 thisObj->putDirect(exec->propertyNames().multiline, jsBoolean(multiline), DontDelete | ReadOnly | DontEnum); 168 thisObj->putDirect(exec->propertyNames().source, jsString(source), DontDelete | ReadOnly | DontEnum); 169 thisObj->putDirect(exec->propertyNames().lastIndex, jsNumber(0), DontDelete | DontEnum); 170 171 static_cast<RegExpImp*>(thisObj)->setRegExp(newRegExp.release()); 172 return jsUndefined(); 173 } 122 174 case ToString: 123 175 UString result = "/" + thisObj->get(exec, exec->propertyNames().source)->toString(exec) + "/";
Note:
See TracChangeset
for help on using the changeset viewer.