2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef PutByIdVariant_h
27 #define PutByIdVariant_h
29 #include "IntendedStructureChain.h"
30 #include "PropertyOffset.h"
31 #include "StructureSet.h"
37 class PutByIdVariant
{
48 , m_newStructure(nullptr)
49 , m_alternateBase(nullptr)
50 , m_offset(invalidOffset
)
54 PutByIdVariant(const PutByIdVariant
&);
55 PutByIdVariant
& operator=(const PutByIdVariant
&);
57 static PutByIdVariant
replace(
58 const StructureSet
& structure
, PropertyOffset offset
);
60 static PutByIdVariant
transition(
61 const StructureSet
& oldStructure
, Structure
* newStructure
,
62 const IntendedStructureChain
* structureChain
, PropertyOffset offset
);
64 static PutByIdVariant
setter(
65 const StructureSet
& structure
, PropertyOffset offset
,
66 IntendedStructureChain
* chain
, std::unique_ptr
<CallLinkStatus
> callLinkStatus
);
68 Kind
kind() const { return m_kind
; }
70 bool isSet() const { return kind() != NotSet
; }
71 bool operator!() const { return !isSet(); }
73 const StructureSet
& structure() const
75 ASSERT(kind() == Replace
|| kind() == Setter
);
76 return m_oldStructure
;
79 const StructureSet
& oldStructure() const
81 ASSERT(kind() == Transition
|| kind() == Replace
|| kind() == Setter
);
82 return m_oldStructure
;
85 StructureSet
& oldStructure()
87 ASSERT(kind() == Transition
|| kind() == Replace
|| kind() == Setter
);
88 return m_oldStructure
;
91 Structure
* oldStructureForTransition() const;
93 Structure
* newStructure() const
95 ASSERT(kind() == Transition
);
96 return m_newStructure
;
99 bool writesStructures() const;
100 bool reallocatesStorage() const;
101 bool makesCalls() const;
103 const ConstantStructureCheckVector
& constantChecks() const
105 return m_constantChecks
;
108 PropertyOffset
offset() const
114 JSObject
* alternateBase() const
116 ASSERT(kind() == Setter
);
117 return m_alternateBase
;
120 StructureSet
baseStructure() const;
122 CallLinkStatus
* callLinkStatus() const
124 ASSERT(kind() == Setter
);
125 return m_callLinkStatus
.get();
128 bool attemptToMerge(const PutByIdVariant
& other
);
130 void dump(PrintStream
&) const;
131 void dumpInContext(PrintStream
&, DumpContext
*) const;
134 bool attemptToMergeTransitionWithReplace(const PutByIdVariant
& replace
);
137 StructureSet m_oldStructure
;
138 Structure
* m_newStructure
;
139 ConstantStructureCheckVector m_constantChecks
;
140 JSObject
* m_alternateBase
;
141 PropertyOffset m_offset
;
142 std::unique_ptr
<CallLinkStatus
> m_callLinkStatus
;
147 #endif // PutByIdVariant_h