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