main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1008 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var call = require('../internals/function-call');
|
---|
4 | var toObject = require('../internals/to-object');
|
---|
5 | var toPrimitive = require('../internals/to-primitive');
|
---|
6 | var toISOString = require('../internals/date-to-iso-string');
|
---|
7 | var classof = require('../internals/classof-raw');
|
---|
8 | var fails = require('../internals/fails');
|
---|
9 |
|
---|
10 | var FORCED = fails(function () {
|
---|
11 | return new Date(NaN).toJSON() !== null
|
---|
12 | || call(Date.prototype.toJSON, { toISOString: function () { return 1; } }) !== 1;
|
---|
13 | });
|
---|
14 |
|
---|
15 | // `Date.prototype.toJSON` method
|
---|
16 | // https://tc39.es/ecma262/#sec-date.prototype.tojson
|
---|
17 | $({ target: 'Date', proto: true, forced: FORCED }, {
|
---|
18 | // eslint-disable-next-line no-unused-vars -- required for `.length`
|
---|
19 | toJSON: function toJSON(key) {
|
---|
20 | var O = toObject(this);
|
---|
21 | var pv = toPrimitive(O, 'number');
|
---|
22 | return typeof pv == 'number' && !isFinite(pv) ? null :
|
---|
23 | (!('toISOString' in O) && classof(O) === 'Date') ? call(toISOString, O) : O.toISOString();
|
---|
24 | }
|
---|
25 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.