1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Exceptions/date-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: date-001.js 1.12 + Corresponds To: 15.9.5.2-2.js 1.13 + ECMA Section: 15.9.5.2 Date.prototype.toString 1.14 + Description: 1.15 + This function returns a string value. The contents of the string are 1.16 + implementation dependent, but are intended to represent the Date in a 1.17 + convenient, human-readable form in the current time zone. 1.18 + 1.19 + The toString function is not generic; it generates a runtime error if its 1.20 + this value is not a Date object. Therefore it cannot be transferred to 1.21 + other kinds of objects for use as a method. 1.22 + 1.23 + 1.24 + This verifies that calling toString on an object that is not a string 1.25 + generates a runtime error. 1.26 + 1.27 + Author: christine@netscape.com 1.28 + Date: 12 november 1997 1.29 +*/ 1.30 +var SECTION = "date-001"; 1.31 +var VERSION = "JS1_4"; 1.32 +var TITLE = "Date.prototype.toString"; 1.33 + 1.34 +startTest(); 1.35 +writeHeaderToLog( SECTION + " "+ TITLE); 1.36 + 1.37 +var result = "Failed"; 1.38 +var exception = "No exception thrown"; 1.39 +var expect = "Passed"; 1.40 + 1.41 +try { 1.42 + var OBJ = new MyObject( new Date(0) ); 1.43 + result = OBJ.toString(); 1.44 +} catch ( e ) { 1.45 + result = expect; 1.46 + exception = e.toString(); 1.47 +} 1.48 + 1.49 +new TestCase( 1.50 + SECTION, 1.51 + "OBJECT = new MyObject( new Date(0)) ; result = OBJ.toString()" + 1.52 + " (threw " + exception +")", 1.53 + expect, 1.54 + result ); 1.55 + 1.56 +test(); 1.57 + 1.58 +function MyObject( value ) { 1.59 + this.value = value; 1.60 + this.valueOf = new Function( "return this.value" ); 1.61 + this.toString = Date.prototype.toString; 1.62 + return this; 1.63 +}