mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
Make v8::script_compiler::Source.get_cached_data return Option (#885)
The `cached_data` property of `Source` is optional, so reading the value should return `Option<&CachedData>`.
This commit is contained in:
parent
e791bf1ef0
commit
a09d392711
2 changed files with 13 additions and 2 deletions
|
@ -143,8 +143,15 @@ impl Source {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_cached_data(&self) -> &CachedData {
|
||||
unsafe { &*v8__ScriptCompiler__Source__GetCachedData(self) }
|
||||
pub fn get_cached_data(&self) -> Option<&CachedData> {
|
||||
unsafe {
|
||||
let cached_data = v8__ScriptCompiler__Source__GetCachedData(self);
|
||||
if cached_data.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(&*cached_data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2348,6 +2348,8 @@ fn script_compiler_source() {
|
|||
Some(&script_origin),
|
||||
);
|
||||
|
||||
assert!(source.get_cached_data().is_none());
|
||||
|
||||
let result = v8::script_compiler::compile_module(scope, source);
|
||||
assert!(result.is_some());
|
||||
}
|
||||
|
@ -5320,6 +5322,7 @@ fn create_module<'s>(
|
|||
false,
|
||||
true,
|
||||
);
|
||||
let has_cache = code_cache.is_some();
|
||||
let source = match code_cache {
|
||||
Some(x) => v8::script_compiler::Source::new_with_cached_data(
|
||||
source,
|
||||
|
@ -5328,6 +5331,7 @@ fn create_module<'s>(
|
|||
),
|
||||
None => v8::script_compiler::Source::new(source, Some(&script_origin)),
|
||||
};
|
||||
assert_eq!(source.get_cached_data().is_some(), has_cache);
|
||||
let module = v8::script_compiler::compile_module2(
|
||||
scope,
|
||||
source,
|
||||
|
|
Loading…
Reference in a new issue