Skip to content

Commit 18440a5

Browse files
authored
Merge pull request #1306 from alexcrichton/encode-into-shared
Fix `passStringToWasm` with shared memory
2 parents c62f652 + 233525d commit 18440a5

File tree

1 file changed

+13
-8
lines changed
  • crates/cli-support/src/js

1 file changed

+13
-8
lines changed

crates/cli-support/src/js/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1211,21 +1211,20 @@ impl<'a> Context<'a> {
12111211
debug
12121212
);
12131213

1214+
// Looks like `encodeInto` doesn't currently work when the memory passed
1215+
// in is backed by a `SharedArrayBuffer`, so force usage of `encode` if
1216+
// a `SharedArrayBuffer` is in use.
1217+
let shared = self.module.memories.get(self.memory).shared;
1218+
12141219
match self.config.encode_into {
1215-
EncodeInto::Never => {
1216-
self.global(&format!(
1217-
"function passStringToWasm(arg) {{ {} }}",
1218-
use_encode,
1219-
));
1220-
}
1221-
EncodeInto::Always => {
1220+
EncodeInto::Always if !shared => {
12221221
self.require_internal_export("__wbindgen_realloc")?;
12231222
self.global(&format!(
12241223
"function passStringToWasm(arg) {{ {} }}",
12251224
use_encode_into,
12261225
));
12271226
}
1228-
EncodeInto::Test => {
1227+
EncodeInto::Test if !shared => {
12291228
self.require_internal_export("__wbindgen_realloc")?;
12301229
self.global(&format!(
12311230
"
@@ -1240,6 +1239,12 @@ impl<'a> Context<'a> {
12401239
use_encode,
12411240
));
12421241
}
1242+
_ => {
1243+
self.global(&format!(
1244+
"function passStringToWasm(arg) {{ {} }}",
1245+
use_encode,
1246+
));
1247+
}
12431248
}
12441249
Ok(())
12451250
}

0 commit comments

Comments
 (0)