Skip to content
Permalink
Browse files

docs(toJson): documented the Safari RangeError known issue

Closes #14221
Closes #13415
  • Loading branch information
petebacondarwin committed May 21, 2016
1 parent 507c666 commit e00f9f62e370e890506b2186e77b597ce8b307ce
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/Angular.js
@@ -1235,6 +1235,27 @@ function toJsonReplacer(key, value) {
* @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
* If set to an integer, the JSON output will contain that many spaces per indentation.
* @returns {string|undefined} JSON-ified string representing `obj`.
* @knownIssue
*
* The Safari browser throws a `RangeError` instead of returning `null` when it tries to stringify a `Date`
* object with an invalid date value. The only reliable way to prevent this is to monkeypatch the
* `Date.prototype.toJSON` method as follows:
*
* ```
* var _DatetoJSON = Date.prototype.toJSON;
* Date.prototype.toJSON = function() {
* try {
* return _DatetoJSON.call(this);
* } catch(e) {
* if (e instanceof RangeError) {
* return null;
* }
* throw e;
* }
* };
* ```
*
* See https://github.com/angular/angular.js/pull/14221 for more information.
*/
function toJson(obj, pretty) {
if (isUndefined(obj)) return undefined;

0 comments on commit e00f9f6

Please sign in to comment.
You can’t perform that action at this time.