<rdar://problem/5601548> REGRESSION: All SourceElements and their children leak after...
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2007 00:40:24 +0000 (00:40 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2007 00:40:24 +0000 (00:40 +0000)
Reviewed by Darin.

Add a stub node to maintain the Vector of SourceElements until assignment.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27831 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes.h

index 4ac7cc4..fdc5054 100644 (file)
@@ -1,3 +1,19 @@
+2007-11-15  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/5601548> REGRESSION: All SourceElements and their children leak after a syntax error
+        
+        Add a stub node to maintain the Vector of SourceElements until assignment.
+
+        * kjs/grammar.y:
+        * kjs/nodes.h:
+        (KJS::SourceElementsStub::SourceElementsStub):
+        (KJS::SourceElementsStub::append):
+        (KJS::SourceElementsStub::release):
+        (KJS::SourceElementsStub::):
+        (KJS::SourceElementsStub::precedence):
+
 2007-11-15  Eric Seidel  <eric@webkit.org>
 
         Reviewed by Sam.
index 311bdc0..0a2bb82 100644 (file)
@@ -107,7 +107,7 @@ static NumberNode* makeNumberNode(double);
     FunctionBodyNode*   functionBodyNode;
     ProgramNode*        programNode;
 
-    SourceElements*     sourceElements;
+    SourceElementsStub* sourceElements;
     PropertyList        propertyList;
     ArgumentList        argumentList;
     VarDeclList         varDeclList;
@@ -660,7 +660,7 @@ Statement:
 
 Block:
     '{' '}'                             { $$ = new BlockNode(new SourceElements); DBG($$, @1, @2); }
-  | '{' SourceElements '}'              { $$ = new BlockNode($2); DBG($$, @1, @3); }
+  | '{' SourceElements '}'              { $$ = new BlockNode($2->release()); DBG($$, @1, @3); }
 ;
 
 VariableStatement:
@@ -821,12 +821,12 @@ CaseClauses:
 
 CaseClause:
     CASE Expr ':'                       { $$ = new CaseClauseNode($2); }
-  | CASE Expr ':' SourceElements        { $$ = new CaseClauseNode($2, $4); }
+  | CASE Expr ':' SourceElements        { $$ = new CaseClauseNode($2, $4->release()); }
 ;
 
 DefaultClause:
     DEFAULT ':'                         { $$ = new CaseClauseNode(0); }
-  | DEFAULT ':' SourceElements          { $$ = new CaseClauseNode(0, $3); }
+  | DEFAULT ':' SourceElements          { $$ = new CaseClauseNode(0, $3->release()); }
 ;
 
 LabelledStatement:
@@ -872,16 +872,16 @@ FormalParameterList:
 
 FunctionBody:
     /* not in spec */           { $$ = new FunctionBodyNode(new SourceElements); }
-  | SourceElements              { $$ = new FunctionBodyNode($1); }
+  | SourceElements              { $$ = new FunctionBodyNode($1->release()); }
 ;
 
 Program:
     /* not in spec */                   { Parser::accept(new ProgramNode(new SourceElements)); }
-    | SourceElements                    { Parser::accept(new ProgramNode($1)); }
+    | SourceElements                    { Parser::accept(new ProgramNode($1->release())); }
 ;
 
 SourceElements:
-    SourceElement                       { $$ = new SourceElements; $$->append($1); }
+    SourceElement                       { $$ = new SourceElementsStub; $$->append($1); }
   | SourceElements SourceElement        { $$->append($2); }
 ;
 
index 0d4a47d..ce2d902 100644 (file)
@@ -1728,6 +1728,25 @@ namespace KJS {
 
   typedef Vector<RefPtr<StatementNode> > SourceElements;
 
+  class SourceElementsStub : public Node {
+  public:
+    SourceElementsStub()
+      : m_sourceElements(new SourceElements)
+      {}
+    void append(StatementNode* element) { m_sourceElements->append(element); }
+    SourceElements* release() { 
+        SourceElements* elems = m_sourceElements.release(); 
+        return elems;
+    }
+    virtual void optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack&) KJS_FAST_CALL { ASSERT_NOT_REACHED(); }
+    virtual Completion execute(ExecState*) KJS_FAST_CALL  { ASSERT_NOT_REACHED(); return Completion(); }
+    virtual void streamTo(SourceStream&) const KJS_FAST_CALL  { ASSERT_NOT_REACHED(); }
+    virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL  { ASSERT_NOT_REACHED(); }
+    virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; }
+  private:
+    OwnPtr<SourceElements> m_sourceElements;
+  };
+    
   class BlockNode : public StatementNode {
   public:
     BlockNode(SourceElements* children) KJS_FAST_CALL;