| 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 = '15.9.5.3-1-n.js'; |
| 7 | |
| 8 | /** |
| 9 | File Name: 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: [email protected] |
| 20 | Date: 12 november 1997 |
| 21 | */ |
| 22 | |
| 23 | var SECTION = "15.9.5.3-1-n"; |
| 24 | var VERSION = "ECMA_1"; |
| 25 | startTest(); |
| 26 | var TITLE = "Date.prototype.valueOf"; |
| 27 | |
| 28 | writeHeaderToLog( SECTION + " "+ TITLE); |
| 29 | |
| 30 | var OBJ = new MyObject( new Date(0) ); |
| 31 | |
| 32 | DESCRIPTION = "var OBJ = new MyObject( new Date(0) ); OBJ.valueOf()"; |
| 33 | EXPECTED = "error"; |
| 34 | |
| 35 | new TestCase( SECTION, |
| 36 | "var OBJ = new MyObject( new Date(0) ); OBJ.valueOf()", |
| 37 | "error", |
| 38 | eval("OBJ.valueOf()") ); |
| 39 | test(); |
| 40 | |
| 41 | function MyObject( value ) { |
| 42 | this.value = value; |
| 43 | this.valueOf = Date.prototype.valueOf; |
| 44 | // The following line causes an infinte loop |
| 45 | // this.toString = new Function( "return this+\"\";"); |
| 46 | return this; |
| 47 | } |