2018-08-05 05:00:16 +03:00
|
|
|
const wasm = require('wasm-bindgen-test.js');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2019-07-16 23:35:59 +03:00
|
|
|
// NB: `wasm-pack` uses the presence of checks for moved values as a way to test
|
|
|
|
// whether it is correctly enabling `--debug` when configured to do so, so don't
|
|
|
|
// change this expected debug output without also updating `wasm-pack`'s tests.
|
|
|
|
const assertMovedPtrThrows = process.env.WASM_BINDGEN_NO_DEBUG == null
|
|
|
|
? f => assert.throws(f, /Attempt to use a moved value/)
|
|
|
|
: f => assert.throws(f, /null pointer passed to rust/);
|
|
|
|
|
2018-08-05 05:00:16 +03:00
|
|
|
const useMoved = () => {
|
|
|
|
const apple = new wasm.Fruit('apple');
|
|
|
|
apple.name();
|
|
|
|
wasm.eat(apple);
|
2019-07-16 23:35:59 +03:00
|
|
|
assertMovedPtrThrows(() => apple.name());
|
2018-08-05 05:00:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const moveMoved = () => {
|
|
|
|
const pear = new wasm.Fruit('pear');
|
|
|
|
pear.name();
|
|
|
|
wasm.eat(pear);
|
2019-07-16 23:35:59 +03:00
|
|
|
assertMovedPtrThrows(() => wasm.eat(pear));
|
|
|
|
};
|
|
|
|
|
|
|
|
const methodMoved = () => {
|
|
|
|
const quince = new wasm.Fruit('quince');
|
|
|
|
quince.name();
|
|
|
|
quince.rot();
|
|
|
|
assertMovedPtrThrows(() => quince.rot());
|
2018-08-05 05:00:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.js_works = () => {
|
|
|
|
useMoved();
|
|
|
|
moveMoved();
|
2019-07-16 23:35:59 +03:00
|
|
|
methodMoved();
|
2018-08-05 05:00:16 +03:00
|
|
|
};
|