[webkit-dev] JavaScriptCore subclass native class created with JSClassCreate in javascript code

Moritz Moeller mmoeller at mxs.de
Thu Oct 2 08:26:54 PDT 2014


Hi,

I’ve created a javascript class in native code (i.e. JSClassCreate, JSObjectMakeConstructor etc.) and want to subclass this class in javascript.

So pretty much:

    JSClassDefinition classDef = kJSClassDefinitionEmpty;
    classDef.className = "TestClass";
    classDef.getProperty = class_getProperty;
    classDef.setProperty = class_setProperty;
    JSClassRef classRef = JSClassCreate(&classDef);
    JSObjectRef constructor = JSObjectMakeConstructor(ctx, gClassRef, class_constructor);
    JSObjectSetProperty(ctx, JSContextGetGlobalObject(ctx), JsString("TestClass"), constructor, 0, NULL);

class_constructor does:
    return JSObjectMake(ctx, classRef, NULL);

This works, so I can do
    var test = new TestClass();
    test.field = 1;

and both class_constructor and class_setProperty is called.

Now I’m trying to subclass the TestClass:
    function SubClass()
    {
        TestClass.apply(this, arguments);
    }

here it already got the problem that TestClass - being a constructor - does not have .bind() or .apply().

Does someone know how to get this working?

Thank you very much,

Mo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20141002/7b5e13a3/attachment.html>


More information about the webkit-dev mailing list