diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-12 15:46:29 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-17 13:10:22 +0100 |
commit | 9caea013ceb221b5617c4940e7bb9ee9fecdd631 (patch) | |
tree | f4480e860a965f6515e516475baeced69b5d91fd /src/qml/jsapi/qjsvalue.cpp | |
parent | b0e9c83f99aa7090c82b7c55894f5e264b74608a (diff) |
Clean up JSCallData setup
We either have pre-populated arguments and thisObject, then we can just
use them and keep them const. Or, we want to allocate and populate the
arguments and the thisObject. Then, do allocate them in a separate
object, and transform that into JSCallData afterwards if necessary.
Furthermore, avoid alloc(0) as that just returns the current stack top.
Writing to it will clobber other data. Rather, just use nullptr and
crash if it's written to.
Also, remove the useless operator-> from JSCallData. That one just
confuses the reader.
Change-Id: I8310911fcfe005b05a07b78fcb3791d991a0c2ce
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsvalue.cpp')
-rw-r--r-- | src/qml/jsapi/qjsvalue.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index c565f4c372..e6b310e86c 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -690,14 +690,14 @@ QJSValue QJSValue::call(const QJSValueList &args) const Q_ASSERT(engine); Scope scope(engine); - JSCallData jsCallData(scope, args.length()); - *jsCallData->thisObject = engine->globalObject; + JSCallArguments jsCallData(scope, args.length()); + *jsCallData.thisObject = engine->globalObject; for (int i = 0; i < args.size(); ++i) { if (!QJSValuePrivate::checkEngine(engine, args.at(i))) { qWarning("QJSValue::call() failed: cannot call function with argument created in a different engine"); return QJSValue(); } - jsCallData->args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); + jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); } ScopedValue result(scope, f->call(jsCallData)); @@ -744,14 +744,14 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList return QJSValue(); } - JSCallData jsCallData(scope, args.size()); - *jsCallData->thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance); + JSCallArguments jsCallData(scope, args.size()); + *jsCallData.thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance); for (int i = 0; i < args.size(); ++i) { if (!QJSValuePrivate::checkEngine(engine, args.at(i))) { qWarning("QJSValue::call() failed: cannot call function with argument created in a different engine"); return QJSValue(); } - jsCallData->args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); + jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); } ScopedValue result(scope, f->call(jsCallData)); @@ -791,13 +791,13 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args) const Q_ASSERT(engine); Scope scope(engine); - JSCallData jsCallData(scope, args.size()); + JSCallArguments jsCallData(scope, args.size()); for (int i = 0; i < args.size(); ++i) { if (!QJSValuePrivate::checkEngine(engine, args.at(i))) { qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine"); return QJSValue(); } - jsCallData->args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); + jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i)); } ScopedValue result(scope, f->callAsConstructor(jsCallData)); |