Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_4 / Functions / function-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 Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
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  *  File Name:          function-001.js
42  *  Description:
43  *
44  * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=324455
45  *
46  *  Earlier versions of JavaScript supported access to the arguments property
47  *  of the function object. This property held the arguments to the function.
48  *  function f() {
49  *      return f.arguments[0];    // deprecated
50  *  }
51  *  var x = f(3);    // x will be 3
52  *
53  * This feature is not a part of the final ECMA standard. Instead, scripts
54  * should simply use just "arguments":
55  *
56  * function f() {
57  *    return arguments[0];    // okay
58  * }
59  *
60  * var x = f(3);    // x will be 3
61  *
62  * Again, this feature was motivated by performance concerns. Access to the
63  * arguments property is not threadsafe, which is of particular concern in
64  * server environments. Also, the compiler can generate better code for
65  * functions because it can tell when the arguments are being accessed only by
66  * name and avoid setting up the arguments object.
67  *
68  *  Author:             christine@netscape.com
69  *  Date:               11 August 1998
70  */
71 var SECTION = "function-001.js";
72 var VERSION = "JS1_4";
73 var TITLE   = "Accessing the arguments property of a function object";
74 var BUGNUMBER="324455";
75 startTest();
76 writeHeaderToLog( SECTION + " "+ TITLE);
77
78 new TestCase(
79   SECTION,
80   "return function.arguments",
81   "P",
82   TestFunction_2("P", "A","S","S")[0] +"");
83
84
85 new TestCase(
86   SECTION,
87   "return arguments",
88   "P",
89   TestFunction_1( "P", "A", "S", "S" )[0] +"");
90
91 new TestCase(
92   SECTION,
93   "return arguments when function contains an arguments property",
94   "PASS",
95   TestFunction_3( "P", "A", "S", "S" ) +"");
96
97 new TestCase(
98   SECTION,
99   "return function.arguments when function contains an arguments property",
100   "PASS",
101   TestFunction_4( "F", "A", "I", "L" ) +"");
102
103 test();
104
105 function TestFunction_1( a, b, c, d, e ) {
106   return arguments;
107 }
108
109 function TestFunction_2( a, b, c, d, e ) {
110   return TestFunction_2.arguments;
111 }
112
113 function TestFunction_3( a, b, c, d, e ) {
114   var arguments = "PASS";
115   return arguments;
116 }
117
118 function TestFunction_4( a, b, c, d, e ) {
119   var arguments = "PASS";
120   return TestFunction_4.arguments;
121 }
122