Permalink
Browse files

Override the native `JSON.stringify` implementation if the `Date#getU…

…TC*` methods are buggy.
  • Loading branch information...
kitcambridge committed Apr 15, 2012
1 parent 97d8344 commit da4db29fcf9b11c5cef12d3428dbae7299d3a3eb
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/json3.js
View
@@ -18,7 +18,7 @@
(function () {
var serialized = '{"result":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}', value = new Date(-3509827334573292), toJSON, original;
// The `Date#getUTC{FullYear, Month, Date}` methods return nonsensical
- // results for certain dates in Opera > 9.64.
+ // results for certain dates in Opera >= 10.54.
try {
getUTCSupported = value.getUTCFullYear() == -109252 && value.getUTCMonth() === 0 && value.getUTCDate() == 1;
} catch (exception) {}
@@ -81,8 +81,8 @@
// Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
// four-digit years instead of six-digit years. Credits: @Yaffle.
case exports.stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"':
- // Safari <= 5.1.5 incorrectly serializes millisecond values < 1000.
- // Credits: @Yaffle.
+ // Safari <= 5.1.5 and Opera >= 10.54 incorrectly serialize
+ // millisecond values less than 1000. Credits: @Yaffle.
case exports.stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"':
stringifySupported = false;
}
@@ -240,7 +240,7 @@
// object properties for serialization. The optional `width` argument may be
// either a string or number that specifies the indentation level of the
// output.
- if (!stringifySupported) {
+ if (!stringifySupported || (stringifySupported && !getUTCSupported)) {
exports.stringify = (function () {
// Maps control characters to their escaped equivalents.
var Escapes = {

0 comments on commit da4db29

Please sign in to comment.