]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/SymbolTable.cpp
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / runtime / SymbolTable.cpp
CommitLineData
93a37866 1/*
81345200 2 * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
93a37866
A
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 *
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.
81345200 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
93a37866
A
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
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.
27 */
28
29#include "config.h"
30#include "SymbolTable.h"
31
81345200
A
32#include "JSDestructibleObject.h"
33#include "JSCInlines.h"
34#include "SlotVisitorInlines.h"
35#include "VariableWatchpointSetInlines.h"
36
93a37866
A
37namespace JSC {
38
81345200 39const ClassInfo SymbolTable::s_info = { "SymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SymbolTable) };
93a37866
A
40
41SymbolTableEntry& SymbolTableEntry::copySlow(const SymbolTableEntry& other)
42{
43 ASSERT(other.isFat());
44 FatEntry* newFatEntry = new FatEntry(*other.fatEntry());
45 freeFatEntry();
46 m_bits = bitwise_cast<intptr_t>(newFatEntry);
47 return *this;
48}
49
81345200 50void SymbolTable::destroy(JSCell* cell)
93a37866 51{
81345200
A
52 SymbolTable* thisObject = jsCast<SymbolTable*>(cell);
53 thisObject->SymbolTable::~SymbolTable();
93a37866
A
54}
55
56void SymbolTableEntry::freeFatEntrySlow()
57{
58 ASSERT(isFat());
59 delete fatEntry();
60}
61
81345200 62JSValue SymbolTableEntry::inferredValue()
93a37866
A
63{
64 if (!isFat())
81345200
A
65 return JSValue();
66 return fatEntry()->m_watchpoints->inferredValue();
93a37866
A
67}
68
81345200 69void SymbolTableEntry::prepareToWatch(SymbolTable* symbolTable)
93a37866
A
70{
71 FatEntry* entry = inflate();
81345200
A
72 if (entry->m_watchpoints)
73 return;
74 entry->m_watchpoints = adoptRef(new VariableWatchpointSet(*symbolTable));
93a37866
A
75}
76
77void SymbolTableEntry::addWatchpoint(Watchpoint* watchpoint)
78{
93a37866
A
79 fatEntry()->m_watchpoints->add(watchpoint);
80}
81
81345200 82void SymbolTableEntry::notifyWriteSlow(VM& vm, JSValue value)
93a37866 83{
81345200 84 VariableWatchpointSet* watchpoints = fatEntry()->m_watchpoints.get();
93a37866
A
85 if (!watchpoints)
86 return;
81345200
A
87
88 watchpoints->notifyWrite(vm, value);
93a37866
A
89}
90
91SymbolTableEntry::FatEntry* SymbolTableEntry::inflateSlow()
92{
93 FatEntry* entry = new FatEntry(m_bits);
94 m_bits = bitwise_cast<intptr_t>(entry);
95 return entry;
96}
97
81345200
A
98SymbolTable::SymbolTable(VM& vm)
99 : JSCell(vm, vm.symbolTableStructure.get())
100 , m_parameterCountIncludingThis(0)
101 , m_usesNonStrictEval(false)
102 , m_captureStart(0)
103 , m_captureEnd(0)
104 , m_functionEnteredOnce(ClearWatchpoint)
105{
106}
107
108SymbolTable::~SymbolTable() { }
109
110void SymbolTable::visitChildren(JSCell* thisCell, SlotVisitor& visitor)
111{
112 SymbolTable* thisSymbolTable = jsCast<SymbolTable*>(thisCell);
113 if (!thisSymbolTable->m_watchpointCleanup) {
114 thisSymbolTable->m_watchpointCleanup =
115 std::make_unique<WatchpointCleanup>(thisSymbolTable);
116 }
117
118 visitor.addUnconditionalFinalizer(thisSymbolTable->m_watchpointCleanup.get());
119}
120
121SymbolTable::WatchpointCleanup::WatchpointCleanup(SymbolTable* symbolTable)
122 : m_symbolTable(symbolTable)
123{
124}
125
126SymbolTable::WatchpointCleanup::~WatchpointCleanup() { }
127
128void SymbolTable::WatchpointCleanup::finalizeUnconditionally()
129{
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();
135 }
136}
137
138SymbolTable* SymbolTable::cloneCapturedNames(VM& vm)
139{
140 SymbolTable* result = SymbolTable::create(vm);
141
142 result->m_parameterCountIncludingThis = m_parameterCountIncludingThis;
143 result->m_usesNonStrictEval = m_usesNonStrictEval;
144 result->m_captureStart = m_captureStart;
145 result->m_captureEnd = m_captureEnd;
146
147 for (auto iter = m_map.begin(), end = m_map.end(); iter != end; ++iter) {
148 if (!isCaptured(iter->value.getIndex()))
149 continue;
150 result->m_map.add(
151 iter->key,
152 SymbolTableEntry(iter->value.getIndex(), iter->value.getAttributes()));
153 }
154
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];
159 }
160
161 return result;
162}
163
93a37866
A
164} // namespace JSC
165