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)

x86
macOS
defect
Not set
normal

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!
Summary: Allow 'es5' to module to work as an injected script → Allow 'es5' module to work as an injected script
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.
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.
(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.
Yeah, I think either of those solutions would be rad.
Attachment #496682 - Flags: review?(adw)
Attachment #496682 - Flags: feedback?(rFobic)
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.
Assignee: nobody → avarma
Blocks: 618080
Status: NEW → ASSIGNED
Blocks: 618481
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
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.

Attachment

General

Created:
Updated:
Size: