summaryrefslogtreecommitdiffstats
path: root/Source/JavaScriptCore/parser
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/parser')
-rw-r--r--Source/JavaScriptCore/parser/ASTBuilder.h32
-rw-r--r--Source/JavaScriptCore/parser/JSParser.cpp38
2 files changed, 50 insertions, 20 deletions
diff --git a/Source/JavaScriptCore/parser/ASTBuilder.h b/Source/JavaScriptCore/parser/ASTBuilder.h
index 0e18d1d..9ab0f9d 100644
--- a/Source/JavaScriptCore/parser/ASTBuilder.h
+++ b/Source/JavaScriptCore/parser/ASTBuilder.h
@@ -76,9 +76,9 @@ public:
ASTBuilder(JSGlobalData* globalData, Lexer* lexer)
: m_globalData(globalData)
, m_lexer(lexer)
+ , m_scope(globalData)
, m_evalCount(0)
{
- m_scopes.append(Scope(globalData));
}
struct BinaryExprContext {
@@ -115,10 +115,10 @@ public:
JSC::SourceElements* createSourceElements() { return new (m_globalData) JSC::SourceElements(m_globalData); }
- ParserArenaData<DeclarationStacks::VarStack>* varDeclarations() { return m_scopes.last().m_varDeclarations; }
- ParserArenaData<DeclarationStacks::FunctionStack>* funcDeclarations() { return m_scopes.last().m_funcDeclarations; }
- int features() const { return m_scopes.last().m_features; }
- int numConstants() const { return m_scopes.last().m_numConstants; }
+ ParserArenaData<DeclarationStacks::VarStack>* varDeclarations() { return m_scope.m_varDeclarations; }
+ ParserArenaData<DeclarationStacks::FunctionStack>* funcDeclarations() { return m_scope.m_funcDeclarations; }
+ int features() const { return m_scope.m_features; }
+ int numConstants() const { return m_scope.m_numConstants; }
void appendToComma(CommaNode* commaNode, ExpressionNode* expr) { commaNode->append(expr); }
@@ -300,7 +300,7 @@ public:
FuncDeclNode* decl = new (m_globalData) FuncDeclNode(m_globalData, *name, body, m_lexer->sourceCode(openBracePos, closeBracePos, bodyStartLine), parameters);
if (*name == m_globalData->propertyNames->arguments)
usesArguments();
- m_scopes.last().m_funcDeclarations->data.append(decl->body());
+ m_scope.m_funcDeclarations->data.append(decl->body());
body->setLoc(bodyStartLine, bodyEndLine);
return decl;
}
@@ -494,7 +494,7 @@ public:
{
if (m_globalData->propertyNames->arguments == *ident)
usesArguments();
- m_scopes.last().m_varDeclarations->data.append(std::make_pair(ident, attrs));
+ m_scope.m_varDeclarations->data.append(std::make_pair(ident, attrs));
}
ExpressionNode* combineCommaNodes(ExpressionNode* list, ExpressionNode* init)
@@ -611,17 +611,17 @@ private:
node->setExceptionSourceCode(divot, divot - start, end - divot);
}
- void incConstants() { m_scopes.last().m_numConstants++; }
- void usesThis() { m_scopes.last().m_features |= ThisFeature; }
- void usesCatch() { m_scopes.last().m_features |= CatchFeature; }
- void usesClosures() { m_scopes.last().m_features |= ClosureFeature; }
- void usesArguments() { m_scopes.last().m_features |= ArgumentsFeature; }
- void usesAssignment() { m_scopes.last().m_features |= AssignFeature; }
- void usesWith() { m_scopes.last().m_features |= WithFeature; }
+ void incConstants() { m_scope.m_numConstants++; }
+ void usesThis() { m_scope.m_features |= ThisFeature; }
+ void usesCatch() { m_scope.m_features |= CatchFeature; }
+ void usesClosures() { m_scope.m_features |= ClosureFeature; }
+ void usesArguments() { m_scope.m_features |= ArgumentsFeature; }
+ void usesAssignment() { m_scope.m_features |= AssignFeature; }
+ void usesWith() { m_scope.m_features |= WithFeature; }
void usesEval()
{
m_evalCount++;
- m_scopes.last().m_features |= EvalFeature;
+ m_scope.m_features |= EvalFeature;
}
ExpressionNode* createNumber(double d)
{
@@ -630,7 +630,7 @@ private:
JSGlobalData* m_globalData;
Lexer* m_lexer;
- Vector<Scope> m_scopes;
+ Scope m_scope;
Vector<BinaryOperand, 10> m_binaryOperandStack;
Vector<AssignmentInfo, 10> m_assignmentInfoStack;
Vector<pair<int, int>, 10> m_binaryOperatorStack;
diff --git a/Source/JavaScriptCore/parser/JSParser.cpp b/Source/JavaScriptCore/parser/JSParser.cpp
index 993dd66..9245eb0 100644
--- a/Source/JavaScriptCore/parser/JSParser.cpp
+++ b/Source/JavaScriptCore/parser/JSParser.cpp
@@ -36,6 +36,7 @@ using namespace JSC;
#include "SourceProvider.h"
#include "SourceProviderCacheItem.h"
#include <wtf/HashFunctions.h>
+#include <wtf/OwnPtr.h>
#include <wtf/WTFThreadData.h>
#include <utility>
@@ -293,7 +294,31 @@ private:
, m_labels(0)
{
}
-
+
+ Scope(const Scope& rhs)
+ : m_globalData(rhs.m_globalData)
+ , m_shadowsArguments(rhs.m_shadowsArguments)
+ , m_usesEval(rhs.m_usesEval)
+ , m_needsFullActivation(rhs.m_needsFullActivation)
+ , m_allowsNewDecls(rhs.m_allowsNewDecls)
+ , m_strictMode(rhs.m_strictMode)
+ , m_isFunction(rhs.m_isFunction)
+ , m_isFunctionBoundary(rhs.m_isFunctionBoundary)
+ , m_isValidStrictMode(rhs.m_isValidStrictMode)
+ , m_loopDepth(rhs.m_loopDepth)
+ , m_switchDepth(rhs.m_switchDepth)
+ , m_labels(0)
+ {
+ if (rhs.m_labels) {
+ m_labels = adoptPtr(new LabelStack);
+
+ typedef LabelStack::const_iterator iterator;
+ iterator end = rhs.m_labels->end();
+ for (iterator it = rhs.m_labels->begin(); it != end; ++it)
+ m_labels->append(ScopeLabelInfo(it->m_ident, it->m_isLoop));
+ }
+ }
+
void startSwitch() { m_switchDepth++; }
void endSwitch() { m_switchDepth--; }
void startLoop() { m_loopDepth++; }
@@ -305,7 +330,7 @@ private:
void pushLabel(const Identifier* label, bool isLoop)
{
if (!m_labels)
- m_labels = new LabelStack;
+ m_labels = adoptPtr(new LabelStack);
m_labels->append(ScopeLabelInfo(label->impl(), isLoop));
}
@@ -465,13 +490,13 @@ private:
int m_switchDepth;
typedef Vector<ScopeLabelInfo, 2> LabelStack;
- LabelStack* m_labels;
+ OwnPtr<LabelStack> m_labels;
IdentifierSet m_declaredVariables;
IdentifierSet m_usedVariables;
IdentifierSet m_closedVariables;
IdentifierSet m_writtenVariables;
};
-
+
typedef Vector<Scope, 10> ScopeStack;
struct ScopeRef {
@@ -2140,3 +2165,8 @@ template <class TreeBuilder> TreeExpression JSParser::parseUnaryExpression(TreeB
}
}
+
+namespace WTF
+{
+ template <> struct VectorTraits<JSC::JSParser::Scope> : SimpleClassVectorTraits { };
+}