diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2023-03-03 10:01:29 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-03-06 09:17:43 +0000 |
commit | 73994b550f85576844df229c6c7bea44604091e9 (patch) | |
tree | 2bbdbe27c9e7ffab496791917b0b02831d8cbb8a /src/lib/corelib/buildgraph | |
parent | 1f8c6d3560607078cf33a396f1907bb1677ba234 (diff) |
Prevent dangling JS values
As opposed to QtScript, such values cannot be re-used in QuickJS. This
was overlooked in 087c22e17721f37490dd2048a567b6a58065d939.
I assume this is the culprit for seemingly random crashes and "not a
function" messages we have been seeing sometimes when building with Qt
Creator.
Change-Id: Ia4e7aed0cda97439ac75db5ecfbf08ff096a02b2
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'src/lib/corelib/buildgraph')
-rw-r--r-- | src/lib/corelib/buildgraph/depscanner.cpp | 9 | ||||
-rw-r--r-- | src/lib/corelib/buildgraph/transformer.cpp | 12 |
2 files changed, 5 insertions, 16 deletions
diff --git a/src/lib/corelib/buildgraph/depscanner.cpp b/src/lib/corelib/buildgraph/depscanner.cpp index e4e10f477..01e781a54 100644 --- a/src/lib/corelib/buildgraph/depscanner.cpp +++ b/src/lib/corelib/buildgraph/depscanner.cpp @@ -238,16 +238,11 @@ QStringList UserDependencyScanner::evaluate(Artifact *artifact, const ScopedJsValueList argsMgr(m_engine->context(), args); const TemporaryGlobalObjectSetter gos(m_engine, m_global); - JSValue &function = script.scriptFunction; - if (!JS_IsFunction(m_engine->context(), function)) { - function = m_engine->evaluate(JsValueOwner::ScriptEngine, script.sourceCode()); - if (Q_UNLIKELY(!JS_IsFunction(m_engine->context(), function))) - throw ErrorInfo(Tr::tr("Invalid scan script."), script.location()); - } + const JSValue function = script.getFunction(m_engine, Tr::tr("Invalid scan script.")); const ScopedJsValue result( m_engine->context(), JS_Call(m_engine->context(), function, m_engine->globalObject(), - int(args.size()), args.data())); + int(args.size()), args.data())); m_engine->clearRequestedProperties(); if (JsException ex = m_engine->checkAndClearException(script.location())) { ErrorInfo err = ex.toErrorInfo(); diff --git a/src/lib/corelib/buildgraph/transformer.cpp b/src/lib/corelib/buildgraph/transformer.cpp index ae044cd2c..2346ad5c9 100644 --- a/src/lib/corelib/buildgraph/transformer.cpp +++ b/src/lib/corelib/buildgraph/transformer.cpp @@ -259,18 +259,12 @@ AbstractCommandPtr Transformer::createCommandFromScriptValue( void Transformer::createCommands(ScriptEngine *engine, const PrivateScriptFunction &script, const JSValueList &args) { - if (JS_IsUndefined(script.scriptFunction)) { - script.scriptFunction = engine->evaluate(JsValueOwner::ScriptEngine, script.sourceCode(), - script.location().filePath(), - script.location().line()); - if (Q_UNLIKELY(!JS_IsFunction(engine->context(), script.scriptFunction))) - throw ErrorInfo(Tr::tr("Invalid prepare script."), script.location()); - } JSValueList argv(args.cbegin(), args.cend()); + const JSValue function = script.getFunction(engine, Tr::tr("Invalid prepare script.")); const ScopedJsValue scriptValue( engine->context(), - JS_Call(engine->context(), script.scriptFunction, engine->globalObject(), - int(argv.size()), argv.data())); + JS_Call(engine->context(), function, engine->globalObject(), + int(argv.size()), argv.data())); propertiesRequestedInPrepareScript = engine->propertiesRequestedInScript(); propertiesRequestedFromArtifactInPrepareScript = engine->propertiesRequestedFromArtifact(); importedFilesUsedInPrepareScript = engine->importedFilesUsedInScript(); |