Changeset 10352 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Aug 26, 2005, 4:42:16 PM (20 years ago)
Author:
mjs
Message:

Reviewed by John.

  • fixed <rdar://problem/4232452> many many leaks in kjsyyparse on some well-formed JavaScript (can repro on sony.com, webkit tests)

Fixed by changing the refcounting scheme for nodes. Instead of each node implementing a custom ref and
deref for all its children (and being responsible for deleting them), nodes use a smart pointer to
hold their children, and smart pointers are used outside the node tree as well. This change mostly
removes code.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/function.cpp: (KJS::DeclaredFunctionImp::DeclaredFunctionImp): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function.h:
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/grammar.y:
  • kjs/internal.cpp: (KJS::Parser::parse): (KJS::Parser::accept): (KJS::InterpreterImp::checkSyntax): (KJS::InterpreterImp::evaluate):
  • kjs/internal.h:
  • kjs/nodes.cpp: (Node::Node): (Node::~Node): (ElementNode::evaluate): (PropertyValueNode::evaluate): (ArgumentListNode::evaluateList): (NewExprNode::evaluate): (FunctionCallValueNode::evaluate): (FunctionCallBracketNode::evaluate): (FunctionCallDotNode::evaluate): (RelationalNode::evaluate): (StatListNode::execute): (StatListNode::processVarDecls): (VarDeclListNode::evaluate): (VarDeclListNode::processVarDecls): (ForInNode::ForInNode): (ClauseListNode::processVarDecls): (CaseBlockNode::evalBlock): (FuncDeclNode::processFuncDecl): (FuncExprNode::evaluate): (SourceElementsNode::execute): (SourceElementsNode::processFuncDecl): (SourceElementsNode::processVarDecls):
  • kjs/nodes.h: (KJS::Node::ref): (KJS::Node::deref): (KJS::NumberNode::NumberNode): (KJS::GroupNode::GroupNode): (KJS::ElementNode::ElementNode): (KJS::ArrayNode::ArrayNode): (KJS::PropertyValueNode::PropertyValueNode): (KJS::ObjectLiteralNode::ObjectLiteralNode): (KJS::BracketAccessorNode::BracketAccessorNode): (KJS::DotAccessorNode::DotAccessorNode): (KJS::ArgumentListNode::ArgumentListNode): (KJS::ArgumentsNode::ArgumentsNode): (KJS::NewExprNode::NewExprNode): (KJS::FunctionCallValueNode::FunctionCallValueNode): (KJS::FunctionCallResolveNode::FunctionCallResolveNode): (KJS::FunctionCallBracketNode::FunctionCallBracketNode): (KJS::FunctionCallDotNode::FunctionCallDotNode): (KJS::PostfixNode::PostfixNode): (KJS::DeleteNode::DeleteNode): (KJS::VoidNode::VoidNode): (KJS::TypeOfNode::TypeOfNode): (KJS::PrefixNode::PrefixNode): (KJS::UnaryPlusNode::UnaryPlusNode): (KJS::NegateNode::NegateNode): (KJS::BitwiseNotNode::BitwiseNotNode): (KJS::LogicalNotNode::LogicalNotNode): (KJS::MultNode::MultNode): (KJS::AddNode::AddNode): (KJS::ShiftNode::ShiftNode): (KJS::RelationalNode::RelationalNode): (KJS::EqualNode::EqualNode): (KJS::BitOperNode::BitOperNode): (KJS::BinaryLogicalNode::BinaryLogicalNode): (KJS::ConditionalNode::ConditionalNode): (KJS::AssignResolveNode::AssignResolveNode): (KJS::AssignBracketNode::AssignBracketNode): (KJS::AssignDotNode::AssignDotNode): (KJS::CommaNode::CommaNode): (KJS::AssignExprNode::AssignExprNode): (KJS::VarDeclListNode::VarDeclListNode): (KJS::VarStatementNode::VarStatementNode): (KJS::ExprStatementNode::ExprStatementNode): (KJS::IfNode::IfNode): (KJS::DoWhileNode::DoWhileNode): (KJS::WhileNode::WhileNode): (KJS::ForNode::ForNode): (KJS::ReturnNode::ReturnNode): (KJS::WithNode::WithNode): (KJS::CaseClauseNode::CaseClauseNode): (KJS::ClauseListNode::ClauseListNode): (KJS::ClauseListNode::clause): (KJS::ClauseListNode::next): (KJS::SwitchNode::SwitchNode): (KJS::LabelNode::LabelNode): (KJS::ThrowNode::ThrowNode): (KJS::CatchNode::CatchNode): (KJS::FinallyNode::FinallyNode): (KJS::TryNode::TryNode): (KJS::ParameterNode::ParameterNode): (KJS::ParameterNode::nextParam): (KJS::FuncDeclNode::FuncDeclNode): (KJS::FuncExprNode::FuncExprNode):
  • kjs/nodes2string.cpp: (KJS::SourceStream::operator<<): (ElementNode::streamTo): (PropertyValueNode::streamTo): (ArgumentListNode::streamTo): (StatListNode::streamTo): (VarDeclListNode::streamTo): (CaseBlockNode::streamTo): (ParameterNode::streamTo): (SourceElementsNode::streamTo):
  • kjs/shared_ptr.h: Added. (kxmlcore::SharedPtr::SharedPtr): (kxmlcore::SharedPtr::~SharedPtr): (kxmlcore::SharedPtr::isNull): (kxmlcore::SharedPtr::notNull): (kxmlcore::SharedPtr::reset): (kxmlcore::SharedPtr::get): (kxmlcore::SharedPtr::operator*): (kxmlcore::SharedPtr::operator->): (kxmlcore::SharedPtr::operator!): (kxmlcore::SharedPtr::operator bool): (kxmlcore::SharedPtr::operator==): (kxmlcore::::operator): (kxmlcore::operator!=): (kxmlcore::static_pointer_cast): (kxmlcore::const_pointer_cast):
