mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-25 08:39:15 -05:00
feat: add String::write_utf8_uninit (#1019)
This commit is contained in:
parent
de7a1acbde
commit
8f8636b4f7
1 changed files with 23 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::convert::TryInto;
|
||||
use std::default::Default;
|
||||
use std::mem::forget;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::slice;
|
||||
|
||||
use crate::support::char;
|
||||
|
@ -264,6 +265,28 @@ impl String {
|
|||
buffer: &mut [u8],
|
||||
nchars_ref: Option<&mut usize>,
|
||||
options: WriteOptions,
|
||||
) -> usize {
|
||||
unsafe {
|
||||
// SAFETY:
|
||||
// We assume that v8 will overwrite the buffer without de-initializing any byte in it.
|
||||
// So the type casting of the buffer is safe.
|
||||
|
||||
let buffer = {
|
||||
let len = buffer.len();
|
||||
let data = buffer.as_mut_ptr().cast();
|
||||
slice::from_raw_parts_mut(data, len)
|
||||
};
|
||||
self.write_utf8_uninit(scope, buffer, nchars_ref, options)
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the contents of the string to an external buffer, as UTF-8.
|
||||
pub fn write_utf8_uninit(
|
||||
&self,
|
||||
scope: &mut Isolate,
|
||||
buffer: &mut [MaybeUninit<u8>],
|
||||
nchars_ref: Option<&mut usize>,
|
||||
options: WriteOptions,
|
||||
) -> usize {
|
||||
let mut nchars_ref_int: int = 0;
|
||||
let bytes = unsafe {
|
||||
|
|
Loading…
Reference in a new issue