2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "as_object.h"
24 // Forward declarations
31 /// Get the length of an object as though it were an array
33 /// It may well be an array, but this also works on normal objects with a
36 /// @param array The object whose array length is needed.
37 /// @return The array length of the object or 0 if no length is
39 size_t arrayLength(as_object
& array
);
41 /// Convert an integral value into an ObjectURI
43 /// NB this function adds a string value to the VM for each separate
44 /// integral value. It's the way the VM works.
46 /// @param i The integral value to find
47 /// @return The ObjectURI to look up.
48 ObjectURI
arrayKey(VM
& vm
, size_t i
);
50 /// A visitor to check whether an array is strict or not.
52 /// Strict arrays have no non-hidden non-numeric properties. Only real arrays
53 /// are strict arrays; any users of this functor should check that first.
54 class IsStrictArray
: public PropertyVisitor
57 IsStrictArray(VM
& st
) : _strict(true), _st(st
) {}
58 virtual bool accept(const ObjectURI
& uri
, const as_value
& val
);
69 /// Genuine arrays handle the length property in a special way.
71 /// The only distinction between Arrays and Objects is that the length
72 /// property is changed when an element is added, and that changing the length
73 /// can result in deleted properties.
74 void checkArrayLength(as_object
& array
, const ObjectURI
& uri
,
78 void foreachArray(as_object
& array
, T
& pred
)
80 size_t size
= arrayLength(array
);
83 VM
& vm
= getVM(array
);
85 for (size_t i
= 0; i
< static_cast<size_t>(size
); ++i
) {
86 pred(getOwnProperty(array
, arrayKey(vm
, i
)));
90 /// Initialize the global.Array object
91 void array_class_init(as_object
& global
, const ObjectURI
& uri
);
93 void registerArrayNative(as_object
& global
);