Chromium Code Reviews| Index: Source/devtools/front_end/Runtime.js |
| diff --git a/Source/devtools/front_end/Runtime.js b/Source/devtools/front_end/Runtime.js |
| index b9e6fc01bd5fa8a256863952e47576ef939ea6c1..953017fe43e113c4fb808b41f7c1b2a5ab24c8c4 100644 |
| --- a/Source/devtools/front_end/Runtime.js |
| +++ b/Source/devtools/front_end/Runtime.js |
| @@ -28,6 +28,7 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| +var allDescriptors = []; |
| var _importedScripts = {}; |
|
eustas
2014/08/15 13:22:26
Is it still "imported" scripts?
apavlov
2014/08/15 13:31:44
Can be renamed _loadedScripts
|
| /** |
| @@ -81,18 +82,9 @@ function normalizePath(path) |
| } |
| /** |
| - * This function behavior depends on the "debug_devtools" flag value. |
| - * - In debug mode it loads scripts synchronously via xhr request. |
| - * - In release mode every occurrence of "importScript" in the js files |
| - * that have been whitelisted in the build system gets replaced with |
| - * the script source code on the compilation phase. |
| - * The build system will throw an exception if it finds an importScript() call |
| - * in other files. |
| - * |
| - * To load scripts lazily in release mode call "loadScript" function. |
| * @param {string} scriptName |
| */ |
| -function importScript(scriptName) |
| +function loadScript(scriptName) |
| { |
| var sourceURL = self._importScriptPathPrefix + scriptName; |
| var schemaIndex = sourceURL.indexOf("://") + 3; |
| @@ -117,13 +109,10 @@ function importScript(scriptName) |
| self._importScriptPathPrefix = baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1); |
| })(); |
| -var loadScript = importScript; |
| - |
| /** |
| * @constructor |
| - * @param {!Array.<!Runtime.ModuleDescriptor>} descriptors |
| */ |
| -var Runtime = function(descriptors) |
| +var Runtime = function() |
| { |
| /** |
| * @type {!Array.<!Runtime.Module>} |
| @@ -147,8 +136,8 @@ var Runtime = function(descriptors) |
| * @type {!Object.<string, !Runtime.ModuleDescriptor>} |
| */ |
| this._descriptorsMap = {}; |
| - for (var i = 0; i < descriptors.length; ++i) |
| - this._descriptorsMap[descriptors[i]["name"]] = descriptors[i]; |
| + for (var i = 0; i < allDescriptors.length; ++i) |
| + this._descriptorsMap[allDescriptors[i]["name"]] = allDescriptors[i]; |
| } |
| /** |
| @@ -157,7 +146,41 @@ var Runtime = function(descriptors) |
| */ |
| Runtime.startWorker = function(moduleName) |
| { |
| - return new Worker(moduleName + "/_module.js"); |
| + if (allDescriptors.length) |
| + return new Worker(moduleName + ".js"); |
| + |
| + /** |
| + * @suppress {checkTypes} |
| + */ |
| + var loader = function() { |
| + self.onmessage = function(event) { |
| + self.onmessage = null; |
| + var scripts = event.data; |
| + for (var i = 0; i < scripts.length; ++i) { |
| + var source = scripts[i]["source"]; |
| + self.eval(source + "\n//# sourceURL=" + scripts[i]["url"]); |
| + } |
| + }; |
| + }; |
| + |
| + var content = loadResource(moduleName + "/module.json"); |
| + if (!content) |
| + throw new Error("Worker is not defined: " + moduleName + " " + new Error().stack); |
| + var workerJSON = JSON.parse(content); |
| + var message = []; |
| + var scripts = workerJSON["scripts"]; |
| + for (var i = 0; i < scripts.length; ++i) { |
| + message.push({ |
| + source: loadResource(moduleName + "/" + scripts[i]), |
| + url: self._importScriptPathPrefix + moduleName + "/" + scripts[i] |
| + }); |
| + } |
| + var blob = new Blob(["(" + loader.toString() + ")()\n//# sourceURL=" + moduleName], { type: "text/javascript" }); |
| + var workerURL = window.URL.createObjectURL(blob); |
| + var worker = new Worker(workerURL); |
| + worker.postMessage(message); |
| + window.URL.revokeObjectURL(workerURL); |
| + return worker; |
| } |
| Runtime.prototype = { |
| @@ -478,8 +501,15 @@ Runtime.Module.prototype = { |
| var dependencies = this._descriptor.dependencies; |
| for (var i = 0; dependencies && i < dependencies.length; ++i) |
| this._manager.loadModule(dependencies[i]); |
| - if (this._descriptor.scripts) |
| - loadScript(this._name + "/_module.js"); |
| + if (this._descriptor.scripts) { |
| + if (allDescriptors.length) { |
| + loadScript(this._name + ".js"); |
| + } else { |
| + var scripts = this._descriptor.scripts; |
| + for (var i = 0; i < scripts.length; ++i) |
| + loadScript(this._name + "/" + scripts[i]); |
| + } |
| + } |
| this._isLoading = false; |
| this._loaded = true; |
| } |