aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-12 14:57:24 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-17 13:10:16 +0100
commitb0e9c83f99aa7090c82b7c55894f5e264b74608a (patch)
tree39a11795b7d17483ce05be5b23c380864eb9bb29 /src
parent2fab46e711abfc04edd1791d050722d1fbfbc7d2 (diff)
Don't store the scope in JSCallData
We only need it when generating CallData, or when filling in any thisObject or arguments that weren't provided. Provide a constructor that expects thisObject and arguments to be pre-allocated and one that allocates them in a scope passed as argument. Change-Id: Iddfba63f4dbc5b09e2b33fb22a94eea88f515902 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp2
-rw-r--r--src/qml/jsruntime/qv4jscall_p.h22
-rw-r--r--src/qml/jsruntime/qv4proxy.cpp22
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp8
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp4
-rw-r--r--src/qml/qml/qqmlbinding.cpp4
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp4
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp2
-rw-r--r--src/qml/qml/qqmlpropertybinding.cpp4
9 files changed, 34 insertions, 38 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 03b99bf564..7bbf6e9133 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -2089,7 +2089,7 @@ ReturnedValue ExecutionEngine::callInContext(Function *function, QObject *self,
QV4::JSCallData jsCall(scope, argc);
QV4::populateJSCallArguments(this, jsCall, argc, args, types);
- QV4::CallData *callData = jsCall->callData();
+ QV4::CallData *callData = jsCall->callData(scope);
return function->call(selfValue, callData->argValues<QV4::Value>(), callData->argc(),
qmlContext);
}
diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h
index 66ff1e7c3b..43dc0de727 100644
--- a/src/qml/jsruntime/qv4jscall_p.h
+++ b/src/qml/jsruntime/qv4jscall_p.h
@@ -62,30 +62,27 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
struct JSCallData {
- JSCallData(const Scope &scope, int argc = 0, const Value *argv = nullptr, const Value *thisObject = nullptr)
- : scope(scope), argc(argc)
+ JSCallData(const Value *thisObject, const Value *argv, int argc)
+ : argc(argc), args(const_cast<Value *>(argv)), thisObject(const_cast<Value *>(thisObject))
+ {
+ }
+
+ JSCallData(const Scope &scope, int argc = 0)
+ : argc(argc), args(scope.alloc(argc)), thisObject(scope.alloc())
{
- if (thisObject)
- this->thisObject = const_cast<Value *>(thisObject);
- else
- this->thisObject = scope.alloc();
- if (argv)
- this->args = const_cast<Value *>(argv);
- else
- this->args = scope.alloc(argc);
}
JSCallData *operator->() {
return this;
}
- CallData *callData(const FunctionObject *f = nullptr) const {
+ CallData *callData(const Scope &scope, const FunctionObject *f = nullptr) const {
int size = int(offsetof(QV4::CallData, args)/sizeof(QV4::Value)) + argc;
CallData *ptr = reinterpret_cast<CallData *>(scope.alloc<Scope::Uninitialized>(size));
ptr->function = Encode::undefined();
ptr->context = Encode::undefined();
ptr->accumulator = Encode::undefined();
- ptr->thisObject = thisObject->asReturnedValue();
+ ptr->thisObject = thisObject ? thisObject->asReturnedValue() : Encode::undefined();
ptr->newTarget = Encode::undefined();
ptr->setArgc(argc);
if (argc)
@@ -94,7 +91,6 @@ struct JSCallData {
ptr->function = f->asReturnedValue();
return ptr;
}
- const Scope &scope;
int argc;
Value *args;
Value *thisObject;
diff --git a/src/qml/jsruntime/qv4proxy.cpp b/src/qml/jsruntime/qv4proxy.cpp
index 8bfc9fc3ba..bc46f0ce58 100644
--- a/src/qml/jsruntime/qv4proxy.cpp
+++ b/src/qml/jsruntime/qv4proxy.cpp
@@ -90,7 +90,7 @@ ReturnedValue ProxyObject::virtualGet(const Managed *m, PropertyKey id, const Va
if (hasProperty)
*hasProperty = true;
- JSCallData cdata(scope, 3, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(3), 3);
cdata.args[0] = target;
cdata.args[1] = id.toStringOrSymbol(scope.engine);
cdata.args[2] = *receiver;
@@ -131,7 +131,7 @@ bool ProxyObject::virtualPut(Managed *m, PropertyKey id, const Value &value, Val
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(scope, 4, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(4), 4);
cdata.args[0] = target;
cdata.args[1] = id.toStringOrSymbol(scope.engine);
cdata.args[2] = value;
@@ -172,7 +172,7 @@ bool ProxyObject::virtualDeleteProperty(Managed *m, PropertyKey id)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(scope, 3, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(3), 3);
cdata.args[0] = target;
cdata.args[1] = id.toStringOrSymbol(scope.engine);
cdata.args[2] = o->d(); // ### fix receiver handling
@@ -208,7 +208,7 @@ bool ProxyObject::virtualHasProperty(const Managed *m, PropertyKey id)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(scope, 2, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(2), 2);
cdata.args[0] = target;
cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
@@ -250,7 +250,7 @@ PropertyAttributes ProxyObject::virtualGetOwnProperty(const Managed *m, Property
return Attr_Invalid;
}
- JSCallData cdata(scope, 2, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(2), 2);
cdata.args[0] = target;
cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
@@ -325,7 +325,7 @@ bool ProxyObject::virtualDefineOwnProperty(Managed *m, PropertyKey id, const Pro
return false;
}
- JSCallData cdata(scope, 3, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(3), 3);
cdata.args[0] = target;
cdata.args[1] = id.isArrayIndex() ? Value::fromUInt32(id.asArrayIndex()).toString(scope.engine) : id.asStringOrSymbol();
cdata.args[2] = ObjectPrototype::fromPropertyDescriptor(scope.engine, p, attrs);
@@ -377,7 +377,7 @@ bool ProxyObject::virtualIsExtensible(const Managed *m)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(scope, 1, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(1), 1);
cdata.args[0] = target;
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
@@ -410,7 +410,7 @@ bool ProxyObject::virtualPreventExtensions(Managed *m)
if (!trap->isFunctionObject())
return scope.engine->throwTypeError();
- JSCallData cdata(scope, 1, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(1), 1);
cdata.args[0] = target;
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
@@ -447,7 +447,7 @@ Heap::Object *ProxyObject::virtualGetPrototypeOf(const Managed *m)
return nullptr;
}
- JSCallData cdata(scope, 1, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(1), 1);
cdata.args[0] = target;
ScopedValue trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
@@ -491,7 +491,7 @@ bool ProxyObject::virtualSetPrototypeOf(Managed *m, const Object *p)
return false;
}
- JSCallData cdata(scope, 2, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(2), 2);
cdata.args[0] = target;
cdata.args[1] = p ? p->asReturnedValue() : Encode::null();
@@ -584,7 +584,7 @@ OwnPropertyKeyIterator *ProxyObject::virtualOwnPropertyKeys(const Object *m, Val
return nullptr;
}
- JSCallData cdata(scope, 1, nullptr, handler);
+ JSCallData cdata(handler, scope.alloc(1), 1);
cdata.args[0] = target;
ScopedObject trapResult(scope, static_cast<const FunctionObject *>(trap.ptr)->call(cdata));
if (scope.engine->hasException)
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 41a57e36c9..f8268849ff 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -2205,8 +2205,8 @@ ReturnedValue QObjectMethod::callInternal(const Value *thisObject, const Value *
}
Scope scope(v4);
- JSCallData cData(scope, argc, argv, thisObject);
- CallData *callData = cData.callData();
+ JSCallData cData(thisObject, argv, argc);
+ CallData *callData = cData.callData(scope);
auto method = d()->methods[0];
@@ -2307,8 +2307,8 @@ ReturnedValue QMetaObjectWrapper::constructInternal(const Value *argv, int argc)
Scope scope(v4);
Scoped<QObjectWrapper> object(scope);
- JSCallData cData(scope, argc, argv);
- CallData *callData = cData.callData();
+ JSCallData cData(scope.alloc(), argv, argc);
+ CallData *callData = cData.callData(scope);
const QQmlObjectOrGadget objectOrGadget(mo);
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 393f99dd8f..2ea54a3512 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -802,7 +802,7 @@ ReturnedValue Runtime::GetIterator::call(ExecutionEngine *engine, const Value &i
ScopedFunctionObject f(scope, o->get(engine->symbol_iterator()));
if (!f)
return engine->throwTypeError();
- JSCallData cData(scope, 0, nullptr, o);
+ JSCallData cData(o, scope.alloc(0), 0);
ScopedObject it(scope, f->call(cData));
if (engine->hasException)
return Encode::undefined();
@@ -825,7 +825,7 @@ ReturnedValue Runtime::IteratorNext::call(ExecutionEngine *engine, const Value &
engine->throwTypeError();
return Encode(true);
}
- JSCallData cData(scope, 0, nullptr, &iterator);
+ JSCallData cData(&iterator, scope.alloc(0), 0);
ScopedObject o(scope, f->call(cData));
if (scope.hasException())
return Encode(true);
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 69ac63b0ad..b54ac38b64 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -211,9 +211,9 @@ QV4::ReturnedValue QQmlBinding::evaluate(bool *isUndefined)
thisObject = &b->d()->boundThis;
}
QV4::Scope scope(v4);
- QV4::JSCallData jsCall(scope, argc, argv, thisObject);
+ QV4::JSCallData jsCall(thisObject, argv, argc);
- return QQmlJavaScriptExpression::evaluate(jsCall.callData(), isUndefined);
+ return QQmlJavaScriptExpression::evaluate(jsCall.callData(scope), isUndefined);
}
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 9e1e056381..8a641970e7 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -196,7 +196,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
QV4::JSCallData jsCall(scope, argCount);
populateJSCallArguments(v4, jsCall, argCount, a, storage.constData());
- QQmlJavaScriptExpression::evaluate(jsCall.callData(), nullptr);
+ QQmlJavaScriptExpression::evaluate(jsCall.callData(scope), nullptr);
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
}
@@ -219,7 +219,7 @@ void QQmlBoundSignalExpression::evaluate(const QList<QVariant> &args)
jsCall->args[ii] = scope.engine->fromVariant(args[ii]);
}
- QQmlJavaScriptExpression::evaluate(jsCall.callData(), nullptr);
+ QQmlJavaScriptExpression::evaluate(jsCall.callData(scope), nullptr);
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
}
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index 1a4d452bfd..ba792cbd8f 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -187,7 +187,7 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(bool *isUndefined)
QV4::Scope scope(v4);
QV4::JSCallData jsCall(scope);
- return evaluate(jsCall.callData(), isUndefined);
+ return evaluate(jsCall.callData(scope), isUndefined);
}
QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QV4::CallData *callData, bool *isUndefined)
diff --git a/src/qml/qml/qqmlpropertybinding.cpp b/src/qml/qml/qqmlpropertybinding.cpp
index ecb1efec2c..af237b60cb 100644
--- a/src/qml/qml/qqmlpropertybinding.cpp
+++ b/src/qml/qml/qqmlpropertybinding.cpp
@@ -472,9 +472,9 @@ QV4::ReturnedValue QQmlPropertyBindingJSForBoundFunction::evaluate(bool *isUndef
thisObject = &b->d()->boundThis;
}
QV4::Scope scope(v4);
- QV4::JSCallData jsCall(scope, argc, argv, thisObject);
+ QV4::JSCallData jsCall(thisObject, argv, argc);
- return QQmlJavaScriptExpression::evaluate(jsCall.callData(), isUndefined);
+ return QQmlJavaScriptExpression::evaluate(jsCall.callData(scope), isUndefined);
}
QT_END_NAMESPACE