Closed Bug 1768060 Opened 3 years ago Closed 2 years ago

Add a wrapper to Cu.import return value that supports lexical variables

Categories

(Core :: XPConnect, task)

task

Tracking

()

RESOLVED FIXED
102 Branch
Tracking Status
firefox102 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

During ESM-ification, existing functions needs to keep working, to avoid breaking not-in-tree code.
This includes the return value of Cu.import, that's the per-JSM global.

This can break for 2 reasons:

  • if any global binding inside JSM is converted from var/function to lexical (let, const, class), it disappears from per-JSM global property (bug 1610653)
  • once ESM-ified there's no global object that has global bindings as properties

Possible options:

  • (a) Return exports object instead
  • (b) Return a proxy for both exports object and per-JSM global

(a) is simpler, but if there's not-in-tree code that retrieves not-exported symbols from the Cu.import return value, it breaks.
Bug 1609271 has context what kind of breakage happens and what change was needed.

(b) is more backward-compatible, but it's not guaranteed to work once ESM-ified.

Investigated the proxy way.
The global variables, especially var, can be optimized away (to LOCAL slot) and in that case it's not accessible from ModuleEnvironmentObject.
Possible workaround is to force de-optimize the top-level variables during compiling the ESM.

Checked Privileged Firefox extensions, and also Thunderbird/SeaMonkey extensions that's compatible with recent versions, and I don't see any case that not-exported symbols are extracted from the Cu.import return value.
So this isn't a problem for extensions.
Remaining case is AutoConfig.

for ESM-ified case, the patch in bug 1766761 solves (including the LOCAL slot issue above).

for not-ESM-ified case, we might need yet another proxy.

Summary: Figure out the non-breaking alternative for Cu.import return value → Add a wrapper to Cu.import return value that supports lexical variables

Mildly depends on bug 1766761, to share the test code.
the implementation itself doesn't have dependency.

Depends on: 1766761
Assignee: nobody → arai.unmht
Attachment #9275804 - Attachment description: WIP: Bug 1768060 - Add a wrapper for Cu.import return value that supports lexical variable. → Bug 1768060 - Add a wrapper for Cu.import return value that supports lexical variable. r?jonco!,Standard8!
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/dd28b0eb27ef Add a wrapper for Cu.import return value that supports lexical variable. r=jonco,Standard8

Backed out for causing spidermonkey failures on Modules.cpp

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: /builds/worker/checkouts/gecko/js/src/vm/Modules.cpp:237:10: error: cannot initialize return object of type 'JSObject *' with an rvalue of type 'js::ModuleEnvironmentObject *'
Flags: needinfo?(arai.unmht)
Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/18553f994228 Add a wrapper for Cu.import return value that supports lexical variable. r=jonco,Standard8
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
Blocks: 1610653
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: