From ddba8f6bb06f0f2312a8c070f8cf4a9e079c9ca7 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 29 Oct 2012 15:37:02 +0100 Subject: [PATCH] Conformant implementation of the object internal methods See section 8.12 of the standard. This implements 8.12.1 - 8.12.7 and 8.12.9 Also gave these methods standard conformant names. They are marked as [[foo]] in the standard, which translates to __foo__ in our code. Change-Id: I1990d6c6dd24e929c23d5c51d36f1e2e0a0a3b63 Reviewed-by: Simon Hausmann --- main.cpp | 6 +- qmljs_objects.cpp | 274 +++++++++++++++++++++++++++------------- qmljs_objects.h | 112 ++++++++++++----- qmljs_runtime.cpp | 82 ++++++------ qv4ecmaobjects.cpp | 364 ++++++++++++++++++++++++++--------------------------- qv4ecmaobjects_p.h | 2 +- 6 files changed, 496 insertions(+), 344 deletions(-) diff --git a/main.cpp b/main.cpp index bdd5b37..91247b8 100644 --- a/main.cpp +++ b/main.cpp @@ -247,7 +247,7 @@ static void evaluate(QQmlJS::VM::Context *ctx, const QString &fileName, const QS ctx->activation = VM::Value::fromObject(new QQmlJS::VM::Object()); foreach (const QString *local, globalCode->locals) { - ctx->activation.objectValue()->setProperty(ctx, *local, QQmlJS::VM::Value::undefinedValue()); + ctx->activation.objectValue()->__put__(ctx, *local, QQmlJS::VM::Value::undefinedValue()); } void * buf = __qmljs_create_exception_handler(ctx); @@ -297,10 +297,10 @@ int main(int argc, char *argv[]) QQmlJS::VM::Context *ctx = vm.rootContext; QQmlJS::VM::Object *globalObject = vm.globalObject.objectValue(); - globalObject->setProperty(ctx, vm.identifier(QStringLiteral("print")), + globalObject->__put__(ctx, vm.identifier(QStringLiteral("print")), QQmlJS::VM::Value::fromObject(new builtins::Print(ctx))); - globalObject->setProperty(ctx, vm.identifier(QStringLiteral("eval")), + globalObject->__put__(ctx, vm.identifier(QStringLiteral("eval")), QQmlJS::VM::Value::fromObject(new builtins::Eval(ctx))); foreach (const QString &fn, args) { diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index bc8aa9f..ecf97c4 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -58,82 +58,61 @@ Object::~Object() delete members; } -void Object::setProperty(Context *ctx, const QString &name, const Value &value) +void Object::__put__(Context *ctx, const QString &name, const Value &value) { - setProperty(ctx, ctx->engine->identifier(name), value); + __put__(ctx, ctx->engine->identifier(name), value); } -void Object::setProperty(Context *ctx, const QString &name, void (*code)(Context *), int count) +void Object::__put__(Context *ctx, const QString &name, void (*code)(Context *), int count) { Q_UNUSED(count); - setProperty(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code))); -} - -Value Object::getProperty(Context *ctx, String *name) -{ - if (name->isEqualTo(ctx->engine->id___proto__)) - return Value::fromObject(prototype); - - PropertyDescriptor tmp; - if (PropertyDescriptor *p = getPropertyDescriptor(ctx, name, &tmp)) { - if (p->isData()) - return p->value; - if (!p->get) - return Value::undefinedValue(); - FunctionObject *f = p->get->asFunctionObject(); - if (f) { - f->call(ctx); - return ctx->result; - } - } - return Value::undefinedValue(); + __put__(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code))); } // Section 8.12.1 -PropertyDescriptor *Object::getOwnProperty(Context *, String *name) +PropertyDescriptor *Object::__getOwnProperty__(Context *, String *name) { if (members) return members->find(name); return 0; } -PropertyDescriptor *Object::getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill) +// Section 8.12.2 +PropertyDescriptor *Object::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill) { - if (PropertyDescriptor *p = getOwnProperty(ctx, name)) + if (PropertyDescriptor *p = __getOwnProperty__(ctx, name)) return p; if (prototype) - return prototype->getPropertyDescriptor(ctx, name, to_fill); + return prototype->__getPropertyDescriptor__(ctx, name, to_fill); return 0; } -// Section 8.12.5 -void Object::setProperty(Context *ctx, String *name, const Value &value, bool throwException) +// Section 8.12.3 +Value Object::__get__(Context *ctx, String *name) { - if (!canSetProperty(ctx, name)) { - if (throwException) - __qmljs_throw_type_error(ctx); - return; - } - - if (!members) - members = new PropertyTable(); + if (name->isEqualTo(ctx->engine->id___proto__)) + return Value::fromObject(prototype); - PropertyDescriptor *pd = getOwnProperty(ctx, name); - if (pd) { - if (pd->isData()) { - pd->value = value; - return; + PropertyDescriptor tmp; + if (PropertyDescriptor *p = __getPropertyDescriptor__(ctx, name, &tmp)) { + if (p->isData()) + return p->value; + if (!p->get) + return Value::undefinedValue(); + FunctionObject *f = p->get->asFunctionObject(); + if (f) { + f->call(ctx); + return ctx->result; } } - PropertyDescriptor *p = members->insert(name); - *p = PropertyDescriptor::fromValue(value); + return Value::undefinedValue(); } // Section 8.12.4 -bool Object::canSetProperty(Context *ctx, String *name) +bool Object::__canPut__(Context *ctx, String *name) { - if (PropertyDescriptor *p = getOwnProperty(ctx, name)) { + if (PropertyDescriptor *p = __getOwnProperty__(ctx, name)) { if (p->isAccessor()) return p->get != 0; return p->isWritable(); @@ -143,7 +122,7 @@ bool Object::canSetProperty(Context *ctx, String *name) return extensible; PropertyDescriptor tmp; - if (PropertyDescriptor *p = prototype->getPropertyDescriptor(ctx, name, &tmp)) { + if (PropertyDescriptor *p = prototype->__getPropertyDescriptor__(ctx, name, &tmp)) { if (p->isAccessor()) return p->get != 0; if (!extensible) @@ -155,37 +134,164 @@ bool Object::canSetProperty(Context *ctx, String *name) return true; } -bool Object::hasProperty(Context *ctx, String *name) const +// Section 8.12.5 +void Object::__put__(Context *ctx, String *name, const Value &value, bool throwException) { - if (members) - return members->find(name) != 0; + // clause 1 + if (!__canPut__(ctx, name)) + goto reject; - return prototype ? prototype->hasProperty(ctx, name) : false; + if (!members) + members = new PropertyTable(); + + { + // Clause 2 + PropertyDescriptor *pd = __getOwnProperty__(ctx, name); + // Clause 3 + if (pd && pd->isData()) { + // spec says to call [[DefineOwnProperty]] with { [[Value]]: value } + + // ### to simplify and speed up we should expand the relevant parts here (clauses 6,7,9,10,12,13) + PropertyDescriptor desc = PropertyDescriptor::fromValue(value); + desc.configurable = PropertyDescriptor::Undefined; + desc.enumberable = PropertyDescriptor::Undefined; + desc.writable = PropertyDescriptor::Undefined; + __defineOwnProperty__(ctx, name, &desc, throwException); + return; + } + + // clause 4 + PropertyDescriptor tmp; + if (prototype) + pd = prototype->__getPropertyDescriptor__(ctx, name, &tmp); + + // Clause 5 + if (pd && pd->isAccessor()) { + assert(pd->set != 0); + FunctionObject *func = pd->set->asFunctionObject(); + assert(func); + + // ### unify with callFunction method + Context k; + Context *c = func->needsActivation ? ctx->engine->newContext() : &k; + Value that = Value::fromObject(this); + Value args[1]; + args[0] = value; + c->initCallContext(ctx, &that, func, args, 1); + func->call(c); + c->leaveCallContext(); + return; + } + + PropertyDescriptor *p = members->insert(name); + *p = PropertyDescriptor::fromValue(value); + } + + reject: + if (throwException) + __qmljs_throw_type_error(ctx); } -bool Object::deleteProperty(Context *, String *name, bool flag) +// Section 8.12.6 +bool Object::__hasProperty__(Context *ctx, String *name) const { - Q_UNUSED(flag); - if (members) - return members->remove(name); + return members->find(name) != 0; - return false; + return prototype ? prototype->__hasProperty__(ctx, name) : false; } -bool Object::defineOwnProperty(Context *ctx, String *name, const Value &getter, const Value &setter, bool flag) +// Section 8.12.7 +bool Object::__delete__(Context *ctx, String *name, bool throwException) +{ + if (members) { + if (PropertyTableEntry *entry = members->findEntry(name)) { + if (entry->descriptor.isConfigurable()) { + members->remove(entry); + return true; + } + if (throwException) + __qmljs_throw_type_error(ctx); + return false; + } + } + return true; +} + +// Section 8.12.9 +bool Object::__defineOwnProperty__(Context *ctx, String *name, PropertyDescriptor *desc, bool throwException) { if (!members) members = new PropertyTable(); - PropertyDescriptor *p = getOwnProperty(ctx, name); - if (!p) { + // Clause 1 + PropertyDescriptor *current = __getOwnProperty__(ctx, name); + if (!current) { + // clause 3 if (!extensible) goto reject; + // clause 4 + *current = *desc; + current->fullyPopulated(); + return true; + } + + // clause 5 + if (desc->isEmpty()) + return true; + + // clause 6 + if (desc->isSubset(current)) + return true; + + // clause 7 + if (!current->isConfigurable()) { + if (desc->isConfigurable()) + goto reject; + if (desc->enumberable != PropertyDescriptor::Unset && desc->enumberable != current->enumberable) + goto reject; } + // clause 8 + if (desc->isGeneric()) + goto accept; + + // clause 9 + if (current->isData() != desc->isData()) { + // 9a + if (!current->isConfigurable()) + goto reject; + if (current->isData()) { + // 9b + current->type = PropertyDescriptor::Accessor; + current->writable = PropertyDescriptor::Undefined; + current->get = 0; + current->set = 0; + } else { + // 9c + current->type = PropertyDescriptor::Data; + current->writable = PropertyDescriptor::Unset; + current->value = Value::undefinedValue(); + } + } else if (current->isData() && desc->isData()) { // clause 10 + if (!current->isConfigurable() && !current->isWritable()) { + if (desc->isWritable() || !current->value.sameValue(desc->value)) + goto reject; + } + } else { // clause 10 + assert(current->isAccessor() && desc->isAccessor()); + if (!current->isConfigurable()) { + if (current->get != desc->get || current->set != desc->set) + goto reject; + } + } + + accept: + + *current += *desc; + return true; reject: - if (flag) + if (throwException) __qmljs_throw_type_error(ctx); return false; } @@ -211,11 +317,11 @@ String *ForEachIteratorObject::nextPropertyName() } } -Value ArrayObject::getProperty(Context *ctx, String *name) +Value ArrayObject::__get__(Context *ctx, String *name) { if (name->isEqualTo(ctx->engine->id_length)) return Value::fromDouble(value.size()); - return Object::getProperty(ctx, name); + return Object::__get__(ctx, name); } bool FunctionObject::hasInstance(Context *ctx, const Value &value) @@ -225,7 +331,7 @@ bool FunctionObject::hasInstance(Context *ctx, const Value &value) return false; } - Value o = getProperty(ctx, ctx->engine->id_prototype); + Value o = __get__(ctx, ctx->engine->id_prototype); if (! o.isObject()) { ctx->throwTypeError(); return false; @@ -290,7 +396,7 @@ void ScriptFunction::call(VM::Context *ctx) function->code(ctx, function->codeData); } -Value RegExpObject::getProperty(Context *ctx, String *name) +Value RegExpObject::__get__(Context *ctx, String *name) { QString n = name->toQString(); if (n == QLatin1String("source")) @@ -303,21 +409,21 @@ Value RegExpObject::getProperty(Context *ctx, String *name) return Value::fromBoolean(value.patternOptions() & QRegularExpression::MultilineOption); else if (n == QLatin1String("lastIndex")) return lastIndex; - return Object::getProperty(ctx, name); + return Object::__get__(ctx, name); } void ScriptFunction::construct(VM::Context *ctx) { Object *obj = ctx->engine->newObject(); - Value proto = getProperty(ctx, ctx->engine->id_prototype); + Value proto = __get__(ctx, ctx->engine->id_prototype); if (proto.isObject()) obj->prototype = proto.objectValue(); ctx->thisObject = Value::fromObject(obj); function->code(ctx, function->codeData); } -PropertyDescriptor *ActivationObject::getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill) +PropertyDescriptor *ActivationObject::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill) { if (context) { for (unsigned int i = 0; i < context->varCount; ++i) { @@ -347,17 +453,17 @@ PropertyDescriptor *ActivationObject::getPropertyDescriptor(Context *ctx, String } } - return Object::getPropertyDescriptor(ctx, name, to_fill); + return Object::__getPropertyDescriptor__(ctx, name, to_fill); } -Value ArgumentsObject::getProperty(Context *ctx, String *name) +Value ArgumentsObject::__get__(Context *ctx, String *name) { if (name->isEqualTo(ctx->engine->id_length)) return Value::fromDouble(context->argumentCount); - return Object::getProperty(ctx, name); + return Object::__get__(ctx, name); } -PropertyDescriptor *ArgumentsObject::getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill) +PropertyDescriptor *ArgumentsObject::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill) { if (context) { const quint32 i = Value::fromString(name).toUInt32(ctx); @@ -367,7 +473,7 @@ PropertyDescriptor *ArgumentsObject::getPropertyDescriptor(Context *ctx, String } } - return Object::getPropertyDescriptor(ctx, name, to_fill); + return Object::__getPropertyDescriptor__(ctx, name, to_fill); } ExecutionEngine::ExecutionEngine() @@ -431,15 +537,15 @@ ExecutionEngine::ExecutionEngine() globalObject = Value::fromObject(glo); rootContext->activation = Value::fromObject(glo); - 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("Boolean")), booleanCtor); - 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))); + glo->__put__(rootContext, identifier(QStringLiteral("Object")), objectCtor); + glo->__put__(rootContext, identifier(QStringLiteral("String")), stringCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Number")), numberCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Boolean")), booleanCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Array")), arrayCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Function")), functionCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Date")), dateCtor); + glo->__put__(rootContext, identifier(QStringLiteral("RegExp")), regExpCtor); + glo->__put__(rootContext, identifier(QStringLiteral("Math")), Value::fromObject(newMathObject(rootContext))); } Context *ExecutionEngine::newContext() @@ -466,8 +572,8 @@ FunctionObject *ExecutionEngine::newScriptFunction(Context *scope, IR::Function { ScriptFunction *f = new ScriptFunction(scope, function); Object *proto = scope->engine->newObject(); - proto->setProperty(scope, scope->engine->id_constructor, Value::fromObject(f)); - f->setProperty(scope, scope->engine->id_prototype, Value::fromObject(proto)); + proto->__put__(scope, scope->engine->id_constructor, Value::fromObject(f)); + f->__put__(scope, scope->engine->id_prototype, Value::fromObject(proto)); f->prototype = scope->engine->functionPrototype; return f; } diff --git a/qmljs_objects.h b/qmljs_objects.h index 425cbd5..0760591 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -154,6 +154,24 @@ struct PropertyDescriptor { return pd; } + // Section 8.10 + inline void fullyPopulated() { + if (type == Generic) { + type = Data; + value = Value::undefinedValue(); + } + if (type == Data) { + if (writable == Undefined) + writable = Unset; + } else { + writable = Undefined; + } + if (enumberable == Undefined) + enumberable = Unset; + if (configurable == Undefined) + configurable = Unset; + } + inline bool isData() const { return type == Data; } inline bool isAccessor() const { return type == Accessor; } inline bool isGeneric() const { return type == Generic; } @@ -161,6 +179,40 @@ struct PropertyDescriptor { inline bool isWritable() const { return writable == Set; } inline bool isEnumerable() const { return enumberable == Set; } inline bool isConfigurable() const { return configurable == Set; } + + inline bool isEmpty() { + return type == Generic && writable == Undefined && enumberable == Undefined && configurable == Undefined; + } + inline bool isSubset(PropertyDescriptor *other) { + if (type != other->type) + return false; + if (enumberable != Undefined && enumberable != other->enumberable) + return false; + if (configurable != Undefined && configurable != other->configurable) + return false; + if (writable != Undefined && writable != other->writable) + return false; + if (type == Data && !value.sameValue(other->value)) + return false; + if (type == Accessor && (get != other->get || set != other->set)) + return false; + return true; + } + inline void operator+=(const PropertyDescriptor &other) { + type = other.type; + if (other.enumberable != Undefined) + enumberable = other.enumberable; + if (other.configurable != Undefined) + configurable = other.configurable; + if (other.writable != Undefined) + writable = other.writable; + if (type == Accessor) { + get = other.get; + set = other.set; + } else { + value = other.value; + } + } }; struct PropertyTableEntry { @@ -205,29 +257,23 @@ public: inline iterator begin() const { return _properties; } inline iterator end() const { return _properties + (_propertyCount + 1); } - bool remove(String *name) + void remove(PropertyTableEntry *prop) { - if (PropertyTableEntry *prop = findEntry(name)) { - // ### TODO check if the property can be removed - - PropertyTableEntry *bucket = _buckets[prop->hashValue() % _bucketCount]; - if (bucket == prop) { - bucket = bucket->next; - } else { - for (PropertyTableEntry *it = bucket; it; it = it->next) { - if (it->next == prop) { - it->next = it->next->next; - break; - } + PropertyTableEntry *bucket = _buckets[prop->hashValue() % _bucketCount]; + if (bucket == prop) { + bucket = bucket->next; + } else { + for (PropertyTableEntry *it = bucket; it; it = it->next) { + if (it->next == prop) { + it->next = it->next->next; + break; } } - - _properties[prop->index] = 0; - prop->next = _freeList; - _freeList = prop; } - return true; + _properties[prop->index] = 0; + prop->next = _freeList; + _freeList = prop; } PropertyTableEntry *findEntry(String *name) const @@ -349,20 +395,20 @@ struct Object { virtual ActivationObject *asActivationObject() { return 0; } virtual ArgumentsObject *asArgumentsObject() { return 0; } - virtual Value getProperty(Context *ctx, String *name); - virtual PropertyDescriptor *getOwnProperty(Context *ctx, String *name); - virtual PropertyDescriptor *getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill); - virtual void setProperty(Context *ctx, String *name, const Value &value, bool throwException = 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 bool defineOwnProperty(Context *ctx, String *name, const Value &getter, const Value &setter, bool flag = false); + virtual Value __get__(Context *ctx, String *name); + virtual PropertyDescriptor *__getOwnProperty__(Context *ctx, String *name); + virtual PropertyDescriptor *__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill); + virtual void __put__(Context *ctx, String *name, const Value &value, bool throwException = false); + virtual bool __canPut__(Context *ctx, String *name); + virtual bool __hasProperty__(Context *ctx, String *name) const; + virtual bool __delete__(Context *ctx, String *name, bool throwException); + virtual bool __defineOwnProperty__(Context *ctx, String *name, PropertyDescriptor *desc, bool throwException = false); // // helpers // - void setProperty(Context *ctx, const QString &name, const Value &value); - void setProperty(Context *ctx, const QString &name, void (*code)(Context *), int count = 0); + void __put__(Context *ctx, const QString &name, const Value &value); + void __put__(Context *ctx, const QString &name, void (*code)(Context *), int count = 0); }; struct ForEachIteratorObject: Object { @@ -409,7 +455,7 @@ struct ArrayObject: Object { ArrayObject(const Array &value): value(value) {} virtual QString className() { return QStringLiteral("Array"); } virtual ArrayObject *asArrayObject() { return this; } - virtual Value getProperty(Context *ctx, String *name); + virtual Value __get__(Context *ctx, String *name); }; struct FunctionObject: Object { @@ -462,7 +508,7 @@ struct RegExpObject: Object { RegExpObject(const QRegularExpression &value, bool global): value(value), lastIndex(Value::fromInt32(0)), global(global) {} virtual QString className() { return QStringLiteral("RegExp"); } virtual RegExpObject *asRegExpObject() { return this; } - virtual Value getProperty(Context *ctx, String *name); + virtual Value __get__(Context *ctx, String *name); }; struct ErrorObject: Object { @@ -478,7 +524,7 @@ struct ActivationObject: Object { ActivationObject(Context *context): context(context), arguments(Value::undefinedValue()) {} virtual QString className() { return QStringLiteral("Activation"); } virtual ActivationObject *asActivationObject() { return this; } - virtual PropertyDescriptor *getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill); + virtual PropertyDescriptor *__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill); }; struct ArgumentsObject: Object { @@ -486,8 +532,8 @@ struct ArgumentsObject: Object { ArgumentsObject(Context *context): context(context) {} virtual QString className() { return QStringLiteral("Arguments"); } virtual ArgumentsObject *asArgumentsObject() { return this; } - virtual Value getProperty(Context *ctx, String *name); - virtual PropertyDescriptor *getPropertyDescriptor(Context *ctx, String *name, PropertyDescriptor *to_fill); + virtual Value __get__(Context *ctx, String *name); + virtual PropertyDescriptor *__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill); }; struct ExecutionEngine diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 8acaec3..5291d45 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -232,7 +232,7 @@ ActivationObject *Value::asArgumentsObject() const Value Value::property(Context *ctx, String *name) const { - return isObject() ? objectValue()->getProperty(ctx, name) : undefinedValue(); + return isObject() ? objectValue()->__get__(ctx, name) : undefinedValue(); } void Context::init(ExecutionEngine *eng) @@ -257,7 +257,7 @@ Value *Context::lookupPropertyDescriptor(String *name) for (Context *ctx = this; ctx; ctx = ctx->parent) { if (ctx->activation.isObject()) { PropertyDescriptor tmp; - if (PropertyDescriptor *pd = ctx->activation.objectValue()->getPropertyDescriptor(this, name, &tmp)) { + if (PropertyDescriptor *pd = ctx->activation.objectValue()->__getPropertyDescriptor__(this, name, &tmp)) { return &pd->value; } } @@ -351,7 +351,7 @@ void Context::leaveConstructorContext(FunctionObject *f) assert(thisObject.isObject()); result = thisObject; - Value proto = f->getProperty(this, engine->id_prototype); + Value proto = f->__get__(this, engine->id_prototype); thisObject.objectValue()->prototype = proto.objectValue(); if (! thisObject.isObject()) thisObject.objectValue()->prototype = engine->objectPrototype; @@ -439,7 +439,7 @@ Value __qmljs_delete_subscript(Context *ctx, Value base, Value index) Value __qmljs_delete_member(Context *ctx, Value base, String *name) { Value obj = base.toObject(ctx); - return Value::fromBoolean(obj.objectValue()->deleteProperty(ctx, name, true)); + return Value::fromBoolean(obj.objectValue()->__delete__(ctx, name, true)); } Value __qmljs_delete_property(Context *ctx, String *name) @@ -447,7 +447,7 @@ Value __qmljs_delete_property(Context *ctx, String *name) Value obj = ctx->activation; if (! obj.isObject()) obj = ctx->engine->globalObject; - return Value::fromBoolean(obj.objectValue()->deleteProperty(ctx, name, true)); + return Value::fromBoolean(obj.objectValue()->__delete__(ctx, name, true)); } Value __qmljs_delete_value(Context *ctx, Value value) @@ -487,7 +487,7 @@ Value __qmljs_in(Value left, Value right, Context *ctx) { if (right.isObject()) { Value s = __qmljs_to_string(left, ctx); - bool r = right.objectValue()->hasProperty(ctx, s.stringValue()); + bool r = right.objectValue()->__hasProperty__(ctx, s.stringValue()); return Value::fromBoolean(r); } else { return __qmljs_throw_type_error(ctx); @@ -750,89 +750,89 @@ void __qmljs_inplace_ushr_element(Value base, Value index, Value value, Context void __qmljs_inplace_bit_and_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_bit_and(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_bit_or_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_bit_or(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_bit_xor_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_bit_xor(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_add_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_add(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_sub_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_sub(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_mul_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_mul(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_div_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_div(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_mod_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_mod(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_shl_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_shl(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_shr_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_shr(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } void __qmljs_inplace_ushr_member(Value value, Value base, String *name, Context *ctx) { Object *o = base.objectValue(); - Value prop = o->getProperty(ctx, name); + Value prop = o->__get__(ctx, name); prop = __qmljs_ushr(prop, value, ctx); - o->setProperty(ctx, name, prop); + o->__put__(ctx, name, prop); } String *__qmljs_string_from_utf8(Context *ctx, const char *s) @@ -903,14 +903,14 @@ Value __qmljs_object_default_value(Context *ctx, Value object, int typeHint) assert(object.isObject()); Object *oo = object.objectValue(); - Value conv = oo->getProperty(ctx, meth1); + Value conv = oo->__get__(ctx, meth1); if (FunctionObject *f = conv.asFunctionObject()) { Value r = callFunction(ctx, object, f, 0, 0); if (r.isPrimitive()) return r; } - conv = oo->getProperty(ctx, meth2); + conv = oo->__get__(ctx, meth2); if (FunctionObject *f = conv.asFunctionObject()) { Value r = callFunction(ctx, object, f, 0, 0); if (r.isPrimitive()) @@ -951,33 +951,33 @@ Value __qmljs_new_string_object(Context *ctx, String *string) void __qmljs_set_property(Context *ctx, Value object, String *name, Value value) { - object.objectValue()->setProperty(ctx, name, value, /*flags*/ 0); + object.objectValue()->__put__(ctx, name, value, /*flags*/ 0); } void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool b) { Value value = Value::fromBoolean(b); - object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0); + object->objectValue()->__put__(ctx, name, value, /*flag*/ 0); } void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double number) { Q_UNUSED(ctx); Value value = Value::fromDouble(number); - object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0); + object->objectValue()->__put__(ctx, name, value, /*flag*/ 0); } void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *s) { Q_UNUSED(ctx); Value value = Value::fromString(s); - object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0); + object->objectValue()->__put__(ctx, name, value, /*flag*/ 0); } void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function) { Value value = __qmljs_init_closure(function, ctx); - object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0); + object->objectValue()->__put__(ctx, name, value, /*flag*/ 0); } Value __qmljs_get_element(Context *ctx, Value object, Value index) @@ -1000,7 +1000,7 @@ Value __qmljs_get_element(Context *ctx, Value object, Value index) if (! object.isObject()) object = __qmljs_to_object(object, ctx); - return object.objectValue()->getProperty(ctx, name); + return object.objectValue()->__get__(ctx, name); } void __qmljs_set_element(Context *ctx, Value object, Value index, Value value) @@ -1017,7 +1017,7 @@ void __qmljs_set_element(Context *ctx, Value object, Value index, Value value) if (! object.isObject()) object = __qmljs_to_object(object, ctx); - object.objectValue()->setProperty(ctx, name, value, /*flags*/ 0); + object.objectValue()->__put__(ctx, name, value, /*flags*/ 0); } Value __qmljs_foreach_iterator_object(Value in, Context *ctx) @@ -1046,7 +1046,7 @@ void __qmljs_set_activation_property(Context *ctx, String *name, Value value) if (Value *prop = ctx->lookupPropertyDescriptor(name)) *prop = value; else - ctx->engine->globalObject.objectValue()->setProperty(ctx, name, value); + ctx->engine->globalObject.objectValue()->__put__(ctx, name, value); } void __qmljs_set_activation_property_boolean(Context *ctx, String *name, bool b) @@ -1076,14 +1076,14 @@ void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Fun Value __qmljs_get_property(Context *ctx, Value object, String *name) { if (object.isObject()) { - return object.objectValue()->getProperty(ctx, name); + return object.objectValue()->__get__(ctx, name); } else if (object.isString() && name->isEqualTo(ctx->engine->id_length)) { return Value::fromInt32(object.stringValue()->toQString().length()); } else { object = __qmljs_to_object(object, ctx); if (object.isObject()) { - return object.objectValue()->getProperty(ctx, name); + return object.objectValue()->__get__(ctx, name); } else { ctx->throwTypeError(); return Value::undefinedValue(); @@ -1225,7 +1225,7 @@ Value __qmljs_construct_property(Context *context, Value base, String *name, Val if (!thisObject.isObject()) thisObject = __qmljs_to_object(base, context); - Value func = thisObject.objectValue()->getProperty(context, name); + Value func = thisObject.objectValue()->__get__(context, name); if (FunctionObject *f = func.asFunctionObject()) { Context k; Context *ctx = f->needsActivation ? context->engine->newContext() : &k; diff --git a/qv4ecmaobjects.cpp b/qv4ecmaobjects.cpp index 1e75ef9..3427d56 100644 --- a/qv4ecmaobjects.cpp +++ b/qv4ecmaobjects.cpp @@ -530,37 +530,37 @@ void ObjectCtor::call(Context *ctx) ctx->result = Value::fromObject(ctx->engine->newObject()); } -Value ObjectCtor::getProperty(Context *ctx, String *name) +Value ObjectCtor::__get__(Context *ctx, String *name) { if (name == ctx->engine->id_length) return Value::fromDouble(1); - return Object::getProperty(ctx, name); + return Object::__get__(ctx, name); } void ObjectPrototype::init(Context *ctx, const Value &ctor) { - ctor.objectValue()->setProperty(ctx, ctx->engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->setProperty(ctx, QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("create"), method_create, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("defineProperty"), method_defineProperty, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("defineProperties"), method_defineProperties, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("seal"), method_seal, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("freeze"), method_freeze, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("preventExtensions"), method_preventExtensions, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("isSealed"), method_isSealed, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("isFrozen"), method_isFrozen, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("isExtensible"), method_isExtensible, 0); - ctor.objectValue()->setProperty(ctx, QStringLiteral("keys"), method_keys, 0); - - setProperty(ctx, QStringLiteral("constructor"), ctor); - setProperty(ctx, QStringLiteral("toString"), method_toString, 0); - setProperty(ctx, QStringLiteral("toLocaleString"), method_toLocaleString, 0); - setProperty(ctx, QStringLiteral("valueOf"), method_valueOf, 0); - setProperty(ctx, QStringLiteral("hasOwnProperty"), method_hasOwnProperty, 0); - setProperty(ctx, QStringLiteral("isPrototypeOf"), method_isPrototypeOf, 0); - setProperty(ctx, QStringLiteral("propertyIsEnumerable"), method_propertyIsEnumerable, 0); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + ctor.objectValue()->__put__(ctx, QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("create"), method_create, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("defineProperty"), method_defineProperty, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("defineProperties"), method_defineProperties, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("seal"), method_seal, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("freeze"), method_freeze, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("preventExtensions"), method_preventExtensions, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("isSealed"), method_isSealed, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("isFrozen"), method_isFrozen, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("isExtensible"), method_isExtensible, 0); + ctor.objectValue()->__put__(ctx, QStringLiteral("keys"), method_keys, 0); + + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString, 0); + __put__(ctx, QStringLiteral("toLocaleString"), method_toLocaleString, 0); + __put__(ctx, QStringLiteral("valueOf"), method_valueOf, 0); + __put__(ctx, QStringLiteral("hasOwnProperty"), method_hasOwnProperty, 0); + __put__(ctx, QStringLiteral("isPrototypeOf"), method_isPrototypeOf, 0); + __put__(ctx, QStringLiteral("propertyIsEnumerable"), method_propertyIsEnumerable, 0); } void ObjectPrototype::method_getPrototypeOf(Context *ctx) @@ -670,7 +670,7 @@ void ObjectPrototype::method_hasOwnProperty(Context *ctx) { String *P = ctx->argument(0).toString(ctx); Value O = ctx->thisObject.toObject(ctx); - bool r = O.objectValue()->getOwnProperty(ctx, P) != 0; + bool r = O.objectValue()->__getOwnProperty__(ctx, P) != 0; ctx->result = Value::fromBoolean(r); } @@ -720,29 +720,29 @@ void StringCtor::call(Context *ctx) void StringPrototype::init(Context *ctx, const Value &ctor) { - ctor.objectValue()->setProperty(ctx, ctx->engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->setProperty(ctx, QStringLiteral("fromCharCode"), method_fromCharCode); - - setProperty(ctx, QStringLiteral("constructor"), 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); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + ctor.objectValue()->__put__(ctx, QStringLiteral("fromCharCode"), method_fromCharCode); + + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString); + __put__(ctx, QStringLiteral("valueOf"), method_valueOf); + __put__(ctx, QStringLiteral("charAt"), method_charAt); + __put__(ctx, QStringLiteral("charCodeAt"), method_charCodeAt); + __put__(ctx, QStringLiteral("concat"), method_concat); + __put__(ctx, QStringLiteral("indexOf"), method_indexOf); + __put__(ctx, QStringLiteral("lastIndexOf"), method_lastIndexOf); + __put__(ctx, QStringLiteral("localeCompare"), method_localeCompare); + __put__(ctx, QStringLiteral("match"), method_match); + __put__(ctx, QStringLiteral("replace"), method_replace); + __put__(ctx, QStringLiteral("search"), method_search); + __put__(ctx, QStringLiteral("slice"), method_slice); + __put__(ctx, QStringLiteral("split"), method_split); + __put__(ctx, QStringLiteral("substr"), method_substr); + __put__(ctx, QStringLiteral("substring"), method_substring); + __put__(ctx, QStringLiteral("toLowerCase"), method_toLowerCase); + __put__(ctx, QStringLiteral("toLocaleLowerCase"), method_toLocaleLowerCase); + __put__(ctx, QStringLiteral("toUpperCase"), method_toUpperCase); + __put__(ctx, QStringLiteral("toLocaleUpperCase"), method_toLocaleUpperCase); } QString StringPrototype::getThisString(Context *ctx) @@ -1027,27 +1027,27 @@ void NumberCtor::call(Context *ctx) void NumberPrototype::init(Context *ctx, const Value &ctor) { - ctor.objectValue()->setProperty(ctx, ctx->engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->setProperty(ctx, QStringLiteral("NaN"), Value::fromDouble(qSNaN())); - ctor.objectValue()->setProperty(ctx, QStringLiteral("NEGATIVE_INFINITY"), Value::fromDouble(-qInf())); - ctor.objectValue()->setProperty(ctx, QStringLiteral("POSITIVE_INFINITY"), Value::fromDouble(qInf())); - ctor.objectValue()->setProperty(ctx, QStringLiteral("MAX_VALUE"), Value::fromDouble(1.7976931348623158e+308)); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + ctor.objectValue()->__put__(ctx, QStringLiteral("NaN"), Value::fromDouble(qSNaN())); + ctor.objectValue()->__put__(ctx, QStringLiteral("NEGATIVE_INFINITY"), Value::fromDouble(-qInf())); + ctor.objectValue()->__put__(ctx, QStringLiteral("POSITIVE_INFINITY"), Value::fromDouble(qInf())); + ctor.objectValue()->__put__(ctx, QStringLiteral("MAX_VALUE"), Value::fromDouble(1.7976931348623158e+308)); #ifdef __INTEL_COMPILER # pragma warning( push ) # pragma warning(disable: 239) #endif - ctor.objectValue()->setProperty(ctx, QStringLiteral("MIN_VALUE"), Value::fromDouble(5e-324)); + ctor.objectValue()->__put__(ctx, QStringLiteral("MIN_VALUE"), Value::fromDouble(5e-324)); #ifdef __INTEL_COMPILER # pragma warning( pop ) #endif - setProperty(ctx, QStringLiteral("constructor"), 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); + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString); + __put__(ctx, QStringLiteral("toLocalString"), method_toLocaleString); + __put__(ctx, QStringLiteral("valueOf"), method_valueOf); + __put__(ctx, QStringLiteral("toFixed"), method_toFixed); + __put__(ctx, QStringLiteral("toExponential"), method_toExponential); + __put__(ctx, QStringLiteral("toPrecision"), method_toPrecision); } void NumberPrototype::method_toString(Context *ctx) @@ -1206,10 +1206,10 @@ void BooleanCtor::call(Context *ctx) void BooleanPrototype::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("toString"), method_toString); - setProperty(ctx, QStringLiteral("valueOf"), method_valueOf); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString); + __put__(ctx, QStringLiteral("valueOf"), method_valueOf); } void BooleanPrototype::method_toString(Context *ctx) @@ -1268,29 +1268,29 @@ void ArrayCtor::call(Context *ctx) void ArrayPrototype::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("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); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString, 0); + __put__(ctx, QStringLiteral("toLocalString"), method_toLocaleString, 0); + __put__(ctx, QStringLiteral("concat"), method_concat, 1); + __put__(ctx, QStringLiteral("join"), method_join, 1); + __put__(ctx, QStringLiteral("pop"), method_pop, 0); + __put__(ctx, QStringLiteral("push"), method_push, 1); + __put__(ctx, QStringLiteral("reverse"), method_reverse, 0); + __put__(ctx, QStringLiteral("shift"), method_shift, 0); + __put__(ctx, QStringLiteral("slice"), method_slice, 2); + __put__(ctx, QStringLiteral("sort"), method_sort, 1); + __put__(ctx, QStringLiteral("splice"), method_splice, 2); + __put__(ctx, QStringLiteral("unshift"), method_unshift, 1); + __put__(ctx, QStringLiteral("indexOf"), method_indexOf, 0); + __put__(ctx, QStringLiteral("lastIndexOf"), method_lastIndexOf, 0); + __put__(ctx, QStringLiteral("every"), method_every, 0); + __put__(ctx, QStringLiteral("some"), method_some, 0); + __put__(ctx, QStringLiteral("forEach"), method_forEach, 0); + __put__(ctx, QStringLiteral("map"), method_map, 0); + __put__(ctx, QStringLiteral("filter"), method_filter, 0); + __put__(ctx, QStringLiteral("reduce"), method_reduce, 0); + __put__(ctx, QStringLiteral("reduceRight"), method_reduceRight, 0); } void ArrayPrototype::method_toString(Context *ctx) @@ -1396,12 +1396,12 @@ void ArrayPrototype::method_pop(Context *ctx) Value r1 = self.property(ctx, ctx->engine->id_length); quint32 r2 = !r1.isUndefined() ? r1.toUInt32(ctx) : 0; if (! r2) { - self.objectValue()->setProperty(ctx, ctx->engine->id_length, Value::fromDouble(0)); + self.objectValue()->__put__(ctx, ctx->engine->id_length, Value::fromDouble(0)); } else { String *r6 = Value::fromDouble(r2 - 1).toString(ctx); Value r7 = self.property(ctx, r6); - self.objectValue()->deleteProperty(ctx, r6, 0); - self.objectValue()->setProperty(ctx, ctx->engine->id_length, Value::fromDouble(2 - 1)); + self.objectValue()->__delete__(ctx, r6, 0); + self.objectValue()->__put__(ctx, ctx->engine->id_length, Value::fromDouble(2 - 1)); ctx->result = r7; } } @@ -1423,10 +1423,10 @@ void ArrayPrototype::method_push(Context *ctx) for (unsigned int index = 0; index < ctx->argumentCount; ++index, ++n) { Value r3 = ctx->argument(index); String *name = Value::fromDouble(n).toString(ctx); - self.objectValue()->setProperty(ctx, name, r3); + self.objectValue()->__put__(ctx, name, r3); } Value r = Value::fromDouble(n); - self.objectValue()->setProperty(ctx, ctx->engine->id_length, r); + self.objectValue()->__put__(ctx, ctx->engine->id_length, r); ctx->result = r; } } @@ -1738,12 +1738,12 @@ void FunctionCtor::call(Context *ctx) void FunctionPrototype::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("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); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString, 0); + __put__(ctx, QStringLiteral("apply"), method_apply, 0); + __put__(ctx, QStringLiteral("call"), method_call, 0); + __put__(ctx, QStringLiteral("bind"), method_bind, 0); } void FunctionPrototype::method_toString(Context *ctx) @@ -1853,57 +1853,57 @@ void DateCtor::call(Context *ctx) void DatePrototype::init(Context *ctx, const Value &ctor) { - ctor.objectValue()->setProperty(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); LocalTZA = getLocalTZA(); - ctor.objectValue()->setProperty(ctx, QStringLiteral("parse"), method_parse, 1); - ctor.objectValue()->setProperty(ctx, QStringLiteral("UTC"), method_UTC, 7); - - setProperty(ctx, QStringLiteral("constructor"), 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); + ctor.objectValue()->__put__(ctx, QStringLiteral("parse"), method_parse, 1); + ctor.objectValue()->__put__(ctx, QStringLiteral("UTC"), method_UTC, 7); + + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("toString"), method_toString, 0); + __put__(ctx, QStringLiteral("toDateString"), method_toDateString, 0); + __put__(ctx, QStringLiteral("toTimeString"), method_toTimeString, 0); + __put__(ctx, QStringLiteral("toLocaleString"), method_toLocaleString, 0); + __put__(ctx, QStringLiteral("toLocaleDateString"), method_toLocaleDateString, 0); + __put__(ctx, QStringLiteral("toLocaleTimeString"), method_toLocaleTimeString, 0); + __put__(ctx, QStringLiteral("valueOf"), method_valueOf, 0); + __put__(ctx, QStringLiteral("getTime"), method_getTime, 0); + __put__(ctx, QStringLiteral("getYear"), method_getYear, 0); + __put__(ctx, QStringLiteral("getFullYear"), method_getFullYear, 0); + __put__(ctx, QStringLiteral("getUTCFullYear"), method_getUTCFullYear, 0); + __put__(ctx, QStringLiteral("getMonth"), method_getMonth, 0); + __put__(ctx, QStringLiteral("getUTCMonth"), method_getUTCMonth, 0); + __put__(ctx, QStringLiteral("getDate"), method_getDate, 0); + __put__(ctx, QStringLiteral("getUTCDate"), method_getUTCDate, 0); + __put__(ctx, QStringLiteral("getDay"), method_getDay, 0); + __put__(ctx, QStringLiteral("getUTCDay"), method_getUTCDay, 0); + __put__(ctx, QStringLiteral("getHours"), method_getHours, 0); + __put__(ctx, QStringLiteral("getUTCHours"), method_getUTCHours, 0); + __put__(ctx, QStringLiteral("getMinutes"), method_getMinutes, 0); + __put__(ctx, QStringLiteral("getUTCMinutes"), method_getUTCMinutes, 0); + __put__(ctx, QStringLiteral("getSeconds"), method_getSeconds, 0); + __put__(ctx, QStringLiteral("getUTCSeconds"), method_getUTCSeconds, 0); + __put__(ctx, QStringLiteral("getMilliseconds"), method_getMilliseconds, 0); + __put__(ctx, QStringLiteral("getUTCMilliseconds"), method_getUTCMilliseconds, 0); + __put__(ctx, QStringLiteral("getTimezoneOffset"), method_getTimezoneOffset, 0); + __put__(ctx, QStringLiteral("setTime"), method_setTime, 1); + __put__(ctx, QStringLiteral("setMilliseconds"), method_setMilliseconds, 1); + __put__(ctx, QStringLiteral("setUTCMilliseconds"), method_setUTCMilliseconds, 1); + __put__(ctx, QStringLiteral("setSeconds"), method_setSeconds, 2); + __put__(ctx, QStringLiteral("setUTCSeconds"), method_setUTCSeconds, 2); + __put__(ctx, QStringLiteral("setMinutes"), method_setMinutes, 3); + __put__(ctx, QStringLiteral("setUTCMinutes"), method_setUTCMinutes, 3); + __put__(ctx, QStringLiteral("setHours"), method_setHours, 4); + __put__(ctx, QStringLiteral("setUTCHours"), method_setUTCHours, 4); + __put__(ctx, QStringLiteral("setDate"), method_setDate, 1); + __put__(ctx, QStringLiteral("setUTCDate"), method_setUTCDate, 1); + __put__(ctx, QStringLiteral("setMonth"), method_setMonth, 2); + __put__(ctx, QStringLiteral("setUTCMonth"), method_setUTCMonth, 2); + __put__(ctx, QStringLiteral("setYear"), method_setYear, 1); + __put__(ctx, QStringLiteral("setFullYear"), method_setFullYear, 3); + __put__(ctx, QStringLiteral("setUTCFullYear"), method_setUTCFullYear, 3); + __put__(ctx, QStringLiteral("toUTCString"), method_toUTCString, 0); + __put__(ctx, QStringLiteral("toGMTString"), method_toUTCString, 0); } double DatePrototype::getThisDate(Context *ctx) @@ -2463,11 +2463,11 @@ void RegExpCtor::call(Context *ctx) 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); + ctor.objectValue()->__put__(ctx, ctx->engine->id_prototype, Value::fromObject(this)); + __put__(ctx, QStringLiteral("constructor"), ctor); + __put__(ctx, QStringLiteral("exec"), method_exec, 0); + __put__(ctx, QStringLiteral("test"), method_test, 0); + __put__(ctx, QStringLiteral("toString"), method_toString, 0); } void RegExpPrototype::method_exec(Context *ctx) @@ -2495,8 +2495,8 @@ void RegExpPrototype::method_exec(Context *ctx) for (int i = 0; i <= captured; ++i) array->value.push(Value::fromString(ctx, match.captured(i))); - array->setProperty(ctx, QLatin1String("index"), Value::fromInt32(match.capturedStart(0))); - array->setProperty(ctx, QLatin1String("input"), arg); + array->__put__(ctx, QLatin1String("index"), Value::fromInt32(match.capturedStart(0))); + array->__put__(ctx, QLatin1String("input"), arg); if (r->global) r->lastIndex = Value::fromInt32(match.capturedEnd(0)); @@ -2535,33 +2535,33 @@ void RegExpPrototype::method_toString(Context *ctx) // MathObject::MathObject(Context *ctx) { - setProperty(ctx, QStringLiteral("E"), Value::fromDouble(::exp(1.0))); - setProperty(ctx, QStringLiteral("LN2"), Value::fromDouble(::log(2.0))); - setProperty(ctx, QStringLiteral("LN10"), Value::fromDouble(::log(10.0))); - setProperty(ctx, QStringLiteral("LOG2E"), Value::fromDouble(1.0/::log(2.0))); - setProperty(ctx, QStringLiteral("LOG10E"), Value::fromDouble(1.0/::log(10.0))); - setProperty(ctx, QStringLiteral("PI"), Value::fromDouble(qt_PI)); - setProperty(ctx, QStringLiteral("SQRT1_2"), Value::fromDouble(::sqrt(0.5))); - setProperty(ctx, QStringLiteral("SQRT2"), Value::fromDouble(::sqrt(2.0))); - - 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); + __put__(ctx, QStringLiteral("E"), Value::fromDouble(::exp(1.0))); + __put__(ctx, QStringLiteral("LN2"), Value::fromDouble(::log(2.0))); + __put__(ctx, QStringLiteral("LN10"), Value::fromDouble(::log(10.0))); + __put__(ctx, QStringLiteral("LOG2E"), Value::fromDouble(1.0/::log(2.0))); + __put__(ctx, QStringLiteral("LOG10E"), Value::fromDouble(1.0/::log(10.0))); + __put__(ctx, QStringLiteral("PI"), Value::fromDouble(qt_PI)); + __put__(ctx, QStringLiteral("SQRT1_2"), Value::fromDouble(::sqrt(0.5))); + __put__(ctx, QStringLiteral("SQRT2"), Value::fromDouble(::sqrt(2.0))); + + __put__(ctx, QStringLiteral("abs"), method_abs, 1); + __put__(ctx, QStringLiteral("acos"), method_acos, 1); + __put__(ctx, QStringLiteral("asin"), method_asin, 0); + __put__(ctx, QStringLiteral("atan"), method_atan, 1); + __put__(ctx, QStringLiteral("atan2"), method_atan2, 2); + __put__(ctx, QStringLiteral("ceil"), method_ceil, 1); + __put__(ctx, QStringLiteral("cos"), method_cos, 1); + __put__(ctx, QStringLiteral("exp"), method_exp, 1); + __put__(ctx, QStringLiteral("floor"), method_floor, 1); + __put__(ctx, QStringLiteral("log"), method_log, 1); + __put__(ctx, QStringLiteral("max"), method_max, 2); + __put__(ctx, QStringLiteral("min"), method_min, 2); + __put__(ctx, QStringLiteral("pow"), method_pow, 2); + __put__(ctx, QStringLiteral("random"), method_random, 0); + __put__(ctx, QStringLiteral("round"), method_round, 1); + __put__(ctx, QStringLiteral("sin"), method_sin, 1); + __put__(ctx, QStringLiteral("sqrt"), method_sqrt, 1); + __put__(ctx, QStringLiteral("tan"), method_tan, 1); } /* copies the sign from y to x and returns the result */ diff --git a/qv4ecmaobjects_p.h b/qv4ecmaobjects_p.h index b048404..6b20e27 100644 --- a/qv4ecmaobjects_p.h +++ b/qv4ecmaobjects_p.h @@ -53,7 +53,7 @@ struct ObjectCtor: FunctionObject virtual void construct(Context *ctx); virtual void call(Context *ctx); - virtual Value getProperty(Context *ctx, String *name); + virtual Value __get__(Context *ctx, String *name); }; struct ObjectPrototype: Object -- 2.7.4