1/*
2 * Copyright (C) 2014-2018 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#pragma once
27
28#include "CallLinkStatus.h"
29#include "ObjectPropertyConditionSet.h"
30#include "PropertyOffset.h"
31#include "StructureSet.h"
32#include <wtf/Box.h>
33
34namespace JSC {
35namespace DOMJIT {
36class GetterSetter;
37}
38
39class CallLinkStatus;
40class GetByStatus;
41struct DumpContext;
42
43class GetByIdVariant {
44 WTF_MAKE_FAST_ALLOCATED;
45public:
46 GetByIdVariant(
47 Box<Identifier>,
48 const StructureSet& structureSet = StructureSet(), PropertyOffset offset = invalidOffset,
49 const ObjectPropertyConditionSet& = ObjectPropertyConditionSet(),
50 std::unique_ptr<CallLinkStatus> = nullptr,
51 JSFunction* = nullptr,
52 FunctionPtr<OperationPtrTag> customAccessorGetter = nullptr,
53 std::unique_ptr<DOMAttributeAnnotation> = nullptr);
54
55 ~GetByIdVariant();
56
57 GetByIdVariant(const GetByIdVariant&);
58 GetByIdVariant& operator=(const GetByIdVariant&);
59
60 bool isSet() const { return !!m_structureSet.size(); }
61 explicit operator bool() const { return isSet(); }
62 const StructureSet& structureSet() const { return m_structureSet; }
63 StructureSet& structureSet() { return m_structureSet; }
64
65 // A non-empty condition set means that this is a prototype load.
66 const ObjectPropertyConditionSet& conditionSet() const { return m_conditionSet; }
67
68 PropertyOffset offset() const { return m_offset; }
69 CallLinkStatus* callLinkStatus() const { return m_callLinkStatus.get(); }
70 JSFunction* intrinsicFunction() const { return m_intrinsicFunction; }
71 Intrinsic intrinsic() const { return m_intrinsicFunction ? m_intrinsicFunction->intrinsic() : NoIntrinsic; }
72 FunctionPtr<OperationPtrTag> customAccessorGetter() const { return m_customAccessorGetter; }
73 DOMAttributeAnnotation* domAttribute() const { return m_domAttribute.get(); }
74
75 bool isPropertyUnset() const { return offset() == invalidOffset; }
76
77 bool attemptToMerge(const GetByIdVariant& other);
78
79 void markIfCheap(SlotVisitor&);
80 bool finalize(VM&);
81
82 void dump(PrintStream&) const;
83 void dumpInContext(PrintStream&, DumpContext*) const;
84
85 Box<Identifier> identifier() const { return m_identifier; }
86
87 bool overlaps(const GetByIdVariant& other)
88 {
89 if (!!m_identifier != !!other.m_identifier)
90 return true;
91 if (m_identifier) {
92 if (m_identifier->impl() != other.m_identifier->impl())
93 return false;
94 }
95 return structureSet().overlaps(other.structureSet());
96 }
97
98private:
99 friend class GetByStatus;
100
101 bool canMergeIntrinsicStructures(const GetByIdVariant&) const;
102
103 StructureSet m_structureSet;
104 ObjectPropertyConditionSet m_conditionSet;
105 PropertyOffset m_offset;
106 std::unique_ptr<CallLinkStatus> m_callLinkStatus;
107 JSFunction* m_intrinsicFunction;
108 FunctionPtr<OperationPtrTag> m_customAccessorGetter;
109 std::unique_ptr<DOMAttributeAnnotation> m_domAttribute;
110 Box<Identifier> m_identifier; // We use this indirection to allow ref/deref in the concurrent compiler.
111};
112
113} // namespace JSC
114