mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-22 12:42:14 +00:00
Tighten up passStringToWasm a bit
Only emit `throw` on debug mode primarily
This commit is contained in:
parent
f1e8e2bee0
commit
978b5ada63
@ -545,17 +545,23 @@ impl<'a> Context<'a> {
|
|||||||
self.required_internal_exports.insert("__wbindgen_malloc");
|
self.required_internal_exports.insert("__wbindgen_malloc");
|
||||||
self.expose_text_encoder();
|
self.expose_text_encoder();
|
||||||
self.expose_uint8_memory();
|
self.expose_uint8_memory();
|
||||||
self.globals.push_str(&format!("
|
let debug = if self.config.debug {
|
||||||
function passStringToWasm(arg) {{
|
"
|
||||||
if (typeof(arg) !== 'string')
|
if (typeof(arg) !== 'string')
|
||||||
throw new Error('expected a string argument');
|
throw new Error('expected a string argument');
|
||||||
|
"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
self.globals.push_str(&format!("
|
||||||
|
function passStringToWasm(arg) {{
|
||||||
|
{}
|
||||||
const buf = textEncoder().encode(arg);
|
const buf = textEncoder().encode(arg);
|
||||||
const len = buf.length;
|
const ptr = wasm.__wbindgen_malloc(buf.length);
|
||||||
const ptr = wasm.__wbindgen_malloc(len);
|
getUint8Memory().set(buf, buf.length);
|
||||||
getUint8Memory().set(buf, ptr);
|
|
||||||
return [ptr, len];
|
return [ptr, len];
|
||||||
}}
|
}}
|
||||||
"));
|
", debug));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expose_pass_array8_to_wasm(&mut self) {
|
fn expose_pass_array8_to_wasm(&mut self) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user