1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#ifndef ARRAY_INSTANCE_H
24#define ARRAY_INSTANCE_H
25
26#include "object.h"
27
28namespace KJS {
29 struct ArrayStorage;
30
31 class KJS_EXPORT ArrayInstance : public JSObject {
32 public:
33 ArrayInstance(JSObject* prototype, unsigned initialLength);
34 ArrayInstance(JSObject* prototype, const List& initialValues);
35 ~ArrayInstance();
36
37 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
38 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
39 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
40 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, int attributes = None);
41 virtual void put(ExecState*, unsigned propertyName, JSValue*, int attributes = None);
42 virtual bool deleteProperty(ExecState *, const Identifier& propertyName);
43 virtual bool deleteProperty(ExecState *, unsigned propertyName);
44 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, PropertyMap::PropertyMode mode);
45
46 virtual bool defineOwnProperty(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& desc, bool shouldThrow);
47 virtual void mark();
48
49 virtual bool getPropertyAttributes(const Identifier& propertyName, unsigned& attributes) const;
50
51 virtual JSValue *getDirect(const Identifier& propertyName) const;
52
53 virtual void putDirect(unsigned index, JSValue *value, int attr = 0);
54 virtual void putDirect(const Identifier &propertyName, JSValue *value, int attr = 0);
55 virtual void putDirect(const Identifier &propertyName, int value, int attr = 0);
56
57 virtual void removeDirect(const Identifier &propertyName);
58
59 virtual const ClassInfo* classInfo() const { return &info; }
60 static const ClassInfo info;
61
62 unsigned getLength() const { return m_length; }
63 JSValue* getItem(unsigned) const;
64
65 void sort(ExecState*);
66 void sort(ExecState*, JSObject* compareFunction);
67
68 private:
69 static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
70 bool inlineGetOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
71 inline struct ArrayEntity* getArrayEntity(unsigned) const;
72
73 void setLength(unsigned);
74 void increaseVectorLength(unsigned newLength);
75
76 unsigned compactForSorting();
77
78 unsigned m_length;
79 unsigned m_vectorLength;
80 ArrayStorage* m_storage;
81
82 inline bool anyItemHasAttribute(unsigned attributes) const;
83 uint32_t m_lengthAttributes;
84 };
85
86} // namespace KJS
87
88#endif
89