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: * Date: 27 Nov 2002 michael@0: * SUMMARY: Ensuring normal function call of Error (ECMA-262 Ed.3 15.11.1.1). michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = ''; michael@0: var summary = 'Ensuring normal function call of Error (ECMA-262 Ed.3 15.11.1.1)'; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: var EMPTY_STRING = ''; michael@0: var EXPECTED_FORMAT = 0; michael@0: michael@0: michael@0: function otherScope(msg) michael@0: { michael@0: return Error(msg); michael@0: } michael@0: michael@0: michael@0: status = inSection(1); michael@0: var err1 = Error('msg1'); michael@0: actual = examineThis(err1, 'msg1'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(2); michael@0: var err2 = otherScope('msg2'); michael@0: actual = examineThis(err2, 'msg2'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(3); michael@0: var err3 = otherScope(); michael@0: actual = examineThis(err3, EMPTY_STRING); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(4); michael@0: var err4 = eval("Error('msg4')"); michael@0: actual = examineThis(err4, 'msg4'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: /* michael@0: * Searches err.toString() for err.name + ':' + err.message, michael@0: * with possible whitespace on each side of the colon sign. michael@0: * michael@0: * We allow for no colon in case err.message was not provided by the user. michael@0: * In such a case, SpiderMonkey and Rhino currently set err.message = '', michael@0: * as allowed for by ECMA 15.11.4.3. This makes |pattern| work in this case. michael@0: * michael@0: * If this is ever changed to a non-empty string, e.g. 'undefined', michael@0: * you may have to modify |pattern| to take that into account - michael@0: * michael@0: */ michael@0: function examineThis(err, msg) michael@0: { michael@0: var pattern = err.name + '\\s*:?\\s*' + msg; michael@0: return err.toString().search(RegExp(pattern)); michael@0: } michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[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 (var i = 0; i < UBound; i++) michael@0: { michael@0: reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }