blob: d8a504a6957cf434b0b4d7e5914d7844d743a0b1 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
Ben Murdochc5610432016-08-08 18:44:38 +010028// Flags: --allow-natives-syntax
29
30var undetectable = %GetUndetectable();
31
Steve Blocka7e24c12009-10-30 11:49:00 +000032// Number
33assertTrue(typeof 0 == 'number');
34assertTrue(typeof 0 === 'number');
Ben Murdochc5610432016-08-08 18:44:38 +010035assertFalse(typeof 0 != 'number');
36assertFalse(typeof 0 !== 'number');
Steve Blocka7e24c12009-10-30 11:49:00 +000037assertTrue(typeof 1.2 == 'number');
38assertTrue(typeof 1.2 === 'number');
Ben Murdochc5610432016-08-08 18:44:38 +010039assertFalse(typeof 1.2 != 'number');
40assertFalse(typeof 1.2 !== 'number');
41assertTrue(typeof 'x' != 'number');
42assertTrue(typeof 'x' !== 'number');
Steve Blocka7e24c12009-10-30 11:49:00 +000043assertFalse(typeof 'x' == 'number');
44assertFalse(typeof 'x' === 'number');
Ben Murdochc5610432016-08-08 18:44:38 +010045assertTrue(typeof Object() != 'number');
46assertTrue(typeof Object() !== 'number');
47assertFalse(typeof Object() == 'number');
48assertFalse(typeof Object() === 'number');
Steve Blocka7e24c12009-10-30 11:49:00 +000049
50// String
51assertTrue(typeof 'x' == 'string');
52assertTrue(typeof 'x' === 'string');
Ben Murdochc5610432016-08-08 18:44:38 +010053assertFalse(typeof 'x' != 'string');
54assertFalse(typeof 'x' !== 'string');
Steve Blocka7e24c12009-10-30 11:49:00 +000055assertTrue(typeof ('x' + 'x') == 'string');
56assertTrue(typeof ('x' + 'x') === 'string');
Ben Murdochc5610432016-08-08 18:44:38 +010057assertFalse(typeof ('x' + 'x') != 'string');
58assertFalse(typeof ('x' + 'x') !== 'string');
59assertTrue(typeof 1 != 'string');
60assertTrue(typeof 1 !== 'string');
Steve Blocka7e24c12009-10-30 11:49:00 +000061assertFalse(typeof 1 == 'string');
62assertFalse(typeof 1 === 'string');
Ben Murdochc5610432016-08-08 18:44:38 +010063assertTrue(typeof Object() != 'string');
64assertTrue(typeof Object() !== 'string');
Steve Blocka7e24c12009-10-30 11:49:00 +000065assertFalse(typeof Object() == 'string');
66assertFalse(typeof Object() === 'string');
67
68// Boolean
69assertTrue(typeof true == 'boolean');
70assertTrue(typeof true === 'boolean');
Ben Murdochc5610432016-08-08 18:44:38 +010071assertFalse(typeof true != 'boolean');
72assertFalse(typeof true !== 'boolean');
Steve Blocka7e24c12009-10-30 11:49:00 +000073assertTrue(typeof false == 'boolean');
74assertTrue(typeof false === 'boolean');
Ben Murdochc5610432016-08-08 18:44:38 +010075assertFalse(typeof false != 'boolean');
76assertFalse(typeof false !== 'boolean');
77assertTrue(typeof 1 != 'boolean');
78assertTrue(typeof 1 !== 'boolean');
Steve Blocka7e24c12009-10-30 11:49:00 +000079assertFalse(typeof 1 == 'boolean');
80assertFalse(typeof 1 === 'boolean');
Ben Murdochc5610432016-08-08 18:44:38 +010081assertTrue(typeof 'x' != 'boolean');
82assertTrue(typeof 'x' !== 'boolean');
83assertFalse(typeof 'x' == 'boolean');
84assertFalse(typeof 'x' === 'boolean');
85assertTrue(typeof Object() != 'boolean');
86assertTrue(typeof Object() !== 'boolean');
Steve Blocka7e24c12009-10-30 11:49:00 +000087assertFalse(typeof Object() == 'boolean');
88assertFalse(typeof Object() === 'boolean');
89
90// Undefined
91assertTrue(typeof void 0 == 'undefined');
92assertTrue(typeof void 0 === 'undefined');
Ben Murdochc5610432016-08-08 18:44:38 +010093assertFalse(typeof void 0 != 'undefined');
94assertFalse(typeof void 0 !== 'undefined');
95assertTrue(typeof 1 != 'undefined');
96assertTrue(typeof 1 !== 'undefined');
Steve Blocka7e24c12009-10-30 11:49:00 +000097assertFalse(typeof 1 == 'undefined');
98assertFalse(typeof 1 === 'undefined');
Ben Murdochc5610432016-08-08 18:44:38 +010099assertTrue(typeof null != 'undefined');
100assertTrue(typeof null !== 'undefined');
101assertFalse(typeof null == 'undefined');
102assertFalse(typeof null === 'undefined');
103assertTrue(typeof Object() != 'undefined');
104assertTrue(typeof Object() !== 'undefined');
Steve Blocka7e24c12009-10-30 11:49:00 +0000105assertFalse(typeof Object() == 'undefined');
106assertFalse(typeof Object() === 'undefined');
Ben Murdochc5610432016-08-08 18:44:38 +0100107assertTrue(typeof undetectable == 'undefined');
108assertTrue(typeof undetectable === 'undefined');
109assertFalse(typeof undetectable != 'undefined');
110assertFalse(typeof undetectable !== 'undefined');
Steve Blocka7e24c12009-10-30 11:49:00 +0000111
112// Function
113assertTrue(typeof Object == 'function');
114assertTrue(typeof Object === 'function');
Ben Murdochc5610432016-08-08 18:44:38 +0100115assertFalse(typeof Object != 'function');
116assertFalse(typeof Object !== 'function');
117assertTrue(typeof 1 != 'function');
118assertTrue(typeof 1 !== 'function');
Steve Blocka7e24c12009-10-30 11:49:00 +0000119assertFalse(typeof 1 == 'function');
120assertFalse(typeof 1 === 'function');
Ben Murdochc5610432016-08-08 18:44:38 +0100121assertTrue(typeof Object() != 'function');
122assertTrue(typeof Object() !== 'function');
Steve Blocka7e24c12009-10-30 11:49:00 +0000123assertFalse(typeof Object() == 'function');
124assertFalse(typeof Object() === 'function');
Ben Murdochc5610432016-08-08 18:44:38 +0100125assertTrue(typeof undetectable != 'function');
126assertTrue(typeof undetectable !== 'function');
127assertFalse(typeof undetectable == 'function');
128assertFalse(typeof undetectable === 'function');
Steve Blocka7e24c12009-10-30 11:49:00 +0000129
130// Object
131assertTrue(typeof Object() == 'object');
132assertTrue(typeof Object() === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100133assertFalse(typeof Object() != 'object');
134assertFalse(typeof Object() !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000135assertTrue(typeof new String('x') == 'object');
136assertTrue(typeof new String('x') === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100137assertFalse(typeof new String('x') != 'object');
138assertFalse(typeof new String('x') !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000139assertTrue(typeof ['x'] == 'object');
140assertTrue(typeof ['x'] === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100141assertFalse(typeof ['x'] != 'object');
142assertFalse(typeof ['x'] !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000143assertTrue(typeof null == 'object');
144assertTrue(typeof null === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100145assertFalse(typeof null != 'object');
146assertFalse(typeof null !== 'object');
147assertTrue(typeof 1 != 'object');
148assertTrue(typeof 1 !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000149assertFalse(typeof 1 == 'object');
150assertFalse(typeof 1 === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100151assertTrue(typeof 'x' != 'object');
152assertTrue(typeof 'x' !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000153assertFalse(typeof 'x' == 'object'); // bug #674753
154assertFalse(typeof 'x' === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100155assertTrue(typeof Object != 'object');
156assertTrue(typeof Object !== 'object');
Steve Blocka7e24c12009-10-30 11:49:00 +0000157assertFalse(typeof Object == 'object');
158assertFalse(typeof Object === 'object');
Ben Murdochc5610432016-08-08 18:44:38 +0100159assertTrue(typeof undetectable != 'object');
160assertTrue(typeof undetectable !== 'object');
161assertFalse(typeof undetectable == 'object');
162assertFalse(typeof undetectable === 'object');