| 6885 | // Public: Initializes JSON 3 using the given `context` object, attaching the |
| 6886 | // `stringify` and `parse` functions to the specified `exports` object. |
| 6887 | function runInContext(context, exports) { |
| 6888 | context || (context = root["Object"]()); |
| 6889 | exports || (exports = root["Object"]()); |
| 6890 | |
| 6891 | // Native constructor aliases. |
| 6892 | var Number = context["Number"] || root["Number"], |
| 6893 | String = context["String"] || root["String"], |
| 6894 | Object = context["Object"] || root["Object"], |
| 6895 | Date = context["Date"] || root["Date"], |
| 6896 | SyntaxError = context["SyntaxError"] || root["SyntaxError"], |
| 6897 | TypeError = context["TypeError"] || root["TypeError"], |
| 6898 | Math = context["Math"] || root["Math"], |
| 6899 | nativeJSON = context["JSON"] || root["JSON"]; |
| 6900 | |
| 6901 | // Delegate to the native `stringify` and `parse` implementations. |
| 6902 | if (typeof nativeJSON == "object" && nativeJSON) { |
| 6903 | exports.stringify = nativeJSON.stringify; |
| 6904 | exports.parse = nativeJSON.parse; |
| 6905 | } |
| 6906 | |
| 6907 | // Convenience aliases. |
| 6908 | var objectProto = Object.prototype, |
| 6909 | getClass = objectProto.toString, |
| 6910 | isProperty, |
| 6911 | forEach, |
| 6912 | undef; |
| 6913 | |
| 6914 | // Test the `Date#getUTC*` methods. Based on work by @Yaffle. |
| 6915 | var isExtended = new Date(-3509827334573292); |
| 6916 | try { |
| 6917 | // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical |
| 6918 | // results for certain dates in Opera >= 10.53. |
| 6919 | isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 && |
| 6920 | // Safari < 2.0.2 stores the internal millisecond time value correctly, |
| 6921 | // but clips the values returned by the date methods to the range of |
| 6922 | // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]). |
| 6923 | isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708; |
| 6924 | } catch (exception) {} |
| 6925 | |
| 6926 | // Internal: Determines whether the native `JSON.stringify` and `parse` |
| 6927 | // implementations are spec-compliant. Based on work by Ken Snyder. |
| 6928 | function has(name) { |
| 6929 | if (has[name] !== undef) { |
| 6930 | // Return cached feature test result. |
| 6931 | return has[name]; |
| 6932 | } |
| 6933 | var isSupported; |
| 6934 | if (name == "bug-string-char-index") { |
| 6935 | // IE <= 7 doesn't support accessing string characters using square |
| 6936 | // bracket notation. IE 8 only supports this for primitives. |
| 6937 | isSupported = "a" [0] != "a"; |
| 6938 | } else if (name == "json") { |
| 6939 | // Indicates whether both `JSON.stringify` and `JSON.parse` are |
| 6940 | // supported. |
| 6941 | isSupported = has("json-stringify") && has("json-parse"); |
| 6942 | } else { |
| 6943 | var value, |
| 6944 | serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}'; |