Fix a few more runtime signatures and optimise toObject conversion
authorLars Knoll <lars.knoll@digia.com>
Thu, 14 Feb 2013 20:41:49 +0000 (21:41 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 14 Feb 2013 21:25:30 +0000 (22:25 +0100)
Change-Id: Ibd1e4b7f2c9609b4ac08d75c8a0e2d5a86521605
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qmljs_runtime.cpp
src/v4/qmljs_runtime.h
src/v4/qmljs_value.cpp
src/v4/qmljs_value.h
src/v4/qv4arrayobject.cpp
src/v4/qv4dateobject.cpp
src/v4/qv4functionobject.cpp
src/v4/qv4objectproto.cpp

index 8b9e4f6..e36e4bf 100644 (file)
@@ -211,8 +211,8 @@ void __qmljs_delete_subscript(ExecutionContext *ctx, Value *result, const Value
 
 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;
 }
@@ -318,133 +318,133 @@ void __qmljs_inplace_ushr_name(ExecutionContext *ctx, String *name, const Value
 
 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);
 }
 
@@ -552,32 +552,30 @@ void __qmljs_throw_type_error(ExecutionContext *ctx)
     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);
 }
 
@@ -601,7 +599,7 @@ void __qmljs_get_element(ExecutionContext *ctx, Value *result, const Value &obje
             return;
         }
 
-        o = __qmljs_to_object(object, ctx).objectValue();
+        o = __qmljs_convert_to_object(ctx, object);
     }
 
     if (idx < UINT_MAX) {
@@ -626,7 +624,7 @@ void __qmljs_get_element(ExecutionContext *ctx, Value *result, const Value &obje
 
 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) {
@@ -645,9 +643,10 @@ void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value
 
 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);
 }
 
@@ -676,7 +675,7 @@ void __qmljs_get_property(ExecutionContext *ctx, Value *result, const Value &obj
     } 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)
@@ -728,7 +727,7 @@ void __qmljs_get_property_lookup(ExecutionContext *ctx, Value *result, const Val
         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);
         }
     }
@@ -738,7 +737,7 @@ void __qmljs_get_property_lookup(ExecutionContext *ctx, Value *result, const Val
 
 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()) {
@@ -846,10 +845,10 @@ void __qmljs_call_property(ExecutionContext *context, Value *result, const Value
         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);
@@ -872,10 +871,10 @@ void __qmljs_call_property_lookup(ExecutionContext *context, Value *result, cons
         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;
@@ -922,12 +921,8 @@ void __qmljs_call_property_lookup(ExecutionContext *context, Value *result, cons
 
 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();
@@ -969,11 +964,9 @@ void __qmljs_construct_value(ExecutionContext *context, Value *result, const Val
 
 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)
@@ -1058,23 +1051,29 @@ void __qmljs_builtin_typeof(ExecutionContext *ctx, Value *result, const Value &v
 
 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)
@@ -1112,7 +1111,7 @@ void __qmljs_builtin_post_increment_name(ExecutionContext *context, Value *resul
 
 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);
 
@@ -1132,7 +1131,7 @@ void __qmljs_builtin_post_increment_member(ExecutionContext *context, Value *res
 
 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();
 
@@ -1192,7 +1191,7 @@ void __qmljs_builtin_post_decrement_name(ExecutionContext *context, Value *resul
 
 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);
 
@@ -1212,7 +1211,7 @@ void __qmljs_builtin_post_decrement_member(ExecutionContext *context, Value *res
 
 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();
 
@@ -1244,7 +1243,7 @@ void __qmljs_builtin_throw(ExecutionContext *context, const Value &val)
 
 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);
 }
 
index 7c4e438..5de6cc3 100644 (file)
@@ -161,10 +161,6 @@ String *__qmljs_identifier_from_utf8(ExecutionContext *ctx, const char *s);
 // objects
 Value __qmljs_object_default_value(ExecutionContext *ctx, Value object, int typeHint);
 void __qmljs_throw_type_error(ExecutionContext *ctx);
-Value __qmljs_new_object(ExecutionContext *ctx);
-Value __qmljs_new_boolean_object(ExecutionContext *ctx, bool boolean);
-Value __qmljs_new_number_object(ExecutionContext *ctx, double n);
-Value __qmljs_new_string_object(ExecutionContext *ctx, String *string);
 void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const Value& value);
 void __qmljs_set_property(ExecutionContext *ctx, const Value &object, String *name, const Value &value);
 void __qmljs_get_property(ExecutionContext *ctx, Value *result, const Value &object, String *name);
@@ -192,7 +188,8 @@ double __qmljs_to_integer(const Value &value, ExecutionContext *ctx);
 int __qmljs_to_int32(const Value &value, ExecutionContext *ctx);
 unsigned short __qmljs_to_uint16(const Value &value, ExecutionContext *ctx);
 Value __qmljs_to_string(const Value &value, ExecutionContext *ctx);
-Value __qmljs_to_object(const Value &value, ExecutionContext *ctx);
+Value __qmljs_to_object(ExecutionContext *ctx, const Value &value);
+Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value);
 //uint __qmljs_check_object_coercible(Context *ctx, Value *result, Value *value);
 Bool __qmljs_is_callable(const Value &value, ExecutionContext *ctx);
 Value __qmljs_default_value(const Value &value, ExecutionContext *ctx, int typeHint);
@@ -426,32 +423,11 @@ inline Value __qmljs_to_string(const Value &value, ExecutionContext *ctx)
     } // switch
 }
 
