• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15function f_arg (arguments)
16{
17  return arguments;
18}
19assert (f_arg (1) === 1);
20
21function f (a, b, c)
22{
23  return arguments;
24}
25
26args = f();
27assert (args[0] === undefined);
28
29args = f (1, 2, 3, 4, 5);
30assert (args[0] === 1);
31assert (args[1] === 2);
32assert (args[2] === 3);
33assert (args[3] === 4);
34assert (args[4] === 5);
35assert (args[5] === undefined);
36
37assert (args.callee === f);
38assert (typeof args.caller === 'undefined');
39
40function g (a, b, c)
41{
42  assert (arguments[0] === 1);
43  assert (arguments[1] === undefined);
44  assert (arguments[2] === undefined);
45
46  a = 'a';
47  b = 'b';
48  c = 'c';
49
50  assert (arguments[0] === 'a');
51  assert (arguments[1] === 'b');
52  assert (arguments[2] === 'c');
53
54  arguments [0] = 1;
55  arguments [1] = 2;
56  arguments [2] = 3;
57
58  assert (a === 1);
59  assert (b === 2);
60  assert (c === 3);
61
62  delete arguments [0];
63  arguments[0] = 'new value';
64  assert (a === 1);
65
66  a = 'a';
67  b = 'b';
68  c = 'c';
69
70  assert (arguments[0] === 'new value');
71  assert (arguments[1] === 'b');
72  assert (arguments[2] === 'c');
73}
74
75g (1);
76
77fn_expr = function (a, b, c)
78{
79  'use strict';
80
81  assert (arguments[0] === 1);
82  assert (arguments[1] === undefined);
83  assert (arguments[2] === undefined);
84
85  a = 'a';
86  b = 'b';
87  c = 'c';
88
89  assert (arguments[0] === 1);
90  assert (arguments[1] === undefined);
91  assert (arguments[2] === undefined);
92
93  arguments [0] = 1;
94  arguments [1] = 'p';
95  arguments [2] = 'q';
96
97  assert (a === 'a');
98  assert (b === 'b');
99  assert (c === 'c');
100
101  delete arguments [0];
102  arguments[0] = 'new value';
103  assert (a === 'a');
104
105  a = 'a';
106  b = 'b';
107  c = 'c';
108
109  assert (arguments[0] === 'new value');
110  assert (arguments[1] === 'p');
111  assert (arguments[2] === 'q');
112
113  function check_type_error_for_property (obj, prop) {
114    try {
115      var v = obj[prop];
116      assert (false);
117    }
118    catch (e) {
119      assert (e instanceof TypeError);
120    }
121  }
122
123  check_type_error_for_property (arguments, 'caller');
124  check_type_error_for_property (arguments, 'callee');
125}
126
127fn_expr (1);
128
129(function () {
130 var a = [arguments];
131})();
132
133function nested_args()
134{
135  var a;
136  for (var i = 0; i < 1; i++)
137  {
138    if (i == 0)
139    {
140      a = arguments[i];
141    }
142  }
143  assert(a === 3);
144}
145nested_args(3);
146