Debian Codegraph @

rhino/testsrc/doctests/date.tojson.doctest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 js> load('testsrc/doctests/util.js');
6
7 js> Date.prototype.toJSON;
8 function toJSON() { [native code for Date.toJSON, arity=1] }
9
10 js> Date.prototype.toJSON.call({
11 > valueOf: function() { return Infinity; }
12 > }, '')
13 null
14
15 js> expectError(function() {
16 > Date.prototype.toJSON.call({}, '')
17 > }, TypeError)
18
19 js> expectError(function() {
20 > Date.prototype.toJSON.call(5, '')
21 > }, TypeError)
22
23 js> expectError(function() {
24 > Date.prototype.toJSON.call({toISOString:5}, '')
25 > }, TypeError)
26
27 js> expectError(function() {
28 > Date.prototype.toJSON.call({toISOString:function(){ return [] }}, '')
29 > }, TypeError)
30
31 js> Date.prototype.toJSON.call({toISOString: function() { return 'w00t' }}, '')
32 w00t
33
34 js> var now = new Date()
35 js> now.toJSON('') === now.toISOString()
36 true
37