Debian Codegraph @

rhino/testsrc/tests/js1_5/Function/regress-222029-001.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-001.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 function f()
38 {
39 return f.caller.p ;
40 }
41
42
43 /*
44 * Call |f| directly
45 */
46 function g()
47 {
48 return f();
49 }
50 g.p = "hello";
51
52
53 /*
54 * Call |f| via |f.call|
55 */
56 function gg()
57 {
58 return f.call(this);
59 }
60 gg.p = "hello";
61
62
63 /*
64 * Call |f| via |f.apply|
65 */
66 function ggg()
67 {
68 return f.apply(this);
69 }
70 ggg.p = "hello";
71
72
73 /*
74 * Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|.
75 * In Sections 2 and 3 below, we no longer expect to recover this value -
76 */
77 Function.prototype.call.p = "goodbye";
78 Function.prototype.apply.p = "goodbye";
79
80
81
82 status = inSection(1);
83 actual = g();
84 expect = "hello";
85 addThis();
86
87 status = inSection(2);
88 actual = gg();
89 expect = "hello";
90 addThis();
91
92 status = inSection(3);
93 actual = ggg();
94 expect = "hello";
95 addThis();
96
97
98
99
100 //-----------------------------------------------------------------------------
101 test();
102 //-----------------------------------------------------------------------------
103
104
105
106 function addThis()
107 {
108 statusitems[UBound] = status;
109 actualvalues[UBound] = actual;
110 expectedvalues[UBound] = expect;
111 UBound++;
112 }
113
114
115 function test()
116 {
117 enterFunc('test');
118 printBugNumber(BUGNUMBER);
119 printStatus(summary);
120
121 for (var i=0; i<UBound; i++)
122 {
123 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
124 }
125
126 exitFunc ('test');
127 }