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

0001 /*
0002     This file is part of the KDE libraries
0003     Copyright (C) 2012  Bernd Buschinski <b.buschinski@googlemail.com>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Lesser General Public
0007     License as published by the Free Software Foundation; either
0008     version 2.1 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public
0016     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0017 */
0018 
0019 #ifndef PROPERTYDESCRIPTOR_H
0020 #define PROPERTYDESCRIPTOR_H
0021 
0022 #include "global.h"
0023 #include "ustring.h"
0024 
0025 namespace KJS
0026 {
0027 
0028 class JSObject;
0029 class ExecState;
0030 
0031 class KJS_EXPORT PropertyDescriptor
0032 {
0033 public:
0034     PropertyDescriptor();
0035 
0036     bool isAccessorDescriptor() const;
0037     bool isDataDescriptor() const;
0038     bool isGenericDescriptor() const;
0039     JSObject *fromPropertyDescriptor(ExecState *exec);
0040     // Set the PropertyDescriptor given Javascript Object containing any of
0041     // value, get, set, enumerable, configurable, writeable
0042     bool setPropertyDescriptorFromObject(ExecState *exec, JSValue *obj);
0043     // Set the PropertyDescriptor from internal Object, given the value, which can be
0044     // a GetterSetterImpl and set attributes
0045     bool setPropertyDescriptorValues(ExecState *exec, JSValue *value, unsigned int attributes);
0046 
0047     bool enumerable() const;
0048     bool writable() const;
0049     bool configurable() const;
0050 
0051     // enumerableSet & co, true if setPropertyDescriptorFromObject contained
0052     // enumerable, configurable or writeable, if not false.
0053     bool enumerableSet() const;
0054     bool writableSet() const;
0055     bool configureSet() const;
0056 
0057     JSValue *value() const;
0058     JSValue *getter() const;
0059     JSValue *setter() const;
0060 
0061     void setEnumerable(bool enumerable);
0062     void setConfigureable(bool configurable);
0063     void setValue(JSValue *value);
0064     void setWritable(bool writable);
0065     void setGetter(JSValue *getter);
0066     void setSetter(JSValue *setter);
0067 
0068     unsigned int attributes() const;
0069 
0070     bool isEmpty() const;
0071 
0072     // Comapred PropertyDescriptor in terms of its value. It compared the Attributes
0073     // but not if these values are explicitly set. Also the check is difference
0074     // in comparing the getter/setter. They are compared if they need to be updated,
0075     // not only if they have the same value.
0076     bool equalTo(ExecState *exec, PropertyDescriptor &other) const;
0077 
0078     // This function gives new Attributes calculation from current and other
0079     // PropertyDescriptor. New Attributes are set depending if Descriptor has
0080     // enumerable/writeable/configurableSet, if absent default is used.
0081     // NOTE: As interval have enumerable/writable/configurable always set and
0082     // javascript object don't, the order matters here.
0083     // In this case the correct order is: current.attributesWithOverride(new)
0084     // where new is the javascript object that might not have all attributes set.
0085     unsigned int attributesWithOverride(PropertyDescriptor &other) const;
0086 
0087 private:
0088     // Check if PropertyDescriptor really is the same. This is private for
0089     // internal use only, so that it will not easily be confused with equalTo.
0090     // This function does compared set Attributes.
0091     bool operator==(PropertyDescriptor &other) const;
0092 
0093     unsigned int m_attributes;
0094     unsigned int m_setAttributes;
0095     enum { WritableSet = 1 << 0, EnumerableSet = 1 << 1, ConfigurableSet = 1 << 2 };
0096 
0097     JSValue *m_value;
0098     JSValue *m_getter;
0099     JSValue *m_setter;
0100 };
0101 
0102 }
0103 
0104 #endif // PROPERTYDESCRIPTOR_H