mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +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.expose_text_encoder();
|
||||
self.expose_uint8_memory();
|
||||
self.globals.push_str(&format!("
|
||||
function passStringToWasm(arg) {{
|
||||
let debug = if self.config.debug {
|
||||
"
|
||||
if (typeof(arg) !== 'string')
|
||||
throw new Error('expected a string argument');
|
||||
"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
self.globals.push_str(&format!("
|
||||
function passStringToWasm(arg) {{
|
||||
{}
|
||||
const buf = textEncoder().encode(arg);
|
||||
const len = buf.length;
|
||||
const ptr = wasm.__wbindgen_malloc(len);
|
||||
getUint8Memory().set(buf, ptr);
|
||||
const ptr = wasm.__wbindgen_malloc(buf.length);
|
||||
getUint8Memory().set(buf, buf.length);
|
||||
return [ptr, len];
|
||||
}}
|
||||
"));
|
||||
", debug));
|
||||
}
|
||||
|
||||
fn expose_pass_array8_to_wasm(&mut self) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user