History

Add forceRedownload parameter to Script.require

Kalila L committed 6 years ago

Commit 26455471 parent 3d8128c2 files · +6 −3Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+3−2
@@ -4,6 +4,7 @@ · 3 unmodified lines
4//4//
5// Created by Brad Hefta-Gaub on 12/14/13.5// Created by Brad Hefta-Gaub on 12/14/13.
6// Copyright 2013 High Fidelity, Inc.6// Copyright 2013 High Fidelity, Inc.
7// Copyright 2020 Vircadia contributors.
7//8//
8// Distributed under the Apache License, Version 2.0.9// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html10// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@@ -1836,7 +1837,7 @@ QScriptValue ScriptEngine::instantiateModule(const QScriptValue& module, const Q · 1826 unmodified lines
1836}1837}
1837 1838
1838// CommonJS/Node.js like require/module support1839// CommonJS/Node.js like require/module support
1839QScriptValue ScriptEngine::require(const QString& moduleId) {1840QScriptValue ScriptEngine::require(const QString& moduleId, bool forceRedownload) {
1840 qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_DEBUG_VALUE_LENGTH) << ")";1841 qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_DEBUG_VALUE_LENGTH) << ")";
1841 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {1842 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
1842 return unboundNullValue();1843 return unboundNullValue();
@@ -1875,7 +1876,7 @@ QScriptValue ScriptEngine::require(const QString& moduleId) { · 32 unmodified lines
1875 // `delete Script.require.cache[Script.require.resolve(moduleId)];`1876 // `delete Script.require.cache[Script.require.resolve(moduleId)];`
1876 1877
1877 // cacheMeta is just used right now to tell deleted keys apart from undefined ones1878 // cacheMeta is just used right now to tell deleted keys apart from undefined ones
1878 bool invalidateCache = module.isUndefined() && cacheMeta.property(moduleId).isValid();1879 bool invalidateCache = (module.isUndefined() && cacheMeta.property(moduleId).isValid()) || forceRedownload;
1879 1880
1880 // reset the cacheMeta record so invalidation won't apply next time, even if the module fails to load1881 // reset the cacheMeta record so invalidation won't apply next time, even if the module fails to load
1881 cacheMeta.setProperty(modulePath, QScriptValue());1882 cacheMeta.setProperty(modulePath, QScriptValue());