|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: date-003.js |
|
9 Corresponds To 15.9.5.3-1.js |
|
10 ECMA Section: 15.9.5.3-1 Date.prototype.valueOf |
|
11 Description: |
|
12 |
|
13 The valueOf function returns a number, which is this time value. |
|
14 |
|
15 The valueOf function is not generic; it generates a runtime error if |
|
16 its this value is not a Date object. Therefore it cannot be transferred |
|
17 to other kinds of objects for use as a method. |
|
18 |
|
19 Author: christine@netscape.com |
|
20 Date: 12 november 1997 |
|
21 */ |
|
22 var SECTION = "date-003"; |
|
23 var VERSION = "JS1_4"; |
|
24 var TITLE = "Date.prototype.valueOf"; |
|
25 |
|
26 startTest(); |
|
27 writeHeaderToLog( SECTION + " "+ TITLE); |
|
28 |
|
29 var result = "Failed"; |
|
30 var exception = "No exception thrown"; |
|
31 var expect = "Passed"; |
|
32 |
|
33 try { |
|
34 var OBJ = new MyObject( new Date(0) ); |
|
35 result = OBJ.valueOf(); |
|
36 } catch ( e ) { |
|
37 result = expect; |
|
38 exception = e.toString(); |
|
39 } |
|
40 |
|
41 new TestCase( |
|
42 SECTION, |
|
43 "OBJ = new MyObject( new Date(0)); OBJ.valueOf()" + |
|
44 " (threw " + exception +")", |
|
45 expect, |
|
46 result ); |
|
47 |
|
48 test(); |
|
49 |
|
50 function MyObject( value ) { |
|
51 this.value = value; |
|
52 this.valueOf = Date.prototype.valueOf; |
|
53 // The following line causes an infinte loop |
|
54 // this.toString = new Function( "return this+\"\";"); |
|
55 return this; |
|
56 } |