mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-15 14:01:25 +00:00
Remove slice logic of "commit to wasm"
When adding support for mutable slices I was under the impression that if the wasm memory was reallocated while we were using it then we'd have to commit the changes from the original buffer back to the new buffer. What I didn't know, however, is that once the wasm memory is reallocated then all views into it are supposed to be defunkt. It looks like node 9 didn't have this implementation quite right and it appears fixed in node 10, causing the deleted test here to fail. While this commit does raise the question of whether this is the right approach to interact with slices in JS I think the answer is still "yes". The user can always initiate the copy if need be and that seems strictly better than copying 100% of the time.
This commit is contained in:
@ -1264,60 +1264,6 @@ impl<'a> Context<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn expose_commit_slice_to_wasm(&mut self, ty: VectorKind)
|
||||
-> Result<&'static str, Error>
|
||||
{
|
||||
let gen = |me: &mut Context, name: &'static str, size: usize, get: &str| {
|
||||
me.global(&format!("
|
||||
function {name}(ptr, view) {{
|
||||
if (view.buffer !== wasm.memory.buffer)
|
||||
{get}().set(view, ptr / {size});
|
||||
}}
|
||||
",
|
||||
name = name,
|
||||
size = size,
|
||||
get = get,
|
||||
));
|
||||
name
|
||||
};
|
||||
match ty {
|
||||
VectorKind::String => bail!("strings cannot be used with mutable slices"),
|
||||
VectorKind::Anyref => bail!("js values cannot be used with mutable slices"),
|
||||
VectorKind::I8 => {
|
||||
self.expose_int8_memory();
|
||||
Ok(gen(self, "commitI8ToWasm", 1, "getInt8Memory"))
|
||||
}
|
||||
VectorKind::U8 => {
|
||||
self.expose_uint8_memory();
|
||||
Ok(gen(self, "commitU8ToWasm", 1, "getUint8Memory"))
|
||||
}
|
||||
VectorKind::I16 => {
|
||||
self.expose_int16_memory();
|
||||
Ok(gen(self, "commitI16ToWasm", 2, "getInt16Memory"))
|
||||
}
|
||||
VectorKind::U16 => {
|
||||
self.expose_uint16_memory();
|
||||
Ok(gen(self, "commitU16ToWasm", 2, "getUint16Memory"))
|
||||
}
|
||||
VectorKind::I32 => {
|
||||
self.expose_int32_memory();
|
||||
Ok(gen(self, "commitI32ToWasm", 4, "getInt32Memory"))
|
||||
}
|
||||
VectorKind::U32 => {
|
||||
self.expose_uint32_memory();
|
||||
Ok(gen(self, "commitU32ToWasm", 4, "getUint32Memory"))
|
||||
}
|
||||
VectorKind::F32 => {
|
||||
self.expose_f32_memory();
|
||||
Ok(gen(self, "commitF32ToWasm", 4, "getFloat32Memory"))
|
||||
}
|
||||
VectorKind::F64 => {
|
||||
self.expose_f64_memory();
|
||||
Ok(gen(self, "commitF64ToWasm", 8, "getFloat64Memory"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn expose_get_global_argument(&mut self) -> Result<(), Error> {
|
||||
if !self.exposed_globals.insert("get_global_argument") {
|
||||
return Ok(());
|
||||
|
@ -93,9 +93,6 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
wasm.__wbindgen_free({0}, {1} * {size});\
|
||||
", abi, abi2, size = ty.size()));
|
||||
self.cx.require_internal_export("__wbindgen_free")?;
|
||||
} else if arg.is_mut_ref() {
|
||||
let f = self.cx.expose_commit_slice_to_wasm(ty)?;
|
||||
self.finally(&format!("{}({1}, v{1});", f, abi));
|
||||
}
|
||||
self.js_arguments.push(format!("v{}", abi));
|
||||
return Ok(())
|
||||
|
Reference in New Issue
Block a user