Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 49 files). Show all
Unified · Split
| @@ -133,7 +133,7 @@ static ScriptValue debugPrint(ScriptContext* context, ScriptEngine* engine) { · 132 unmodified lines | ||
| 133 | 133 | ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan |
| 134 | 134 | while (userContext && userContext->functionContext()->functionType() == ScriptFunctionContext::NativeFunction) { |
| 135 | 135 | parentContext = userContext->parentContext(); |
| 136 | − userContext = parentContext.data(); | |
| 136 | + userContext = parentContext.get(); | |
| 137 | 137 | } |
| 138 | 138 | QString location; |
| 139 | 139 | if (userContext) { |
| @@ -211,7 +211,8 @@ ScriptManagerPointer scriptManagerFactory(ScriptManager::Context context, · 71 unmodified lines | ||
| 211 | 211 | ScriptManagerPointer newScriptManager(ScriptManager::Context context, |
| 212 | 212 | const QString& scriptContents, |
| 213 | 213 | const QString& fileNameString) { |
| 214 | − ScriptManagerPointer manager(new ScriptManager(context, scriptContents, fileNameString), &QObject::deleteLater); | |
| 214 | + ScriptManagerPointer manager(new ScriptManager(context, scriptContents, fileNameString), | |
| 215 | + [](ScriptManager* obj) { obj->deleteLater(); }); | |
| 215 | 216 | ScriptEnginePointer engine = newScriptEngine(manager.get()); |
| 216 | 217 | manager->_engine = engine; |
| 217 | 218 | return manager; |
| @@ -559,7 +560,7 @@ static ScriptValue createScriptableResourcePrototype(ScriptManagerPointer manage · 341 unmodified lines | ||
| 559 | 560 | auto prototype = engine->newObject(); |
| 560 | 561 | |
| 561 | 562 | // Expose enum State to JS/QML via properties |
| 562 | − QObject* state = new QObject(manager.data()); | |
| 563 | + QObject* state = new QObject(manager.get()); | |
| 563 | 564 | state->setObjectName("ResourceState"); |
| 564 | 565 | auto metaEnum = QMetaEnum::fromType<ScriptableResource::State>(); |
| 565 | 566 | for (int i = 0; i < metaEnum.keyCount(); ++i) { |
| @@ -623,7 +624,7 @@ void ScriptManager::init() { · 57 unmodified lines | ||
| 623 | 624 | _isInitialized = true; |
| 624 | 625 | runStaticInitializers(this); |
| 625 | 626 | |
| 626 | − auto scriptEngine = _engine.data(); | |
| 627 | + auto scriptEngine = _engine.get(); | |
| 627 | 628 | |
| 628 | 629 | // register various meta-types |
| 629 | 630 | registerMIDIMetaTypes(scriptEngine); |
| @@ -693,7 +694,7 @@ void ScriptManager::init() { · 63 unmodified lines | ||
| 693 | 694 | scriptEngine->registerFunction("console", "groupEnd", ConsoleScriptingInterface::groupEnd, 0); |
| 694 | 695 | |
| 695 | 696 | // Scriptable cache access |
| 696 | − auto resourcePrototype = createScriptableResourcePrototype(qSharedPointerCast<ScriptManager>(sharedFromThis())); | |
| 697 | + auto resourcePrototype = createScriptableResourcePrototype(shared_from_this()); | |
| 697 | 698 | scriptEngine->globalObject().setProperty("Resource", resourcePrototype); |
| 698 | 699 | scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype); |
| 699 | 700 | scriptRegisterMetaType(scriptEngine, scriptableResourceToScriptValue, scriptableResourceFromScriptValue); |
| @@ -960,7 +961,7 @@ void ScriptManager::run() { · 260 unmodified lines | ||
| 960 | 961 | |
| 961 | 962 | emit releaseEntityPacketSenderMessages(true); |
| 962 | 963 | |
| 963 | − emit finished(_fileNameString, qSharedPointerCast<ScriptManager>(sharedFromThis())); | |
| 964 | + emit finished(_fileNameString, shared_from_this()); | |
| 964 | 965 | |
| 965 | 966 | // Don't leave our local-file-access flag laying around, reset it to false when the scriptengine |
| 966 | 967 | // thread is finished |
| @@ -1117,7 +1118,7 @@ QUrl ScriptManager::resolvePath(const QString& include) const { · 150 unmodified lines | ||
| 1117 | 1118 | auto contextInfo = context->functionContext(); |
| 1118 | 1119 | parentURL = QUrl(contextInfo->fileName()); |
| 1119 | 1120 | parentContext = context->parentContext(); |
| 1120 | − context = parentContext.data(); | |
| 1121 | + context = parentContext.get(); | |
| 1121 | 1122 | } while (parentURL.isRelative() && context); |
| 1122 | 1123 | |
| 1123 | 1124 | if (parentURL.isRelative()) { |
| @@ -1258,7 +1259,8 @@ ScriptValue ScriptManager::currentModule() { · 134 unmodified lines | ||
| 1258 | 1259 | auto cache = jsRequire.property("cache"); |
| 1259 | 1260 | ScriptValue candidate; |
| 1260 | 1261 | ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan |
| 1261 | − for (auto context = _engine->currentContext(); context && !candidate.isObject(); parentContext = context->parentContext(), context = parentContext.data()) { | |
| 1262 | + for (auto context = _engine->currentContext(); context && !candidate.isObject(); | |
| 1263 | + parentContext = context->parentContext(), context = parentContext.get()) { | |
| 1262 | 1264 | auto contextInfo = context->functionContext(); |
| 1263 | 1265 | candidate = cache.property(contextInfo->fileName()); |
| 1264 | 1266 | } |
| @@ -1808,10 +1810,10 @@ void ScriptManager::loadEntityScript(const EntityItemID& entityID, const QString · 543 unmodified lines | ||
| 1808 | 1810 | |
| 1809 | 1811 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 1810 | 1812 | // note: see EntityTreeRenderer.cpp for shared pointer lifecycle management |
| 1811 | − QWeakPointer<ScriptManager> weakRef(sharedFromThis()); | |
| 1813 | + std::weak_ptr<ScriptManager> weakRef(shared_from_this()); | |
| 1812 | 1814 | scriptCache->getScriptContents(entityScript, |
| 1813 | 1815 | [this, weakRef, entityScript, entityID](const QString& url, const QString& contents, bool isURL, bool success, const QString& status) { |
| 1814 | − QSharedPointer<ScriptManager> strongRef(weakRef); | |
| 1816 | + std::shared_ptr<ScriptManager> strongRef(weakRef); | |
| 1815 | 1817 | if (!strongRef) { |
| 1816 | 1818 | qCWarning(scriptengine) << "loadEntityScript.contentAvailable -- ScriptManager was deleted during getScriptContents!!"; |
| 1817 | 1819 | return; |
| @@ -1929,7 +1931,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 111 unmodified lines | ||
| 1929 | 1931 | return; |
| 1930 | 1932 | } |
| 1931 | 1933 | auto program = _engine->newProgram( contents, fileName ); |
| 1932 | − if (program.isNull()) { | |
| 1934 | + if (!program) { | |
| 1933 | 1935 | setError("Bad program (isNull)", EntityScriptStatus::ERROR_RUNNING_SCRIPT); |
| 1934 | 1936 | emit unhandledException(_engine->makeError(_engine->newValue("program.isNull"))); |
| 1935 | 1937 | return; // done processing script |
| @@ -2337,7 +2339,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 401 unmodified lines | ||
| 2337 | 2339 | } |
| 2338 | 2340 | |
| 2339 | 2341 | if (callAllowed && entityScript.property(methodName).isFunction()) { |
| 2340 | − auto scriptEngine = engine().data(); | |
| 2342 | + auto scriptEngine = engine().get(); | |
| 2341 | 2343 | |
| 2342 | 2344 | ScriptValueList args; |
| 2343 | 2345 | args << EntityItemIDtoScriptValue(scriptEngine, entityID); |
| @@ -2380,7 +2382,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 36 unmodified lines | ||
| 2380 | 2382 | } |
| 2381 | 2383 | ScriptValue entityScript = details.scriptObject; // previously loaded |
| 2382 | 2384 | if (entityScript.property(methodName).isFunction()) { |
| 2383 | − auto scriptEngine = engine().data(); | |
| 2385 | + auto scriptEngine = engine().get(); | |
| 2384 | 2386 | |
| 2385 | 2387 | ScriptValueList args; |
| 2386 | 2388 | args << EntityItemIDtoScriptValue(scriptEngine, entityID); |
| @@ -2420,7 +2422,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 33 unmodified lines | ||
| 2420 | 2422 | } |
| 2421 | 2423 | ScriptValue entityScript = details.scriptObject; // previously loaded |
| 2422 | 2424 | if (entityScript.property(methodName).isFunction()) { |
| 2423 | − auto scriptEngine = engine().data(); | |
| 2425 | + auto scriptEngine = engine().get(); | |
| 2424 | 2426 | |
| 2425 | 2427 | ScriptValueList args; |
| 2426 | 2428 | args << EntityItemIDtoScriptValue(scriptEngine, entityID); |