arrayPrototype = new ArrayPrototype();
datePrototype = new DatePrototype();
functionPrototype = new FunctionPrototype(rootContext);
+ regExpPrototype = new RegExpPrototype();
stringPrototype->prototype = objectPrototype;
numberPrototype->prototype = objectPrototype;
arrayPrototype->prototype = objectPrototype;
datePrototype->prototype = objectPrototype;
functionPrototype->prototype = objectPrototype;
-
- Value objectCtor = Value::fromObject(new ObjectCtor(rootContext));
- Value stringCtor = Value::fromObject(new StringCtor(rootContext));
- Value numberCtor = Value::fromObject(new NumberCtor(rootContext));
- Value booleanCtor = Value::fromObject(new BooleanCtor(rootContext));
- Value arrayCtor = Value::fromObject(new ArrayCtor(rootContext));
- Value functionCtor = Value::fromObject(new FunctionCtor(rootContext));
- Value dateCtor = Value::fromObject(new DateCtor(rootContext));
-
- stringCtor.objectValue->prototype = functionPrototype;
- numberCtor.objectValue->prototype = functionPrototype;
- booleanCtor.objectValue->prototype = functionPrototype;
- arrayCtor.objectValue->prototype = functionPrototype;
+ regExpPrototype->prototype = objectPrototype;
+
+ objectCtor = Value::fromObject(new ObjectCtor(rootContext));
+ stringCtor = Value::fromObject(new StringCtor(rootContext));
+ numberCtor = Value::fromObject(new NumberCtor(rootContext));
+ booleanCtor = Value::fromObject(new BooleanCtor(rootContext));
+ arrayCtor = Value::fromObject(new ArrayCtor(rootContext));
+ functionCtor = Value::fromObject(new FunctionCtor(rootContext));
+ dateCtor = Value::fromObject(new DateCtor(rootContext));
+ regExpCtor = Value::fromObject(new RegExpCtor(rootContext));
+
+ stringCtor.objectValue->prototype = stringPrototype;
+ numberCtor.objectValue->prototype = numberPrototype;
+ booleanCtor.objectValue->prototype = booleanPrototype;
+ arrayCtor.objectValue->prototype = arrayPrototype;
functionCtor.objectValue->prototype = functionPrototype;
- dateCtor.objectValue->prototype = functionPrototype;
+ dateCtor.objectValue->prototype = datePrototype;
+ regExpCtor.objectValue->prototype = regExpPrototype;
objectPrototype->init(rootContext, objectCtor);
stringPrototype->init(rootContext, stringCtor);
arrayPrototype->init(rootContext, arrayCtor);
datePrototype->init(rootContext, dateCtor);
functionPrototype->init(rootContext, functionCtor);
+ regExpPrototype->init(rootContext, regExpCtor);
//
// set up the global object
glo->setProperty(rootContext, identifier(QStringLiteral("Array")), arrayCtor);
glo->setProperty(rootContext, identifier(QStringLiteral("Function")), functionCtor);
glo->setProperty(rootContext, identifier(QStringLiteral("Date")), dateCtor);
+ glo->setProperty(rootContext, identifier(QStringLiteral("RegExp")), regExpCtor);
glo->setProperty(rootContext, identifier(QStringLiteral("Math")), Value::fromObject(newMathObject(rootContext)));
}
return new DateCtor(ctx);
}
+Object *ExecutionEngine::newRegExpObject(const Value &value)
+{
+ Object *object = new RegExpObject(value);
+ object->prototype = regExpPrototype;
+ return object;
+}
+
+FunctionObject *ExecutionEngine::newRegExpCtor(Context *ctx)
+{
+ return new RegExpCtor(ctx);
+}
+
Object *ExecutionEngine::newErrorObject(const Value &value)
{
ErrorObject *object = new ErrorObject(value);
struct ArrayObject;
struct DateObject;
struct FunctionObject;
+struct RegExpObject;
struct ErrorObject;
struct ArgumentsObject;
struct Context;
struct ArrayPrototype;
struct FunctionPrototype;
struct DatePrototype;
+struct RegExpPrototype;
struct String {
String(const QString &text)
virtual DateObject *asDateObject() { return 0; }
virtual ArrayObject *asArrayObject() { return 0; }
virtual FunctionObject *asFunctionObject() { return 0; }
+ virtual RegExpObject *asRegExpObject() { return 0; }
virtual ErrorObject *asErrorObject() { return 0; }
virtual ArgumentsObject *asArgumentsObject() { return 0; }
virtual void construct(Context *ctx);
};
+struct RegExpObject: Object {
+ Value value;
+ RegExpObject(const Value &value): value(value) {}
+ virtual QString className() { return QStringLiteral("RegExp"); }
+ virtual RegExpObject *asRegExpObject() { return this; }
+};
+
struct ErrorObject: Object {
Value value;
ErrorObject(const Value &message): value(message) {}
Value arrayCtor;
Value functionCtor;
Value dateCtor;
+ Value regExpCtor;
ObjectPrototype *objectPrototype;
StringPrototype *stringPrototype;
ArrayPrototype *arrayPrototype;
FunctionPrototype *functionPrototype;
DatePrototype *datePrototype;
+ RegExpPrototype *regExpPrototype;
QHash<QString, String *> identifiers;
Object *newDateObject(const Value &value);
FunctionObject *newDateCtor(Context *ctx);
+ Object *newRegExpObject(const Value &value);
+ FunctionObject *newRegExpCtor(Context *ctx);
+
Object *newErrorObject(const Value &value);
Object *newMathObject(Context *ctx);
Object *newArgumentsObject(Context *ctx);
}
//
+// RegExp object
+//
+RegExpCtor::RegExpCtor(Context *scope)
+ : FunctionObject(scope)
+{
+}
+
+void RegExpCtor::construct(Context *ctx)
+{
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newStringObject(Value::undefinedValue()));
+}
+
+void RegExpCtor::call(Context *ctx)
+{
+ __qmljs_init_object(&ctx->result, ctx->engine->newRegExpObject(Value::undefinedValue()));
+}
+
+void RegExpPrototype::init(Context *ctx, const Value &ctor)
+{
+ ctor.objectValue->setProperty(ctx, ctx->engine->id_prototype, Value::fromObject(this));
+ setProperty(ctx, QStringLiteral("constructor"), ctor);
+ setProperty(ctx, QStringLiteral("exec"), method_exec, 0);
+ setProperty(ctx, QStringLiteral("test"), method_test, 0);
+ setProperty(ctx, QStringLiteral("toString"), method_toString, 0);
+}
+
+void RegExpPrototype::method_exec(Context *ctx)
+{
+ ctx->throwUnimplemented(QStringLiteral("RegExp.prototype.exec"));
+}
+
+void RegExpPrototype::method_test(Context *ctx)
+{
+ ctx->throwUnimplemented(QStringLiteral("RegExp.prototype.test"));
+}
+
+void RegExpPrototype::method_toString(Context *ctx)
+{
+ ctx->throwUnimplemented(QStringLiteral("RegExp.prototype.toString"));
+}
+
+//
// Math object
//
MathObject::MathObject(Context *ctx)
static void method_toUTCString(Context *ctx);
};
+struct RegExpCtor: FunctionObject
+{
+ RegExpCtor(Context *scope);
+
+ virtual void construct(Context *ctx);
+ virtual void call(Context *ctx);
+};
+
+struct RegExpPrototype: RegExpObject
+{
+ RegExpPrototype(): RegExpObject(Value::fromNumber(qSNaN())) {}
+ void init(Context *ctx, const Value &ctor);
+
+ static void method_exec(Context *ctx);
+ static void method_test(Context *ctx);
+ static void method_toString(Context *ctx);
+};
+
struct MathObject: Object
{
MathObject(Context *ctx);