Skip to content

Commit b9cf47d

Browse files
feat(realms): Add support for modules in realms. (#41)
This commit adds rudimentary support for ES module in realms.
1 parent 048cb84 commit b9cf47d

File tree

6 files changed

+596
-680
lines changed

6 files changed

+596
-680
lines changed

core/modules/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::modules::NoopModuleLoader;
2020
use crate::modules::PrepareLoadFuture;
2121
use crate::modules::RecursiveModuleLoad;
2222
use crate::modules::ResolutionKind;
23+
use crate::runtime::JsRealm;
2324
use crate::runtime::SnapshottedData;
24-
use crate::JsRealm;
2525
use anyhow::Error;
2626
use futures::future::FutureExt;
2727
use futures::stream::FuturesUnordered;

core/runtime/bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
466466
};
467467

468468
if has_unhandled_rejection_handler {
469-
let state_rc = JsRuntime::state_from(tc_scope);
469+
let state_rc = JsRealm::state_from_scope(tc_scope);
470470
let mut state = state_rc.borrow_mut();
471471
if let Some(pending_mod_evaluate) = state.pending_mod_evaluate.as_mut() {
472472
if !pending_mod_evaluate.has_evaluated {

core/runtime/jsrealm.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ impl Hasher for IdentityHasher {
5050
}
5151
}
5252

53-
pub(crate) struct DynImportModEvaluate {
54-
pub(crate) load_id: ModuleLoadId,
55-
pub(crate) module_id: ModuleId,
56-
pub(crate) promise: v8::Global<v8::Promise>,
57-
pub(crate) module: v8::Global<v8::Module>,
53+
struct DynImportModEvaluate {
54+
load_id: ModuleLoadId,
55+
module_id: ModuleId,
56+
promise: v8::Global<v8::Promise>,
57+
module: v8::Global<v8::Module>,
5858
}
5959

6060
pub(crate) struct ModEvaluate {
61-
pub(crate) promise: Option<v8::Global<v8::Promise>>,
61+
promise: Option<v8::Global<v8::Promise>>,
6262
pub(crate) has_evaluated: bool,
6363
pub(crate) handled_promise_rejections: Vec<v8::Global<v8::Promise>>,
64-
pub(crate) sender: oneshot::Sender<Result<(), Error>>,
64+
sender: oneshot::Sender<Result<(), Error>>,
6565
}
6666

6767
#[derive(Default)]
@@ -73,9 +73,7 @@ pub(crate) struct ContextState {
7373
pub(crate) js_wasm_streaming_cb: Option<Rc<v8::Global<v8::Function>>>,
7474
pub(crate) pending_promise_rejections:
7575
VecDeque<(v8::Global<v8::Promise>, v8::Global<v8::Value>)>,
76-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
77-
#[allow(unused)]
78-
pub(crate) pending_dyn_mod_evaluate: Vec<DynImportModEvaluate>,
76+
pending_dyn_mod_evaluate: Vec<DynImportModEvaluate>,
7977
pub(crate) pending_mod_evaluate: Option<ModEvaluate>,
8078
pub(crate) unrefed_ops: HashSet<i32, BuildHasherDefault<IdentityHasher>>,
8179
pub(crate) pending_ops: JoinSet<(PromiseId, OpId, OpResult)>,
@@ -168,14 +166,10 @@ impl JsRealmInner {
168166
self.context_state.borrow().unrefed_ops.len()
169167
}
170168

171-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
172-
#[allow(unused)]
173169
pub fn has_pending_dyn_imports(&self) -> bool {
174170
self.module_map.borrow().has_pending_dynamic_imports()
175171
}
176172

177-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
178-
#[allow(unused)]
179173
pub fn has_pending_dyn_module_evaluation(&self) -> bool {
180174
!self
181175
.context_state
@@ -184,8 +178,6 @@ impl JsRealmInner {
184178
.is_empty()
185179
}
186180

187-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
188-
#[allow(unused)]
189181
pub fn has_pending_module_evaluation(&self) -> bool {
190182
self.context_state.borrow().pending_mod_evaluate.is_some()
191183
}
@@ -439,8 +431,6 @@ impl JsRealm {
439431
.instantiate_module(&mut self.handle_scope(isolate), id)
440432
}
441433

442-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
443-
#[allow(unused)]
444434
fn dynamic_import_module_evaluate(
445435
&self,
446436
isolate: &mut v8::Isolate,
@@ -663,8 +653,6 @@ impl JsRealm {
663653
receiver
664654
}
665655

666-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
667-
#[allow(unused)]
668656
fn dynamic_import_reject(
669657
&self,
670658
isolate: &mut v8::Isolate,
@@ -690,8 +678,6 @@ impl JsRealm {
690678
scope.perform_microtask_checkpoint();
691679
}
692680

693-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
694-
#[allow(unused)]
695681
fn dynamic_import_resolve(
696682
&self,
697683
isolate: &mut v8::Isolate,
@@ -729,8 +715,6 @@ impl JsRealm {
729715
scope.perform_microtask_checkpoint();
730716
}
731717

732-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
733-
#[allow(unused)]
734718
pub(in crate::runtime) fn prepare_dyn_imports(
735719
&self,
736720
isolate: &mut v8::Isolate,
@@ -782,8 +766,6 @@ impl JsRealm {
782766
}
783767
}
784768

785-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
786-
#[allow(unused)]
787769
pub(in crate::runtime) fn poll_dyn_imports(
788770
&self,
789771
isolate: &mut v8::Isolate,
@@ -892,8 +874,6 @@ impl JsRealm {
892874
/// Thus during turn of event loop we need to check if V8 has
893875
/// resolved or rejected the promise. If the promise is still pending
894876
/// then another turn of event loop must be performed.
895-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
896-
#[allow(unused)]
897877
pub(in crate::runtime) fn evaluate_pending_module(
898878
&self,
899879
isolate: &mut v8::Isolate,
@@ -950,8 +930,6 @@ impl JsRealm {
950930
}
951931

952932
// Returns true if some dynamic import was resolved.
953-
// TODO(bartlomieju): remove, once migration to realm module handling is complete
954-
#[allow(unused)]
955933
pub(in crate::runtime) fn evaluate_dyn_imports(
956934
&self,
957935
isolate: &mut v8::Isolate,

0 commit comments

Comments
 (0)