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