1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 ECMA Section: 15.6.2 The Boolean Constructor
43 15.6.2.1 new Boolean( value )
44 15.6.2.2 new Boolean()
46 This test verifies that the Boolean constructor
47 initializes a new object (typeof should return
48 "object"). The prototype of the new object should
49 be Boolean.prototype. The value of the object
50 should be ToBoolean( value ) (a boolean value).
53 Author: christine@netscape.com
57 var SECTION = "15.6.2";
58 var VERSION = "ECMA_1";
60 var TITLE = "15.6.2 The Boolean Constructor; 15.6.2.1 new Boolean( value ); 15.6.2.2 new Boolean()";
62 writeHeaderToLog( SECTION + " "+ TITLE);
64 var array = new Array();
67 new TestCase( SECTION, "typeof (new Boolean(1))", "object", typeof (new Boolean(1)) );
68 new TestCase( SECTION, "(new Boolean(1)).constructor", Boolean.prototype.constructor, (new Boolean(1)).constructor );
69 new TestCase( SECTION,
70 "TESTBOOL=new Boolean(1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
72 eval("TESTBOOL=new Boolean(1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
73 new TestCase( SECTION, "(new Boolean(1)).valueOf()", true, (new Boolean(1)).valueOf() );
74 new TestCase( SECTION, "typeof new Boolean(1)", "object", typeof new Boolean(1) );
75 new TestCase( SECTION, "(new Boolean(0)).constructor", Boolean.prototype.constructor, (new Boolean(0)).constructor );
76 new TestCase( SECTION,
77 "TESTBOOL=new Boolean(0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
79 eval("TESTBOOL=new Boolean(0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
80 new TestCase( SECTION, "(new Boolean(0)).valueOf()", false, (new Boolean(0)).valueOf() );
81 new TestCase( SECTION, "typeof new Boolean(0)", "object", typeof new Boolean(0) );
82 new TestCase( SECTION, "(new Boolean(-1)).constructor", Boolean.prototype.constructor, (new Boolean(-1)).constructor );
83 new TestCase( SECTION,
84 "TESTBOOL=new Boolean(-1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
86 eval("TESTBOOL=new Boolean(-1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
87 new TestCase( SECTION, "(new Boolean(-1)).valueOf()", true, (new Boolean(-1)).valueOf() );
88 new TestCase( SECTION, "typeof new Boolean(-1)", "object", typeof new Boolean(-1) );
89 new TestCase( SECTION, "(new Boolean('1')).constructor", Boolean.prototype.constructor, (new Boolean('1')).constructor );
90 new TestCase( SECTION,
91 "TESTBOOL=new Boolean('1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
93 eval("TESTBOOL=new Boolean('1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
94 new TestCase( SECTION, "(new Boolean('1')).valueOf()", true, (new Boolean('1')).valueOf() );
95 new TestCase( SECTION, "typeof new Boolean('1')", "object", typeof new Boolean('1') );
96 new TestCase( SECTION, "(new Boolean('0')).constructor", Boolean.prototype.constructor, (new Boolean('0')).constructor );
97 new TestCase( SECTION,
98 "TESTBOOL=new Boolean('0');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
100 eval("TESTBOOL=new Boolean('0');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
101 new TestCase( SECTION, "(new Boolean('0')).valueOf()", true, (new Boolean('0')).valueOf() );
102 new TestCase( SECTION, "typeof new Boolean('0')", "object", typeof new Boolean('0') );
103 new TestCase( SECTION, "(new Boolean('-1')).constructor", Boolean.prototype.constructor, (new Boolean('-1')).constructor );
104 new TestCase( SECTION,
105 "TESTBOOL=new Boolean('-1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
107 eval("TESTBOOL=new Boolean('-1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
108 new TestCase( SECTION, "(new Boolean('-1')).valueOf()", true, (new Boolean('-1')).valueOf() );
109 new TestCase( SECTION, "typeof new Boolean('-1')", "object", typeof new Boolean('-1') );
110 new TestCase( SECTION, "(new Boolean(new Boolean(true))).constructor", Boolean.prototype.constructor, (new Boolean(new Boolean(true))).constructor );
111 new TestCase( SECTION,
112 "TESTBOOL=new Boolean(new Boolean(true));TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
114 eval("TESTBOOL=new Boolean(new Boolean(true));TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
115 new TestCase( SECTION, "(new Boolean(new Boolean(true))).valueOf()", true, (new Boolean(new Boolean(true))).valueOf() );
116 new TestCase( SECTION, "typeof new Boolean(new Boolean(true))", "object", typeof new Boolean(new Boolean(true)) );
117 new TestCase( SECTION, "(new Boolean(Number.NaN)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NaN)).constructor );
118 new TestCase( SECTION,
119 "TESTBOOL=new Boolean(Number.NaN);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
121 eval("TESTBOOL=new Boolean(Number.NaN);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
122 new TestCase( SECTION, "(new Boolean(Number.NaN)).valueOf()", false, (new Boolean(Number.NaN)).valueOf() );
123 new TestCase( SECTION, "typeof new Boolean(Number.NaN)", "object", typeof new Boolean(Number.NaN) );
124 new TestCase( SECTION, "(new Boolean(null)).constructor", Boolean.prototype.constructor, (new Boolean(null)).constructor );
125 new TestCase( SECTION,
126 "TESTBOOL=new Boolean(null);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
128 eval("TESTBOOL=new Boolean(null);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
129 new TestCase( SECTION, "(new Boolean(null)).valueOf()", false, (new Boolean(null)).valueOf() );
130 new TestCase( SECTION, "typeof new Boolean(null)", "object", typeof new Boolean(null) );
131 new TestCase( SECTION, "(new Boolean(void 0)).constructor", Boolean.prototype.constructor, (new Boolean(void 0)).constructor );
132 new TestCase( SECTION,
133 "TESTBOOL=new Boolean(void 0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
135 eval("TESTBOOL=new Boolean(void 0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
136 new TestCase( SECTION, "(new Boolean(void 0)).valueOf()", false, (new Boolean(void 0)).valueOf() );
137 new TestCase( SECTION, "typeof new Boolean(void 0)", "object", typeof new Boolean(void 0) );
138 new TestCase( SECTION, "(new Boolean(Number.POSITIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.POSITIVE_INFINITY)).constructor );
139 new TestCase( SECTION,
140 "TESTBOOL=new Boolean(Number.POSITIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
142 eval("TESTBOOL=new Boolean(Number.POSITIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
143 new TestCase( SECTION, "(new Boolean(Number.POSITIVE_INFINITY)).valueOf()", true, (new Boolean(Number.POSITIVE_INFINITY)).valueOf() );
144 new TestCase( SECTION, "typeof new Boolean(Number.POSITIVE_INFINITY)", "object", typeof new Boolean(Number.POSITIVE_INFINITY) );
145 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NEGATIVE_INFINITY)).constructor );
146 new TestCase( SECTION,
147 "TESTBOOL=new Boolean(Number.NEGATIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
149 eval("TESTBOOL=new Boolean(Number.NEGATIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
150 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).valueOf()", true, (new Boolean(Number.NEGATIVE_INFINITY)).valueOf() );
151 new TestCase( SECTION, "typeof new Boolean(Number.NEGATIVE_INFINITY)", "object", typeof new Boolean(Number.NEGATIVE_INFINITY) );
152 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NEGATIVE_INFINITY)).constructor );
153 new TestCase( "15.6.2.2",
154 "TESTBOOL=new Boolean();TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
156 eval("TESTBOOL=new Boolean();TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
157 new TestCase( "15.6.2.2", "(new Boolean()).valueOf()", false, (new Boolean()).valueOf() );
158 new TestCase( "15.6.2.2", "typeof new Boolean()", "object", typeof new Boolean() );