From 083f43346c96b5ba729f5f37c1249a721c119959 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Thu, 7 Mar 2024 09:36:06 -0800 Subject: [PATCH] feat: expose CachedData::rejected (#1413) --- src/script_compiler.rs | 13 +++++++++---- tests/test_api.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/script_compiler.rs b/src/script_compiler.rs index 6b02dfe2..eecfa8ea 100644 --- a/src/script_compiler.rs +++ b/src/script_compiler.rs @@ -118,6 +118,11 @@ impl<'a> CachedData<'a> { pub(crate) fn buffer_policy(&self) -> BufferPolicy { self.buffer_policy } + + #[inline(always)] + pub fn rejected(&self) -> bool { + self.rejected + } } impl<'a> std::ops::Deref for CachedData<'a> { @@ -227,11 +232,11 @@ pub enum NoCacheReason { #[inline(always)] pub fn compile_module<'s>( scope: &mut HandleScope<'s>, - source: Source, + mut source: Source, ) -> Option> { compile_module2( scope, - source, + &mut source, CompileOptions::NoCompileOptions, NoCacheReason::NoReason, ) @@ -241,7 +246,7 @@ pub fn compile_module<'s>( #[inline(always)] pub fn compile_module2<'s>( scope: &mut HandleScope<'s>, - mut source: Source, + source: &mut Source, options: CompileOptions, no_cache_reason: NoCacheReason, ) -> Option> { @@ -249,7 +254,7 @@ pub fn compile_module2<'s>( scope.cast_local(|sd| { v8__ScriptCompiler__CompileModule( sd.get_isolate_ptr(), - &mut source, + source, options, no_cache_reason, ) diff --git a/tests/test_api.rs b/tests/test_api.rs index a17ee1b7..518f3ae0 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -8670,7 +8670,7 @@ fn create_module<'s>( true, ); 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( source, Some(&script_origin), @@ -8678,14 +8678,18 @@ 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, + &mut source, options, v8::script_compiler::NoCacheReason::NoReason, ) .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 }