Changeset 28608 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp
- Timestamp:
- Dec 10, 2007, 9:47:41 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.cpp
r28577 r28608 266 266 static inline int currentSourceId(ExecState* exec) 267 267 { 268 return exec-> currentBody()->sourceId();268 return exec->scopeNode()->sourceId(); 269 269 } 270 270 … … 272 272 static inline const UString& currentSourceURL(ExecState* exec) 273 273 { 274 return exec-> currentBody()->sourceURL();274 return exec->scopeNode()->sourceURL(); 275 275 } 276 276 … … 4401 4401 // ------------------------------ FunctionBodyNode ----------------------------- 4402 4402 4403 FunctionBodyNode::FunctionBodyNode(SourceElements* children)4403 ScopeNode::ScopeNode(SourceElements* children) 4404 4404 : BlockNode(children) 4405 4405 , m_sourceURL(parser().sourceURL()) 4406 4406 , m_sourceId(parser().sourceId()) 4407 , m_initializedDeclarationStacks(false) 4408 , m_initializedSymbolTable(false) 4409 , m_optimizedResolveNodes(false) 4410 { 4411 } 4412 4413 void FunctionBodyNode::initializeDeclarationStacks(ExecState* exec) 4407 { 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) 4422 , m_initialized(false) 4423 { 4424 } 4425 4426 void ScopeNode::initializeDeclarationStacks(ExecState* exec) 4414 4427 { 4415 4428 DeclarationStacks::NodeStack nodeStack; … … 4430 4443 nodeStack.shrink(size); 4431 4444 } 4432 4433 m_initializedDeclarationStacks = true;4434 4445 } 4435 4446 … … 4448 4459 for (i = 0, size = m_functionStack.size(); i < size; ++i) 4449 4460 m_symbolTable.set(m_functionStack[i]->ident.ustring().rep(), count++); 4450 4451 m_initializedSymbolTable = true;4452 4461 } 4453 4462 … … 4469 4478 nodeStack.shrink(size); 4470 4479 } 4471 4472 m_optimizedResolveNodes = true;4473 4480 } 4474 4481 4475 4482 void FunctionBodyNode::processDeclarations(ExecState* exec) 4476 4483 { 4477 if (!m_initialized DeclarationStacks)4484 if (!m_initialized) { 4478 4485 initializeDeclarationStacks(exec); 4479 4480 if (exec->codeType() == FunctionCode)4481 processDeclarationsForFunctionCode(exec);4482 else4483 processDeclarationsForProgramCode(exec);4484 }4485 4486 void FunctionBodyNode::processDeclarationsForFunctionCode(ExecState* exec)4487 {4488 if (!m_initializedSymbolTable)4489 4486 initializeSymbolTable(); 4490 4491 if (!m_optimizedResolveNodes)4492 4487 optimizeVariableAccess(); 4488 4489 m_initialized = true; 4490 } 4493 4491 4494 4492 LocalStorage& localStorage = exec->variableObject()->localStorage(); … … 4521 4519 } 4522 4520 4523 void FunctionBodyNode::processDeclarationsForProgramCode(ExecState* exec) 4524 { 4521 void ProgramNode::processDeclarations(ExecState* exec) 4522 { 4523 initializeDeclarationStacks(exec); 4524 4525 4525 size_t i, size; 4526 4526 4527 JS Object* variableObject = exec->variableObject();4528 4529 int minAttributes = Internal | (exec->codeType() != EvalCode ? DontDelete : 0);4527 JSVariableObject* variableObject = exec->variableObject(); 4528 4529 int minAttributes = Internal | DontDelete; 4530 4530 4531 4531 for (i = 0, size = m_varStack.size(); i < size; ++i) { … … 4539 4539 } 4540 4540 4541 ASSERT(!m_parameters.size());4542 4543 4541 for (i = 0, size = m_functionStack.size(); i < size; ++i) { 4544 4542 FuncDeclNode* node = m_functionStack[i]; … … 4547 4545 } 4548 4546 4549 void FunctionBodyNode::addParam(const Identifier& ident) 4550 { 4551 m_parameters.append(ident); 4547 void EvalNode::processDeclarations(ExecState* exec) 4548 { 4549 initializeDeclarationStacks(exec); 4550 4551 size_t i, size; 4552 4553 JSVariableObject* variableObject = exec->variableObject(); 4554 4555 int minAttributes = Internal; 4556 4557 for (i = 0, size = m_varStack.size(); i < size; ++i) { 4558 VarDeclNode* node = m_varStack[i]; 4559 if (variableObject->hasProperty(exec, node->ident)) 4560 continue; 4561 int attributes = minAttributes; 4562 if (node->varType == VarDeclNode::Constant) 4563 attributes |= ReadOnly; 4564 variableObject->put(exec, node->ident, jsUndefined(), attributes); 4565 } 4566 4567 for (i = 0, size = m_functionStack.size(); i < size; ++i) { 4568 FuncDeclNode* node = m_functionStack[i]; 4569 variableObject->put(exec, node->ident, node->makeFunction(exec), minAttributes); 4570 } 4552 4571 } 4553 4572 … … 4555 4574 { 4556 4575 UString s(""); 4557 size_t count = numParams();4576 size_t count = m_parameters.size(); 4558 4577 for (size_t pos = 0; pos < count; ++pos) { 4559 4578 if (!s.isEmpty()) 4560 4579 s += ", "; 4561 s += paramName(pos).ustring();4580 s += m_parameters[pos].ustring(); 4562 4581 } 4563 4582 4564 4583 return s; 4584 } 4585 4586 Completion ProgramNode::execute(ExecState* exec) 4587 { 4588 processDeclarations(exec); 4589 return ScopeNode::execute(exec); 4590 } 4591 4592 Completion EvalNode::execute(ExecState* exec) 4593 { 4594 processDeclarations(exec); 4595 return ScopeNode::execute(exec); 4565 4596 } 4566 4597 … … 4576 4607 } 4577 4608 4578 Completion completion = BlockNode::execute(exec);4609 Completion completion = ScopeNode::execute(exec); 4579 4610 4580 4611 if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) { … … 4597 4628 { 4598 4629 for (ParameterNode *p = param.get(); p != 0L; p = p->nextParam()) 4599 body-> addParam(p->ident());4630 body->parameters().append(p->ident()); 4600 4631 } 4601 4632 … … 4613 4644 func->put(exec, exec->propertyNames().prototype, proto, Internal|DontDelete); 4614 4645 4615 func->put(exec, exec->propertyNames().length, jsNumber(body-> numParams()), ReadOnly|DontDelete|DontEnum);4646 func->put(exec, exec->propertyNames().length, jsNumber(body->parameters().size()), ReadOnly|DontDelete|DontEnum); 4616 4647 return func; 4617 4648 } … … 4628 4659 { 4629 4660 for (ParameterNode *p = param.get(); p != 0L; p = p->nextParam()) 4630 body-> addParam(p->ident());4661 body->parameters().append(p->ident()); 4631 4662 } 4632 4663 … … 4657 4688 } 4658 4689 4659 ProgramNode::ProgramNode(SourceElements* children) 4660 : FunctionBodyNode(children) 4661 { 4662 } 4663 4664 } 4690 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.