Implement RegExp.prototype.compile
authorLars Knoll <lars.knoll@digia.com>
Mon, 21 Jan 2013 17:43:03 +0000 (18:43 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 21 Jan 2013 18:20:52 +0000 (19:20 +0100)
This method is a non standard extension, but supported by
all engines, and even used in the test suite.

Change-Id: Ie75c840d4da13bd1a62aa7567e8ea2737d31d33e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_objects.h
qv4ecmaobjects.cpp
qv4ecmaobjects_p.h
tests/TestExpectations

index 429cc0a..27a9e0b 100644 (file)
@@ -345,7 +345,7 @@ struct IsFiniteFunction: FunctionObject
 struct RegExpObject: Object {
     RefPtr<RegExp> value;
     PropertyDescriptor *lastIndexProperty;
-    const bool global;
+    bool global;
     RegExpObject(ExecutionEngine *engine, PassRefPtr<RegExp> value, bool global);
     virtual QString className() { return QStringLiteral("RegExp"); }
     virtual RegExpObject *asRegExpObject() { return this; }
index 80f27b4..c9976cb 100644 (file)
@@ -1670,6 +1670,7 @@ void RegExpPrototype::init(ExecutionContext *ctx, const Value &ctor)
     defineDefaultProperty(ctx, QStringLiteral("exec"), method_exec, 1);
     defineDefaultProperty(ctx, QStringLiteral("test"), method_test, 1);
     defineDefaultProperty(ctx, QStringLiteral("toString"), method_toString, 0);
+    defineDefaultProperty(ctx, QStringLiteral("compile"), method_compile, 2);
 }
 
 Value RegExpPrototype::method_exec(ExecutionContext *ctx)
@@ -1737,6 +1738,19 @@ Value RegExpPrototype::method_toString(ExecutionContext *ctx)
     return Value::fromString(ctx, result);
 }
 
+Value RegExpPrototype::method_compile(ExecutionContext *ctx)
+{
+    RegExpObject *r = ctx->thisObject.asRegExpObject();
+    if (!r)
+        ctx->throwTypeError();
+
+    RegExpObject *re = ctx->engine->regExpCtor.asFunctionObject()->construct(ctx, ctx->arguments, ctx->argumentCount).asRegExpObject();
+
+    r->value = re->value;
+    r->global = re->global;
+    return Value::undefinedValue();
+}
+
 //
 // ErrorCtr
 //
index 46f6140..6ee8e0d 100644 (file)
@@ -199,6 +199,7 @@ struct RegExpPrototype: RegExpObject
     static Value method_exec(ExecutionContext *ctx);
     static Value method_test(ExecutionContext *ctx);
     static Value method_toString(ExecutionContext *ctx);
+    static Value method_compile(ExecutionContext *ctx);
 };
 
 struct ErrorCtor: FunctionObject
index e7e8a56..8143b46 100644 (file)
@@ -514,7 +514,6 @@ S15.1.3.2_A5.3 failing
 15.2.3.3-4-11 failing
 15.2.3.3-4-12 failing
 15.2.3.3-4-13 failing
-15.2.3.3-4-164 failing
 15.2.3.3-4-51 failing
 15.2.3.3-4-9 failing
 15.2.3.3-4-90 failing