mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 13:31:22 +00:00
Add an unsafe method view_mut_raw (#1850)
* adding .vscode folder to .gitignore * Adding view_mut_raw to generated arrays * test populating rust vector from JS function * Uint32Array test, need to make it generic * Add doc + more test cases * replacing macro-generated tests with generic test function it is cleaner, safer and better that way * improving rustdoc
This commit is contained in:
committed by
Alex Crichton
parent
e7bfa161e0
commit
d51f539d1a
@ -4792,6 +4792,31 @@ macro_rules! arrays {
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a JS typed array which is a view into wasm's linear
|
||||
/// memory at the specified pointer with specified length.
|
||||
///
|
||||
/// This function returns a new typed array which is a view into
|
||||
/// wasm's memory. This view does not copy the underlying data.
|
||||
///
|
||||
/// # Unsafety
|
||||
///
|
||||
/// Views into WebAssembly memory are only valid so long as the
|
||||
/// backing buffer isn't resized in JS. Once this function is called
|
||||
/// any future calls to `Box::new` (or malloc of any form) may cause
|
||||
/// the returned value here to be invalidated. Use with caution!
|
||||
///
|
||||
/// Additionally the returned object can be safely mutated,
|
||||
/// the changes are guranteed to be reflected in the input array.
|
||||
pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
|
||||
let buf = wasm_bindgen::memory();
|
||||
let mem = buf.unchecked_ref::<WebAssembly::Memory>();
|
||||
$name::new_with_byte_offset_and_length(
|
||||
&mem.buffer(),
|
||||
ptr as u32,
|
||||
length as u32
|
||||
)
|
||||
}
|
||||
|
||||
fn raw_copy_to(&self, dst: &mut [$ty]) {
|
||||
let buf = wasm_bindgen::memory();
|
||||
let mem = buf.unchecked_ref::<WebAssembly::Memory>();
|
||||
|
Reference in New Issue
Block a user