blob: be4daf7f76d317411045e7c5e2400c5b9523b968 [file] [log] [blame]
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +00001/*
mark.lam@apple.com18b4eab2018-03-31 07:04:00 +00002 * Copyright (C) 2008-2018 Apple Inc. All rights reserved.
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
mjs@apple.com92047332014-03-15 04:08:27 +000013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000027
oliver@apple.com68848412014-01-02 20:56:20 +000028#include "JSCJSValue.h"
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +000029#include "PropertySlot.h"
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000030#include <wtf/Assertions.h>
31
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000032namespace JSC {
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000033
mark.lam@apple.com188640e2014-09-04 19:10:36 +000034class JSObject;
35class JSFunction;
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000036
mark.lam@apple.com188640e2014-09-04 19:10:36 +000037class PutPropertySlot {
38public:
barraclough@apple.com674f9cb2016-02-09 21:19:59 +000039 enum Type { Uncachable, ExistingProperty, NewProperty, SetterProperty, CustomValue, CustomAccessor };
mark.lam@apple.com188640e2014-09-04 19:10:36 +000040 enum Context { UnknownContext, PutById, PutByIdEval };
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +000041 typedef bool (*PutValueFunc)(ExecState*, EncodedJSValue thisObject, EncodedJSValue value);
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000042
saambarati1@gmail.com060e7512015-09-03 19:45:44 +000043 PutPropertySlot(JSValue thisValue, bool isStrictMode = false, Context context = UnknownContext, bool isInitialization = false)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000044 : m_type(Uncachable)
45 , m_base(0)
46 , m_thisValue(thisValue)
fpizlo@apple.comb22d1112015-08-04 01:14:38 +000047 , m_offset(invalidOffset)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000048 , m_isStrictMode(isStrictMode)
saambarati1@gmail.com060e7512015-09-03 19:45:44 +000049 , m_isInitialization(isInitialization)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000050 , m_context(context)
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +000051 , m_cacheability(CachingAllowed)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000052 {
53 }
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000054
mark.lam@apple.com188640e2014-09-04 19:10:36 +000055 void setExistingProperty(JSObject* base, PropertyOffset offset)
56 {
57 m_type = ExistingProperty;
58 m_base = base;
59 m_offset = offset;
60 }
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +000061
mark.lam@apple.com188640e2014-09-04 19:10:36 +000062 void setNewProperty(JSObject* base, PropertyOffset offset)
63 {
64 m_type = NewProperty;
65 m_base = base;
66 m_offset = offset;
67 }
oliver@apple.com68848412014-01-02 20:56:20 +000068
mark.lam@apple.comde0dba72018-04-18 03:31:09 +000069 void setCustomValue(JSObject* base, FunctionPtr<OperationPtrTag> function)
mark.lam@apple.com188640e2014-09-04 19:10:36 +000070 {
barraclough@apple.com674f9cb2016-02-09 21:19:59 +000071 m_type = CustomValue;
72 m_base = base;
73 m_putFunction = function;
74 }
75
mark.lam@apple.comde0dba72018-04-18 03:31:09 +000076 void setCustomAccessor(JSObject* base, FunctionPtr<OperationPtrTag> function)
barraclough@apple.com674f9cb2016-02-09 21:19:59 +000077 {
78 m_type = CustomAccessor;
mark.lam@apple.com188640e2014-09-04 19:10:36 +000079 m_base = base;
80 m_putFunction = function;
81 }
fpizlo@apple.com1d55d362014-04-08 19:39:55 +000082
mark.lam@apple.com188640e2014-09-04 19:10:36 +000083 void setCacheableSetter(JSObject* base, PropertyOffset offset)
84 {
85 m_type = SetterProperty;
86 m_base = base;
87 m_offset = offset;
88 }
mark.lam@apple.com268dda72014-08-29 00:48:59 +000089
mark.lam@apple.com188640e2014-09-04 19:10:36 +000090 void setThisValue(JSValue thisValue)
91 {
92 m_thisValue = thisValue;
93 }
oliver@apple.com11ce5ff2014-03-06 21:27:13 +000094
cdumez@apple.comb35e2be2016-03-04 06:00:02 +000095 void setStrictMode(bool value)
96 {
97 m_isStrictMode = value;
98 }
99
mark.lam@apple.comde0dba72018-04-18 03:31:09 +0000100 FunctionPtr<OperationPtrTag> customSetter() const
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000101 {
102 ASSERT(isCacheableCustom());
103 return m_putFunction;
104 }
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +0000105
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000106 Context context() const { return static_cast<Context>(m_context); }
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +0000107
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000108 Type type() const { return m_type; }
109 JSObject* base() const { return m_base; }
110 JSValue thisValue() const { return m_thisValue; }
oliver@apple.com11ce5ff2014-03-06 21:27:13 +0000111
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000112 bool isStrictMode() const { return m_isStrictMode; }
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +0000113 bool isCacheablePut() const { return isCacheable() && (m_type == NewProperty || m_type == ExistingProperty); }
114 bool isCacheableSetter() const { return isCacheable() && m_type == SetterProperty; }
115 bool isCacheableCustom() const { return isCacheable() && (m_type == CustomValue || m_type == CustomAccessor); }
116 bool isCustomAccessor() const { return isCacheable() && m_type == CustomAccessor; }
saambarati1@gmail.com060e7512015-09-03 19:45:44 +0000117 bool isInitialization() const { return m_isInitialization; }
ggaren@apple.com22b5daa2011-03-14 00:34:32 +0000118
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000119 PropertyOffset cachedOffset() const
120 {
121 return m_offset;
122 }
oliver@apple.com68848412014-01-02 20:56:20 +0000123
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +0000124 void disableCaching()
125 {
126 m_cacheability = CachingDisallowed;
127 }
128
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000129private:
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +0000130 bool isCacheable() const { return m_cacheability == CachingAllowed; }
131
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000132 Type m_type;
133 JSObject* m_base;
134 JSValue m_thisValue;
135 PropertyOffset m_offset;
136 bool m_isStrictMode;
saambarati1@gmail.com060e7512015-09-03 19:45:44 +0000137 bool m_isInitialization;
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000138 uint8_t m_context;
utatane.tea@gmail.comb449aac2016-03-16 13:59:43 +0000139 CacheabilityType m_cacheability;
mark.lam@apple.comde0dba72018-04-18 03:31:09 +0000140 FunctionPtr<OperationPtrTag> m_putFunction;
mark.lam@apple.com188640e2014-09-04 19:10:36 +0000141};
ggaren@apple.com8d8ff6a2008-09-03 02:31:45 +0000142
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000143} // namespace JSC