-
Notifications
You must be signed in to change notification settings - Fork 263
Bug 743382 - Make loader independent of other modules. #401
Conversation
I still plan on writing more documentation for loader module. And will have another iteration to remove dependency on self module. With this patch all example add-on works and all tests pass except one: |
wantXrays: wantXrays, | ||
sandboxName: name, | ||
sameGroupAs: sandbox | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using something like this:
let sandboxOptions = {
sandboxPrototype: options.prototype || {},
wantXrays: options.wantXrays ||false,
sandboxName: options.name
}
if (options.sandbox)
sandboxOptions.sameGroupAs = sandbox;
Your current code is unecessary complex. The mapping between input options and the sandbox options, and what will be the default value is all but simple to catch. Using same variable name for both is a bad practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using something like this:
let sandboxOptions = {
sandboxPrototype: options.prototype || {},
wantXrays: options.wantXrays ||false,
sandboxName: options.name
}
if (options.sandbox)
sandboxOptions.sameGroupAs = sandbox;
I wish I could! you will get warnings if options don't have those properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that would help I could do following instead:
let defualts = {
principal: systemPrincipal,
prototype: {},
wantXrays: false,
}
options = override(defualts, options)
if (options.sandbox)
sandboxOptions.sameGroupAs = sandbox;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would.
Don't you think Otherwise, it looks good. There is some comments to be added, may be some stuff to make clearer. |
In that case firefox features implemented with sdk won't be able to use unload feature, also unit test will have hard time simulating unloads. So I thought it was better to do it via observer-service. Also I could be convinced otherwise. |
In any case, if they want to support unload feature, they will have to use unload module. Am I missing something? |
Well yes they could use unload module to handle unloads, but they also may choose not to use unload module. This way standard observer-service can be used to listen for unloads as it's used to listen for other similar events like application unload etc... Which is arguably is a better idea, since observer service keeps weak references so listeners won't be kept if they can be garbage collected. Also, this way loader does supports unload, everything else is just a sugar on top. All pieces become independent of each other:
I think it's best to reduce knowledge of independent components from each other, that way changes later will be easier. BTW: What do you have against, I mean what's your objections to a way it's now ? |
We are talking about simplifying loader and removing features/dependencies. |
In that case let's leave it for now, specially since we'll have another iteration to get rid of |
Ok so I believe I have addressed all the review comments. Also, I have trucked down a bug that was causing test failures, was a stupid one loader test were unloading an actual loader causing event listeners to be unregistered and there for causing timeouts. So I'll be waiting for a final review! @ochameau I think you may also want to try your html-l10n branch on top of this one to see if it works. |
…into "addon/runner" instead.
function iced(f, prototype) { | ||
f.prototype = prototype && freeze(prototype); | ||
return freeze(f); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to find any usage of second parameter prototype
without success.
And I don't think we can overload a function prototype.
function foo(){}
foo.prototype = {bar:true};
foo.prototype.bar is undefined.
Looks like we should just do:
function iced(f) {
Object.freeze(f.prototype);
return Object.freeze(f);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure you did some mistake you definitely can set function prototype (not redefine though) unless it's frozen. This works
function foo() {}
foo.prototype = undefined
typeof foo.prototype // undefined
As of prototype
argument it's undefined doing exactly what I want ;) But yeah I can remove it, it's just at first I thought I'd non undefined
prototype somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.S.: Also your example there returns true
.
I think there is something wrong with lambda/iced and I still hope Sandbox can be easier to read. |
Bug 743382 - Make loader independent of other modules. r=@ochameau
This patch decouples loader from all the dependencies (except from
self
which I'll cover in next iteration). In more details it:uriPrefix
was renamed toprefixURI
to be more consistent with other options.Object.freeze
of the parent compartment to workaround Bug 674195. This required switches from incompatible__defineGetter__
Object.defineProperty
.bootstrap.js
was moved to helperaddon/runner
module thatbootstrap.js
uses to prepare SDK environment for add-on startup.unload
module. Now message using observer-service is send to propagate unload.observer-service
andunload
modules, lower leverobserver-service
APIs have being extracted tosystem/events
module implementing familiar event emitter APIs, which is usedby
unload
module to track loader unloads & byobserver-service
under the hood.console
are added later in the process viaaddon/runner
. All modules that need to useconsole
and such earlier will have to require explicitly.require.main
as specified by CommonJS. It'srequire.main === module
for the main moudlenow.
addon/runner
. Also API exposed by loader now is a super-set ofapi-utils/sandbox
which we will be able to remove in a future (let's do it in next iteration).