deno_core
deno_core copied to clipboard
Realms should be constructable from a `v8::HandleScope`
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 ofcreate_realm
, since it's public, it can stay with the current API, but the implementation would move toJsRuntime::create_realm_from_scope
. - The
extensions
,global_template_middlewares
,global_object_middlewares
,preserve_snapshotted_modules
andinit_mode
fields ofJsRuntime
must be available from theJsRuntimeState
. @mmastrac suggested making aRuntimeExtensionInfo
struct with those fields, which would also make things easier for #52. - Don't run the entire isolate event loop in
JsRuntime::init_extension_js
. #99 takes care of this. - Currently
JsRealm::execute_script
and module loading and evaluation use the scope returned byJsRealm::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, andJsRealm::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 theseJsRealm
methods accept a parent scope, and usev8::ContextScope
to switch into the realm.