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: 25 Nov 2002 michael@0: * SUMMARY: Calling a user-defined superconstructor michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=181914, esp. Comment 10. michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = '181914'; michael@0: var summary = 'Calling a user-defined superconstructor'; 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: // make a user-defined version of the Error constructor michael@0: function _Error(msg) michael@0: { michael@0: this.message = msg; michael@0: } michael@0: _Error.prototype = new Error(); michael@0: _Error.prototype.name = '_Error'; michael@0: michael@0: michael@0: // derive MyApplyError from _Error michael@0: function MyApplyError(msg) michael@0: { michael@0: if(this instanceof MyApplyError) michael@0: _Error.apply(this, arguments); michael@0: else michael@0: return new MyApplyError(msg); michael@0: } michael@0: MyApplyError.prototype = new _Error(); michael@0: MyApplyError.prototype.name = "MyApplyError"; michael@0: michael@0: michael@0: // derive MyCallError from _Error michael@0: function MyCallError(msg) michael@0: { michael@0: if(this instanceof MyCallError) michael@0: _Error.call(this, msg); michael@0: else michael@0: return new MyCallError(msg); michael@0: } michael@0: MyCallError.prototype = new _Error(); michael@0: MyCallError.prototype.name = "MyCallError"; michael@0: michael@0: michael@0: function otherScope(msg) michael@0: { michael@0: return MyApplyError(msg); michael@0: } michael@0: michael@0: michael@0: status = inSection(1); michael@0: var err1 = new MyApplyError('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 = new MyCallError('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 = MyApplyError('msg3'); michael@0: actual = examineThis(err3, 'msg3'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(4); michael@0: var err4 = MyCallError('msg4'); michael@0: actual = examineThis(err4, 'msg4'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(5); michael@0: var err5 = otherScope('msg5'); michael@0: actual = examineThis(err5, 'msg5'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(6); michael@0: var err6 = otherScope(); michael@0: actual = examineThis(err6, EMPTY_STRING); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(7); michael@0: var err7 = eval("MyApplyError('msg7')"); michael@0: actual = examineThis(err7, 'msg7'); michael@0: expect = EXPECTED_FORMAT; michael@0: addThis(); michael@0: michael@0: status = inSection(8); michael@0: var err8; michael@0: try michael@0: { michael@0: throw MyApplyError('msg8'); michael@0: } michael@0: catch(e) michael@0: { michael@0: if(e instanceof Error) michael@0: err8 = e; michael@0: } michael@0: actual = examineThis(err8, 'msg8'); 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: // Searches |err.toString()| for |err.name + ':' + err.message| 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: }