1 | /* |
---|---|

2 | * Copyright (C) 2008-2015 Apple Inc. All rights reserved. |

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 | * |

13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |

14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |

15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |

16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |

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 | |

26 | #ifndef PutPropertySlot_h |

27 | #define PutPropertySlot_h |

28 | |

29 | #include "JSCJSValue.h" |

30 | #include "PropertyOffset.h" |

31 | |

32 | #include <wtf/Assertions.h> |

33 | |

34 | namespace JSC { |

35 | |

36 | class JSObject; |

37 | class JSFunction; |

38 | |

39 | class PutPropertySlot { |

40 | public: |

41 | enum Type { Uncachable, ExistingProperty, NewProperty, SetterProperty, CustomValue, CustomAccessor }; |

42 | enum Context { UnknownContext, PutById, PutByIdEval }; |

43 | typedef void (*PutValueFunc)(ExecState*, EncodedJSValue thisObject, EncodedJSValue value); |

44 | |

45 | PutPropertySlot(JSValue thisValue, bool isStrictMode = false, Context context = UnknownContext, bool isInitialization = false) |

46 | : m_type(Uncachable) |

47 | , m_base(0) |

48 | , m_thisValue(thisValue) |

49 | , m_offset(invalidOffset) |

50 | , m_isStrictMode(isStrictMode) |

51 | , m_isInitialization(isInitialization) |

52 | , m_context(context) |

53 | , m_putFunction(nullptr) |

54 | { |

55 | } |

56 | |

57 | void setExistingProperty(JSObject* base, PropertyOffset offset) |

58 | { |

59 | m_type = ExistingProperty; |

60 | m_base = base; |

61 | m_offset = offset; |

62 | } |

63 | |

64 | void setNewProperty(JSObject* base, PropertyOffset offset) |

65 | { |

66 | m_type = NewProperty; |

67 | m_base = base; |

68 | m_offset = offset; |

69 | } |

70 | |

71 | void setCustomValue(JSObject* base, PutValueFunc function) |

72 | { |

73 | m_type = CustomValue; |

74 | m_base = base; |

75 | m_putFunction = function; |

76 | } |

77 | |

78 | void setCustomAccessor(JSObject* base, PutValueFunc function) |

79 | { |

80 | m_type = CustomAccessor; |

81 | m_base = base; |

82 | m_putFunction = function; |

83 | } |

84 | |

85 | void setCacheableSetter(JSObject* base, PropertyOffset offset) |

86 | { |

87 | m_type = SetterProperty; |

88 | m_base = base; |

89 | m_offset = offset; |

90 | } |

91 | |

92 | void setThisValue(JSValue thisValue) |

93 | { |

94 | m_thisValue = thisValue; |

95 | } |

96 | |

97 | PutValueFunc customSetter() const |

98 | { |

99 | ASSERT(isCacheableCustom()); |

100 | return m_putFunction; |

101 | } |

102 | |

103 | Context context() const { return static_cast<Context>(m_context); } |

104 | |

105 | Type type() const { return m_type; } |

106 | JSObject* base() const { return m_base; } |

107 | JSValue thisValue() const { return m_thisValue; } |

108 | |

109 | bool isStrictMode() const { return m_isStrictMode; } |

110 | bool isCacheablePut() const { return m_type == NewProperty || m_type == ExistingProperty; } |

111 | bool isCacheableSetter() const { return m_type == SetterProperty; } |

112 | bool isCacheableCustom() const { return m_type == CustomValue || m_type == CustomAccessor; } |

113 | bool isCustomAccessor() const { return m_type == CustomAccessor; } |

114 | bool isInitialization() const { return m_isInitialization; } |

115 | |

116 | PropertyOffset cachedOffset() const |

117 | { |

118 | return m_offset; |

119 | } |

120 | |

121 | private: |

122 | Type m_type; |

123 | JSObject* m_base; |

124 | JSValue m_thisValue; |

125 | PropertyOffset m_offset; |

126 | bool m_isStrictMode; |

127 | bool m_isInitialization; |

128 | uint8_t m_context; |

129 | PutValueFunc m_putFunction; |

130 | }; |

131 | |

132 | } // namespace JSC |

133 | |

134 | #endif // PutPropertySlot_h |

135 |