mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
Merge pull request #869 from alexcrichton/cleanup-classes
Only generate JS null checks in debug mode
This commit is contained in:
commit
616b27457d
@ -985,7 +985,7 @@ impl ToTokens for ast::Enum {
|
|||||||
_extra: &mut ::wasm_bindgen::convert::Stack,
|
_extra: &mut ::wasm_bindgen::convert::Stack,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
#(#cast_clauses else)* {
|
#(#cast_clauses else)* {
|
||||||
::wasm_bindgen::throw("invalid enum value passed")
|
::wasm_bindgen::throw_str("invalid enum value passed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,13 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
/// passed should be `this.ptr`.
|
/// passed should be `this.ptr`.
|
||||||
pub fn method(&mut self, method: bool, consumed: bool) -> &mut Self {
|
pub fn method(&mut self, method: bool, consumed: bool) -> &mut Self {
|
||||||
if method {
|
if method {
|
||||||
self.prelude(
|
if self.cx.config.debug {
|
||||||
"if (this.ptr === 0) {
|
self.prelude(
|
||||||
throw new Error('Attempt to use a moved value');
|
"if (this.ptr === 0) {
|
||||||
}",
|
throw new Error('Attempt to use a moved value');
|
||||||
);
|
}",
|
||||||
|
);
|
||||||
|
}
|
||||||
if consumed {
|
if consumed {
|
||||||
self.prelude(
|
self.prelude(
|
||||||
"\
|
"\
|
||||||
|
@ -85,7 +85,8 @@ exports.custom_type_return_2 = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.touch_custom_type = function() {
|
exports.touch_custom_type = function() {
|
||||||
assert.throws(() => CUSTOM_TYPE.touch(), /Attempt to use a moved value/);
|
assert.throws(() => CUSTOM_TYPE.touch(),
|
||||||
|
/Attempt to use a moved value|null pointer passed to rust/);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.interpret_2_as_custom_type = function() {
|
exports.interpret_2_as_custom_type = function() {
|
||||||
|
@ -5,14 +5,16 @@ const useMoved = () => {
|
|||||||
const apple = new wasm.Fruit('apple');
|
const apple = new wasm.Fruit('apple');
|
||||||
apple.name();
|
apple.name();
|
||||||
wasm.eat(apple);
|
wasm.eat(apple);
|
||||||
assert.throws(() => apple.name(), /Attempt to use a moved value/);
|
assert.throws(() => apple.name(),
|
||||||
|
/Attempt to use a moved value|null pointer passed to rust/);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveMoved = () => {
|
const moveMoved = () => {
|
||||||
const pear = new wasm.Fruit('pear');
|
const pear = new wasm.Fruit('pear');
|
||||||
pear.name();
|
pear.name();
|
||||||
wasm.eat(pear);
|
wasm.eat(pear);
|
||||||
assert.throws(() => wasm.eat(pear), /Attempt to use a moved value/);
|
assert.throws(() => wasm.eat(pear),
|
||||||
|
/Attempt to use a moved value|null pointer passed to rust/);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.js_works = () => {
|
exports.js_works = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user