1 /* 2 This file is part of the KDE libraries 3 Copyright (C) 2012 Bernd Buschinski <b.buschinski@googlemail.com> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef PROPERTYDESCRIPTOR_H 20 #define PROPERTYDESCRIPTOR_H 21 22 #include "global.h" 23 #include "ustring.h" 24 25 namespace KJS 26 { 27 28 class JSObject; 29 class ExecState; 30 31 class KJS_EXPORT PropertyDescriptor 32 { 33 public: 34 PropertyDescriptor(); 35 36 bool isAccessorDescriptor() const; 37 bool isDataDescriptor() const; 38 bool isGenericDescriptor() const; 39 JSObject *fromPropertyDescriptor(ExecState *exec); 40 // Set the PropertyDescriptor given Javascript Object containing any of 41 // value, get, set, enumerable, configurable, writeable 42 bool setPropertyDescriptorFromObject(ExecState *exec, JSValue *obj); 43 // Set the PropertyDescriptor from internal Object, given the value, which can be 44 // a GetterSetterImpl and set attributes 45 bool setPropertyDescriptorValues(ExecState *exec, JSValue *value, unsigned int attributes); 46 47 bool enumerable() const; 48 bool writable() const; 49 bool configurable() const; 50 51 // enumerableSet & co, true if setPropertyDescriptorFromObject contained 52 // enumerable, configurable or writeable, if not false. 53 bool enumerableSet() const; 54 bool writableSet() const; 55 bool configureSet() const; 56 57 JSValue *value() const; 58 JSValue *getter() const; 59 JSValue *setter() const; 60 61 void setEnumerable(bool enumerable); 62 void setConfigureable(bool configurable); 63 void setValue(JSValue *value); 64 void setWritable(bool writable); 65 void setGetter(JSValue *getter); 66 void setSetter(JSValue *setter); 67 68 unsigned int attributes() const; 69 70 bool isEmpty() const; 71 72 // Comapred PropertyDescriptor in terms of its value. It compared the Attributes 73 // but not if these values are explicitly set. Also the check is difference 74 // in comparing the getter/setter. They are compared if they need to be updated, 75 // not only if they have the same value. 76 bool equalTo(ExecState *exec, PropertyDescriptor &other) const; 77 78 // This function gives new Attributes calculation from current and other 79 // PropertyDescriptor. New Attributes are set depending if Descriptor has 80 // enumerable/writeable/configurableSet, if absent default is used. 81 // NOTE: As interval have enumerable/writable/configurable always set and 82 // javascript object don't, the order matters here. 83 // In this case the correct order is: current.attributesWithOverride(new) 84 // where new is the javascript object that might not have all attributes set. 85 unsigned int attributesWithOverride(PropertyDescriptor &other) const; 86 87 private: 88 // Check if PropertyDescriptor really is the same. This is private for 89 // internal use only, so that it will not easily be confused with equalTo. 90 // This function does compared set Attributes. 91 bool operator==(PropertyDescriptor &other) const; 92 93 unsigned int m_attributes; 94 unsigned int m_setAttributes; 95 enum { WritableSet = 1 << 0, EnumerableSet = 1 << 1, ConfigurableSet = 1 << 2 }; 96 97 JSValue *m_value; 98 JSValue *m_getter; 99 JSValue *m_setter; 100 }; 101 102 } 103 104 #endif // PROPERTYDESCRIPTOR_H 105