0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-12 17:09:28 -05:00

feat: pass source as mut ref to script_compiler::compile (#1420)

This commit is contained in:
Igor Zinkovsky 2024-03-12 16:55:29 -07:00 committed by GitHub
parent bc5ac4d486
commit 2371c4534b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -265,7 +265,7 @@ pub fn compile_module2<'s>(
#[inline(always)]
pub fn compile<'s>(
scope: &mut HandleScope<'s>,
mut source: Source,
source: &mut Source,
options: CompileOptions,
no_cache_reason: NoCacheReason,
) -> Option<Local<'s, Script>> {
@ -273,7 +273,7 @@ pub fn compile<'s>(
scope.cast_local(|sd| {
v8__ScriptCompiler__Compile(
&*sd.get_current_context(),
&mut source,
source,
options,
no_cache_reason,
)

View file

@ -8913,10 +8913,10 @@ fn eager_compile_script() {
let scope = &mut v8::ContextScope::new(scope, context);
let code = v8::String::new(scope, "1 + 1").unwrap();
let source = v8::script_compiler::Source::new(code, None);
let mut source = v8::script_compiler::Source::new(code, None);
let script = v8::script_compiler::compile(
scope,
source,
&mut source,
v8::script_compiler::CompileOptions::EagerCompile,
v8::script_compiler::NoCacheReason::NoReason,
)
@ -8953,18 +8953,21 @@ fn code_cache_script() {
let scope = &mut v8::ContextScope::new(scope, context);
let code = v8::String::new(scope, CODE).unwrap();
let source = v8::script_compiler::Source::new_with_cached_data(
let mut source = v8::script_compiler::Source::new_with_cached_data(
code,
None,
v8::CachedData::new(&code_cache),
);
let script = v8::script_compiler::compile(
scope,
source,
&mut source,
v8::script_compiler::CompileOptions::ConsumeCodeCache,
v8::script_compiler::NoCacheReason::NoReason,
)
.unwrap();
let code_cache = source.get_cached_data();
assert!(code_cache.is_some());
assert!(!code_cache.unwrap().rejected());
let ret = script.run(scope).unwrap();
assert_eq!(ret.uint32_value(scope).unwrap(), 2);
}