return new (memoryManager) DateCtor(ctx);
}
-Object *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
+RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
{
bool global = (flags & IR::RegExp::RegExp_Global);
QRegularExpression::PatternOptions options = 0;
if (flags & IR::RegExp::RegExp_Multiline)
options |= QRegularExpression::MultilineOption;
- Object *object = new (memoryManager) RegExpObject(QRegularExpression(pattern, options), global);
+ QRegularExpression re(pattern, options);
+ return newRegExpObject(re, global);
+}
+
+RegExpObject *ExecutionEngine::newRegExpObject(const QRegularExpression &re, bool global)
+{
+ RegExpObject *object = new (memoryManager) RegExpObject(re, global);
object->prototype = regExpPrototype;
return object;
}
Object *newDateObject(const Value &value);
FunctionObject *newDateCtor(ExecutionContext *ctx);
- Object *newRegExpObject(const QString &pattern, int flags);
+ RegExpObject *newRegExpObject(const QString &pattern, int flags);
+ RegExpObject *newRegExpObject(const QRegularExpression &re, bool global);
FunctionObject *newRegExpCtor(ExecutionContext *ctx);
Object *newErrorObject(const Value &value);
Value RegExpCtor::construct(ExecutionContext *ctx)
{
-// if (ctx->argumentCount > 2) {
-// ctx->throwTypeError();
-// return;
-// }
-
Value r = ctx->argumentCount > 0 ? ctx->argument(0) : Value::undefinedValue();
Value f = ctx->argumentCount > 1 ? ctx->argument(1) : Value::undefinedValue();
if (RegExpObject *re = r.asRegExpObject()) {
if (!f.isUndefined())
ctx->throwTypeError();
- return Value::fromObject(new (ctx->engine->memoryManager) RegExpObject(re->value, false));
+ RegExpObject *o = ctx->engine->newRegExpObject(re->value, re->global);
+ ctx->thisObject = Value::fromObject(o);
+ return ctx->thisObject;
}
if (r.isUndefined())
if (!re.isValid())
ctx->throwTypeError();
- ctx->thisObject = Value::fromObject(new (ctx->engine->memoryManager) RegExpObject(re, global));
+ RegExpObject *o = ctx->engine->newRegExpObject(re, global);
+ ctx->thisObject = Value::fromObject(o);
return ctx->thisObject;
}