diff --git a/Cargo.lock b/Cargo.lock index 6cd68e5ce1..90e857dc57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1500,9 +1500,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.326.0" +version = "0.327.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed157162dc5320a2b46ffeeaec24788339df0f2437cfaea78a8d82696715ad7f" +checksum = "eaf8dff204b9c2415deb47b9f30d4d38b0925d0d88f1f9074e8e76f59e6d7ded" dependencies = [ "anyhow", "az", @@ -2074,9 +2074,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.202.0" +version = "0.203.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd8ac1af251e292388e516dd339b9a3b982a6d1e7f8644c08e34671ca39003c" +checksum = "b146ca74cac431843486ade58e2accc16c11315fb2c6934590a52a73c56b7ec3" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -6725,9 +6725,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.235.0" +version = "0.236.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07afd8b67b4a442ecc2823038473ac0e9e5682de93c213323b60661afdd7eb4" +checksum = "e23b3abce64010612f88f4ff689a959736f99eb3dc0dbf1c7903434b8bd8cda5" dependencies = [ "num-bigint", "serde", diff --git a/Cargo.toml b/Cargo.toml index ccdf64986e..f290d1480b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno" [workspace.dependencies] deno_ast = { version = "=0.44.0", features = ["transpiling"] } -deno_core = { version = "0.326.0" } +deno_core = { version = "0.327.0" } deno_bench_util = { version = "0.178.0", path = "./bench_util" } deno_config = { version = "=0.40.0", features = ["workspace", "sync"] } diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 5e4ff875dc..3ba8753335 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -996,7 +996,7 @@ impl ModuleLoader std::future::ready(()).boxed_local() } - fn get_source_map(&self, file_name: &str) -> Option> { + fn get_source_map(&self, file_name: &str) -> Option> { let specifier = resolve_url(file_name).ok()?; match specifier.scheme() { // we should only be looking for emits for schemes that denote external @@ -1008,7 +1008,7 @@ impl ModuleLoader .0 .load_prepared_module_for_source_map_sync(&specifier) .ok()??; - source_map_from_code(source.code.as_bytes()) + source_map_from_code(source.code.as_bytes()).map(Cow::Owned) } fn get_source_mapped_source_line( diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index f7ffa46e4f..3707543eb0 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -746,7 +746,7 @@ impl<'a> DenoCompileBinaryWriter<'a> { for (specifier, source_map) in source_maps { source_map_store.add( Cow::Owned(root_dir_url.specifier_key(specifier).into_owned()), - Cow::Owned(source_map), + Cow::Owned(source_map.into_bytes()), ); } diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index d7227f2bd5..75247a98c0 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -502,7 +502,7 @@ impl ModuleLoader for EmbeddedModuleLoader { std::future::ready(()).boxed_local() } - fn get_source_map(&self, file_name: &str) -> Option> { + fn get_source_map(&self, file_name: &str) -> Option> { if file_name.starts_with("file:///") { let url = deno_path_util::url_from_directory_path(self.shared.vfs.root()).ok()?; @@ -512,8 +512,7 @@ impl ModuleLoader for EmbeddedModuleLoader { } else { self.shared.source_maps.get(file_name) } - // todo(https://github.com/denoland/deno_core/pull/1007): don't clone - .map(|s| s.as_bytes().to_vec()) + .map(Cow::Borrowed) } fn get_source_mapped_source_line( diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 8fe593c005..4c18e0eb53 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -86,7 +86,7 @@ pub fn serialize_binary_data_section( builder.append_le(specifier.len() as u32); builder.append(specifier); builder.append_le(source_map.len() as u32); - builder.append(source_map); + builder.append(source_map.as_ref()); } } @@ -124,9 +124,9 @@ pub fn deserialize_binary_data_section( #[allow(clippy::type_complexity)] fn read_source_map_entry( input: &[u8], - ) -> Result<(&[u8], (Cow, Cow)), AnyError> { + ) -> Result<(&[u8], (Cow, &[u8])), AnyError> { let (input, specifier) = read_string_lossy(input)?; - let (input, source_map) = read_string_lossy(input)?; + let (input, source_map) = read_bytes_with_u32_len(input)?; Ok((input, (specifier, source_map))) } @@ -164,7 +164,7 @@ pub fn deserialize_binary_data_section( let (current_input, (specifier, source_map)) = read_source_map_entry(input)?; input = current_input; - source_maps.add(specifier, source_map); + source_maps.add(specifier, Cow::Borrowed(source_map)); } // finally ensure we read the magic bytes at the end @@ -293,7 +293,7 @@ impl DenoCompileModuleSource { } pub struct SourceMapStore { - data: IndexMap, Cow<'static, str>>, + data: IndexMap, Cow<'static, [u8]>>, } impl SourceMapStore { @@ -306,13 +306,13 @@ impl SourceMapStore { pub fn add( &mut self, specifier: Cow<'static, str>, - source_map: Cow<'static, str>, + source_map: Cow<'static, [u8]>, ) { self.data.insert(specifier, source_map); } - pub fn get(&self, specifier: &str) -> Option<&Cow<'static, str>> { - self.data.get(specifier) + pub fn get(&self, specifier: &str) -> Option<&[u8]> { + self.data.get(specifier).map(|v| v.as_ref()) } } @@ -763,8 +763,7 @@ fn check_has_len(input: &[u8], len: usize) -> Result<(), AnyError> { } fn read_string_lossy(input: &[u8]) -> Result<(&[u8], Cow), AnyError> { - let (input, str_len) = read_u32_as_usize(input)?; - let (input, data_bytes) = read_bytes(input, str_len)?; + let (input, data_bytes) = read_bytes_with_u32_len(input)?; Ok((input, String::from_utf8_lossy(data_bytes))) } diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 624fa76bf6..2b36a8ddd8 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -198,7 +198,7 @@ pub struct CoverageReport { fn generate_coverage_report( script_coverage: &cdp::ScriptCoverage, script_source: String, - maybe_source_map: &Option>, + maybe_source_map: Option<&[u8]>, output: &Option, ) -> CoverageReport { let maybe_source_map = maybe_source_map @@ -625,7 +625,7 @@ pub fn cover_files( let coverage_report = generate_coverage_report( &script_coverage, runtime_code.as_str().to_owned(), - &source_map, + source_map.as_deref(), &out_mode, ); diff --git a/cli/util/text_encoding.rs b/cli/util/text_encoding.rs index 06b311e150..107b78a213 100644 --- a/cli/util/text_encoding.rs +++ b/cli/util/text_encoding.rs @@ -140,23 +140,23 @@ mod tests { #[test] fn test_source_map_from_code() { let to_string = - |bytes: Vec| -> String { String::from_utf8(bytes).unwrap() }; + |bytes: Vec| -> String { String::from_utf8(bytes.to_vec()).unwrap() }; assert_eq!( source_map_from_code( - b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=", + b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=" ).map(to_string), Some("testingtesting".to_string()) ); assert_eq!( source_map_from_code( - b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n \n", + b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n \n" ).map(to_string), Some("testingtesting".to_string()) ); assert_eq!( source_map_from_code( - b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n test\n", - ), + b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n test\n" + ).map(to_string), None ); assert_eq!( @@ -164,7 +164,7 @@ mod tests { b"\"use strict\"; throw new Error(\"Hello world!\"); -//# sourceMappingURL=data:application/json;base64,{", +//# sourceMappingURL=data:application/json;base64,{" ), None );