Re: Object creation in SpiderMonkey 45
Mihai Dobrescu <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday, May 4, 2016 at 7:48:10 PM UTC+3, Mihai Dobrescu wrote:
> Hello,
>
> What changed concerning custom global objects?
> I have defined some with "toString" function. In version 38, when instantiating them with JS_NewObject, "toString" was called successfully.
> Now, this happens for objects created by the SpiderMonkey itself, but my code that uses JS_NewObject seems to skip assigning the "toString" method, as it is not called anymore. What could be the reason?
>
> Thanks.
I've tried to debug, but still, no success.
For the following javascript:
var ap1 = new AIRealPoint(3, 3); --> (h, v), both of type AIReal
print(ap1);
print(ap1.h);
I get:
{ h: 3, v: 3 } --> my toString implementation
[object AIReal] --> default toString implementation, should have been my custom toString, having the output of "3"
For the following code:
var r = new AIReal(3);
print(r);
I get the expected custom toString output:
3
The h and v properties are defined using a templated function, basically creating a custom object of type AIReal (in this case) to return, using JS_NewObject. It surely does it, as the toString output states "[object AIReal]", but for some reason it doesn't call the custom toString when it is created this way. Any hints?
BTW, the print function uses JS::ToString to access object's toString method.