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: * Date: 14 Mar 2001 michael@0: * michael@0: * SUMMARY: Testing the internal [[Class]] property of objects michael@0: * See ECMA-262 Edition 3 13-Oct-1999, Section 8.6.2 michael@0: * michael@0: * The getJSClass() function we use is in a utility file, e.g. "shell.js". michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var i = 0; michael@0: var UBound = 0; michael@0: var BUGNUMBER = '(none)'; michael@0: var summary = 'Testing the internal [[Class]] property of objects'; michael@0: var statprefix = 'Current object is: '; michael@0: var status = ''; var statusList = [ ]; michael@0: var actual = ''; var actualvalue = [ ]; michael@0: var expect= ''; var expectedvalue = [ ]; michael@0: michael@0: michael@0: status = 'the global object'; michael@0: actual = getJSClass(this); michael@0: expect = GLOBAL; michael@0: if (expect == 'Window' && actual == 'XPCCrossOriginWrapper') michael@0: { michael@0: print('Skipping global object due to XPCCrossOriginWrapper. See bug 390946'); michael@0: } michael@0: else michael@0: { michael@0: addThis(); michael@0: } michael@0: michael@0: status = 'new Object()'; michael@0: actual = getJSClass(new Object()); michael@0: expect = 'Object'; michael@0: addThis(); michael@0: michael@0: status = 'new Function()'; michael@0: actual = getJSClass(new Function()); michael@0: expect = 'Function'; michael@0: addThis(); michael@0: michael@0: status = 'new Array()'; michael@0: actual = getJSClass(new Array()); michael@0: expect = 'Array'; michael@0: addThis(); michael@0: michael@0: status = 'new String()'; michael@0: actual = getJSClass(new String()); michael@0: expect = 'String'; michael@0: addThis(); michael@0: michael@0: status = 'new Boolean()'; michael@0: actual = getJSClass(new Boolean()); michael@0: expect = 'Boolean'; michael@0: addThis(); michael@0: michael@0: status = 'new Number()'; michael@0: actual = getJSClass(new Number()); michael@0: expect = 'Number'; michael@0: addThis(); michael@0: michael@0: status = 'Math'; michael@0: actual = getJSClass(Math); // can't use 'new' with the Math object (EMCA3, 15.8) michael@0: expect = 'Math'; michael@0: addThis(); michael@0: michael@0: status = 'new Date()'; michael@0: actual = getJSClass(new Date()); michael@0: expect = 'Date'; michael@0: addThis(); michael@0: michael@0: status = 'new RegExp()'; michael@0: actual = getJSClass(new RegExp()); michael@0: expect = 'RegExp'; michael@0: addThis(); michael@0: michael@0: status = 'new Error()'; michael@0: actual = getJSClass(new Error()); michael@0: expect = 'Error'; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------------------- michael@0: test(); michael@0: //--------------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusList[UBound] = status; michael@0: actualvalue[UBound] = actual; michael@0: expectedvalue[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (i = 0; i < UBound; i++) michael@0: { michael@0: reportCompare(expectedvalue[i], actualvalue[i], getStatus(i)); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: } michael@0: michael@0: michael@0: function getStatus(i) michael@0: { michael@0: return statprefix + statusList[i]; michael@0: }