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 ***** */
41 ECMA Section: 15.6.2 The Boolean Constructor
42 15.6.2.1 new Boolean( value )
43 15.6.2.2 new Boolean()
45 This test verifies that the Boolean constructor
46 initializes a new object (typeof should return
47 "object"). The prototype of the new object should
48 be Boolean.prototype. The value of the object
49 should be ToBoolean( value ) (a boolean value).
52 Author: christine@netscape.com
56 var SECTION = "15.6.2";
57 var VERSION = "ECMA_1";
59 var TITLE = "15.6.2 The Boolean Constructor; 15.6.2.1 new Boolean( value ); 15.6.2.2 new Boolean()";
61 writeHeaderToLog( SECTION + " "+ TITLE);
63 var array = new Array();
66 new TestCase( SECTION, "typeof (new Boolean(1))", "object", typeof (new Boolean(1)) );
67 new TestCase( SECTION, "(new Boolean(1)).constructor", Boolean.prototype.constructor, (new Boolean(1)).constructor );
68 new TestCase( SECTION,
69 "TESTBOOL=new Boolean(1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
71 eval("TESTBOOL=new Boolean(1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
72 new TestCase( SECTION, "(new Boolean(1)).valueOf()", true, (new Boolean(1)).valueOf() );
73 new TestCase( SECTION, "typeof new Boolean(1)", "object", typeof new Boolean(1) );
74 new TestCase( SECTION, "(new Boolean(0)).constructor", Boolean.prototype.constructor, (new Boolean(0)).constructor );
75 new TestCase( SECTION,
76 "TESTBOOL=new Boolean(0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
78 eval("TESTBOOL=new Boolean(0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
79 new TestCase( SECTION, "(new Boolean(0)).valueOf()", false, (new Boolean(0)).valueOf() );
80 new TestCase( SECTION, "typeof new Boolean(0)", "object", typeof new Boolean(0) );
81 new TestCase( SECTION, "(new Boolean(-1)).constructor", Boolean.prototype.constructor, (new Boolean(-1)).constructor );
82 new TestCase( SECTION,
83 "TESTBOOL=new Boolean(-1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
85 eval("TESTBOOL=new Boolean(-1);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
86 new TestCase( SECTION, "(new Boolean(-1)).valueOf()", true, (new Boolean(-1)).valueOf() );
87 new TestCase( SECTION, "typeof new Boolean(-1)", "object", typeof new Boolean(-1) );
88 new TestCase( SECTION, "(new Boolean('1')).constructor", Boolean.prototype.constructor, (new Boolean('1')).constructor );
89 new TestCase( SECTION,
90 "TESTBOOL=new Boolean('1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
92 eval("TESTBOOL=new Boolean('1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
93 new TestCase( SECTION, "(new Boolean('1')).valueOf()", true, (new Boolean('1')).valueOf() );
94 new TestCase( SECTION, "typeof new Boolean('1')", "object", typeof new Boolean('1') );
95 new TestCase( SECTION, "(new Boolean('0')).constructor", Boolean.prototype.constructor, (new Boolean('0')).constructor );
96 new TestCase( SECTION,
97 "TESTBOOL=new Boolean('0');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
99 eval("TESTBOOL=new Boolean('0');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
100 new TestCase( SECTION, "(new Boolean('0')).valueOf()", true, (new Boolean('0')).valueOf() );
101 new TestCase( SECTION, "typeof new Boolean('0')", "object", typeof new Boolean('0') );
102 new TestCase( SECTION, "(new Boolean('-1')).constructor", Boolean.prototype.constructor, (new Boolean('-1')).constructor );
103 new TestCase( SECTION,
104 "TESTBOOL=new Boolean('-1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
106 eval("TESTBOOL=new Boolean('-1');TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
107 new TestCase( SECTION, "(new Boolean('-1')).valueOf()", true, (new Boolean('-1')).valueOf() );
108 new TestCase( SECTION, "typeof new Boolean('-1')", "object", typeof new Boolean('-1') );
109 new TestCase( SECTION, "(new Boolean(new Boolean(true))).constructor", Boolean.prototype.constructor, (new Boolean(new Boolean(true))).constructor );
110 new TestCase( SECTION,
111 "TESTBOOL=new Boolean(new Boolean(true));TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
113 eval("TESTBOOL=new Boolean(new Boolean(true));TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
114 new TestCase( SECTION, "(new Boolean(new Boolean(true))).valueOf()", true, (new Boolean(new Boolean(true))).valueOf() );
115 new TestCase( SECTION, "typeof new Boolean(new Boolean(true))", "object", typeof new Boolean(new Boolean(true)) );
116 new TestCase( SECTION, "(new Boolean(Number.NaN)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NaN)).constructor );
117 new TestCase( SECTION,
118 "TESTBOOL=new Boolean(Number.NaN);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
120 eval("TESTBOOL=new Boolean(Number.NaN);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
121 new TestCase( SECTION, "(new Boolean(Number.NaN)).valueOf()", false, (new Boolean(Number.NaN)).valueOf() );
122 new TestCase( SECTION, "typeof new Boolean(Number.NaN)", "object", typeof new Boolean(Number.NaN) );
123 new TestCase( SECTION, "(new Boolean(null)).constructor", Boolean.prototype.constructor, (new Boolean(null)).constructor );
124 new TestCase( SECTION,
125 "TESTBOOL=new Boolean(null);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
127 eval("TESTBOOL=new Boolean(null);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
128 new TestCase( SECTION, "(new Boolean(null)).valueOf()", false, (new Boolean(null)).valueOf() );
129 new TestCase( SECTION, "typeof new Boolean(null)", "object", typeof new Boolean(null) );
130 new TestCase( SECTION, "(new Boolean(void 0)).constructor", Boolean.prototype.constructor, (new Boolean(void 0)).constructor );
131 new TestCase( SECTION,
132 "TESTBOOL=new Boolean(void 0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
134 eval("TESTBOOL=new Boolean(void 0);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
135 new TestCase( SECTION, "(new Boolean(void 0)).valueOf()", false, (new Boolean(void 0)).valueOf() );
136 new TestCase( SECTION, "typeof new Boolean(void 0)", "object", typeof new Boolean(void 0) );
137 new TestCase( SECTION, "(new Boolean(Number.POSITIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.POSITIVE_INFINITY)).constructor );
138 new TestCase( SECTION,
139 "TESTBOOL=new Boolean(Number.POSITIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
141 eval("TESTBOOL=new Boolean(Number.POSITIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
142 new TestCase( SECTION, "(new Boolean(Number.POSITIVE_INFINITY)).valueOf()", true, (new Boolean(Number.POSITIVE_INFINITY)).valueOf() );
143 new TestCase( SECTION, "typeof new Boolean(Number.POSITIVE_INFINITY)", "object", typeof new Boolean(Number.POSITIVE_INFINITY) );
144 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NEGATIVE_INFINITY)).constructor );
145 new TestCase( SECTION,
146 "TESTBOOL=new Boolean(Number.NEGATIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
148 eval("TESTBOOL=new Boolean(Number.NEGATIVE_INFINITY);TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
149 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).valueOf()", true, (new Boolean(Number.NEGATIVE_INFINITY)).valueOf() );
150 new TestCase( SECTION, "typeof new Boolean(Number.NEGATIVE_INFINITY)", "object", typeof new Boolean(Number.NEGATIVE_INFINITY) );
151 new TestCase( SECTION, "(new Boolean(Number.NEGATIVE_INFINITY)).constructor", Boolean.prototype.constructor, (new Boolean(Number.NEGATIVE_INFINITY)).constructor );
152 new TestCase( "15.6.2.2",
153 "TESTBOOL=new Boolean();TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()",
155 eval("TESTBOOL=new Boolean();TESTBOOL.toString=Object.prototype.toString;TESTBOOL.toString()") );
156 new TestCase( "15.6.2.2", "(new Boolean()).valueOf()", false, (new Boolean()).valueOf() );
157 new TestCase( "15.6.2.2", "typeof new Boolean()", "object", typeof new Boolean() );