es6.date.to-json.js 729 B

12345678910111213141516171819
  1. 'use strict';
  2. var $export = require('./_export');
  3. var toObject = require('./_to-object');
  4. var toPrimitive = require('./_to-primitive');
  5. var toISOString = require('./_date-to-iso-string');
  6. var classof = require('./_classof');
  7. $export($export.P + $export.F * require('./_fails')(function () {
  8. return new Date(NaN).toJSON() !== null
  9. || Date.prototype.toJSON.call({ toISOString: function () { return 1; } }) !== 1;
  10. }), 'Date', {
  11. // eslint-disable-next-line no-unused-vars
  12. toJSON: function toJSON(key) {
  13. var O = toObject(this);
  14. var pv = toPrimitive(O);
  15. return typeof pv == 'number' && !isFinite(pv) ? null :
  16. (!('toISOString' in O) && classof(O) == 'Date') ? toISOString.call(O) : O.toISOString();
  17. }
  18. });