Repository navigation
Closed
Description
I try to use the libsodium-wrapper in QuickJS follow the document, but it hang when await ready .
after some test, i took the strange thing, the Promise will break the VM then i use the code from document .
the mini code in follow :
import {getQuickJS, QuickJSContext, QuickJSHandle, Scope, shouldInterruptAfterDeadline} from 'quickjs-emscripten';
(async () => {
const QuickJS = await getQuickJS();
await Scope.withScopeAsync(async (scope) => {
const vm = scope.manage(QuickJS.newContext());
const result = vm.evalCode(
`
(new Promise((resolve, reject) => {
setTimeout(args => {
resolve(undefined);
}, 1000);
})).then(T=>{});
`
);
// run in sync way, it return ok.
// // output:
// // Success: {}
// // undefined
// if (result.error) {
// console.log('Execution failed:', vm.dump(result.error));
// result.error.dispose();
// } else {
// console.log('Success:', vm.dump(result.value));
// result.value.dispose();
// }
// return;
// run in async way, it return into strange ?
// output:
// promiseHandle
// resolvedResult
// resolvedResultPromise Promise { <pending> }
//
// then the process end.
console.log('promiseHandle');
const promiseHandle = (vm.unwrapResult(result));
console.log('resolvedResult');
const resolvedResultPromise = vm.resolvePromise(promiseHandle);
console.log('resolvedResultPromise', resolvedResultPromise);
const resolvedResult = await resolvedResultPromise; // <============ end on the `await` op
console.log('promiseHandle.dispose'); // <============ this code be never run
promiseHandle.dispose();
console.log('resolvedHandle');
const resolvedHandle = (vm.unwrapResult(resolvedResult));
console.log('resolvedHandle', vm.getString(resolvedHandle));
console.log('resolvedHandle.dispose');
resolvedHandle.dispose();
});
})().then(T => {
console.log(T);
}).catch(E => {
console.error(E);
});anything wrong ?
Metadata
Metadata
Assignees
Labels
No labels
Activity
justjake commentedon Jun 22, 2022
Lyoko-Jeremie commentedon Jun 22, 2022
@justjake
i think so , but the promise create in the vm , use in the vm , and resolve in the vm , where can i call the executePendingJobs ?
Lyoko-Jeremie commentedon Jun 22, 2022
i find a
JS_BOOL JS_IsJobPending(JSRuntime *rt);function from quickjs.hhttps://github.com/bellard/quickjs/blob/2788d71e823b522b178db3b3660ce93689534e6d/quickjs.h#L874
the
JS_IsJobPendingseems like usefull .and after i look up the document, i find some thing :
https://github.com/justjake/quickjs-emscripten/blob/897fded554b9b1c056c830789f407690ed01a2d9/CHANGELOG.md#breaking-changes
executependingjobs()
haspendingjob()
and from the evalcode() comment :
so, i add
vm.runtime.executePendingJobs()call between thevm.resolvePromiseandawaitlike follow, the above code work !seems like the document in Readme.md need some update
Squashed 'vendor/quickjs/' changes from 36911f0..e5fd391
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Update vendored QuickJS to 2025-09-13 (rebased) (#243)
Update vendored QuickJS to 2025-09-13 (rebased) (justjake#243)