| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
/* |
| 7 |
* |
| 8 |
* Date: 13 Oct 2003 |
| 9 |
* SUMMARY: Make our f.caller property match IE's wrt f.apply and f.call |
| 10 |
* See http://bugzilla.mozilla.org/show_bug.cgi?id=222029 |
| 11 |
* |
| 12 |
* Below, when gg calls f via |f.call|, we have this call chain: |
| 13 |
* |
| 14 |
* calls calls |
| 15 |
* gg() ---------> Function.prototype.call() ---------> f() |
| 16 |
* |
| 17 |
* |
| 18 |
* The question this bug addresses is, "What should we say |f.caller| is?" |
| 19 |
* |
| 20 |
* Before this fix, SpiderMonkey said it was |Function.prototype.call|. |
| 21 |
* After this fix, SpiderMonkey emulates IE and says |gg| instead. |
| 22 |
* |
| 23 |
*/ |
| 24 |
//----------------------------------------------------------------------------- |
| 25 |
var UBound = 0; |
| 26 |
var BUGNUMBER = 222029; |
| 27 |
var summary = "Make our f.caller property match IE's wrt f.apply and f.call"; |
| 28 |
var status = ''; |
| 29 |
var statusitems = []; |
| 30 |
var actual = ''; |
| 31 |
var actualvalues = []; |
| 32 |
var expect= ''; |
| 33 |
var expectedvalues = []; |
| 34 |
|
| 35 |
|
| 36 |
function f() |
| 37 |
{ |
| 38 |
return f.caller.p ; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
/* |
| 43 |
* Call |f| directly |
| 44 |
*/ |
| 45 |
function g() |
| 46 |
{ |
| 47 |
return f(); |
| 48 |
} |
| 49 |
g.p = "hello"; |
| 50 |
|
| 51 |
|
| 52 |
/* |
| 53 |
* Call |f| via |f.call| |
| 54 |
*/ |
| 55 |
function gg() |
| 56 |
{ |
| 57 |
return f.call(this); |
| 58 |
} |
| 59 |
gg.p = "hello"; |
| 60 |
|
| 61 |
|
| 62 |
/* |
| 63 |
* Call |f| via |f.apply| |
| 64 |
*/ |
| 65 |
function ggg() |
| 66 |
{ |
| 67 |
return f.apply(this); |
| 68 |
} |
| 69 |
ggg.p = "hello"; |
| 70 |
|
| 71 |
|
| 72 |
/* |
| 73 |
* Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|. |
| 74 |
* In Sections 2 and 3 below, we no longer expect to recover this value - |
| 75 |
*/ |
| 76 |
Function.prototype.call.p = "goodbye"; |
| 77 |
Function.prototype.apply.p = "goodbye"; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
status = inSection(1); |
| 82 |
actual = g(); |
| 83 |
expect = "hello"; |
| 84 |
addThis(); |
| 85 |
|
| 86 |
status = inSection(2); |
| 87 |
actual = gg(); |
| 88 |
expect = "hello"; |
| 89 |
addThis(); |
| 90 |
|
| 91 |
status = inSection(3); |
| 92 |
actual = ggg(); |
| 93 |
expect = "hello"; |
| 94 |
addThis(); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
//----------------------------------------------------------------------------- |
| 100 |
test(); |
| 101 |
//----------------------------------------------------------------------------- |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
function addThis() |
| 106 |
{ |
| 107 |
statusitems[UBound] = status; |
| 108 |
actualvalues[UBound] = actual; |
| 109 |
expectedvalues[UBound] = expect; |
| 110 |
UBound++; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
function test() |
| 115 |
{ |
| 116 |
printBugNumber(BUGNUMBER); |
| 117 |
printStatus(summary); |
| 118 |
|
| 119 |
for (var i=0; i<UBound; i++) |
| 120 |
{ |
| 121 |
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 122 |
} |
| 123 |
} |