mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-03 10:51:09 +00:00
Merge pull request #1020 from fitzgen/move-by-value-debug-asserts
Only emit JS glue assertions for move arguments in debug mode
This commit is contained in:
commit
227e836e04
@ -330,12 +330,24 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
self.prelude(&format!(
|
self.prelude(&format!(
|
||||||
"\
|
"\
|
||||||
const ptr{i} = {arg}.ptr;\n\
|
const ptr{i} = {arg}.ptr;\n\
|
||||||
|
",
|
||||||
|
i = i,
|
||||||
|
arg = name
|
||||||
|
));
|
||||||
|
if self.cx.config.debug {
|
||||||
|
self.prelude(&format!(
|
||||||
|
"\
|
||||||
if (ptr{i} === 0) {{
|
if (ptr{i} === 0) {{
|
||||||
throw new Error('Attempt to use a moved value');
|
throw new Error('Attempt to use a moved value');
|
||||||
}}
|
}}
|
||||||
{arg}.ptr = 0;\n\
|
|
||||||
",
|
",
|
||||||
i = i,
|
i = i,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
self.prelude(&format!(
|
||||||
|
"\
|
||||||
|
{arg}.ptr = 0;\n\
|
||||||
|
",
|
||||||
arg = name
|
arg = name
|
||||||
));
|
));
|
||||||
self.rust_arguments.push(format!("ptr{}", i));
|
self.rust_arguments.push(format!("ptr{}", i));
|
||||||
|
@ -124,7 +124,7 @@ exports.js_readonly_fields = () => {
|
|||||||
|
|
||||||
exports.js_double_consume = () => {
|
exports.js_double_consume = () => {
|
||||||
const r = new wasm.DoubleConsume();
|
const r = new wasm.DoubleConsume();
|
||||||
assert.throws(() => r.consume(r), /Attempt to use a moved value/);
|
assert.throws(() => r.consume(r));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user