[quickjs-devel] native classes, ctx vs. rt

  • From: Mario Gliewe <mag@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Thu, 12 Sep 2019 14:12:33 +0200

Hi,

i'm still investigating the possibillity of implementing a
Worker/SharedWorker interface.


A short question:

While browsing the code, i stumbled on a a possible API
kwirk/inconsistency..

When defining a native class, I'll do that for the JSRuntime. Setting
the prototype object, I'll have to create a new Object, which has to be
done on the JSContext.

Is that intentional?

So that  each context using a native class will create its own class
instance, having its own unique class_id, the class definition belonging
to the runtime (important for malloc/free and gc) and the prototype
belonging to the context (important for object behavior in context) ?


greets

maG


-- snip --
JSClassID clsid;
JSClassDef clsdef = {
    "NewClass", .finalizer=[..], .gc_mark=[..], .call=[..]
};
JS_NewClassID(&clsid);
JS_NewClass(rt, clsid, &clsdef);
JSValue proto = JS_NewObject(ctx);
   [...JS_SetPropertyFunctionList( .. )]

JS_SetClassProto(ctx, clsid, proto);

-- snap --


Other related posts: