Only generate JS null checks in debug mode

In non-debug mode Rust is already checking these pointers, so let's only
generate the relevant code in debug mode.
This commit is contained in:
Alex Crichton
2018-09-21 15:17:19 -07:00
parent 727cfc3bb5
commit ab3688d01a
4 changed files with 14 additions and 9 deletions

View File

@ -985,7 +985,7 @@ impl ToTokens for ast::Enum {
_extra: &mut ::wasm_bindgen::convert::Stack,
) -> Self {
#(#cast_clauses else)* {
::wasm_bindgen::throw("invalid enum value passed")
::wasm_bindgen::throw_str("invalid enum value passed")
}
}
}

View File

@ -68,11 +68,13 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
/// passed should be `this.ptr`.
pub fn method(&mut self, method: bool, consumed: bool) -> &mut Self {
if method {
self.prelude(
"if (this.ptr === 0) {
throw new Error('Attempt to use a moved value');
}",
);
if self.cx.config.debug {
self.prelude(
"if (this.ptr === 0) {
throw new Error('Attempt to use a moved value');
}",
);
}
if consumed {
self.prelude(
"\