]> git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/GetByIdVariant.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / GetByIdVariant.cpp
1 /*
2 * Copyright (C) 2014 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 #include "config.h"
27 #include "GetByIdVariant.h"
28
29 #include "CallLinkStatus.h"
30 #include "JSCInlines.h"
31 #include <wtf/ListDump.h>
32
33 namespace JSC {
34
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)
40 , m_offset(offset)
41 , m_callLinkStatus(WTF::move(callLinkStatus))
42 {
43 if (!structureSet.size()) {
44 ASSERT(offset == invalidOffset);
45 ASSERT(!chain);
46 }
47
48 if (chain && chain->size()) {
49 m_alternateBase = chain->terminalPrototype();
50 chain->gatherChecks(m_constantChecks);
51 }
52 }
53
54 GetByIdVariant::~GetByIdVariant() { }
55
56 GetByIdVariant::GetByIdVariant(const GetByIdVariant& other)
57 : GetByIdVariant()
58 {
59 *this = other;
60 }
61
62 GetByIdVariant& GetByIdVariant::operator=(const GetByIdVariant& other)
63 {
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);
70 else
71 m_callLinkStatus = nullptr;
72 return *this;
73 }
74
75 StructureSet GetByIdVariant::baseStructure() const
76 {
77 if (!m_alternateBase)
78 return structureSet();
79
80 Structure* structure = structureFor(m_constantChecks, m_alternateBase);
81 RELEASE_ASSERT(structure);
82 return structure;
83 }
84
85 bool GetByIdVariant::attemptToMerge(const GetByIdVariant& other)
86 {
87 if (m_alternateBase != other.m_alternateBase)
88 return false;
89 if (m_offset != other.m_offset)
90 return false;
91 if (m_callLinkStatus || other.m_callLinkStatus)
92 return false;
93 if (!areCompatible(m_constantChecks, other.m_constantChecks))
94 return false;
95
96 mergeInto(other.m_constantChecks, m_constantChecks);
97 m_structureSet.merge(other.m_structureSet);
98
99 return true;
100 }
101
102 void GetByIdVariant::dump(PrintStream& out) const
103 {
104 dumpInContext(out, 0);
105 }
106
107 void GetByIdVariant::dumpInContext(PrintStream& out, DumpContext* context) const
108 {
109 if (!isSet()) {
110 out.print("<empty>");
111 return;
112 }
113
114 out.print(
115 "<", inContext(structureSet(), context), ", ",
116 "[", listDumpInContext(m_constantChecks, context), "]");
117 if (m_alternateBase)
118 out.print(", alternateBase = ", inContext(JSValue(m_alternateBase), context));
119 out.print(", offset = ", offset());
120 if (m_callLinkStatus)
121 out.print(", call = ", *m_callLinkStatus);
122 out.print(">");
123 }
124
125 } // namespace JSC
126