Skip to content

Draft: Initial implementation of ShadowRealm built-in with realm isolation#5077

Draft
ParthMozarkar wants to merge 20 commits intoboa-dev:mainfrom
ParthMozarkar:feat/shadowrealm
Draft

Draft: Initial implementation of ShadowRealm built-in with realm isolation#5077
ParthMozarkar wants to merge 20 commits intoboa-dev:mainfrom
ParthMozarkar:feat/shadowrealm

Conversation

@ParthMozarkar
Copy link

Draft PR: Initial Implementation of ShadowRealm Built-in

This PR introduces an initial implementation of the ShadowRealm built-in object based on the TC39 ShadowRealm proposal.

The purpose of this draft PR is to establish the core realm isolation mechanism and provide a foundation for the remaining features of ShadowRealm.


Implemented Features

ShadowRealm Constructor

  • Added the ShadowRealm built-in constructor.
  • Verified that new ShadowRealm() correctly creates a ShadowRealm instance.

Realm Isolation

  • Implemented basic support for ShadowRealm.prototype.evaluate.
  • Code executed through evaluate runs in a separate and fully isolated realm.
  • The global state between the host realm and the ShadowRealm remains isolated.

Example behavior:

const realm = new ShadowRealm();

realm.evaluate(`
  globalThis.testValue = 42;
`);

console.log(globalThis.testValue); // undefined

This confirms that state changes inside the ShadowRealm do not affect the host realm.


Tests

Unit tests were added to verify:

  • Constructor behavior
  • Realm isolation through evaluate

All added tests are currently passing.

Test file:

core/engine/src/builtins/shadow_realm/tests.rs

Code Changes

New files:

core/engine/src/builtins/shadow_realm/mod.rs
core/engine/src/builtins/shadow_realm/tests.rs

Updated files:

core/engine/src/builtins/mod.rs
core/engine/src/context/intrinsics.rs
core/string/src/common.rs

These updates register the ShadowRealm built-in and integrate it into the engine intrinsics and static strings.


Remaining Work

This PR is opened as a Draft because some parts of the ShadowRealm specification are not yet implemented.

Callable Masking

Functions returned across realms are not yet supported. Proper wrapped callable objects still need to be implemented.

importValue

Support for dynamic module imports inside the ShadowRealm (ShadowRealm.prototype.importValue) has not yet been implemented.


Next Steps

Planned follow-up work includes:

  • Implement callable masking for cross-realm functions
  • Add support for ShadowRealm.prototype.importValue
  • Expand test coverage
  • Ensure closer alignment with the TC39 proposal

Request for Feedback

Opening this as a Draft PR to get early feedback on the approach and integration before continuing with the remaining parts of the implementation.

ParthMozarkar and others added 19 commits February 26, 2026 15:02
The test test_complex_tuple_decode_out_of_bounds provided an array of size 3 for a type that requires 3 bytes ((u8, i8) where the first is the format u8). Modifying the test array to [0, 1] reduces length to 2, correctly testing the bounds error.

Also explicitly used the unified read::<u8> to bounds check reading the format byte across decode implementations.
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 14, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 14, 2026
@github-actions github-actions bot added C-Dependencies Pull requests that update a dependency file C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics C-Actions Pull requests that update Github Actions code C-Runtime Issues and PRs related to Boa's runtime features labels Mar 14, 2026
@github-actions
Copy link

github-actions bot commented Mar 14, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,070 49,932 -138
Ignored 2,072 2,210 +138
Failed 821 821 0
Panics 0 0 0
Conformance 94.54% 94.28% -0.26%

Tested main commit: 3016f492d02a06033e11269fdcef603d293222c4
Tested PR commit: b929c1828a59744835761154287f8ce6ef1274aa
Compare commits: 3016f49...b929c18

@jedel1043 jedel1043 added Waiting On Author Waiting on PR changes from the author and removed Waiting On Review Waiting on reviews from the maintainers labels Mar 15, 2026
@jedel1043
Copy link
Member

Don't forget to gate everything behind the experimental feature

@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 15, 2026
@ParthMozarkar
Copy link
Author

Don't forget to gate everything behind the experimental feature

yaa sure you could check my next commit and review once if anything is else needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Actions Pull requests that update Github Actions code C-Builtins PRs and Issues related to builtins/intrinsics C-Dependencies Pull requests that update a dependency file C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Author Waiting on PR changes from the author Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants