]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/InferredValue.cpp
2 * Copyright (C) 2015 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 "InferredValue.h"
29 #include "JSCInlines.h"
33 const ClassInfo
InferredValue::s_info
= { "InferredValue", 0, 0, CREATE_METHOD_TABLE(InferredValue
) };
35 InferredValue
* InferredValue::create(VM
& vm
)
37 InferredValue
* result
= new (NotNull
, allocateCell
<InferredValue
>(vm
.heap
)) InferredValue(vm
);
38 result
->finishCreation(vm
);
42 void InferredValue::destroy(JSCell
* cell
)
44 InferredValue
* inferredValue
= static_cast<InferredValue
*>(cell
);
45 inferredValue
->InferredValue::~InferredValue();
48 Structure
* InferredValue::createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
50 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(CellType
, StructureFlags
), info());
53 void InferredValue::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
55 InferredValue
* inferredValue
= jsCast
<InferredValue
*>(cell
);
57 if (inferredValue
->m_set
.hasBeenInvalidated()) {
58 inferredValue
->m_cleanup
= nullptr;
62 if (!inferredValue
->m_value
)
64 if (!inferredValue
->m_value
.get().isCell())
67 if (!inferredValue
->m_cleanup
)
68 inferredValue
->m_cleanup
= std::make_unique
<ValueCleanup
>(inferredValue
);
69 visitor
.addUnconditionalFinalizer(inferredValue
->m_cleanup
.get());
72 InferredValue::InferredValue(VM
& vm
)
73 : Base(vm
, vm
.inferredValueStructure
.get())
74 , m_set(ClearWatchpoint
)
78 InferredValue::~InferredValue()
82 void InferredValue::notifyWriteSlow(VM
& vm
, JSValue value
, const FireDetail
& detail
)
85 switch (m_set
.state()) {
87 m_value
.set(vm
, this, value
);
88 m_set
.startWatching();
93 if (m_value
.get() == value
)
103 ASSERT_NOT_REACHED();
106 void InferredValue::notifyWriteSlow(VM
& vm
, JSValue value
, const char* reason
)
108 notifyWriteSlow(vm
, value
, StringFireDetail(reason
));
111 InferredValue::ValueCleanup::ValueCleanup(InferredValue
* owner
)
116 InferredValue::ValueCleanup::~ValueCleanup()
120 void InferredValue::ValueCleanup::finalizeUnconditionally()
122 ASSERT(m_owner
->m_value
);
123 ASSERT(m_owner
->m_value
.get().isCell());
125 if (Heap::isMarked(m_owner
->m_value
.get().asCell()))
128 m_owner
->invalidate(StringFireDetail("InferredValue clean-up during GC"));