uRIErrorPrototype->prototype = objectPrototype;
objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext));
- stringCtor = Value::fromObject(StringPrototype::newConstructor(rootContext));
+ stringCtor = Value::fromObject(new (memoryManager) StringCtor(rootContext));
numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext));
booleanCtor = Value::fromObject(new (memoryManager) BooleanCtor(rootContext));
arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext));
uRIErrorCtor.objectValue()->prototype = functionPrototype;
objectPrototype->init(rootContext, objectCtor);
- stringPrototype->initClass(this, stringCtor);
+ stringPrototype->init(this, stringCtor);
numberPrototype->init(rootContext, numberCtor);
booleanPrototype->init(rootContext, booleanCtor);
arrayPrototype->init(rootContext, arrayCtor);
Object::markObjects(that);
}
-Value StringPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, Value *argv, int argc)
+DEFINE_MANAGED_VTABLE(StringCtor);
+
+StringCtor::StringCtor(ExecutionContext *scope)
+ : FunctionObject(scope, scope->engine->newIdentifier(QStringLiteral("String")))
+{
+ vtbl = &static_vtbl;
+}
+
+Value StringCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int argc)
{
Value value;
if (argc)
return Value::fromObject(ctx->engine->newStringObject(value));
}
-Value StringPrototype::ctor_method_call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc)
+Value StringCtor::call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc)
{
Value value;
if (argc)
return value;
}
+void StringPrototype::init(ExecutionEngine *engine, const Value &ctor)
+{
+ ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this));
+ ctor.objectValue()->defineReadonlyProperty(engine->id_length, Value::fromInt32(1));
+ ctor.objectValue()->defineDefaultProperty(engine, QStringLiteral("fromCharCode"), method_fromCharCode, 1);
+
+ defineDefaultProperty(engine, QStringLiteral("constructor"), ctor);
+ defineDefaultProperty(engine, QStringLiteral("toString"), method_toString);
+ defineDefaultProperty(engine, QStringLiteral("valueOf"), method_toString); // valueOf and toString are identical
+ defineDefaultProperty(engine, QStringLiteral("charAt"), method_charAt, 1);
+ defineDefaultProperty(engine, QStringLiteral("charCodeAt"), method_charCodeAt, 1);
+ defineDefaultProperty(engine, QStringLiteral("concat"), method_concat, 1);
+ defineDefaultProperty(engine, QStringLiteral("indexOf"), method_indexOf, 1);
+ defineDefaultProperty(engine, QStringLiteral("lastIndexOf"), method_lastIndexOf, 1);
+ defineDefaultProperty(engine, QStringLiteral("localeCompare"), method_localeCompare, 1);
+ defineDefaultProperty(engine, QStringLiteral("match"), method_match, 1);
+ defineDefaultProperty(engine, QStringLiteral("replace"), method_replace, 2);
+ defineDefaultProperty(engine, QStringLiteral("search"), method_search, 1);
+ defineDefaultProperty(engine, QStringLiteral("slice"), method_slice, 2);
+ defineDefaultProperty(engine, QStringLiteral("split"), method_split, 2);
+ defineDefaultProperty(engine, QStringLiteral("substr"), method_substr, 2);
+ defineDefaultProperty(engine, QStringLiteral("substring"), method_substring, 2);
+ defineDefaultProperty(engine, QStringLiteral("toLowerCase"), method_toLowerCase);
+ defineDefaultProperty(engine, QStringLiteral("toLocaleLowerCase"), method_toLocaleLowerCase);
+ defineDefaultProperty(engine, QStringLiteral("toUpperCase"), method_toUpperCase);
+ defineDefaultProperty(engine, QStringLiteral("toLocaleUpperCase"), method_toLocaleUpperCase);
+ defineDefaultProperty(engine, QStringLiteral("trim"), method_trim);
+}
+
static QString getThisString(ExecutionContext *ctx)
{
String* str = 0;
return method_toUpperCase(ctx);
}
-Value StringPrototype::ctor_method_fromCharCode(SimpleCallContext *context)
+Value StringPrototype::method_fromCharCode(SimpleCallContext *context)
{
QString str(context->argumentCount, Qt::Uninitialized);
QChar *ch = str.data();
return Value::fromString(ctx, QString(chars + start, end - start + 1));
}
-
-#include "qv4stringobject_p_jsclass.cpp"
static void markObjects(Managed *that);
};
-struct QV4_JS_CLASS(StringPrototype): StringObject
+struct StringCtor: FunctionObject
{
- QV4_ANNOTATE(argc 1)
+ StringCtor(ExecutionContext *scope);
- StringPrototype(ExecutionEngine *engine): StringObject(engine, Value::fromString(engine, QString())) {}
- void initClass(ExecutionEngine *engine, const Value &ctor);
- static Object *newConstructor(ExecutionContext *scope);
+ static Value construct(Managed *that, ExecutionContext *context, Value *args, int argc);
+ static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int);
- static Value ctor_method_construct(Managed *that, ExecutionContext *context, Value *args, int argc);
- static Value ctor_method_call(Managed *that, ExecutionContext *, const Value &, Value *, int);
+protected:
+ static const ManagedVTable static_vtbl;
+};
+
+struct StringPrototype: StringObject
+{
+ StringPrototype(ExecutionEngine *engine): StringObject(engine, Value::fromString(engine, QString())) {}
+ void init(ExecutionEngine *engine, const Value &ctor);
- static Value method_toString(SimpleCallContext *context) QV4_ANNOTATE(alias valueOf);
- static Value method_charAt(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_charCodeAt(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_concat(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_indexOf(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_lastIndexOf(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_localeCompare(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_match(SimpleCallContext *context) QV4_ARGC(1);
- static Value method_replace(SimpleCallContext *ctx) QV4_ARGC(2);
- static Value method_search(SimpleCallContext *ctx) QV4_ARGC(1);
- static Value method_slice(SimpleCallContext *ctx) QV4_ARGC(2);
- static Value method_split(SimpleCallContext *ctx) QV4_ARGC(2);
- static Value method_substr(SimpleCallContext *context) QV4_ARGC(2);
- static Value method_substring(SimpleCallContext *context) QV4_ARGC(2);
+ static Value method_toString(SimpleCallContext *context);
+ static Value method_charAt(SimpleCallContext *context);
+ static Value method_charCodeAt(SimpleCallContext *context);
+ static Value method_concat(SimpleCallContext *context);
+ static Value method_indexOf(SimpleCallContext *context);
+ static Value method_lastIndexOf(SimpleCallContext *context);
+ static Value method_localeCompare(SimpleCallContext *context);
+ static Value method_match(SimpleCallContext *context);
+ static Value method_replace(SimpleCallContext *ctx);
+ static Value method_search(SimpleCallContext *ctx);
+ static Value method_slice(SimpleCallContext *ctx);
+ static Value method_split(SimpleCallContext *ctx);
+ static Value method_substr(SimpleCallContext *context);
+ static Value method_substring(SimpleCallContext *context);
static Value method_toLowerCase(SimpleCallContext *ctx);
static Value method_toLocaleLowerCase(SimpleCallContext *ctx);
static Value method_toUpperCase(SimpleCallContext *ctx);
static Value method_toLocaleUpperCase(SimpleCallContext *ctx);
- static Value ctor_method_fromCharCode(SimpleCallContext *context) QV4_ARGC(1);
+ static Value method_fromCharCode(SimpleCallContext *context);
static Value method_trim(SimpleCallContext *ctx);
};
$$PWD/v4classgen
JS_CLASS_SOURCES += $$PWD/qv4dateobject_p.h \
- $$PWD/qv4stringobject_p.h \
$$PWD/qv4variantobject_p.h \
$$PWD/qv4sequenceobject_p.h \
$$PWD/qv4errorobject_p.h