-inline Value __qmljs_to_object(const Value &value, ExecutionContext *ctx)
+inline Value __qmljs_to_object(ExecutionContext *ctx, const Value &value)
 {
     if (value.isObject())
         return value;
-
-    switch (value.type()) {
-    case Value::Undefined_Type:
-    case Value::Null_Type:
-        __qmljs_throw_type_error(ctx);
-        break;
-    case Value::Boolean_Type:
-        return __qmljs_new_boolean_object(ctx, value.booleanValue());
-        break;
-    case Value::String_Type:
-        return __qmljs_new_string_object(ctx, value.stringValue());
-        break;
-    case Value::Object_Type:
-        Q_UNREACHABLE();
-        break;
-    case Value::Integer_Type:
-        return __qmljs_new_number_object(ctx, value.int_32);
-        break;
-    default: // double
-        return __qmljs_new_number_object(ctx, value.doubleValue());
-        break;
-    }
+    return Value::fromObject(__qmljs_convert_to_object(ctx, value));
 }
 
 /*
index 83dd9c6..042a1e0 100644 (file)
@@ -75,11 +75,6 @@ String *Value::toString(ExecutionContext *ctx) const
     return v.stringValue();
 }
 
-Value Value::toObject(ExecutionContext *ctx) const
-{
-    return __qmljs_to_object(*this, ctx);
-}
-
 bool Value::sameValue(Value other) const {
     if (val == other.val)
         return true;
index 2675d55..d0639c8 100644 (file)
@@ -60,6 +60,7 @@ struct Value;
 
 extern "C" {
 double __qmljs_to_number(const Value &value, ExecutionContext *ctx);
+Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value);
 }
 
 typedef uint Bool;
@@ -207,7 +208,7 @@ struct Q_V4_EXPORT Value
     double toInteger(ExecutionContext *ctx) const;
     double toNumber(ExecutionContext *ctx) const;
     String *toString(ExecutionContext *ctx) const;
-    Value toObject(ExecutionContext *ctx) const;
+    Object *toObject(ExecutionContext *ctx) const;
 
     inline bool isPrimitive() const { return !isObject(); }
 #if CPU(X86_64)
@@ -351,6 +352,13 @@ inline Value Value::fromObject(Object *o)
     return v;
 }
 
+inline Object *Value::toObject(ExecutionContext *ctx) const
+{
+    if (isObject())
+        return objectValue();
+    return __qmljs_convert_to_object(ctx, *this);
+}
+
 inline int Value::toInt32(ExecutionContext *ctx) const
 {
     if (isConvertibleToInt())
index 8117a65..69edf9e 100644 (file)
@@ -218,7 +218,7 @@ Value ArrayPrototype::method_join(ExecutionContext *ctx)
 
 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) {
@@ -239,7 +239,7 @@ Value ArrayPrototype::method_pop(ExecutionContext *ctx)
 
 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) {
@@ -296,7 +296,7 @@ Value ArrayPrototype::method_push(ExecutionContext *ctx)
 
 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;
@@ -319,7 +319,7 @@ Value ArrayPrototype::method_reverse(ExecutionContext *ctx)
 
 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) {
@@ -382,7 +382,7 @@ Value ArrayPrototype::method_shift(ExecutionContext *ctx)
 
 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);
@@ -419,7 +419,7 @@ Value ArrayPrototype::method_slice(ExecutionContext *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);
 
@@ -430,7 +430,7 @@ Value ArrayPrototype::method_sort(ExecutionContext *ctx)
 
 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);
@@ -494,7 +494,7 @@ Value ArrayPrototype::method_splice(ExecutionContext *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;
@@ -546,7 +546,7 @@ Value ArrayPrototype::method_unshift(ExecutionContext *ctx)
 
 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);
@@ -583,7 +583,7 @@ Value ArrayPrototype::method_indexOf(ExecutionContext *ctx)
 
 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);
@@ -620,7 +620,7 @@ Value ArrayPrototype::method_lastIndexOf(ExecutionContext *ctx)
 
 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);
 
@@ -649,7 +649,7 @@ Value ArrayPrototype::method_every(ExecutionContext *ctx)
 
 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);
 
@@ -678,7 +678,7 @@ Value ArrayPrototype::method_some(ExecutionContext *ctx)
 
 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);
 
@@ -705,7 +705,7 @@ Value ArrayPrototype::method_forEach(ExecutionContext *ctx)
 
 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);
 
@@ -737,7 +737,7 @@ Value ArrayPrototype::method_map(ExecutionContext *ctx)
 
 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);
 
@@ -772,7 +772,7 @@ Value ArrayPrototype::method_filter(ExecutionContext *ctx)
 
 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);
 
@@ -814,7 +814,7 @@ Value ArrayPrototype::method_reduce(ExecutionContext *ctx)
 
 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);
 
index 77ed279..72a96af 100644 (file)
@@ -1302,7 +1302,7 @@ Value DatePrototype::method_toISOString(ExecutionContext *ctx)
 
 Value DatePrototype::method_toJSON(ExecutionContext *ctx)
 {
-    Value O = __qmljs_to_object(ctx->thisObject, ctx);
+    Value O = __qmljs_to_object(ctx, ctx->thisObject);
     Value tv = __qmljs_to_primitive(O, ctx, NUMBER_HINT);
 
     if (tv.isNumber() && !isfinite(tv.toNumber(ctx)))
index af23182..013bdca 100644 (file)
@@ -397,7 +397,7 @@ Value ScriptFunction::call(Managed *that, ExecutionContext *context, const Value
             if (!f->isBuiltinFunction)
                 ctx->thisObject = context->engine->globalObject;
         } else {
-            ctx->thisObject = thisObject.toObject(context);
+            ctx->thisObject = Value::fromObject(thisObject.toObject(context));
         }
     }
 
@@ -445,7 +445,7 @@ Value BuiltinFunctionOld::call(Managed *that, ExecutionContext *context, const V
             if (!f->isBuiltinFunction)
                 ctx->thisObject = context->engine->globalObject;
         } else {
-            ctx->thisObject = thisObject.toObject(context);
+            ctx->thisObject = Value::fromObject(thisObject.toObject(context));
         }
     }
 
index 6e9f51e..0af8c1d 100644 (file)
@@ -89,14 +89,14 @@ Value ObjectCtor::construct(Managed *that, ExecutionContext *ctx, Value *args, i
             obj->prototype = proto.objectValue();
         return Value::fromObject(obj);
     }
-    return __qmljs_to_object(args[0], ctx);
+    return __qmljs_to_object(ctx, args[0]);
 }
 
 Value ObjectCtor::call(Managed *, ExecutionContext *ctx, const Value &/*thisObject*/, Value *args, int argc)
 {
     if (!argc || args[0].isUndefined() || args[0].isNull())
         return Value::fromObject(ctx->engine->newObject());
-    return __qmljs_to_object(args[0], ctx);
+    return __qmljs_to_object(ctx, args[0]);
 }
 
 void ObjectPrototype::init(ExecutionContext *ctx, const Value &ctor)
