diff --git a/examples/example/tests/test-includes/a.js b/examples/example/tests/test-includes/a.js new file mode 100644 index 0000000000..1d99a08525 --- /dev/null +++ b/examples/example/tests/test-includes/a.js @@ -0,0 +1,7 @@ +// a.js: +Script.include('b.js'); +if (a === undefined) { +a = 0; +} +a++; +print('script a:' + a); diff --git a/examples/example/tests/test-includes/b.js b/examples/example/tests/test-includes/b.js new file mode 100644 index 0000000000..ea3f9664ba --- /dev/null +++ b/examples/example/tests/test-includes/b.js @@ -0,0 +1,6 @@ +// b.js: +if (b === undefined) { +b = 0; +} +b++; +print('script b: ' + b); \ No newline at end of file diff --git a/examples/example/tests/test-includes/start.js b/examples/example/tests/test-includes/start.js new file mode 100644 index 0000000000..8060ffcf71 --- /dev/null +++ b/examples/example/tests/test-includes/start.js @@ -0,0 +1,5 @@ +// start.js: +var a, b; +print('initially: a:' + a + ' b:' + b); +Script.include(['a.js', '../test-includes/a.js', 'b.js', 'a.js']); +print('finally a:' + a + ' b:' + b); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index a460a1189d..83a87b718f 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -863,7 +863,9 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac QUrl thisURL { resolvePath(file) }; if (!_includedURLs.contains(thisURL)) { urls.append(thisURL); - } else { + _includedURLs << thisURL; + } + else { qCDebug(scriptengine) << "Script.include() ignoring previously included url:" << thisURL; } } @@ -876,7 +878,6 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac if (contents.isNull()) { qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__; } else { - _includedURLs << url; QScriptValue result = evaluate(contents, url.toString()); } }