v8/
unbound_module_script.rs1use crate::CachedData;
2use crate::Local;
3use crate::PinScope;
4use crate::UnboundModuleScript;
5use crate::UniqueRef;
6use crate::Value;
7
8unsafe extern "C" {
9 fn v8__UnboundModuleScript__CreateCodeCache(
10 script: *const UnboundModuleScript,
11 ) -> *mut CachedData<'static>;
12
13 fn v8__UnboundModuleScript__GetSourceMappingURL(
14 script: *const UnboundModuleScript,
15 ) -> *const Value;
16
17 fn v8__UnboundModuleScript__GetSourceURL(
18 script: *const UnboundModuleScript,
19 ) -> *const Value;
20}
21
22impl UnboundModuleScript {
23 #[inline(always)]
27 pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
28 let code_cache = unsafe {
29 UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))
30 };
31 if let Some(code_cache) = &code_cache {
32 debug_assert_eq!(
33 code_cache.buffer_policy(),
34 crate::script_compiler::BufferPolicy::BufferOwned
35 );
36 }
37 code_cache
38 }
39
40 pub fn get_source_mapping_url<'s>(
41 &self,
42 scope: &PinScope<'s, '_>,
43 ) -> Local<'s, Value> {
44 unsafe {
45 scope
46 .cast_local(|_| v8__UnboundModuleScript__GetSourceMappingURL(self))
47 .unwrap()
48 }
49 }
50
51 pub fn get_source_url<'s>(
52 &self,
53 scope: &PinScope<'s, '_>,
54 ) -> Local<'s, Value> {
55 unsafe {
56 scope
57 .cast_local(|_| v8__UnboundModuleScript__GetSourceURL(self))
58 .unwrap()
59 }
60 }
61}