]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /** |
2 | File Name: date-003.js | |
3 | Corresponds To 15.9.5.3-1.js | |
4 | ECMA Section: 15.9.5.3-1 Date.prototype.valueOf | |
5 | Description: | |
6 | ||
7 | The valueOf function returns a number, which is this time value. | |
8 | ||
9 | The valueOf function is not generic; it generates a runtime error if | |
10 | its this value is not a Date object. Therefore it cannot be transferred | |
11 | to other kinds of objects for use as a method. | |
12 | ||
13 | Author: christine@netscape.com | |
14 | Date: 12 november 1997 | |
15 | */ | |
16 | var SECTION = "date-003"; | |
17 | var VERSION = "JS1_4"; | |
18 | var TITLE = "Date.prototype.valueOf"; | |
19 | ||
20 | startTest(); | |
21 | writeHeaderToLog( SECTION + " "+ TITLE); | |
22 | ||
23 | var tc = 0; | |
24 | var testcases = new Array(); | |
25 | ||
26 | var result = "Failed"; | |
27 | var exception = "No exception thrown"; | |
28 | var expect = "Passed"; | |
29 | ||
30 | try { | |
31 | var OBJ = new MyObject( new Date(0) ); | |
32 | result = OBJ.valueOf(); | |
33 | } catch ( e ) { | |
34 | result = expect; | |
35 | exception = e.toString(); | |
36 | } | |
37 | ||
38 | testcases[tc++] = new TestCase( | |
39 | SECTION, | |
40 | "OBJ = new MyObject( new Date(0)); OBJ.valueOf()" + | |
41 | " (threw " + exception +")", | |
42 | expect, | |
43 | result ); | |
44 | ||
45 | test(); | |
46 | ||
47 | function MyObject( value ) { | |
48 | this.value = value; | |
49 | this.valueOf = Date.prototype.valueOf; | |
50 | // The following line causes an infinte loop | |
51 | // this.toString = new Function( "return this+\"\";"); | |
52 | return this; | |
53 | } |