mirror of
https://github.com/openai/codex.git
synced 2026-10-30 19:18:49 +00:00
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
This commit is contained in:
@@ -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::<v8::ArrayBufferView>::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}");
|
||||
|
||||
Reference in New Issue
Block a user