Debian Codegraph @

rhino/testsrc/tests/js1_5/Function/regress-222029-002.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 gTestfile = 'regress-222029-002.js';
26 var UBound = 0;
27 var BUGNUMBER = 222029;
28 var summary = "Make our f.caller property match IE's wrt f.apply and f.call";
29 var status = '';
30 var statusitems = [];
31 var actual = '';
32 var actualvalues = [];
33 var expect= '';
34 var expectedvalues = [];
35
36 /*
37 * Try to confuse the engine by adding a |p| property to everything!
38 */
39 var p = 'global';
40 var o = {p:'object'};
41
42
43 function f(obj)
44 {
45 return f.caller.p ;
46 }
47
48
49 /*
50 * Call |f| directly
51 */
52 function g(obj)
53 {
54 var p = 'local';
55 return f(obj);
56 }
57 g.p = "hello";
58
59
60 /*
61 * Call |f| via |f.call|
62 */
63 function gg(obj)
64 {
65 var p = 'local';
66 return f.call(obj, obj);
67 }
68 gg.p = "hello";
69
70
71 /*
72 * Call |f| via |f.apply|
73 */
74 function ggg(obj)
75 {
76 var p = 'local';
77 return f.apply(obj, [obj]);
78 }
79 ggg.p = "hello";
80
81
82 /*
83 * Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|.
84 * In Sections 2 and 3 below, we no longer expect to recover this value -
85 */
86 Function.prototype.call.p = "goodbye";
87 Function.prototype.apply.p = "goodbye";
88
89
90
91 status = inSection(1);
92 actual = g(o);
93 expect = "hello";
94 addThis();
95
96 status = inSection(2);
97 actual = gg(o);
98 expect = "hello";
99 addThis();
100
101 status = inSection(3);
102 actual = ggg(o);
103 expect = "hello";
104 addThis();
105
106
107
108
109 //-----------------------------------------------------------------------------
110 test();
111 //-----------------------------------------------------------------------------
112
113
114
115 function addThis()
116 {
117 statusitems[UBound] = status;
118 actualvalues[UBound] = actual;
119 expectedvalues[UBound] = expect;
120 UBound++;
121 }
122
123
124 function test()
125 {
126 enterFunc('test');
127 printBugNumber(BUGNUMBER);
128 printStatus(summary);
129
130 for (var i=0; i<UBound; i++)
131 {
132 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
133 }
134
135 exitFunc ('test');
136 }