From a727f1f11ae06dcb196cd028a31900dbfd2f68ed Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Fri, 30 Oct 2026 16:28:45 +0000 Subject: [PATCH] Test V8 inline typed array storage limits (#58385) ## What changed Extract the inline storage predicate into a test helper in `codex-rs/v8-poc/src/lib.rs` and reuse it in the typed array contents test. Add coverage for disabled inline storage (a zero limit), empty arrays, and lengths at and above a nonzero limit. GitOrigin-RevId: 3370ea41b58e0d0ff00266272ccc4fa331bcf38b --- codex-rs/v8-poc/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/codex-rs/v8-poc/src/lib.rs b/codex-rs/v8-poc/src/lib.rs index 500bb986e5..3b710be61d 100644 --- a/codex-rs/v8-poc/src/lib.rs +++ b/codex-rs/v8-poc/src/lib.rs @@ -30,6 +30,10 @@ mod tests { use super::bazel_target; + fn uses_inline_typed_array_storage(length: usize, max_inline_size: usize) -> bool { + max_inline_size != 0 && length <= max_inline_size + } + fn initialize_v8() { static INIT: Once = Once::new(); @@ -141,6 +145,20 @@ mod tests { assert_eq!(evaluate_expression("'hello ' + 'world'"), "hello world"); } + #[test] + fn inline_typed_array_storage_respects_disabled_and_bounded_limits() { + assert_eq!( + [ + uses_inline_typed_array_storage(/*length*/ 0, /*max_inline_size*/ 0), + uses_inline_typed_array_storage(/*length*/ 1, /*max_inline_size*/ 0), + uses_inline_typed_array_storage(/*length*/ 0, /*max_inline_size*/ 64), + uses_inline_typed_array_storage(/*length*/ 64, /*max_inline_size*/ 64), + uses_inline_typed_array_storage(/*length*/ 65, /*max_inline_size*/ 64), + ], + [false, false, true, true, false] + ); + } + #[test] fn reads_typed_array_contents_with_the_compiled_binding_size() { initialize_v8(); @@ -153,8 +171,7 @@ mod tests { let expression = format!("new Uint8Array({length}).fill(90)"); let value = evaluate_script(scope, &expression); let view = v8::Local::::try_from(value).unwrap(); - let on_heap = - v8::TYPED_ARRAY_MAX_SIZE_IN_HEAP != 0 && length <= v8::TYPED_ARRAY_MAX_SIZE_IN_HEAP; + let on_heap = uses_inline_typed_array_storage(length, v8::TYPED_ARRAY_MAX_SIZE_IN_HEAP); // Check native placement before asking C++ to copy into storage: // stale size-zero bindings must fail here rather than abort in FFI. assert_eq!(view.has_buffer(), !on_heap, "byte length {length}");