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: 13 Oct 2003 michael@0: * SUMMARY: Make our f.caller property match IE's wrt f.apply and f.call michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=222029 michael@0: * michael@0: * Below, when gg calls f via |f.call|, we have this call chain: michael@0: * michael@0: * calls calls michael@0: * gg() ---------> Function.prototype.call() ---------> f() michael@0: * michael@0: * michael@0: * The question this bug addresses is, "What should we say |f.caller| is?" michael@0: * michael@0: * Before this fix, SpiderMonkey said it was |Function.prototype.call|. michael@0: * After this fix, SpiderMonkey emulates IE and says |gg| instead. michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 222029; michael@0: var summary = "Make our f.caller property match IE's wrt f.apply and f.call"; 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: michael@0: michael@0: function f() michael@0: { michael@0: return f.caller.p ; michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Call |f| directly michael@0: */ michael@0: function g() michael@0: { michael@0: return f(); michael@0: } michael@0: g.p = "hello"; michael@0: michael@0: michael@0: /* michael@0: * Call |f| via |f.call| michael@0: */ michael@0: function gg() michael@0: { michael@0: return f.call(this); michael@0: } michael@0: gg.p = "hello"; michael@0: michael@0: michael@0: /* michael@0: * Call |f| via |f.apply| michael@0: */ michael@0: function ggg() michael@0: { michael@0: return f.apply(this); michael@0: } michael@0: ggg.p = "hello"; michael@0: michael@0: michael@0: /* michael@0: * Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|. michael@0: * In Sections 2 and 3 below, we no longer expect to recover this value - michael@0: */ michael@0: Function.prototype.call.p = "goodbye"; michael@0: Function.prototype.apply.p = "goodbye"; michael@0: michael@0: michael@0: michael@0: status = inSection(1); michael@0: actual = g(); michael@0: expect = "hello"; michael@0: addThis(); michael@0: michael@0: status = inSection(2); michael@0: actual = gg(); michael@0: expect = "hello"; michael@0: addThis(); michael@0: michael@0: status = inSection(3); michael@0: actual = ggg(); michael@0: expect = "hello"; michael@0: addThis(); michael@0: 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: 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