]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: 10.1.8-2 | |
24 | ECMA Section: Arguments Object | |
25 | Description: | |
26 | ||
27 | When control enters an execution context for declared function code, | |
28 | anonymous code, or implementation-supplied code, an arguments object is | |
29 | created and initialized as follows: | |
30 | ||
31 | The [[Prototype]] of the arguments object is to the original Object | |
32 | prototype object, the one that is the initial value of Object.prototype | |
33 | (section 15.2.3.1). | |
34 | ||
35 | A property is created with name callee and property attributes {DontEnum}. | |
36 | The initial value of this property is the function object being executed. | |
37 | This allows anonymous functions to be recursive. | |
38 | ||
39 | A property is created with name length and property attributes {DontEnum}. | |
40 | The initial value of this property is the number of actual parameter values | |
41 | supplied by the caller. | |
42 | ||
43 | For each non-negative integer, iarg, less than the value of the length | |
44 | property, a property is created with name ToString(iarg) and property | |
45 | attributes { DontEnum }. The initial value of this property is the value | |
46 | of the corresponding actual parameter supplied by the caller. The first | |
47 | actual parameter value corresponds to iarg = 0, the second to iarg = 1 and | |
48 | so on. In the case when iarg is less than the number of formal parameters | |
49 | for the function object, this property shares its value with the | |
50 | corresponding property of the activation object. This means that changing | |
51 | this property changes the corresponding property of the activation object | |
52 | and vice versa. The value sharing mechanism depends on the implementation. | |
53 | ||
54 | Author: christine@netscape.com | |
55 | Date: 12 november 1997 | |
56 | */ | |
57 | ||
58 | var SECTION = "10.1.8-2"; | |
59 | var VERSION = "ECMA_1"; | |
60 | startTest(); | |
61 | var TITLE = "Arguments Object"; | |
62 | ||
63 | writeHeaderToLog( SECTION + " "+ TITLE); | |
64 | ||
65 | var testcases = new Array(); | |
66 | ||
67 | // Tests for anonymous functions | |
68 | ||
69 | var GetCallee = new Function( "var c = arguments.callee; return c" ); | |
70 | var GetArguments = new Function( "var a = arguments; return a" ); | |
71 | var GetLength = new Function( "var l = arguments.length; return l" ); | |
72 | ||
73 | var ARG_STRING = "value of the argument property"; | |
74 | ||
75 | testcases[tc++] = new TestCase( SECTION, | |
76 | "GetCallee()", | |
77 | GetCallee, | |
78 | GetCallee() ); | |
79 | ||
80 | var LIMIT = 100; | |
81 | ||
82 | for ( var i = 0, args = "" ; i < LIMIT; i++ ) { | |
83 | args += String(i) + ( i+1 < LIMIT ? "," : "" ); | |
84 | ||
85 | } | |
86 | ||
87 | var LENGTH = eval( "GetLength("+ args +")" ); | |
88 | ||
89 | testcases[tc++] = new TestCase( SECTION, | |
90 | "GetLength("+args+")", | |
91 | 100, | |
92 | LENGTH ); | |
93 | ||
94 | var ARGUMENTS = eval( "GetArguments( " +args+")" ); | |
95 | ||
96 | for ( var i = 0; i < 100; i++ ) { | |
97 | testcases[tc++] = new TestCase( SECTION, | |
98 | "GetArguments("+args+")["+i+"]", | |
99 | i, | |
100 | ARGUMENTS[i] ); | |
101 | } | |
102 | ||
103 | test(); | |
104 | ||
105 | function test() { | |
106 | for ( tc=0; tc < testcases.length; tc++ ) { | |
107 | testcases[tc].passed = writeTestCaseResult( | |
108 | testcases[tc].expect, | |
109 | testcases[tc].actual, | |
110 | testcases[tc].description +" = "+ | |
111 | testcases[tc].actual ); | |
112 | ||
113 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
114 | } | |
115 | stopTest(); | |
116 | return ( testcases ); | |
117 | } |