@@ -208,7 +208,7 @@ Value ObjectPrototype::method_defineProperties(ExecutionContext *ctx)
     if (!O.isObject())
         ctx->throwTypeError();
 
-    Object *o = ctx->argument(1).toObject(ctx).objectValue();
+    Object *o = ctx->argument(1).toObject(ctx);
 
     ObjectIterator it(ctx, o, ObjectIterator::EnumberableOnly);
     while (1) {
@@ -372,7 +372,7 @@ Value ObjectPrototype::method_toString(ExecutionContext *ctx)
     } else if (ctx->thisObject.isNull()) {
         return Value::fromString(ctx, QStringLiteral("[object Null]"));
     } else {
-        Value obj = __qmljs_to_object(ctx->thisObject, ctx);
+        Value obj = __qmljs_to_object(ctx, ctx->thisObject);
         QString className = obj.objectValue()->className();
         return Value::fromString(ctx, QString::fromUtf8("[object %1]").arg(className));
     }
@@ -380,7 +380,7 @@ Value ObjectPrototype::method_toString(ExecutionContext *ctx)
 
 Value ObjectPrototype::method_toLocaleString(ExecutionContext *ctx)
 {
-    Object *o = __qmljs_to_object(ctx->thisObject, ctx).objectValue();
+    Object *o = ctx->thisObject.toObject(ctx);
     Value ts = o->__get__(ctx, ctx->engine->newString(QStringLiteral("toString")));
     FunctionObject *f = ts.asFunctionObject();
     if (!f)
@@ -390,14 +390,14 @@ Value ObjectPrototype::method_toLocaleString(ExecutionContext *ctx)
 
 Value ObjectPrototype::method_valueOf(ExecutionContext *ctx)
 {
-    return ctx->thisObject.toObject(ctx);
+    return Value::fromObject(ctx->thisObject.toObject(ctx));
 }
 
 Value ObjectPrototype::method_hasOwnProperty(ExecutionContext *ctx)
 {
     String *P = ctx->argument(0).toString(ctx);
-    Value O = ctx->thisObject.toObject(ctx);
-    bool r = O.objectValue()->__getOwnProperty__(ctx, P) != 0;
+    Object *O = ctx->thisObject.toObject(ctx);
+    bool r = O->__getOwnProperty__(ctx, P) != 0;
     return Value::fromBoolean(r);
 }
 
@@ -407,7 +407,7 @@ Value ObjectPrototype::method_isPrototypeOf(ExecutionContext *ctx)
     if (! V.isObject())
         return Value::fromBoolean(false);
 
-    Object *O = ctx->thisObject.toObject(ctx).objectValue();
+    Object *O = ctx->thisObject.toObject(ctx);
     Object *proto = V.objectValue()->prototype;
     while (proto) {
         if (O == proto)
@@ -421,7 +421,7 @@ Value ObjectPrototype::method_propertyIsEnumerable(ExecutionContext *ctx)
 {
     String *p = ctx->argument(0).toString(ctx);
 
-    Object *o = ctx->thisObject.toObject(ctx).objectValue();
+    Object *o = ctx->thisObject.toObject(ctx);
     PropertyDescriptor *pd = o->__getOwnProperty__(ctx, p);
     return Value::fromBoolean(pd && pd->isEnumerable());
 }
@@ -436,7 +436,7 @@ Value ObjectPrototype::method_defineGetter(ExecutionContext *ctx)
     if (!f)
         __qmljs_throw_type_error(ctx);
 
-    Object *o = ctx->thisObject.toObject(ctx).objectValue();
+    Object *o = ctx->thisObject.toObject(ctx);
 
     PropertyDescriptor pd = PropertyDescriptor::fromAccessor(f, 0);
     pd.configurable = PropertyDescriptor::Enabled;
@@ -455,7 +455,7 @@ Value ObjectPrototype::method_defineSetter(ExecutionContext *ctx)
     if (!f)
         __qmljs_throw_type_error(ctx);
 
-    Object *o = ctx->thisObject.toObject(ctx).objectValue();
+    Object *o = ctx->thisObject.toObject(ctx);
 
     PropertyDescriptor pd = PropertyDescriptor::fromAccessor(0, f);
     pd.configurable = PropertyDescriptor::Enabled;