michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: typeof_1.js michael@0: ECMA Section: 11.4.3 typeof operator michael@0: Description: typeof evaluates unary expressions: michael@0: undefined "undefined" michael@0: null "object" michael@0: Boolean "boolean" michael@0: Number "number" michael@0: String "string" michael@0: Object "object" [native, doesn't implement Call] michael@0: Object "function" [native, implements [Call]] michael@0: Object implementation dependent michael@0: [not sure how to test this] michael@0: Author: christine@netscape.com michael@0: Date: june 30, 1997 michael@0: michael@0: */ michael@0: michael@0: var SECTION = "11.4.3"; michael@0: michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = " The typeof operator"; michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, "typeof(void(0))", "undefined", typeof(void(0)) ); michael@0: new TestCase( SECTION, "typeof(null)", "object", typeof(null) ); michael@0: new TestCase( SECTION, "typeof(true)", "boolean", typeof(true) ); michael@0: new TestCase( SECTION, "typeof(false)", "boolean", typeof(false) ); michael@0: new TestCase( SECTION, "typeof(new Boolean())", "object", typeof(new Boolean()) ); michael@0: new TestCase( SECTION, "typeof(new Boolean(true))", "object", typeof(new Boolean(true)) ); michael@0: new TestCase( SECTION, "typeof(Boolean())", "boolean", typeof(Boolean()) ); michael@0: new TestCase( SECTION, "typeof(Boolean(false))", "boolean", typeof(Boolean(false)) ); michael@0: new TestCase( SECTION, "typeof(Boolean(true))", "boolean", typeof(Boolean(true)) ); michael@0: new TestCase( SECTION, "typeof(NaN)", "number", typeof(Number.NaN) ); michael@0: new TestCase( SECTION, "typeof(Infinity)", "number", typeof(Number.POSITIVE_INFINITY) ); michael@0: new TestCase( SECTION, "typeof(-Infinity)", "number", typeof(Number.NEGATIVE_INFINITY) ); michael@0: new TestCase( SECTION, "typeof(Math.PI)", "number", typeof(Math.PI) ); michael@0: new TestCase( SECTION, "typeof(0)", "number", typeof(0) ); michael@0: new TestCase( SECTION, "typeof(1)", "number", typeof(1) ); michael@0: new TestCase( SECTION, "typeof(-1)", "number", typeof(-1) ); michael@0: new TestCase( SECTION, "typeof('0')", "string", typeof("0") ); michael@0: new TestCase( SECTION, "typeof(Number())", "number", typeof(Number()) ); michael@0: new TestCase( SECTION, "typeof(Number(0))", "number", typeof(Number(0)) ); michael@0: new TestCase( SECTION, "typeof(Number(1))", "number", typeof(Number(1)) ); michael@0: new TestCase( SECTION, "typeof(Nubmer(-1))", "number", typeof(Number(-1)) ); michael@0: new TestCase( SECTION, "typeof(new Number())", "object", typeof(new Number()) ); michael@0: new TestCase( SECTION, "typeof(new Number(0))", "object", typeof(new Number(0)) ); michael@0: new TestCase( SECTION, "typeof(new Number(1))", "object", typeof(new Number(1)) ); michael@0: michael@0: // Math does not implement [[Construct]] or [[Call]] so its type is object. michael@0: michael@0: new TestCase( SECTION, "typeof(Math)", "object", typeof(Math) ); michael@0: michael@0: new TestCase( SECTION, "typeof(Number.prototype.toString)", "function", typeof(Number.prototype.toString) ); michael@0: michael@0: new TestCase( SECTION, "typeof('a string')", "string", typeof("a string") ); michael@0: new TestCase( SECTION, "typeof('')", "string", typeof("") ); michael@0: new TestCase( SECTION, "typeof(new Date())", "object", typeof(new Date()) ); michael@0: new TestCase( SECTION, "typeof(new Array(1,2,3))", "object", typeof(new Array(1,2,3)) ); michael@0: new TestCase( SECTION, "typeof(new String('string object'))", "object", typeof(new String("string object")) ); michael@0: new TestCase( SECTION, "typeof(String('string primitive'))", "string", typeof(String("string primitive")) ); michael@0: new TestCase( SECTION, "typeof(['array', 'of', 'strings'])", "object", typeof(["array", "of", "strings"]) ); michael@0: new TestCase( SECTION, "typeof(new Function())", "function", typeof( new Function() ) ); michael@0: new TestCase( SECTION, "typeof(parseInt)", "function", typeof( parseInt ) ); michael@0: new TestCase( SECTION, "typeof(test)", "function", typeof( test ) ); michael@0: new TestCase( SECTION, "typeof(String.fromCharCode)", "function", typeof( String.fromCharCode ) ); michael@0: michael@0: michael@0: test(); michael@0: