]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/PutPropertySlot.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / PutPropertySlot.h
CommitLineData
9dae56ea
A
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
81345200 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
9dae56ea
A
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
81345200 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
9dae56ea
A
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef PutPropertySlot_h
28#define PutPropertySlot_h
29
81345200 30#include "JSCJSValue.h"
ed1e77d3 31#include "PropertyOffset.h"
81345200 32
9dae56ea
A
33#include <wtf/Assertions.h>
34
35namespace JSC {
36
ed1e77d3
A
37class JSObject;
38class JSFunction;
9dae56ea 39
ed1e77d3
A
40class PutPropertySlot {
41public:
42 enum Type { Uncachable, ExistingProperty, NewProperty, SetterProperty, CustomProperty };
43 enum Context { UnknownContext, PutById, PutByIdEval };
44 typedef void (*PutValueFunc)(ExecState*, JSObject* base, EncodedJSValue thisObject, EncodedJSValue value);
45
46 PutPropertySlot(JSValue thisValue, bool isStrictMode = false, Context context = UnknownContext)
47 : m_type(Uncachable)
48 , m_base(0)
49 , m_thisValue(thisValue)
50 , m_isStrictMode(isStrictMode)
51 , m_context(context)
52 , m_putFunction(nullptr)
53 {
54 }
55
56 void setExistingProperty(JSObject* base, PropertyOffset offset)
57 {
58 m_type = ExistingProperty;
59 m_base = base;
60 m_offset = offset;
61 }
62
63 void setNewProperty(JSObject* base, PropertyOffset offset)
64 {
65 m_type = NewProperty;
66 m_base = base;
67 m_offset = offset;
68 }
69
70 void setCustomProperty(JSObject* base, PutValueFunc function)
71 {
72 m_type = CustomProperty;
73 m_base = base;
74 m_putFunction = function;
75 }
76
77 void setCacheableSetter(JSObject* base, PropertyOffset offset)
78 {
79 m_type = SetterProperty;
80 m_base = base;
81 m_offset = offset;
82 }
83
84 void setThisValue(JSValue thisValue)
85 {
86 m_thisValue = thisValue;
87 }
88
89 PutValueFunc customSetter() const { return m_putFunction; }
90
91 Context context() const { return static_cast<Context>(m_context); }
92
93 Type type() const { return m_type; }
94 JSObject* base() const { return m_base; }
95 JSValue thisValue() const { return m_thisValue; }
96
97 bool isStrictMode() const { return m_isStrictMode; }
98 bool isCacheablePut() const { return m_type == NewProperty || m_type == ExistingProperty; }
99 bool isCacheableSetter() const { return m_type == SetterProperty; }
100 bool isCacheableCustom() const { return m_type == CustomProperty; }
101
102 PropertyOffset cachedOffset() const
103 {
104 return m_offset;
105 }
106
107private:
108 Type m_type;
109 JSObject* m_base;
110 JSValue m_thisValue;
111 PropertyOffset m_offset;
112 bool m_isStrictMode;
113 uint8_t m_context;
114 PutValueFunc m_putFunction;
115};
9dae56ea
A
116
117} // namespace JSC
118
119#endif // PutPropertySlot_h