Location:
trunk/JavaScriptCore/kjs
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/function.cpp

    r10207 r10352  
    3232#include "debugger.h"
    3333#include "context.h"
     34#include "shared_ptr.h"
    3435
    3536#include <stdio.h>
     
    4243#include <unicode/uchar.h>
    4344#endif
     45
     46using namespace kxmlcore;
    4447
    4548namespace KJS {
     
    304307  : FunctionImp(exec,n), body(b)
    305308{
    306   body->ref();
    307309  setScope(sc);
    308 }
    309 
    310 DeclaredFunctionImp::~DeclaredFunctionImp()
    311 {
    312   if ( body->deref() )
    313     delete body;
    314310}
    315311
     
    794790        int errLine;
    795791        UString errMsg;
    796         ProgramNode *progNode = Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg);
     792        SharedPtr<ProgramNode> progNode(Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg));
    797793
    798794        Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();
     
    804800
    805801        // no program node means a syntax occurred
    806         if (!progNode)
     802        if (!progNode) {
    807803          return throwError(exec, SyntaxError, errMsg, errLine, sid, NULL);
    808        
    809         progNode->ref();
    810        
     804        }
     805
    811806        // enter a new execution context
    812807        ObjectImp *thisVal = static_cast<ObjectImp *>(exec->context().thisValue());
     
    833828        else if (c.isValueCompletion())
    834829            res = c.value();
    835 
    836         if ( progNode->deref() )
    837           delete progNode;
    838830      }
    839831      break;
  • trunk/JavaScriptCore/kjs/function.h

    r10148 r10352  
    7777    DeclaredFunctionImp(ExecState *exec, const Identifier &n,
    7878                        FunctionBodyNode *b, const ScopeChain &sc);
    79     ~DeclaredFunctionImp();
    8079
    8180    bool implementsConstruct() const;
     
    8483    virtual Completion execute(ExecState *exec);
    8584    CodeType codeType() const { return FunctionCode; }
    86     FunctionBodyNode *body;
     85    kxmlcore::SharedPtr<FunctionBodyNode> body;
    8786
    8887    virtual const ClassInfo *classInfo() const { return &info; }
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r10207 r10352  
    3535
    3636using namespace KJS;
     37using namespace kxmlcore;
    3738
    3839// ------------------------------ FunctionPrototypeImp -------------------------
     
    198199  int errLine;
    199200  UString errMsg;
    200   ProgramNode *progNode = Parser::parse(sourceURL, lineNumber, body.data(),body.size(),&sid,&errLine,&errMsg);
     201  SharedPtr<ProgramNode> progNode = Parser::parse(sourceURL, lineNumber, body.data(),body.size(),&sid,&errLine,&errMsg);
    201202
    202203  // notify debugger that source has been parsed
     
    219220  ScopeChain scopeChain;
    220221  scopeChain.push(exec->dynamicInterpreter()->globalObject());
    221   FunctionBodyNode *bodyNode = progNode;
     222  FunctionBodyNode *bodyNode = progNode.get();
    222223
    223224  FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode,
  • trunk/JavaScriptCore/kjs/grammar.y

    r10148 r10352  
    693693Program:
    694694    /* nothing, empty script */      { $$ = new ProgramNode(0);
    695                                      Parser::progNode = $$; }
     695                                     Parser::accept($$); }
    696696    | SourceElements                 { $$ = new ProgramNode($1);
    697                                      Parser::progNode = $$; }
     697                                     Parser::accept($$); }
    698698;
    699699
  • trunk/JavaScriptCore/kjs/internal.cpp

    r10207 r10352  
    5353
    5454extern int kjsyyparse();
     55
     56using namespace kxmlcore;
    5557
    5658namespace KJS {
     
    346348// ------------------------------ Parser ---------------------------------------
    347349
    348 ProgramNode *Parser::progNode = 0;
     350static SharedPtr<ProgramNode> *progNode;
    349351int Parser::sid = 0;
    350352
    351 ProgramNode *Parser::parse(const UString &sourceURL, int startingLineNumber,
    352                            const UChar *code, unsigned int length, int *sourceId,
    353                            int *errLine, UString *errMsg)
     353SharedPtr<ProgramNode> Parser::parse(const UString &sourceURL, int startingLineNumber,
     354                                     const UChar *code, unsigned int length, int *sourceId,
     355                                     int *errLine, UString *errMsg)
    354356{
    355357  if (errLine)
     
    357359  if (errMsg)
    358360    *errMsg = 0;
    359  
     361  if (!progNode)
     362    progNode = new SharedPtr<ProgramNode>;
     363
    360364  Lexer::curr()->setCode(sourceURL, startingLineNumber, code, length);
    361   progNode = 0;
     365  *progNode = 0;
    362366  sid++;
    363367  if (sourceId)
     
    369373  bool lexError = Lexer::curr()->sawError();
    370374  Lexer::curr()->doneParsing();
    371   ProgramNode *prog = progNode;
    372   progNode = 0;
     375  SharedPtr<ProgramNode> prog = *progNode;
     376  *progNode = 0;
    373377
    374378  if (parseError || lexError) {
     
    378382    if (errMsg)
    379383      *errMsg = "Parse error";
    380     if (prog) {
    381       // must ref and deref to clean up properly
    382       prog->ref();
    383       prog->deref();
    384       delete prog;
    385     }
    386     return 0;
     384    return SharedPtr<ProgramNode>();
    387385  }
    388386
    389387  return prog;
    390388}
     389
     390void Parser::accept(ProgramNode *prog)
     391{
     392  *progNode = prog;
     393}
     394
    391395
    392396// ------------------------------ InterpreterImp -------------------------------
     
    612616{
    613617  // Parser::parse() returns 0 in a syntax error occurs, so we just check for that
    614   ProgramNode *progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0);
    615   bool ok = (progNode != 0);
    616   if (progNode) {
    617     // must ref and deref to clean up properly
    618     progNode->ref();
    619     progNode->deref();
    620     delete progNode;
    621   }
    622   return ok;
     618  SharedPtr<ProgramNode> progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0);
     619  return progNode;
    623620}
    624621
     
    643640  int errLine;
    644641  UString errMsg;
    645   ProgramNode *progNode = Parser::parse(sourceURL, startingLineNumber, code.data(),code.size(),&sid,&errLine,&errMsg);
     642  SharedPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code.data(),code.size(),&sid,&errLine,&errMsg);
    646643
    647644  // notify debugger that source has been parsed
     
    671668
    672669  recursion++;
    673   progNode->ref();
    674670
    675671  ObjectImp *globalObj = globalObject();
     
    699695  }
    700696
    701   if (progNode->deref())
    702     delete progNode;
    703697  recursion--;
    704698
  • trunk/JavaScriptCore/kjs/internal.h

    r10182 r10352  
    3333#include "interpreter.h"
    3434#include "scope_chain.h"
     35#include "shared_ptr.h"
    3536
    3637#define I18N_NOOP(s) s
     
    195196  class Parser {
    196197  public:
    197     static ProgramNode *parse(const UString &sourceURL, int startingLineNumber,
    198                               const UChar *code, unsigned int length, int *sourceId = 0,
    199                               int *errLine = 0, UString *errMsg = 0);
    200 
    201     static ProgramNode *progNode;
     198    static kxmlcore::SharedPtr<ProgramNode> parse(const UString &sourceURL, int startingLineNumber,
     199                                                  const UChar *code, unsigned int length, int *sourceId = 0,
     200                                                  int *errLine = 0, UString *errMsg = 0);
     201    static void accept(ProgramNode *prog);
     202
    202203    static int sid;
    203204  };
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r10258 r10352  
    9999  line = Lexer::curr()->lineNo();
    100100  sourceURL = Lexer::curr()->sourceURL();
    101   refcount = 0;
    102 #ifdef KJS_DEBUG_MEM
    103   if (!s_nodes)
    104     s_nodes = new std::list<Node *>;
    105   s_nodes->push_back(this);
    106 #endif
     101  m_refcount = 0;
    107102}
    108103
    109104Node::~Node()
    110105{
    111 #ifdef KJS_DEBUG_MEM
    112   s_nodes->remove( this );
    113 #endif
    114106}
    115107
     
    337329// ------------------------------ GroupNode ------------------------------------
    338330
    339 void GroupNode::ref()
    340 {
    341   Node::ref();
    342   if ( group )
    343     group->ref();
    344 }
    345 
    346 bool GroupNode::deref()
    347 {
    348   if ( group && group->deref() )
    349     delete group;
    350   return Node::deref();
    351 }
    352 
    353331// ECMA 11.1.6
    354332ValueImp *GroupNode::evaluate(ExecState *exec)
     
    364342// ------------------------------ ElementNode ----------------------------------
    365343
    366 void ElementNode::ref()
    367 {
    368   for (ElementNode *n = this; n; n = n->list) {
    369     n->Node::ref();
    370     if (n->node)
    371       n->node->ref();
    372   }
    373 }
    374 
    375 bool ElementNode::deref()
    376 {
    377   ElementNode *next;
    378   for (ElementNode *n = this; n; n = next) {
    379     next = n->list;
    380     if (n->node && n->node->deref())
    381       delete n->node;
    382     if (n != this && n->Node::deref())
    383       delete n;
    384   }
    385   return Node::deref();
    386 }
    387 
    388344// ECMA 11.1.4
    389345ValueImp *ElementNode::evaluate(ExecState *exec)
     
    391347  ObjectImp *array = exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty());
    392348  int length = 0;
    393   for (ElementNode *n = this; n; n = n->list) {
     349  for (ElementNode *n = this; n; n = n->list.get()) {
    394350    ValueImp *val = n->node->evaluate(exec);
    395351    KJS_CHECKEXCEPTIONVALUE
     
    401357
    402358// ------------------------------ ArrayNode ------------------------------------
    403 
    404 void ArrayNode::ref()
    405 {
    406   Node::ref();
    407   if ( element )
    408     element->ref();
    409 }
    410 
    411 bool ArrayNode::deref()
    412 {
    413   if ( element && element->deref() )
    414     delete element;
    415   return Node::deref();
    416 }
    417359
    418360// ECMA 11.1.4
     
    440382// ------------------------------ ObjectLiteralNode ----------------------------
    441383
    442 void ObjectLiteralNode::ref()
    443 {
    444   Node::ref();
    445   if ( list )
    446     list->ref();
    447 }
    448 
    449 bool ObjectLiteralNode::deref()
    450 {
    451   if ( list && list->deref() )
    452     delete list;
    453   return Node::deref();
    454 }
    455 
    456384// ECMA 11.1.5
    457385ValueImp *ObjectLiteralNode::evaluate(ExecState *exec)
     
    465393// ------------------------------ PropertyValueNode ----------------------------
    466394
    467 void PropertyValueNode::ref()
    468 {
    469   for (PropertyValueNode *n = this; n; n = n->list) {
    470     n->Node::ref();
    471     if (n->name)
    472       n->name->ref();
    473     if (n->assign)
    474       n->assign->ref();
    475   }
    476 }
    477 
    478 bool PropertyValueNode::deref()
    479 {
    480   PropertyValueNode *next;
    481   for (PropertyValueNode *n = this; n; n = next) {
    482     next = n->list;
    483     if ( n->name && n->name->deref() )
    484       delete n->name;
    485     if ( n->assign && n->assign->deref() )
    486       delete n->assign;
    487     if (n != this && n->Node::deref() )
    488       delete n;
    489   }
    490   return Node::deref();
    491 }
    492 
    493395// ECMA 11.1.5
    494396ValueImp *PropertyValueNode::evaluate(ExecState *exec)
     
    496398  ObjectImp *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
    497399 
    498   for (PropertyValueNode *p = this; p; p = p->list) {
     400  for (PropertyValueNode *p = this; p; p = p->list.get()) {
    499401    ValueImp *n = p->name->evaluate(exec);
    500402    KJS_CHECKEXCEPTIONVALUE
     
    525427
    526428// ------------------------------ BracketAccessorNode --------------------------------
    527 
    528 void BracketAccessorNode::ref()
    529 {
    530   Node::ref();
    531   if ( expr1 )
    532     expr1->ref();
    533   if ( expr2 )
    534     expr2->ref();
    535 }
    536 
    537 bool BracketAccessorNode::deref()
    538 {
    539   if ( expr1 && expr1->deref() )
    540     delete expr1;
    541   if ( expr2 && expr2->deref() )
    542     delete expr2;
    543   return Node::deref();
    544 }
    545429
    546430// ECMA 11.2.1a
     
    573457// ------------------------------ DotAccessorNode --------------------------------
    574458
    575 void DotAccessorNode::ref()
    576 {
    577   Node::ref();
    578   if ( expr )
    579     expr->ref();
    580 }
    581 
    582 bool DotAccessorNode::deref()
    583 {
    584   if ( expr && expr->deref() )
    585     delete expr;
    586   return Node::deref();
    587 }
    588 
    589459// ECMA 11.2.1b
    590460ValueImp *DotAccessorNode::evaluate(ExecState *exec)
     
    606476// ------------------------------ ArgumentListNode -----------------------------
    607477
    608 void ArgumentListNode::ref()
    609 {
    610   for (ArgumentListNode *n = this; n; n = n->list) {
    611     n->Node::ref();
    612     if (n->expr)
    613       n->expr->ref();
    614   }
    615 }
    616 
    617 bool ArgumentListNode::deref()
    618 {
    619   ArgumentListNode *next;
    620   for (ArgumentListNode *n = this; n; n = next) {
    621     next = n->list;
    622     if (n->expr && n->expr->deref())
    623       delete n->expr;
    624     if (n != this && n->Node::deref())
    625       delete n;
    626   }
    627   return Node::deref();
    628 }
    629 
    630478ValueImp *ArgumentListNode::evaluate(ExecState */*exec*/)
    631479{
     
    639487  List l;
    640488
    641   for (ArgumentListNode *n = this; n; n = n->list) {
     489  for (ArgumentListNode *n = this; n; n = n->list.get()) {
    642490    ValueImp *v = n->expr->evaluate(exec);
    643491    KJS_CHECKEXCEPTIONLIST
     
    650498// ------------------------------ ArgumentsNode --------------------------------
    651499
    652 void ArgumentsNode::ref()
    653 {
    654   Node::ref();
    655   if ( list )
    656     list->ref();
    657 }
    658 
    659 bool ArgumentsNode::deref()
    660 {
    661   if ( list && list->deref() )
    662     delete list;
    663   return Node::deref();
    664 }
    665 
    666500ValueImp *ArgumentsNode::evaluate(ExecState */*exec*/)
    667501{
     
    682516
    683517// ECMA 11.2.2
    684 
    685 void NewExprNode::ref()
    686 {
    687   Node::ref();
    688   if ( expr )
    689     expr->ref();
    690   if ( args )
    691     args->ref();
    692 }
    693 
    694 bool NewExprNode::deref()
    695 {
    696   if ( expr && expr->deref() )
    697     delete expr;
    698   if ( args && args->deref() )
    699     delete args;
    700   return Node::deref();
    701 }
    702518
    703519ValueImp *NewExprNode::evaluate(ExecState *exec)
     
    713529
    714530  if (!v->isObject()) {
    715     return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr);
     531    return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr.get());
    716532  }
    717533
    718534  ObjectImp *constr = static_cast<ObjectImp*>(v);
    719535  if (!constr->implementsConstruct()) {
    720     return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr);
     536    return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr.get());
    721537  }
    722538
    723539  return constr->construct(exec, argList);
    724 }
    725 
    726 void FunctionCallValueNode::ref()
    727 {
    728   Node::ref();
    729   if (expr)
    730     expr->ref();
    731   if (args)
    732     args->ref();
    733 }
    734 
    735 bool FunctionCallValueNode::deref()
    736 {
    737   if (expr && expr->deref())
    738     delete expr;
    739   if (args && args->deref())
    740     delete args;
    741   return Node::deref();
    742540}
    743541
     
    749547
    750548  if (!v->isObject()) {
    751     return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr);
     549    return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr.get());
    752550  }
    753551 
     
    755553
    756554  if (!func->implementsCall()) {
    757     return throwError(exec, TypeError, "Object %s (result of expression %s) does not allow calls.", v, expr);
     555    return throwError(exec, TypeError, "Object %s (result of expression %s) does not allow calls.", v, expr.get());
    758556  }
    759557
     
    764562
    765563  return func->call(exec, thisObj, argList);
    766 }
    767 
    768 
    769 void FunctionCallResolveNode::ref()
    770 {
    771   Node::ref();
    772   if (args)
    773     args->ref();
    774 }
    775 
    776 bool FunctionCallResolveNode::deref()
    777 {
    778   if (args && args->deref())
    779     delete args;
    780   return Node::deref();
    781564}
    782565
     
    830613}
    831614
    832 void FunctionCallBracketNode::ref()
    833 {
    834   Node::ref();
    835   if (base)
    836     base->ref();
    837   if (subscript)
    838     base->ref();
    839   if (args)
    840     args->ref();
    841 }
    842 
    843 bool FunctionCallBracketNode::deref()
    844 {
    845   if (base && base->deref())
    846     delete base;
    847   if (subscript && subscript->deref())
    848     delete subscript;
    849   if (args && args->deref())
    850     delete args;
    851   return Node::deref();
    852 }
    853 
    854615// ECMA 11.2.3
    855616ValueImp *FunctionCallBracketNode::evaluate(ExecState *exec)
     
    881642 
    882643  if (!funcVal->isObject()) {
    883     return throwError(exec, TypeError, "Value %s (result of expression %s[%s]) is not object.", funcVal, base, subscript);
     644    return throwError(exec, TypeError, "Value %s (result of expression %s[%s]) is not object.", funcVal, base.get(), subscript.get());
    884645  }
    885646 
     
    887648
    888649  if (!func->implementsCall()) {
    889     return throwError(exec, TypeError, "Object %s (result of expression %s[%s]) does not allow calls.", funcVal, base, subscript);
     650    return throwError(exec, TypeError, "Object %s (result of expression %s[%s]) does not allow calls.", funcVal, base.get(), subscript.get());
    890651  }
    891652
     
    901662}
    902663
    903 
    904 void FunctionCallDotNode::ref()
    905 {
    906   Node::ref();
    907   if (base)
    908     base->ref();
    909   if (args)
    910     args->ref();
    911 }
    912 
    913 bool FunctionCallDotNode::deref()
    914 {
    915   if (base && base->deref())
    916     delete base;
    917   if (args && args->deref())
    918     delete args;
    919   return Node::deref();
    920 }
    921 
    922664static const char *dotExprNotAnObjectString()
    923665{
     
    941683
    942684  if (!funcVal->isObject())
    943     return throwError(exec, TypeError, dotExprNotAnObjectString(), funcVal, base, ident);
     685    return throwError(exec, TypeError, dotExprNotAnObjectString(), funcVal, base.get(), ident);
    944686 
    945687  ObjectImp *func = static_cast<ObjectImp*>(funcVal);
    946688
    947689  if (!func->implementsCall())
    948     return throwError(exec, TypeError, dotExprDoesNotAllowCallsString(), funcVal, base, ident);
     690    return throwError(exec, TypeError, dotExprDoesNotAllowCallsString(), funcVal, base.get(), ident);
    949691
    950692  List argList = args->evaluateList(exec);
     
    961703// ------------------------------ PostfixNode ----------------------------------
    962704
    963 void PostfixNode::ref()
    964 {
    965   Node::ref();
    966   if ( expr )
    967     expr->ref();
    968 }
    969 
    970 bool PostfixNode::deref()
    971 {
    972   if ( expr && expr->deref() )
    973     delete expr;
    974   return Node::deref();
    975 }
    976 
    977705// ECMA 11.3
    978706ValueImp *PostfixNode::evaluate(ExecState *exec)
     
    993721// ------------------------------ DeleteNode -----------------------------------
    994722
    995 void DeleteNode::ref()
    996 {
    997   Node::ref();
    998   if ( expr )
    999     expr->ref();
    1000 }
    1001 
    1002 bool DeleteNode::deref()
    1003 {
    1004   if ( expr && expr->deref() )
    1005     delete expr;
    1006   return Node::deref();
    1007 }
    1008 
    1009723// ECMA 11.4.1
    1010724ValueImp *DeleteNode::evaluate(ExecState *exec)
     
    1017731// ------------------------------ VoidNode -------------------------------------
    1018732
    1019 void VoidNode::ref()
    1020 {
    1021   Node::ref();
    1022   if ( expr )
    1023     expr->ref();
    1024 }
    1025 
    1026 bool VoidNode::deref()
    1027 {
    1028   if ( expr && expr->deref() )
    1029     delete expr;
    1030   return Node::deref();
    1031 }
    1032 
    1033733// ECMA 11.4.2
    1034734ValueImp *VoidNode::evaluate(ExecState *exec)
     
    1041741
    1042742// ------------------------------ TypeOfNode -----------------------------------
    1043 
    1044 void TypeOfNode::ref()
    1045 {
    1046   Node::ref();
    1047   if ( expr )
    1048     expr->ref();
    1049 }
    1050 
    1051 bool TypeOfNode::deref()
    1052 {
    1053   if ( expr && expr->deref() )
    1054     delete expr;
    1055   return Node::deref();
    1056 }
    1057743
    1058744// ECMA 11.4.3
     
    1096782// ------------------------------ PrefixNode -----------------------------------
    1097783
    1098 void PrefixNode::ref()
    1099 {
    1100   Node::ref();
    1101   if ( expr )
    1102     expr->ref();
    1103 }
    1104 
    1105 bool PrefixNode::deref()
    1106 {
    1107   if ( expr && expr->deref() )
    1108     delete expr;
    1109   return Node::deref();
    1110 }
    1111 
    1112784// ECMA 11.4.4 and 11.4.5
    1113785ValueImp *PrefixNode::evaluate(ExecState *exec)
     
    1130802// ------------------------------ UnaryPlusNode --------------------------------
    1131803
    1132 void UnaryPlusNode::ref()
    1133 {
    1134   Node::ref();
    1135   if ( expr )
    1136     expr->ref();
    1137 }
    1138 
    1139 bool UnaryPlusNode::deref()
    1140 {
    1141   if ( expr && expr->deref() )
    1142     delete expr;
    1143   return Node::deref();
    1144 }
    1145 
    1146804// ECMA 11.4.6
    1147805ValueImp *UnaryPlusNode::evaluate(ExecState *exec)
     
    1154812
    1155813// ------------------------------ NegateNode -----------------------------------
    1156 
    1157 void NegateNode::ref()
    1158 {
    1159   Node::ref();
    1160   if ( expr )
    1161     expr->ref();
    1162 }
    1163 
    1164 bool NegateNode::deref()
    1165 {
    1166   if ( expr && expr->deref() )
    1167     delete expr;
    1168   return Node::deref();
    1169 }
    1170814
    1171815// ECMA 11.4.7
     
    1182826// ------------------------------ BitwiseNotNode -------------------------------
    1183827
    1184 void BitwiseNotNode::ref()
    1185 {
    1186   Node::ref();
    1187   if ( expr )
    1188     expr->ref();
    1189 }
    1190 
    1191 bool BitwiseNotNode::deref()
    1192 {
    1193   if ( expr && expr->deref() )
    1194     delete expr;
    1195   return Node::deref();
    1196 }
    1197 
    1198828// ECMA 11.4.8
    1199829ValueImp *BitwiseNotNode::evaluate(ExecState *exec)
     
    1206836// ------------------------------ LogicalNotNode -------------------------------
    1207837
    1208 void LogicalNotNode::ref()
    1209 {
    1210   Node::ref();
    1211   if ( expr )
    1212     expr->ref();
    1213 }
    1214 
    1215 bool LogicalNotNode::deref()
    1216 {
    1217   if ( expr && expr->deref() )
    1218     delete expr;
    1219   return Node::deref();
    1220 }
    1221 
    1222838// ECMA 11.4.9
    1223839ValueImp *LogicalNotNode::evaluate(ExecState *exec)
     
    1230846// ------------------------------ MultNode -------------------------------------
    1231847
    1232 void MultNode::ref()
    1233 {
    1234   Node::ref();
    1235   if ( term1 )
    1236     term1->ref();
    1237   if ( term2 )
    1238     term2->ref();
    1239 }
    1240 
    1241 bool MultNode::deref()
    1242 {
    1243   if ( term1 && term1->deref() )
    1244     delete term1;
    1245   if ( term2 && term2->deref() )
    1246     delete term2;
    1247   return Node::deref();
    1248 }
    1249 
    1250848// ECMA 11.5
    1251849ValueImp *MultNode::evaluate(ExecState *exec)
     
    1262860// ------------------------------ AddNode --------------------------------------
    1263861
    1264 void AddNode::ref()
    1265 {
    1266   Node::ref();
    1267   if ( term1 )
    1268     term1->ref();
    1269   if ( term2 )
    1270     term2->ref();
    1271 }
    1272 
    1273 bool AddNode::deref()
    1274 {
    1275   if ( term1 && term1->deref() )
    1276     delete term1;
    1277   if ( term2 && term2->deref() )
    1278     delete term2;
    1279   return Node::deref();
    1280 }
    1281 
    1282862// ECMA 11.6
    1283863ValueImp *AddNode::evaluate(ExecState *exec)
     
    1293873
    1294874// ------------------------------ ShiftNode ------------------------------------
    1295 
    1296 void ShiftNode::ref()
    1297 {
    1298   Node::ref();
    1299   if ( term1 )
    1300     term1->ref();
    1301   if ( term2 )
    1302     term2->ref();
    1303 }
    1304 
    1305 bool ShiftNode::deref()
    1306 {
    1307   if ( term1 && term1->deref() )
    1308     delete term1;
    1309   if ( term2 && term2->deref() )
    1310     delete term2;
    1311   return Node::deref();
    1312 }
    1313875
    1314876// ECMA 11.7
     
    1336898
    1337899// ------------------------------ RelationalNode -------------------------------
    1338 
    1339 void RelationalNode::ref()
    1340 {
    1341   Node::ref();
    1342   if ( expr1 )
    1343     expr1->ref();
    1344   if ( expr2 )
    1345     expr2->ref();
    1346 }
    1347 
    1348 bool RelationalNode::deref()
    1349 {
    1350   if ( expr1 && expr1->deref() )
    1351     delete expr1;
    1352   if ( expr2 && expr2->deref() )
    1353     delete expr2;
    1354   return Node::deref();
    1355 }
    1356900
    1357901// ECMA 11.8
     
    1380924      if (!v2->isObject())
    1381925          return throwError(exec,  TypeError,
    1382                              "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2);
     926                             "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2.get());
    1383927      ObjectImp *o2(static_cast<ObjectImp*>(v2));
    1384928      b = o2->hasProperty(exec, Identifier(v1->toString(exec)));
     
    1386930    if (!v2->isObject())
    1387931        return throwError(exec,  TypeError,
    1388                            "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2);
     932                           "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2.get());
    1389933
    1390934    ObjectImp *o2(static_cast<ObjectImp*>(v2));
     
    1406950// ------------------------------ EqualNode ------------------------------------
    1407951
    1408 void EqualNode::ref()
    1409 {
    1410   Node::ref();
    1411   if ( expr1 )
    1412     expr1->ref();
    1413   if ( expr2 )
    1414     expr2->ref();
    1415 }
    1416 
    1417 bool EqualNode::deref()
    1418 {
    1419   if ( expr1 && expr1->deref() )
    1420     delete expr1;
    1421   if ( expr2 && expr2->deref() )
    1422     delete expr2;
    1423   return Node::deref();
    1424 }
    1425 
    1426952// ECMA 11.9
    1427953ValueImp *EqualNode::evaluate(ExecState *exec)
     
    1447973// ------------------------------ BitOperNode ----------------------------------
    1448974
    1449 void BitOperNode::ref()
    1450 {
    1451   Node::ref();
    1452   if ( expr1 )
    1453     expr1->ref();
    1454   if ( expr2 )
    1455     expr2->ref();
    1456 }
    1457 
    1458 bool BitOperNode::deref()
    1459 {
    1460   if ( expr1 && expr1->deref() )
    1461     delete expr1;
    1462   if ( expr2 && expr2->deref() )
    1463     delete expr2;
    1464   return Node::deref();
    1465 }
    1466 
    1467975// ECMA 11.10
    1468976ValueImp *BitOperNode::evaluate(ExecState *exec)
     
    1487995// ------------------------------ BinaryLogicalNode ----------------------------
    1488996
    1489 void BinaryLogicalNode::ref()
    1490 {
    1491   Node::ref();
    1492   if ( expr1 )
    1493     expr1->ref();
    1494   if ( expr2 )
    1495     expr2->ref();
    1496 }
    1497 
    1498 bool BinaryLogicalNode::deref()
    1499 {
    1500   if ( expr1 && expr1->deref() )
    1501     delete expr1;
    1502   if ( expr2 && expr2->deref() )
    1503     delete expr2;
    1504   return Node::deref();
    1505 }
    1506 
    1507997// ECMA 11.11
    1508998ValueImp *BinaryLogicalNode::evaluate(ExecState *exec)
     
    15211011
    15221012// ------------------------------ ConditionalNode ------------------------------
    1523 
    1524 void ConditionalNode::ref()
    1525 {
    1526   Node::ref();
    1527   if ( expr1 )
    1528     expr1->ref();
    1529   if ( expr2 )
    1530     expr2->ref();
    1531   if ( logical )
    1532     logical->ref();
    1533 }
    1534 
    1535 bool ConditionalNode::deref()
    1536 {
    1537   if ( expr1 && expr1->deref() )
    1538     delete expr1;
    1539   if ( expr2 && expr2->deref() )
    1540     delete expr2;
    1541   if ( logical && logical->deref() )
    1542     delete logical;
    1543   return Node::deref();
    1544 }
    15451013
    15461014// ECMA 11.12
     
    16321100// ------------------------------ AssignResolveNode -----------------------------------
    16331101
    1634 void AssignResolveNode::ref()
    1635 {
    1636   Node::ref();
    1637   if (m_right)
    1638     m_right->ref();
    1639 }
    1640 
    1641 bool AssignResolveNode::deref()
    1642 {
    1643   if (m_right && m_right->deref())
    1644     delete m_right;
    1645 
    1646   return Node::deref();
    1647 }
    1648 
    16491102ValueImp *AssignResolveNode::evaluate(ExecState *exec)
    16501103{
     
    16881141
    16891142// ------------------------------ AssignDotNode -----------------------------------
    1690 
    1691 void AssignDotNode::ref()
    1692 {
    1693   Node::ref();
    1694   if (m_base)
    1695     m_base->ref();
    1696   if (m_right)
    1697     m_right->ref();
    1698 }
    1699 
    1700 bool AssignDotNode::deref()
    1701 {
    1702   if (m_base && m_base->deref())
    1703     delete m_base;
    1704   if (m_right && m_right->deref())
    1705     delete m_right;
    1706   return Node::deref();
    1707 }
    17081143
    17091144ValueImp *AssignDotNode::evaluate(ExecState *exec)
     
    17321167
    17331168// ------------------------------ AssignBracketNode -----------------------------------
    1734 
    1735 void AssignBracketNode::ref()
    1736 {
    1737   Node::ref();
    1738   if (m_base)
    1739     m_base->ref();
    1740   if (m_subscript)
    1741     m_subscript->ref();
    1742   if (m_right)
    1743     m_right->ref();
    1744 }
    1745 
    1746 bool AssignBracketNode::deref()
    1747 {
    1748   if (m_base && m_base->deref())
    1749     delete m_base;
    1750   if (m_subscript && m_subscript->deref())
    1751     delete m_subscript;
    1752   if (m_right && m_right->deref())
    1753     delete m_right;
    1754 
    1755   return Node::deref();
    1756 }
    17571169
    17581170ValueImp *AssignBracketNode::evaluate(ExecState *exec)
     
    18051217// ------------------------------ CommaNode ------------------------------------
    18061218
    1807 void CommaNode::ref()
    1808 {
    1809   Node::ref();
    1810   if ( expr1 )
    1811     expr1->ref();
    1812   if ( expr2 )
    1813     expr2->ref();
    1814 }
    1815 
    1816 bool CommaNode::deref()
    1817 {
    1818   if ( expr1 && expr1->deref() )
    1819     delete expr1;
    1820   if ( expr2 && expr2->deref() )
    1821     delete expr2;
    1822   return Node::deref();
    1823 }
    1824 
    18251219// ECMA 11.14
    18261220ValueImp *CommaNode::evaluate(ExecState *exec)
     
    18471241  l->list = this;
    18481242  setLoc(l->firstLine(), s->lastLine(), l->sourceId());
    1849 }
    1850 
    1851 void StatListNode::ref()
    1852 {
    1853   for (StatListNode *n = this; n; n = n->list) {
    1854     n->Node::ref();
    1855     if (n->statement)
    1856       n->statement->ref();
    1857   }
    1858 }
    1859 
    1860 bool StatListNode::deref()
    1861 {
    1862   StatListNode *next;
    1863   for (StatListNode *n = this; n; n = next) {
    1864     next = n->list;
    1865     if (n->statement && n->statement->deref())
    1866       delete n->statement;
    1867     if (n != this && n->Node::deref())
    1868       delete n;
    1869   }
    1870   return Node::deref();
    18711243}
    18721244
     
    18871259  ValueImp *v = c.value();
    18881260 
    1889   for (StatListNode *n = list; n; n = n->list) {
     1261  for (StatListNode *n = list.get(); n; n = n->list.get()) {
    18901262    Completion c2 = n->statement->execute(exec);
    18911263    KJS_ABORTPOINT
     
    19091281void StatListNode::processVarDecls(ExecState *exec)
    19101282{
    1911   for (StatListNode *n = this; n; n = n->list)
     1283  for (StatListNode *n = this; n; n = n->list.get())
    19121284    n->statement->processVarDecls(exec);
    19131285}
    19141286
    19151287// ------------------------------ AssignExprNode -------------------------------
    1916 
    1917 void AssignExprNode::ref()
    1918 {
    1919   Node::ref();
    1920   if ( expr )
    1921     expr->ref();
    1922 }
    1923 
    1924 bool AssignExprNode::deref()
    1925 {
    1926   if ( expr && expr->deref() )
    1927     delete expr;
    1928   return Node::deref();
    1929 }
    19301288
    19311289// ECMA 12.2
     
    19411299    : varType(t), ident(id), init(in)
    19421300{
    1943 }
    1944 
    1945 void VarDeclNode::ref()
    1946 {
    1947   Node::ref();
    1948   if ( init )
    1949     init->ref();
    1950 }
    1951 
    1952 bool VarDeclNode::deref()
    1953 {
    1954   if ( init && init->deref() )
    1955     delete init;
    1956   return Node::deref();
    19571301}
    19581302
     
    20071351// ------------------------------ VarDeclListNode ------------------------------
    20081352
    2009 void VarDeclListNode::ref()
    2010 {
    2011   for (VarDeclListNode *n = this; n; n = n->list) {
    2012     n->Node::ref();
    2013     if (n->var)
    2014       n->var->ref();
    2015   }
    2016 }
    2017 
    2018 bool VarDeclListNode::deref()
    2019 {
    2020   VarDeclListNode *next;
    2021   for (VarDeclListNode *n = this; n; n = next) {
    2022     next = n->list;
    2023     if (n->var && n->var->deref())
    2024       delete n->var;
    2025     if (n != this && n->Node::deref())
    2026       delete n;
    2027   }
    2028   return Node::deref();
    2029 }
    2030 
    2031 
    20321353// ECMA 12.2
    20331354ValueImp *VarDeclListNode::evaluate(ExecState *exec)
    20341355{
    2035   for (VarDeclListNode *n = this; n; n = n->list) {
     1356  for (VarDeclListNode *n = this; n; n = n->list.get()) {
    20361357    n->var->evaluate(exec);
    20371358    KJS_CHECKEXCEPTIONVALUE
     
    20421363void VarDeclListNode::processVarDecls(ExecState *exec)
    20431364{
    2044   for (VarDeclListNode *n = this; n; n = n->list)
     1365  for (VarDeclListNode *n = this; n; n = n->list.get())
    20451366    n->var->processVarDecls(exec);
    20461367}
    20471368
    20481369// ------------------------------ VarStatementNode -----------------------------
    2049 
    2050 void VarStatementNode::ref()
    2051 {
    2052   Node::ref();
    2053   if ( list )
    2054     list->ref();
    2055 }
    2056 
    2057 bool VarStatementNode::deref()
    2058 {
    2059   if ( list && list->deref() )
    2060     delete list;
    2061   return Node::deref();
    2062 }
    20631370
    20641371// ECMA 12.2
     
    20911398}
    20921399
    2093 void BlockNode::ref()
    2094 {
    2095   Node::ref();
    2096   if ( source )
    2097     source->ref();
    2098 }
    2099 
    2100 bool BlockNode::deref()
    2101 {
    2102   if ( source && source->deref() )
    2103     delete source;
    2104   return Node::deref();
    2105 }
    2106 
    21071400// ECMA 12.1
    21081401Completion BlockNode::execute(ExecState *exec)
     
    21321425// ------------------------------ ExprStatementNode ----------------------------
    21331426
    2134 void ExprStatementNode::ref()
    2135 {
    2136   Node::ref();
    2137   if ( expr )
    2138     expr->ref();
    2139 }
    2140 
    2141 bool ExprStatementNode::deref()
    2142 {
    2143   if ( expr && expr->deref() )
    2144     delete expr;
    2145   return Node::deref();
    2146 }
    2147 
    21481427// ECMA 12.4
    21491428Completion ExprStatementNode::execute(ExecState *exec)
     
    21581437
    21591438// ------------------------------ IfNode ---------------------------------------
    2160 
    2161 void IfNode::ref()
    2162 {
    2163   Node::ref();
    2164   if ( statement1 )
    2165     statement1->ref();
    2166   if ( statement2 )
    2167     statement2->ref();
    2168   if ( expr )
    2169     expr->ref();
    2170 }
    2171 
    2172 bool IfNode::deref()
    2173 {
    2174   if ( statement1 && statement1->deref() )
    2175     delete statement1;
    2176   if ( statement2 && statement2->deref() )
    2177     delete statement2;
    2178   if ( expr && expr->deref() )
    2179     delete expr;
    2180   return Node::deref();
    2181 }
    21821439
    21831440// ECMA 12.5
     
    22111468
    22121469// ------------------------------ DoWhileNode ----------------------------------
    2213 
    2214 void DoWhileNode::ref()
    2215 {
    2216   Node::ref();
    2217   if ( statement )
    2218     statement->ref();
    2219   if ( expr )
    2220     expr->ref();
    2221 }
    2222 
    2223 bool DoWhileNode::deref()
    2224 {
    2225   if ( statement && statement->deref() )
    2226     delete statement;
    2227   if ( expr && expr->deref() )
    2228     delete expr;
    2229   return Node::deref();
    2230 }
    22311470
    22321471// ECMA 12.6.1
     
    22651504// ------------------------------ WhileNode ------------------------------------
    22661505
    2267 void WhileNode::ref()
    2268 {
    2269   Node::ref();
    2270   if ( statement )
    2271     statement->ref();
    2272   if ( expr )
    2273     expr->ref();
    2274 }
    2275 
    2276 bool WhileNode::deref()
    2277 {
    2278   if ( statement && statement->deref() )
    2279     delete statement;
    2280   if ( expr && expr->deref() )
    2281     delete expr;
    2282   return Node::deref();
    2283 }
    2284 
    22851506// ECMA 12.6.2
    22861507Completion WhileNode::execute(ExecState *exec)
     
    23271548
    23281549// ------------------------------ ForNode --------------------------------------
    2329 
    2330 void ForNode::ref()
    2331 {
    2332   Node::ref();
    2333   if ( statement )
    2334     statement->ref();
    2335   if ( expr1 )
    2336     expr1->ref();
    2337   if ( expr2 )
    2338     expr2->ref();
    2339   if ( expr3 )
    2340     expr3->ref();
    2341 }
    2342 
    2343 bool ForNode::deref()
    2344 {
    2345   if ( statement && statement->deref() )
    2346     delete statement;
    2347   if ( expr1 && expr1->deref() )
    2348     delete expr1;
    2349   if ( expr2 && expr2->deref() )
    2350     delete expr2;
    2351   if ( expr3 && expr3->deref() )
    2352     delete expr3;
    2353   return Node::deref();
    2354 }
    23551550
    23561551// ECMA 12.6.3
     
    24121607{
    24131608  // for( var foo = bar in baz )
    2414   varDecl = new VarDeclNode(ident, init, VarDeclNode::Variable);
     1609  varDecl = new VarDeclNode(ident, init.get(), VarDeclNode::Variable);
    24151610  lexpr = new ResolveNode(ident);
    2416 }
    2417 
    2418 void ForInNode::ref()
    2419 {
    2420   Node::ref();
    2421   if ( statement )
    2422     statement->ref();
    2423   if ( expr )
    2424     expr->ref();
    2425   if ( lexpr )
    2426     lexpr->ref();
    2427   if ( init )
    2428     init->ref();
    2429   if ( varDecl )
    2430     varDecl->ref();
    2431 }
    2432 
    2433 bool ForInNode::deref()
    2434 {
    2435   if ( statement && statement->deref() )
    2436     delete statement;
    2437   if ( expr && expr->deref() )
    2438     delete expr;
    2439   if ( lexpr && lexpr->deref() )
    2440     delete lexpr;
    2441   if ( init && init->deref() )
    2442     delete init;
    2443   if ( varDecl && varDecl->deref() )
    2444     delete varDecl;
    2445   return Node::deref();
    24461611}
    24471612
     
    25521717// ------------------------------ ReturnNode -----------------------------------
    25531718
    2554 void ReturnNode::ref()
    2555 {
    2556   Node::ref();
    2557   if ( value )
    2558     value->ref();
    2559 }
    2560 
    2561 bool ReturnNode::deref()
    2562 {
    2563   if ( value && value->deref() )
    2564     delete value;
    2565   return Node::deref();
    2566 }
    2567 
    25681719// ECMA 12.9
    25691720Completion ReturnNode::execute(ExecState *exec)
     
    25861737
    25871738// ------------------------------ WithNode -------------------------------------
    2588 
    2589 void WithNode::ref()
    2590 {
    2591   Node::ref();
    2592   if ( statement )
    2593     statement->ref();
    2594   if ( expr )
    2595     expr->ref();
    2596 }
    2597 
    2598 bool WithNode::deref()
    2599 {
    2600   if ( statement && statement->deref() )
    2601     delete statement;
    2602   if ( expr && expr->deref() )
    2603     delete expr;
    2604   return Node::deref();
    2605 }
    26061739
    26071740// ECMA 12.10
     
    26281761// ------------------------------ CaseClauseNode -------------------------------
    26291762
    2630 void CaseClauseNode::ref()
    2631 {
    2632   Node::ref();
    2633   if ( expr )
    2634     expr->ref();
    2635   if ( list )
    2636     list->ref();
    2637 }
    2638 
    2639 bool CaseClauseNode::deref()
    2640 {
    2641   if ( expr && expr->deref() )
    2642     delete expr;
    2643   if ( list && list->deref() )
    2644     delete list;
    2645   return Node::deref();
    2646 }
    2647 
    26481763// ECMA 12.11
    26491764ValueImp *CaseClauseNode::evaluate(ExecState *exec)
     
    26721787// ------------------------------ ClauseListNode -------------------------------
    26731788
    2674 void ClauseListNode::ref()
    2675 {
    2676   for (ClauseListNode *n = this; n; n = n->nx) {
    2677     n->Node::ref();
    2678     if (n->cl)
    2679       n->cl->ref();
    2680   }
    2681 }
    2682 
    2683 bool ClauseListNode::deref()
    2684 {
    2685   ClauseListNode *next;
    2686   for (ClauseListNode *n = this; n; n = next) {
    2687     next = n->nx;
    2688     if (n->cl && n->cl->deref())
    2689       delete n->cl;
    2690     if (n != this && n->Node::deref())
    2691       delete n;
    2692   }
    2693   return Node::deref();
    2694 }
    2695 
    26961789ValueImp *ClauseListNode::evaluate(ExecState */*exec*/)
    26971790{
     
    27041797void ClauseListNode::processVarDecls(ExecState *exec)
    27051798{
    2706   for (ClauseListNode *n = this; n; n = n->nx)
     1799  for (ClauseListNode *n = this; n; n = n->nx.get())
    27071800    if (n->cl)
    27081801      n->cl->processVarDecls(exec);
     
    27311824}
    27321825 
    2733 void CaseBlockNode::ref()
    2734 {
    2735   Node::ref();
    2736   if ( def )
    2737     def->ref();
    2738   if ( list1 )
    2739     list1->ref();
    2740   if ( list2 )
    2741     list2->ref();
    2742 }
    2743 
    2744 bool CaseBlockNode::deref()
    2745 {
    2746   if ( def && def->deref() )
    2747     delete def;
    2748   if ( list1 && list1->deref() )
    2749     delete list1;
    2750   if ( list2 && list2->deref() )
    2751     delete list2;
    2752   return Node::deref();
    2753 }
    2754 
    27551826ValueImp *CaseBlockNode::evaluate(ExecState */*exec*/)
    27561827{
     
    27651836  ValueImp *v;
    27661837  Completion res;
    2767   ClauseListNode *a = list1, *b = list2;
     1838  ClauseListNode *a = list1.get();
     1839  ClauseListNode *b = list2.get();
    27681840  CaseClauseNode *clause;
    27691841
     
    28061878      return res;
    28071879  }
    2808   b = list2;
     1880  b = list2.get();
    28091881 step18:
    28101882  while (b) {
     
    28341906// ------------------------------ SwitchNode -----------------------------------
    28351907
    2836 void SwitchNode::ref()
    2837 {
    2838   Node::ref();
    2839   if ( expr )
    2840     expr->ref();
    2841   if ( block )
    2842     block->ref();
    2843 }
    2844 
    2845 bool SwitchNode::deref()
    2846 {
    2847   if ( expr && expr->deref() )
    2848     delete expr;
    2849   if ( block && block->deref() )
    2850     delete block;
    2851   return Node::deref();
    2852 }
    2853 
    28541908// ECMA 12.11
    28551909Completion SwitchNode::execute(ExecState *exec)
     
    28751929
    28761930// ------------------------------ LabelNode ------------------------------------
    2877 
    2878 void LabelNode::ref()
    2879 {
    2880   Node::ref();
    2881   if ( statement )
    2882     statement->ref();
    2883 }
    2884 
    2885 bool LabelNode::deref()
    2886 {
    2887   if ( statement && statement->deref() )
    2888     delete statement;
    2889   return Node::deref();
    2890 }
    28911931
    28921932// ECMA 12.12
     
    29141954// ------------------------------ ThrowNode ------------------------------------
    29151955
    2916 void ThrowNode::ref()
    2917 {
    2918   Node::ref();
    2919   if ( expr )
    2920     expr->ref();
    2921 }
    2922 
    2923 bool ThrowNode::deref()
    2924 {
    2925   if ( expr && expr->deref() )
    2926     delete expr;
    2927   return Node::deref();
    2928 }
    2929 
    29301956// ECMA 12.13
    29311957Completion ThrowNode::execute(ExecState *exec)
     
    29401966
    29411967// ------------------------------ CatchNode ------------------------------------
    2942 
    2943 void CatchNode::ref()
    2944 {
    2945   Node::ref();
    2946   if ( block )
    2947     block->ref();
    2948 }
    2949 
    2950 bool CatchNode::deref()
    2951 {
    2952   if ( block && block->deref() )
    2953     delete block;
    2954   return Node::deref();
    2955 }
    29561968
    29571969Completion CatchNode::execute(ExecState */*exec*/)
     
    29851997// ------------------------------ FinallyNode ----------------------------------
    29861998
    2987 void FinallyNode::ref()
    2988 {
    2989   Node::ref();
    2990   if ( block )
    2991     block->ref();
    2992 }
    2993 
    2994 bool FinallyNode::deref()
    2995 {
    2996   if ( block && block->deref() )
    2997     delete block;
    2998   return Node::deref();
    2999 }
    3000 
    30011999// ECMA 12.14
    30022000Completion FinallyNode::execute(ExecState *exec)
     
    30112009
    30122010// ------------------------------ TryNode --------------------------------------
    3013 
    3014 void TryNode::ref()
    3015 {
    3016   Node::ref();
    3017   if ( block )
    3018     block->ref();
    3019   if ( _final )
    3020     _final->ref();
    3021   if ( _catch )
    3022     _catch->ref();
    3023 }
    3024 
    3025 bool TryNode::deref()
    3026 {
    3027   if ( block && block->deref() )
    3028     delete block;
    3029   if ( _final && _final->deref() )
    3030     delete _final;
    3031   if ( _catch && _catch->deref() )
    3032     delete _catch;
    3033   return Node::deref();
    3034 }
    30352011
    30362012// ECMA 12.14
     
    30792055// ------------------------------ ParameterNode --------------------------------
    30802056
    3081 void ParameterNode::ref()
    3082 {
    3083   for (ParameterNode *n = this; n; n = n->next)
    3084     n->Node::ref();
    3085 }
    3086 
    3087 bool ParameterNode::deref()
    3088 {
    3089   ParameterNode *next;
    3090   for (ParameterNode *n = this; n; n = next) {
    3091     next = n->next;
    3092     if (n != this && n->Node::deref())
    3093       delete n;
    3094   }
    3095   return Node::deref();
    3096 }
    3097 
    30982057// ECMA 13
    30992058ValueImp *ParameterNode::evaluate(ExecState */*exec*/)
     
    31192078// ------------------------------ FuncDeclNode ---------------------------------
    31202079
    3121 void FuncDeclNode::ref()
    3122 {
    3123   Node::ref();
    3124   if ( param )
    3125     param->ref();
    3126   if ( body )
    3127     body->ref();
    3128 }
    3129 
    3130 bool FuncDeclNode::deref()
    3131 {
    3132   if ( param && param->deref() )
    3133     delete param;
    3134   if ( body && body->deref() )
    3135     delete body;
    3136   return Node::deref();
    3137 }
    3138 
    31392080// ECMA 13
    31402081void FuncDeclNode::processFuncDecl(ExecState *exec)
     
    31432084
    31442085  // TODO: let this be an object with [[Class]] property "Function"
    3145   FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, context->scopeChain());
     2086  FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain());
    31462087  ObjectImp *func(fimp); // protect from GC
    31472088
     
    31512092
    31522093  int plen = 0;
    3153   for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
     2094  for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++)
    31542095    fimp->addParameter(p->ident());
    31552096
     
    31732114// ------------------------------ FuncExprNode ---------------------------------
    31742115
    3175 void FuncExprNode::ref()
    3176 {
    3177   Node::ref();
    3178   if ( param )
    3179     param->ref();
    3180   if ( body )
    3181     body->ref();
    3182 }
    3183 
    3184 bool FuncExprNode::deref()
    3185 {
    3186   if ( param && param->deref() )
    3187     delete param;
    3188   if ( body && body->deref() )
    3189     delete body;
    3190   return Node::deref();
    3191 }
    3192 
    3193 
    31942116// ECMA 13
    31952117ValueImp *FuncExprNode::evaluate(ExecState *exec)
    31962118{
    3197   FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body, exec->context().imp()->scopeChain());
     2119  FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body.get(), exec->context().imp()->scopeChain());
    31982120  ValueImp *ret(fimp);
    31992121  ValueImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
     
    32012123
    32022124  int plen = 0;
    3203   for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
     2125  for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++)
    32042126    fimp->addParameter(p->ident());
    32052127
     
    32202142  s1->elements = this;
    32212143  setLoc(s1->firstLine(), s2->lastLine(), s1->sourceId());
    3222 }
    3223 
    3224 void SourceElementsNode::ref()
    3225 {
    3226   for (SourceElementsNode *n = this; n; n = n->elements) {
    3227     n->Node::ref();
    3228     if (n->element)
    3229       n->element->ref();
    3230   }
    3231 }
    3232 
    3233 bool SourceElementsNode::deref()
    3234 {
    3235   SourceElementsNode *next;
    3236   for (SourceElementsNode *n = this; n; n = next) {
    3237     next = n->elements;
    3238     if (n->element && n->element->deref())
    3239       delete n->element;
    3240     if (n != this && n->Node::deref())
    3241       delete n;
    3242   }
    3243   return Node::deref();
    32442144}
    32452145
     
    32542154    return c1;
    32552155 
    3256   for (SourceElementsNode *n = elements; n; n = n->elements) {
     2156  for (SourceElementsNode *n = elements.get(); n; n = n->elements.get()) {
    32572157    Completion c2 = n->element->execute(exec);
    32582158    if (c2.complType() != Normal)
     
    32702170void SourceElementsNode::processFuncDecl(ExecState *exec)
    32712171{
    3272   for (SourceElementsNode *n = this; n; n = n->elements)
     2172  for (SourceElementsNode *n = this; n; n = n->elements.get())
    32732173    n->element->processFuncDecl(exec);
    32742174}
     
    32762176void SourceElementsNode::processVarDecls(ExecState *exec)
    32772177{
    3278   for (SourceElementsNode *n = this; n; n = n->elements)
     2178  for (SourceElementsNode *n = this; n; n = n->elements.get())
    32792179    n->element->processVarDecls(exec);
    32802180}
  • trunk/JavaScriptCore/kjs/nodes.h

    r10154 r10352  
    2727
    2828#include "fast_malloc.h"
     29#include "shared_ptr.h"
    2930
    3031#include "internal.h"
     
    9293  public:
    9394    // reference counting mechanism
    94     virtual void ref() { refcount++; }
    95 #ifdef KJS_DEBUG_MEM
    96     virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }
    97 #else
    98     virtual bool deref() { return (!--refcount); }
    99 #endif
    100 
    101 
    102 #ifdef KJS_DEBUG_MEM
    103     static void finalCheck();
    104 #endif
     95    void ref() { ++m_refcount; }
     96    void deref() { --m_refcount; if (!m_refcount) delete this; }
     97
    10598  protected:
    10699    ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg);
     
    114107    int line;
    115108    UString sourceURL;
    116     unsigned int refcount;
     109    unsigned int m_refcount;
    117110    virtual int sourceId() const { return -1; }
    118111  private:
    119 #ifdef KJS_DEBUG_MEM
    120     // List of all nodes, for debugging purposes. Don't remove!
    121     static std::list<Node *> *s_nodes;
    122 #endif
    123112    // disallow assignment
    124113    Node& operator=(const Node&);
     
    165154  class NumberNode : public Node {
    166155  public:
    167     NumberNode(double v) : value(v) { }
     156    NumberNode(double v) : value(v) {}
    168157    ValueImp *evaluate(ExecState *exec);
    169158    virtual void streamTo(SourceStream &s) const;
     
    211200  public:
    212201    GroupNode(Node *g) : group(g) { }
    213     virtual void ref();
    214     virtual bool deref();
    215202    virtual ValueImp *evaluate(ExecState *exec);
    216203    virtual Reference evaluateReference(ExecState *exec);
    217204    virtual void streamTo(SourceStream &s) const;
    218205  private:
    219     Node *group;
     206    kxmlcore::SharedPtr<Node> group;
    220207  };
    221208
     
    226213    ElementNode(ElementNode *l, int e, Node *n)
    227214      : list(l->list), elision(e), node(n) { l->list = this; }
    228     virtual void ref();
    229     virtual bool deref();
    230215    ValueImp *evaluate(ExecState *exec);
    231216    virtual void streamTo(SourceStream &s) const;
    232217  private:
    233218    friend class ArrayNode;
    234     ElementNode *list;
     219    kxmlcore::SharedPtr<ElementNode> list;
    235220    int elision;
    236     Node *node;
     221    kxmlcore::SharedPtr<Node> node;
    237222  };
    238223
     
    244229    ArrayNode(int eli, ElementNode *ele)
    245230      : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
    246     virtual void ref();
    247     virtual bool deref();
    248     ValueImp *evaluate(ExecState *exec);
    249     virtual void streamTo(SourceStream &s) const;
    250   private:
    251     ElementNode *element;
     231    ValueImp *evaluate(ExecState *exec);
     232    virtual void streamTo(SourceStream &s) const;
     233  private:
     234    kxmlcore::SharedPtr<ElementNode> element;
    252235    int elision;
    253236    bool opt;
     
    261244    PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
    262245      : name(n), assign(a), list(l->list) { l->list = this; }
    263     virtual void ref();
    264     virtual bool deref();
    265246    ValueImp *evaluate(ExecState *exec);
    266247    virtual void streamTo(SourceStream &s) const;
    267248  private:
    268249    friend class ObjectLiteralNode;
    269     PropertyNode *name;
    270     Node *assign;
    271     PropertyValueNode *list;
     250    kxmlcore::SharedPtr<PropertyNode> name;
     251    kxmlcore::SharedPtr<Node> assign;
     252    kxmlcore::SharedPtr<PropertyValueNode> list;
    272253  };
    273254
     
    276257    ObjectLiteralNode() : list(0) { }
    277258    ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
    278     virtual void ref();
    279     virtual bool deref();
    280     ValueImp *evaluate(ExecState *exec);
    281     virtual void streamTo(SourceStream &s) const;
    282   private:
    283     PropertyValueNode *list;
     259    ValueImp *evaluate(ExecState *exec);
     260    virtual void streamTo(SourceStream &s) const;
     261  private:
     262    kxmlcore::SharedPtr<PropertyValueNode> list;
    284263  };
    285264
     
    298277  public:
    299278    BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    300     virtual void ref();
    301     virtual bool deref();
    302279    ValueImp *evaluate(ExecState *exec);
    303280    virtual Reference evaluateReference(ExecState *exec);
    304281    virtual void streamTo(SourceStream &s) const;
    305282  private:
    306     Node *expr1;
    307     Node *expr2;
     283    kxmlcore::SharedPtr<Node> expr1;
     284    kxmlcore::SharedPtr<Node> expr2;
    308285  };
    309286
     
    311288  public:
    312289    DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
    313     virtual void ref();
    314     virtual bool deref();
    315290    ValueImp *evaluate(ExecState *exec);
    316291    virtual Reference evaluateReference(ExecState *exec);
    317292    virtual void streamTo(SourceStream &s) const;
    318293  private:
    319     Node *expr;
     294    kxmlcore::SharedPtr<Node> expr;
    320295    Identifier ident;
    321296  };
     
    327302    ArgumentListNode(ArgumentListNode *l, Node *e)
    328303      : list(l->list), expr(e) { l->list = this; }
    329     virtual void ref();
    330     virtual bool deref();
    331304    ValueImp *evaluate(ExecState *exec);
    332305    List evaluateList(ExecState *exec);
     
    334307  private:
    335308    friend class ArgumentsNode;
    336     ArgumentListNode *list;
    337     Node *expr;
     309    kxmlcore::SharedPtr<ArgumentListNode> list;
     310    kxmlcore::SharedPtr<Node> expr;
    338311  };
    339312
     
    343316    ArgumentsNode(ArgumentListNode *l)
    344317      : list(l->list) { l->list = 0; }
    345     virtual void ref();
    346     virtual bool deref();
    347318    ValueImp *evaluate(ExecState *exec);
    348319    List evaluateList(ExecState *exec);
    349320    virtual void streamTo(SourceStream &s) const;
    350321  private:
    351     ArgumentListNode *list;
     322    kxmlcore::SharedPtr<ArgumentListNode> list;
    352323  };
    353324
     
    356327    NewExprNode(Node *e) : expr(e), args(0) {}
    357328    NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    358     virtual void ref();
    359     virtual bool deref();
    360     ValueImp *evaluate(ExecState *exec);
    361     virtual void streamTo(SourceStream &s) const;
    362   private:
    363     Node *expr;
    364     ArgumentsNode *args;
     329    ValueImp *evaluate(ExecState *exec);
     330    virtual void streamTo(SourceStream &s) const;
     331  private:
     332    kxmlcore::SharedPtr<Node> expr;
     333    kxmlcore::SharedPtr<ArgumentsNode> args;
    365334  };
    366335
     
    368337  public:
    369338    FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    370     virtual void ref();
    371     virtual bool deref();
    372     ValueImp *evaluate(ExecState *exec);
    373     virtual void streamTo(SourceStream &s) const;
    374   private:
    375     Node *expr;
    376     ArgumentsNode *args;
     339    ValueImp *evaluate(ExecState *exec);
     340    virtual void streamTo(SourceStream &s) const;
     341  private:
     342    kxmlcore::SharedPtr<Node> expr;
     343    kxmlcore::SharedPtr<ArgumentsNode> args;
    377344  };
    378345
     
    380347  public:
    381348    FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {}
    382     virtual void ref();
    383     virtual bool deref();
    384349    ValueImp *evaluate(ExecState *exec);
    385350    virtual void streamTo(SourceStream &s) const;
    386351  private:
    387352    Identifier ident;
    388     ArgumentsNode *args;
     353    kxmlcore::SharedPtr<ArgumentsNode> args;
    389354  };
    390355
     
    392357  public:
    393358    FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {}
    394     virtual void ref();
    395     virtual bool deref();
    396359    ValueImp *evaluate(ExecState *exec);
    397360    virtual void streamTo(SourceStream &s) const;
    398361  protected:
    399     Node *base;
    400     Node *subscript;
    401     ArgumentsNode *args;
     362    kxmlcore::SharedPtr<Node> base;
     363    kxmlcore::SharedPtr<Node> subscript;
     364    kxmlcore::SharedPtr<ArgumentsNode> args;
    402365  };
    403366
     
    411374  public:
    412375    FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {}
    413     virtual void ref();
    414     virtual bool deref();
    415376    ValueImp *evaluate(ExecState *exec);
    416377    virtual void streamTo(SourceStream &s) const;
    417378  protected:
    418     Node *base;
     379    kxmlcore::SharedPtr<Node> base;
    419380    Identifier ident;
    420     ArgumentsNode *args;
     381    kxmlcore::SharedPtr<ArgumentsNode> args;
    421382  };
    422383
     
    430391  public:
    431392    PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
    432     virtual void ref();
    433     virtual bool deref();
    434     ValueImp *evaluate(ExecState *exec);
    435     virtual void streamTo(SourceStream &s) const;
    436   private:
    437     Node *expr;
     393    ValueImp *evaluate(ExecState *exec);
     394    virtual void streamTo(SourceStream &s) const;
     395  private:
     396    kxmlcore::SharedPtr<Node> expr;
    438397    Operator oper;
    439398  };
     
    442401  public:
    443402    DeleteNode(Node *e) : expr(e) {}
    444     virtual void ref();
    445     virtual bool deref();
    446     ValueImp *evaluate(ExecState *exec);
    447     virtual void streamTo(SourceStream &s) const;
    448   private:
    449     Node *expr;
     403    ValueImp *evaluate(ExecState *exec);
     404    virtual void streamTo(SourceStream &s) const;
     405  private:
     406    kxmlcore::SharedPtr<Node> expr;
    450407  };
    451408
     
    453410  public:
    454411    VoidNode(Node *e) : expr(e) {}
    455     virtual void ref();
    456     virtual bool deref();
    457     ValueImp *evaluate(ExecState *exec);
    458     virtual void streamTo(SourceStream &s) const;
    459   private:
    460     Node *expr;
     412    ValueImp *evaluate(ExecState *exec);
     413    virtual void streamTo(SourceStream &s) const;
     414  private:
     415    kxmlcore::SharedPtr<Node> expr;
    461416  };
    462417
     
    464419  public:
    465420    TypeOfNode(Node *e) : expr(e) {}
    466     virtual void ref();
    467     virtual bool deref();
    468     ValueImp *evaluate(ExecState *exec);
    469     virtual void streamTo(SourceStream &s) const;
    470   private:
    471     Node *expr;
     421    ValueImp *evaluate(ExecState *exec);
     422    virtual void streamTo(SourceStream &s) const;
     423  private:
     424    kxmlcore::SharedPtr<Node> expr;
    472425  };
    473426
     
    475428  public:
    476429    PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
    477     virtual void ref();
    478     virtual bool deref();
    479430    ValueImp *evaluate(ExecState *exec);
    480431    virtual void streamTo(SourceStream &s) const;
    481432  private:
    482433    Operator oper;
    483     Node *expr;
     434    kxmlcore::SharedPtr<Node> expr;
    484435  };
    485436
     
    487438  public:
    488439    UnaryPlusNode(Node *e) : expr(e) {}
    489     virtual void ref();
    490     virtual bool deref();
    491     ValueImp *evaluate(ExecState *exec);
    492     virtual void streamTo(SourceStream &s) const;
    493   private:
    494     Node *expr;
     440    ValueImp *evaluate(ExecState *exec);
     441    virtual void streamTo(SourceStream &s) const;
     442  private:
     443    kxmlcore::SharedPtr<Node> expr;
    495444  };
    496445
     
    498447  public:
    499448    NegateNode(Node *e) : expr(e) {}
    500     virtual void ref();
    501     virtual bool deref();
    502     ValueImp *evaluate(ExecState *exec);
    503     virtual void streamTo(SourceStream &s) const;
    504   private:
    505     Node *expr;
     449    ValueImp *evaluate(ExecState *exec);
     450    virtual void streamTo(SourceStream &s) const;
     451  private:
     452    kxmlcore::SharedPtr<Node> expr;
    506453  };
    507454
     
    509456  public:
    510457    BitwiseNotNode(Node *e) : expr(e) {}
    511     virtual void ref();
    512     virtual bool deref();
    513     ValueImp *evaluate(ExecState *exec);
    514     virtual void streamTo(SourceStream &s) const;
    515   private:
    516     Node *expr;
     458    ValueImp *evaluate(ExecState *exec);
     459    virtual void streamTo(SourceStream &s) const;
     460  private:
     461    kxmlcore::SharedPtr<Node> expr;
    517462  };
    518463
     
    520465  public:
    521466    LogicalNotNode(Node *e) : expr(e) {}
    522     virtual void ref();
    523     virtual bool deref();
    524     ValueImp *evaluate(ExecState *exec);
    525     virtual void streamTo(SourceStream &s) const;
    526   private:
    527     Node *expr;
     467    ValueImp *evaluate(ExecState *exec);
     468    virtual void streamTo(SourceStream &s) const;
     469  private:
     470    kxmlcore::SharedPtr<Node> expr;
    528471  };
    529472
     
    531474  public:
    532475    MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    533     virtual void ref();
    534     virtual bool deref();
    535     ValueImp *evaluate(ExecState *exec);
    536     virtual void streamTo(SourceStream &s) const;
    537   private:
    538     Node *term1, *term2;
     476    ValueImp *evaluate(ExecState *exec);
     477    virtual void streamTo(SourceStream &s) const;
     478  private:
     479    kxmlcore::SharedPtr<Node> term1;
     480    kxmlcore::SharedPtr<Node> term2;
    539481    char oper;
    540482  };
     
    543485  public:
    544486    AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    545     virtual void ref();
    546     virtual bool deref();
    547     ValueImp *evaluate(ExecState *exec);
    548     virtual void streamTo(SourceStream &s) const;
    549   private:
    550     Node *term1, *term2;
     487    ValueImp *evaluate(ExecState *exec);
     488    virtual void streamTo(SourceStream &s) const;
     489  private:
     490    kxmlcore::SharedPtr<Node> term1;
     491    kxmlcore::SharedPtr<Node> term2;
    551492    char oper;
    552493  };
     
    556497    ShiftNode(Node *t1, Operator o, Node *t2)
    557498      : term1(t1), term2(t2), oper(o) {}
    558     virtual void ref();
    559     virtual bool deref();
    560     ValueImp *evaluate(ExecState *exec);
    561     virtual void streamTo(SourceStream &s) const;
    562   private:
    563     Node *term1, *term2;
     499    ValueImp *evaluate(ExecState *exec);
     500    virtual void streamTo(SourceStream &s) const;
     501  private:
     502    kxmlcore::SharedPtr<Node> term1;
     503    kxmlcore::SharedPtr<Node> term2;
    564504    Operator oper;
    565505  };
     
    569509    RelationalNode(Node *e1, Operator o, Node *e2) :
    570510      expr1(e1), expr2(e2), oper(o) {}
    571     virtual void ref();
    572     virtual bool deref();
    573     ValueImp *evaluate(ExecState *exec);
    574     virtual void streamTo(SourceStream &s) const;
    575   private:
    576     Node *expr1, *expr2;
     511    ValueImp *evaluate(ExecState *exec);
     512    virtual void streamTo(SourceStream &s) const;
     513  private:
     514    kxmlcore::SharedPtr<Node> expr1;
     515    kxmlcore::SharedPtr<Node> expr2;
    577516    Operator oper;
    578517  };
     
    582521    EqualNode(Node *e1, Operator o, Node *e2)
    583522      : expr1(e1), expr2(e2), oper(o) {}
    584     virtual void ref();
    585     virtual bool deref();
    586     ValueImp *evaluate(ExecState *exec);
    587     virtual void streamTo(SourceStream &s) const;
    588   private:
    589     Node *expr1, *expr2;
     523    ValueImp *evaluate(ExecState *exec);
     524    virtual void streamTo(SourceStream &s) const;
     525  private:
     526    kxmlcore::SharedPtr<Node> expr1;
     527    kxmlcore::SharedPtr<Node> expr2;
    590528    Operator oper;
    591529  };
     
    595533    BitOperNode(Node *e1, Operator o, Node *e2) :
    596534      expr1(e1), expr2(e2), oper(o) {}
    597     virtual void ref();
    598     virtual bool deref();
    599     ValueImp *evaluate(ExecState *exec);
    600     virtual void streamTo(SourceStream &s) const;
    601   private:
    602     Node *expr1, *expr2;
     535    ValueImp *evaluate(ExecState *exec);
     536    virtual void streamTo(SourceStream &s) const;
     537  private:
     538    kxmlcore::SharedPtr<Node> expr1;
     539    kxmlcore::SharedPtr<Node> expr2;
    603540    Operator oper;
    604541  };
     
    611548    BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
    612549      expr1(e1), expr2(e2), oper(o) {}
    613     virtual void ref();
    614     virtual bool deref();
    615     ValueImp *evaluate(ExecState *exec);
    616     virtual void streamTo(SourceStream &s) const;
    617   private:
    618     Node *expr1, *expr2;
     550    ValueImp *evaluate(ExecState *exec);
     551    virtual void streamTo(SourceStream &s) const;
     552  private:
     553    kxmlcore::SharedPtr<Node> expr1;
     554    kxmlcore::SharedPtr<Node> expr2;
    619555    Operator oper;
    620556  };
     
    627563    ConditionalNode(Node *l, Node *e1, Node *e2) :
    628564      logical(l), expr1(e1), expr2(e2) {}
    629     virtual void ref();
    630     virtual bool deref();
    631     ValueImp *evaluate(ExecState *exec);
    632     virtual void streamTo(SourceStream &s) const;
    633   private:
    634     Node *logical, *expr1, *expr2;
     565    ValueImp *evaluate(ExecState *exec);
     566    virtual void streamTo(SourceStream &s) const;
     567  private:
     568    kxmlcore::SharedPtr<Node> logical;
     569    kxmlcore::SharedPtr<Node> expr1;
     570    kxmlcore::SharedPtr<Node> expr2;
    635571  };
    636572
     
    639575    AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
    640576      : m_ident(ident), m_oper(oper), m_right(right) {}
    641     virtual void ref();
    642     virtual bool deref();
    643577    ValueImp *evaluate(ExecState *exec);
    644578    virtual void streamTo(SourceStream &s) const;
     
    646580    Identifier m_ident;
    647581    Operator m_oper;
    648     Node *m_right;
     582    kxmlcore::SharedPtr<Node> m_right;
    649583  };
    650584
     
    653587    AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
    654588      : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
    655     virtual void ref();
    656     virtual bool deref();
    657589    ValueImp *evaluate(ExecState *exec);
    658590    virtual void streamTo(SourceStream &s) const;
    659591  protected:
    660     Node *m_base;
    661     Node *m_subscript;
     592    kxmlcore::SharedPtr<Node> m_base;
     593    kxmlcore::SharedPtr<Node> m_subscript;
    662594    Operator m_oper;
    663     Node *m_right;
     595    kxmlcore::SharedPtr<Node> m_right;
    664596  };
    665597
     
    668600    AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
    669601      : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
    670     virtual void ref();
    671     virtual bool deref();
    672602    ValueImp *evaluate(ExecState *exec);
    673603    virtual void streamTo(SourceStream &s) const;
    674604  protected:
    675     Node *m_base;
     605    kxmlcore::SharedPtr<Node> m_base;
    676606    Identifier m_ident;
    677607    Operator m_oper;
    678     Node *m_right;
     608    kxmlcore::SharedPtr<Node> m_right;
    679609  };
    680610
     
    682612  public:
    683613    CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    684     virtual void ref();
    685     virtual bool deref();
    686     ValueImp *evaluate(ExecState *exec);
    687     virtual void streamTo(SourceStream &s) const;
    688   private:
    689     Node *expr1, *expr2;
     614    ValueImp *evaluate(ExecState *exec);
     615    virtual void streamTo(SourceStream &s) const;
     616  private:
     617    kxmlcore::SharedPtr<Node> expr1;
     618    kxmlcore::SharedPtr<Node> expr2;
    690619  };
    691620
     
    695624    StatListNode(StatementNode *s);
    696625    StatListNode(StatListNode *l, StatementNode *s);
    697     virtual void ref();
    698     virtual bool deref();
    699626    virtual Completion execute(ExecState *exec);
    700627    virtual void processVarDecls(ExecState *exec);
     
    702629  private:
    703630    friend class CaseClauseNode;
    704     StatementNode *statement;
    705     StatListNode *list;
     631    kxmlcore::SharedPtr<StatementNode> statement;
     632    kxmlcore::SharedPtr<StatListNode> list;
    706633  };
    707634
     
    709636  public:
    710637    AssignExprNode(Node *e) : expr(e) {}
    711     virtual void ref();
    712     virtual bool deref();
    713     ValueImp *evaluate(ExecState *exec);
    714     virtual void streamTo(SourceStream &s) const;
    715   private:
    716     Node *expr;
     638    ValueImp *evaluate(ExecState *exec);
     639    virtual void streamTo(SourceStream &s) const;
     640  private:
     641    kxmlcore::SharedPtr<Node> expr;
    717642  };
    718643
     
    721646    enum Type { Variable, Constant };
    722647    VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
    723     virtual void ref();
    724     virtual bool deref();
    725648    ValueImp *evaluate(ExecState *exec);
    726649    virtual void processVarDecls(ExecState *exec);
     
    729652    Type varType;
    730653    Identifier ident;
    731     AssignExprNode *init;
     654    kxmlcore::SharedPtr<AssignExprNode> init;
    732655  };
    733656
     
    738661    VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
    739662      : list(l->list), var(v) { l->list = this; }
    740     virtual void ref();
    741     virtual bool deref();
    742663    ValueImp *evaluate(ExecState *exec);
    743664    virtual void processVarDecls(ExecState *exec);
     
    746667    friend class ForNode;
    747668    friend class VarStatementNode;
    748     VarDeclListNode *list;
    749     VarDeclNode *var;
     669    kxmlcore::SharedPtr<VarDeclListNode> list;
     670    kxmlcore::SharedPtr<VarDeclNode> var;
    750671  };
    751672
     
    753674  public:
    754675    VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
    755     virtual void ref();
    756     virtual bool deref();
    757     virtual Completion execute(ExecState *exec);
    758     virtual void processVarDecls(ExecState *exec);
    759     virtual void streamTo(SourceStream &s) const;
    760   private:
    761     VarDeclListNode *list;
     676    virtual Completion execute(ExecState *exec);
     677    virtual void processVarDecls(ExecState *exec);
     678    virtual void streamTo(SourceStream &s) const;
     679  private:
     680    kxmlcore::SharedPtr<VarDeclListNode> list;
    762681  };
    763682
     
    765684  public:
    766685    BlockNode(SourceElementsNode *s);
    767     virtual void ref();
    768     virtual bool deref();
    769686    virtual Completion execute(ExecState *exec);
    770687    virtual void processVarDecls(ExecState *exec);
    771688    virtual void streamTo(SourceStream &s) const;
    772689  protected:
    773     SourceElementsNode *source;
     690    kxmlcore::SharedPtr<SourceElementsNode> source;
    774691  };
    775692
     
    784701  public:
    785702    ExprStatementNode(Node *e) : expr(e) { }
    786     virtual void ref();
    787     virtual bool deref();
    788     virtual Completion execute(ExecState *exec);
    789     virtual void streamTo(SourceStream &s) const;
    790   private:
    791     Node *expr;
     703    virtual Completion execute(ExecState *exec);
     704    virtual void streamTo(SourceStream &s) const;
     705  private:
     706    kxmlcore::SharedPtr<Node> expr;
    792707  };
    793708
     
    796711    IfNode(Node *e, StatementNode *s1, StatementNode *s2)
    797712      : expr(e), statement1(s1), statement2(s2) {}
    798     virtual void ref();
    799     virtual bool deref();
    800     virtual Completion execute(ExecState *exec);
    801     virtual void processVarDecls(ExecState *exec);
    802     virtual void streamTo(SourceStream &s) const;
    803   private:
    804     Node *expr;
    805     StatementNode *statement1, *statement2;
     713    virtual Completion execute(ExecState *exec);
     714    virtual void processVarDecls(ExecState *exec);
     715    virtual void streamTo(SourceStream &s) const;
     716  private:
     717    kxmlcore::SharedPtr<Node> expr;
     718    kxmlcore::SharedPtr<StatementNode> statement1;
     719    kxmlcore::SharedPtr<StatementNode> statement2;
    806720  };
    807721
     
    809723  public:
    810724    DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
    811     virtual void ref();
    812     virtual bool deref();
    813     virtual Completion execute(ExecState *exec);
    814     virtual void processVarDecls(ExecState *exec);
    815     virtual void streamTo(SourceStream &s) const;
    816   private:
    817     StatementNode *statement;
    818     Node *expr;
     725    virtual Completion execute(ExecState *exec);
     726    virtual void processVarDecls(ExecState *exec);
     727    virtual void streamTo(SourceStream &s) const;
     728  private:
     729    kxmlcore::SharedPtr<StatementNode> statement;
     730    kxmlcore::SharedPtr<Node> expr;
    819731  };
    820732
     
    822734  public:
    823735    WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
    824     virtual void ref();
    825     virtual bool deref();
    826     virtual Completion execute(ExecState *exec);
    827     virtual void processVarDecls(ExecState *exec);
    828     virtual void streamTo(SourceStream &s) const;
    829   private:
    830     Node *expr;
    831     StatementNode *statement;
     736    virtual Completion execute(ExecState *exec);
     737    virtual void processVarDecls(ExecState *exec);
     738    virtual void streamTo(SourceStream &s) const;
     739  private:
     740    kxmlcore::SharedPtr<Node> expr;
     741    kxmlcore::SharedPtr<StatementNode> statement;
    832742  };
    833743
     
    838748    ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
    839749      expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
    840     virtual void ref();
    841     virtual bool deref();
    842     virtual Completion execute(ExecState *exec);
    843     virtual void processVarDecls(ExecState *exec);
    844     virtual void streamTo(SourceStream &s) const;
    845   private:
    846     Node *expr1, *expr2, *expr3;
    847     StatementNode *statement;
     750    virtual Completion execute(ExecState *exec);
     751    virtual void processVarDecls(ExecState *exec);
     752    virtual void streamTo(SourceStream &s) const;
     753  private:
     754    kxmlcore::SharedPtr<Node> expr1;
     755    kxmlcore::SharedPtr<Node> expr2;
     756    kxmlcore::SharedPtr<Node> expr3;
     757    kxmlcore::SharedPtr<StatementNode> statement;
    848758  };
    849759
     
    852762    ForInNode(Node *l, Node *e, StatementNode *s);
    853763    ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
    854     virtual void ref();
    855     virtual bool deref();
    856764    virtual Completion execute(ExecState *exec);
    857765    virtual void processVarDecls(ExecState *exec);
     
    859767  private:
    860768    Identifier ident;
    861     AssignExprNode *init;
    862     Node *lexpr, *expr;
    863     VarDeclNode *varDecl;
    864     StatementNode *statement;
     769    kxmlcore::SharedPtr<AssignExprNode> init;
     770    kxmlcore::SharedPtr<Node> lexpr;
     771    kxmlcore::SharedPtr<Node> expr;
     772    kxmlcore::SharedPtr<VarDeclNode> varDecl;
     773    kxmlcore::SharedPtr<StatementNode> statement;
    865774  };
    866775
     
    888797  public:
    889798    ReturnNode(Node *v) : value(v) {}
    890     virtual void ref();
    891     virtual bool deref();
    892     virtual Completion execute(ExecState *exec);
    893     virtual void streamTo(SourceStream &s) const;
    894   private:
    895     Node *value;
     799    virtual Completion execute(ExecState *exec);
     800    virtual void streamTo(SourceStream &s) const;
     801  private:
     802    kxmlcore::SharedPtr<Node> value;
    896803  };
    897804
     
    899806  public:
    900807    WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
    901     virtual void ref();
    902     virtual bool deref();
    903     virtual Completion execute(ExecState *exec);
    904     virtual void processVarDecls(ExecState *exec);
    905     virtual void streamTo(SourceStream &s) const;
    906   private:
    907     Node *expr;
    908     StatementNode *statement;
     808    virtual Completion execute(ExecState *exec);
     809    virtual void processVarDecls(ExecState *exec);
     810    virtual void streamTo(SourceStream &s) const;
     811  private:
     812    kxmlcore::SharedPtr<Node> expr;
     813    kxmlcore::SharedPtr<StatementNode> statement;
    909814  };
    910815
     
    914819    CaseClauseNode(Node *e, StatListNode *l)
    915820      : expr(e), list(l->list) { l->list = 0; }
    916     virtual void ref();
    917     virtual bool deref();
    918821    ValueImp *evaluate(ExecState *exec);
    919822    Completion evalStatements(ExecState *exec);
     
    921824    virtual void streamTo(SourceStream &s) const;
    922825  private:
    923     Node *expr;
    924     StatListNode *list;
     826    kxmlcore::SharedPtr<Node> expr;
     827    kxmlcore::SharedPtr<StatListNode> list;
    925828  };
    926829
     
    931834    ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
    932835      : cl(c), nx(n->nx) { n->nx = this; }
    933     virtual void ref();
    934     virtual bool deref();
    935     ValueImp *evaluate(ExecState *exec);
    936     CaseClauseNode *clause() const { return cl; }
    937     ClauseListNode *next() const { return nx; }
     836    ValueImp *evaluate(ExecState *exec);
     837    CaseClauseNode *clause() const { return cl.get(); }
     838    ClauseListNode *next() const { return nx.get(); }
    938839    virtual void processVarDecls(ExecState *exec);
    939840    virtual void streamTo(SourceStream &s) const;
    940841  private:
    941842    friend class CaseBlockNode;
    942     CaseClauseNode *cl;
    943     ClauseListNode *nx;
     843    kxmlcore::SharedPtr<CaseClauseNode> cl;
     844    kxmlcore::SharedPtr<ClauseListNode> nx;
    944845  };
    945846
     
    947848  public:
    948849    CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
    949     virtual void ref();
    950     virtual bool deref();
    951850    ValueImp *evaluate(ExecState *exec);
    952851    Completion evalBlock(ExecState *exec, ValueImp *input);
     
    954853    virtual void streamTo(SourceStream &s) const;
    955854  private:
    956     ClauseListNode *list1;
    957     CaseClauseNode *def;
    958     ClauseListNode *list2;
     855    kxmlcore::SharedPtr<ClauseListNode> list1;
     856    kxmlcore::SharedPtr<CaseClauseNode> def;
     857    kxmlcore::SharedPtr<ClauseListNode> list2;
    959858  };
    960859
     
    962861  public:
    963862    SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
    964     virtual void ref();
    965     virtual bool deref();
    966     virtual Completion execute(ExecState *exec);
    967     virtual void processVarDecls(ExecState *exec);
    968     virtual void streamTo(SourceStream &s) const;
    969   private:
    970     Node *expr;
    971     CaseBlockNode *block;
     863    virtual Completion execute(ExecState *exec);
     864    virtual void processVarDecls(ExecState *exec);
     865    virtual void streamTo(SourceStream &s) const;
     866  private:
     867    kxmlcore::SharedPtr<Node> expr;
     868    kxmlcore::SharedPtr<CaseBlockNode> block;
    972869  };
    973870
     
    975872  public:
    976873    LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
    977     virtual void ref();
    978     virtual bool deref();
    979874    virtual Completion execute(ExecState *exec);
    980875    virtual void processVarDecls(ExecState *exec);
     
    982877  private:
    983878    Identifier label;
    984     StatementNode *statement;
     879    kxmlcore::SharedPtr<StatementNode> statement;
    985880  };
    986881
     
    988883  public:
    989884    ThrowNode(Node *e) : expr(e) {}
    990     virtual void ref();
    991     virtual bool deref();
    992     virtual Completion execute(ExecState *exec);
    993     virtual void streamTo(SourceStream &s) const;
    994   private:
    995     Node *expr;
     885    virtual Completion execute(ExecState *exec);
     886    virtual void streamTo(SourceStream &s) const;
     887  private:
     888    kxmlcore::SharedPtr<Node> expr;
    996889  };
    997890
     
    999892  public:
    1000893    CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
    1001     virtual void ref();
    1002     virtual bool deref();
    1003894    virtual Completion execute(ExecState *exec);
    1004895    Completion execute(ExecState *exec, ValueImp *arg);
     
    1007898  private:
    1008899    Identifier ident;
    1009     StatementNode *block;
     900    kxmlcore::SharedPtr<StatementNode> block;
    1010901  };
    1011902
     
    1013904  public:
    1014905    FinallyNode(StatementNode *b) : block(b) {}
    1015     virtual void ref();
    1016     virtual bool deref();
    1017     virtual Completion execute(ExecState *exec);
    1018     virtual void processVarDecls(ExecState *exec);
    1019     virtual void streamTo(SourceStream &s) const;
    1020   private:
    1021     StatementNode *block;
     906    virtual Completion execute(ExecState *exec);
     907    virtual void processVarDecls(ExecState *exec);
     908    virtual void streamTo(SourceStream &s) const;
     909  private:
     910    kxmlcore::SharedPtr<StatementNode> block;
    1022911  };
    1023912
     
    1030919    TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
    1031920      : block(b), _catch(c), _final(f) {}
    1032     virtual void ref();
    1033     virtual bool deref();
    1034     virtual Completion execute(ExecState *exec);
    1035     virtual void processVarDecls(ExecState *exec);
    1036     virtual void streamTo(SourceStream &s) const;
    1037   private:
    1038     StatementNode *block;
    1039     CatchNode *_catch;
    1040     FinallyNode *_final;
     921    virtual Completion execute(ExecState *exec);
     922    virtual void processVarDecls(ExecState *exec);
     923    virtual void streamTo(SourceStream &s) const;
     924  private:
     925    kxmlcore::SharedPtr<StatementNode> block;
     926    kxmlcore::SharedPtr<CatchNode> _catch;
     927    kxmlcore::SharedPtr<FinallyNode> _final;
    1041928  };
    1042929
     
    1047934    ParameterNode(ParameterNode *list, const Identifier &i)
    1048935      : id(i), next(list->next) { list->next = this; }
    1049     virtual void ref();
    1050     virtual bool deref();
    1051936    ValueImp *evaluate(ExecState *exec);
    1052937    Identifier ident() { return id; }
    1053     ParameterNode *nextParam() { return next; }
     938    ParameterNode *nextParam() { return next.get(); }
    1054939    virtual void streamTo(SourceStream &s) const;
    1055940  private:
     
    1057942    friend class FuncExprNode;
    1058943    Identifier id;
    1059     ParameterNode *next;
     944    kxmlcore::SharedPtr<ParameterNode> next;
    1060945  };
    1061946
     
    1073958    FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
    1074959      : ident(i), param(p->next), body(b) { p->next = 0; }
    1075     virtual void ref();
    1076     virtual bool deref();
    1077960    Completion execute(ExecState */*exec*/)
    1078961      { /* empty */ return Completion(); }
     
    1081964  private:
    1082965    Identifier ident;
    1083     ParameterNode *param;
    1084     FunctionBodyNode *body;
     966    kxmlcore::SharedPtr<ParameterNode> param;
     967    kxmlcore::SharedPtr<FunctionBodyNode> body;
    1085968  };
    1086969
     
    1090973    FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
    1091974      : param(p->next), body(b) { p->next = 0; }
    1092     virtual void ref();
    1093     virtual bool deref();
    1094     ValueImp *evaluate(ExecState *exec);
    1095     virtual void streamTo(SourceStream &s) const;
    1096   private:
    1097     ParameterNode *param;
    1098     FunctionBodyNode *body;
     975    ValueImp *evaluate(ExecState *exec);
     976    virtual void streamTo(SourceStream &s) const;
     977  private:
     978    kxmlcore::SharedPtr<ParameterNode> param;
     979    kxmlcore::SharedPtr<FunctionBodyNode> body;
    1099980  };
    1100981
     
    1105986    SourceElementsNode(StatementNode *s1);
    1106987    SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
    1107     virtual void ref();
    1108     virtual bool deref();
     988
    1109989    Completion execute(ExecState *exec);
    1110990    void processFuncDecl(ExecState *exec);
     
    1113993  private:
    1114994    friend class BlockNode;
    1115     StatementNode *element; // 'this' element
    1116     SourceElementsNode *elements; // pointer to next
     995    kxmlcore::SharedPtr<StatementNode> element; // 'this' element
     996    kxmlcore::SharedPtr<SourceElementsNode> elements; // pointer to next
    1117997  };
    1118998
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r10218 r10352  
    2424#include "nodes.h"
    2525
     26using namespace kxmlcore;
     27
    2628namespace KJS {
    2729  /**
     
    4143    SourceStream& operator<<(Format f);
    4244    SourceStream& operator<<(const Node *);
     45    template <typename T> SourceStream& operator<<(SharedPtr<T> n) { return this->operator<<(n.get()); }
    4346  private:
    4447    UString str; /* TODO: buffer */
     
    132135void ElementNode::streamTo(SourceStream &s) const
    133136{
    134   for (const ElementNode *n = this; n; n = n->list) {
     137  for (const ElementNode *n = this; n; n = n->list.get()) {
    135138    for (int i = 0; i < n->elision; i++)
    136139      s << ",";
     
    157160void PropertyValueNode::streamTo(SourceStream &s) const
    158161{
    159   for (const PropertyValueNode *n = this; n; n = n->list)
     162  for (const PropertyValueNode *n = this; n; n = n->list.get())
    160163    s << n->name << ": " << n->assign;
    161164}
     
    182185{
    183186  s << expr;
    184   for (ArgumentListNode *n = list; n; n = n->list)
     187  for (ArgumentListNode *n = list.get(); n; n = n->list.get())
    185188    s << ", " << n->expr;
    186189}
     
    443446void StatListNode::streamTo(SourceStream &s) const
    444447{
    445   for (const StatListNode *n = this; n; n = n->list)
     448  for (const StatListNode *n = this; n; n = n->list.get())
    446449    s << n->statement;
    447450}
     
    460463{
    461464  s << var;
    462   for (VarDeclListNode *n = list; n; n = n->list)
     465  for (VarDeclListNode *n = list.get(); n; n = n->list.get())
    463466    s << ", " << n->var;
    464467}
     
    578581void CaseBlockNode::streamTo(SourceStream &s) const
    579582{
    580   for (const ClauseListNode *n = list1; n; n = n->next())
     583  for (const ClauseListNode *n = list1.get(); n; n = n->next())
    581584    s << n->clause();
    582585  if (def)
    583586    s << def;
    584   for (const ClauseListNode *n = list2; n; n = n->next())
     587  for (const ClauseListNode *n = list2.get(); n; n = n->next())
    585588    s << n->clause();
    586589}
     
    624627{
    625628  s << id;
    626   for (ParameterNode *n = next; n; n = n->next)
     629  for (ParameterNode *n = next.get(); n; n = n->next.get())
    627630    s << ", " << n->id;
    628631}
     
    644647void SourceElementsNode::streamTo(SourceStream &s) const
    645648{
    646   for (const SourceElementsNode *n = this; n; n = n->elements)
     649  for (const SourceElementsNode *n = this; n; n = n->elements.get())
    647650    s << n->element;
    648651}
Note: See TracChangeset for help on using the changeset viewer.