Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realms should be constructable from a v8::HandleScope #101

Open
andreubotella opened this issue Jul 28, 2023 · 0 comments
Open

Realms should be constructable from a v8::HandleScope #101

andreubotella opened this issue Jul 28, 2023 · 0 comments

Comments

@andreubotella
Copy link
Contributor

In order to make the ShadowRealm constructor work, it must be possible to create a new realm in the same way as JsRuntime::create_realm, but with a &mut v8::HandleScope rather than a &mut JsRuntime. This implies:

  • Making JsRuntime::create_realm and the methods it depends on static methods taking a scope or an isolate reference. In the case of create_realm, since it's public, it can stay with the current API, but the implementation would move to JsRuntime::create_realm_from_scope.
  • The extensions, global_template_middlewares, global_object_middlewares, preserve_snapshotted_modules and init_mode fields of JsRuntime must be available from the JsRuntimeState. @mmastrac suggested making a RuntimeExtensionInfo struct with those fields, which would also make things easier for Create an ExtensionSet to handle logic around multiple extensions #52.
  • Don't run the entire isolate event loop in JsRuntime::init_extension_js. fix(realms): Make realm creation not hang with async ops running #99 takes care of this.
  • Currently JsRealm::execute_script and module loading and evaluation use the scope returned by JsRealm::handle_scope. However, rusty_v8 needs each scope to take in a reference to the previous scope in order to keep track of the lifetimes, and JsRealm::handle_scope creates a new root scope. If this scope is created when the stack is not empty, as would happen when constructing a new realm from inside a JS execution context, handle_scope will panic. We would need to somehow make these JsRealm methods accept a parent scope, and use v8::ContextScope to switch into the realm.
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

No branches or pull requests

1 participant