fix logic
[personal-kdelibs.git] / kjs / array_instance.h
blob3f2b6302f37dcd7b7b40471b2b0561bb89624ea8
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.
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.
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.
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
23 #ifndef ARRAY_INSTANCE_H
24 #define ARRAY_INSTANCE_H
26 #include "object.h"
28 namespace KJS {
29 struct ArrayStorage;
31 class KJS_EXPORT ArrayInstance : public JSObject {
32 public:
33 ArrayInstance(JSObject* prototype, unsigned initialLength);
34 ArrayInstance(JSObject* prototype, const List& initialValues);
35 ~ArrayInstance();
37 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
38 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
39 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, int attributes = None);
40 virtual void put(ExecState*, unsigned propertyName, JSValue*, int attributes = None);
41 virtual bool deleteProperty(ExecState *, const Identifier& propertyName);
42 virtual bool deleteProperty(ExecState *, unsigned propertyName);
43 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&);
45 virtual void mark();
47 virtual const ClassInfo* classInfo() const { return &info; }
48 static const ClassInfo info;
50 unsigned getLength() const { return m_length; }
51 JSValue* getItem(unsigned) const;
53 void sort(ExecState*);
54 void sort(ExecState*, JSObject* compareFunction);
56 private:
57 static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
58 bool inlineGetOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
60 void setLength(unsigned);
61 void increaseVectorLength(unsigned newLength);
63 unsigned compactForSorting();
65 unsigned m_length;
66 unsigned m_vectorLength;
67 ArrayStorage* m_storage;
70 } // namespace KJS
72 #endif