1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 1999-2000 Harri Porten ([email protected])
|
---|
4 | * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef JSArray_h
|
---|
23 | #define JSArray_h
|
---|
24 |
|
---|
25 | #include "JSObject.h"
|
---|
26 |
|
---|
27 | namespace KJS {
|
---|
28 |
|
---|
29 | struct ArrayStorage;
|
---|
30 |
|
---|
31 | class JSArray : public JSObject {
|
---|
32 | public:
|
---|
33 | JSArray(JSObject* prototype, unsigned initialLength);
|
---|
34 | JSArray(JSObject* prototype, const ArgList& initialValues);
|
---|
35 | virtual ~JSArray();
|
---|
36 |
|
---|
37 | virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
|
---|
38 | virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
|
---|
39 | virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem.
|
---|
40 |
|
---|
41 | static const ClassInfo info;
|
---|
42 |
|
---|
43 | unsigned getLength() const { return m_length; }
|
---|
44 | void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray.
|
---|
45 | JSValue* getItem(unsigned) const;
|
---|
46 |
|
---|
47 | void sort(ExecState*);
|
---|
48 | void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&);
|
---|
49 |
|
---|
50 | protected:
|
---|
51 | virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
|
---|
52 | virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
|
---|
53 | virtual bool deleteProperty(ExecState*, unsigned propertyName);
|
---|
54 | virtual void getPropertyNames(ExecState*, PropertyNameArray&);
|
---|
55 | virtual void mark();
|
---|
56 |
|
---|
57 | void* lazyCreationData();
|
---|
58 | void setLazyCreationData(void*);
|
---|
59 |
|
---|
60 | private:
|
---|
61 | using JSObject::get;
|
---|
62 |
|
---|
63 | virtual const ClassInfo* classInfo() const { return &info; }
|
---|
64 |
|
---|
65 | static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
|
---|
66 | bool inlineGetOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
|
---|
67 |
|
---|
68 | bool increaseVectorLength(unsigned newLength);
|
---|
69 |
|
---|
70 | unsigned compactForSorting();
|
---|
71 |
|
---|
72 | enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck };
|
---|
73 | void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck);
|
---|
74 |
|
---|
75 | unsigned m_length;
|
---|
76 | unsigned m_vectorLength;
|
---|
77 | ArrayStorage* m_storage;
|
---|
78 | };
|
---|
79 |
|
---|
80 | JSArray* constructEmptyArray(ExecState*);
|
---|
81 | JSArray* constructEmptyArray(ExecState*, unsigned initialLength);
|
---|
82 | JSArray* constructArray(ExecState*, JSValue* singleItemValue);
|
---|
83 | JSArray* constructArray(ExecState*, const ArgList& values);
|
---|
84 |
|
---|
85 | } // namespace KJS
|
---|
86 |
|
---|
87 | #endif
|
---|