(name)
| 76 | // Internal: Determines whether the native `JSON.stringify` and `parse` |
| 77 | // implementations are spec-compliant. Based on work by Ken Snyder. |
| 78 | function has(name) { |
| 79 | if (has[name] != null) { |
| 80 | // Return cached feature test result. |
| 81 | return has[name]; |
| 82 | } |
| 83 | var isSupported; |
| 84 | if (name == "bug-string-char-index") { |
| 85 | // IE <= 7 doesn't support accessing string characters using square |
| 86 | // bracket notation. IE 8 only supports this for primitives. |
| 87 | isSupported = "a"[0] != "a"; |
| 88 | } else if (name == "json") { |
| 89 | // Indicates whether both `JSON.stringify` and `JSON.parse` are |
| 90 | // supported. |
| 91 | isSupported = has("json-stringify") && has("date-serialization") && has("json-parse"); |
| 92 | } else if (name == "date-serialization") { |
| 93 | // Indicates whether `Date`s can be serialized accurately by `JSON.stringify`. |
| 94 | isSupported = has("json-stringify") && isExtended; |
| 95 | if (isSupported) { |
| 96 | var stringify = exports.stringify; |
| 97 | attempt(function () { |
| 98 | isSupported = |
| 99 | // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly |
| 100 | // serialize extended years. |
| 101 | stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' && |
| 102 | // The milliseconds are optional in ES 5, but required in 5.1. |
| 103 | stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' && |
| 104 | // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative |
| 105 | // four-digit years instead of six-digit years. Credits: @Yaffle. |
| 106 | stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' && |
| 107 | // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond |
| 108 | // values less than 1000. Credits: @Yaffle. |
| 109 | stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"'; |
| 110 | }); |
| 111 | } |
| 112 | } else { |
| 113 | var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}'; |
| 114 | // Test `JSON.stringify`. |
| 115 | if (name == "json-stringify") { |
| 116 | var stringify = exports.stringify, stringifySupported = typeof stringify == "function"; |
| 117 | if (stringifySupported) { |
| 118 | // A test function object with a custom `toJSON` method. |
| 119 | (value = function () { |
| 120 | return 1; |
| 121 | }).toJSON = value; |
| 122 | attempt(function () { |
| 123 | stringifySupported = |
| 124 | // Firefox 3.1b1 and b2 serialize string, number, and boolean |
| 125 | // primitives as object literals. |
| 126 | stringify(0) === "0" && |
| 127 | // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object |
| 128 | // literals. |
| 129 | stringify(new Number()) === "0" && |
| 130 | stringify(new String()) == '""' && |
| 131 | // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or |
| 132 | // does not define a canonical JSON representation (this applies to |
| 133 | // objects with `toJSON` properties as well, *unless* they are nested |
| 134 | // within an object or array). |
| 135 | stringify(getClass) === undefined && |
no test coverage detected