Skip to content

Commit fdc38eb

Browse files
fix: ret definition, test failure
1 parent bb1d971 commit fdc38eb

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

crates/js-component-bindgen/src/function_bindgen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl FunctionBindgen<'_> {
254254
///
255255
fn write_result_assignment(&mut self, amt: usize, results: &mut Vec<String>) {
256256
match amt {
257-
0 => {}
257+
0 => uwrite!(self.src, "let ret;"),
258258
1 => {
259259
uwrite!(self.src, "let ret = ");
260260
results.push("ret".to_string());

crates/js-component-bindgen/src/intrinsics/p3/async_task.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,27 +1347,21 @@ impl AsyncTaskIntrinsic {
13471347
13481348
const callbackFnName = task.getCallbackFnName();
13491349
1350-
// TODO: how can we know whether this is a Promise? (due to WebAssembly.promising, because async)
1351-
// BUT, attempting to await this promising with a host import that is async fails with
1352-
// 'trying to suspend JS frames'
13531350
callbackResult = await callbackResult;
1351+
if (callbackResult === undefined) {{ return; }}
13541352
13551353
let callbackCode;
13561354
let waitableSetRep;
13571355
let unpacked;
1358-
if (callbackResult !== undefined) {{
1359-
if (!({i32_typecheck}(callbackResult))) {{
1360-
throw new Error('invalid callback result [' + callbackResult + '], not a number');
1361-
}}
1362-
if (callbackResult < 0 || callbackResult > 3) {{
1363-
throw new Error('invalid async return value, outside callback code range');
1364-
}}
1365-
unpacked = {unpack_callback_result_fn}(callbackResult);
1366-
callbackCode = unpacked[0];
1367-
waitableSetRep = unpacked[1];
1368-
}} else {{
1369-
throw new Error('NO INTIIAL CALLBACK RESULT');
1356+
if (!({i32_typecheck}(callbackResult))) {{
1357+
throw new Error('invalid callback result [' + callbackResult + '], not a number');
1358+
}}
1359+
if (callbackResult < 0 || callbackResult > 3) {{
1360+
throw new Error('invalid async return value, outside callback code range');
13701361
}}
1362+
unpacked = {unpack_callback_result_fn}(callbackResult);
1363+
callbackCode = unpacked[0];
1364+
waitableSetRep = unpacked[1];
13711365
13721366
let eventCode;
13731367
let index;

crates/js-component-bindgen/src/intrinsics/p3/host.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,22 @@ impl HostIntrinsic {
144144
throw new Error(`task component idx [${{ currentCallerTask.componentIdx() }}] differs from caller [${{ callerInstanceIdx }}] (callee ${{ calleeInstanceIdx }})`);
145145
}}
146146
147-
const directParams = storagePtr === -1;
147+
// TODO: support direct params based on storagePtr/args
148+
const directParams = true;
148149
let getCalleeParamsFn;
149150
if (directParams) {{
150151
const directParamsArr = argArray.slice(8);
151152
getCalleeParamsFn = () => directParamsArr;
152153
}} else {{
153-
if (memoryIdx === null) {{ throw new Error('memory index not supplied to prepare depsite indirect params being used'); }}
154+
if (memoryIdx === null) {{ throw new Error('memory idx not supplied to prepare depsite indirect params being used'); }}
154155
155156
// TODO: call startFn() which lifts parameters into given space
156157
//
157158
// TODO: if we're using indirect params/the max number of params,
158159
// then the last param is actually a return pointer?
160+
//
161+
// storagePtr can come in as -2 (likely packed)
162+
// storageLen can come in as a value like 1193328 (and then the wasm-sent params)
159163
throw new Error(`indirect parameter loading not yet supported`);
160164
}}
161165

packages/jco/test/p3/ported/wasmtime/component-async/post-return.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ suite('post-return async sleep scenario', () => {
101101
});
102102
const instance = res.instance;
103103
cleanup = res.cleanup;
104-
console.log("FOLDER:", res.outputDir);
105104

106105
const result = await instance['local:local/sleep-post-return'].asyncRun(waitTimeMs);
107106
expect(result).toBeUndefined();

0 commit comments

Comments
 (0)