Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Expressions / 11.4.3.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
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.
22  *
23  * Contributor(s):
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          typeof_1.js
42    ECMA Section:       11.4.3 typeof operator
43    Description:        typeof evaluates unary expressions:
44    undefined   "undefined"
45    null        "object"
46    Boolean     "boolean"
47    Number      "number"
48    String      "string"
49    Object      "object" [native, doesn't implement Call]
50    Object      "function" [native, implements [Call]]
51    Object      implementation dependent
52    [not sure how to test this]
53    Author:             christine@netscape.com
54    Date:               june 30, 1997
55
56 */
57
58 var SECTION = "11.4.3";
59
60 var VERSION = "ECMA_1";
61 startTest();
62 var TITLE   = " The typeof operator";
63 writeHeaderToLog( SECTION + " "+ TITLE);
64
65 new TestCase( SECTION,     "typeof(void(0))",              "undefined",        typeof(void(0)) );
66 new TestCase( SECTION,     "typeof(null)",                 "object",           typeof(null) );
67 new TestCase( SECTION,     "typeof(true)",                 "boolean",          typeof(true) );
68 new TestCase( SECTION,     "typeof(false)",                "boolean",          typeof(false) );
69 new TestCase( SECTION,     "typeof(new Boolean())",        "object",           typeof(new Boolean()) );
70 new TestCase( SECTION,     "typeof(new Boolean(true))",    "object",           typeof(new Boolean(true)) );
71 new TestCase( SECTION,     "typeof(Boolean())",            "boolean",          typeof(Boolean()) );
72 new TestCase( SECTION,     "typeof(Boolean(false))",       "boolean",          typeof(Boolean(false)) );
73 new TestCase( SECTION,     "typeof(Boolean(true))",        "boolean",          typeof(Boolean(true)) );
74 new TestCase( SECTION,     "typeof(NaN)",                  "number",           typeof(Number.NaN) );
75 new TestCase( SECTION,     "typeof(Infinity)",             "number",           typeof(Number.POSITIVE_INFINITY) );
76 new TestCase( SECTION,     "typeof(-Infinity)",            "number",           typeof(Number.NEGATIVE_INFINITY) );
77 new TestCase( SECTION,     "typeof(Math.PI)",              "number",           typeof(Math.PI) );
78 new TestCase( SECTION,     "typeof(0)",                    "number",           typeof(0) );
79 new TestCase( SECTION,     "typeof(1)",                    "number",           typeof(1) );
80 new TestCase( SECTION,     "typeof(-1)",                   "number",           typeof(-1) );
81 new TestCase( SECTION,     "typeof('0')",                  "string",           typeof("0") );
82 new TestCase( SECTION,     "typeof(Number())",             "number",           typeof(Number()) );
83 new TestCase( SECTION,     "typeof(Number(0))",            "number",           typeof(Number(0)) );
84 new TestCase( SECTION,     "typeof(Number(1))",            "number",           typeof(Number(1)) );
85 new TestCase( SECTION,     "typeof(Nubmer(-1))",           "number",           typeof(Number(-1)) );
86 new TestCase( SECTION,     "typeof(new Number())",         "object",           typeof(new Number()) );
87 new TestCase( SECTION,     "typeof(new Number(0))",        "object",           typeof(new Number(0)) );
88 new TestCase( SECTION,     "typeof(new Number(1))",        "object",           typeof(new Number(1)) );
89
90 // Math does not implement [[Construct]] or [[Call]] so its type is object.
91
92 new TestCase( SECTION,     "typeof(Math)",                 "object",         typeof(Math) );
93
94 new TestCase( SECTION,     "typeof(Number.prototype.toString)", "function",    typeof(Number.prototype.toString) );
95
96 new TestCase( SECTION,     "typeof('a string')",           "string",           typeof("a string") );
97 new TestCase( SECTION,     "typeof('')",                   "string",           typeof("") );
98 new TestCase( SECTION,     "typeof(new Date())",           "object",           typeof(new Date()) );
99 new TestCase( SECTION,     "typeof(new Array(1,2,3))",     "object",           typeof(new Array(1,2,3)) );
100 new TestCase( SECTION,     "typeof(new String('string object'))",  "object",   typeof(new String("string object")) );
101 new TestCase( SECTION,     "typeof(String('string primitive'))",    "string",  typeof(String("string primitive")) );
102 new TestCase( SECTION,     "typeof(['array', 'of', 'strings'])",   "object",   typeof(["array", "of", "strings"]) );
103 new TestCase( SECTION,     "typeof(new Function())",                "function",     typeof( new Function() ) );
104 new TestCase( SECTION,     "typeof(parseInt)",                      "function",     typeof( parseInt ) );
105 new TestCase( SECTION,     "typeof(test)",                          "function",     typeof( test ) );
106 new TestCase( SECTION,     "typeof(String.fromCharCode)",           "function",     typeof( String.fromCharCode )  );
107
108
109 test();
110