From cc821835dad883ea43dc132f3422921d9172993b Mon Sep 17 00:00:00 2001 From: Ralic Lo Date: Sun, 15 Nov 2026 12:21:17 +0800 Subject: [PATCH 1/2] refactor(runtime): read StringHeader payloads through string_data at the eight new open-coded sites The string payload-access ratchet fails on main (perry-runtime inline-offset: baseline 327, found 335). The eight new sites add size_of::() to a header pointer by hand instead of calling crate::string::string_data, which computes exactly that address: - object/http_handle_prototype.rs (3, from e1fbae4ae7) - object/field_get_set/buffer_own_prop.rs (1, from b96fcce917) - tests: array/from_primitive_tests.rs (892ad29ce3), buffer/error_object_tests.rs (86dc5e90c2), object/global_this/declaration_keys_tests.rs (e5e99ef9a3), thread/error_stack_clone_tests.rs (841006a706) No behaviour change: string_data(s) is (s as *const u8).add(size_of::()). The count returns to the baseline, which is not changed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p --- .../perry-runtime/src/array/from_primitive_tests.rs | 2 +- .../perry-runtime/src/buffer/error_object_tests.rs | 2 +- .../src/object/field_get_set/buffer_own_prop.rs | 5 +---- .../src/object/global_this/declaration_keys_tests.rs | 2 +- .../src/object/http_handle_prototype.rs | 12 +++--------- .../src/thread/error_stack_clone_tests.rs | 6 +----- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/crates/perry-runtime/src/array/from_primitive_tests.rs b/crates/perry-runtime/src/array/from_primitive_tests.rs index 7d3ea6e5890..bf87b205f50 100644 --- a/crates/perry-runtime/src/array/from_primitive_tests.rs +++ b/crates/perry-runtime/src/array/from_primitive_tests.rs @@ -156,7 +156,7 @@ fn element_bytes(arr: *mut ArrayHeader, index: u32) -> Vec { crate::value::js_get_string_pointer_unified(value) as *const crate::string::StringHeader; unsafe { let len = (*sptr).byte_len as usize; - let data = (sptr as *const u8).add(std::mem::size_of::()); + let data = crate::string::string_data(sptr); std::slice::from_raw_parts(data, len).to_vec() } } diff --git a/crates/perry-runtime/src/buffer/error_object_tests.rs b/crates/perry-runtime/src/buffer/error_object_tests.rs index 46323872413..726d133b8e1 100644 --- a/crates/perry-runtime/src/buffer/error_object_tests.rs +++ b/crates/perry-runtime/src/buffer/error_object_tests.rs @@ -7,7 +7,7 @@ use crate::string::StringHeader; unsafe fn text(s: *const StringHeader) -> String { let len = (*s).byte_len as usize; - let data = (s as *const u8).add(std::mem::size_of::()); + let data = crate::string::string_data(s); String::from_utf8_lossy(std::slice::from_raw_parts(data, len)).into_owned() } diff --git a/crates/perry-runtime/src/object/field_get_set/buffer_own_prop.rs b/crates/perry-runtime/src/object/field_get_set/buffer_own_prop.rs index 348048da864..7a396fba0a8 100644 --- a/crates/perry-runtime/src/object/field_get_set/buffer_own_prop.rs +++ b/crates/perry-runtime/src/object/field_get_set/buffer_own_prop.rs @@ -138,10 +138,7 @@ pub(crate) fn view_get(obj: *const ObjectHeader, key: *const crate::StringHeader let addr = obj as usize; if !key.is_null() { let key_bytes = unsafe { - std::slice::from_raw_parts( - (key as *const u8).add(std::mem::size_of::()), - (*key).byte_len as usize, - ) + std::slice::from_raw_parts(crate::string::string_data(key), (*key).byte_len as usize) }; if let Ok(name) = std::str::from_utf8(key_bytes) { if let Some(v) = crate::buffer::buffer_read_own_prop(addr, name) { diff --git a/crates/perry-runtime/src/object/global_this/declaration_keys_tests.rs b/crates/perry-runtime/src/object/global_this/declaration_keys_tests.rs index 976a3310cbc..1a4bcd2828e 100644 --- a/crates/perry-runtime/src/object/global_this/declaration_keys_tests.rs +++ b/crates/perry-runtime/src/object/global_this/declaration_keys_tests.rs @@ -14,7 +14,7 @@ fn own_string_keys(proto: f64) -> std::collections::BTreeSet { let s = crate::builtins::js_string_coerce(crate::array::js_array_get_f64(names, i)); unsafe { let bytes = std::slice::from_raw_parts( - (s as *const u8).add(std::mem::size_of::()), + crate::string::string_data(s), (*s).byte_len as usize, ); String::from_utf8_lossy(bytes).into_owned() diff --git a/crates/perry-runtime/src/object/http_handle_prototype.rs b/crates/perry-runtime/src/object/http_handle_prototype.rs index 254d0008572..50e22ff4aad 100644 --- a/crates/perry-runtime/src/object/http_handle_prototype.rs +++ b/crates/perry-runtime/src/object/http_handle_prototype.rs @@ -60,10 +60,7 @@ pub(crate) fn inherited_field( let scope = crate::gc::RuntimeHandleScope::new(); let key_root = scope.root_nanbox_f64(crate::value::js_nanbox_string(key as i64)); let name = unsafe { - std::slice::from_raw_parts( - (key as *const u8).add(std::mem::size_of::()), - (*key).byte_len as usize, - ) + std::slice::from_raw_parts(crate::string::string_data(key), (*key).byte_len as usize) } .to_vec(); let mut proto = scope.root_nanbox_f64(of_handle(handle_id)?); @@ -104,17 +101,14 @@ pub(crate) fn field(handle_id: usize, key: *const crate::StringHeader) -> Option let scope = crate::gc::RuntimeHandleScope::new(); let key_root = scope.root_nanbox_f64(crate::value::js_nanbox_string(key as i64)); let name = unsafe { - std::slice::from_raw_parts( - (key as *const u8).add(std::mem::size_of::()), - (*key).byte_len as usize, - ) + std::slice::from_raw_parts(crate::string::string_data(key), (*key).byte_len as usize) }; let name_owned = std::str::from_utf8(name).ok()?.to_owned(); let name = name_owned.as_str(); let native = || { let key = (key_root.get_nanbox_u64() & crate::value::POINTER_MASK) as *const crate::StringHeader; - let ptr = unsafe { (key as *const u8).add(std::mem::size_of::()) }; + let ptr = crate::string::string_data(key); let value = super::class_handles::handle_property_dispatch() .map(|dispatch| unsafe { dispatch(handle_id as i64, ptr, name.len()) }) .unwrap_or_else(|| f64::from_bits(crate::value::TAG_UNDEFINED)); diff --git a/crates/perry-runtime/src/thread/error_stack_clone_tests.rs b/crates/perry-runtime/src/thread/error_stack_clone_tests.rs index 94d31a999ad..56d212ba18d 100644 --- a/crates/perry-runtime/src/thread/error_stack_clone_tests.rs +++ b/crates/perry-runtime/src/thread/error_stack_clone_tests.rs @@ -88,11 +88,7 @@ fn error_stack_clone_reads_a_non_enumerable_getter_once() { let ptr = crate::value::js_get_string_pointer_unified(stack) as *const crate::string::StringHeader; let bytes = unsafe { - std::slice::from_raw_parts( - ptr.cast::() - .add(std::mem::size_of::()), - (*ptr).byte_len as usize, - ) + std::slice::from_raw_parts(crate::string::string_data(ptr), (*ptr).byte_len as usize) }; assert_eq!(bytes, b"getter-stack"); } From b7ebbade6d26aa1f6edd40ef78d9881f9983a7e0 Mon Sep 17 00:00:00 2001 From: Ralic Lo Date: Sun, 15 Nov 2026 13:53:31 +0800 Subject: [PATCH 2/2] chore: changelog entry for #14751 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p --- changelog.d/14751-string-payload-accessor.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14751-string-payload-accessor.md diff --git a/changelog.d/14751-string-payload-accessor.md b/changelog.d/14751-string-payload-accessor.md new file mode 100644 index 00000000000..9cf682405c6 --- /dev/null +++ b/changelog.d/14751-string-payload-accessor.md @@ -0,0 +1 @@ +Eight new open-coded `StringHeader` payload offsets (the HTTP handle prototype's field lookups, the ArrayBuffer/DataView own-property read and four unit tests) read the payload through `string::string_data`, returning the string payload-access ratchet to its baseline. No behaviour change.