Re: JS 45 problem
Boris Zbarsky <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
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