2 // Copyright (C) 2007, 2009, 2010, 2011, 2017 Free Software Foundation, Inc.
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.
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
29 #if OUTPUT_VERSION
> 5
32 // enumerate characters of a sprite
35 // Create a recorder and init it.
36 recorder
= new Array(10);
41 // Create six characters
43 _root
.createEmptyMovieClip
('mc'+i
, i
+1);
46 // Use the recorder to record the enumerated results in _root
49 recorder
[j
.toString
()] = _root
[j
];
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);
70 // enumerate properties of an AS object
73 recorder
= new Array(10);
75 // initialize the recorder
81 obj
.x1
= function () {};
87 // equivalent to recorder[j.toString()] = obj[j.toString()];
88 recorder
[j
.toString
()] = obj
[j
];
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);
101 enumerateObj
= function(object
) {
109 /// Try different enumerations.
115 check_equals
(enumerateObj
(o
), "a,");
118 check_equals
(enumerateObj
(o
), "b,a,");
121 check_equals
(enumerateObj
(o
), "el,b,a,");
124 check_equals
(enumerateObj
(o
), "8,el,b,a,");
127 check_equals
(enumerateObj
(o
), "8,el,b,a,");
130 check_equals
(enumerateObj
(o
), "8,el,a,");
132 o
.b
= "string again";
133 check_equals
(enumerateObj
(o
), "b,8,el,a,");
136 check_equals
(enumerateObj
(o
), "b,8,el,a,");
140 check_equals
(enumerateObj
(o
), "[object Object],b,8,el,a,");
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,");
149 check_equals
(enumerateObj
(o
), "9,c,[object Object],b,el,a,");
152 check_equals
(enumerateObj
(o
), "6,9,c,[object Object],b,el,a,");
158 #ifdef MING_SUPPORTS_ASM
161 // The first test (enumerate) is possible with any asm-supporting ming,
162 // the second only with version from 2009-05-20 or later.
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.
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);
211 #if MING_VERSION_CODE
>= 40004
214 // Do the same for enum2
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);
259 #endif
// OUTPUT_VERSION > 5