bool Object::inplaceBinOp(Value rhs, String *name, BinOp op, ExecutionContext *ctx)
{
PropertyDescriptor to_fill;
- PropertyDescriptor *pd = __getPropertyDescriptor__(ctx, name, &to_fill);
- if (!pd)
+ bool hasProperty = false;
+ Value v = __get__(ctx, name, &hasProperty);
+ if (!hasProperty)
return false;
- Value result = op(getValue(ctx, pd), rhs, ctx);
+ Value result = op(v, rhs, ctx);
__put__(ctx, name, result);
return true;
}
}
// Section 8.12.2
-PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, String *name, PropertyDescriptor *to_fill)
+PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, String *name)
{
if (members)
if (PropertyDescriptor *p = members->find(name))
return p;
if (prototype)
- return prototype->__getPropertyDescriptor__(ctx, name, to_fill);
+ return prototype->__getPropertyDescriptor__(ctx, name);
return 0;
}
return Value::fromObject(prototype);
}
- PropertyDescriptor tmp;
- if (PropertyDescriptor *p = __getPropertyDescriptor__(ctx, name, &tmp)) {
+ if (PropertyDescriptor *p = __getPropertyDescriptor__(ctx, name)) {
if (hasProperty)
*hasProperty = true;
return getValue(ctx, p);
if (! prototype)
return extensible;
- PropertyDescriptor tmp;
- if (PropertyDescriptor *p = prototype->__getPropertyDescriptor__(ctx, name, &tmp)) {
+ if (PropertyDescriptor *p = prototype->__getPropertyDescriptor__(ctx, name)) {
if (p->isAccessor())
return p->set != 0;
if (!extensible)
}
// clause 4
- PropertyDescriptor tmp;
if (!pd && prototype)
- pd = prototype->__getPropertyDescriptor__(ctx, name, &tmp);
+ pd = prototype->__getPropertyDescriptor__(ctx, name);
// Clause 5
if (pd && pd->isAccessor()) {
*hasProperty = true;
return Value::fromInt32(context->argumentCount);
}
+ if (context) {
+ bool ok = false;
+ int idx = name->toQString().toInt(&ok);
+ if (ok && idx >= 0 && idx < context->argumentCount)
+ return context->argument(idx);
+ }
+
return Object::__get__(ctx, name, hasProperty);
}
-PropertyDescriptor *ArgumentsObject::__getPropertyDescriptor__(ExecutionContext *ctx, String *name, PropertyDescriptor *to_fill)
+
+ArgumentsObject::ArgumentsObject(ExecutionContext *context)
+ : context(context)
+{
+ defineDefaultProperty(context->engine->id_length, Value::fromInt32(context->argumentCount));
+}
+
+void ArgumentsObject::__put__(ExecutionContext *ctx, String *name, Value value)
{
if (context) {
- const quint32 i = Value::fromString(name).toUInt32(ctx);
- if (i < context->argumentCount) {
- *to_fill = PropertyDescriptor::fromValue(context->argument(i));
- to_fill->writable = PropertyDescriptor::Disabled;
- to_fill->enumberable = PropertyDescriptor::Disabled;
- return to_fill;
- }
+ bool ok = false;
+ int idx = name->toQString().toInt(&ok);
+ if (ok && idx >= 0 && idx < context->argumentCount)
+ context->arguments[idx] = value;
+ }
+
+ return Object::__put__(ctx, name, value);
+}
+
+bool ArgumentsObject::__canPut__(ExecutionContext *ctx, String *name)
+{
+ if (context) {
+ bool ok = false;
+ int idx = name->toQString().toInt(&ok);
+ if (ok && idx >= 0 && idx < context->argumentCount)
+ return true;
}
- return Object::__getPropertyDescriptor__(ctx, name, to_fill);
+ return Object::__canPut__(ctx, name);
}
NativeFunction::NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
virtual Value __get__(ExecutionContext *ctx, String *name, bool *hasProperty = 0);
virtual PropertyDescriptor *__getOwnProperty__(ExecutionContext *ctx, String *name);
- virtual PropertyDescriptor *__getPropertyDescriptor__(ExecutionContext *ctx, String *name, PropertyDescriptor *to_fill);
+ PropertyDescriptor *__getPropertyDescriptor__(ExecutionContext *ctx, String *name);
virtual void __put__(ExecutionContext *ctx, String *name, Value value);
virtual bool __canPut__(ExecutionContext *ctx, String *name);
virtual bool __hasProperty__(const ExecutionContext *ctx, String *name) const;
struct ArgumentsObject: Object {
ExecutionContext *context;
- ArgumentsObject(ExecutionContext *context): context(context) {}
+ ArgumentsObject(ExecutionContext *context);
virtual QString className() { return QStringLiteral("Arguments"); }
virtual ArgumentsObject *asArgumentsObject() { return this; }
virtual Value __get__(ExecutionContext *ctx, String *name, bool *hasProperty);
- virtual PropertyDescriptor *__getPropertyDescriptor__(ExecutionContext *ctx, String *name, PropertyDescriptor *to_fill);
+ virtual void __put__(ExecutionContext *ctx, String *name, Value value);
+ virtual bool __canPut__(ExecutionContext *ctx, String *name);
};
} // namespace VM