js/src/tests/ecma/Array/15.4.5.1-2.js

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

mercurial