Changeset 28854 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp
- Timestamp:
- Dec 18, 2007, 11:42:29 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.cpp
r28608 r28854 111 111 static WTFLogChannel LogKJSNodeLeaks = { 0x00000000, "", WTFLogChannelOn }; 112 112 113 struct NodeCounter {113 struct ParserRefCountedCounter { 114 114 static unsigned count; 115 ~NodeCounter()115 ParserRefCountedCounter() 116 116 { 117 117 if (count) … … 119 119 } 120 120 }; 121 unsigned NodeCounter::count = 0;122 static NodeCounter nodeCounter;121 unsigned ParserRefCountedCounter::count = 0; 122 static ParserRefCountedCounter parserRefCountedCounter; 123 123 #endif 124 124 125 static HashSet<Node*>* newNodes; 126 static HashCountedSet<Node*>* nodeExtraRefCounts; 125 static HashSet<ParserRefCounted*>* newTrackedObjects; 126 static HashCountedSet<ParserRefCounted*>* trackedObjectExtraRefCounts; 127 128 ParserRefCounted::ParserRefCounted() 129 { 130 #ifndef NDEBUG 131 ++ParserRefCountedCounter::count; 132 #endif 133 if (!newTrackedObjects) 134 newTrackedObjects = new HashSet<ParserRefCounted*>; 135 newTrackedObjects->add(this); 136 ASSERT(newTrackedObjects->contains(this)); 137 } 138 139 ParserRefCounted::~ParserRefCounted() 140 { 141 #ifndef NDEBUG 142 --ParserRefCountedCounter::count; 143 #endif 144 } 145 146 void ParserRefCounted::ref() 147 { 148 // bumping from 0 to 1 is just removing from the new nodes set 149 if (newTrackedObjects) { 150 HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->find(this); 151 if (it != newTrackedObjects->end()) { 152 newTrackedObjects->remove(it); 153 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this)); 154 return; 155 } 156 } 157 158 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this)); 159 160 if (!trackedObjectExtraRefCounts) 161 trackedObjectExtraRefCounts = new HashCountedSet<ParserRefCounted*>; 162 trackedObjectExtraRefCounts->add(this); 163 } 164 165 void ParserRefCounted::deref() 166 { 167 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this)); 168 169 if (!trackedObjectExtraRefCounts) { 170 delete this; 171 return; 172 } 173 174 HashCountedSet<ParserRefCounted*>::iterator it = trackedObjectExtraRefCounts->find(this); 175 if (it == trackedObjectExtraRefCounts->end()) 176 delete this; 177 else 178 trackedObjectExtraRefCounts->remove(it); 179 } 180 181 unsigned ParserRefCounted::refcount() 182 { 183 if (newTrackedObjects && newTrackedObjects->contains(this)) { 184 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this)); 185 return 0; 186 } 187 188 ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this)); 189 190 if (!trackedObjectExtraRefCounts) 191 return 1; 192 193 return 1 + trackedObjectExtraRefCounts->count(this); 194 } 195 196 void ParserRefCounted::deleteNewObjects() 197 { 198 if (!newTrackedObjects) 199 return; 200 201 #ifndef NDEBUG 202 HashSet<ParserRefCounted*>::iterator end = newTrackedObjects->end(); 203 for (HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->begin(); it != end; ++it) 204 ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(*it)); 205 #endif 206 deleteAllValues(*newTrackedObjects); 207 delete newTrackedObjects; 208 newTrackedObjects = 0; 209 } 127 210 128 211 Node::Node() … … 130 213 , m_expectedReturnType(ObjectType) 131 214 { 132 #ifndef NDEBUG133 ++NodeCounter::count;134 #endif135 215 m_line = lexer().lineNo(); 136 if (!newNodes)137 newNodes = new HashSet<Node*>;138 newNodes->add(this);139 216 } 140 217 … … 143 220 , m_expectedReturnType(expectedReturn) 144 221 { 145 #ifndef NDEBUG146 ++NodeCounter::count;147 #endif148 222 m_line = lexer().lineNo(); 149 if (!newNodes)150 newNodes = new HashSet<Node*>;151 newNodes->add(this);152 }153 154 Node::~Node()155 {156 #ifndef NDEBUG157 --NodeCounter::count;158 #endif159 }160 161 void Node::ref()162 {163 // bumping from 0 to 1 is just removing from the new nodes set164 if (newNodes) {165 HashSet<Node*>::iterator it = newNodes->find(this);166 if (it != newNodes->end()) {167 newNodes->remove(it);168 ASSERT(!nodeExtraRefCounts || !nodeExtraRefCounts->contains(this));169 return;170 }171 }172 173 ASSERT(!newNodes || !newNodes->contains(this));174 175 if (!nodeExtraRefCounts)176 nodeExtraRefCounts = new HashCountedSet<Node*>;177 nodeExtraRefCounts->add(this);178 }179 180 void Node::deref()181 {182 ASSERT(!newNodes || !newNodes->contains(this));183 184 if (!nodeExtraRefCounts) {185 delete this;186 return;187 }188 189 HashCountedSet<Node*>::iterator it = nodeExtraRefCounts->find(this);190 if (it == nodeExtraRefCounts->end())191 delete this;192 else193 nodeExtraRefCounts->remove(it);194 }195 196 unsigned Node::refcount()197 {198 if (newNodes && newNodes->contains(this)) {199 ASSERT(!nodeExtraRefCounts || !nodeExtraRefCounts->contains(this));200 return 0;201 }202 203 ASSERT(!newNodes || !newNodes->contains(this));204 205 if (!nodeExtraRefCounts)206 return 1;207 208 return 1 + nodeExtraRefCounts->count(this);209 }210 211 void Node::clearNewNodes()212 {213 if (!newNodes)214 return;215 216 #ifndef NDEBUG217 HashSet<Node*>::iterator end = newNodes->end();218 for (HashSet<Node*>::iterator it = newNodes->begin(); it != end; ++it)219 ASSERT(!nodeExtraRefCounts || !nodeExtraRefCounts->contains(*it));220 #endif221 deleteAllValues(*newNodes);222 delete newNodes;223 newNodes = 0;224 223 } 225 224 … … 4401 4400 // ------------------------------ FunctionBodyNode ----------------------------- 4402 4401 4403 ScopeNode::ScopeNode(SourceElements* children )4402 ScopeNode::ScopeNode(SourceElements* children, DeclarationStacks::VarStack* varStack, DeclarationStacks::FunctionStack* funcStack) 4404 4403 : BlockNode(children) 4405 4404 , m_sourceURL(parser().sourceURL()) 4406 4405 , m_sourceId(parser().sourceId()) 4407 4406 { 4408 } 4409 4410 ProgramNode::ProgramNode(SourceElements* children) 4411 : ScopeNode(children) 4412 { 4413 } 4414 4415 EvalNode::EvalNode(SourceElements* children) 4416 : ScopeNode(children) 4417 { 4418 } 4419 4420 FunctionBodyNode::FunctionBodyNode(SourceElements* children) 4421 : ScopeNode(children) 4407 if (varStack) 4408 m_varStack = *varStack; 4409 4410 if (funcStack) 4411 m_functionStack = *funcStack; 4412 } 4413 4414 ProgramNode::ProgramNode(SourceElements* children, DeclarationStacks::VarStack* varStack, DeclarationStacks::FunctionStack* funcStack) 4415 : ScopeNode(children, varStack, funcStack) 4416 { 4417 } 4418 4419 EvalNode::EvalNode(SourceElements* children, DeclarationStacks::VarStack* varStack, DeclarationStacks::FunctionStack* funcStack) 4420 : ScopeNode(children, varStack, funcStack) 4421 { 4422 } 4423 4424 FunctionBodyNode::FunctionBodyNode(SourceElements* children, DeclarationStacks::VarStack* varStack, DeclarationStacks::FunctionStack* funcStack) 4425 : ScopeNode(children, varStack, funcStack) 4422 4426 , m_initialized(false) 4423 4427 { 4424 4428 } 4425 4429 4426 void ScopeNode::initializeDeclarationStacks(ExecState* exec) 4427 { 4428 DeclarationStacks::NodeStack nodeStack; 4429 DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack); 4430 Node* node = statementListInitializeDeclarationStack(*m_children, nodeStack); 4431 if (!node) 4432 return; 4433 4434 while (true) { 4435 ASSERT(node->mayHaveDeclarations()); // Otherwise, we wasted time putting an irrelevant node on the stack. 4436 node->getDeclarations(stacks); 4437 4438 size_t size = nodeStack.size(); 4439 if (!size) 4440 break; 4441 --size; 4442 node = nodeStack[size]; 4443 nodeStack.shrink(size); 4444 } 4445 } 4446 4447 void FunctionBodyNode::initializeSymbolTable() 4430 void FunctionBodyNode::initializeSymbolTable(ExecState* exec) 4448 4431 { 4449 4432 size_t i, size; … … 4451 4434 4452 4435 // The order of additions here implicitly enforces the mutual exclusion described in ECMA 10.1.3. 4453 for (i = 0, size = m_varStack.size(); i < size; ++i) 4454 m_symbolTable.set(m_varStack[i]->ident.ustring().rep(), count++); 4436 for (i = 0, size = m_varStack.size(); i < size; ++i) { 4437 if (m_varStack[i]->ident != exec->propertyNames().arguments) 4438 m_symbolTable.set(m_varStack[i]->ident.ustring().rep(), count); 4439 count++; 4440 } 4455 4441 4456 4442 for (i = 0, size = m_parameters.size(); i < size; ++i) … … 4483 4469 { 4484 4470 if (!m_initialized) { 4485 initializeDeclarationStacks(exec); 4486 initializeSymbolTable(); 4471 initializeSymbolTable(exec); 4487 4472 optimizeVariableAccess(); 4488 4473 … … 4521 4506 void ProgramNode::processDeclarations(ExecState* exec) 4522 4507 { 4523 initializeDeclarationStacks(exec);4524 4525 4508 size_t i, size; 4526 4509 … … 4547 4530 void EvalNode::processDeclarations(ExecState* exec) 4548 4531 { 4549 initializeDeclarationStacks(exec);4550 4551 4532 size_t i, size; 4552 4533
Note:
See TracChangeset
for help on using the changeset viewer.