2 * Copyright (C) 2012, 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
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "SymbolTable.h"
32 #include "JSDestructibleObject.h"
33 #include "JSCInlines.h"
34 #include "SlotVisitorInlines.h"
35 #include "VariableWatchpointSetInlines.h"
39 const ClassInfo
SymbolTable::s_info
= { "SymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SymbolTable
) };
41 SymbolTableEntry
& SymbolTableEntry::copySlow(const SymbolTableEntry
& other
)
43 ASSERT(other
.isFat());
44 FatEntry
* newFatEntry
= new FatEntry(*other
.fatEntry());
46 m_bits
= bitwise_cast
<intptr_t>(newFatEntry
);
50 void SymbolTable::destroy(JSCell
* cell
)
52 SymbolTable
* thisObject
= jsCast
<SymbolTable
*>(cell
);
53 thisObject
->SymbolTable::~SymbolTable();
56 void SymbolTableEntry::freeFatEntrySlow()
62 JSValue
SymbolTableEntry::inferredValue()
66 return fatEntry()->m_watchpoints
->inferredValue();
69 void SymbolTableEntry::prepareToWatch(SymbolTable
* symbolTable
)
71 FatEntry
* entry
= inflate();
72 if (entry
->m_watchpoints
)
74 entry
->m_watchpoints
= adoptRef(new VariableWatchpointSet(*symbolTable
));
77 void SymbolTableEntry::addWatchpoint(Watchpoint
* watchpoint
)
79 fatEntry()->m_watchpoints
->add(watchpoint
);
82 void SymbolTableEntry::notifyWriteSlow(VM
& vm
, JSValue value
)
84 VariableWatchpointSet
* watchpoints
= fatEntry()->m_watchpoints
.get();
88 watchpoints
->notifyWrite(vm
, value
);
91 SymbolTableEntry::FatEntry
* SymbolTableEntry::inflateSlow()
93 FatEntry
* entry
= new FatEntry(m_bits
);
94 m_bits
= bitwise_cast
<intptr_t>(entry
);
98 SymbolTable::SymbolTable(VM
& vm
)
99 : JSCell(vm
, vm
.symbolTableStructure
.get())
100 , m_parameterCountIncludingThis(0)
101 , m_usesNonStrictEval(false)
104 , m_functionEnteredOnce(ClearWatchpoint
)
108 SymbolTable::~SymbolTable() { }
110 void SymbolTable::visitChildren(JSCell
* thisCell
, SlotVisitor
& visitor
)
112 SymbolTable
* thisSymbolTable
= jsCast
<SymbolTable
*>(thisCell
);
113 if (!thisSymbolTable
->m_watchpointCleanup
) {
114 thisSymbolTable
->m_watchpointCleanup
=
115 std::make_unique
<WatchpointCleanup
>(thisSymbolTable
);
118 visitor
.addUnconditionalFinalizer(thisSymbolTable
->m_watchpointCleanup
.get());
121 SymbolTable::WatchpointCleanup::WatchpointCleanup(SymbolTable
* symbolTable
)
122 : m_symbolTable(symbolTable
)
126 SymbolTable::WatchpointCleanup::~WatchpointCleanup() { }
128 void SymbolTable::WatchpointCleanup::finalizeUnconditionally()
130 Map::iterator iter
= m_symbolTable
->m_map
.begin();
131 Map::iterator end
= m_symbolTable
->m_map
.end();
132 for (; iter
!= end
; ++iter
) {
133 if (VariableWatchpointSet
* set
= iter
->value
.watchpointSet())
134 set
->finalizeUnconditionally();
138 SymbolTable
* SymbolTable::cloneCapturedNames(VM
& vm
)
140 SymbolTable
* result
= SymbolTable::create(vm
);
142 result
->m_parameterCountIncludingThis
= m_parameterCountIncludingThis
;
143 result
->m_usesNonStrictEval
= m_usesNonStrictEval
;
144 result
->m_captureStart
= m_captureStart
;
145 result
->m_captureEnd
= m_captureEnd
;
147 for (auto iter
= m_map
.begin(), end
= m_map
.end(); iter
!= end
; ++iter
) {
148 if (!isCaptured(iter
->value
.getIndex()))
152 SymbolTableEntry(iter
->value
.getIndex(), iter
->value
.getAttributes()));
155 if (m_slowArguments
) {
156 result
->m_slowArguments
= std::make_unique
<SlowArgument
[]>(parameterCount());
157 for (unsigned i
= parameterCount(); i
--;)
158 result
->m_slowArguments
[i
] = m_slowArguments
[i
];