[webkit-dev] prototypes and host objects

Kent Hansen kent.hansen at nokia.com
Wed Feb 10 08:42:15 PST 2010


ext Allison Newman wrote:
> Hi,
> I have a framework written in C using a hand-rolled class system, and I am trying to create Javascript bindings to use this framework.
> So far I have succesfully created objects containing all of the desired methods and properties (with their appropriate getters and setters), correctly handle callbacks etc etc.  BUT, I have hit a problem - I cannot seem to create the prototype for these host objects that I have created.
> Specifically, in Javascript, if I write:
>     var host_object = new MyHostObject();
> host_object.prototype resolves as [undefined].
> I have tried setting the prototype of objects created in the various callAsConstructor callbacks that I have implemented, by calling JSObjectSetPrototype, but this doesn't seem to have any effect, and I have also tried setting the class attributes in the class reference to kJSClassAttributeNoAutomaticPrototype also to no avail. Maybe I am not making the call in the right place? Or is there another step that I am missing?
> Does anybody have a working example of doing this correctly? Or even a suggestion for what I am doing wrong?
> Thanks in advance,
> Alli

(This question belongs on the webkit-help list.)
Looks like you're confusing the property named "prototype" with the 
internal [[Prototype]] ("__proto__") property.
"host_object.__proto__" should resolve to your prototype object (and 
moreover, "host_object.foo" should resolve to property "foo" in your 
prototype). "MyHostObject.prototype" should also resolve to your 
prototype object if you want your constructor to seem like a "normal" JS 
constructor (see section 13.2.2 of the ES5 spec).


More information about the webkit-dev mailing list