File indexing completed on 2024-05-12 15:43:14

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
0004  *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
0005  *
0006  *  This library is free software; you can redistribute it and/or
0007  *  modify it under the terms of the GNU Lesser General Public
0008  *  License as published by the Free Software Foundation; either
0009  *  version 2 of the License, or (at your option) any later version.
0010  *
0011  *  This library is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  *  Lesser General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU Lesser General Public
0017  *  License along with this library; if not, write to the Free Software
0018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  *
0020  */
0021 
0022 #ifndef ARRAY_INSTANCE_H
0023 #define ARRAY_INSTANCE_H
0024 
0025 #include "object.h"
0026 
0027 namespace KJS
0028 {
0029 struct ArrayStorage;
0030 
0031 class KJS_EXPORT ArrayInstance : public JSObject
0032 {
0033 public:
0034     ArrayInstance(JSObject *prototype, unsigned initialLength);
0035     ArrayInstance(JSObject *prototype, const List &initialValues);
0036     ~ArrayInstance() override;
0037 
0038     bool getOwnPropertySlot(ExecState *, const Identifier &propertyName, PropertySlot &) override;
0039     bool getOwnPropertySlot(ExecState *, unsigned propertyName, PropertySlot &) override;
0040     bool getOwnPropertyDescriptor(ExecState *, const Identifier &, PropertyDescriptor &) override;
0041     void put(ExecState *, const Identifier &propertyName, JSValue *, int attributes = None) override;
0042     void put(ExecState *, unsigned propertyName, JSValue *, int attributes = None) override;
0043     bool deleteProperty(ExecState *, const Identifier &propertyName) override;
0044     bool deleteProperty(ExecState *, unsigned propertyName) override;
0045     void getOwnPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode) override;
0046 
0047     bool defineOwnProperty(ExecState *exec, const Identifier &propertyName, PropertyDescriptor &desc, bool shouldThrow) override;
0048     void mark() override;
0049 
0050     bool getPropertyAttributes(const Identifier &propertyName, unsigned &attributes) const override;
0051 
0052     JSValue *getDirect(const Identifier &propertyName) const override;
0053 
0054     virtual void putDirect(unsigned index, JSValue *value, int attr = 0);
0055     void putDirect(const Identifier &propertyName, JSValue *value, int attr = 0) override;
0056     void putDirect(const Identifier &propertyName, int value, int attr = 0) override;
0057 
0058     void removeDirect(const Identifier &propertyName) override;
0059 
0060     const ClassInfo *classInfo() const override
0061     {
0062         return &info;
0063     }
0064     static const ClassInfo info;
0065 
0066     unsigned getLength() const
0067     {
0068         return m_length;
0069     }
0070     JSValue *getItem(unsigned) const;
0071 
0072     void sort(ExecState *);
0073     void sort(ExecState *, JSObject *compareFunction);
0074 
0075 private:
0076     static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &);
0077     bool inlineGetOwnPropertySlot(ExecState *, unsigned propertyName, PropertySlot &);
0078     inline struct ArrayEntity *getArrayEntity(unsigned) const;
0079 
0080     void setLength(unsigned);
0081     void increaseVectorLength(unsigned newLength);
0082 
0083     unsigned compactForSorting();
0084 
0085     unsigned m_length;
0086     unsigned m_vectorLength;
0087     ArrayStorage *m_storage;
0088 
0089     inline bool anyItemHasAttribute(unsigned attributes) const;
0090     uint32_t m_lengthAttributes;
0091 };
0092 
0093 } // namespace KJS
0094 
0095 #endif