Refactored Object

This commit is contained in:
Roberto Raggi 2012-05-25 12:54:36 +02:00
parent a5229e821d
commit fc6f96166f
10 changed files with 421 additions and 437 deletions

View File

@ -90,8 +90,8 @@ void evaluate(QQmlJS::VM::ExecutionEngine *vm, const QString &fileName, const QS
VM::Object *globalObject = vm->globalObject.objectValue;
VM::Context *ctx = vm->rootContext;
globalObject->put(vm->identifier(QLatin1String("print")),
VM::Value::fromObject(new builtins::Print(ctx)));
globalObject->setProperty(ctx, vm->identifier(QStringLiteral("print")),
VM::Value::fromObject(new builtins::Print(ctx)));
ctx->varCount = globalCode->locals.size();
if (ctx->varCount) {

View File

@ -18,7 +18,7 @@ Object::~Object()
void Object::setProperty(Context *ctx, const QString &name, const Value &value)
{
put(ctx->engine->identifier(name), value);
setProperty(ctx, ctx->engine->identifier(name), value);
}
void Object::setProperty(Context *ctx, const QString &name, void (*code)(Context *), int count)
@ -27,18 +27,7 @@ void Object::setProperty(Context *ctx, const QString &name, void (*code)(Context
setProperty(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code)));
}
bool Object::get(String *name, Value *result)
{
if (Value *prop = getProperty(name)) {
*result = *prop;
return true;
}
__qmljs_init_undefined(result);
return false;
}
Value *Object::getOwnProperty(String *name, PropertyAttributes *attributes)
Value *Object::getOwnProperty(Context *ctx, String *name, PropertyAttributes *attributes)
{
if (members) {
if (Property *prop = members->find(name)) {
@ -50,16 +39,16 @@ Value *Object::getOwnProperty(String *name, PropertyAttributes *attributes)
return 0;
}
Value *Object::getProperty(String *name, PropertyAttributes *attributes)
Value *Object::getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes)
{
if (Value *prop = getOwnProperty(name, attributes))
if (Value *prop = getOwnProperty(ctx, name, attributes))
return prop;
else if (prototype)
return prototype->getProperty(name, attributes);
return prototype->getPropertyDescriptor(ctx, name, attributes);
return 0;
}
void Object::put(String *name, const Value &value, bool flag)
void Object::setProperty(Context *ctx, String *name, const Value &value, bool flag)
{
Q_UNUSED(flag);
@ -69,14 +58,14 @@ void Object::put(String *name, const Value &value, bool flag)
members->insert(name, value);
}
bool Object::canPut(String *name)
bool Object::canSetProperty(Context *ctx, String *name)
{
PropertyAttributes attrs = PropertyAttributes();
if (getOwnProperty(name, &attrs)) {
if (getOwnProperty(ctx, name, &attrs)) {
return attrs & WritableAttribute;
} else if (! prototype) {
return extensible;
} else if (prototype->getProperty(name, &attrs)) {
} else if (prototype->getPropertyDescriptor(ctx, name, &attrs)) {
return attrs & WritableAttribute;
} else {
return extensible;
@ -84,7 +73,7 @@ bool Object::canPut(String *name)
return true;
}
bool Object::hasProperty(String *name) const
bool Object::hasProperty(Context *ctx, String *name) const
{
if (members)
return members->find(name) != 0;
@ -92,7 +81,7 @@ bool Object::hasProperty(String *name) const
return false;
}
bool Object::deleteProperty(String *name, bool flag)
bool Object::deleteProperty(Context *ctx, String *name, bool flag)
{
Q_UNUSED(flag);
@ -102,14 +91,19 @@ bool Object::deleteProperty(String *name, bool flag)
return false;
}
Value *ArrayObject::getOwnProperty(String *name, PropertyAttributes *attributes)
void Object::defineOwnProperty(Context *ctx, const Value &getter, const Value &setter, bool flag)
{
if (name->toQString() == QLatin1String("length")) {
length.numberValue = value.size();
return &length;
}
Q_UNUSED(getter);
Q_UNUSED(setter);
Q_UNUSED(flag);
ctx->throwUnimplemented(QStringLiteral("defineOwnProperty"));
}
return Object::getOwnProperty(name, attributes);
Value ArrayObject::getProperty(Context *ctx, String *name, PropertyAttributes *attributes)
{
if (name->isEqualTo(ctx->engine->id_length))
return Value::fromNumber(value.size());
return Object::getProperty(ctx, name, attributes);
}
bool FunctionObject::hasInstance(const Value &value) const
@ -168,7 +162,7 @@ void ScriptFunction::construct(VM::Context *ctx)
function->code(ctx);
}
Value *ArgumentsObject::getProperty(String *name, PropertyAttributes *attributes)
Value *ArgumentsObject::getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes)
{
if (context) {
for (size_t i = 0; i < context->varCount; ++i) {
@ -188,7 +182,7 @@ Value *ArgumentsObject::getProperty(String *name, PropertyAttributes *attributes
}
}
}
if (Value *prop = Object::getProperty(name, attributes))
if (Value *prop = Object::getPropertyDescriptor(ctx, name, attributes))
return prop;
return 0;
}
@ -206,20 +200,21 @@ ExecutionEngine::ExecutionEngine()
datePrototype.type = NULL_TYPE;
functionPrototype.type = NULL_TYPE;
id_length = identifier(QStringLiteral("length"));
id_prototype = identifier(QStringLiteral("prototype"));
//
// set up the global object
//
String *prototype = identifier(QLatin1String("prototype"));
VM::Object *glo = newArgumentsObject(rootContext);
__qmljs_init_object(&globalObject, glo);
__qmljs_init_object(&rootContext->activation, glo);
objectCtor = ObjectCtor::create(this);
objectCtor.objectValue->get(prototype, &objectPrototype);
objectPrototype = objectCtor.property(rootContext, id_prototype);
functionCtor = FunctionCtor::create(this);
functionCtor.objectValue->get(prototype, &functionPrototype);
functionPrototype = functionCtor.property(rootContext, id_prototype);
stringCtor = StringCtor::create(this);
numberCtor = NumberCtor::create(this);
@ -227,19 +222,19 @@ ExecutionEngine::ExecutionEngine()
arrayCtor = ArrayCtor::create(this);
dateCtor = DateCtor::create(this);
stringCtor.objectValue->get(prototype, &stringPrototype);
numberCtor.objectValue->get(prototype, &numberPrototype);
booleanCtor.objectValue->get(prototype, &booleanPrototype);
arrayCtor.objectValue->get(prototype, &arrayPrototype);
dateCtor.objectValue->get(prototype, &datePrototype);
stringPrototype = stringCtor.property(rootContext, id_prototype);
numberPrototype = numberCtor.property(rootContext, id_prototype);
booleanPrototype = booleanCtor.property(rootContext, id_prototype);
arrayPrototype = arrayCtor.property(rootContext, id_prototype);
datePrototype = dateCtor.property(rootContext, id_prototype);
glo->put(identifier(QLatin1String("Object")), objectCtor);
glo->put(identifier(QLatin1String("String")), stringCtor);
glo->put(identifier(QLatin1String("Number")), numberCtor);
glo->put(identifier(QLatin1String("Array")), arrayCtor);
glo->put(identifier(QLatin1String("Function")), functionCtor);
glo->put(identifier(QLatin1String("Date")), dateCtor);
glo->put(identifier(QLatin1String("Math")), Value::fromObject(newMathObject(rootContext)));
glo->setProperty(rootContext, identifier(QStringLiteral("Object")), objectCtor);
glo->setProperty(rootContext, identifier(QStringLiteral("String")), stringCtor);
glo->setProperty(rootContext, identifier(QStringLiteral("Number")), numberCtor);
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("Math")), Value::fromObject(newMathObject(rootContext)));
}
Context *ExecutionEngine::newContext()
@ -459,13 +454,13 @@ void Context::throwError(const QString &message)
void Context::throwTypeError()
{
Value v = Value::fromString(this, QLatin1String("Type error"));
Value v = Value::fromString(this, QStringLiteral("Type error"));
throwError(Value::fromObject(engine->newErrorObject(v)));
}
void Context::throwUnimplemented(const QString &message)
{
Value v = Value::fromString(this, QLatin1String("Unimplemented ") + message);
Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message);
throwError(Value::fromObject(engine->newErrorObject(v)));
}
@ -529,10 +524,9 @@ void Context::leaveConstructorContext(FunctionObject *f, Value *returnValue)
assert(thisObject.is(OBJECT_TYPE));
result = thisObject;
Value proto;
if (f->get(engine->identifier(QLatin1String("prototype")), &proto)) {
if (proto.type == OBJECT_TYPE)
thisObject.objectValue->prototype = proto.objectValue;
}
Value proto = f->getProperty(this, engine->id_prototype);
if (proto.isObject())
thisObject.objectValue->prototype = proto.objectValue;
leaveCallContext(f, returnValue);
}

View File

