]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/GetByIdVariant.cpp
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.
27 #include "GetByIdVariant.h"
29 #include "CallLinkStatus.h"
30 #include "JSCInlines.h"
31 #include <wtf/ListDump.h>
35 GetByIdVariant::GetByIdVariant(
36 const StructureSet
& structureSet
, PropertyOffset offset
,
37 const IntendedStructureChain
* chain
, std::unique_ptr
<CallLinkStatus
> callLinkStatus
)
38 : m_structureSet(structureSet
)
39 , m_alternateBase(nullptr)
41 , m_callLinkStatus(WTF::move(callLinkStatus
))
43 if (!structureSet
.size()) {
44 ASSERT(offset
== invalidOffset
);
48 if (chain
&& chain
->size()) {
49 m_alternateBase
= chain
->terminalPrototype();
50 chain
->gatherChecks(m_constantChecks
);
54 GetByIdVariant::~GetByIdVariant() { }
56 GetByIdVariant::GetByIdVariant(const GetByIdVariant
& other
)
62 GetByIdVariant
& GetByIdVariant::operator=(const GetByIdVariant
& other
)
64 m_structureSet
= other
.m_structureSet
;
65 m_constantChecks
= other
.m_constantChecks
;
66 m_alternateBase
= other
.m_alternateBase
;
67 m_offset
= other
.m_offset
;
68 if (other
.m_callLinkStatus
)
69 m_callLinkStatus
= std::make_unique
<CallLinkStatus
>(*other
.m_callLinkStatus
);
71 m_callLinkStatus
= nullptr;
75 StructureSet
GetByIdVariant::baseStructure() const
78 return structureSet();
80 Structure
* structure
= structureFor(m_constantChecks
, m_alternateBase
);
81 RELEASE_ASSERT(structure
);
85 bool GetByIdVariant::attemptToMerge(const GetByIdVariant
& other
)
87 if (m_alternateBase
!= other
.m_alternateBase
)
89 if (m_offset
!= other
.m_offset
)
91 if (m_callLinkStatus
|| other
.m_callLinkStatus
)
93 if (!areCompatible(m_constantChecks
, other
.m_constantChecks
))
96 mergeInto(other
.m_constantChecks
, m_constantChecks
);
97 m_structureSet
.merge(other
.m_structureSet
);
102 void GetByIdVariant::dump(PrintStream
& out
) const
104 dumpInContext(out
, 0);
107 void GetByIdVariant::dumpInContext(PrintStream
& out
, DumpContext
* context
) const
110 out
.print("<empty>");
115 "<", inContext(structureSet(), context
), ", ",
116 "[", listDumpInContext(m_constantChecks
, context
), "]");
118 out
.print(", alternateBase = ", inContext(JSValue(m_alternateBase
), context
));
119 out
.print(", offset = ", offset());
120 if (m_callLinkStatus
)
121 out
.print(", call = ", *m_callLinkStatus
);