Debian Codegraph @

rhino/testsrc/tests/ecma/Array/15.4.5.1-2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.4.5.1-2.js';
7
8 /**
9 File Name: 15.4.5.1-2.js
10 ECMA Section: [[ Put]] (P, V)
11 Description:
12 Array objects use a variation of the [[Put]] method used for other native
13 ECMAScript objects (section 8.6.2.2).
14
15 Assume A is an Array object and P is a string.
16
17 When the [[Put]] method of A is called with property P and value V, the
18 following steps are taken:
19
20 1. Call the [[CanPut]] method of A with name P.
21 2. If Result(1) is false, return.
22 3. If A doesn't have a property with name P, go to step 7.
23 4. If P is "length", go to step 12.
24 5. Set the value of property P of A to V.
25 6. Go to step 8.
26 7. Create a property with name P, set its value to V and give it empty
27 attributes.
28 8. If P is not an array index, return.
29 9. If A itself has a property (not an inherited property) named "length",
30 andToUint32(P) is less than the value of the length property of A, then
31 return.
32 10. Change (or set) the value of the length property of A to ToUint32(P)+1.
33 11. Return.
34 12. Compute ToUint32(V).
35 13. For every integer k that is less than the value of the length property
36 of A but not less than Result(12), if A itself has a property (not an
37 inherited property) named ToString(k), then delete that property.
38 14. Set the value of property P of A to Result(12).
39 15. Return.
40
41
42 These are gTestcases from Waldemar, detailed in
43 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123552
44
45 Author: [email protected]
46 Date: 15 June 1998
47 */
48
49 var SECTION = "15.4.5.1-2";
50 var VERSION = "ECMA_1";
51 startTest();
52 var TITLE = "Array [[Put]] (P,V)";
53
54 writeHeaderToLog( SECTION + " "+ TITLE);
55
56 var a = new Array();
57
58 AddCase( "3.00", "three" );
59 AddCase( "00010", "eight" );
60 AddCase( "37xyz", "thirty-five" );
61 AddCase("5000000000", 5)
62 AddCase( "-2", -3 );
63
64 new TestCase( SECTION,
65 "a[10]",
66 void 0,
67 a[10] );
68
69 new TestCase( SECTION,
70 "a[3]",
71 void 0,
72 a[3] );
73
74 a[4] = "four";
75
76 new TestCase( SECTION,
77 "a[4] = \"four\"; a[4]",
78 "four",
79 a[4] );
80
81 new TestCase( SECTION,
82 "a[\"4\"]",
83 "four",
84 a["4"] );
85
86 new TestCase( SECTION,
87 "a[\"4.00\"]",
88 void 0,
89 a["4.00"] );
90
91 new TestCase( SECTION,
92 "a.length",
93 5,
94 a.length );
95
96
97 a["5000000000"] = 5;
98
99 new TestCase( SECTION,
100 "a[\"5000000000\"] = 5; a.length",
101 5,
102 a.length );
103
104 new TestCase( SECTION,
105 "a[\"-2\"] = -3; a.length",
106 5,
107 a.length );
108
109 test();
110
111 function AddCase ( arg, value ) {
112
113 a[arg] = value;
114
115 new TestCase( SECTION,
116 "a[\"" + arg + "\"] = "+ value +"; a.length",
117 0,
118 a.length );
119 }