• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.6
24    ECMA Section:       Activation Object
25    Description:
26
27    If the function object being invoked has an arguments property, let x be
28    the value of that property; the activation object is also given an internal
29    property [[OldArguments]] whose initial value is x; otherwise, an arguments
30    property is created for the function object but the activation object is
31    not given an [[OldArguments]] property. Next, arguments object described
32    below (the same one stored in the arguments property of the activation
33    object) is used as the new value of the arguments property of the function
34    object. This new value is installed even if the arguments property already
35    exists and has the ReadOnly attribute (as it will for native Function
36    objects). (These actions are taken to provide compatibility with a form of
37    program syntax that is now discouraged: to access the arguments object for
38    function f within the body of f by using the expression f.arguments.
39    The recommended way to access the arguments object for function f within
40    the body of f is simply to refer to the variable arguments.)
41
42    Author:             christine@netscape.com
43    Date:               12 november 1997
44*/
45
46    var SECTION = "10.1.6";
47    var VERSION = "ECMA_1";
48    startTest();
49    var TITLE   = "Activation Object";
50
51    writeHeaderToLog( SECTION + " "+ TITLE);
52
53    var testcases = new Array();
54
55    var arguments = "FAILED!";
56
57    var ARG_STRING = "value of the argument property";
58
59    testcases[tc++] = new TestCase( SECTION,
60                                    "(new TestObject(0,1,2,3,4,5)).length",
61                                    6,
62                                    (new TestObject(0,1,2,3,4,5)).length );
63
64    for ( i = 0; i < 6; i++ ) {
65
66        testcases[tc++] = new TestCase( SECTION,
67                                        "(new TestObject(0,1,2,3,4,5))["+i+"]",
68                                        i,
69                                        (new TestObject(0,1,2,3,4,5))[i]);
70    }
71
72
73    //    The current object already has an arguments property.
74
75    testcases[tc++] = new TestCase( SECTION,
76                                    "(new AnotherTestObject(1,2,3)).arguments",
77                                    ARG_STRING,
78                                    (new AnotherTestObject(1,2,3)).arguments );
79
80    //  The function invoked with [[Call]]
81
82    testcases[tc++] = new TestCase( SECTION,
83                                    "TestFunction(1,2,3)",
84                                    ARG_STRING,
85                                    TestFunction() + '' );
86
87
88    test();
89
90
91
92function Prototype() {
93    this.arguments = ARG_STRING;
94}
95function TestObject() {
96    this.__proto__ = new Prototype();
97    return arguments;
98}
99function AnotherTestObject() {
100    this.__proto__ = new Prototype();
101    return this;
102}
103function TestFunction() {
104    arguments = ARG_STRING;
105    return arguments;
106}
107function AnotherTestFunction() {
108    this.__proto__ = new Prototype();
109    return this;
110}
111
112function test() {
113    for ( tc=0; tc < testcases.length; tc++ ) {
114        testcases[tc].passed = writeTestCaseResult(
115                            testcases[tc].expect,
116                            testcases[tc].actual,
117                            testcases[tc].description +" = "+
118                            testcases[tc].actual );
119
120        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
121    }
122    stopTest();
123    return ( testcases );
124}
125