mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 11:41:17 +02:00
Add forceRedownload parameter to Script.require
This commit is contained in:
parent
3d8128cc08
commit
2645547f48
2 changed files with 6 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 12/14/13.
|
// Created by Brad Hefta-Gaub on 12/14/13.
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
// Copyright 2020 Vircadia contributors.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommonJS/Node.js like require/module support
|
// CommonJS/Node.js like require/module support
|
||||||
QScriptValue ScriptEngine::require(const QString& moduleId) {
|
QScriptValue ScriptEngine::require(const QString& moduleId, bool forceRedownload) {
|
||||||
qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_DEBUG_VALUE_LENGTH) << ")";
|
qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_DEBUG_VALUE_LENGTH) << ")";
|
||||||
if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
|
if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
|
||||||
return unboundNullValue();
|
return unboundNullValue();
|
||||||
|
@ -1875,7 +1876,7 @@ QScriptValue ScriptEngine::require(const QString& moduleId) {
|
||||||
// `delete Script.require.cache[Script.require.resolve(moduleId)];`
|
// `delete Script.require.cache[Script.require.resolve(moduleId)];`
|
||||||
|
|
||||||
// cacheMeta is just used right now to tell deleted keys apart from undefined ones
|
// cacheMeta is just used right now to tell deleted keys apart from undefined ones
|
||||||
bool invalidateCache = module.isUndefined() && cacheMeta.property(moduleId).isValid();
|
bool invalidateCache = (module.isUndefined() && cacheMeta.property(moduleId).isValid()) || forceRedownload;
|
||||||
|
|
||||||
// reset the cacheMeta record so invalidation won't apply next time, even if the module fails to load
|
// reset the cacheMeta record so invalidation won't apply next time, even if the module fails to load
|
||||||
cacheMeta.setProperty(modulePath, QScriptValue());
|
cacheMeta.setProperty(modulePath, QScriptValue());
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 12/14/13.
|
// Created by Brad Hefta-Gaub on 12/14/13.
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
// Copyright 2020 Vircadia contributors.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
@ -421,10 +422,11 @@ public:
|
||||||
* @function Script.require
|
* @function Script.require
|
||||||
* @param {string} module - The module to use. May be a JavaScript file, a JSON file, or the name of a system module such
|
* @param {string} module - The module to use. May be a JavaScript file, a JSON file, or the name of a system module such
|
||||||
* as <code>"appUi"</code> (i.e., the "appUi.js" system module JavaScript file).
|
* as <code>"appUi"</code> (i.e., the "appUi.js" system module JavaScript file).
|
||||||
|
* @param {bool} [forceRedownload=false] - Invalidate the cache for this module and redownload it if necessary.
|
||||||
* @returns {object|array} The value assigned to <code>module.exports</code> in the JavaScript file, or the value defined
|
* @returns {object|array} The value assigned to <code>module.exports</code> in the JavaScript file, or the value defined
|
||||||
* in the JSON file.
|
* in the JSON file.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE QScriptValue require(const QString& moduleId);
|
Q_INVOKABLE QScriptValue require(const QString& moduleId, bool forceRedownload = false);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function Script.resetModuleCache
|
* @function Script.resetModuleCache
|
||||||
|
|
Loading…
Reference in a new issue