From: Lars Knoll Date: Wed, 12 Dec 2012 07:28:08 +0000 (+0100) Subject: Properly set the prototype for regexp objects X-Git-Tag: upstream/5.2.1~669^2~659^2~717 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=463ed070beb7cc5ad15692b6ea2cc403695b2a49;p=platform%2Fupstream%2Fqtdeclarative.git Properly set the prototype for regexp objects Clean up the code, so that regexp's get instantiated by the ExecutionEngine Change-Id: Iacc8d9fee0427342156747d6e8814d7660bdbb1a Reviewed-by: Simon Hausmann --- diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index a29088f..6e837e2 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -357,7 +357,7 @@ FunctionObject *ExecutionEngine::newDateCtor(ExecutionContext *ctx) 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; @@ -366,7 +366,13 @@ Object *ExecutionEngine::newRegExpObject(const QString &pattern, int flags) 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; } diff --git a/qmljs_engine.h b/qmljs_engine.h index eef62a3..bcaff09 100644 --- a/qmljs_engine.h +++ b/qmljs_engine.h @@ -193,7 +193,8 @@ struct ExecutionEngine 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); diff --git a/qv4ecmaobjects.cpp b/qv4ecmaobjects.cpp index fb3f6d7..82d20f7 100644 --- a/qv4ecmaobjects.cpp +++ b/qv4ecmaobjects.cpp @@ -2726,18 +2726,15 @@ RegExpCtor::RegExpCtor(ExecutionContext *scope) 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()) @@ -2767,7 +2764,8 @@ Value RegExpCtor::construct(ExecutionContext *ctx) 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; }