Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix codegen for descriptors of async fn returns (#1782)
They erroneously reported returning the original return type, not the promise! Let's also add a bunch of positive tests while we're at it. Closes #1781
- Loading branch information
1 parent
8ba0142
commit 9c33052
Showing
5 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const assert = require('assert'); | ||
const wasm = require('wasm-bindgen-test'); | ||
|
||
exports.call_exports = async function() { | ||
await wasm.async_do_nothing(); | ||
assert.strictEqual(1, await wasm.async_return_1()); | ||
assert.strictEqual(2, await wasm.async_return_2()); | ||
await wasm.async_nothing_again(); | ||
assert.strictEqual(3, await wasm.async_return_3()); | ||
assert.strictEqual(4, await wasm.async_return_4()); | ||
assert.strictEqual(5, (await wasm.async_return_5()).val); | ||
assert.strictEqual(6, (await wasm.async_return_6()).val); | ||
assert.strictEqual(7, (await wasm.async_return_7()).val); | ||
assert.strictEqual(8, (await wasm.async_return_8()).val); | ||
await assert.rejects(wasm.async_throw(), /async message/); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen_test::*; | ||
|
||
#[wasm_bindgen(module = "tests/wasm/futures.js")] | ||
extern "C" { | ||
fn call_exports() -> js_sys::Promise; | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
async fn smoke() { | ||
wasm_bindgen_futures::JsFuture::from(call_exports()).await.unwrap(); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_do_nothing() {} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_1() -> JsValue { | ||
1.into() | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_2() -> u32 { | ||
2 | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_nothing_again() -> Result<(), JsValue> { | ||
Ok(()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_3() -> Result<u32, JsValue> { | ||
Ok(3) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_4() -> Result<JsValue, JsValue> { | ||
Ok(4.into()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct AsyncCustomReturn { | ||
pub val: u32, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_5() -> AsyncCustomReturn { | ||
AsyncCustomReturn { val: 5 } | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_6() -> Result<AsyncCustomReturn, JsValue> { | ||
Ok(AsyncCustomReturn { val: 6 }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_7() -> Result<AsyncCustomReturn, u32> { | ||
Ok(AsyncCustomReturn { val: 7 }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_return_8() -> Result<AsyncCustomReturn, AsyncCustomReturn> { | ||
Ok(AsyncCustomReturn { val: 8 }) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_throw() -> Result<(), js_sys::Error> { | ||
Err(js_sys::Error::new("async message")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters