From 5d2f12ee03d942e5bd37df2b976b90525f51a1e4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 1 Dec 2012 20:08:26 +0100 Subject: [PATCH] Remove the callFunction() method Give Object a virtual call() method, that simply throws a type error. FunctionObject reimplements this to do the right thing. Change-Id: I5a11a4de0302ad86b9ad3a822501224e11692b70 Reviewed-by: Simon Hausmann --- qmljs_objects.cpp | 6 ++++++ qmljs_objects.h | 2 ++ qmljs_runtime.cpp | 40 ++++++++++++++++++---------------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index 5ed251e..e0ebc67 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -322,6 +322,12 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, Property return false; } +Value Object::call(ExecutionContext *context, Value , Value *, int) +{ + context->throwTypeError(); + return Value::undefinedValue(); +} + String *ForEachIteratorObject::nextPropertyName() { PropertyTableEntry *p = 0; diff --git a/qmljs_objects.h b/qmljs_objects.h index 927b9f3..cd9c243 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -429,6 +429,8 @@ struct Object { virtual bool __delete__(ExecutionContext *ctx, String *name); virtual bool __defineOwnProperty__(ExecutionContext *ctx, String *name, PropertyDescriptor *desc); + virtual Value call(ExecutionContext *context, Value, Value *, int); + // // helpers // diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index dcfb62d..20002aa 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -57,16 +57,6 @@ namespace QQmlJS { namespace VM { -static inline Value callFunction(ExecutionContext *context, Value thisObject, FunctionObject *func, Value *args, int argc) -{ - if (func) { - return func->call(context, thisObject, args, argc); - } else { - context->throwTypeError(); - return Value::undefinedValue(); - } -} - QString numberToString(double num, int radix = 10) { if (std::isnan(num)) { @@ -497,15 +487,15 @@ Value __qmljs_object_default_value(ExecutionContext *ctx, Value object, int type Object *oo = object.objectValue(); Value conv = oo->__get__(ctx, meth1); - if (FunctionObject *f = conv.asFunctionObject()) { - Value r = callFunction(ctx, object, f, 0, 0); + if (Object *o = conv.asObject()) { + Value r = o->call(ctx, object, 0, 0); if (r.isPrimitive()) return r; } conv = oo->__get__(ctx, meth2); - if (FunctionObject *f = conv.asFunctionObject()) { - Value r = callFunction(ctx, object, f, 0, 0); + if (Object *o = conv.asObject()) { + Value r = o->call(ctx, object, 0, 0); if (r.isPrimitive()) return r; } @@ -711,12 +701,11 @@ uint __qmljs_equal(Value x, Value y, ExecutionContext *ctx) Value __qmljs_call_activation_property(ExecutionContext *context, String *name, Value *args, int argc) { Value func = __qmljs_get_activation_property(context, name); - if (FunctionObject *f = func.asFunctionObject()) { - return callFunction(context, Value::undefinedValue(), f, args, argc); - } else { + Object *o = func.asObject(); + if (!o) context->throwReferenceError(Value::fromString(name)); - return Value::undefinedValue(); - } + + return o->call(context, Value::undefinedValue(), args, argc); } Value __qmljs_call_property(ExecutionContext *context, Value thisObject, String *name, Value *args, int argc) @@ -725,15 +714,22 @@ Value __qmljs_call_property(ExecutionContext *context, Value thisObject, String thisObject = __qmljs_to_object(thisObject, context); assert(thisObject.isObject()); - Object *baseObject = base.objectValue(); + Object *baseObject = thisObject.objectValue(); Value func = baseObject->__get__(context, name); - return callFunction(context, thisObject, func.asFunctionObject(), args, argc); + Object *o = func.asObject(); + if (!o) + context->throwTypeError(); + + return o->call(context, thisObject, args, argc); } Value __qmljs_call_value(ExecutionContext *context, Value thisObject, Value func, Value *args, int argc) { - return callFunction(context, thisObject, func.asFunctionObject(), args, argc); + Object *o = func.asObject(); + if (!o) + context->throwTypeError(); + return o->call(context, thisObject, args, argc); } Value __qmljs_construct_activation_property(ExecutionContext *context, String *name, Value *args, int argc) -- 2.7.4