[prev in list] [next in list] [prev in thread] [next in thread]
List: webkit-dev
Subject: Re: [webkit-dev] JavaScriptCore subclass native class created with JSClassCreate in javascript code
From: Geoffrey Garen <ggaren () apple ! com>
Date: 2014-10-06 19:22:40
Message-ID: 51D36D9D-FA66-4407-A0A4-FD210B7938EC () apple ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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@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@apple.com \
> <mailto:ggaren@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@apple.com \
> > > <mailto:ggaren@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@mxs.de \
> > > > <mailto:mmoeller@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@lists.webkit.org <mailto:webkit-dev@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@lists.webkit.org <mailto:webkit-dev@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@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
[Attachment #5 (text/html)]
<html><head><meta http-equiv="Content-Type" content="text/html \
charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: \
space; -webkit-line-break: after-white-space;" class="">Did you make sure to \
indicate, using the C API, that TestClass/parent class was the parent class of \
SubClass?<div class=""><br class=""></div><div class="">Geoff</div><div class=""><br \
class=""><div><blockquote type="cite" class=""><div class="">On Oct 5, 2014, at 4:48 \
AM, Moritz Moeller <<a href="mailto:mmoeller@mxs.de" \
class="">mmoeller@mxs.de</a>> wrote:</div><br \
class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" \
content="text/html charset=windows-1252" class=""><div style="word-wrap: break-word; \
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div \
class=""><br class=""></div><div class="">thank you for the feedback!</div><div \
class=""><br class=""></div><div class="">The constructor call now works, but the \
setProperty call does not seem to get forwarded.</div><div class=""><br \
class=""></div><div class="">If i do (new SubClass()).someProperty = true; the \
setProperty method of the TestClass/parent class is not called.</div><div \
class=""><br class=""></div><div class="">getProperty is called though.</div><div \
class=""><br class=""></div><div class="">There does not seem to be any \
Object.defineProperty API on the C level?</div><div class=""><br class=""></div><div \
class="">Thank you,</div><div class=""><br class=""></div><div \
class="">Moritz</div><div class=""><br class=""></div><div class=""><br class=""><div \
class=""><div class="">On 03 Oct 2014, at 1:37 , Geoffrey Garen <<a \
href="mailto:ggaren@apple.com" class="">ggaren@apple.com</a>> wrote:</div><br \
class="Apple-interchange-newline"><blockquote type="cite" class=""><meta \
http-equiv="Content-Type" content="text/html charset=windows-1252" class=""><div \
style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: \
after-white-space;" class="">…Yet another option is to insert Function.prototype into \
the TestClass prototype chain.<div class=""><br class=""></div><div \
class="">Geoff</div><div class=""><br class=""><div class=""><blockquote type="cite" \
class=""><div class="">On Oct 2, 2014, at 4:37 PM, Geoffrey Garen <<a \
href="mailto:ggaren@apple.com" class="">ggaren@apple.com</a>> wrote:</div><br \
class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" \
content="text/html charset=windows-1252" class=""><div style="word-wrap: break-word; \
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You’ll \
need to manually copy Function.prototype.apply to the TestClass prototype.<div \
class=""><br class=""></div><div class="">Another option is \
“Function.prototype.apply.call(TestClass, this, arguments)”.<br class=""><div \
class=""><br class=""></div><div class="">Geoff</div><div class=""><br class=""><div \
class=""><blockquote type="cite" class=""><div class="">On Oct 2, 2014, at 8:26 AM, \
Moritz Moeller <<a href="mailto:mmoeller@mxs.de" class="">mmoeller@mxs.de</a>> \
wrote:</div><br class="Apple-interchange-newline"><div class=""><meta \
http-equiv="Content-Type" content="text/html charset=windows-1252" class=""><div \
style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: \
after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I’ve \
created a javascript class in native code (i.e. JSClassCreate, \
JSObjectMakeConstructor etc.) and want to subclass this class in \
javascript.</div><div class=""><br class=""></div><div class="">So pretty \
much:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; \
font-size: 11px; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span \
style="" class=""> </span>JSClassDefinition<span style="" \
class=""> classDef = </span>kJSClassDefinitionEmpty<span style="" \
class="">;</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" \
class=""> classDef.<span style="color: rgb(112, 61, 170);" \
class="">className</span> = <span style="color: rgb(209, 47, 27);" \
class="">"TestClass"</span>;</div><div style="margin: 0px; font-size: 11px; \
font-family: Menlo;" class=""> classDef.<span style="color: rgb(112, 61, \
170);" class="">getProperty</span> = <span style="color: rgb(49, 89, 93);" \
class="">class_getProperty</span>;</div><div style="margin: 0px; font-size: 11px; \
font-family: Menlo;" class=""> classDef.<span style="color: rgb(112, 61, \
170);" class="">setProperty</span> = <span style="color: rgb(49, 89, 93);" \
class="">class_setProperty</span>;</div><div style="margin: 0px; font-size: 11px; \
font-family: Menlo; min-height: 13px;" class=""> <span \
style="color: rgb(112, 61, 170);" class="">JSClassRef</span> classRef \
= <span style="color: rgb(61, 29, 129);" \
class="">JSClassCreate</span>(&classDef);</div></div><div class=""><div \
style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> \
<span style="color: rgb(112, 61, 170);" \
class="">JSObjectRef</span> constructor = JSObjectMakeConstructor(ctx, \
gClassRef, class_constructor);</div><div style="margin: 0px; font-size: 11px; \
font-family: Menlo;" class=""> <span style="color: rgb(61, 29, \
129);" class="">JSObjectSetProperty</span>(ctx, <span style="color: rgb(61, 29, \
129);" class="">JSContextGetGlobalObject</span>(ctx), <span style="color: \
rgb(79, 129, 135);" class="">JsString</span>(<span style="color: rgb(209, 47, 27);" \
class="">"TestClass"</span>), constructor, <span style="color: rgb(39, 42, \
216);" class="">0</span>, <span style="color: rgb(187, 44, 162);" \
class="">NULL</span>);</div></div><div class=""><br class=""></div><div \
class="">class_constructor does:</div><div class=""><div style="margin: 0px; \
font-size: 11px; font-family: Menlo;" class=""> <span style="color: \
rgb(187, 44, 162);" class="">return</span> <span style="color: rgb(61, 29, \
129);" class="">JSObjectMake</span>(ctx, classRef, <span style="color: \
rgb(187, 44, 162);" class="">NULL</span>);</div></div><div class=""><br \
class=""></div><div class="">This works, so I can do</div><div class=""><div \
style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> \
<span style="color: rgb(187, 44, 162);" class="">var</span> test \
= <span style="color: rgb(187, 44, 162);" \
class="">new</span> TestClass();</div><div style="margin: 0px; font-size: 11px; \
font-family: Menlo;" class=""> test.field = <span style="color: \
rgb(39, 42, 216);" class="">1</span>;</div></div><div style="margin: 0px; font-size: \
11px; font-family: Menlo;" class=""><br class=""></div><div class="">and both \
class_constructor and class_setProperty is called.</div><div class=""><br \
class=""></div><div class="">Now I’m trying to subclass the TestClass:</div><div \
class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" \
class=""> <span style="color: rgb(187, 44, 162);" \
class="">function</span> SubClass()</div><div style="margin: 0px; font-size: \
11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; \
font-size: 11px; font-family: Menlo;" class=""> \
TestClass.apply(<span style="color: rgb(187, 44, 162);" class="">this</span>, \
arguments);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" \
class=""> }</div></div><div class=""><br class=""></div><div \
class="">here it already got the problem that TestClass - being a constructor - does \
not have .bind() or .apply().</div><div class=""><br class=""></div><div \
class="">Does someone know how to get this working?</div><div class=""><br \
class=""></div><div class="">Thank you very much,</div><div class=""><br \
class=""></div><div class="">Mo</div></div>_______________________________________________<br \
class="">webkit-dev mailing list<br class=""><a \
href="mailto:webkit-dev@lists.webkit.org" class="">webkit-dev@lists.webkit.org</a><br \
class=""><a href="https://lists.webkit.org/mailman/listinfo/webkit-dev" \
class="">https://lists.webkit.org/mailman/listinfo/webkit-dev</a><br \
class=""></div></blockquote></div><br \
class=""></div></div></div>_______________________________________________<br \
class="">webkit-dev mailing list<br class=""><a \
href="mailto:webkit-dev@lists.webkit.org" class="">webkit-dev@lists.webkit.org</a><br \
class=""><a href="https://lists.webkit.org/mailman/listinfo/webkit-dev" \
class="">https://lists.webkit.org/mailman/listinfo/webkit-dev</a><br \
class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br \
class=""></div></div>_______________________________________________<br \
class="">webkit-dev mailing list<br class=""><a \
href="mailto:webkit-dev@lists.webkit.org" class="">webkit-dev@lists.webkit.org</a><br \
class="">https://lists.webkit.org/mailman/listinfo/webkit-dev<br \
class=""></div></blockquote></div><br class=""></div></body></html>
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic