mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-11 14:46:04 +00:00
Fix passStringToWasm
with shared memory
Looks like `TextEncoder#encodeInto` isn't compatible when the buffer passed in is backed by a `SharedArrayBuffer`, so if the module has a shared thread skip the `encodeInto` optimization entirely.
This commit is contained in:
parent
c62f6529d8
commit
233525d7d6
@ -1211,21 +1211,20 @@ impl<'a> Context<'a> {
|
|||||||
debug
|
debug
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Looks like `encodeInto` doesn't currently work when the memory passed
|
||||||
|
// in is backed by a `SharedArrayBuffer`, so force usage of `encode` if
|
||||||
|
// a `SharedArrayBuffer` is in use.
|
||||||
|
let shared = self.module.memories.get(self.memory).shared;
|
||||||
|
|
||||||
match self.config.encode_into {
|
match self.config.encode_into {
|
||||||
EncodeInto::Never => {
|
EncodeInto::Always if !shared => {
|
||||||
self.global(&format!(
|
|
||||||
"function passStringToWasm(arg) {{ {} }}",
|
|
||||||
use_encode,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
EncodeInto::Always => {
|
|
||||||
self.require_internal_export("__wbindgen_realloc")?;
|
self.require_internal_export("__wbindgen_realloc")?;
|
||||||
self.global(&format!(
|
self.global(&format!(
|
||||||
"function passStringToWasm(arg) {{ {} }}",
|
"function passStringToWasm(arg) {{ {} }}",
|
||||||
use_encode_into,
|
use_encode_into,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
EncodeInto::Test => {
|
EncodeInto::Test if !shared => {
|
||||||
self.require_internal_export("__wbindgen_realloc")?;
|
self.require_internal_export("__wbindgen_realloc")?;
|
||||||
self.global(&format!(
|
self.global(&format!(
|
||||||
"
|
"
|
||||||
@ -1240,6 +1239,12 @@ impl<'a> Context<'a> {
|
|||||||
use_encode,
|
use_encode,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
|
self.global(&format!(
|
||||||
|
"function passStringToWasm(arg) {{ {} }}",
|
||||||
|
use_encode,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user