aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-10-20 14:50:19 +0200
committerLars Knoll <lars.knoll@qt.io>2017-11-07 09:00:23 +0000
commit7287690a41ab762c0c4efe02632efeaf3e0187b4 (patch)
treeb5f1a04748b005119ee4d2f0693f50d80c8ec5c2 /src/qml
parentfb84c9b4f860ee71d0584207f4c0f1d70d96755c (diff)
Change signature of call/construct
Change-Id: I139a7a31651d9a2ea46ced88978ac4633294bc60 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp2
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp24
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h12
-rw-r--r--src/qml/jsruntime/qv4jscall_p.h6
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp33
5 files changed, 36 insertions, 41 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index 0cf4515cc9..5a68a8cef6 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -136,7 +136,7 @@ ReturnedValue ArrayPrototype::method_toString(const BuiltinFunction *builtin, Ca
callData->accumulator = v4->newString(QStringLiteral("join"));
callData->function = static_cast<Object &>(callData->thisObject).get(static_cast<String *>(&callData->accumulator));
if (callData->function.isFunctionObject())
- return static_cast<FunctionObject &>(callData->function).call(callData);
+ return static_cast<FunctionObject &>(callData->function).call(&callData->thisObject, callData->args, callData->argc());
return ObjectPrototype::method_toString(builtin, callData);
}
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 54896382fb..2ae2cc57e9 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -69,15 +69,17 @@ DEFINE_OBJECT_VTABLE(FunctionObject);
Q_STATIC_ASSERT((Heap::FunctionObject::markTable & Heap::Object::markTable) == Heap::Object::markTable);
-static ReturnedValue jsCallWrapper(const QV4::Managed *m, CallData *data)
+static ReturnedValue jsCallWrapper(const QV4::FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
{
- const FunctionObject *f = static_cast<const FunctionObject *>(m);
- return f->vtable()->call(f, data);
+ Scope scope(f->engine());
+ JSCall callData(scope, f->asReturnedValue(), argv, argc, thisObject);
+ return f->vtable()->call(f, callData);
}
-ReturnedValue jsConstructWrapper(const QV4::Managed *m, CallData *data)
+ReturnedValue jsConstructWrapper(const QV4::FunctionObject *f, const Value *argv, int argc)
{
- const FunctionObject *f = static_cast<const FunctionObject *>(m);
- return f->vtable()->construct(f, data);
+ Scope scope(f->engine());
+ JSCall callData(scope, f->asReturnedValue(), argv, argc);
+ return f->vtable()->construct(f, callData);
}
@@ -97,8 +99,8 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name,
void Heap::FunctionObject::init(QV4::ExecutionContext *scope, Function *function, bool createProto)
{
- jsCall = reinterpret_cast<const ObjectVTable *>(vtable())->call;
- jsConstruct = reinterpret_cast<const ObjectVTable *>(vtable())->construct;
+ jsCall = jsCallWrapper;
+ jsConstruct = jsConstructWrapper;
Object::init();
this->function = function;
@@ -119,8 +121,8 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, const QString &nam
void Heap::FunctionObject::init()
{
- jsCall = reinterpret_cast<const ObjectVTable *>(vtable())->call;
- jsConstruct = reinterpret_cast<const ObjectVTable *>(vtable())->construct;
+ jsCall = jsCallWrapper;
+ jsConstruct = jsConstructWrapper;
Object::init();
function = nullptr;
@@ -349,7 +351,7 @@ ReturnedValue FunctionPrototype::method_call(const BuiltinFunction *b, CallData
callData->args[i] = callData->args[i + 1];
--engine->jsStackTop;
}
- return static_cast<FunctionObject &>(callData->function).call(callData);
+ return static_cast<FunctionObject &>(callData->function).call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue FunctionPrototype::method_bind(const BuiltinFunction *b, CallData *callData)
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index 36f873e1a2..f5354aed08 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -64,8 +64,8 @@ namespace QV4 {
struct BuiltinFunction;
struct IndexedBuiltinFunction;
-typedef ReturnedValue (*jsCallFunction)(const Managed *, CallData *data);
-typedef ReturnedValue (*jsConstructFunction)(const Managed *, CallData *data);
+typedef ReturnedValue (*jsCallFunction)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+typedef ReturnedValue (*jsConstructFunction)(const FunctionObject *, const Value *argv, int argc);
namespace Heap {
@@ -155,11 +155,11 @@ struct Q_QML_EXPORT FunctionObject: Object {
void init(String *name, bool createProto);
- ReturnedValue construct(CallData *callData) {
- return d()->jsConstruct(this, callData);
+ ReturnedValue construct(const Value *argv, int argc) const {
+ return d()->jsConstruct(this, argv, argc);
}
- ReturnedValue call(CallData *callData) {
- return d()->jsCall(this, callData);
+ ReturnedValue call(const Value *thisObject, const Value *argv, int argc) const {
+ return d()->jsCall(this, thisObject, argv, argc);
}
static ReturnedValue construct(const Managed *that, CallData *);
static ReturnedValue call(const Managed *that, CallData *d);
diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h
index bf85d75fdf..75f866706b 100644
--- a/src/qml/jsruntime/qv4jscall_p.h
+++ b/src/qml/jsruntime/qv4jscall_p.h
@@ -93,7 +93,7 @@ struct JSCall {
ptr->setArgc(argc);
memcpy(ptr->args, argv, argc*sizeof(Value));
}
- JSCall(const Scope &scope, ReturnedValue function, Value *argv, int argc, Value *thisObject = 0)
+ JSCall(const Scope &scope, ReturnedValue function, const Value *argv, int argc, const Value *thisObject = 0)
{
int size = int(offsetof(QV4::CallData, args)/sizeof(QV4::Value)) + argc;
ptr = reinterpret_cast<CallData *>(scope.engine->jsStackTop);
@@ -115,11 +115,11 @@ struct JSCall {
}
ReturnedValue call() const {
- return static_cast<FunctionObject &>(ptr->function).call(ptr);
+ return static_cast<FunctionObject &>(ptr->function).call(&ptr->thisObject, ptr->args, ptr->argc());
}
ReturnedValue callAsConstructor() const {
- return static_cast<FunctionObject &>(ptr->function).construct(ptr);
+ return static_cast<FunctionObject &>(ptr->function).construct(ptr->args, ptr->argc());
}
CallData *ptr;
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 08bffeb2ce..9077be7bfe 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -970,15 +970,12 @@ uint Runtime::method_compareIn(ExecutionEngine *engine, const Value &left, const
ReturnedValue Runtime::method_callGlobalLookup(ExecutionEngine *engine, uint index, Value *argv, int argc)
{
Lookup *l = engine->currentStackFrame->v4Function->compilationUnit->runtimeLookups + index;
- ReturnedValue function = l->globalGetter(l, engine);
- Scope scope(engine);
- JSCall callData(scope, function, argv, argc);
- Q_ASSERT(callData->args + callData->argc() == engine->jsStackTop);
-
- if (!callData->function.isFunctionObject())
+ Value function = Value::fromReturnedValue(l->globalGetter(l, engine));
+ if (!function.isFunctionObject())
return engine->throwTypeError();
- return static_cast<FunctionObject &>(callData->function).call(callData);
+ Value thisObject = Primitive::undefinedValue();
+ return static_cast<FunctionObject &>(function).call(&thisObject, argv, argc);
}
ReturnedValue Runtime::method_callPossiblyDirectEval(ExecutionEngine *engine, Value *argv, int argc)
@@ -1005,7 +1002,7 @@ ReturnedValue Runtime::method_callPossiblyDirectEval(ExecutionEngine *engine, Va
if (f.d() == engine->evalFunction()->d())
return static_cast<EvalFunction &>(f).evalCall(callData, true);
- return f.call(callData);
+ return f.call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue Runtime::method_callName(ExecutionEngine *engine, int nameIndex, Value *argv, int argc)
@@ -1032,7 +1029,7 @@ ReturnedValue Runtime::method_callName(ExecutionEngine *engine, int nameIndex, V
}
FunctionObject &f = static_cast<FunctionObject &>(callData->function);
- return f.call(callData);
+ return f.call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue Runtime::method_callProperty(ExecutionEngine *engine, Value *base, int nameIndex, Value *argv, int argc)
@@ -1066,7 +1063,7 @@ ReturnedValue Runtime::method_callProperty(ExecutionEngine *engine, Value *base,
}
FunctionObject &f = static_cast<FunctionObject &>(callData->function);
- return f.call(callData);
+ return f.call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue Runtime::method_callPropertyLookup(ExecutionEngine *engine, Value *base, uint index, Value *argv, int argc)
@@ -1083,7 +1080,7 @@ ReturnedValue Runtime::method_callPropertyLookup(ExecutionEngine *engine, Value
return engine->throwTypeError();
FunctionObject &f = static_cast<FunctionObject &>(callData->function);
- return f.call(callData);
+ return f.call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue Runtime::method_callElement(ExecutionEngine *engine, Value *base, const Value &index, Value *argv, int argc)
@@ -1101,7 +1098,7 @@ ReturnedValue Runtime::method_callElement(ExecutionEngine *engine, Value *base,
if (!callData->function.isFunctionObject())
return engine->throwTypeError();
- return static_cast<FunctionObject &>(callData->function).call(callData);
+ return static_cast<FunctionObject &>(callData->function).call(&callData->thisObject, callData->args, callData->argc());
}
ReturnedValue Runtime::method_callValue(ExecutionEngine *engine, const Value &func, Value *argv, int argc)
@@ -1113,20 +1110,16 @@ ReturnedValue Runtime::method_callValue(ExecutionEngine *engine, const Value &fu
JSCall callData(scope, func.asReturnedValue(), argv, argc);
Q_ASSERT(callData->args + callData->argc() == engine->jsStackTop);
- return static_cast<FunctionObject &>(callData->function).call(callData);
+ return static_cast<FunctionObject &>(callData->function).call(&callData->thisObject, callData->args, callData->argc());
}
-ReturnedValue Runtime::method_construct(ExecutionEngine *engine, const Value &func, Value *argv, int argc)
+ReturnedValue Runtime::method_construct(ExecutionEngine *engine, const Value &function, Value *argv, int argc)
{
- if (!func.isFunctionObject())
+ if (!function.isFunctionObject())
return engine->throwTypeError();
- Scope scope(engine);
- JSCall callData(scope, func.asReturnedValue(), argv, argc);
- Q_ASSERT(callData->args + callData->argc() == engine->jsStackTop);
-
- return static_cast<FunctionObject &>(callData->function).construct(callData);
+ return static_cast<const FunctionObject &>(function).construct(argv, argc);
}
void Runtime::method_throwException(ExecutionEngine *engine, const Value &value)