From 463ed070beb7cc5ad15692b6ea2cc403695b2a49 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 12 Dec 2012 08:28:08 +0100 Subject: [PATCH] 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 --- qmljs_engine.cpp | 10 ++++++++-- qmljs_engine.h | 3 ++- qv4ecmaobjects.cpp | 12 +++++------- 3 files changed, 15 insertions(+), 10 deletions(-) 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; } -- 2.7.4