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

Commit e00f9f6

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

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

0 commit comments

Comments
 (0)