Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit eaa1119

Browse files
docs(toJson): documented the Safari RangeError known issue
Closes #14221 Closes #13415
1 parent efa72a8 commit eaa1119

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Angular.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,27 @@ function toJsonReplacer(key, value) {
12331233
* @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
12341234
* If set to an integer, the JSON output will contain that many spaces per indentation.
12351235
* @returns {string|undefined} JSON-ified string representing `obj`.
1236+
* @knownIssue
1237+
*
1238+
* The Safari browser throws a `RangeError` instead of returning `null` when it tries to stringify a `Date`
1239+
* object with an invalid date value. The only reliable way to prevent this is to monkeypatch the
1240+
* `Date.prototype.toJSON` method as follows:
1241+
*
1242+
* ```
1243+
* var _DatetoJSON = Date.prototype.toJSON;
1244+
* Date.prototype.toJSON = function() {
1245+
* try {
1246+
* return _DatetoJSON.call(this);
1247+
* } catch(e) {
1248+
* if (e instanceof RangeError) {
1249+
* return null;
1250+
* }
1251+
* throw e;
1252+
* }
1253+
* };
1254+
* ```
1255+
*
1256+
* See https://github.com/angular/angular.js/pull/14221 for more information.
12361257
*/
12371258
function toJson(obj, pretty) {
12381259
if (isUndefined(obj)) return undefined;

0 commit comments

Comments
 (0)