quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

JS_GetOpaque return NULL on derived js class

Open CeceWall opened this issue 4 years ago • 1 comments

Description

Can't get opaque pointer on derived js obj

    static JSClassID base_class_id = 0;

    JSValue base_method_a(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
         JS_GetOpaque(this_val, base_class_id); // would return NULL if deriverd object call methodA
    }

    static JSCFunctionListEntry base_class_funcs[] = {
        JS_CFUNC_DEF("methodA", 2, base_method_a),
    };

    void init() {
        /**
         * define base class
         */
        JSValue proto = JS_NewObject(ctx);
        JS_NewClassID(&base_class_id);
        JS_NewClass(JS_GetRuntime(ctx), base_class_id, &base_class_def);
        JS_SetClassProto(ctx, base_class_id, proto);
        JS_SetPropertyFunctionList(ctx, proto, base_class_funcs, countof(base_class_funcs));
    
        /**
         * define derived class
         */
        JSValue baseObj = JS_NewObjectClass(ctx, base_class_id);
        JS_NewClassID(&derived_class_id);
        JS_NewClass(JS_GetRuntime(ctx), derived_class_id, &derived_class_def);
        JS_SetClassProto(ctx, derived_class_id, baseObj);
    }

Build environment

Ubuntu 18.04 gcc version 9.3.0 QuickJS version 2021-03-27

CeceWall avatar May 08 '21 02:05 CeceWall

@CeceWall did you ever find a solution or workaround for this? I'm also trying to access base class methods and hitting the same problem.

projectitis avatar Aug 22 '21 07:08 projectitis