Author: johnh
Date: Sat Apr 30 01:43:16 2011
New Revision: 1098034

URL: http://svn.apache.org/viewvc?rev=1098034&view=rev
Log:
Fix gadgets.json to be able to coexist with prototype.js or any other toJSON 
overriding lib.


Modified:
    shindig/trunk/features/src/main/javascript/features/core.json/json-native.js

Modified: 
shindig/trunk/features/src/main/javascript/features/core.json/json-native.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.json/json-native.js?rev=1098034&r1=1098033&r2=1098034&view=diff
==============================================================================
--- 
shindig/trunk/features/src/main/javascript/features/core.json/json-native.js 
(original)
+++ 
shindig/trunk/features/src/main/javascript/features/core.json/json-native.js 
Sat Apr 30 01:43:16 2011
@@ -43,6 +43,12 @@ if (window.JSON && window.JSON.parse && 
   // JSON says to throw on parse errors and to support filtering functions. OS 
does not.
   gadgets.json = (function() {
     var endsWith___ = /___$/;
+
+    function getOrigValue(key, value) {
+      var origValue = this[key];
+      return origValue;
+    }
+
     return {
       /* documented below */
       parse: function(str) {
@@ -54,8 +60,14 @@ if (window.JSON && window.JSON.parse && 
       },
       /* documented below */
       stringify: function(obj) {
+        var orig = window.JSON.stringify;
+        function patchedStringify(val) {
+          return orig.call(this, val, getOrigValue);
+        }
+        var stringifyFn = (Array.prototype.toJSON && orig([{x:1}]) === 
"\"[{\\\"x\\\": 1}]\"") ?
+            patchedStringify : orig;
         try {
-          return window.JSON.stringify(obj, function(k,v) {
+          return stringifyFn(obj, function(k,v) {
             return !endsWith___.test(k) ? v : null;
           });
         } catch (e) {


Reply via email to