Closed
Bug 614957
Opened 15 years ago
Closed 15 years ago
Allow 'es5' module to work as an injected script
Categories
(Add-on SDK Graveyard :: General, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: avarma, Assigned: avarma)
References
Details
Attachments
(1 file)
Currently the 'es5' module is used at such an early place in the startup of Jetpack that we are doing some gymnastics to allow it to be require'd without causing strange effects.
For instance, jrburke's patch for bug 596932 contains a specific check within the require() implementation to see if the module being requested is es5 or not.
In other places, while we don't explicity have workarounds for es5, we take a lot of implicit assumptions into account in order to allow it to be imported at an early stage. For instance, when implementing bug 567703, warner and I had to think pretty hard to allow es5 to be imported without any fuss in e10s.
These kinds of changes make me feel that the require() implementation is more complex than it needs to be for others to understand. It also makes it very brittle, since seemingly innocuous changes to the implementation of require() may cause the importing of es5 to break at an early stage in the loading of Jetpack.
Aside from that, the es5 module is structured to make really invasive changes to another global scope's foundational structure, which confuses the behavior of compartments, and is likely to continue to break our compatibility with SpiderMonkey/XPConnect as future enhancements to compartments are made.
Yet another problem with the current approach is that it significantly complicates warner's object-capability security plan for isolation at the module level, since it means that every single newly-minted global scope contains pointers to the es5 module for fundamental functionality.
For these reasons, I think it may be a good idea to allow for the following use case of es5.js: if it is *injected* into a pristine global scope rather than loaded as a CommonJS module--which can be detected via the presence of exports/require/etc--it should simply call init(Object, Array, Function) on the current global scope and do nothing more.
This means that we can simply inject the script into every new sandbox we create for CommonJS modules without having to deal with the chicken-and-egg problem of having to be able to require('es5') within our implementation of require(). Aside from making the implementation of require() simpler, it will also mean that every newly-minted global scope doesn't contain pointers to other global scopes at the level of JS built-ins, which should lessen the chance of future breakage with compartments and make module-level isolation easier to enforce.
All that said, since Gecko 2 either already has all the features of ES5 implemented or will very soon, we may be able to simplify this situation even further by just removing es5.js altogether!
| Assignee | ||
Updated•15 years ago
|
Summary: Allow 'es5' to module to work as an injected script → Allow 'es5' module to work as an injected script
Comment 1•15 years ago
|
||
Atul there is one thing to keep in mind though, sandbox natives are only mutated by es5 if there are no native analogs, so no cross-module pointers should be created in Gecko 2. Also cross-module pointers are required to implement following behavior:
var obj = {}
Object.freeze(obj)
Object.isFrozen(obj)
Proposed change will break example above if obj is from different scope.
Also please note that compartments changes are inrelevant since they are introduced in Gecko 2 where es5 module does nothing.
| Assignee | ||
Comment 2•15 years ago
|
||
Thanks, Irakli. Can we just remove the es5 module from the SDK then, since the SDK only supports Gecko 2 now? From what I mentioned, I think it could greatly improve the readibility, maintainability, and robustness of the SDK code.
Comment 3•15 years ago
|
||
(In reply to comment #2)
> Thanks, Irakli. Can we just remove the es5 module from the SDK then, since the
> SDK only supports Gecko 2 now? From what I mentioned, I think it could greatly
> improve the readibility, maintainability, and robustness of the SDK code.
Removing ES5 will break most|all of the API's on FF3.*, which work just fine now. Not sure it's worth the change, also I don't think I'm in title to decide that.
As an alternative we can simplify ES5 module (disable custom enumeration, freeze etc) and make it script inject-able, in that case we won't break APIs.
| Assignee | ||
Comment 4•15 years ago
|
||
Yeah, I think either of those solutions would be rad.
| Assignee | ||
Comment 5•15 years ago
|
||
| Assignee | ||
Updated•15 years ago
|
Attachment #496682 -
Flags: review?(adw)
Attachment #496682 -
Flags: feedback?(rFobic)
| Assignee | ||
Comment 6•15 years ago
|
||
The pull request I just pointed to makes es5 work as an injected script, and modifies current code to use it as such. It can still be used via require() but I don't think anything actually does that. It doesn't remove any features from es5 either, though it does move the custom Iterator function into es5.js (some justification for it is in the commit log).
Among other things, this significantly simplifies terrible logic in bootstrap-remote-process.js to make way for bug 618080.
Comment 7•15 years ago
|
||
Commented in pull request https://github.com/mozilla/addon-sdk/pull/83#issuecomment-603201
Comment 8•15 years ago
|
||
Comment on attachment 496682 [details]
Pointer to pull request
https://github.com/toolness/jetpack-sdk/commit/de656283f9977438770166c3d96ac489227f51ce#commitcomment-215270
Attachment #496682 -
Flags: review?(adw) → review+
| Assignee | ||
Comment 9•15 years ago
|
||
Pushed: https://github.com/mozilla/addon-sdk/commit/f66645a2d714184a4d462dbb0859b85dea450a0c
Filed bug 618481 as a follow-up to address Irakli's concerns in comment 7.
Updated•15 years ago
|
Attachment #496682 -
Flags: feedback+
Updated•15 years ago
|
Attachment #496682 -
Flags: feedback?(rFobic)
Attachment #496682 -
Flags: feedback+
You need to log in
before you can comment on or make changes to this bug.
Description
•