Debian Codegraph @

rhino/testsrc/tests/ecma_2/Exceptions/date-001.js

raw symbols SCIP
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-001.js';
7
8 /**
9 File Name: date-001.js
10 Corresponds To: 15.9.5.2-2.js
11 ECMA Section: 15.9.5.2 Date.prototype.toString
12 Description:
13 This function returns a string value. The contents of the string are
14 implementation dependent, but are intended to represent the Date in a
15 convenient, human-readable form in the current time zone.
16
17 The toString function is not generic; it generates a runtime error if its
18 this value is not a Date object. Therefore it cannot be transferred to
19 other kinds of objects for use as a method.
20
21
22 This verifies that calling toString on an object that is not a string
23 generates a runtime error.
24
25 Author: [email protected]
26 Date: 12 november 1997
27 */
28 var SECTION = "date-001";
29 var VERSION = "JS1_4";
30 var TITLE = "Date.prototype.toString";
31
32 startTest();
33 writeHeaderToLog( SECTION + " "+ TITLE);
34
35 var result = "Failed";
36 var exception = "No exception thrown";
37 var expect = "Passed";
38
39 try {
40 var OBJ = new MyObject( new Date(0) );
41 result = OBJ.toString();
42 } catch ( e ) {
43 result = expect;
44 exception = e.toString();
45 }
46
47 new TestCase(
48 SECTION,
49 "OBJECT = new MyObject( new Date(0)) ; result = OBJ.toString()" +
50 " (threw " + exception +")",
51 expect,
52 result );
53
54 test();
55
56 function MyObject( value ) {
57 this.value = value;
58 this.valueOf = new Function( "return this.value" );
59 this.toString = Date.prototype.toString;
60 return this;
61 }