@ -33,6 +33,12 @@ struct String {
String(const QString &text)
: _text(text), _hashValue(0) {}
bool isEqualTo(const String *other) const {
if (other && hashValue() == other->hashValue())
return this == other || toQString() == other->toQString();
return false;
}
inline const QString &toQString() const {
return _text;
}
@ -63,18 +69,8 @@ struct Property {
inline bool isEnumerable() const { return attributes & EnumerableAttribute; }
inline bool isConfigurable() const { return attributes & ConfigurableAttribute; }
inline bool hasName(String *n) const {
if (name == n) {
return true;
} else if (name->hashValue() == n->hashValue() && name->toQString() == n->toQString()) {
return true;
}
return false;
}
inline unsigned hashValue() const {
return name->hashValue();
}
inline bool hasName(String *n) const { return name->isEqualTo(n); }
inline unsigned hashValue() const { return name->hashValue(); }
};
class Table
@ -206,15 +202,20 @@ struct Object {
virtual ErrorObject *asErrorObject() { return 0; }
virtual ArgumentsObject *asArgumentsObject() { return 0; }
bool get(String *name, Value *result);
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes = 0)
{
if (Value *v = getPropertyDescriptor(ctx, name, attributes))
return *v;
return Value::undefinedValue();
}
virtual Value *getOwnProperty(String *name, PropertyAttributes *attributes = 0);
virtual Value *getProperty(String *name, PropertyAttributes *attributes = 0);
virtual void put(String *name, const Value &value, bool flag = 0);
virtual bool canPut(String *name);
virtual bool hasProperty(String *name) const;
virtual bool deleteProperty(String *name, bool flag);
// ### TODO: defineOwnProperty(name, descriptor, boolean) -> boolean
virtual Value *getOwnProperty(Context *ctx, String *name, PropertyAttributes *attributes = 0);
virtual Value *getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes = 0);
virtual void setProperty(Context *ctx, String *name, const Value &value, bool flag = false);
virtual bool canSetProperty(Context *ctx, String *name);
virtual bool hasProperty(Context *ctx, String *name) const;
virtual bool deleteProperty(Context *ctx, String *name, bool flag);
virtual void defineOwnProperty(Context *ctx, const Value &getter, const Value &setter, bool flag = false);
//
// helpers
@ -249,11 +250,10 @@ struct DateObject: Object {
struct ArrayObject: Object {
Array value;
Value length;
ArrayObject() { length.type = NUMBER_TYPE; }
ArrayObject(const Array &value): value(value) { length.type = NUMBER_TYPE; }
ArrayObject() {}
ArrayObject(const Array &value): value(value) {}
virtual ArrayObject *asArrayObject() { return this; }
virtual Value *getOwnProperty(String *name, PropertyAttributes *attributes);
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes);
};
struct FunctionObject: Object {
@ -306,7 +306,7 @@ struct ArgumentsObject: Object {
Context *context;
ArgumentsObject(Context *context): context(context) {}
virtual ArgumentsObject *asArgumentsObject() { return this; }
virtual Value *getProperty(String *name, PropertyAttributes *attributes);
virtual Value *getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes);
};
struct Context {
@ -325,11 +325,11 @@ struct Context {
int calledAsConstructor;
int hasUncaughtException;
Value *lookup(String *name)
Value *lookupPropertyDescriptor(String *name)
{
for (Context *ctx = this; ctx; ctx = ctx->parent) {
if (ctx->activation.is(OBJECT_TYPE)) {
if (Value *prop = ctx->activation.objectValue->getProperty(name)) {
if (Value *prop = ctx->activation.objectValue->getPropertyDescriptor(this, name)) {
return prop;
}
}
@ -406,6 +406,9 @@ struct ExecutionEngine
QHash<QString, String *> identifiers;
String *id_length;
String *id_prototype;
ExecutionEngine();
Context *newContext();

View File

@ -15,7 +15,7 @@ namespace VM {
QString numberToString(double num, int radix = 10)
{
if (qIsNaN(num)) {
return QLatin1String("NaN");
return QStringLiteral("NaN");
} else if (qIsInf(num)) {
return QLatin1String(num < 0 ? "-Infinity" : "Infinity");
}
@ -211,6 +211,16 @@ ArgumentsObject *Value::asArgumentsObject() const
return type == OBJECT_TYPE ? objectValue->asArgumentsObject() : 0;
}
Value Value::property(Context *ctx, String *name) const
{
return isObject() ? objectValue->getProperty(ctx, name) : undefinedValue();
}
Value *Value::getPropertyDescriptor(Context *ctx, String *name) const
{
return isObject() ? objectValue->getPropertyDescriptor(ctx, name) : 0;
}
extern "C" {
void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos)
@ -220,47 +230,47 @@ void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos)
void __qmljs_string_literal_undefined(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("undefined")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("undefined")));
}
void __qmljs_string_literal_null(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("null")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("null")));
}
void __qmljs_string_literal_true(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("true")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("true")));
}
void __qmljs_string_literal_false(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("false")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("false")));
}
void __qmljs_string_literal_object(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("object")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("object")));
}
void __qmljs_string_literal_boolean(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("boolean")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("boolean")));
}
void __qmljs_string_literal_number(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("number")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("number")));
}
void __qmljs_string_literal_string(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("string")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("string")));
}
void __qmljs_string_literal_function(Context *ctx, Value *result)
{
__qmljs_init_string(result, ctx->engine->identifier(QLatin1String("function")));
__qmljs_init_string(result, ctx->engine->identifier(QStringLiteral("function")));
}
void __qmljs_delete(Context *ctx, Value *result, const Value *value)
@ -290,7 +300,7 @@ void __qmljs_in(Context *ctx, Value *result, const Value *left, const Value *rig
if (right->type == OBJECT_TYPE) {
Value s;
__qmljs_to_string(ctx, &s, left);
bool r = right->objectValue->hasProperty(s.stringValue);
bool r = right->objectValue->hasProperty(ctx, s.stringValue);
__qmljs_init_boolean(result, r);
} else {
__qmljs_throw_type_error(ctx, result);
@ -353,20 +363,20 @@ void __qmljs_object_default_value(Context *ctx, Value *result, const Value *obje
Object *oo = object->asObject();
assert(oo != 0);
Value *conv = oo->getProperty(meth1);
if (conv && conv->isFunctionObject()) {
Value conv = oo->getProperty(ctx, meth1);
if (!conv.isUndefined() && conv.isFunctionObject()) {
Value r;
__qmljs_call_value(ctx, &r, object, conv, 0, 0);
__qmljs_call_value(ctx, &r, object, &conv, 0, 0);
if (r.isPrimitive()) {
*result = r;
return;
}
}
conv = object->asObject()->getProperty(meth2);
if (conv && conv->isFunctionObject()) {
conv = oo->getProperty(ctx, meth2);
if (!conv.isUndefined() && conv.isFunctionObject()) {
Value r;
__qmljs_call_value(ctx, &r, object, conv, 0, 0);
__qmljs_call_value(ctx, &r, object, &conv, 0, 0);
if (r.isPrimitive()) {
*result = r;
return;
@ -409,16 +419,14 @@ void __qmljs_new_string_object(Context *ctx, Value *result, String *string)
void __qmljs_set_property(Context *ctx, Value *object, String *name, Value *value)
{
Q_UNUSED(ctx);
object->objectValue->put(name, *value, /*flags*/ 0);
object->objectValue->setProperty(ctx, name, *value, /*flags*/ 0);
}
void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool number)
{
Q_UNUSED(ctx);
Value value;
__qmljs_init_boolean(&value, number);
object->objectValue->put(name, value, /*flag*/ 0);
object->objectValue->setProperty(ctx, name, value, /*flag*/ 0);
}
void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double number)
@ -426,7 +434,7 @@ void __qmljs_set_property_number(Context *ctx, Value *object, String *name, doub
Q_UNUSED(ctx);
Value value;
__qmljs_init_number(&value, number);
object->objectValue->put(name, value, /*flag*/ 0);
object->objectValue->setProperty(ctx, name, value, /*flag*/ 0);
}
void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *s)
@ -434,14 +442,14 @@ void __qmljs_set_property_string(Context *ctx, Value *object, String *name, Stri
Q_UNUSED(ctx);
Value value;
__qmljs_init_string(&value, s);
object->objectValue->put(name, value, /*flag*/ 0);
object->objectValue->setProperty(ctx, name, value, /*flag*/ 0);
}
void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function)
{
Value value;
__qmljs_init_closure(ctx, &value, function);
object->objectValue->put(name, value, /*flag*/ 0);
object->objectValue->setProperty(ctx, name, value, /*flag*/ 0);
}
void __qmljs_get_element(Context *ctx, Value *result, Value *object, Value *index)
@ -460,7 +468,7 @@ void __qmljs_get_element(Context *ctx, Value *result, Value *object, Value *inde
if (! object->isObject())
__qmljs_to_object(ctx, object, object);
object->objectValue->get(name, result);
*result = object->property(ctx, name);
}
}
@ -474,7 +482,7 @@ void __qmljs_set_element(Context *ctx, Value *object, Value *index, Value *value
if (! object->isObject())
__qmljs_to_object(ctx, object, object);
object->objectValue->put(name, *value, /*flags*/ 0);
object->objectValue->setProperty(ctx, name, *value, /*flags*/ 0);
}
}
@ -487,7 +495,7 @@ void __qmljs_set_element_number(Context *ctx, Value *object, Value *index, doubl
void __qmljs_set_activation_element(Context *ctx, String *name, Value *index, Value *value)
{
if (Value *base = ctx->lookup(name)) {
if (Value *base = ctx->lookupPropertyDescriptor(name)) {
__qmljs_set_element(ctx, base, index, value);
} else {
ctx->throwReferenceError(Value::fromString(name));
@ -503,15 +511,15 @@ void __qmljs_set_activation_element_number(Context *ctx, String *name, Value *in
void __qmljs_set_activation_property(Context *ctx, String *name, Value *value)
{
if (Value *prop = ctx->lookup(name)) {
if (Value *prop = ctx->lookupPropertyDescriptor(name)) {
*prop = *value;
} else
ctx->engine->globalObject.objectValue->put(name, *value);
ctx->engine->globalObject.objectValue->setProperty(ctx, name, *value);
}
void __qmljs_copy_activation_property(Context *ctx, String *name, String *other)
{
if (Value *source = ctx->lookup(other))
if (Value *source = ctx->lookupPropertyDescriptor(other))
__qmljs_set_activation_property(ctx, name, source);
else
ctx->throwReferenceError(Value::fromString(name));
@ -548,7 +556,9 @@ void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Fun
void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *name)
{
if (object->type == OBJECT_TYPE) {
object->objectValue->get(name, result);
*result = object->property(ctx, name);
} else if (object->type == STRING_TYPE && name->isEqualTo(ctx->engine->id_length)) {
__qmljs_init_number(result, object->stringValue->toQString().length());
} else {
Value o;
__qmljs_to_object(ctx, &o, object);
@ -561,7 +571,7 @@ void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *na
void __qmljs_get_activation_property(Context *ctx, Value *result, String *name)
{
if (Value *prop = ctx->lookup(name))
if (Value *prop = ctx->lookupPropertyDescriptor(name))
*result = *prop;
else
ctx->throwReferenceError(Value::fromString(name));
@ -577,14 +587,6 @@ void __qmljs_get_thisObject(Context *ctx, Value *result)
*result = ctx->thisObject;
}
void __qmljs_copy_property(Context *ctx, Value *target, String *name, Value *source, String *other)
{
Q_UNUSED(ctx);
Value v;
source->objectValue->get(other, &v);
target->objectValue->put(name, v);
}
void __qmljs_compare(Context *ctx, Value *result, const Value *x, const Value *y, bool leftFirst)
{
Value px, py;
@ -667,7 +669,7 @@ bool __qmljs_equal(Context *ctx, const Value *x, const Value *y)
void __qmljs_call_activation_property(Context *context, Value *result, String *name, Value *args, int argc)
{
Value *func = context->lookup(name);
Value *func = context->lookupPropertyDescriptor(name);
if (! func)
context->throwReferenceError(Value::fromString(name));
else
@ -688,22 +690,17 @@ void __qmljs_call_property(Context *context, Value *result, const Value *base, S
baseObject = context->activation;
__qmljs_init_null(&thisObject);
}
Value func;
baseObject.objectValue->get(name, &func);
if (func.type == OBJECT_TYPE) {
if (FunctionObject *f = func.objectValue->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initCallContext(context->engine, &thisObject, f, args, argc);
f->call(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveCallContext(f, result);
} else {
context->throwTypeError();
Value func = baseObject.property(context, name);
if (FunctionObject *f = func.asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initCallContext(context->engine, &thisObject, f, args, argc);
f->call(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveCallContext(f, result);
} else {
context->throwTypeError();
}
@ -711,20 +708,16 @@ void __qmljs_call_property(Context *context, Value *result, const Value *base, S
void __qmljs_call_value(Context *context, Value *result, const Value *thisObject, const Value *func, Value *args, int argc)
{
if (func->type == OBJECT_TYPE) {
if (FunctionObject *f = func->objectValue->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initCallContext(context->engine, thisObject, f, args, argc);
f->call(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveCallContext(f, result);
} else {
context->throwTypeError();
if (FunctionObject *f = func->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initCallContext(context->engine, thisObject, f, args, argc);
f->call(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveCallContext(f, result);
} else {
context->throwTypeError();
}
@ -732,7 +725,7 @@ void __qmljs_call_value(Context *context, Value *result, const Value *thisObject
void __qmljs_construct_activation_property(Context *context, Value *result, String *name, Value *args, int argc)
{
Value *func = context->lookup(name);
Value *func = context->lookupPropertyDescriptor(name);
if (! func)
context->throwReferenceError(Value::fromString(name));
else
@ -741,21 +734,16 @@ void __qmljs_construct_activation_property(Context *context, Value *result, Stri
void __qmljs_construct_value(Context *context, Value *result, const Value *func, Value *args, int argc)
{
Q_UNUSED(context);
if (func->type == OBJECT_TYPE) {
if (FunctionObject *f = func->objectValue->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initConstructorContext(context->engine, 0, f, args, argc);
f->construct(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveConstructorContext(f, result);
} else {
context->throwTypeError();
if (FunctionObject *f = func->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initConstructorContext(context->engine, 0, f, args, argc);
f->construct(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveConstructorContext(f, result);
} else {
context->throwTypeError();
}
@ -763,28 +751,23 @@ void __qmljs_construct_value(Context *context, Value *result, const Value *func,
void __qmljs_construct_property(Context *context, Value *result, const Value *base, String *name, Value *args, int argc)
{
Value func;
Value thisObject = *base;
if (thisObject.type != OBJECT_TYPE)
__qmljs_to_object(context, &thisObject, base);
assert(thisObject.type == OBJECT_TYPE);
thisObject.objectValue->get(name, &func);
if (func.type == OBJECT_TYPE) {
if (FunctionObject *f = func.objectValue->asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initConstructorContext(context->engine, 0, f, args, argc);
ctx->calledAsConstructor = true;
f->construct(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveConstructorContext(f, result);
} else {
context->throwTypeError();
Value func = thisObject.property(context, name);
if (FunctionObject *f = func.asFunctionObject()) {
Context k;
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
ctx->initConstructorContext(context->engine, 0, f, args, argc);
ctx->calledAsConstructor = true;
f->construct(ctx);
if (ctx->hasUncaughtException) {
context->hasUncaughtException = ctx->hasUncaughtException; // propagate the exception
context->result = ctx->result;
}
ctx->leaveConstructorContext(f, result);
} else {
context->throwTypeError();
}

View File

@ -114,7 +114,6 @@ void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Fun
void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *name);
void __qmljs_get_activation_property(Context *ctx, Value *result, String *name);
void __qmljs_copy_activation_property(Context *ctx, String *name, String *other);
void __qmljs_copy_property(Context *ctx, Value *target, String *name, Value *source, String *other);
void __qmljs_get_element(Context *ctx, Value *result, Value *object, Value *index);
@ -271,6 +270,9 @@ struct Value {
ArrayObject *asArrayObject() const;
ErrorObject *asErrorObject() const;
ArgumentsObject *asArgumentsObject() const;
Value property(Context *ctx, String *name) const;
Value *getPropertyDescriptor(Context *ctx, String *name) const;
};
extern "C" {

View File

@ -209,7 +209,7 @@ protected:
{
if (! _env->hasDirectEval) {
if (IdentifierExpression *id = cast<IdentifierExpression *>(ast->base)) {
if (id->name == QLatin1String("eval")) {
if (id->name == QStringLiteral("eval")) {
_env->hasDirectEval = true;
}
}
@ -287,7 +287,7 @@ IR::Function *Codegen::operator()(Program *node, IR::Module *module)
ScanFunctions scan(this);
scan(node);
IR::Function *globalCode = defineFunction(QLatin1String("%entry"), node, 0, node->elements);
IR::Function *globalCode = defineFunction(QStringLiteral("%entry"), node, 0, node->elements);
foreach (IR::Function *function, _module->functions) {
linearize(function);
@ -803,7 +803,7 @@ bool Codegen::visit(Expression *ast)
bool Codegen::visit(ArrayLiteral *ast)
{
const unsigned t = _block->newTemp();
move(_block->TEMP(t), _block->NEW(_block->NAME(QLatin1String("Array"), ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn)));
move(_block->TEMP(t), _block->NEW(_block->NAME(QStringLiteral("Array"), ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn)));
int index = 0;
for (ElementList *it = ast->elements; it; it = it->next) {
for (Elision *elision = it->elision; elision; elision = elision->next)
@ -1138,7 +1138,7 @@ bool Codegen::visit(NumericLiteral *ast)
bool Codegen::visit(ObjectLiteral *ast)
{
const unsigned t = _block->newTemp();
move(_block->TEMP(t), _block->NEW(_block->NAME(QLatin1String("Object"), ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn)));
move(_block->TEMP(t), _block->NEW(_block->NAME(QStringLiteral("Object"), ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn)));
for (PropertyNameAndValueList *it = ast->properties; it; it = it->next) {
QString name = propertyName(it->name);
Result value = expression(it->value);
@ -1215,7 +1215,7 @@ bool Codegen::visit(StringLiteral *ast)
bool Codegen::visit(ThisExpression *ast)
{
_expr.code = _block->NAME(QLatin1String("this"), ast->thisToken.startLine, ast->thisToken.startColumn);
_expr.code = _block->NAME(QStringLiteral("this"), ast->thisToken.startLine, ast->thisToken.startColumn);
return false;
}

View File

@ -322,52 +322,52 @@ static inline double ParseString(const QString &s)
dt = QDateTime::fromString(s, Qt::ISODate);
if (!dt.isValid()) {
QStringList formats;
formats << QLatin1String("M/d/yyyy")
<< QLatin1String("M/d/yyyy hh:mm")
<< QLatin1String("M/d/yyyy hh:mm A")
formats << QStringLiteral("M/d/yyyy")
<< QStringLiteral("M/d/yyyy hh:mm")
<< QStringLiteral("M/d/yyyy hh:mm A")
<< QLatin1String("M/d/yyyy, hh:mm")
<< QLatin1String("M/d/yyyy, hh:mm A")
<< QStringLiteral("M/d/yyyy, hh:mm")
<< QStringLiteral("M/d/yyyy, hh:mm A")
<< QLatin1String("MMM d yyyy")
<< QLatin1String("MMM d yyyy hh:mm")
<< QLatin1String("MMM d yyyy hh:mm:ss")
<< QLatin1String("MMM d yyyy, hh:mm")
<< QLatin1String("MMM d yyyy, hh:mm:ss")
<< QStringLiteral("MMM d yyyy")
<< QStringLiteral("MMM d yyyy hh:mm")
<< QStringLiteral("MMM d yyyy hh:mm:ss")
<< QStringLiteral("MMM d yyyy, hh:mm")
<< QStringLiteral("MMM d yyyy, hh:mm:ss")
<< QLatin1String("MMMM d yyyy")
<< QLatin1String("MMMM d yyyy hh:mm")
<< QLatin1String("MMMM d yyyy hh:mm:ss")
<< QLatin1String("MMMM d yyyy, hh:mm")
<< QLatin1String("MMMM d yyyy, hh:mm:ss")
<< QStringLiteral("MMMM d yyyy")
<< QStringLiteral("MMMM d yyyy hh:mm")
<< QStringLiteral("MMMM d yyyy hh:mm:ss")
<< QStringLiteral("MMMM d yyyy, hh:mm")
<< QStringLiteral("MMMM d yyyy, hh:mm:ss")
<< QLatin1String("MMM d, yyyy")
<< QLatin1String("MMM d, yyyy hh:mm")
<< QLatin1String("MMM d, yyyy hh:mm:ss")
<< QStringLiteral("MMM d, yyyy")
<< QStringLiteral("MMM d, yyyy hh:mm")
<< QStringLiteral("MMM d, yyyy hh:mm:ss")
<< QLatin1String("MMMM d, yyyy")
<< QLatin1String("MMMM d, yyyy hh:mm")
<< QLatin1String("MMMM d, yyyy hh:mm:ss")
<< QStringLiteral("MMMM d, yyyy")
<< QStringLiteral("MMMM d, yyyy hh:mm")
<< QStringLiteral("MMMM d, yyyy hh:mm:ss")
<< QLatin1String("d MMM yyyy")
<< QLatin1String("d MMM yyyy hh:mm")
<< QLatin1String("d MMM yyyy hh:mm:ss")
<< QLatin1String("d MMM yyyy, hh:mm")
<< QLatin1String("d MMM yyyy, hh:mm:ss")
<< QStringLiteral("d MMM yyyy")
<< QStringLiteral("d MMM yyyy hh:mm")
<< QStringLiteral("d MMM yyyy hh:mm:ss")
<< QStringLiteral("d MMM yyyy, hh:mm")
<< QStringLiteral("d MMM yyyy, hh:mm:ss")
<< QLatin1String("d MMMM yyyy")
<< QLatin1String("d MMMM yyyy hh:mm")
<< QLatin1String("d MMMM yyyy hh:mm:ss")
<< QLatin1String("d MMMM yyyy, hh:mm")
<< QLatin1String("d MMMM yyyy, hh:mm:ss")
<< QStringLiteral("d MMMM yyyy")
<< QStringLiteral("d MMMM yyyy hh:mm")
<< QStringLiteral("d MMMM yyyy hh:mm:ss")
<< QStringLiteral("d MMMM yyyy, hh:mm")
<< QStringLiteral("d MMMM yyyy, hh:mm:ss")
<< QLatin1String("d MMM, yyyy")
<< QLatin1String("d MMM, yyyy hh:mm")
<< QLatin1String("d MMM, yyyy hh:mm:ss")
<< QStringLiteral("d MMM, yyyy")
<< QStringLiteral("d MMM, yyyy hh:mm")
<< QStringLiteral("d MMM, yyyy hh:mm:ss")
<< QLatin1String("d MMMM, yyyy")
<< QLatin1String("d MMMM, yyyy hh:mm")
<< QLatin1String("d MMMM, yyyy hh:mm:ss");
<< QStringLiteral("d MMMM, yyyy")
<< QStringLiteral("d MMMM, yyyy hh:mm")
<< QStringLiteral("d MMMM, yyyy hh:mm:ss");
for (int i = 0; i < formats.size(); ++i) {
dt = QDateTime::fromString(s, formats.at(i));
@ -403,8 +403,8 @@ static inline QDateTime ToDateTime(double t, Qt::TimeSpec spec)
static inline QString ToString(double t)
{
if (qIsNaN(t))
return QLatin1String("Invalid Date");
QString str = ToDateTime(t, Qt::LocalTime).toString() + QLatin1String(" GMT");
return QStringLiteral("Invalid Date");
QString str = ToDateTime(t, Qt::LocalTime).toString() + QStringLiteral(" GMT");
double tzoffset = LocalTZA + DaylightSavingTA(t);
if (tzoffset) {
int hours = static_cast<int>(::fabs(tzoffset) / 1000 / 60 / 60);
@ -423,8 +423,8 @@ static inline QString ToString(double t)
static inline QString ToUTCString(double t)
{
if (qIsNaN(t))
return QLatin1String("Invalid Date");
return ToDateTime(t, Qt::UTC).toString() + QLatin1String(" GMT");
return QStringLiteral("Invalid Date");
return ToDateTime(t, Qt::UTC).toString() + QStringLiteral(" GMT");
}
static inline QString ToDateString(double t)
@ -477,7 +477,7 @@ Value ObjectCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newObjectCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newObjectPrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newObjectPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -498,8 +498,8 @@ void ObjectCtor::call(Context *)
ObjectPrototype::ObjectPrototype(Context *ctx, FunctionObject *ctor)
{
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString, 0);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString, 0);
}
void ObjectPrototype::method_toString(Context *ctx)
@ -514,7 +514,7 @@ Value StringCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newStringCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newStringPrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newStringPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -544,27 +544,27 @@ void StringCtor::call(Context *ctx)
StringPrototype::StringPrototype(Context *ctx, FunctionObject *ctor)
{
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString);
setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
setProperty(ctx, QLatin1String("charAt"), method_charAt);
setProperty(ctx, QLatin1String("charCodeAt"), method_charCodeAt);
setProperty(ctx, QLatin1String("concat"), method_concat);
setProperty(ctx, QLatin1String("indexOf"), method_indexOf);
setProperty(ctx, QLatin1String("lastIndexOf"), method_lastIndexOf);
setProperty(ctx, QLatin1String("localeCompare"), method_localeCompare);
setProperty(ctx, QLatin1String("match"), method_match);
setProperty(ctx, QLatin1String("replace"), method_replace);
setProperty(ctx, QLatin1String("search"), method_search);
setProperty(ctx, QLatin1String("slice"), method_slice);
setProperty(ctx, QLatin1String("split"), method_split);
setProperty(ctx, QLatin1String("substr"), method_substr);
setProperty(ctx, QLatin1String("substring"), method_substring);
setProperty(ctx, QLatin1String("toLowerCase"), method_toLowerCase);
setProperty(ctx, QLatin1String("toLocaleLowerCase"), method_toLocaleLowerCase);
setProperty(ctx, QLatin1String("toUpperCase"), method_toUpperCase);
setProperty(ctx, QLatin1String("toLocaleUpperCase"), method_toLocaleUpperCase);
setProperty(ctx, QLatin1String("fromCharCode"), method_fromCharCode);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString);
setProperty(ctx, QStringLiteral("valueOf"), method_valueOf);
setProperty(ctx, QStringLiteral("charAt"), method_charAt);
setProperty(ctx, QStringLiteral("charCodeAt"), method_charCodeAt);
setProperty(ctx, QStringLiteral("concat"), method_concat);
setProperty(ctx, QStringLiteral("indexOf"), method_indexOf);
setProperty(ctx, QStringLiteral("lastIndexOf"), method_lastIndexOf);
setProperty(ctx, QStringLiteral("localeCompare"), method_localeCompare);
setProperty(ctx, QStringLiteral("match"), method_match);
setProperty(ctx, QStringLiteral("replace"), method_replace);
setProperty(ctx, QStringLiteral("search"), method_search);
setProperty(ctx, QStringLiteral("slice"), method_slice);
setProperty(ctx, QStringLiteral("split"), method_split);
setProperty(ctx, QStringLiteral("substr"), method_substr);
setProperty(ctx, QStringLiteral("substring"), method_substring);
setProperty(ctx, QStringLiteral("toLowerCase"), method_toLowerCase);
setProperty(ctx, QStringLiteral("toLocaleLowerCase"), method_toLocaleLowerCase);
setProperty(ctx, QStringLiteral("toUpperCase"), method_toUpperCase);
setProperty(ctx, QStringLiteral("toLocaleUpperCase"), method_toLocaleUpperCase);
setProperty(ctx, QStringLiteral("fromCharCode"), method_fromCharCode);
}
QString StringPrototype::getThisString(Context *ctx)
@ -694,19 +694,19 @@ void StringPrototype::method_localeCompare(Context *ctx)
void StringPrototype::method_match(Context *ctx)
{
// requires Regexp
ctx->throwUnimplemented(QLatin1String("String.prototype.match"));
ctx->throwUnimplemented(QStringLiteral("String.prototype.match"));
}
void StringPrototype::method_replace(Context *ctx)
{
// requires Regexp
ctx->throwUnimplemented(QLatin1String("String.prototype.replace"));
ctx->throwUnimplemented(QStringLiteral("String.prototype.replace"));
}
void StringPrototype::method_search(Context *ctx)
{
// requires Regexp
ctx->throwUnimplemented(QLatin1String("String.prototype.search"));
ctx->throwUnimplemented(QStringLiteral("String.prototype.search"));
}
void StringPrototype::method_slice(Context *ctx)
@ -734,7 +734,7 @@ void StringPrototype::method_slice(Context *ctx)
void StringPrototype::method_split(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("String.prototype.splt"));
ctx->throwUnimplemented(QStringLiteral("String.prototype.splt"));
}
void StringPrototype::method_substr(Context *ctx)
@ -836,7 +836,7 @@ Value NumberCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newNumberCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newNumberPrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newNumberPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -860,26 +860,26 @@ void NumberCtor::call(Context *ctx)
NumberPrototype::NumberPrototype(Context *ctx, FunctionObject *ctor)
: NumberObject(Value::fromNumber(0))
{
ctor->setProperty(ctx, QLatin1String("NaN"), Value::fromNumber(qSNaN()));
ctor->setProperty(ctx, QLatin1String("NEGATIVE_INFINITY"), Value::fromNumber(-qInf()));
ctor->setProperty(ctx, QLatin1String("POSITIVE_INFINITY"), Value::fromNumber(qInf()));
ctor->setProperty(ctx, QLatin1String("MAX_VALUE"), Value::fromNumber(1.7976931348623158e+308));
ctor->setProperty(ctx, QStringLiteral("NaN"), Value::fromNumber(qSNaN()));
ctor->setProperty(ctx, QStringLiteral("NEGATIVE_INFINITY"), Value::fromNumber(-qInf()));
ctor->setProperty(ctx, QStringLiteral("POSITIVE_INFINITY"), Value::fromNumber(qInf()));
ctor->setProperty(ctx, QStringLiteral("MAX_VALUE"), Value::fromNumber(1.7976931348623158e+308));
#ifdef __INTEL_COMPILER
# pragma warning( push )
# pragma warning(disable: 239)
#endif
ctor->setProperty(ctx, QLatin1String("MIN_VALUE"), Value::fromNumber(5e-324));
ctor->setProperty(ctx, QStringLiteral("MIN_VALUE"), Value::fromNumber(5e-324));
#ifdef __INTEL_COMPILER
# pragma warning( pop )
#endif
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString);
setProperty(ctx, QLatin1String("toLocalString"), method_toLocaleString);
setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
setProperty(ctx, QLatin1String("toFixed"), method_toFixed);
setProperty(ctx, QLatin1String("toExponential"), method_toExponential);
setProperty(ctx, QLatin1String("toPrecision"), method_toPrecision);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString);
setProperty(ctx, QStringLiteral("toLocalString"), method_toLocaleString);
setProperty(ctx, QStringLiteral("valueOf"), method_valueOf);
setProperty(ctx, QStringLiteral("toFixed"), method_toFixed);
setProperty(ctx, QStringLiteral("toExponential"), method_toExponential);
setProperty(ctx, QStringLiteral("toPrecision"), method_toPrecision);
}
void NumberPrototype::method_toString(Context *ctx)
@ -896,7 +896,7 @@ void NumberPrototype::method_toString(Context *ctx)
double num = thisObject->value.numberValue;
if (qIsNaN(num)) {
ctx->result = Value::fromString(ctx, QLatin1String("NaN"));
ctx->result = Value::fromString(ctx, QStringLiteral("NaN"));
return;
} else if (qIsInf(num)) {
ctx->result = Value::fromString(ctx, QLatin1String(num < 0 ? "-Infinity" : "Infinity"));
@ -1023,7 +1023,7 @@ 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)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newBooleanPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -1047,9 +1047,9 @@ void BooleanCtor::call(Context *ctx)
BooleanPrototype::BooleanPrototype(Context *ctx, FunctionObject *ctor)
: BooleanObject(Value::fromBoolean(false))
{
ctor->setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
ctor->setProperty(ctx, QLatin1String("toString"), method_toString);
ctor->setProperty(ctx, QLatin1String("valueOf"), method_valueOf);
ctor->setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
ctor->setProperty(ctx, QStringLiteral("toString"), method_toString);
ctor->setProperty(ctx, QStringLiteral("valueOf"), method_valueOf);
}
void BooleanPrototype::method_toString(Context *ctx)
@ -1077,7 +1077,7 @@ Value ArrayCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newArrayCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newArrayPrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newArrayPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -1100,7 +1100,7 @@ void ArrayCtor::call(Context *ctx)
quint32 isize = Value::toUInt32(size);
if (size != double(isize)) {
ctx->throwError(QLatin1String("Invalid array length"));
ctx->throwError(QStringLiteral("Invalid array length"));
return;
}
@ -1116,28 +1116,28 @@ void ArrayCtor::call(Context *ctx)
ArrayPrototype::ArrayPrototype(Context *ctx, FunctionObject *ctor)
{
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString, 0);
setProperty(ctx, QLatin1String("toLocalString"), method_toLocaleString, 0);
setProperty(ctx, QLatin1String("concat"), method_concat, 1);
setProperty(ctx, QLatin1String("join"), method_join, 1);
setProperty(ctx, QLatin1String("pop"), method_pop, 0);
setProperty(ctx, QLatin1String("push"), method_push, 1);
setProperty(ctx, QLatin1String("reverse"), method_reverse, 0);
setProperty(ctx, QLatin1String("shift"), method_shift, 0);
setProperty(ctx, QLatin1String("slice"), method_slice, 2);
setProperty(ctx, QLatin1String("sort"), method_sort, 1);
setProperty(ctx, QLatin1String("splice"), method_splice, 2);
setProperty(ctx, QLatin1String("unshift"), method_unshift, 1);
setProperty(ctx, QLatin1String("indexOf"), method_indexOf, 0);
setProperty(ctx, QLatin1String("lastIndexOf"), method_lastIndexOf, 0);
setProperty(ctx, QLatin1String("every"), method_every, 0);
setProperty(ctx, QLatin1String("some"), method_some, 0);
setProperty(ctx, QLatin1String("forEach"), method_forEach, 0);
setProperty(ctx, QLatin1String("map"), method_map, 0);
setProperty(ctx, QLatin1String("filter"), method_filter, 0);
setProperty(ctx, QLatin1String("reduce"), method_reduce, 0);
setProperty(ctx, QLatin1String("reduceRight"), method_reduceRight, 0);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString, 0);
setProperty(ctx, QStringLiteral("toLocalString"), method_toLocaleString, 0);
setProperty(ctx, QStringLiteral("concat"), method_concat, 1);
setProperty(ctx, QStringLiteral("join"), method_join, 1);
setProperty(ctx, QStringLiteral("pop"), method_pop, 0);
setProperty(ctx, QStringLiteral("push"), method_push, 1);
setProperty(ctx, QStringLiteral("reverse"), method_reverse, 0);
setProperty(ctx, QStringLiteral("shift"), method_shift, 0);
setProperty(ctx, QStringLiteral("slice"), method_slice, 2);
setProperty(ctx, QStringLiteral("sort"), method_sort, 1);
setProperty(ctx, QStringLiteral("splice"), method_splice, 2);
setProperty(ctx, QStringLiteral("unshift"), method_unshift, 1);
setProperty(ctx, QStringLiteral("indexOf"), method_indexOf, 0);
setProperty(ctx, QStringLiteral("lastIndexOf"), method_lastIndexOf, 0);
setProperty(ctx, QStringLiteral("every"), method_every, 0);
setProperty(ctx, QStringLiteral("some"), method_some, 0);
setProperty(ctx, QStringLiteral("forEach"), method_forEach, 0);
setProperty(ctx, QStringLiteral("map"), method_map, 0);
setProperty(ctx, QStringLiteral("filter"), method_filter, 0);
setProperty(ctx, QStringLiteral("reduce"), method_reduce, 0);
setProperty(ctx, QStringLiteral("reduceRight"), method_reduceRight, 0);
}
void ArrayPrototype::method_toString(Context *ctx)
@ -1181,15 +1181,13 @@ void ArrayPrototype::method_join(Context *ctx)
QString r4;
if (arg.isUndefined())
r4 = QLatin1String(",");
r4 = QStringLiteral(",");
else
r4 = arg.toString(ctx)->toQString();
Value self = ctx->thisObject;
Value *length = self.objectValue->getProperty(ctx->engine->identifier("length"));
double r1 = length ? length->toNumber(ctx) : 0;
quint32 r2 = Value::toUInt32(r1);
const Value length = self.property(ctx, ctx->engine->id_length);
const quint32 r2 = Value::toUInt32(length.isUndefined() ? 0 : length.toNumber(ctx));
static QSet<Object *> visitedArrayElements;
@ -1203,7 +1201,7 @@ void ArrayPrototype::method_join(Context *ctx)
QString R;
if (ArrayObject *a = self.objectValue->asArrayObject()) {
if (ArrayObject *a = self.asArrayObject()) {
for (uint i = 0; i < a->value.size(); ++i) {
if (i)
R += r4;
@ -1216,18 +1214,18 @@ void ArrayPrototype::method_join(Context *ctx)
//
// crazy!
//
Value *r6 = self.objectValue->getProperty(ctx->engine->identifier(QLatin1String("0")));
if (r6 && !(r6->isUndefined() || r6->isNull()))
R = r6->toString(ctx)->toQString();
Value r6 = self.property(ctx, ctx->engine->identifier(QStringLiteral("0")));
if (!(r6.isUndefined() || r6.isNull()))
R = r6.toString(ctx)->toQString();
for (quint32 k = 1; k < r2; ++k) {
R += r4;
String *name = Value::fromNumber(k).toString(ctx);
Value *r12 = self.objectValue->getProperty(name);
Value r12 = self.property(ctx, name);
if (r12 && ! (r12->isUndefined() || r12->isNull()))
R += r12->toString(ctx)->toQString();
if (! (r12.isUndefined() || r12.isNull()))
R += r12.toString(ctx)->toQString();
}
}
@ -1242,18 +1240,16 @@ void ArrayPrototype::method_pop(Context *ctx)
Value elt = instance->value.pop();
ctx->result = elt;
} else {
String *id_length = ctx->engine->identifier(QLatin1String("length"));
Value *r1 = self.objectValue->getProperty(id_length);
quint32 r2 = r1 ? r1->toUInt32(ctx) : 0;
Value r1 = self.property(ctx, ctx->engine->id_length);
quint32 r2 = !r1.isUndefined() ? r1.toUInt32(ctx) : 0;
if (! r2) {
self.objectValue->put(id_length, Value::fromNumber(0));
self.objectValue->setProperty(ctx, ctx->engine->id_length, Value::fromNumber(0));
} else {
String *r6 = Value::fromNumber(r2 - 1).toString(ctx);
Value *r7 = self.objectValue->getProperty(r6);
self.objectValue->deleteProperty(r6, 0);
self.objectValue->put(id_length, Value::fromNumber(2 - 1));
if (r7)
ctx->result = *r7;
Value r7 = self.property(ctx, r6);
self.objectValue->deleteProperty(ctx, r6, 0);
self.objectValue->setProperty(ctx, ctx->engine->id_length, Value::fromNumber(2 - 1));
ctx->result = r7;
}
}
}
@ -1269,16 +1265,15 @@ void ArrayPrototype::method_push(Context *ctx)
}
ctx->result = Value::fromNumber(pos);
} else {
String *id_length = ctx->engine->identifier(QLatin1String("length"));
Value *r1 = self.objectValue->getProperty(id_length);
quint32 n = r1 ? r1->toUInt32(ctx) : 0;
Value r1 = self.property(ctx, ctx->engine->id_length);
quint32 n = !r1.isUndefined() ? r1.toUInt32(ctx) : 0;
for (size_t index = 0; index < ctx->argumentCount; ++index, ++n) {
Value r3 = ctx->argument(index);
String *name = Value::fromNumber(n).toString(ctx);
self.objectValue->put(name, r3);
self.objectValue->setProperty(ctx, name, r3);
}
Value r = Value::fromNumber(n);
self.objectValue->put(id_length, r);
self.objectValue->setProperty(ctx, ctx->engine->id_length, r);
ctx->result = r;
}
}
@ -1295,7 +1290,7 @@ void ArrayPrototype::method_reverse(Context *ctx)
instance->value.assign(hi, tmp);
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.reverse"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.reverse"));
}
}
@ -1305,7 +1300,7 @@ void ArrayPrototype::method_shift(Context *ctx)
if (ArrayObject *instance = self.asArrayObject()) {
ctx->result = instance->value.takeFirst();
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.reverse"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.reverse"));
}
}
@ -1317,9 +1312,8 @@ void ArrayPrototype::method_slice(Context *ctx)
Value start = ctx->argument(0);
Value end = ctx->argument(1);
Value self = ctx->thisObject;
String *id_length = ctx->engine->identifier(QLatin1String("length"));
Value *l = self.objectValue->getProperty(id_length);
double r2 = l ? l->toNumber(ctx) : 0;
Value l = self.property(ctx, ctx->engine->id_length);
double r2 = !l.isUndefined() ? l.toNumber(ctx) : 0;
quint32 r3 = Value::toUInt32(r2);
qint32 r4 = qint32(start.toInteger(ctx));
quint32 r5 = r4 < 0 ? qMax(quint32(r3 + r4), quint32(0)) : qMin(quint32(r4), r3);
@ -1329,8 +1323,9 @@ void ArrayPrototype::method_slice(Context *ctx)
quint32 n = 0;
for (; k < r8; ++k) {
String *r11 = Value::fromNumber(k).toString(ctx);
if (Value *v = self.objectValue->getProperty(r11))
result.assign(n++, *v);
Value v = self.property(ctx, r11);
if (! v.isUndefined())
result.assign(n++, v);
}
ctx->result = Value::fromObject(ctx->engine->newArrayObject(result));
}
@ -1343,7 +1338,7 @@ void ArrayPrototype::method_sort(Context *ctx)
instance->value.sort(ctx, comparefn);
ctx->result = ctx->thisObject;
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.sort"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.sort"));
}
}
@ -1365,23 +1360,23 @@ void ArrayPrototype::method_splice(Context *ctx)
instance->value.splice(start, deleteCount, items, otherInstance->value);
ctx->result = a;
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.splice"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.splice"));
}
}
void ArrayPrototype::method_unshift(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("Array.prototype.indexOf"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.indexOf"));
}
void ArrayPrototype::method_indexOf(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("Array.prototype.indexOf"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.indexOf"));
}
void ArrayPrototype::method_lastIndexOf(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("Array.prototype.indexOf"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.indexOf"));
}
void ArrayPrototype::method_every(Context *ctx)
@ -1410,7 +1405,7 @@ void ArrayPrototype::method_every(Context *ctx)
ctx->throwTypeError();
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.every"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.every"));
}
}
@ -1440,7 +1435,7 @@ void ArrayPrototype::method_some(Context *ctx)
ctx->throwTypeError();
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.some"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.some"));
}
}
@ -1466,7 +1461,7 @@ void ArrayPrototype::method_forEach(Context *ctx)
}
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.forEach"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.forEach"));
}
}
@ -1496,7 +1491,7 @@ void ArrayPrototype::method_map(Context *ctx)
ctx->result = Value::fromObject(a);
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.map"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.map"));
}
}
@ -1529,7 +1524,7 @@ void ArrayPrototype::method_filter(Context *ctx)
ctx->result = Value::fromObject(a);
}
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.filter"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.filter"));
}
}
@ -1561,7 +1556,7 @@ void ArrayPrototype::method_reduce(Context *ctx)
}
ctx->result = acc;
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.reduce"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.reduce"));
}
}
@ -1593,7 +1588,7 @@ void ArrayPrototype::method_reduceRight(Context *ctx)
}
ctx->result = acc;
} else {
ctx->throwUnimplemented(QLatin1String("Array.prototype.reduceRight"));
ctx->throwUnimplemented(QStringLiteral("Array.prototype.reduceRight"));
}
}
@ -1607,7 +1602,7 @@ Value FunctionCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newFunctionCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newFunctionPrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newFunctionPrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -1618,28 +1613,29 @@ FunctionCtor::FunctionCtor(Context *scope)
void FunctionCtor::construct(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("Function.prototype.constructor"));
ctx->throwUnimplemented(QStringLiteral("Function.prototype.constructor"));
}
void FunctionCtor::call(Context *ctx)
{
ctx->throwUnimplemented(QLatin1String("Function"));
ctx->throwUnimplemented(QStringLiteral("Function"));
}
FunctionPrototype::FunctionPrototype(Context *ctx, FunctionObject *ctor)
: FunctionObject(ctx)
{
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString, 0);
setProperty(ctx, QLatin1String("apply"), method_apply, 0);
setProperty(ctx, QLatin1String("call"), method_call, 0);
setProperty(ctx, QLatin1String("bind"), method_bind, 0);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString, 0);
setProperty(ctx, QStringLiteral("apply"), method_apply, 0);
setProperty(ctx, QStringLiteral("call"), method_call, 0);
setProperty(ctx, QStringLiteral("bind"), method_bind, 0);
}
void FunctionPrototype::method_toString(Context *ctx)
{
if (FunctionObject *fun = ctx->thisObject.asFunctionObject()) {
ctx->result = Value::fromString(ctx, QLatin1String("function() { [code] }"));
Q_UNUSED(fun);
ctx->result = Value::fromString(ctx, QStringLiteral("function() { [code] }"));
} else {
ctx->throwTypeError();
}
@ -1648,7 +1644,8 @@ void FunctionPrototype::method_toString(Context *ctx)
void FunctionPrototype::method_apply(Context *ctx)
{
if (FunctionObject *fun = ctx->thisObject.asFunctionObject()) {
ctx->throwUnimplemented(QLatin1String("Function.prototype.apply"));
Q_UNUSED(fun);
ctx->throwUnimplemented(QStringLiteral("Function.prototype.apply"));
} else {
ctx->throwTypeError();
}
@ -1657,6 +1654,7 @@ void FunctionPrototype::method_apply(Context *ctx)
void FunctionPrototype::method_call(Context *ctx)
{
if (FunctionObject *fun = ctx->thisObject.asFunctionObject()) {
Q_UNUSED(fun);
Value thisArg = ctx->argument(0);
QVector<Value> args(ctx->argumentCount ? ctx->argumentCount - 1 : 0);
if (ctx->argumentCount)
@ -1670,7 +1668,8 @@ void FunctionPrototype::method_call(Context *ctx)
void FunctionPrototype::method_bind(Context *ctx)
{
if (FunctionObject *fun = ctx->thisObject.asFunctionObject()) {
ctx->throwUnimplemented(QLatin1String("Function.prototype.bind"));
Q_UNUSED(fun);
ctx->throwUnimplemented(QStringLiteral("Function.prototype.bind"));
} else {
ctx->throwTypeError();
}
@ -1683,7 +1682,7 @@ Value DateCtor::create(ExecutionEngine *engine)
{
Context *ctx = engine->rootContext;
FunctionObject *ctor = ctx->engine->newDateCtor(ctx);
ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newDatePrototype(ctx, ctor)));
ctor->setProperty(ctx, QStringLiteral("prototype"), Value::fromObject(ctx->engine->newDatePrototype(ctx, ctor)));
return Value::fromObject(ctor);
}
@ -1741,54 +1740,54 @@ DatePrototype::DatePrototype(Context *ctx, FunctionObject *ctor)
{
LocalTZA = getLocalTZA();
ctor->setProperty(ctx, QLatin1String("parse"), method_parse, 1);
ctor->setProperty(ctx, QLatin1String("UTC"), method_UTC, 7);
ctor->setProperty(ctx, QStringLiteral("parse"), method_parse, 1);
ctor->setProperty(ctx, QStringLiteral("UTC"), method_UTC, 7);
setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
setProperty(ctx, QLatin1String("toString"), method_toString, 0);
setProperty(ctx, QLatin1String("toDateString"), method_toDateString, 0);
setProperty(ctx, QLatin1String("toTimeString"), method_toTimeString, 0);
setProperty(ctx, QLatin1String("toLocaleString"), method_toLocaleString, 0);
setProperty(ctx, QLatin1String("toLocaleDateString"), method_toLocaleDateString, 0);
setProperty(ctx, QLatin1String("toLocaleTimeString"), method_toLocaleTimeString, 0);
setProperty(ctx, QLatin1String("valueOf"), method_valueOf, 0);
setProperty(ctx, QLatin1String("getTime"), method_getTime, 0);
setProperty(ctx, QLatin1String("getYear"), method_getYear, 0);
setProperty(ctx, QLatin1String("getFullYear"), method_getFullYear, 0);
setProperty(ctx, QLatin1String("getUTCFullYear"), method_getUTCFullYear, 0);
setProperty(ctx, QLatin1String("getMonth"), method_getMonth, 0);
setProperty(ctx, QLatin1String("getUTCMonth"), method_getUTCMonth, 0);
setProperty(ctx, QLatin1String("getDate"), method_getDate, 0);
setProperty(ctx, QLatin1String("getUTCDate"), method_getUTCDate, 0);
setProperty(ctx, QLatin1String("getDay"), method_getDay, 0);
setProperty(ctx, QLatin1String("getUTCDay"), method_getUTCDay, 0);
setProperty(ctx, QLatin1String("getHours"), method_getHours, 0);
setProperty(ctx, QLatin1String("getUTCHours"), method_getUTCHours, 0);
setProperty(ctx, QLatin1String("getMinutes"), method_getMinutes, 0);
setProperty(ctx, QLatin1String("getUTCMinutes"), method_getUTCMinutes, 0);
setProperty(ctx, QLatin1String("getSeconds"), method_getSeconds, 0);
setProperty(ctx, QLatin1String("getUTCSeconds"), method_getUTCSeconds, 0);
setProperty(ctx, QLatin1String("getMilliseconds"), method_getMilliseconds, 0);
setProperty(ctx, QLatin1String("getUTCMilliseconds"), method_getUTCMilliseconds, 0);
setProperty(ctx, QLatin1String("getTimezoneOffset"), method_getTimezoneOffset, 0);
setProperty(ctx, QLatin1String("setTime"), method_setTime, 1);
setProperty(ctx, QLatin1String("setMilliseconds"), method_setMilliseconds, 1);
setProperty(ctx, QLatin1String("setUTCMilliseconds"), method_setUTCMilliseconds, 1);
setProperty(ctx, QLatin1String("setSeconds"), method_setSeconds, 2);
setProperty(ctx, QLatin1String("setUTCSeconds"), method_setUTCSeconds, 2);
setProperty(ctx, QLatin1String("setMinutes"), method_setMinutes, 3);
setProperty(ctx, QLatin1String("setUTCMinutes"), method_setUTCMinutes, 3);
setProperty(ctx, QLatin1String("setHours"), method_setHours, 4);
setProperty(ctx, QLatin1String("setUTCHours"), method_setUTCHours, 4);
setProperty(ctx, QLatin1String("setDate"), method_setDate, 1);
setProperty(ctx, QLatin1String("setUTCDate"), method_setUTCDate, 1);
setProperty(ctx, QLatin1String("setMonth"), method_setMonth, 2);
setProperty(ctx, QLatin1String("setUTCMonth"), method_setUTCMonth, 2);
setProperty(ctx, QLatin1String("setYear"), method_setYear, 1);
setProperty(ctx, QLatin1String("setFullYear"), method_setFullYear, 3);
setProperty(ctx, QLatin1String("setUTCFullYear"), method_setUTCFullYear, 3);
setProperty(ctx, QLatin1String("toUTCString"), method_toUTCString, 0);
setProperty(ctx, QLatin1String("toGMTString"), method_toUTCString, 0);
setProperty(ctx, QStringLiteral("constructor"), Value::fromObject(ctor));
setProperty(ctx, QStringLiteral("toString"), method_toString, 0);
setProperty(ctx, QStringLiteral("toDateString"), method_toDateString, 0);
setProperty(ctx, QStringLiteral("toTimeString"), method_toTimeString, 0);
setProperty(ctx, QStringLiteral("toLocaleString"), method_toLocaleString, 0);
setProperty(ctx, QStringLiteral("toLocaleDateString"), method_toLocaleDateString, 0);
setProperty(ctx, QStringLiteral("toLocaleTimeString"), method_toLocaleTimeString, 0);
setProperty(ctx, QStringLiteral("valueOf"), method_valueOf, 0);
setProperty(ctx, QStringLiteral("getTime"), method_getTime, 0);
setProperty(ctx, QStringLiteral("getYear"), method_getYear, 0);
setProperty(ctx, QStringLiteral("getFullYear"), method_getFullYear, 0);
setProperty(ctx, QStringLiteral("getUTCFullYear"), method_getUTCFullYear, 0);
setProperty(ctx, QStringLiteral("getMonth"), method_getMonth, 0);
setProperty(ctx, QStringLiteral("getUTCMonth"), method_getUTCMonth, 0);
setProperty(ctx, QStringLiteral("getDate"), method_getDate, 0);
setProperty(ctx, QStringLiteral("getUTCDate"), method_getUTCDate, 0);
setProperty(ctx, QStringLiteral("getDay"), method_getDay, 0);
setProperty(ctx, QStringLiteral("getUTCDay"), method_getUTCDay, 0);
setProperty(ctx, QStringLiteral("getHours"), method_getHours, 0);
setProperty(ctx, QStringLiteral("getUTCHours"), method_getUTCHours, 0);
setProperty(ctx, QStringLiteral("getMinutes"), method_getMinutes, 0);
setProperty(ctx, QStringLiteral("getUTCMinutes"), method_getUTCMinutes, 0);
setProperty(ctx, QStringLiteral("getSeconds"), method_getSeconds, 0);
setProperty(ctx, QStringLiteral("getUTCSeconds"), method_getUTCSeconds, 0);
setProperty(ctx, QStringLiteral("getMilliseconds"), method_getMilliseconds, 0);
setProperty(ctx, QStringLiteral("getUTCMilliseconds"), method_getUTCMilliseconds, 0);
setProperty(ctx, QStringLiteral("getTimezoneOffset"), method_getTimezoneOffset, 0);
setProperty(ctx, QStringLiteral("setTime"), method_setTime, 1);
setProperty(ctx, QStringLiteral("setMilliseconds"), method_setMilliseconds, 1);
setProperty(ctx, QStringLiteral("setUTCMilliseconds"), method_setUTCMilliseconds, 1);
setProperty(ctx, QStringLiteral("setSeconds"), method_setSeconds, 2);
setProperty(ctx, QStringLiteral("setUTCSeconds"), method_setUTCSeconds, 2);
setProperty(ctx, QStringLiteral("setMinutes"), method_setMinutes, 3);
setProperty(ctx, QStringLiteral("setUTCMinutes"), method_setUTCMinutes, 3);
setProperty(ctx, QStringLiteral("setHours"), method_setHours, 4);
setProperty(ctx, QStringLiteral("setUTCHours"), method_setUTCHours, 4);
setProperty(ctx, QStringLiteral("setDate"), method_setDate, 1);
setProperty(ctx, QStringLiteral("setUTCDate"), method_setUTCDate, 1);
setProperty(ctx, QStringLiteral("setMonth"), method_setMonth, 2);
setProperty(ctx, QStringLiteral("setUTCMonth"), method_setUTCMonth, 2);
setProperty(ctx, QStringLiteral("setYear"), method_setYear, 1);
setProperty(ctx, QStringLiteral("setFullYear"), method_setFullYear, 3);
setProperty(ctx, QStringLiteral("setUTCFullYear"), method_setUTCFullYear, 3);
setProperty(ctx, QStringLiteral("toUTCString"), method_toUTCString, 0);
setProperty(ctx, QStringLiteral("toGMTString"), method_toUTCString, 0);
}
double DatePrototype::getThisDate(Context *ctx)
@ -1803,14 +1802,17 @@ double DatePrototype::getThisDate(Context *ctx)
void DatePrototype::method_MakeTime(Context *ctx)
{
ctx->throwUnimplemented(QStringLiteral("Data.MakeTime"));
}
void DatePrototype::method_MakeDate(Context *ctx)
{
ctx->throwUnimplemented(QStringLiteral("Data.MakeDate"));
}
void DatePrototype::method_TimeClip(Context *ctx)
{
ctx->throwUnimplemented(QStringLiteral("Data.TimeClip"));
}
void DatePrototype::method_parse(Context *ctx)
@ -2276,33 +2278,33 @@ void DatePrototype::method_toUTCString(Context *ctx)
//
MathObject::MathObject(Context *ctx)
{
setProperty(ctx, QLatin1String("E"), Value::fromNumber(::exp(1.0)));
setProperty(ctx, QLatin1String("LN2"), Value::fromNumber(::log(2.0)));
setProperty(ctx, QLatin1String("LN10"), Value::fromNumber(::log(10.0)));
setProperty(ctx, QLatin1String("LOG2E"), Value::fromNumber(1.0/::log(2.0)));
setProperty(ctx, QLatin1String("LOG10E"), Value::fromNumber(1.0/::log(10.0)));
setProperty(ctx, QLatin1String("PI"), Value::fromNumber(qt_PI));
setProperty(ctx, QLatin1String("SQRT1_2"), Value::fromNumber(::sqrt(0.5)));
setProperty(ctx, QLatin1String("SQRT2"), Value::fromNumber(::sqrt(2.0)));
setProperty(ctx, QStringLiteral("E"), Value::fromNumber(::exp(1.0)));
setProperty(ctx, QStringLiteral("LN2"), Value::fromNumber(::log(2.0)));
setProperty(ctx, QStringLiteral("LN10"), Value::fromNumber(::log(10.0)));
setProperty(ctx, QStringLiteral("LOG2E"), Value::fromNumber(1.0/::log(2.0)));
setProperty(ctx, QStringLiteral("LOG10E"), Value::fromNumber(1.0/::log(10.0)));
setProperty(ctx, QStringLiteral("PI"), Value::fromNumber(qt_PI));
setProperty(ctx, QStringLiteral("SQRT1_2"), Value::fromNumber(::sqrt(0.5)));
setProperty(ctx, QStringLiteral("SQRT2"), Value::fromNumber(::sqrt(2.0)));
setProperty(ctx, QLatin1String("abs"), method_abs, 1);
setProperty(ctx, QLatin1String("acos"), method_acos, 1);
setProperty(ctx, QLatin1String("asin"), method_asin, 0);
setProperty(ctx, QLatin1String("atan"), method_atan, 1);
setProperty(ctx, QLatin1String("atan2"), method_atan2, 2);
setProperty(ctx, QLatin1String("ceil"), method_ceil, 1);
setProperty(ctx, QLatin1String("cos"), method_cos, 1);
setProperty(ctx, QLatin1String("exp"), method_exp, 1);
setProperty(ctx, QLatin1String("floor"), method_floor, 1);
setProperty(ctx, QLatin1String("log"), method_log, 1);
setProperty(ctx, QLatin1String("max"), method_max, 2);
setProperty(ctx, QLatin1String("min"), method_min, 2);
setProperty(ctx, QLatin1String("pow"), method_pow, 2);
setProperty(ctx, QLatin1String("random"), method_random, 0);
setProperty(ctx, QLatin1String("round"), method_round, 1);
setProperty(ctx, QLatin1String("sin"), method_sin, 1);
setProperty(ctx, QLatin1String("sqrt"), method_sqrt, 1);
setProperty(ctx, QLatin1String("tan"), method_tan, 1);
setProperty(ctx, QStringLiteral("abs"), method_abs, 1);
setProperty(ctx, QStringLiteral("acos"), method_acos, 1);
setProperty(ctx, QStringLiteral("asin"), method_asin, 0);
setProperty(ctx, QStringLiteral("atan"), method_atan, 1);
setProperty(ctx, QStringLiteral("atan2"), method_atan2, 2);
setProperty(ctx, QStringLiteral("ceil"), method_ceil, 1);
setProperty(ctx, QStringLiteral("cos"), method_cos, 1);
setProperty(ctx, QStringLiteral("exp"), method_exp, 1);
setProperty(ctx, QStringLiteral("floor"), method_floor, 1);
setProperty(ctx, QStringLiteral("log"), method_log, 1);
setProperty(ctx, QStringLiteral("max"), method_max, 2);
setProperty(ctx, QStringLiteral("min"), method_min, 2);
setProperty(ctx, QStringLiteral("pow"), method_pow, 2);
setProperty(ctx, QStringLiteral("random"), method_random, 0);
setProperty(ctx, QStringLiteral("round"), method_round, 1);
setProperty(ctx, QStringLiteral("sin"), method_sin, 1);
setProperty(ctx, QStringLiteral("sqrt"), method_sqrt, 1);
setProperty(ctx, QStringLiteral("tan"), method_tan, 1);
}
/* copies the sign from y to x and returns the result */

View File

@ -211,15 +211,15 @@ QString String::escape(const QString &s)
for (int i = 0; i < s.length(); ++i) {
const QChar ch = s.at(i);
if (ch == QLatin1Char('\n'))
r += QLatin1String("\\n");
r += QStringLiteral("\\n");
else if (ch == QLatin1Char('\r'))
r += QLatin1String("\\r");
r += QStringLiteral("\\r");
else if (ch == QLatin1Char('\\'))
r += QLatin1String("\\\\");
r += QStringLiteral("\\\\");
else if (ch == QLatin1Char('"'))
r += QLatin1String("\\\"");
r += QStringLiteral("\\\"");
else if (ch == QLatin1Char('\''))
r += QLatin1String("\\'");
r += QStringLiteral("\\'");
else
r += ch;
}

View File

@ -611,8 +611,8 @@ struct Function {
: module(module)
, pool(&module->pool)
, tempCount(0)
, handlersBlock(0)
, maxNumberOfArguments(0)
, handlersBlock(0)
, code(0)
, hasDirectEval(false)
, hasNestedFunctions(false)

View File

@ -506,7 +506,7 @@ void InstructionSelection::visitMove(IR::Move *s)
if (IR::Name *n = s->source->asName()) {
amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8);
loadTempAddress(AMD64_RSI, t);
if (*n->id == QLatin1String("this")) { // ### `this' should be a builtin.
if (*n->id == QStringLiteral("this")) { // ### `this' should be a builtin.
amd64_call_code(_codePtr, __qmljs_get_thisObject);
} else {
String *propertyName = identifier(*n->id);