summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/qbs-setup-toolchains/xcodeprobe.cpp2
-rw-r--r--src/lib/corelib/language/evaluator.cpp6
-rw-r--r--src/lib/corelib/language/scriptengine.cpp63
-rw-r--r--src/lib/corelib/language/scriptengine.h15
-rw-r--r--src/lib/corelib/language/scriptimporter.cpp5
5 files changed, 61 insertions, 30 deletions
diff --git a/src/app/qbs-setup-toolchains/xcodeprobe.cpp b/src/app/qbs-setup-toolchains/xcodeprobe.cpp
index bb246742f..5fbfcc4e6 100644
--- a/src/app/qbs-setup-toolchains/xcodeprobe.cpp
+++ b/src/app/qbs-setup-toolchains/xcodeprobe.cpp
@@ -150,7 +150,7 @@ void XcodeProbe::detectDeveloperPaths()
if (!selectedXcode.waitForFinished(-1) || selectedXcode.exitCode()) {
qbsInfo() << Tr::tr("Could not detect selected Xcode with /usr/bin/xcode-select");
} else {
- QString path = QString::fromLocal8Bit(selectedXcode.readAllStandardOutput());
+ QString path = QString::fromLocal8Bit(selectedXcode.readAllStandardOutput().trimmed());
addDeveloperPath(path);
}
addDeveloperPath(defaultDeveloperPath);
diff --git a/src/lib/corelib/language/evaluator.cpp b/src/lib/corelib/language/evaluator.cpp
index 833ab96f2..4d85f5f8a 100644
--- a/src/lib/corelib/language/evaluator.cpp
+++ b/src/lib/corelib/language/evaluator.cpp
@@ -268,9 +268,9 @@ Evaluator::FileContextScopes Evaluator::fileContextScopes(const FileContextConst
}
if (!JS_IsObject(result.importScope)) {
try {
- result.importScope = m_scriptEngine->newObject();
- setupScriptEngineForFile(m_scriptEngine, file, result.importScope,
- ObserveMode::Enabled);
+ ScopedJsValue importScope(m_scriptEngine->context(), m_scriptEngine->newObject());
+ setupScriptEngineForFile(m_scriptEngine, file, importScope, ObserveMode::Enabled);
+ result.importScope = importScope.release();
} catch (const ErrorInfo &e) {
result.importScope = throwError(m_scriptEngine->context(), e.toString());
}
diff --git a/src/lib/corelib/language/scriptengine.cpp b/src/lib/corelib/language/scriptengine.cpp
index c5d4656cb..58c2817c6 100644
--- a/src/lib/corelib/language/scriptengine.cpp
+++ b/src/lib/corelib/language/scriptengine.cpp
@@ -226,22 +226,7 @@ void ScriptEngine::reset()
void ScriptEngine::import(const FileContextBaseConstPtr &fileCtx, JSValue &targetObject,
ObserveMode observeMode)
{
- installImportFunctions(targetObject);
- m_currentDirPathStack.push(FileInfo::path(fileCtx->filePath()));
- m_extensionSearchPathsStack.push(fileCtx->searchPaths());
- m_observeMode = observeMode;
-
- for (const JsImport &jsImport : fileCtx->jsImports())
- import(jsImport, targetObject);
- if (m_observeMode == ObserveMode::Enabled) {
- for (JSValue &sv : m_requireResults)
- observeImport(sv);
- m_requireResults.clear();
- }
-
- m_currentDirPathStack.pop();
- m_extensionSearchPathsStack.pop();
- uninstallImportFunctions();
+ Importer(*this, fileCtx, targetObject, observeMode).run();
}
void ScriptEngine::import(const JsImport &jsImport, JSValue &targetObject)
@@ -259,9 +244,10 @@ void ScriptEngine::import(const JsImport &jsImport, JSValue &targetObject)
if (debugJSImports)
qDebug() << "[ENGINE] " << jsImport.filePaths << " (cache miss)";
- jsImportValue = JS_NewObject(m_context);
+ ScopedJsValue scopedImportValue(m_context, JS_NewObject(m_context));
for (const QString &filePath : jsImport.filePaths)
- importFile(filePath, jsImportValue);
+ importFile(filePath, scopedImportValue);
+ jsImportValue = scopedImportValue.release();
m_jsImportCache.insert(jsImport, jsImportValue);
std::vector<QString> &filePathsForScriptValue
= m_filePathsPerImport[jsObjectId(jsImportValue)];
@@ -437,7 +423,7 @@ void ScriptEngine::setEnvironment(const QProcessEnvironment &env)
m_environment = env;
}
-void ScriptEngine::importFile(const QString &filePath, JSValue &targetObject)
+void ScriptEngine::importFile(const QString &filePath, JSValue targetObject)
{
AccumulatingTimer importTimer(m_elapsedTimeImporting != -1 ? &m_elapsedTimeImporting : nullptr);
JSValue &evaluationResult = m_jsFileCache[filePath];
@@ -591,9 +577,9 @@ JSValue ScriptEngine::js_require(JSContext *ctx, JSValueConst this_val,
engine->m_logger.qbsDebug()
<< "[require] importing file " << filePath;
}
- JSValue obj = engine->newObject();
+ ScopedJsValue obj(engine->context(), engine->newObject());
engine->importFile(filePath, obj);
- values << obj;
+ values << obj.release();
filePaths.push_back(filePath);
}
} catch (const ErrorInfo &e) {
@@ -624,8 +610,9 @@ JSValue ScriptEngine::js_require(JSContext *ctx, JSValueConst this_val,
result = getJsProperty(ctx, func_data[0], scopeName);
if (JS_IsObject(result))
return result; // Same JS file imported from same qbs file via different JS files (e.g. codesign.js from DarwinGCC.qbs via gcc.js and darwin.js).
- result = engine->newObject();
- engine->importFile(filePath, result);
+ ScopedJsValue scopedResult(engine->context(), engine->newObject());
+ engine->importFile(filePath, scopedResult);
+ result = scopedResult.release();
setJsProperty(ctx, result, StringConstants::importScopeNamePropertyInternal(), scopeName);
setJsProperty(ctx, func_data[0], scopeName, result);
engine->m_requireResults.push_back(result);
@@ -1020,5 +1007,35 @@ void ScriptEngine::takeOwnership(JSValue v)
++m_evalResults[v];
}
+ScriptEngine::Importer::Importer(
+ ScriptEngine &engine, const FileContextBaseConstPtr &fileCtx, JSValue &targetObject,
+ ObserveMode observeMode)
+ : m_engine(engine), m_fileCtx(fileCtx), m_targetObject(targetObject)
+{
+ m_engine.installImportFunctions(targetObject);
+ m_engine.m_currentDirPathStack.push(FileInfo::path(fileCtx->filePath()));
+ m_engine.m_extensionSearchPathsStack.push(fileCtx->searchPaths());
+ m_engine.m_observeMode = observeMode;
+}
+
+ScriptEngine::Importer::~Importer()
+{
+ if (m_engine.m_observeMode == ObserveMode::Enabled)
+ m_engine.m_requireResults.clear();
+ m_engine.m_currentDirPathStack.pop();
+ m_engine.m_extensionSearchPathsStack.pop();
+ m_engine.uninstallImportFunctions();
+}
+
+void ScriptEngine::Importer::run()
+{
+ for (const JsImport &jsImport : m_fileCtx->jsImports())
+ m_engine.import(jsImport, m_targetObject);
+ if (m_engine.m_observeMode == ObserveMode::Enabled) {
+ for (JSValue &sv : m_engine.m_requireResults)
+ m_engine.observeImport(sv);
+ }
+}
+
} // namespace Internal
} // namespace qbs
diff --git a/src/lib/corelib/language/scriptengine.h b/src/lib/corelib/language/scriptengine.h
index d7798decf..8c97e3079 100644
--- a/src/lib/corelib/language/scriptengine.h
+++ b/src/lib/corelib/language/scriptengine.h
@@ -292,6 +292,19 @@ public:
void setProperty(const char *k, const QVariant &v) { m_properties.insert(QLatin1String(k), v); }
private:
+ class Importer {
+ public:
+ Importer(ScriptEngine &engine, const FileContextBaseConstPtr &fileCtx,
+ JSValue &targetObject, ObserveMode observeMode);
+ ~Importer();
+ void run();
+
+ private:
+ ScriptEngine &m_engine;
+ const FileContextBaseConstPtr &m_fileCtx;
+ JSValue &m_targetObject;
+ };
+
static int interruptor(JSRuntime *rt, void *opaqueEngine);
bool gatherFileResults() const;
@@ -305,7 +318,7 @@ private:
void uninstallImportFunctions();
void import(const JsImport &jsImport, JSValue &targetObject);
void observeImport(JSValue &jsImport);
- void importFile(const QString &filePath, JSValue &targetObject);
+ void importFile(const QString &filePath, JSValue targetObject);
static JSValue js_require(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv, int magic, JSValue *func_data);
JSValue mergeExtensionObjects(const JSValueList &lst);
diff --git a/src/lib/corelib/language/scriptimporter.cpp b/src/lib/corelib/language/scriptimporter.cpp
index 1b012f3c3..fdb0689ad 100644
--- a/src/lib/corelib/language/scriptimporter.cpp
+++ b/src/lib/corelib/language/scriptimporter.cpp
@@ -142,10 +142,11 @@ JSValue ScriptImporter::importSourceCode(const QString &sourceCode, const QStrin
code = QLatin1String("(function(){\n") + sourceCode + extractor.suffix();
}
- JSValue result = m_engine->evaluate(JsValueOwner::Caller, code, filePath, 0);
+ ScopedJsValue result(m_engine->context(),
+ m_engine->evaluate(JsValueOwner::Caller, code, filePath, 0));
throwOnEvaluationError(m_engine, [&filePath] () { return CodeLocation(filePath, 0); });
copyProperties(m_engine->context(), result, targetObject);
- return result;
+ return result.release();
}
void ScriptImporter::copyProperties(JSContext *ctx, const JSValue &src, JSValue &dst)