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..9f6230e88d7d6d72c41c0ed5f5d245447bb82cb5 100644 |
| --- a/Source/devtools/front_end/Runtime.js |
| +++ b/Source/devtools/front_end/Runtime.js |
| @@ -28,7 +28,8 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -var _importedScripts = {}; |
| +var allDescriptors = []; |
|
lushnikov
2014/08/15 14:23:13
let's clarify how/when it gets some values
apavlov
2014/08/15 14:54:45
Done.
|
| +var _loadedScripts = {}; |
| /** |
| * @param {string} url |
| @@ -81,25 +82,16 @@ 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; |
| sourceURL = sourceURL.substring(0, schemaIndex) + normalizePath(sourceURL.substring(schemaIndex)); |
| - if (_importedScripts[sourceURL]) |
| + if (_loadedScripts[sourceURL]) |
| return; |
| - _importedScripts[sourceURL] = true; |
| + _loadedScripts[sourceURL] = true; |
| var scriptSource = loadResource(sourceURL); |
| if (!scriptSource) |
| throw "empty response arrived for script '" + sourceURL + "'"; |
| @@ -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); |
|
lushnikov
2014/08/15 14:23:13
lets inline
apavlov
2014/08/15 14:54:45
Done.
|
| + 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] |
|
lushnikov
2014/08/15 14:23:13
lets normalize path here
apavlov
2014/08/15 14:54:45
Done.
|
| + }); |
| + } |
| + 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); |
|
lushnikov
2014/08/15 14:23:13
lets do this in finally to not leak memory
apavlov
2014/08/15 14:54:45
Done.
|
| + 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) { |
|
lushnikov
2014/08/15 14:23:13
lets introduce isRelease() on Runtime
apavlov
2014/08/15 14:54:46
Done.
|
| + 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; |
| } |