0
0
Fork 0
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:
Romain Marcadier 2022-02-01 01:15:49 +01:00 committed by GitHub
parent e791bf1ef0
commit a09d392711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

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

View file

@ -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,