[TIMOB-4876] Android - "hasOwnProperty" and JSON.parse incompatible
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-08-26T09:34:48.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | Sprint 2011-33, Release 1.8.0 |
Components | Android |
Labels | hasOwnProperty, json |
Reporter | Pedro Enrique |
Assignee | Vikramjeet Singh |
Created | 2011-08-03T09:44:58.000+0000 |
Updated | 2014-06-19T12:46:22.000+0000 |
Description
The function hasOwnProperty does not work in android when using a JSON object. Reason is that the JSON object ends up having double quotes on its properties making it a stringified object.
For example, this does not work on Android:
var json = JSON.stringify({x: 1});
alert(JSON.parse(json).hasOwnProperty('x'));
If you where to alert the json alone, it would alert:
{ "x" : 1 }
This, instead, works fine:
alert( ({x: 1}).hasOwnProperty('x') );
Doublequoted keys in objects is perfectly legal in javascript and there is absolutely no reason why this should result in an object where the hasOwnProperty-method is 'undefined'.
To test this, you can simply run the
json
test suite in Drillbit, which has a new test that tests all kinds of different prototype functions for Object, String, Array, and Boolean on objects returned fromJSON.parse
.Ran drillbit with version=1.8.0 timestamp=09/12/11 15:27 githash=8169a91 All test pass
How is this fixed? By changing the runtime to v8? Or is that fixed for anybody?