Incoming JS module (JSM) / component loader changes

Kris Maglione kmaglione at mozilla.com
Thu Aug 31 18:33:45 UTC 2017


To clarify, this is about XPConnect JS modules (loaded by Cu.import[1]) and
components, not ES6 modules[2], which already work this way.

[1]: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using
[2]: https://hacks.mozilla.org/2015/08/es6-in-depth-modules/

On Thu, Aug 31, 2017 at 11:14:34AM -0700, Kris Maglione wrote:
>A quick heads-up on some incoming changes to the JS component loader 
>that may affect some existing JSM or JS component code:
>
>1) As of bug 1394556[1], all JS module and component scripts are 
>automatically compiled in strict mode[2]. While I fixed all of the 
>resulting issues that showed up in automated tests, new issues may 
>turn up in code with incomplete test coverage. Please be on the 
>lookout for errors like "TypeError: this is null", "TypeError: setting 
>a property that has only a getter", and "ReferenceError: assignment to 
>undeclared variable", and if you see any, file bugs blocking bug 
>1394556.
>
>2) Andrew McCreight has been working on changing the component loader 
>to load most modules and components into a single global[3], with each 
>module still getting its own top-level variable scope (similar to a 
>with() block). Most of the blockers for this have been resolved, and 
>it should hopefully be ready to land within the next week.
>
>This change will significantly reduce the memory overhead of JS 
>modules, along with the performance overhead of creating dozens module 
>globals at startup, and of creating thousands of cross-compartment 
>object wrappers at runtime.
>
>But it does so at the cost of decreased isolation among module 
>scripts. All (non-add-on) modules will now share prototypes for 
>built-in objects. It will be possible to define objects on the shared 
>global that affect all modules. getGlobalForObject will no longer 
>return the root scope for a module. In short, it's possible we will 
>see subtle issues as a result of this change (as we often saw on b2g, 
>which its module loader differed from the desktop module loader), so 
>please be on the look-out over the next few weeks.
>
>Thanks.
>
>-Kris
>
>[1]: https://bugzil.la/1394556
>[2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
>[3]: https://bugzil.la/1186409

-- 
Kris Maglione
Senior Firefox Add-ons Engineer
Mozilla Corporation

For every prohibition you create you also create an underground.
	--Jello Biafra



More information about the firefox-dev mailing list