"use strict";
const EXPORTED_SYMBOLS = ["require", "startup", "shutdown", "onShutdown"];
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
var shutdownHandlers = [];
var onShutdown = {
done: false,
add: function onShutdown_add(handler) {
if (shutdownHandlers.indexOf(handler) < 0)
shutdownHandlers.push(handler);
}
,
remove: function onShutdown_remove(handler) {
var index = shutdownHandlers.indexOf(handler);
if (index !== - 1)
shutdownHandlers.splice(index,1);
}
};
const MODULES_BASE_URI = (function () {
var uri = Services.io.newURI(__URI__,null,null);
uri = Services.io.newURI(uri.resolve("../modules/"),null,null);
return uri;
}
)();
function require(path) {
var baseURI = /^\.\.?\//.test(path) && (this && "requireBaseURL" in this) ? Services.io.newURI(this.requireBaseURL,null,null) : MODULES_BASE_URI;
var url = Services.io.newURI(path,null,baseURI).spec + ".js";
var scopes = require.scopes;
if (! (url in scopes))
{
scopes[url] = {
Cc: Cc,
Ci: Ci,
Cr: Cr,
Cu: Cu,
XPCOMUtils: XPCOMUtils,
Services: Services,
require: require,
NativeAPI: require.NativeAPI,
onShutdown: onShutdown,
exports: Object.create(null),
requireBaseURL: url};
Services.scriptloader.loadSubScript(url,scopes[url]);
(scopes[url].EXPORTED_SYMBOLS || []).forEach(function (name) {
if (! (name in this.exports))
this.exports[name] = this[name];
}
,scopes[url]);
}

return scopes[url].exports;
}

require.scopes = Object.create(null);
require.NativeAPI = null;
function startup() {
onShutdown.done = false;
}

function shutdown() {
onShutdown.done = true;
shutdownHandlers.forEach(function (handler) {
try {
handler();
}
catch (e) {
Cu.reportError(e);
}

}
);
shutdownHandlers = [];
for each(let scope in require.scopes) {
Object.keys(scope).forEach(function (key) {
if (scope.__lookupGetter__(key) || scope.__lookupSetter__(key))
delete scope[key];
scope[key] = null;
}
);
}

require.scopes = Object.create(null);
require.NativeAPI = null;
}

