Permalink
Browse files
docs(toJson): documented the Safari RangeError known issue
- Loading branch information
Showing
with
21 additions
and
0 deletions.
-
+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; |
|
|
|