Skip to content

JSModuleNamespaceObject: expose __esModule marker as own property - #361

Closed
terry90918 wants to merge 1 commit into
oven-sh:mainfrom
terry90918:codex/fix-esmodule-own-property
Closed

JSModuleNamespaceObject: expose __esModule marker as own property#361
terry90918 wants to merge 1 commit into
oven-sh:mainfrom
terry90918:codex/fix-esmodule-own-property

Conversation

@terry90918

Copy link
Copy Markdown

Summary

This replays the single-file fix from #279 onto the current oven-sh/WebKit:main so Bun can obtain a fresh, compatible preview build.

The original #279 preview (autobuild-preview-pr-279-10b2c963) no longer compiles with current Bun main because the surrounding WebKit API has moved. The patch itself is unchanged: its stable patch ID matches #279 exactly.

This pull request is only intended to refresh the preview artifact on top of current main. It carries forward the original author’s implementation and intent; it is not claiming replacement credit for #279.

Change

When Bun sets m_hasESModuleMarker, JSModuleNamespaceObject exposes __esModule as its own enumerable, non-configurable property and includes it in sorted own-property enumeration. This lets the companion Bun change remove the custom namespace prototype and preserve correct ESM namespace re-exports through CommonJS interop helpers.

Validation

  • Replayed commit has the same stable patch ID as JSModuleNamespaceObject: expose the __esModule marker as an own property #279.
  • git diff --check upstream/main...HEAD
  • Diff is limited to Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp (28 additions, 4 deletions).
  • Full compilation will be exercised by this PR’s Preview Build and by building current Bun main against the resulting preview tag.

Original implementation: #279
Companion Bun work: supersedes oven-sh/bun#33894

When Bun's require(esm) sets m_hasESModuleMarker on a module namespace
object, the marker was previously surfaced through a custom accessor on
a bespoke prototype. That made ns.__esModule read as true but kept it
invisible to own-property operations (Object.keys, Object.hasOwn,
spread, Object.assign, JSON.stringify), which is what transpiler interop
helpers rely on after cloning the namespace.

Node's require(esm) returns a namespace where __esModule is an own,
enumerable, non-configurable data property, interleaved with the other
exports in code-point order.

This change makes m_hasESModuleMarker == True behave as an own property:

  getOwnPropertySlotCommon  reports { value: true, writable, enumerable,
                             configurable: false } directly on this
  getOwnPropertyNames       inserts __esModule at its sorted position
  deleteProperty            treats it as non-configurable
  put / defineOwnProperty   write the TriState directly instead of
                             routing through Base:: (which previously
                             relied on a prototype accessor)

With this in place Bun can drop its custom moduleNamespaceObjectStructure
prototype and return to the spec's null prototype.
@terry90918

terry90918 commented Jul 27, 2026

Copy link
Copy Markdown
Author

@robobun The automatic Preview Build stopped at the fork-permission gate (action_required). Could you or another maintainer please dispatch .github/workflows/build-preview.yml for pr_number=361?

This PR is a patch-identical replay of #279 on current main, intended only to refresh the preview artifact for the companion Bun fix. Thank you.

@terry90918 terry90918 closed this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants