Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / Function / regress-222029-001.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2003
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   Adrian Herscu<bmf1972@icqmail.com>, pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    13 Oct 2003
42  * SUMMARY: Make our f.caller property match IE's wrt f.apply and f.call
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=222029
44  *
45  * Below, when gg calls f via |f.call|, we have this call chain:
46  *
47  *          calls                                  calls
48  *   gg() --------->  Function.prototype.call()  --------->  f()
49  *
50  *
51  * The question this bug addresses is, "What should we say |f.caller| is?"
52  *
53  * Before this fix, SpiderMonkey said it was |Function.prototype.call|.
54  * After this fix, SpiderMonkey emulates IE and says |gg| instead.
55  *
56  */
57 //-----------------------------------------------------------------------------
58 var UBound = 0;
59 var BUGNUMBER = 222029;
60 var summary = "Make our f.caller property match IE's wrt f.apply and f.call";
61 var status = '';
62 var statusitems = [];
63 var actual = '';
64 var actualvalues = [];
65 var expect= '';
66 var expectedvalues = [];
67
68
69 function f()
70 {
71   return f.caller.p ;
72 }
73
74
75 /*
76  * Call |f| directly
77  */
78 function g()
79 {
80   return f();
81 }
82 g.p = "hello";
83
84
85 /*
86  * Call |f| via |f.call|
87  */
88 function gg()
89 {
90   return f.call(this);
91 }
92 gg.p = "hello";
93
94
95 /*
96  * Call |f| via |f.apply|
97  */
98 function ggg()
99 {
100   return f.apply(this);
101 }
102 ggg.p = "hello";
103
104
105 /*
106  * Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|.
107  * In Sections 2 and 3 below, we no longer expect to recover this value -
108  */
109 Function.prototype.call.p = "goodbye";
110 Function.prototype.apply.p = "goodbye";
111
112
113
114 status = inSection(1);
115 actual = g();
116 expect = "hello";
117 addThis();
118
119 status = inSection(2);
120 actual = gg();
121 expect = "hello";
122 addThis();
123
124 status = inSection(3);
125 actual = ggg();
126 expect = "hello";
127 addThis();
128
129
130
131
132 //-----------------------------------------------------------------------------
133 test();
134 //-----------------------------------------------------------------------------
135
136
137
138 function addThis()
139 {
140   statusitems[UBound] = status;
141   actualvalues[UBound] = actual;
142   expectedvalues[UBound] = expect;
143   UBound++;
144 }
145
146
147 function test()
148 {
149   enterFunc('test');
150   printBugNumber(BUGNUMBER);
151   printStatus(summary);
152
153   for (var i=0; i<UBound; i++)
154   {
155     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
156   }
157
158   exitFunc ('test');
159 }