// ECMA 15.10.4 Object RegExpObjectImp::construct(ExecState *exec, const List &args) { UString p = args.isEmpty() ? UString("") : args[0].toString(exec); UString flags = args[1].toString(exec); RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->interpreter()->builtinRegExpPrototype().imp()); RegExpImp *dat = new RegExpImp(proto); Object obj(dat); // protect from GC bool global = (flags.find("g") >= 0); bool ignoreCase = (flags.find("i") >= 0); bool multiline = (flags.find("m") >= 0); // TODO: throw a syntax error on invalid flags dat->putDirect("global", global ? BooleanImp::staticTrue : BooleanImp::staticFalse); dat->putDirect("ignoreCase", ignoreCase ? BooleanImp::staticTrue : BooleanImp::staticFalse); dat->putDirect("multiline", multiline ? BooleanImp::staticTrue : BooleanImp::staticFalse); dat->putDirect("source", new StringImp(p)); dat->putDirect("lastIndex", NumberImp::zero(), DontDelete | DontEnum); int reflags = RegExp::None; if (global) reflags |= RegExp::Global; if (ignoreCase) reflags |= RegExp::IgnoreCase; if (multiline) reflags |= RegExp::Multiline; dat->setRegExp(new RegExp(p, reflags)); return obj; }
// ECMA 15.10.4 JSObject *RegExpObjectImp::construct(ExecState *exec, const List &args) { JSObject *o = args[0]->getObject(); if (o && o->inherits(&RegExpImp::info)) { if (!args[1]->isUndefined()) return throwError(exec, TypeError); return o; } UString p = args[0]->isUndefined() ? UString("") : args[0]->toString(exec); UString flags = args[1]->isUndefined() ? UString("") : args[1]->toString(exec); RegExpPrototype *proto = static_cast<RegExpPrototype*>(exec->lexicalInterpreter()->builtinRegExpPrototype()); RegExpImp *dat = new RegExpImp(proto); bool global = (flags.find("g") >= 0); bool ignoreCase = (flags.find("i") >= 0); bool multiline = (flags.find("m") >= 0); dat->putDirect(exec->propertyNames().global, jsBoolean(global), DontDelete | ReadOnly | DontEnum); dat->putDirect(exec->propertyNames().ignoreCase, jsBoolean(ignoreCase), DontDelete | ReadOnly | DontEnum); dat->putDirect(exec->propertyNames().multiline, jsBoolean(multiline), DontDelete | ReadOnly | DontEnum); dat->putDirect(exec->propertyNames().source, jsString(p), DontDelete | ReadOnly | DontEnum); dat->putDirect(exec->propertyNames().lastIndex, jsNumber(0), DontDelete | DontEnum); int reflags = RegExp::None; if (global) reflags |= RegExp::Global; if (ignoreCase) reflags |= RegExp::IgnoreCase; if (multiline) reflags |= RegExp::Multiline; OwnPtr<RegExp> re(new RegExp(p, reflags)); if (!re->isValid()) return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(re->errorMessage())); dat->setRegExp(re.release()); return dat; }