Update with current status
[gnash.git] / testsuite / actionscript.all / enumerate.as
blob0510a979f7d5073ef31cd8d2af909dadbf9ebdbc
1 //
2 // Copyright (C) 2007, 2009, 2010, 2011, 2017 Free Software Foundation, Inc.
3 //
4 // This program is free software; you can redistribute it and/or modchecky
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; check not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fcheckth Floor, Boston, MA 02110-1301 USA
20 * Zou Lunkai, zoulunkai@gmail.com
22 * Test ActionEnumerate/2
26 rcsid="enumerate.as";
27 #include "check.as"
29 #if OUTPUT_VERSION > 5
32 // enumerate characters of a sprite
35 // Create a recorder and init it.
36 recorder = new Array(10);
37 for(i=0; i<10; i++){
38 recorder['mc'+i] = 0;
41 // Create six characters
42 for(i=0; i<6; i++){
43 _root.createEmptyMovieClip('mc'+i, i+1);
46 // Use the recorder to record the enumerated results in _root
47 i = 0;
48 for (var j in _root){
49 recorder[j.toString()] = _root[j];
50 i++;
53 // Test what we got in the above step. Tests show that characters were also got enumerated!
54 check_equals(typeof(recorder['mc0']), 'movieclip');
55 check_equals(typeof(recorder['mc1']), 'movieclip');
56 check_equals(typeof(recorder['mc2']), 'movieclip');
57 check_equals(typeof(recorder['mc3']), 'movieclip');
58 check_equals(typeof(recorder['mc4']), 'movieclip');
59 check_equals(typeof(recorder['mc5']), 'movieclip');
60 check_equals(_root.hasOwnProperty('mc0'), false);
61 check_equals(_root.hasOwnProperty('mc1'), false);
62 check_equals(_root.hasOwnProperty('mc2'), false);
63 check_equals(_root.hasOwnProperty('mc3'), false);
64 check_equals(_root.hasOwnProperty('mc4'), false);
65 check_equals(_root.hasOwnProperty('mc5'), false);
66 delete recorder;
70 // enumerate properties of an AS object
73 recorder = new Array(10);
75 // initialize the recorder
76 for(i=0; i<10; i++){
77 recorder['x'+i] = 0;
80 obj = new Object();
81 obj.x1 = function () {};
82 obj.x2 = 1;
83 obj.x3 = Array();
85 i = 0;
86 for (var j in obj){
87 // equivalent to recorder[j.toString()] = obj[j.toString()];
88 recorder[j.toString()] = obj[j];
89 i++;
92 check_equals(typeof(recorder['x1']), 'function');
93 check_equals(typeof(recorder['x2']), 'number');
94 check_equals(typeof(recorder['x3']), 'object');
95 check_equals(obj.hasOwnProperty('x1'), true);
96 check_equals(obj.hasOwnProperty('x2'), true);
97 check_equals(obj.hasOwnProperty('x3'), true);
98 delete recorder;
101 enumerateObj = function(object) {
102 list = "";
103 for (el in object) {
104 list += el + ",";
106 return list;
109 /// Try different enumerations.
111 list = "";
112 o = {};
114 o.a = 3;
115 check_equals(enumerateObj(o), "a,");
117 o.b = "string";
118 check_equals(enumerateObj(o), "b,a,");
120 o["el"] = 5;
121 check_equals(enumerateObj(o), "el,b,a,");
123 o[8] = new Date();
124 check_equals(enumerateObj(o), "8,el,b,a,");
126 o.b = 8;
127 check_equals(enumerateObj(o), "8,el,b,a,");
129 delete o.b;
130 check_equals(enumerateObj(o), "8,el,a,");
132 o.b = "string again";
133 check_equals(enumerateObj(o), "b,8,el,a,");
135 r = o.u;
136 check_equals(enumerateObj(o), "b,8,el,a,");
138 t = {};
139 o[t] = 9;
140 check_equals(enumerateObj(o), "[object Object],b,8,el,a,");
142 delete o["8"];
143 check_equals(enumerateObj(o), "[object Object],b,el,a,");
145 o.c = Object.prototype.toString;
146 check_equals(enumerateObj(o), "c,[object Object],b,el,a,");
148 o[9] = 7;
149 check_equals(enumerateObj(o), "9,c,[object Object],b,el,a,");
151 o["6"] = 8;
152 check_equals(enumerateObj(o), "6,9,c,[object Object],b,el,a,");
156 extras = 0;
158 #ifdef MING_SUPPORTS_ASM
159 extras += 6;
161 // The first test (enumerate) is possible with any asm-supporting ming,
162 // the second only with version from 2009-05-20 or later.
163 a = new Object();
164 a.a = 1;
165 a.b = "string";
167 var r0, r1, r2, r3, r4;
170 // We make sure the stack is clear, then push 'stackfirst', then enumerate
171 // and see what all the stack values are.
172 asm {
175 push 'stackfirst'
176 push 'a'
177 enumerate
178 setregister r:0
179 push 'r0', r:0
180 setvariable
182 setregister r:1
183 push 'r1', r:1
184 setvariable
186 setregister r:2
187 push 'r2', r:2
188 setvariable
190 setregister r:3
191 push 'r3', r:3
192 setvariable
194 setregister r:4
195 push 'r4', r:4
196 setvariable
200 check_equals(r0, "b");
201 check_equals(r1, "a");
202 check_equals(r2, undefined);
204 // Use strictly equals to check that it isn't "null"
205 check(r2 === undefined);
207 check_equals(r3, "stackfirst");
208 check_equals(r4, undefined);
209 #endif
211 #if MING_VERSION_CODE >= 40004
212 extras += 6;
214 // Do the same for enum2
215 asm {
218 push 'stackfirst'
219 push 'a'
220 getvariable
221 enumerate2
222 setregister r:0
223 push 'r0', r:0
224 setvariable
226 setregister r:1
227 push 'r1', r:1
228 setvariable
230 setregister r:2
231 push 'r2', r:2
232 setvariable
234 setregister r:3
235 push 'r3', r:3
236 setvariable
238 setregister r:4
239 push 'r4', r:4
240 setvariable
244 check_equals(r0, "b");
245 check_equals(r1, "a");
246 check_equals(r2, undefined);
248 // Use strictly equals to check that it isn't "null"
249 check(r2 === undefined);
251 check_equals(r3, "stackfirst");
252 check_equals(r4, undefined);
253 #endif
255 totals(31 + extras);
257 #else
258 totals(0);
259 #endif // OUTPUT_VERSION > 5