Add this code after prototype.js =). Also this code replaces FF 3.5
Native JSON.stringify with ES compatible...
It breaks compatibility!

delete String.prototype.toJSON; //! deleting this properties required
to save FF 3.5 Native JSON.stringify
delete Array.prototype.toJSON;  //!
delete Number.prototype.toJSON;

Hash.prototype.toJSON = function() {
  return this.toObject();
};

Date.prototype.toISOString = function() {
  return this.getUTCFullYear() + '-' +
    (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
    this.getUTCDate().toPaddedString(2) + 'T' +
    this.getUTCHours().toPaddedString(2) + ':' +
    this.getUTCMinutes().toPaddedString(2) + ':' +
    this.getUTCSeconds().toPaddedString(2) + '.' +
    this.getUTCMilliseconds().toPaddedString(3) + 'Z';
};

Date.prototype.toJSON = function(key) {
  return (Object.isNumber(this) && !isFinite(this) ? null :
this.toISOString());
};

Object.isBoolean = function(object) {
  return Object.prototype.toString.call(object) === "[object
Boolean]";
};

Object.toJSON = (function() {
  var stack, gap, propertyList, replacerFunction;

  function quote(string) {
    return String(string).inspect(true);
  }
  function str(key, holder, indent) {
    var value = holder[key];

    if (value !== null && (typeof value === 'object' || typeof value
=== 'function') && Object.isFunction(value.toJSON)) {
      value = value.toJSON(key);
    }

    if (Object.isElement(value)) { return; }

    value = replacerFunction.call(holder, key, value);

    if (value === null || Object.isBoolean(value)) {
      return String(value);
    }

    if (Object.isString(value)) {
      return quote(value);
    }

    if (Object.isNumber(value)) {
      return (isFinite(value) ? String(value) : 'null');
    }

    if (typeof value === 'object') {
      if (stack.indexOf(value) !== -1) {
        throw new TypeError();
      }
      stack.push(value);

      var partial = [],
          braces  = ['{', '}'], i, strP, length, k;

      if (Object.isArray(value)) {
        braces = ['[', ']'];
        for(i = 0, length = value.length; i < length; i++) {
          strP = str(i, value, indent + gap);
          partial.push(Object.isUndefined(strP) ? 'null' : strP);
        }
      } else {
        k = propertyList || Object.keys(value);
        for(i = 0, length = k.length; i < length; i++) {
          strP = str(k[i], value, indent + gap);
          if (!Object.isUndefined(strP)) {
            partial.push(quote(k[i]) + (gap ? ': ' : ':') + strP);
          }
        }
      }

      stack.pop();
      return braces[0] + (partial.length && gap ? '\n' + indent + gap
+ partial.join(',\n' + indent + gap) + '\n' + indent : partial.join
(','))  + braces[1];
    }
  }

  return function(value /*, replacer, space */) {
    var replacer = arguments[1],
        space    = arguments[2] || '';
    stack = [];

    replacerFunction = (Object.isFunction(replacer) ? replacer :
function(k, v) { return v; });

    if (Object.isArray(replacer)) {
      var hash = {};
      propertyList = replacer.inject([], function(array, v) {
        if ((Object.isString(v) || Object.isNumber(v)) && !
hash.hasOwnProperty(' ' + v)) {
          hash[' ' + v] = 1;
          array.push(String(v));
        }
        return array;
      });
    } else {
      propertyList = null;
    }

    if (Object.isNumber(space)) {
      space = Math.min(Math.floor(+space) || 0, 10);
      gap   = ' '.times(space);
    } else if (Object.isString(space)) {
      gap   = space.substr(0, 10);
    } else {
      gap   = '';
    }

    return str('', {'': value}, '');
  };
}());

(window.JSON = window.JSON || {}).stringify = Object.toJSON;// FF 3.5
uses diff. implementation

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

Reply via email to