void __qmljs_delete_member(ExecutionContext *ctx, Value *result, const Value &base, String *name)
{
- Value obj = base.toObject(ctx);
- Value res = Value::fromBoolean(obj.objectValue()->__delete__(ctx, name));
+ Object *obj = base.toObject(ctx);
+ Value res = Value::fromBoolean(obj->__delete__(ctx, name));
if (result)
*result = res;
}
void __qmljs_inplace_bit_and_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_and, index, rhs);
}
void __qmljs_inplace_bit_or_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_or, index, rhs);
}
void __qmljs_inplace_bit_xor_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_bit_xor, index, rhs);
}
void __qmljs_inplace_add_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_add, index, rhs);
}
void __qmljs_inplace_sub_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_sub, index, rhs);
}
void __qmljs_inplace_mul_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_mul, index, rhs);
}
void __qmljs_inplace_div_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_div, index, rhs);
}
void __qmljs_inplace_mod_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_mod, index, rhs);
}
void __qmljs_inplace_shl_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_shl, index, rhs);
}
void __qmljs_inplace_shr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_shr, index, rhs);
}
void __qmljs_inplace_ushr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
{
- Object *obj = base.toObject(ctx).objectValue();
+ Object *obj = base.toObject(ctx);
obj->inplaceBinOp(ctx, __qmljs_ushr, index, rhs);
}
void __qmljs_inplace_bit_and_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_and, name, rhs);
}
void __qmljs_inplace_bit_or_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_or, name, rhs);
}
void __qmljs_inplace_bit_xor_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_bit_xor, name, rhs);
}
void __qmljs_inplace_add_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_add, name, rhs);
}
void __qmljs_inplace_sub_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_sub, name, rhs);
}
void __qmljs_inplace_mul_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_mul, name, rhs);
}
void __qmljs_inplace_div_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_div, name, rhs);
}
void __qmljs_inplace_mod_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_mod, name, rhs);
}
void __qmljs_inplace_shl_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_shl, name, rhs);
}
void __qmljs_inplace_shr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_shr, name, rhs);
}
void __qmljs_inplace_ushr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
{
- Object *o = base.toObject(ctx).objectValue();
+ Object *o = base.toObject(ctx);
o->inplaceBinOp(ctx, __qmljs_ushr, name, rhs);
}
ctx->throwTypeError();
}
-Value __qmljs_new_object(ExecutionContext *ctx)
+Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value)
{
- return Value::fromObject(ctx->engine->newObject());
-}
-
-Value __qmljs_new_boolean_object(ExecutionContext *ctx, bool boolean)
-{
- Value value = Value::fromBoolean(boolean);
- return Value::fromObject(ctx->engine->newBooleanObject(value));
-}
-
-Value __qmljs_new_number_object(ExecutionContext *ctx, double number)
-{
- Value value = Value::fromDouble(number);
- return Value::fromObject(ctx->engine->newNumberObject(value));
+ assert(!value.isObject());
+ switch (value.type()) {
+ case Value::Undefined_Type:
+ case Value::Null_Type:
+ __qmljs_throw_type_error(ctx);
+ case Value::Boolean_Type:
+ return ctx->engine->newBooleanObject(value);
+ case Value::String_Type:
+ return ctx->engine->newStringObject(ctx, value);
+ break;
+ case Value::Object_Type:
+ Q_UNREACHABLE();
+ case Value::Integer_Type:
+ default: // double
+ return ctx->engine->newNumberObject(value);
+ }
}
-Value __qmljs_new_string_object(ExecutionContext *ctx, String *string)
-{
- Value value = Value::fromString(string);
- return Value::fromObject(ctx->engine->newStringObject(ctx, value));
-}
void __qmljs_set_property(ExecutionContext *ctx, const Value &object, String *name, const Value &value)
{
- Object *o = object.isObject() ? object.objectValue() : __qmljs_to_object(object, ctx).objectValue();
+ Object *o = object.toObject(ctx);
o->__put__(ctx, name, value);
}
return;
}
- o = __qmljs_to_object(object, ctx).objectValue();
+ o = __qmljs_convert_to_object(ctx, object);
}
if (idx < UINT_MAX) {
void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value &index, const Value &value)
{
- Object *o = __qmljs_to_object(object, ctx).objectValue();
+ Object *o = object.toObject(ctx);
uint idx = index.asArrayIndex();
if (idx < UINT_MAX) {
Value __qmljs_foreach_iterator_object(Value in, ExecutionContext *ctx)
{
+ Object *o = 0;
if (!in.isNull() && !in.isUndefined())
- in = __qmljs_to_object(in, ctx);
- Object *it = ctx->engine->newForEachIteratorObject(ctx, in.asObject());
+ o = in.toObject(ctx);
+ Object *it = ctx->engine->newForEachIteratorObject(ctx, o);
return Value::fromObject(it);
}
} else if (object.isString() && name->isEqualTo(ctx->engine->id_length)) {
res = Value::fromInt32(object.stringValue()->toQString().length());
} else {
- o = __qmljs_to_object(object, ctx).objectValue();
+ o = __qmljs_convert_to_object(ctx, object);
res = o->__get__(ctx, name);
}
if (result)
if (object.isString() && l->name->isEqualTo(ctx->engine->id_length)) {
res = Value::fromInt32(object.stringValue()->toQString().length());
} else {
- o = __qmljs_to_object(object, ctx).objectValue();
+ o = __qmljs_convert_to_object(ctx, object);
res = o->__get__(ctx, l->name);
}
}
void __qmljs_set_property_lookup(ExecutionContext *ctx, const Value &object, int lookupIndex, const Value &value)
{
- Object *o = object.isObject() ? object.objectValue() : __qmljs_to_object(object, ctx).objectValue();
+ Object *o = object.toObject(ctx);
Lookup *l = ctx->lookups + lookupIndex;
if (l->index != ArrayObject::LengthPropertyIndex || !o->isArrayObject()) {
baseObject = context->engine->stringPrototype;
} else {
if (!thisObject.isObject())
- thisObject = __qmljs_to_object(thisObject, context);
+ thisObject = Value::fromObject(__qmljs_convert_to_object(context, thisObject));
assert(thisObject.isObject());
- baseObject = thisObject.objectValue();
+ baseObject = thisObject.objectValue();
}
Value func = baseObject->__get__(context, name);
baseObject = context->engine->stringPrototype;
} else {
if (!thisObject.isObject())
- thisObject = __qmljs_to_object(thisObject, context);
+ thisObject = Value::fromObject(__qmljs_convert_to_object(context, thisObject));
- assert(thisObject.isObject());
- baseObject = thisObject.objectValue();
+ assert(thisObject.isObject());
+ baseObject = thisObject.objectValue();
}
PropertyDescriptor *p = 0;
void __qmljs_call_element(ExecutionContext *context, Value *result, const Value &that, const Value &index, Value *args, int argc)
{
- Value thisObject = that;
- if (!thisObject.isObject())
- thisObject = __qmljs_to_object(thisObject, context);
-
- assert(thisObject.isObject());
- Object *baseObject = thisObject.objectValue();
+ Object *baseObject = that.toObject(context);
+ Value thisObject = Value::fromObject(baseObject);
Value func = baseObject->__get__(context, index.toString(context));
FunctionObject *o = func.asFunctionObject();
void __qmljs_construct_property(ExecutionContext *context, Value *result, const Value &base, String *name, Value *args, int argc)
{
- Value thisObject = base;
- if (!thisObject.isObject())
- thisObject = __qmljs_to_object(base, context);
+ Object *thisObject = base.toObject(context);
- Value func = thisObject.objectValue()->__get__(context, name);
+ Value func = thisObject->__get__(context, name);
if (FunctionObject *f = func.asFunctionObject()) {
Value res = f->construct(context, args, argc);
if (result)
void __qmljs_builtin_typeof_name(ExecutionContext *context, Value *result, String *name)
{
+ Value res;
+ __qmljs_builtin_typeof(context, &res, context->getPropertyNoThrow(name));
if (result)
- __qmljs_builtin_typeof(context, result, context->getPropertyNoThrow(name));
+ *result = res;
}
void __qmljs_builtin_typeof_member(ExecutionContext *context, Value *result, const Value &base, String *name)
{
- Value obj = base.toObject(context);
+ Object *obj = base.toObject(context);
+ Value res;
+ __qmljs_builtin_typeof(context, &res, obj->__get__(context, name));
if (result)
- __qmljs_builtin_typeof(context, result, obj.objectValue()->__get__(context, name));
+ *result = res;
}
void __qmljs_builtin_typeof_element(ExecutionContext *context, Value *result, const Value &base, const Value &index)
{
String *name = index.toString(context);
- Value obj = base.toObject(context);
+ Object *obj = base.toObject(context);
+ Value res;
+ __qmljs_builtin_typeof(context, &res, obj->__get__(context, name));
if (result)
- __qmljs_builtin_typeof(context, result, obj.objectValue()->__get__(context, name));
+ *result = res;
}
void __qmljs_builtin_post_increment(ExecutionContext *ctx, Value *result, Value *val)
void __qmljs_builtin_post_increment_member(ExecutionContext *context, Value *result, const Value &base, String *name)
{
- Object *o = __qmljs_to_object(base, context).objectValue();
+ Object *o = base.toObject(context);
Value v = o->__get__(context, name);
void __qmljs_builtin_post_increment_element(ExecutionContext *context, Value *result, const Value &base, const Value *index)
{
- Object *o = __qmljs_to_object(base, context).objectValue();
+ Object *o = base.toObject(context);
uint idx = index->asArrayIndex();
void __qmljs_builtin_post_decrement_member(ExecutionContext *context, Value *result, const Value &base, String *name)
{
- Object *o = __qmljs_to_object(base, context).objectValue();
+ Object *o = base.toObject(context);
Value v = o->__get__(context, name);
void __qmljs_builtin_post_decrement_element(ExecutionContext *context, Value *result, const Value &base, const Value &index)
{
- Object *o = __qmljs_to_object(base, context).objectValue();
+ Object *o = base.toObject(context);
uint idx = index.asArrayIndex();
ExecutionContext *__qmljs_builtin_push_with_scope(Value o, ExecutionContext *ctx)
{
- Object *obj = __qmljs_to_object(o, ctx).asObject();
+ Object *obj = o.toObject(ctx);
return ctx->createWithScope(obj);
}
Value ArrayPrototype::method_pop(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len) {
Value ArrayPrototype::method_push(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (len + ctx->argumentCount < len) {
Value ArrayPrototype::method_reverse(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint length = getLength(ctx, instance);
int lo = 0, hi = length - 1;
Value ArrayPrototype::method_shift(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len) {
Value ArrayPrototype::method_slice(ExecutionContext *ctx)
{
- Object *o = ctx->thisObject.toObject(ctx).objectValue();
+ Object *o = ctx->thisObject.toObject(ctx);
ArrayObject *result = ctx->engine->newArrayObject(ctx);
uint len = o->__get__(ctx, ctx->engine->id_length).toUInt32(ctx);
Value ArrayPrototype::method_sort(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_splice(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
ArrayObject *newArray = ctx->engine->newArrayObject(ctx);
Value ArrayPrototype::method_unshift(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
bool protoHasArray = false;
Value ArrayPrototype::method_indexOf(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len)
return Value::fromInt32(-1);
Value ArrayPrototype::method_lastIndexOf(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
if (!len)
return Value::fromInt32(-1);
Value ArrayPrototype::method_every(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_some(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_forEach(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_map(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_filter(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_reduce(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);
Value ArrayPrototype::method_reduceRight(ExecutionContext *ctx)
{
- Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+ Object *instance = ctx->thisObject.toObject(ctx);
uint len = getLength(ctx, instance);