Re: JS 45 problem

Kent Williams <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
Thanks a lot.  I remember talk about this. Luckily we don't (yet!) have 
a lot of code using JS_InitClass

On 05/24/2016 09:47 AM, Boris Zbarsky wrote:
> On 5/24/16 10:32 AM, Kent Williams wrote:
>>         obj = JS_NewObject(cx, &TESTO);
>
> Kent,
>
> This line is the problem.  JS_NewObject used to guess at the prototype 
> to use based on the name of the given class and what that name 
> resolved to in global scope.
>
> This was all sorts of broken and fragile, and was removed (see 
> <https://bugzilla.mozilla.org/show_bug.cgi?id=1125567>).  If you use 
> JS_NewObject, you will get an object whose prototype is Object.prototype.
>
> What you want here is JS_NewObjectWithGivenProto and pass in the thing 
> you want as your prototype.
>
> I think you have a few options for how to do that:
>
> 1)  Save the value returned from JS_InitClass and use that. Should be 
> the right thing as long as no one is subclassing you.
>
> 2)  In the constructor, get the "prototype" property of args.callee() 
> and use that.  Again, should be the right thing as long as no one is 
> subclassing you.
>
> 3)  In the constructor, get the "prototype" property of 
> args.newTarget().  Should do the right thing (as in, use the proto of 
> the constructor that was actually invoked) even if you're subclassed.
>
> -Boris
> _______________________________________________
> dev-tech-js-engine mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.