Re: JS 45 problem

Boris Zbarsky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 5/24/16 12:17 PM, Kent Williams wrote:
> +        JS::RootedObject newTarget(cx,&args.newTarget().toObject());
> +        JS::RootedObject protoObj(cx);
> +        if(!JS_GetPrototype(cx,newTarget,&protoObj))

No, that's wrong.  What you want is more like:

   JS::RootedValue protoVal(cx);
   if (!JS_GetProperty(cx, newTarget, "prototype", &protoVal))
     return false;
   JS::RootedObject protoObj(cx);
   if (protoVal.isObject())
     protoObj = &protoVal.toObject();
   else
     protoObj = JS_GetObjectPrototype(cx, newTarget);
   obj = JS_NewObjectWithGivenProto(cx, &spider_xml, protoObj);

(yes, the signature of JS_GetObjectPrototype is dumb; we should fix that).

Basically, implement 
http://www.ecma-international.org/ecma-262/6.0/#sec-getprototypefromconstructor 
with the second arg being %ObjectPrototype%.

I don't think there's a more succinct API for this, sadly.  We should 
totally consider adding one; something like:

   JS::GetPrototypeFromConstructor(JSContext *cx,
                                   JSObject* ctor,
                                   JSProtoKey key);

or something.  I filed 
https://bugzilla.mozilla.org/show_bug.cgi?id=1275312 on that.

-Boris
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.