Only emit JS glue assertions for move arguments in debug mode

This commit is contained in:
Nick Fitzgerald
2018-11-08 14:50:29 -08:00
parent d646b29bb7
commit 75c18f0916
2 changed files with 19 additions and 7 deletions

View File

@ -85,7 +85,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
if self.cx.config.debug {
self.prelude(
"if (this.ptr === 0) {
throw new Error('Attempt to use a moved value');
throw new Error('Attempt to use a moved value');
}",
);
}
@ -330,14 +330,26 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.prelude(&format!(
"\
const ptr{i} = {arg}.ptr;\n\
if (ptr{i} === 0) {{
throw new Error('Attempt to use a moved value');
}}
{arg}.ptr = 0;\n\
",
",
i = i,
arg = name
));
if self.cx.config.debug {
self.prelude(&format!(
"\
if (ptr{i} === 0) {{
throw new Error('Attempt to use a moved value');
}}
",
i = i,
));
}
self.prelude(&format!(
"\
{arg}.ptr = 0;\n\
",
arg = name
));
self.rust_arguments.push(format!("ptr{}", i));
}
return Ok(self);