0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-02-01 12:15:46 -05:00

feat: expose CachedData::rejected (#1413)

This commit is contained in:
Igor Zinkovsky 2024-03-07 09:36:06 -08:00 committed by GitHub
parent 9dd629e1c3
commit 083f43346c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -118,6 +118,11 @@ impl<'a> CachedData<'a> {
pub(crate) fn buffer_policy(&self) -> BufferPolicy { pub(crate) fn buffer_policy(&self) -> BufferPolicy {
self.buffer_policy self.buffer_policy
} }
#[inline(always)]
pub fn rejected(&self) -> bool {
self.rejected
}
} }
impl<'a> std::ops::Deref for CachedData<'a> { impl<'a> std::ops::Deref for CachedData<'a> {
@ -227,11 +232,11 @@ pub enum NoCacheReason {
#[inline(always)] #[inline(always)]
pub fn compile_module<'s>( pub fn compile_module<'s>(
scope: &mut HandleScope<'s>, scope: &mut HandleScope<'s>,
source: Source, mut source: Source,
) -> Option<Local<'s, Module>> { ) -> Option<Local<'s, Module>> {
compile_module2( compile_module2(
scope, scope,
source, &mut source,
CompileOptions::NoCompileOptions, CompileOptions::NoCompileOptions,
NoCacheReason::NoReason, NoCacheReason::NoReason,
) )
@ -241,7 +246,7 @@ pub fn compile_module<'s>(
#[inline(always)] #[inline(always)]
pub fn compile_module2<'s>( pub fn compile_module2<'s>(
scope: &mut HandleScope<'s>, scope: &mut HandleScope<'s>,
mut source: Source, source: &mut Source,
options: CompileOptions, options: CompileOptions,
no_cache_reason: NoCacheReason, no_cache_reason: NoCacheReason,
) -> Option<Local<'s, Module>> { ) -> Option<Local<'s, Module>> {
@ -249,7 +254,7 @@ pub fn compile_module2<'s>(
scope.cast_local(|sd| { scope.cast_local(|sd| {
v8__ScriptCompiler__CompileModule( v8__ScriptCompiler__CompileModule(
sd.get_isolate_ptr(), sd.get_isolate_ptr(),
&mut source, source,
options, options,
no_cache_reason, no_cache_reason,
) )

View file

@ -8670,7 +8670,7 @@ fn create_module<'s>(
true, true,
); );
let has_cache = code_cache.is_some(); let has_cache = code_cache.is_some();
let source = match code_cache { let mut source = match code_cache {
Some(x) => v8::script_compiler::Source::new_with_cached_data( Some(x) => v8::script_compiler::Source::new_with_cached_data(
source, source,
Some(&script_origin), Some(&script_origin),
@ -8678,14 +8678,18 @@ fn create_module<'s>(
), ),
None => v8::script_compiler::Source::new(source, Some(&script_origin)), 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( let module = v8::script_compiler::compile_module2(
scope, scope,
source, &mut source,
options, options,
v8::script_compiler::NoCacheReason::NoReason, v8::script_compiler::NoCacheReason::NoReason,
) )
.unwrap(); .unwrap();
let code_cache = source.get_cached_data();
assert_eq!(code_cache.is_some(), has_cache);
if let Some(code_cache) = code_cache {
assert!(!code_cache.rejected());
}
module module
} }