Bug 1462223: Remove unnecessary/unused bootstrap scope setup code. r=aswan

This also removes the workerbootstrap test extension, which is no longer used,
and contains the last references to the Worker and ChromeWorker bootstrap
globals.

MozReview-Commit-ID: 8YWReXMqX5W

--HG--
extra : rebase_source : b0aa59b2b5e6a08f4be803e828bd507f894e4a19
This commit is contained in:
Kris Maglione 2018-05-19 14:03:50 -07:00
parent b060e51d52
commit f8aeb3dbfc
12 changed files with 2 additions and 226 deletions

View File

@ -1,138 +0,0 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
function testForExpectedSymbols(stage, data) {
const expectedSymbols = [ "Worker", "ChromeWorker" ];
for (var symbol of expectedSymbols) {
Services.prefs.setBoolPref("workertest.bootstrap." + stage + "." + symbol,
symbol in this);
}
}
var gWorkerAndCallback = {
_ensureStarted: function() {
if (!this._worker) {
throw new Error("Not yet started!");
}
},
start: function(data) {
if (!this._worker) {
this._worker = new Worker("chrome://workerbootstrap/content/worker.js");
this._worker.onerror = function(event) {
Cu.reportError(event.message);
event.preventDefault();
};
}
},
stop: function() {
if (this._worker) {
this._worker.terminate();
delete this._worker;
}
},
set callback(val) {
this._ensureStarted();
var callback = val.QueryInterface(Ci.nsIObserver);
if (this._callback != callback) {
if (callback) {
this._worker.onmessage = function(event) {
callback.observe(this, event.type, event.data);
};
this._worker.onerror = function(event) {
callback.observe(this, event.type, event.message);
event.preventDefault();
};
}
else {
this._worker.onmessage = null;
this._worker.onerror = null;
}
this._callback = callback;
}
},
get callback() {
return this._callback;
},
postMessage: function(data) {
this._ensureStarted();
this._worker.postMessage(data);
},
terminate: function() {
this._ensureStarted();
this._worker.terminate();
delete this._callback;
}
};
function WorkerTestBootstrap() {
}
WorkerTestBootstrap.prototype = {
observe: function(subject, topic, data) {
gWorkerAndCallback.callback = subject;
switch (topic) {
case "postMessage":
gWorkerAndCallback.postMessage(data);
break;
case "terminate":
gWorkerAndCallback.terminate();
break;
default:
throw new Error("Unknown worker command");
}
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver])
};
var gFactory = {
register: function() {
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
var classID = Components.ID("{36b5df0b-8dcf-4aa2-9c45-c51d871295f9}");
var description = "WorkerTestBootstrap";
var contractID = "@mozilla.org/test/workertestbootstrap;1";
var factory = XPCOMUtils._getFactory(WorkerTestBootstrap);
registrar.registerFactory(classID, description, contractID, factory);
this.unregister = function() {
registrar.unregisterFactory(classID, factory);
delete this.unregister;
};
}
};
function install(data, reason) {
testForExpectedSymbols("install");
}
function startup(data, reason) {
testForExpectedSymbols("startup");
gFactory.register();
gWorkerAndCallback.start(data);
}
function shutdown(data, reason) {
testForExpectedSymbols("shutdown");
gWorkerAndCallback.stop();
gFactory.unregister();
}
function uninstall(data, reason) {
testForExpectedSymbols("uninstall");
}

View File

@ -1,31 +0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:name>WorkerTestBootstrap</em:name>
<em:description>Worker functions for use in testing.</em:description>
<em:creator>Mozilla</em:creator>
<em:version>2016.03.09</em:version>
<em:id>workerbootstrap-test@mozilla.org</em:id>
<em:type>2</em:type>
<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<!-- Firefox -->
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>45.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
<em:targetApplication>
<Description>
<!-- Fennec -->
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
<em:minVersion>45.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

View File

@ -1,3 +0,0 @@
workerbootstrap.jar:
% content workerbootstrap %content/
content/worker.js (worker.js)

View File

@ -4,17 +4,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
XPI_NAME = 'workerbootstrap'
JAR_MANIFESTS += ['jar.mn']
USE_EXTENSION_MANIFEST = True
NO_JS_MANIFEST = True
FINAL_TARGET_FILES += [
'bootstrap.js',
'install.rdf',
]
TEST_HARNESS_FILES.testing.mochitest.extensions += [
'workerbootstrap-test@mozilla.org.xpi',
]

View File

