You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following the suggestion from #193 the Value property on my custom JSObject's now inherit from JSObject. This causes the following test to not pass, hence my custom json serializer registered on the global context is not invoked:
I then tried to override the "toJSON" property as follows:
The problem is then that the returned string gets qouted because of the recursive call to stringifyImpl() instead of being returned directly:
Should this code instead be:
if (toJSONmemb._valueType == JSValueType.Function)
{
var json = (toJSONmemb._oValue as Function).Call(obj, null);
if (json.Value is string jsonString)
{
return jsonString;
}
return stringifyImpl("", json, null, null, space, processed, null);
}
?
The text was updated successfully, but these errors were encountered:
Unfortunately, this is correct behavior of JSON.stringify with toJSON (see this).
Yes, it's weird, but it's not the only weird place in JS.
I think about this trouble and concluded, that condition about JSValue and it's subclasses should be removed. But it's required to solve problem with performance penalty, which will arise after this.
Also you can return instance of another type, which not inherits JSValue and passes through this condition.
Or do not inherit JSValue in you current implementation (see this example. Attributes not required, all works without them)
Following the suggestion from #193 the Value property on my custom JSObject's now inherit from JSObject. This causes the following test to not pass, hence my custom json serializer registered on the global context is not invoked:
![image](https://user-images.githubusercontent.com/2112306/66478001-aaec0080-ea99-11e9-97a7-c04cb5f03acc.png)
I then tried to override the "toJSON" property as follows:
![image](https://user-images.githubusercontent.com/2112306/66478090-dff85300-ea99-11e9-975b-670168852bb6.png)
The problem is then that the returned string gets qouted because of the recursive call to
stringifyImpl()
instead of being returned directly:Should this code instead be:
?
The text was updated successfully, but these errors were encountered: