0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-26 09:13:46 -05:00

feat: add Module::is_graph_async (#1607)

This commit is contained in:
snek 2024-09-04 18:00:29 -07:00 committed by GitHub
parent 9f37bb80df
commit a97d89614e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View file

@ -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();
}

View file

@ -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(
@ -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 {

View file

@ -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());
@ -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);