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: 2001-07-03 michael@0: * michael@0: * SUMMARY: Testing scope with nested functions michael@0: * michael@0: * From correspondence with Christopher Oliver : michael@0: * michael@0: * > Running this test with Rhino produces the following exception: michael@0: * > michael@0: * > uncaught JavaScript exception: undefined: Cannot find default value for michael@0: * > object. (line 3) michael@0: * > michael@0: * > This is due to a bug in org.mozilla.javascript.NativeCall which doesn't michael@0: * > implement toString or valueOf or override getDefaultValue. michael@0: * > However, even after I hacked in an implementation of getDefaultValue in michael@0: * > NativeCall, Rhino still produces a different result then SpiderMonkey: michael@0: * > michael@0: * > [object Call] michael@0: * > [object Object] michael@0: * > [object Call] michael@0: * michael@0: * Note the results should be: michael@0: * michael@0: * [object global] michael@0: * [object Object] michael@0: * [object global] michael@0: * michael@0: * This is what we are checking for in this testcase - michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = '(none)'; michael@0: var summary = 'Testing scope with nested functions'; michael@0: var statprefix = 'Section '; michael@0: var statsuffix = ' of test -'; michael@0: var self = this; // capture a reference to the global object; michael@0: var cnGlobal = self.toString(); michael@0: var cnObject = (new Object).toString(); michael@0: var statusitems = []; michael@0: var actualvalues = []; michael@0: var expectedvalues = []; michael@0: michael@0: michael@0: function a() michael@0: { michael@0: function b() michael@0: { michael@0: capture(this.toString()); michael@0: } michael@0: michael@0: this.c = function() michael@0: { michael@0: capture(this.toString()); michael@0: b(); michael@0: } michael@0: michael@0: b(); michael@0: } michael@0: michael@0: michael@0: var obj = new a(); // captures actualvalues[0] michael@0: obj.c(); // captures actualvalues[1], actualvalues[2] michael@0: michael@0: michael@0: // The values we expect - see introduction above - michael@0: expectedvalues[0] = cnGlobal; michael@0: expectedvalues[1] = cnObject; michael@0: expectedvalues[2] = cnGlobal; michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function capture(val) michael@0: { michael@0: actualvalues[UBound] = val; michael@0: statusitems[UBound] = getStatus(UBound); 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