@ -1,7 +0,0 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
onmessage = function(event) {
postMessage(event.data);
}

View File

@ -1,7 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DIRS += ['bootstrap']

View File

@ -576,7 +576,6 @@ class UrlFinder(object):
dir_parts = parts[0].rsplit(app_name + '/', 1)
url = mozpath.normpath(mozpath.join(self.topobjdir, 'dist', 'bin', dir_parts[1].lstrip('/'), parts[1].lstrip('/')))
elif '.xpi!' in url:
# e.g. file:///tmp/tmpMdo5gV.mozrunner/extensions/workerbootstrap-test@mozilla.org.xpi!/bootstrap.js
# This matching mechanism is quite brittle and based on examples seen in the wild.
# There's no rule to match the XPI name to the path in dist/xpi-stage.
parts = url_obj.path.split('.xpi!', 1)

View File

@ -297,10 +297,6 @@ class TestUrlFinder(unittest.TestCase):
'path4',
None
],
'dist/xpi-stage/workerbootstrap/bootstrap.js': [
'path5',
None
],
'dist/bin/modules/osfile/osfile_async_worker.js': [
'toolkit/components/osfile/modules/osfile_async_worker.js',
None
@ -340,7 +336,6 @@ class TestUrlFinder(unittest.TestCase):
('jar:file:///home/worker/workspace/build/application/' + app_name + '/' + omnijar_name + '!/components/MainProcessSingleton.js', 'path1'),
('jar:file:///home/worker/workspace/build/application/' + app_name + '/browser/' + omnijar_name + '!/components/nsSessionStartup.js', 'path2'),
('jar:file:///home/worker/workspace/build/application/' + app_name + '/browser/features/firefox@getpocket.com.xpi!/bootstrap.js', 'path4'),
('jar:file:///tmp/tmpMdo5gV.mozrunner/extensions/workerbootstrap-test@mozilla.org.xpi!/bootstrap.js', 'path5'),
]
url_finder = lcov_rewriter.UrlFinder(self._chrome_map_file, '', '', [])

View File

@ -239,7 +239,6 @@ class RobocopTestRunner(MochitestDesktop):
self.options.extensionsToExclude.extend([
'mochikit@mozilla.org',
'workerbootstrap-test@mozilla.org.xpi',
'indexedDB-test@mozilla.org.xpi',
])

View File

@ -1897,18 +1897,6 @@ class BootstrapScope {
logger.debug(`Loading bootstrap scope from ${this.file.path}`);
let principal = Services.scriptSecurityManager.getSystemPrincipal();
if (!this.file.exists()) {
this.scope =
new Cu.Sandbox(principal, { sandboxName: this.file.path,
addonId: this.addon.id,
wantGlobalProperties: ["ChromeUtils"],
metadata: { addonID: this.addon.id } });
logger.error(`Attempted to load bootstrap scope from missing directory ${this.file.path}`);
return;
}
if (isWebExtension(this.addon.type)) {
this.scope = Extension.getBootstrapScope(this.addon.id, this.file);
} else if (this.addon.type === "webextension-langpack") {
@ -1918,6 +1906,7 @@ class BootstrapScope {
} else {
let uri = getURIForResourceInFile(this.file, "bootstrap.js").spec;
let principal = Services.scriptSecurityManager.getSystemPrincipal();
this.scope =
new Cu.Sandbox(principal, { sandboxName: uri,
addonId: this.addon.id,
@ -1925,19 +1914,12 @@ class BootstrapScope {
metadata: { addonID: this.addon.id, URI: uri } });
try {
// Copy the reason values from the global object into the bootstrap scope.
for (let name in BOOTSTRAP_REASONS)
this.scope[name] = BOOTSTRAP_REASONS[name];
Object.assign(this.scope, BOOTSTRAP_REASONS);
// Add other stuff that extensions want.
Object.assign(this.scope, {Worker, ChromeWorker});
// Define a console for the add-on
XPCOMUtils.defineLazyGetter(
this.scope, "console",
() => new ConsoleAPI({ consoleID: `addon/${this.addon.id}` }));
this.scope.__SCRIPT_URI_SPEC__ = uri;
Services.scriptloader.loadSubScript(uri, this.scope);
} catch (e) {
logger.warn(`Error loading bootstrap.js for ${this.addon.id}`, e);

View File

@ -8,8 +8,6 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
const EXPECTED_GLOBALS = [
["Worker", "function"],
["ChromeWorker", "function"],
["console", "object"]
];