Skip to content

context.getPromiseState readme sample not working #210

Open

Description

@damianofalcioni

Hi,
I'm try to run the context.getPromiseState demo in the readme but I got the following error:

import { getQuickJS, shouldInterruptAfterDeadline } from 'quickjs-emscripten'

const QuickJS = await getQuickJS();
const context = QuickJS.newContext();

const promiseHandle = context.evalCode(`Promise.resolve(42)`);
const resultHandle = context.unwrapResult(context.getPromiseState(promiseHandle));
console.log(context.getNumber(resultHandle));
resultHandle.dispose();
promiseHandle.dispose();

context.dispose();

Error:

0
file:///.../node_modules/quickjs-emscripten-core/dist/chunk-JTKJZQYV.mjs:3
Lifetime used`):new QuickJSUseAfterFree("Lifetime not alive")}},StaticLifetime=class extends Lifetime{constructor(value,owner){super(value,void 0,void 0,owner)}get dupable(){return!0}dup(){return this}dispose(){}},WeakLifetime=class extends Lifetime{constructor(value,copier,disposer,owner){super(value,copier,disposer,owner)}dispose(){this._alive=!1}};function scopeFinally(scope,blockError){let disposeError;try{scope.dispose()}catch(error){disposeError=error}if(blockError&&disposeError)throw Object.assign(blockError,{message:`${blockError.message}
                ^

QuickJSUseAfterFree: Lifetime not alive
    at _Lifetime.assertAlive (file:///.../node_modules/quickjs-emscripten-core/dist/chunk-JTKJZQYV.mjs:3:17)
    at _Lifetime.dispose (file:///.../node_modules/quickjs-emscripten-core/dist/chunk-JTKJZQYV.mjs:1:4093)
    at DisposableSuccess.dispose (file:///.../node_modules/quickjs-emscripten-core/dist/chunk-JTKJZQYV.mjs:4:2379)
    at file:///.../src/connectors/js-quickjs/index.js:10:15

Node.js v20.16.0

Also the intellisense report an error on context.getPromiseState(promiseHandle):

Argument of type 'JSPromiseState' is not assignable to parameter of type 'SuccessOrFail<QuickJSHandle, QuickJSHandle>'.
  Type 'JSPromiseStatePending' is not assignable to type 'SuccessOrFail<QuickJSHandle, QuickJSHandle>'.
    Property 'value' is missing in type 'JSPromiseStatePending' but required in type '{ value: QuickJSHandle; error?: undefined; }'.

quickjs-emscripten version: 0.31.0

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions