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

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: Rebase, add script which was left behind 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 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;
}
« 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