ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 18b4eab | 2018-03-31 07:04:00 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2018 Apple Inc. All rights reserved. |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 3 | * |
| 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.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 17 | * 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.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 27 | |
oliver@apple.com | 6884841 | 2014-01-02 20:56:20 +0000 | [diff] [blame] | 28 | #include "JSCJSValue.h" |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 29 | #include "PropertySlot.h" |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 30 | #include <wtf/Assertions.h> |
| 31 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 32 | namespace JSC { |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 33 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 34 | class JSObject; |
| 35 | class JSFunction; |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 36 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 37 | class PutPropertySlot { |
| 38 | public: |
barraclough@apple.com | 674f9cb | 2016-02-09 21:19:59 +0000 | [diff] [blame] | 39 | enum Type { Uncachable, ExistingProperty, NewProperty, SetterProperty, CustomValue, CustomAccessor }; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 40 | enum Context { UnknownContext, PutById, PutByIdEval }; |
utatane.tea@gmail.com | 78b50c6 | 2016-03-11 17:28:46 +0000 | [diff] [blame] | 41 | typedef bool (*PutValueFunc)(ExecState*, EncodedJSValue thisObject, EncodedJSValue value); |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 42 | |
saambarati1@gmail.com | 060e751 | 2015-09-03 19:45:44 +0000 | [diff] [blame] | 43 | PutPropertySlot(JSValue thisValue, bool isStrictMode = false, Context context = UnknownContext, bool isInitialization = false) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 44 | : m_type(Uncachable) |
| 45 | , m_base(0) |
| 46 | , m_thisValue(thisValue) |
fpizlo@apple.com | b22d111 | 2015-08-04 01:14:38 +0000 | [diff] [blame] | 47 | , m_offset(invalidOffset) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 48 | , m_isStrictMode(isStrictMode) |
saambarati1@gmail.com | 060e751 | 2015-09-03 19:45:44 +0000 | [diff] [blame] | 49 | , m_isInitialization(isInitialization) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 50 | , m_context(context) |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 51 | , m_cacheability(CachingAllowed) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 52 | { |
| 53 | } |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 54 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 55 | void setExistingProperty(JSObject* base, PropertyOffset offset) |
| 56 | { |
| 57 | m_type = ExistingProperty; |
| 58 | m_base = base; |
| 59 | m_offset = offset; |
| 60 | } |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 61 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 62 | void setNewProperty(JSObject* base, PropertyOffset offset) |
| 63 | { |
| 64 | m_type = NewProperty; |
| 65 | m_base = base; |
| 66 | m_offset = offset; |
| 67 | } |
oliver@apple.com | 6884841 | 2014-01-02 20:56:20 +0000 | [diff] [blame] | 68 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 69 | void setCustomValue(JSObject* base, FunctionPtr<OperationPtrTag> function) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 70 | { |
barraclough@apple.com | 674f9cb | 2016-02-09 21:19:59 +0000 | [diff] [blame] | 71 | m_type = CustomValue; |
| 72 | m_base = base; |
| 73 | m_putFunction = function; |
| 74 | } |
| 75 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 76 | void setCustomAccessor(JSObject* base, FunctionPtr<OperationPtrTag> function) |
barraclough@apple.com | 674f9cb | 2016-02-09 21:19:59 +0000 | [diff] [blame] | 77 | { |
| 78 | m_type = CustomAccessor; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 79 | m_base = base; |
| 80 | m_putFunction = function; |
| 81 | } |
fpizlo@apple.com | 1d55d36 | 2014-04-08 19:39:55 +0000 | [diff] [blame] | 82 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 83 | void setCacheableSetter(JSObject* base, PropertyOffset offset) |
| 84 | { |
| 85 | m_type = SetterProperty; |
| 86 | m_base = base; |
| 87 | m_offset = offset; |
| 88 | } |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 89 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 90 | void setThisValue(JSValue thisValue) |
| 91 | { |
| 92 | m_thisValue = thisValue; |
| 93 | } |
oliver@apple.com | 11ce5ff | 2014-03-06 21:27:13 +0000 | [diff] [blame] | 94 | |
cdumez@apple.com | b35e2be | 2016-03-04 06:00:02 +0000 | [diff] [blame] | 95 | void setStrictMode(bool value) |
| 96 | { |
| 97 | m_isStrictMode = value; |
| 98 | } |
| 99 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 100 | FunctionPtr<OperationPtrTag> customSetter() const |
barraclough@apple.com | 674f9cb | 2016-02-09 21:19:59 +0000 | [diff] [blame] | 101 | { |
| 102 | ASSERT(isCacheableCustom()); |
| 103 | return m_putFunction; |
| 104 | } |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 105 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 106 | Context context() const { return static_cast<Context>(m_context); } |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 107 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 108 | Type type() const { return m_type; } |
| 109 | JSObject* base() const { return m_base; } |
| 110 | JSValue thisValue() const { return m_thisValue; } |
oliver@apple.com | 11ce5ff | 2014-03-06 21:27:13 +0000 | [diff] [blame] | 111 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 112 | bool isStrictMode() const { return m_isStrictMode; } |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 113 | 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.com | 060e751 | 2015-09-03 19:45:44 +0000 | [diff] [blame] | 117 | bool isInitialization() const { return m_isInitialization; } |
ggaren@apple.com | 22b5daa | 2011-03-14 00:34:32 +0000 | [diff] [blame] | 118 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 119 | PropertyOffset cachedOffset() const |
| 120 | { |
| 121 | return m_offset; |
| 122 | } |
oliver@apple.com | 6884841 | 2014-01-02 20:56:20 +0000 | [diff] [blame] | 123 | |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 124 | void disableCaching() |
| 125 | { |
| 126 | m_cacheability = CachingDisallowed; |
| 127 | } |
| 128 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 129 | private: |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 130 | bool isCacheable() const { return m_cacheability == CachingAllowed; } |
| 131 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 132 | Type m_type; |
| 133 | JSObject* m_base; |
| 134 | JSValue m_thisValue; |
| 135 | PropertyOffset m_offset; |
| 136 | bool m_isStrictMode; |
saambarati1@gmail.com | 060e751 | 2015-09-03 19:45:44 +0000 | [diff] [blame] | 137 | bool m_isInitialization; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 138 | uint8_t m_context; |
utatane.tea@gmail.com | b449aac | 2016-03-16 13:59:43 +0000 | [diff] [blame] | 139 | CacheabilityType m_cacheability; |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 140 | FunctionPtr<OperationPtrTag> m_putFunction; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 141 | }; |
ggaren@apple.com | 8d8ff6a | 2008-09-03 02:31:45 +0000 | [diff] [blame] | 142 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 143 | } // namespace JSC |