diff options
Diffstat (limited to 'JavaScriptCore/parser/Nodes.h')
| -rw-r--r-- | JavaScriptCore/parser/Nodes.h | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/JavaScriptCore/parser/Nodes.h b/JavaScriptCore/parser/Nodes.h index c216ea8..6930f63 100644 --- a/JavaScriptCore/parser/Nodes.h +++ b/JavaScriptCore/parser/Nodes.h @@ -57,6 +57,7 @@ namespace JSC { const CodeFeatures WithFeature = 1 << 4; const CodeFeatures CatchFeature = 1 << 5; const CodeFeatures ThisFeature = 1 << 6; + const CodeFeatures StrictModeFeature = 1 << 7; const CodeFeatures AllFeatures = EvalFeature | ClosureFeature | AssignFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature; enum Operator { @@ -81,6 +82,8 @@ namespace JSC { OpLogicalOr }; + typedef HashSet<RefPtr<StringImpl>, IdentifierRepHash> IdentifierSet; + namespace DeclarationStacks { enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; typedef Vector<std::pair<const Identifier*, unsigned> > VarStack; @@ -152,6 +155,7 @@ namespace JSC { virtual bool isCommaNode() const { return false; } virtual bool isSimpleArray() const { return false; } virtual bool isAdd() const { return false; } + virtual bool isSubtract() const { return false; } virtual bool hasConditionContextCodegen() const { return false; } virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label*, Label*, bool) { ASSERT_NOT_REACHED(); } @@ -265,9 +269,8 @@ namespace JSC { uint16_t endOffset() const { return m_endOffset; } protected: - RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message); - RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message, const UString&); - RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message, const Identifier&); + RegisterID* emitThrowReferenceError(BytecodeGenerator&, const UString& message); + RegisterID* emitThrowSyntaxError(BytecodeGenerator&, const UString& message); private: uint32_t m_divot; @@ -404,12 +407,13 @@ namespace JSC { class PropertyNode : public ParserArenaFreeable { public: - enum Type { Constant, Getter, Setter }; + enum Type { Constant = 1, Getter = 2, Setter = 4 }; PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type); PropertyNode(JSGlobalData*, double name, ExpressionNode* value, Type); const Identifier& name() const { return m_name; } + Type type() const { return m_type; } private: friend class PropertyListNode; @@ -805,6 +809,9 @@ namespace JSC { RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0); + ExpressionNode* lhs() { return m_expr1; }; + ExpressionNode* rhs() { return m_expr2; }; + private: virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); @@ -853,6 +860,8 @@ namespace JSC { class SubNode : public BinaryOpNode { public: SubNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); + + virtual bool isSubtract() const { return true; } }; class LeftShiftNode : public BinaryOpNode { @@ -1142,6 +1151,7 @@ namespace JSC { public: BlockNode(JSGlobalData*, SourceElements* = 0); + StatementNode* singleStatement() const; StatementNode* lastStatement() const; private: @@ -1293,6 +1303,8 @@ namespace JSC { public: ReturnNode(JSGlobalData*, ExpressionNode* value); + ExpressionNode* value() { return m_value; } + private: virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); @@ -1366,13 +1378,14 @@ namespace JSC { typedef DeclarationStacks::VarStack VarStack; typedef DeclarationStacks::FunctionStack FunctionStack; - ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, int numConstants); + ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, int numConstants); ParserArena m_arena; VarStack m_varStack; FunctionStack m_functionStack; int m_numConstants; SourceElements* m_statements; + IdentifierSet m_capturedVariables; }; class ScopeNode : public StatementNode, public ParserArenaRefCounted { @@ -1380,17 +1393,11 @@ namespace JSC { typedef DeclarationStacks::VarStack VarStack; typedef DeclarationStacks::FunctionStack FunctionStack; - ScopeNode(JSGlobalData*); - ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, CodeFeatures, int numConstants); + ScopeNode(JSGlobalData*, bool inStrictContext); + ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants); using ParserArenaRefCounted::operator new; - void adoptData(std::auto_ptr<ScopeNodeData> data) - { - ASSERT(!data->m_arena.contains(this)); - ASSERT(!m_data); - m_data.adopt(data); - } ScopeNodeData* data() const { return m_data.get(); } void destroyData() { m_data.clear(); } @@ -1403,9 +1410,14 @@ namespace JSC { bool usesEval() const { return m_features & EvalFeature; } bool usesArguments() const { return m_features & ArgumentsFeature; } + bool isStrictMode() const { return m_features & StrictModeFeature; } void setUsesArguments() { m_features |= ArgumentsFeature; } bool usesThis() const { return m_features & ThisFeature; } - bool needsActivation() const { return m_features & (EvalFeature | ClosureFeature | WithFeature | CatchFeature); } + bool needsActivationForMoreThanVariables() const { ASSERT(m_data); return m_features & (EvalFeature | WithFeature | CatchFeature); } + bool needsActivation() const { ASSERT(m_data); return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); } + bool hasCapturedVariables() const { return !!m_data->m_capturedVariables.size(); } + size_t capturedVariableCount() const { return m_data->m_capturedVariables.size(); } + bool captures(const Identifier& ident) { return m_data->m_capturedVariables.contains(ident.impl()); } VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; } FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } @@ -1433,24 +1445,26 @@ namespace JSC { class ProgramNode : public ScopeNode { public: - static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + static const bool isFunctionNode = false; + static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); static const bool scopeIsFunction = false; private: - ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); }; class EvalNode : public ScopeNode { public: - static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + static const bool isFunctionNode = false; + static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); static const bool scopeIsFunction = false; private: - EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); }; @@ -1465,8 +1479,9 @@ namespace JSC { class FunctionBodyNode : public ScopeNode { public: - static FunctionBodyNode* create(JSGlobalData*); - static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + static const bool isFunctionNode = true; + static FunctionBodyNode* create(JSGlobalData*, bool isStrictMode); + static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); FunctionParameters* parameters() const { return m_parameters.get(); } size_t parameterCount() const { return m_parameters->size(); } @@ -1481,8 +1496,8 @@ namespace JSC { static const bool scopeIsFunction = true; private: - FunctionBodyNode(JSGlobalData*); - FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); + FunctionBodyNode(JSGlobalData*, bool inStrictContext); + FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); Identifier m_ident; RefPtr<FunctionParameters> m_parameters; |
