Skip to content

Commit

Permalink
feat: add Module::is_graph_async (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Sep 5, 2024
1 parent 9f37bb8 commit a97d896
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,10 @@ const v8::Value* v8__Module__Evaluate(const v8::Module& self,
ptr_to_local(&self)->Evaluate(ptr_to_local(&context)));
}

bool v8__Module__IsGraphAsync(const v8::Module& self) {
return ptr_to_local(&self)->IsGraphAsync();
}

bool v8__Module__IsSourceTextModule(const v8::Module& self) {
return ptr_to_local(&self)->IsSourceTextModule();
}
Expand Down
10 changes: 10 additions & 0 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extern "C" {
this: *const Module,
context: *const Context,
) -> *const Value;
fn v8__Module__IsGraphAsync(this: *const Module) -> bool;
fn v8__Module__IsSourceTextModule(this: *const Module) -> bool;
fn v8__Module__IsSyntheticModule(this: *const Module) -> bool;
fn v8__Module__CreateSyntheticModule(
Expand Down Expand Up @@ -349,6 +350,15 @@ impl Module {
}
}

/// Returns whether this module or any of its requested modules is async,
/// i.e. contains top-level await.
///
/// The module's status must be at least kInstantiated.
#[inline(always)]
pub fn is_graph_async(&self) -> bool {
unsafe { v8__Module__IsGraphAsync(self) }
}

/// Returns whether the module is a SourceTextModule.
#[inline(always)]
pub fn is_source_text_module(&self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4989,6 +4989,7 @@ fn module_stalled_top_level_await() {
.instantiate_module(scope, compile_specifier_as_module_resolve_callback);
assert!(result.unwrap());
assert_eq!(v8::ModuleStatus::Instantiated, module.get_status());
assert!(module.is_graph_async());

let result = module.evaluate(scope);
assert!(result.is_some());
Expand Down Expand Up @@ -7756,6 +7757,7 @@ fn synthetic_module() {
.instantiate_module(scope, unexpected_module_resolve_callback)
.unwrap();
assert_eq!(module.get_status(), v8::ModuleStatus::Instantiated);
assert!(!module.is_graph_async());

module.evaluate(scope).unwrap();
assert_eq!(module.get_status(), v8::ModuleStatus::Evaluated);
Expand Down

0 comments on commit a97d896

Please sign in to comment.