PropertyDescriptor.h 4.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright (C) 2009 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef PropertyDescriptor_h
#define PropertyDescriptor_h

29
#include "JSCJSValue.h"
30 31

namespace JSC {
32 33
    class GetterSetter;

34 35 36
    // See ES5.1 9.12
    bool sameValue(ExecState*, JSValue, JSValue);

37 38 39
    class PropertyDescriptor {
    public:
        PropertyDescriptor()
40 41
            : m_attributes(defaultAttributes)
            , m_seenAttributes(0)
42 43
        {
        }
44 45 46 47 48 49 50 51
        PropertyDescriptor(JSValue value, unsigned attributes)
            : m_value(value)
            , m_attributes(attributes)
            , m_seenAttributes(EnumerablePresent | ConfigurablePresent | WritablePresent)
        {
            ASSERT(m_value);
            ASSERT(!m_value.isGetterSetter());
        }
52 53 54 55
        JS_EXPORT_PRIVATE bool writable() const;
        JS_EXPORT_PRIVATE bool enumerable() const;
        JS_EXPORT_PRIVATE bool configurable() const;
        JS_EXPORT_PRIVATE bool isDataDescriptor() const;
56
        bool isGenericDescriptor() const;
57
        JS_EXPORT_PRIVATE bool isAccessorDescriptor() const;
58
        unsigned attributes() const { return m_attributes; }
59
        JSValue value() const { return m_value; }
60 61
        JS_EXPORT_PRIVATE JSValue getter() const;
        JS_EXPORT_PRIVATE JSValue setter() const;
62 63
        JSObject* getterObject() const;
        JSObject* setterObject() const;
64 65
        JS_EXPORT_PRIVATE void setUndefined();
        JS_EXPORT_PRIVATE void setDescriptor(JSValue value, unsigned attributes);
66
        JS_EXPORT_PRIVATE void setAccessorDescriptor(GetterSetter* accessor, unsigned attributes);
67 68 69
        JS_EXPORT_PRIVATE void setWritable(bool);
        JS_EXPORT_PRIVATE void setEnumerable(bool);
        JS_EXPORT_PRIVATE void setConfigurable(bool);
70
        void setValue(JSValue value) { m_value = value; }
71 72
        JS_EXPORT_PRIVATE void setSetter(JSValue);
        JS_EXPORT_PRIVATE void setGetter(JSValue);
73 74 75 76 77 78
        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; }
79
        bool equalTo(ExecState* exec, const PropertyDescriptor& other) const;
80
        bool attributesEqual(const PropertyDescriptor& other) const;
81 82
        unsigned attributesOverridingCurrent(const PropertyDescriptor& current) const;

83
    private:
84
        JS_EXPORTDATA static unsigned defaultAttributes;
85 86
        bool operator==(const PropertyDescriptor&){ return false; }
        enum { WritablePresent = 1, EnumerablePresent = 2, ConfigurablePresent = 4};
87 88 89 90 91
        // May be a getter/setter
        JSValue m_value;
        JSValue m_getter;
        JSValue m_setter;
        unsigned m_attributes;
92
        unsigned m_seenAttributes;
93 94 95 96
    };
}

#endif