From 79d49df796e0e4f6a73db8957789629c6f391e99 Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Mon, 10 Mar 2025 18:33:53 -0300 Subject: [PATCH 1/5] Fix hermes get original function name --- .gitignore | 1 + tests/test_hermes.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index d6b09013..374bd04d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store target Cargo.lock +.idea \ No newline at end of file diff --git a/tests/test_hermes.rs b/tests/test_hermes.rs index d73ca1f6..37583d9e 100644 --- a/tests/test_hermes.rs +++ b/tests/test_hermes.rs @@ -19,6 +19,12 @@ fn test_react_native_hermes() { ("input.js", 2, 0, None) ); assert_eq!(sm.get_original_function_name(11857), Some("")); + + assert_eq!( + sm.lookup_token(0, 11947).unwrap().to_tuple(), + ("module.js", 1, 4, None) + ); + assert_eq!(sm.get_original_function_name(11947), Some("foo")); } #[test] From 9e18abf43b381ce2f38bfabfe6783ed9265f3bc5 Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Mon, 10 Mar 2025 18:39:47 -0300 Subject: [PATCH 2/5] Actual bug fix --- src/hermes.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hermes.rs b/src/hermes.rs index 085f0d78..321d85d2 100644 --- a/src/hermes.rs +++ b/src/hermes.rs @@ -108,8 +108,10 @@ impl SourceMapHermes { // Find the closest mapping, just like here: // https://github.com/facebook/metro/blob/63b523eb20e7bdf62018aeaf195bb5a3a1a67f36/packages/metro-symbolicate/src/SourceMetadataMapConsumer.js#L204-L231 + // Mappings use 1-based index for lines, and 0-based index for cols, as seen here: + // https://github.com/facebook/metro/blob/f2d80cebe66d3c64742f67259f41da26e83a0d8d/packages/metro/src/Server/symbolicate.js#L58-L60 let (_mapping_idx, mapping) = - greatest_lower_bound(&function_map.mappings, &token.get_src(), |o| { + greatest_lower_bound(&function_map.mappings, &(token.get_src_line() + 1, token.get_src_col()), |o| { (o.line, o.column) })?; function_map From f0b7a08944875806bdd2006054c4c186570d1d71 Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Tue, 11 Mar 2025 10:00:57 -0300 Subject: [PATCH 3/5] lint --- src/hermes.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hermes.rs b/src/hermes.rs index 321d85d2..737dedc4 100644 --- a/src/hermes.rs +++ b/src/hermes.rs @@ -110,10 +110,11 @@ impl SourceMapHermes { // https://github.com/facebook/metro/blob/63b523eb20e7bdf62018aeaf195bb5a3a1a67f36/packages/metro-symbolicate/src/SourceMetadataMapConsumer.js#L204-L231 // Mappings use 1-based index for lines, and 0-based index for cols, as seen here: // https://github.com/facebook/metro/blob/f2d80cebe66d3c64742f67259f41da26e83a0d8d/packages/metro/src/Server/symbolicate.js#L58-L60 - let (_mapping_idx, mapping) = - greatest_lower_bound(&function_map.mappings, &(token.get_src_line() + 1, token.get_src_col()), |o| { - (o.line, o.column) - })?; + let (_mapping_idx, mapping) = greatest_lower_bound( + &function_map.mappings, + &(token.get_src_line() + 1, token.get_src_col()), + |o| (o.line, o.column), + )?; function_map .names .get(mapping.name_index as usize) From 49d1f5e9b86653d7436692762583cff7de5aae9f Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Fri, 14 Mar 2025 09:51:54 -0300 Subject: [PATCH 4/5] Fix cargo clippy errors --- src/ram_bundle.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ram_bundle.rs b/src/ram_bundle.rs index ca2d3c18..98b54b5a 100644 --- a/src/ram_bundle.rs +++ b/src/ram_bundle.rs @@ -416,7 +416,7 @@ impl<'a> SplitRamBundleModuleIter<'a> { } } -impl<'a> Iterator for SplitRamBundleModuleIter<'a> { +impl Iterator for SplitRamBundleModuleIter<'_> { type Item = Result<(String, SourceView, SourceMap)>; fn next(&mut self) -> Option { @@ -457,8 +457,7 @@ pub fn split_ram_bundle<'a>( pub fn is_ram_bundle_slice(slice: &[u8]) -> bool { slice .pread_with::(0, scroll::LE) - .ok() - .map_or(false, |x| x.is_valid_magic()) + .ok().is_some_and(|x| x.is_valid_magic()) } /// Returns "true" if the given path points to the startup file of a file RAM bundle From f63e1d85f9e702eb3aab924f526644a2f5795154 Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Fri, 14 Mar 2025 09:57:34 -0300 Subject: [PATCH 5/5] Fix lint --- src/ram_bundle.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ram_bundle.rs b/src/ram_bundle.rs index 98b54b5a..c01a3d7c 100644 --- a/src/ram_bundle.rs +++ b/src/ram_bundle.rs @@ -457,7 +457,8 @@ pub fn split_ram_bundle<'a>( pub fn is_ram_bundle_slice(slice: &[u8]) -> bool { slice .pread_with::(0, scroll::LE) - .ok().is_some_and(|x| x.is_valid_magic()) + .ok() + .is_some_and(|x| x.is_valid_magic()) } /// Returns "true" if the given path points to the startup file of a file RAM bundle