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