Closed portaljacker closed 2 years ago
This method implements JSON.stringify(), which can return undefined in rare circumstances (e.g. JSON.stringify(undefined)
). Undefined is not a string, so to match the spec the return value had to change. Generally from a compatibility perspective, I've prioritized matching the JS spec over maintaining backwards compatibility in the C# API.
Makes sense. So I just wrapped the block where I was using my result with this if statement: if (result is string s) { doStuff(s); }
and everything worked fine.
Or you can just do: result = (string)JSONObject.Stringify(...)
. The method will only return Undefined.Value
if you pass in something that can't be converted to JSON, like a function. If you know that'll never happen then it's safe just to immediately cast the result :-)
What's the reasoning for a stringify function not returning a string? That's a pretty big breaking change and I can't find anything mentioning it in this repository...
https://github.com/paulbartrum/jurassic/blob/4ecc4685f26128fbc38441ed6e7da72dd96de050/Jurassic/Library/JSON/JSONObject.cs#L58