1/*
2* The contents of this file are subject to the Netscape Public
3* License Version 1.1 (the "License"); you may not use this file
4* except in compliance with the License. You may obtain a copy of
5* the License at http://www.mozilla.org/NPL/
6*
7* Software distributed under the License is distributed on an "AS
8* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9* implied. See the License for the specific language governing
10* rights and limitations under the License.
11*
12* The Original Code is mozilla.org code.
13*
14* The Initial Developer of the Original Code is Netscape
15* Communications Corporation.  Portions created by Netscape are
16* Copyright (C) 1998 Netscape Communications Corporation.
17* All Rights Reserved.
18*
19* Contributor(s): pschwartau@netscape.com
20* Date: 2001-06-14
21*
22* SUMMARY: Regression test for Bugzilla bug 85880
23*
24* Rhino interpreted mode was nulling out the arguments object of a
25* function if it happened to call another function inside its body.
26*
27* See http://bugzilla.mozilla.org/show_bug.cgi?id=85880
28*
29*/
30//-------------------------------------------------------------------------------------------------
31var UBound = 0;
32var bug = 85880;
33var summary = 'Arguments object of g(){f()} should not be null';
34var cnNonNull = 'Arguments != null';
35var cnNull = 'Arguments == null';
36var cnRecurse = true;
37var status = '';
38var statusitems = [];
39var actual = '';
40var actualvalues = [];
41var expect= '';
42var expectedvalues = [];
43
44
45function f1(x)
46{
47}
48
49
50function f2()
51{
52  return f2.arguments;
53}
54status = 'Section A of test';
55actual = (f2() == null);
56expect = false;
57addThis();
58
59status = 'Section B of test';
60actual = (f2(0) == null);
61expect = false;
62addThis();
63
64
65function f3()
66{
67  f1();
68  return f3.arguments;
69}
70status = 'Section C of test';
71actual = (f3() == null);
72expect = false;
73addThis();
74
75status = 'Section D of test';
76actual = (f3(0) == null);
77expect = false;
78addThis();
79
80
81function f4()
82{
83  f1();
84  f2();
85  f3();
86  return f4.arguments;
87}
88status = 'Section E of test';
89actual = (f4() == null);
90expect = false;
91addThis();
92
93status = 'Section F of test';
94actual = (f4(0) == null);
95expect = false;
96addThis();
97
98
99function f5()
100{
101  if (cnRecurse)
102  {
103    cnRecurse = false;
104    f5();
105  }
106  return f5.arguments;
107}
108status = 'Section G of test';
109actual = (f5() == null);
110expect = false;
111addThis();
112
113status = 'Section H of test';
114actual = (f5(0) == null);
115expect = false;
116addThis();
117
118
119
120//-------------------------------------------------------------------------------------------------
121test();
122//-------------------------------------------------------------------------------------------------
123
124
125function addThis()
126{
127  statusitems[UBound] = status;
128  actualvalues[UBound] = isThisNull(actual);
129  expectedvalues[UBound] = isThisNull(expect);
130  UBound++;
131}
132
133
134function test()
135{
136  enterFunc ('test');
137  printBugNumber (bug);
138  printStatus (summary);
139
140  for (var i = 0; i < UBound; i++)
141  {
142    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
143  }
144
145  exitFunc ('test');
146}
147
148
149function isThisNull(bool)
150{
151  return bool? cnNull : cnNonNull
152}
153