History

rework ScriptValue to act like a stack variable rather than a pointer

Heather Anderson committed 5 years ago

Commit 85810221 parent f209c51170 files · +2837 −2594Browse files

Showing the changes to plugins/JSAPIExample/src/JSAPIExample.cpp (1 of 170 files). Show all

Unified · Split

plugins/JSAPIExample/src/JSAPIExample.cpp+6−5
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 #include <QtCore/QSharedPointer>
1818 #include <QtCore/QJsonObject>
1919 #include <QtCore/QLoggingCategory>
20+#include <QtCore/QSharedPointer>
2021 #include <QtCore/QThread>
2122 #include <QtCore/QTimer>
2223
@@ -65,7 +66,7 @@ namespace REPLACE_ME_WITH_UNIQUE_NAME { · 42 unmodified lines
6566 qCWarning(logger) << "registering w/ScriptInitializerMixin..." << scriptInit.data();
6667 scriptInit->registerScriptInitializer([this](ScriptEngine* engine) {
6768 auto value = engine->newQObject(this, ScriptEngine::QtOwnership);
68− engine->globalObject()->setProperty(objectName(), value);
69+ engine->globalObject().setProperty(objectName(), value);
6970 // qCDebug(logger) << "setGlobalInstance" << objectName() << engine->property("fileName");
7071 });
7172 // qCInfo(logger) << "plugin loaded" << qApp << toString() << QThread::currentThread();
@@ -73,7 +74,7 @@ namespace REPLACE_ME_WITH_UNIQUE_NAME { · 1 unmodified line
7374
7475 // NOTES: everything within the "public slots:" section below will be available from JS via overall plugin QObject
7576 // also, to demonstrate future-proofing JS API code, QVariant's are used throughout most of these examples --
76− // which still makes them very Qt-specific, but avoids depending directly on deprecated ScriptValuePointer APIs.
77+ // which still makes them very Qt-specific, but avoids depending directly on deprecated ScriptValue APIs.
7778 // (as such this plugin class and its methods remain forward-compatible with other engines like QML's QJSEngine)
7879
7980 public slots:
@@ -160,14 +161,14 @@ namespace REPLACE_ME_WITH_UNIQUE_NAME { · 80 unmodified lines
160161 * print("all example::* keys", settings.allKeys());
161162 * settings = null; // optional best pratice; allows the object to be reclaimed ASAP by the JS garbage collector
162163 */
163− ScriptValuePointer getScopedSettings(const QString& scope) {
164+ ScriptValue getScopedSettings(const QString& scope) {
164165 auto engine = Scriptable::engine();
165166 if (!engine) {
166− return ScriptValuePointer();
167+ return ScriptValue();
167168 }
168169 auto manager = engine->manager();
169170 if (!manager) {
170− return ScriptValuePointer();
171+ return ScriptValue();
171172 }
172173 QString error;
173174 auto cppValue = createScopedSettings(scope, manager, error);