diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/PropertyDescriptor.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/runtime/PropertyDescriptor.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/PropertyDescriptor.h | 150 |
1 files changed, 88 insertions, 62 deletions
diff --git a/Source/JavaScriptCore/runtime/PropertyDescriptor.h b/Source/JavaScriptCore/runtime/PropertyDescriptor.h index 2cc95fb21..eb461d36f 100644 --- a/Source/JavaScriptCore/runtime/PropertyDescriptor.h +++ b/Source/JavaScriptCore/runtime/PropertyDescriptor.h @@ -23,74 +23,100 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef PropertyDescriptor_h -#define PropertyDescriptor_h +#pragma once +#include "DefinePropertyAttributes.h" #include "JSCJSValue.h" namespace JSC { - class GetterSetter; - // See ES5.1 9.12 - bool sameValue(ExecState*, JSValue, JSValue); +class GetterSetter; - class PropertyDescriptor { - public: - PropertyDescriptor() - : m_attributes(defaultAttributes) - , m_seenAttributes(0) - { - } - PropertyDescriptor(JSValue value, unsigned attributes) - : m_value(value) - , m_attributes(attributes) - , m_seenAttributes(EnumerablePresent | ConfigurablePresent | WritablePresent) - { - ASSERT(m_value); - ASSERT(!m_value.isGetterSetter()); - } - JS_EXPORT_PRIVATE bool writable() const; - JS_EXPORT_PRIVATE bool enumerable() const; - JS_EXPORT_PRIVATE bool configurable() const; - JS_EXPORT_PRIVATE bool isDataDescriptor() const; - bool isGenericDescriptor() const; - JS_EXPORT_PRIVATE bool isAccessorDescriptor() const; - unsigned attributes() const { return m_attributes; } - JSValue value() const { return m_value; } - JS_EXPORT_PRIVATE JSValue getter() const; - JS_EXPORT_PRIVATE JSValue setter() const; - JSObject* getterObject() const; - JSObject* setterObject() const; - JS_EXPORT_PRIVATE void setUndefined(); - JS_EXPORT_PRIVATE void setDescriptor(JSValue value, unsigned attributes); - JS_EXPORT_PRIVATE void setAccessorDescriptor(GetterSetter* accessor, unsigned attributes); - JS_EXPORT_PRIVATE void setWritable(bool); - JS_EXPORT_PRIVATE void setEnumerable(bool); - JS_EXPORT_PRIVATE void setConfigurable(bool); - void setValue(JSValue value) { m_value = value; } - JS_EXPORT_PRIVATE void setSetter(JSValue); - JS_EXPORT_PRIVATE void setGetter(JSValue); - bool isEmpty() const { return !(m_value || m_getter || m_setter || m_seenAttributes); } - bool writablePresent() const { return m_seenAttributes & WritablePresent; } - bool enumerablePresent() const { return m_seenAttributes & EnumerablePresent; } - bool configurablePresent() const { return m_seenAttributes & ConfigurablePresent; } - bool setterPresent() const { return m_setter; } - bool getterPresent() const { return m_getter; } - bool equalTo(ExecState* exec, const PropertyDescriptor& other) const; - bool attributesEqual(const PropertyDescriptor& other) const; - unsigned attributesOverridingCurrent(const PropertyDescriptor& current) const; +class PropertyDescriptor { +public: + PropertyDescriptor() + : m_attributes(defaultAttributes) + , m_seenAttributes(0) + { + } + PropertyDescriptor(JSValue value, unsigned attributes) + : m_value(value) + , m_attributes(attributes) + , m_seenAttributes(EnumerablePresent | ConfigurablePresent | WritablePresent) + { + ASSERT(m_value); + ASSERT(!m_value.isGetterSetter()); + ASSERT(!m_value.isCustomGetterSetter()); + } + JS_EXPORT_PRIVATE bool writable() const; + JS_EXPORT_PRIVATE bool enumerable() const; + JS_EXPORT_PRIVATE bool configurable() const; + JS_EXPORT_PRIVATE bool isDataDescriptor() const; + bool isGenericDescriptor() const; + JS_EXPORT_PRIVATE bool isAccessorDescriptor() const; + unsigned attributes() const { return m_attributes; } + JSValue value() const { return m_value; } + GetterSetter* slowGetterSetter(ExecState*); // Be aware that this will lazily allocate a GetterSetter object. It's much better to use getter() and setter() individually if possible. + JS_EXPORT_PRIVATE JSValue getter() const; + JS_EXPORT_PRIVATE JSValue setter() const; + JSObject* getterObject() const; + JSObject* setterObject() const; + JS_EXPORT_PRIVATE void setUndefined(); + JS_EXPORT_PRIVATE void setDescriptor(JSValue, unsigned attributes); + JS_EXPORT_PRIVATE void setCustomDescriptor(unsigned attributes); + JS_EXPORT_PRIVATE void setAccessorDescriptor(GetterSetter* accessor, unsigned attributes); + JS_EXPORT_PRIVATE void setWritable(bool); + JS_EXPORT_PRIVATE void setEnumerable(bool); + JS_EXPORT_PRIVATE void setConfigurable(bool); + void setValue(JSValue value) { m_value = value; } + JS_EXPORT_PRIVATE void setSetter(JSValue); + JS_EXPORT_PRIVATE void setGetter(JSValue); + bool isEmpty() const { return !(m_value || m_getter || m_setter || m_seenAttributes); } + bool writablePresent() const { return m_seenAttributes & WritablePresent; } + bool enumerablePresent() const { return m_seenAttributes & EnumerablePresent; } + bool configurablePresent() const { return m_seenAttributes & ConfigurablePresent; } + bool setterPresent() const { return !!m_setter; } + bool getterPresent() const { return !!m_getter; } + bool equalTo(ExecState*, const PropertyDescriptor& other) const; + bool attributesEqual(const PropertyDescriptor& other) const; + unsigned attributesOverridingCurrent(const PropertyDescriptor& current) const; - private: - JS_EXPORTDATA static unsigned defaultAttributes; - bool operator==(const PropertyDescriptor&){ return false; } - enum { WritablePresent = 1, EnumerablePresent = 2, ConfigurablePresent = 4}; - // May be a getter/setter - JSValue m_value; - JSValue m_getter; - JSValue m_setter; - unsigned m_attributes; - unsigned m_seenAttributes; - }; +private: + JS_EXPORTDATA static unsigned defaultAttributes; + bool operator==(const PropertyDescriptor&) { return false; } + enum { WritablePresent = 1, EnumerablePresent = 2, ConfigurablePresent = 4}; + // May be a getter/setter + JSValue m_value; + JSValue m_getter; + JSValue m_setter; + unsigned m_attributes; + unsigned m_seenAttributes; +}; + +inline PropertyDescriptor toPropertyDescriptor(JSValue value, JSValue getter, JSValue setter, DefinePropertyAttributes attributes) +{ + // We assume that validation is already done. + PropertyDescriptor desc; + + if (std::optional<bool> enumerable = attributes.enumerable()) + desc.setEnumerable(enumerable.value()); + + if (std::optional<bool> configurable = attributes.configurable()) + desc.setConfigurable(configurable.value()); + + if (attributes.hasValue()) + desc.setValue(value); + + if (std::optional<bool> writable = attributes.writable()) + desc.setWritable(writable.value()); + + if (attributes.hasGet()) + desc.setGetter(getter); + + if (attributes.hasSet()) + desc.setSetter(setter); + + return desc; } -#endif +} |