• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15assert (Date.length == 7);
16
17var d;
18
19try
20{
21  d = new Date({toString: function() { throw new Error("foo"); }});
22  assert (false);
23}
24catch (e)
25{
26  assert (e instanceof Error);
27  assert (e.message === "foo");
28}
29
30d = new Date("abcd");
31assert (isNaN(d.valueOf()));
32
33d = new Date();
34assert (!isNaN(d.valueOf()));
35
36d = new Date("2015-01-01");
37assert (d.valueOf() == 1420070400000);
38
39d = new Date(1420070400000);
40assert (d.valueOf() == 1420070400000);
41
42d = new Date(2015,0,1,0,0,0,0);
43assert (d.valueOf() - (d.getTimezoneOffset() * 60000) == 1420070400000);
44
45d = new Date(8.64e+15);
46assert (d.valueOf() == 8.64e+15);
47
48d = new Date(8.64e+15 + 1);
49assert (isNaN(d.valueOf()));
50
51d = new Date(20000000, 0, 1);
52assert (isNaN(d.valueOf()));
53
54d = new Date(0, 20000000, 1);
55assert (isNaN(d.valueOf()));
56
57var Obj = function (val)
58{
59  this.value = val;
60  this.valueOf = function () { throw new ReferenceError ("valueOf-" + this.value); };
61  this.toString = function () { throw new ReferenceError ("toString-"+ this.value); };
62};
63
64try
65{
66  d = new Date (new Obj (1), new Obj (2));
67  // Should not be reached.
68  assert (false);
69}
70catch (e)
71{
72  assert (e instanceof ReferenceError);
73  assert (e.message === "valueOf-1");
74}
75
76assert (typeof Date (2015) == "string");
77assert (typeof Date() != typeof (new Date ()));
78assert (Date (Number.NaN) == Date ());
79