Closed Bug 2079881 Opened 1 month ago Closed 4 days ago

Change NAMESPACE representation in ResolvedBinding Record

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: dminor, Assigned: allstars.chh)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 6 external files)

Attached file poc-namespace.tgz —

We currently use star_namespace_star to represent ~NAMESPACE~ in the ResolvedBinding record. This works fine for JavaScript, but any utf-8 string can be used for wasm exports, meaning that *namespace* is a valid wasm export name. If someone attempted to use this name, it would be shadowed by our existing use.

I've attached some claude generated test files illustrating the problem.

Severity: -- → S3
Priority: -- → P3

Yoshi, could you take a look when you get a minute?

Flags: needinfo?(allstars.chh)

ResolvedBindingObject::bindingName() still uses atom,

For WebAssembly module, the [[BindingName]] is the exportName,
https://webassembly.github.io/esm-integration/js-api/index.html#resolve-export

whereas in ECMAScript, the [[BindingName]] is the ExportEntry.[[LocalName]]
https://tc39.es/ecma262/#sec-resolveexport

// module.mjs
var x = 1;
export { x as "*namespace*" }; 

In ECMAScript, the ResolvedBinding record's [[BindingName]] is "x"

In the ns.wat example from comment 0,

(export "*namespace*" (func $f))

The ResolvedBinding record's [[BindingName]] is "namespace"

I'll fix the [[BindingName]], maybe along with others.

Assignee: nobody → allstars.chh
Flags: needinfo?(allstars.chh)

ResolveExport can return String, NAMESPACE or DEFERRED-NAMESPACE in
[[BindingName]], this patch adds a BindingNameType in ResolvedBindingObject to
indicate the type of the [[BindingName]].

Add a resolveExport function to ShellModuleObjectWrapper, the function returns
a ResolvedBindingObject, which can be used to verify the type and the value of
[[BindingName]] of Resolved Binding Record returned from ResolveExport.

Synthetic Module Records can have arbitrary [[ExportNames]].
See https://tc39.es/ecma262/#table-synthetic-module-record-fields

Add a createSyntheticModule test function in the JS shell to simulate export
arbitrary names from a synthetic module or a wasm modules.

An export named namespace or deferred-namespace shadowed the
internal slots. Name them with a lone surrogate, which no export name
can contain.

Attachment #9671548 - Attachment description: Bug 2079881 - Part 4: Use collision-free names for the internal namespace slots. r?jonco! → Bug 2079881 - Part 4: Store the namespace objects in ModuleEnvironmentObject. r?jonco!

The namespace objects of a module are now stored in reserved slots of its
environment, so the namespace and deferred-namespace bindings that the
parser declared in every module scope are no longer used.

The spec doesn't handle the case when the [[BindingName]] is namespace,
See https://github.com/WebAssembly/esm-integration/issues/127.

Throws an exception first to prvent hitting assertion.

Duplicate of this bug: 2091340
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: