Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,10 @@ int v8__String__WriteUtf8(const v8::String& self, v8::Isolate* isolate,
}

size_t v8__String__WriteUtf8_v2(const v8::String& self, v8::Isolate* isolate,
char* buffer, size_t capacity, int flags) {
return self.WriteUtf8V2(isolate, buffer, capacity, flags);
char* buffer, size_t capacity, int flags,
size_t* processed_characters_return) {
return self.WriteUtf8V2(isolate, buffer, capacity, flags,
processed_characters_return);
}

const v8::String::ExternalStringResource* v8__String__GetExternalStringResource(
Expand Down
16 changes: 15 additions & 1 deletion src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ unsafe extern "C" {
buffer: *mut char,
capacity: size_t,
flags: int,
processed_characters_return: *mut size_t,
) -> int;

fn v8__String__GetExternalStringResource(
Expand Down Expand Up @@ -651,6 +652,7 @@ impl String {
scope: &mut Isolate,
buffer: &mut [u8],
flags: WriteFlags,
processed_characters_return: Option<&mut usize>,
) -> usize {
unsafe {
// SAFETY:
Expand All @@ -662,7 +664,12 @@ impl String {
let data = buffer.as_mut_ptr().cast();
slice::from_raw_parts_mut(data, len)
};
self.write_utf8_uninit_v2(scope, buffer, flags)
self.write_utf8_uninit_v2(
scope,
buffer,
flags,
processed_characters_return,
)
}
}

Expand Down Expand Up @@ -698,6 +705,7 @@ impl String {
scope: &mut Isolate,
buffer: &mut [MaybeUninit<u8>],
flags: WriteFlags,
processed_characters_return: Option<&mut usize>,
) -> usize {
let bytes = unsafe {
v8__String__WriteUtf8_v2(
Expand All @@ -706,6 +714,9 @@ impl String {
buffer.as_mut_ptr() as _,
buffer.len(),
flags.bits(),
processed_characters_return
.map(|p| p as *mut _)
.unwrap_or(std::ptr::null_mut()),
)
};
bytes as usize
Expand Down Expand Up @@ -997,6 +1008,7 @@ impl String {
scope,
&mut *buffer,
WriteFlags::kReplaceInvalidUtf8,
None,
);
debug_assert!(length == len_utf8);

Expand Down Expand Up @@ -1067,6 +1079,7 @@ impl String {
scope,
buffer,
WriteFlags::kReplaceInvalidUtf8,
None,
);
debug_assert!(length == len_utf8);

Expand Down Expand Up @@ -1095,6 +1108,7 @@ impl String {
scope,
&mut *buffer,
WriteFlags::kReplaceInvalidUtf8,
None,
);
debug_assert!(length == len_utf8);

Expand Down
9 changes: 8 additions & 1 deletion tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,17 @@ fn test_string() {
assert_eq!(17, local.utf8_length(scope));
assert_eq!(reference, local.to_rust_string_lossy(scope));
let mut vec = vec![0; 17];
let mut processed_characters = 0;
assert_eq!(
17,
local.write_utf8_v2(scope, &mut vec, v8::WriteFlags::empty())
local.write_utf8_v2(
scope,
&mut vec,
v8::WriteFlags::empty(),
Some(&mut processed_characters)
)
);
assert_eq!(15, processed_characters);
let mut u16_buffer = [0u16; 16];
local.write_v2(scope, 0, &mut u16_buffer, v8::WriteFlags::empty());
assert_eq!(
Expand Down
Loading