-
Notifications
You must be signed in to change notification settings - Fork 328
/
Copy pathunbound_module_script.rs
61 lines (55 loc) · 1.58 KB
/
unbound_module_script.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::CachedData;
use crate::HandleScope;
use crate::Local;
use crate::UnboundModuleScript;
use crate::UniqueRef;
use crate::Value;
unsafe extern "C" {
fn v8__UnboundModuleScript__CreateCodeCache(
script: *const UnboundModuleScript,
) -> *mut CachedData<'static>;
fn v8__UnboundModuleScript__GetSourceMappingURL(
script: *const UnboundModuleScript,
) -> *const Value;
fn v8__UnboundModuleScript__GetSourceURL(
script: *const UnboundModuleScript,
) -> *const Value;
}
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.
#[inline(always)]
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
let code_cache = unsafe {
UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))
};
if let Some(code_cache) = &code_cache {
debug_assert_eq!(
code_cache.buffer_policy(),
crate::script_compiler::BufferPolicy::BufferOwned
);
}
code_cache
}
pub fn get_source_mapping_url<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe {
scope
.cast_local(|_| v8__UnboundModuleScript__GetSourceMappingURL(self))
.unwrap()
}
}
pub fn get_source_url<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe {
scope
.cast_local(|_| v8__UnboundModuleScript__GetSourceURL(self))
.unwrap()
}
}
}