@@ -7,7 +7,7 @@ use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject};
7
7
use crate :: avm2:: value:: Value ;
8
8
use crate :: avm2:: Error ;
9
9
use crate :: avm2:: Multiname ;
10
- use crate :: string:: AvmString ;
10
+ use crate :: string:: { AvmString , WStr } ;
11
11
use crate :: utils:: HasPrefixField ;
12
12
use core:: fmt;
13
13
use gc_arena:: barrier:: unlock;
@@ -84,6 +84,11 @@ impl<'gc> ArrayObject<'gc> {
84
84
) )
85
85
}
86
86
87
+ pub fn as_array_index ( local_name : & WStr ) -> Option < usize > {
88
+ // TODO match avmplus
89
+ local_name. parse :: < usize > ( ) . ok ( )
90
+ }
91
+
87
92
pub fn set_element ( self , mc : & Mutation < ' gc > , index : usize , value : Value < ' gc > ) {
88
93
unlock ! ( Gc :: write( mc, self . 0 ) , ArrayObjectData , array)
89
94
. borrow_mut ( )
@@ -115,7 +120,7 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
115
120
) -> Result < Value < ' gc > , Error < ' gc > > {
116
121
if name. valid_dynamic_name ( ) {
117
122
if let Some ( name) = name. local_name ( ) {
118
- if let Ok ( index) = name . parse :: < usize > ( ) {
123
+ if let Some ( index) = ArrayObject :: as_array_index ( & name ) {
119
124
if let Some ( result) = self . get_index_property ( index) {
120
125
return Ok ( result) ;
121
126
}
@@ -151,7 +156,7 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
151
156
152
157
if name. valid_dynamic_name ( ) {
153
158
if let Some ( name) = name. local_name ( ) {
154
- if let Ok ( index) = name . parse :: < usize > ( ) {
159
+ if let Some ( index) = ArrayObject :: as_array_index ( & name ) {
155
160
self . set_element ( mc, index, value) ;
156
161
157
162
return Ok ( ( ) ) ;
@@ -172,7 +177,7 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
172
177
173
178
if name. valid_dynamic_name ( ) {
174
179
if let Some ( name) = name. local_name ( ) {
175
- if let Ok ( index) = name . parse :: < usize > ( ) {
180
+ if let Some ( index) = ArrayObject :: as_array_index ( & name ) {
176
181
self . set_element ( mc, index, value) ;
177
182
178
183
return Ok ( ( ) ) ;
@@ -192,7 +197,7 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
192
197
193
198
if name. valid_dynamic_name ( ) {
194
199
if let Some ( name) = name. local_name ( ) {
195
- if let Ok ( index) = name . parse :: < usize > ( ) {
200
+ if let Some ( index) = ArrayObject :: as_array_index ( & name ) {
196
201
unlock ! ( Gc :: write( mc, self . 0 ) , ArrayObjectData , array)
197
202
. borrow_mut ( )
198
203
. delete ( index) ;
@@ -208,7 +213,7 @@ impl<'gc> TObject<'gc> for ArrayObject<'gc> {
208
213
fn has_own_property ( self , name : & Multiname < ' gc > ) -> bool {
209
214
if name. valid_dynamic_name ( ) {
210
215
if let Some ( name) = name. local_name ( ) {
211
- if let Ok ( index) = name . parse :: < usize > ( ) {
216
+ if let Some ( index) = ArrayObject :: as_array_index ( & name ) {
212
217
return self . 0 . array . borrow ( ) . get ( index) . is_some ( ) ;
213
218
}
214
219
}
0 commit comments