Skip to content
Permalink
Browse files
Add logic to track whether a function uses a locally scoped eval or r…
…equires a closure

Reviewed by Maciej

Now that we limit eval we can track those uses of eval that operate
in the local scope and functions that require a closure.  We track
this information during initial parsing to avoid yet another tree
walk.


Canonical link: https://commits.webkit.org/24755@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31072 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ojhunt committed Mar 15, 2008
1 parent fa127c2 commit f9f3efa7791f7f438b888625a79d36b858090073
@@ -1,3 +1,34 @@
2008-03-14 Oliver Hunt <oliver@apple.com>

Reviewed by Maciej.

Add logic to track whether a function uses a locally scoped eval or requires a closure

Now that we limit eval we can track those uses of eval that operate
in the local scope and functions that require a closure. We track
this information during initial parsing to avoid yet another tree
walk.

* JavaScriptCore.exp:
* kjs/NodeInfo.h:
* kjs/Parser.cpp:
(KJS::Parser::didFinishParsing):
* kjs/Parser.h:
(KJS::Parser::parse):
* kjs/grammar.y:
* kjs/nodes.cpp:
(KJS::ScopeNode::ScopeNode):
(KJS::ProgramNode::ProgramNode):
(KJS::ProgramNode::create):
(KJS::EvalNode::EvalNode):
(KJS::EvalNode::create):
(KJS::FunctionBodyNode::FunctionBodyNode):
(KJS::FunctionBodyNode::create):
* kjs/nodes.h:
(KJS::ScopeNode::):
(KJS::ScopeNode::usesEval):
(KJS::ScopeNode::needsClosure):

2008-03-14 Geoffrey Garen <ggaren@apple.com>

Reviewed by Beth Dakin.
@@ -91,7 +91,7 @@ __ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiS5_PNS_7JSValueE
__ZN3KJS11JSImmediate4typeEPKNS_7JSValueE
__ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE
__ZN3KJS11JSImmediate8toStringEPKNS_7JSValueE
__ZN3KJS11ProgramNode6createEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS4_IPNS_12FuncDeclNodeELm16EEE
__ZN3KJS11ProgramNode6createEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS4_IPNS_12FuncDeclNodeELm16EEEbb
__ZN3KJS11PropertyMap11getLocationERKNS_10IdentifierE
__ZN3KJS11PropertyMap5clearEv
__ZN3KJS11PropertyMap7restoreERKNS_15SavedPropertiesE
@@ -25,19 +25,40 @@

namespace KJS {

template <typename T> struct NodeInfo {
T m_node;
ParserRefCountedData<DeclarationStacks::VarStack>* m_varDeclarations;
ParserRefCountedData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
};

typedef NodeInfo<StatementNode*> StatementNodeInfo;
typedef NodeInfo<CaseBlockNode*> CaseBlockNodeInfo;
typedef NodeInfo<CaseClauseNode*> CaseClauseNodeInfo;
typedef NodeInfo<SourceElements*> SourceElementsInfo;
typedef NodeInfo<ClauseList> ClauseListInfo;
typedef NodeInfo<ExpressionNode*> VarDeclListInfo;
typedef NodeInfo<ConstDeclList> ConstDeclListInfo;
typedef unsigned int FeatureInfo;

const FeatureInfo NoFeatures = 0;
const FeatureInfo EvalFeature = 1 << 0;
const FeatureInfo ClosureFeature = 1 << 1;

template <typename T> struct NodeFeatureInfo {
T m_node;
FeatureInfo m_featureInfo;
};

typedef NodeFeatureInfo<FuncExprNode*> FuncExprNodeInfo;
typedef NodeFeatureInfo<ExpressionNode*> ExpressionNodeInfo;
typedef NodeFeatureInfo<ArgumentsNode*> ArgumentsNodeInfo;
typedef NodeFeatureInfo<ConstDeclNode*> ConstDeclNodeInfo;
typedef NodeFeatureInfo<PropertyNode*> PropertyNodeInfo;
typedef NodeFeatureInfo<PropertyList> PropertyListInfo;
typedef NodeFeatureInfo<ElementList> ElementListInfo;
typedef NodeFeatureInfo<ArgumentList> ArgumentListInfo;

template <typename T> struct NodeDeclarationInfo {
T m_node;
ParserRefCountedData<DeclarationStacks::VarStack>* m_varDeclarations;
ParserRefCountedData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
FeatureInfo m_featureInfo;
};

typedef NodeDeclarationInfo<StatementNode*> StatementNodeInfo;
typedef NodeDeclarationInfo<CaseBlockNode*> CaseBlockNodeInfo;
typedef NodeDeclarationInfo<CaseClauseNode*> CaseClauseNodeInfo;
typedef NodeDeclarationInfo<SourceElements*> SourceElementsInfo;
typedef NodeDeclarationInfo<ClauseList> ClauseListInfo;
typedef NodeDeclarationInfo<ExpressionNode*> VarDeclListInfo;
typedef NodeDeclarationInfo<ConstDeclList> ConstDeclListInfo;

} // namespace KJS

@@ -72,11 +72,13 @@ void Parser::parse(int startingLineNumber,
}

void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, int lastLine)
ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, bool usesEval, bool needsClosure, int lastLine)
{
m_sourceElements = sourceElements ? sourceElements : new SourceElements;
m_varDeclarations = varStack;
m_funcDeclarations = funcStack;
m_usesEval = usesEval;
m_needsClosure = needsClosure;
m_lastLine = lastLine;
}

@@ -52,7 +52,7 @@ namespace KJS {
int sourceId() const { return m_sourceId; }

void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
ParserRefCountedData<DeclarationStacks::FunctionStack>*, int lastLine);
ParserRefCountedData<DeclarationStacks::FunctionStack>*, bool usesEval, bool needsClosure, int lastLine);

private:
friend Parser& parser();
@@ -66,6 +66,8 @@ namespace KJS {
RefPtr<SourceElements> m_sourceElements;
RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
bool m_usesEval;
bool m_needsClosure;
int m_lastLine;
};

@@ -84,7 +86,9 @@ namespace KJS {
}
RefPtr<ParsedNode> node = ParsedNode::create(m_sourceElements.release().get(),
m_varDeclarations ? &m_varDeclarations->data : 0,
m_funcDeclarations ? &m_funcDeclarations->data : 0);
m_funcDeclarations ? &m_funcDeclarations->data : 0,
m_usesEval,
m_needsClosure);
m_varDeclarations = 0;
m_funcDeclarations = 0;
m_sourceURL = UString();

0 comments on commit f9f3efa

Please sign in to comment.