[ 
https://issues.apache.org/jira/browse/CB-11737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15433363#comment-15433363
 ] 

Shazron Abdullah commented on CB-11737:
---------------------------------------

I did some experiments last night on this. Yes, that is true the JSON spec does 
not support these values, and recommend that when stringifying these values, to 
convert them to null. What does Windows do in this case, what do they convert 
to?

Three approaches:
1. Have a try catch, and reject the serialization attempt, report the error. 
Let plugin developers develop their own way to serialize this case -- not sure 
this is feasible. At least the app won't crash, but then the app will be in an 
indeterminate state.
2. Serialize Infinity and NaN to the string values "Infinity" and "NaN". These 
in JavaScript can be coerced into the right values of Infinity and NaN. 
However, deserialization is a problem.
3. Serialize Infinity and NaN to null.  Again, deserialization is a problem.

For 2 and 3, deserialization may be only a problem for the unit tests with 
mixed data to test whether the serialization worked. 

Also, for these two cases, we would have to iterate through everything in the 
object to serialize to determine if it is a NSNumber (INFINITY or NAN) and 
explicitly convert it to the desired value. This may or may not have a 
performance impact, depending on how deep objects are nested (for NSDictionarys 
for example) - in UIWebView this process is synchronous (and needs to be on the 
main thread).


> cordova-ios crash in case of Infinity value in result
> -----------------------------------------------------
>
>                 Key: CB-11737
>                 URL: https://issues.apache.org/jira/browse/CB-11737
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>            Reporter: Chris Brody
>            Assignee: Shazron Abdullah
>
> In case an iOS plugin attempts to return a JSON result with an Infinity value 
> it will crash with NSInvalidArgumentException. I discovered this when 
> investigating this issue: 
> https://github.com/litehelpers/Cordova-sqlite-storage/issues/405
> Similar to: CB-9435



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to