Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2056)

Unified Diff: Source/devtools/front_end/Runtime.js

Issue 472903003: DevTools: Get rid of module initializers in the source tree (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove more dead code and fix GN build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/audits/_module.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/Runtime.js
diff --git a/Source/devtools/front_end/Runtime.js b/Source/devtools/front_end/Runtime.js
index 532aa3600f66eb1a57600f7f98c70e696b5a5d53..137096e7fcc76781f27d4f783efa0cff69884457 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 = {};
/**
@@ -48,18 +49,9 @@ function loadResource(url)
}
/**
- * 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;
if (_importedScripts[sourceURL])
@@ -82,13 +74,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>}
@@ -112,8 +101,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];
}
/**
@@ -122,7 +111,21 @@ var Runtime = function(descriptors)
*/
Runtime.startWorker = function(moduleName)
{
- return new Worker(moduleName + "/_module.js");
+ if (allDescriptors.length)
+ return new Worker(moduleName + ".js");
+ 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 workerString = "";
+ var scripts = workerJSON["scripts"];
+ for (var i = 0; i < scripts.length; ++i)
+ workerString += loadResource(moduleName + "/" + scripts[i]) + ";";
+ var blob = new Blob([workerString], { type: "text/javascript" });
vsevik 2014/08/14 16:43:47 This will make debugging workers harder since all
+ var workerURL = window.URL.createObjectURL(blob);
+ var worker = new Worker(workerURL);
+ window.URL.revokeObjectURL(workerURL);
+ return worker;
}
Runtime.prototype = {
@@ -444,7 +447,7 @@ Runtime.Module.prototype = {
for (var i = 0; dependencies && i < dependencies.length; ++i)
this._manager.loadModule(dependencies[i]);
if (this._descriptor.scripts)
- loadScript(this._name + "/_module.js");
+ loadScript(this._name + ".js");
this._isLoading = false;
this._loaded = true;
}
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/audits/_module.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698