js/src/tests/ecma_2/Exceptions/date-001.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial