Object *ExecutionEngine::newStringPrototype(Context *ctx, FunctionObject *proto)
{
- return new StringPrototype(ctx, proto);
+ Object *stringProto = new StringPrototype(ctx, proto);
+ stringProto->prototype = objectPrototype.objectValue;
+ return stringProto;
}
Object *ExecutionEngine::newNumberObject(const Value &value)
Object *ExecutionEngine::newNumberPrototype(Context *ctx, FunctionObject *proto)
{
- return new NumberPrototype(ctx, proto);
+ Object *numberProto = new NumberPrototype(ctx, proto);
+ numberProto->prototype = objectPrototype.objectValue;
+ return numberProto;
}
Object *ExecutionEngine::newBooleanObject(const Value &value)
return new BooleanObject(value);
}
+FunctionObject *ExecutionEngine::newBooleanCtor(Context *ctx)
+{
+ return new BooleanCtor(ctx);
+}
+
+Object *ExecutionEngine::newBooleanPrototype(Context *ctx, FunctionObject *proto)
+{
+ Object *booleanProto = new BooleanPrototype(ctx, proto);
+ booleanProto->prototype = objectPrototype.objectValue;
+ return booleanProto;
+}
+
Object *ExecutionEngine::newErrorObject(const Value &value)
{
return new ErrorObject(value);
Object *newNumberPrototype(Context *ctx, FunctionObject *proto);
Object *newBooleanObject(const Value &value);
+ FunctionObject *newBooleanCtor(Context *ctx);
+ Object *newBooleanPrototype(Context *ctx, FunctionObject *proto);
+
Object *newErrorObject(const Value &value);
Object *newMathObject(Context *ctx);
Object *newArgumentsObject(Context *ctx);
Value value;
__qmljs_init_boolean(&value, boolean);
__qmljs_init_object(result, ctx->engine->newBooleanObject(value));
+ result->objectValue->prototype = ctx->engine->objectPrototype.objectValue;
}
void __qmljs_new_number_object(Context *ctx, Value *result, double number)
}
//
+// Boolean object
+//
+Value BooleanCtor::create(ExecutionEngine *engine)
+{
+ Context *ctx = engine->rootContext;
+ FunctionObject *ctor = ctx->engine->newBooleanCtor(ctx);
+ ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newBooleanPrototype(ctx, ctor)));
+ return Value::fromObject(ctor);
+}
+
+BooleanCtor::BooleanCtor(Context *scope)
+ : FunctionObject(scope)
+{
+}
+
+void BooleanCtor::construct(Context *ctx)
+{
+ const double n = ctx->argument(0).toBoolean(ctx);
+ __qmljs_init_object(&ctx->thisObject, ctx->engine->newBooleanObject(Value::fromBoolean(n)));
+}
+
+void BooleanCtor::call(Context *ctx)
+{
+ double value = ctx->argumentCount ? ctx->argument(0).toBoolean(ctx) : 0;
+ __qmljs_init_boolean(&ctx->result, value);
+}
+
+BooleanPrototype::BooleanPrototype(Context *ctx, FunctionObject *ctor)
+{
+ ctor->setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
+ ctor->setProperty(ctx, QLatin1String("toString"), method_toString);
+ ctor->setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
+}
+
+void BooleanPrototype::method_toString(Context *ctx)
+{
+ Value self = ctx->thisObject;
+// if (self.classInfo() != classInfo) {
+// return throwThisObjectTypeError(
+// context, QLatin1String("Boolean.prototype.toString"));
+// }
+ assert(self.isObject());
+ Value internalValue;
+ self.objectValue->defaultValue(ctx, &internalValue, PREFERREDTYPE_HINT);
+ assert(internalValue.isBoolean());
+ bool v = internalValue.booleanValue;
+ ctx->result = Value::fromString(ctx, QLatin1String(v ? "true" : "false"));
+}
+
+void BooleanPrototype::method_valueOf(Context *ctx)
+{
+ Value self = ctx->thisObject;
+// if (self.classInfo() != classInfo) {
+// return throwThisObjectTypeError(
+// context, QLatin1String("Boolean.prototype.valueOf"));
+// }
+ assert(self.isObject());
+ Value internalValue;
+ self.objectValue->defaultValue(ctx, &internalValue, PREFERREDTYPE_HINT);
+ assert(internalValue.isBoolean());
+ ctx->result = internalValue;
+}
+
+//
// Math object
//
MathObject::MathObject(Context *ctx)
static void method_toPrecision(Context *ctx);
};
+struct BooleanCtor: FunctionObject
+{
+ static Value create(ExecutionEngine *engine);
+
+ BooleanCtor(Context *scope);
+
+ virtual void construct(Context *ctx);
+ virtual void call(Context *ctx);
+};
+
+struct BooleanPrototype: Object
+{
+ BooleanPrototype(Context *ctx, FunctionObject *ctor);
+
+protected:
+ static void method_toString(Context *ctx);
+ static void method_valueOf(Context *ctx);
+};
+
struct MathObject: Object
{
MathObject(Context *ctx);