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