You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see this functionality mentioned in the readme, and in a couple of issues, notably #152 , but I can't seem to make it work.
My situation, simplified, is as below. I happen to be using the async variant, in case that has something to do with my inability to share across contexts.
asyncmain(){construntime=module.newRuntime();constcontext1=runtime.newContext();awaitcontext1.evalCodeAsync(` function add(x) { return x + 50; }; `);consttest1Res=context.unwrapResult(awaitcontext1.evalCodeAsync(`add(50)`));console.log('add result1 (should be 100):',context1.getNumber(test1Res));test1Res.dispose();constcontextPointer=context1.ctx.value;constcontext2=runtime.newContext({contextPointer});// Throws with 'add' is not defined.consttest2Res=context2.unwrapResult(awaitcontext2.evalCodeAsync(`add(10)`));console.log('add result2 (should be 60):',context2.getNumber(test2Res));test2Res.dispose();}
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Here context2 should actually a reference to context1 since they have the same underlying memory pointer address. The issue is there’s a bug in the asyncified runtime’s newContext method where it ignores the passed pointer, so you are actually getting two contexts in the same runtime.
I think you are misusing the API. There’s no point to having context JS objects pointing to the same context C pointer. To make a painful analogy, let’s say the pointer is a door, and the QuickJSContext object is a doorknob. What your code is trying to do is attach two doorknobs to the same door.
Contexts in a runtime do not share any globals. What I mean by “sharing values” is that you can take a handle returned from one context, and pass it as a parameter into another context, if the contexts share the same runtime.
I see this functionality mentioned in the readme, and in a couple of issues, notably #152 , but I can't seem to make it work.
My situation, simplified, is as below. I happen to be using the async variant, in case that has something to do with my inability to share across contexts.
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: