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 | |
33 | namespace JSC { |
34 | namespace DOMJIT { |
35 | class GetterSetter; |
36 | } |
37 | |
38 | class CallLinkStatus; |
39 | class GetByIdStatus; |
40 | struct DumpContext; |
41 | |
42 | class GetByIdVariant { |
43 | public: |
44 | GetByIdVariant( |
45 | const StructureSet& structureSet = StructureSet(), PropertyOffset offset = invalidOffset, |
46 | const ObjectPropertyConditionSet& = ObjectPropertyConditionSet(), |
47 | std::unique_ptr<CallLinkStatus> = nullptr, |
48 | JSFunction* = nullptr, |
49 | FunctionPtr<OperationPtrTag> customAccessorGetter = nullptr, |
50 | Optional<DOMAttributeAnnotation> = WTF::nullopt); |
51 | |
52 | ~GetByIdVariant(); |
53 | |
54 | GetByIdVariant(const GetByIdVariant&); |
55 | GetByIdVariant& operator=(const GetByIdVariant&); |
56 | |
57 | bool isSet() const { return !!m_structureSet.size(); } |
58 | explicit operator bool() const { return isSet(); } |
59 | const StructureSet& structureSet() const { return m_structureSet; } |
60 | StructureSet& structureSet() { return m_structureSet; } |
61 | |
62 | // A non-empty condition set means that this is a prototype load. |
63 | const ObjectPropertyConditionSet& conditionSet() const { return m_conditionSet; } |
64 | |
65 | PropertyOffset offset() const { return m_offset; } |
66 | CallLinkStatus* callLinkStatus() const { return m_callLinkStatus.get(); } |
67 | JSFunction* intrinsicFunction() const { return m_intrinsicFunction; } |
68 | Intrinsic intrinsic() const { return m_intrinsicFunction ? m_intrinsicFunction->intrinsic() : NoIntrinsic; } |
69 | FunctionPtr<OperationPtrTag> customAccessorGetter() const { return m_customAccessorGetter; } |
70 | Optional<DOMAttributeAnnotation> domAttribute() const { return m_domAttribute; } |
71 | |
72 | bool isPropertyUnset() const { return offset() == invalidOffset; } |
73 | |
74 | bool attemptToMerge(const GetByIdVariant& other); |
75 | |
76 | void markIfCheap(SlotVisitor&); |
77 | bool finalize(VM&); |
78 | |
79 | void dump(PrintStream&) const; |
80 | void dumpInContext(PrintStream&, DumpContext*) const; |
81 | |
82 | private: |
83 | friend class GetByIdStatus; |
84 | |
85 | bool canMergeIntrinsicStructures(const GetByIdVariant&) const; |
86 | |
87 | StructureSet m_structureSet; |
88 | ObjectPropertyConditionSet m_conditionSet; |
89 | PropertyOffset m_offset; |
90 | std::unique_ptr<CallLinkStatus> m_callLinkStatus; |
91 | JSFunction* m_intrinsicFunction; |
92 | FunctionPtr<OperationPtrTag> m_customAccessorGetter; |
93 | Optional<DOMAttributeAnnotation> m_domAttribute; |
94 | }; |
95 | |
96 | } // namespace JSC |
97 | |