Browse files

Add basic instrumentation signalling new and existing globals through…

… the observer service.
  • Loading branch information...
1 parent 5339863 commit 6ed73f9e810dea2ee40c23410db9230d5994a8b3 @Mossop committed Sep 12, 2012
Showing with 46 additions and 1 deletion.
  1. +22 −0 packages/api-utils/lib/addon/runner.js
  2. +24 −1 packages/api-utils/lib/loader.js
View
22 packages/api-utils/lib/addon/runner.js
@@ -16,6 +16,7 @@ const { when: unload } = require('../unload');
const { loadReason } = require('self');
const { rootURI } = require("@loader/options");
const globals = require('../globals');
+const obs = require("../observer-service");
const NAME2TOPIC = {
'Firefox': 'sessionstore-windows-restored',
@@ -76,6 +77,27 @@ function startup(reason, options) {
// Inject globals ASAP in order to have console API working ASAP
Object.defineProperties(options.loader.globals, descriptor(globals));
+ obs.add("sdk-ping-loaders", function observer() {
+ let id = options.loader.id;
+ if (!id)
+ return;
+
+ let data = {
+ id: id,
+ name: require("self").name,
+ globals: []
+ }
+
+ for (let uri in options.loader.sandboxes) {
+ data.globals.push({
+ uri: uri,
+ global: options.loader.sandboxes[uri]
+ });
+ }
+
+ obs.notify("sdk-pong-globals", { wrappedJSObject: data }, id);
+ });
+
// Load localization manifest and .properties files.
// Run the addon even in case of error (best effort approach)
require('api-utils/l10n/loader').
View
25 packages/api-utils/lib/loader.js
@@ -194,6 +194,16 @@ const load = iced(function load(loader, module) {
wantXrays: false
});
+ if (loader.id) {
+ dump("Created global for " + loader.id + " from " + module.uri + "\n");
+ notifyObservers({
+ wrappedJSObject: {
+ uri: module.uri,
+ global: sandbox
+ }
+ }, "sdk-global-created", loader.id);
+ }
+
evaluate(sandbox, module.uri);
if (module.exports && typeof(module.exports) === 'object')
@@ -326,13 +336,25 @@ exports.unload = unload;
// If `resolve` does not returns `uri` string exception will be thrown by
// an associated `require` call.
const Loader = iced(function Loader(options) {
- let { modules, globals, resolve, paths } = override({
+ let { id, modules, globals, resolve, paths } = override({
+ id: undefined,
paths: {},
modules: {},
globals: {},
resolve: exports.resolve
}, options);
+ if (id) {
+ dump("Creating new loader " + id + " " + options.name + "\n");
+ notifyObservers({
+ wrappedJSObject: {
+ id: id,
+ name: options.name,
+ globals: []
+ }
+ }, "sdk-loader-created", id);
+ }
+
// We create an identity object that will be dispatched on an unload
// event as subject. This way unload listeners will be able to assert
// which loader is unloaded. Please note that we intentionally don't
@@ -371,6 +393,7 @@ const Loader = iced(function Loader(options) {
// state. We freeze it and mark make it's properties non-enumerable
// as they are pure implementation detail that no one should rely upon.
return freeze(create(null, {
+ id: { enumerable: false, value: id },
destructor: { enumerable: false, value: destructor },
globals: { enumerable: false, value: globals },
mapping: { enumerable: false, value: mapping },

0 comments on commit 6ed73f9

Please sign in to comment.