2

ESMification: In-tree Migration Phase 1 [PUBLIC]

 2 years ago
source link: https://docs.google.com/document/d/1cpzIK-BdP7u6RJSar-Z955GV--2Rj8V4x2vl34m36Go/edit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ESMification: In-tree Migration Phase 1 [PUBLIC]

ESMification: In-tree Migration Phase 1 [PUBLIC]
Request edit access
 Share
Tools
To enable screen reader support, press Ctrl+Alt+Z To learn about keyboard shortcuts, press Ctrl+slash
Outline
ESMification: In-tree Migration Phase 1
Index
What are JSMs and ESMs?
What’s new in system ESM?
Static import
Always strict mode
No per-JSM global `this` object
Defining global variables
Exporting lexical variable to `Cu.import` for compatibility
Defining lazy getters
Re-exporting a lazy getter (no longer possible)
What doesn’t change with system ESM?
Per-process singleton
JSM and ESM files can be mixed
Interface to the consumer
Lazy getters
URI except for the filename extension
Definition in `moz.build` file
Definition in `jar.mn` file
New APIs
ChromeUtils.importESModule
ChromeUtils.defineESModuleGetters
Cu.isESModuleLoaded
Cu.loadedESModules
“esModuleURI” key for ChromeUtils.registerWindowActor
“esModuleURI” key for ChromeUtils.registerProcessActor
“esModule” key for components.conf
Restrictions in system ESM
Compatibility Layer
Redirect ChromeUtils.import(“foo.jsm”) to ESM
Cu.isJSModuleLoaded and Cu.loadedJSModules
If the redirect doesn’t work
JSM-to-ESM conversion Walkthrough for Phase 1
Step 1. Convert JSM to ESM (`./mach esmify --convert …`)
Step 1-a. Automatically renames JSM with `*.jsm` or `*.js` or `*.jsm.js` to `*.sys.mjs`
Step 1-b. Automatically replaces references to `*.jsm` in build file, .e.g. `moz.build`
Step 1-c. Automatically replaces `EXPORTED_SYMBOLS` with `export` declaration
Step 1-d. Automatically rewrites ChromeUtils.importESModule with static import
Step 2. Automatically rewrites consumers to use new APIs (`./mach esmify --imports …`)
Step 2-a. Automatically replaces `ChromeUtils.import` with `ChromeUtils.importESModule`
Step 2-b. Automatically replaces `ChromeUtils.import` with static import declaration
Step 2-c. Automatically rewrites lazy getter for the module
Step 2-d. Automatically rewrites `components.conf` for the module
Step 2-e. Automatically rewrites `ChromeUtils.registerWindowActor` for the module
Step 2-f. Automatically rewrites `ChromeUtils.registerProcessActor` for the module
Step 2-g. (not automated) Rewrite `Cu.isModuleLoaded` for the module
Step 2-h. (not automated) Rewrite `Cu.loadedModules` for the module
Edge cases that need manual migration or extra steps
Empty lines are added or removed
JSM is loaded also as CommonJS
JSM is loaded from CommonJS in DevTools
JSM is loaded also as worker script
Filename collision
Code not compatible with strict mode
JSM was not covered by preparation
JSM file is auto-generated
JSM file is referred from unsupported build files
The load for the JSM file is monitored by performance-related test cases
The file is loaded with older binary
New JSM files
Timeline
Terminology

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK