Properly set the prototype for regexp objects
authorLars Knoll <lars.knoll@digia.com>
Wed, 12 Dec 2012 07:28:08 +0000 (08:28 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 12 Dec 2012 08:09:32 +0000 (09:09 +0100)
Clean up the code, so that regexp's get instantiated by
the ExecutionEngine

Change-Id: Iacc8d9fee0427342156747d6e8814d7660bdbb1a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_engine.cpp
qmljs_engine.h
qv4ecmaobjects.cpp

index a29088f..6e837e2 100644 (file)
@@ -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;
 }
index eef62a3..bcaff09 100644 (file)
@@ -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);
index fb3f6d7..82d20f7 100644 (file)
@@ -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;
 }