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

Geoffrey Garen ggaren at apple.com
Mon Oct 6 12:22:40 PDT 2014


Did you make sure to indicate, using the C API, that TestClass/parent class was the parent class of SubClass?

Geoff

> On Oct 5, 2014, at 4:48 AM, Moritz Moeller <mmoeller at mxs.de> wrote:
> 
> Hi,
> 
> thank you for the feedback!
> 
> The constructor call now works, but the setProperty call does not seem to get forwarded.
> 
> If i do (new SubClass()).someProperty = true; the setProperty method of the TestClass/parent class is not called.
> 
> getProperty is called though.
> 
> There does not seem to be any Object.defineProperty API on the C level?
> 
> Thank you,
> 
> Moritz
> 
> 
> On 03 Oct 2014, at 1:37 , Geoffrey Garen <ggaren at apple.com <mailto:ggaren at apple.com>> wrote:
> 
>> …Yet another option is to insert Function.prototype into the TestClass prototype chain.
>> 
>> Geoff
>> 
>>> On Oct 2, 2014, at 4:37 PM, Geoffrey Garen <ggaren at apple.com <mailto:ggaren at apple.com>> wrote:
>>> 
>>> You’ll need to manually copy Function.prototype.apply to the TestClass prototype.
>>> 
>>> Another option is “Function.prototype.apply.call(TestClass, this, arguments)”.
>>> 
>>> Geoff
>>> 
>>>> On Oct 2, 2014, at 8:26 AM, Moritz Moeller <mmoeller at mxs.de <mailto:mmoeller at mxs.de>> wrote:
>>>> 
>>>> 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
>>>> _______________________________________________
>>>> webkit-dev mailing list
>>>> webkit-dev at lists.webkit.org <mailto:webkit-dev at lists.webkit.org>
>>>> https://lists.webkit.org/mailman/listinfo/webkit-dev <https://lists.webkit.org/mailman/listinfo/webkit-dev>
>>> 
>>> _______________________________________________
>>> webkit-dev mailing list
>>> webkit-dev at lists.webkit.org <mailto:webkit-dev at lists.webkit.org>
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev <https://lists.webkit.org/mailman/listinfo/webkit-dev>
>> 
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20141006/6ac405e2/attachment.html>


More information about the webkit-dev mailing list