0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-09 21:47:00 -04:00
rusty-v8/src/unbound_module_script.rs

29 lines
884 B
Rust
Raw Normal View History

2021-03-05 18:26:37 +08:00
use crate::CachedData;
use crate::UnboundModuleScript;
use crate::UniqueRef;
extern "C" {
fn v8__UnboundModuleScript__CreateCodeCache(
script: *const UnboundModuleScript,
) -> *mut CachedData<'static>;
}
impl UnboundModuleScript {
/// Creates and returns code cache for the specified unbound_module_script.
/// This will return nullptr if the script cannot be serialized. The
/// CachedData returned by this function should be owned by the caller.
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
let code_cache = unsafe {
2021-03-05 18:26:37 +08:00
UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))
};
#[cfg(debug_assertions)]
if let Some(code_cache) = &code_cache {
debug_assert_eq!(
code_cache.buffer_policy(),
crate::script_compiler::BufferPolicy::BufferOwned
);
2021-03-05 18:26:37 +08:00
}
code_cache
2021-03-05 18:26:37 +08:00
}
}