⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodes.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  if ( value )    value->ref();}bool ReturnNode::deref(){  if ( value && value->deref() )    delete value;  return Node::deref();}// ECMA 12.9Completion ReturnNode::execute(ExecState *exec){  KJS_BREAKPOINT;  if (!value)    return Completion(ReturnValue, Undefined());  Value v = value->evaluate(exec);  KJS_CHECKEXCEPTION  return Completion(ReturnValue, v);}// ------------------------------ WithNode -------------------------------------void WithNode::ref(){  Node::ref();  if ( statement )    statement->ref();  if ( expr )    expr->ref();}bool WithNode::deref(){  if ( statement && statement->deref() )    delete statement;  if ( expr && expr->deref() )    delete expr;  return Node::deref();}// ECMA 12.10Completion WithNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTION  Object o = v.toObject(exec);  KJS_CHECKEXCEPTION  exec->context().imp()->pushScope(o);  Completion res = statement->execute(exec);  exec->context().imp()->popScope();  return res;}void WithNode::processVarDecls(ExecState *exec){  statement->processVarDecls(exec);}// ------------------------------ CaseClauseNode -------------------------------void CaseClauseNode::ref(){  Node::ref();  if ( expr )    expr->ref();  if ( list )    list->ref();}bool CaseClauseNode::deref(){  if ( expr && expr->deref() )    delete expr;  if ( list && list->deref() )    delete list;  return Node::deref();}// ECMA 12.11Value CaseClauseNode::evaluate(ExecState *exec){  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTIONVALUE  return v;}// ECMA 12.11Completion CaseClauseNode::evalStatements(ExecState *exec){  if (list)    return list->execute(exec);  else    return Completion(Normal, Undefined());}void CaseClauseNode::processVarDecls(ExecState *exec){  if (list)    list->processVarDecls(exec);}// ------------------------------ ClauseListNode -------------------------------void ClauseListNode::ref(){  for (ClauseListNode *n = this; n; n = n->nx) {    n->Node::ref();    if (n->cl)      n->cl->ref();  }}bool ClauseListNode::deref(){  ClauseListNode *next;  for (ClauseListNode *n = this; n; n = next) {    next = n->nx;    if (n->cl && n->cl->deref())      delete n->cl;    if (n != this && n->Node::deref())      delete n;  }  return Node::deref();}Value ClauseListNode::evaluate(ExecState */*exec*/){  /* should never be called */  assert(false);  return Value();}// ECMA 12.11void ClauseListNode::processVarDecls(ExecState *exec){  for (ClauseListNode *n = this; n; n = n->nx)    if (n->cl)      n->cl->processVarDecls(exec);}// ------------------------------ CaseBlockNode --------------------------------CaseBlockNode::CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d,                             ClauseListNode *l2){  if (l1) {    list1 = l1->nx;    l1->nx = 0;  } else {    list1 = 0;  }  def = d;  if (l2) {    list2 = l2->nx;    l2->nx = 0;  } else {    list2 = 0;  }} void CaseBlockNode::ref(){  Node::ref();  if ( def )    def->ref();  if ( list1 )    list1->ref();  if ( list2 )    list2->ref();}bool CaseBlockNode::deref(){  if ( def && def->deref() )    delete def;  if ( list1 && list1->deref() )    delete list1;  if ( list2 && list2->deref() )    delete list2;  return Node::deref();}Value CaseBlockNode::evaluate(ExecState */*exec*/){  /* should never be called */  assert(false);  return Value();}// ECMA 12.11Completion CaseBlockNode::evalBlock(ExecState *exec, const Value& input){  Value v;  Completion res;  ClauseListNode *a = list1, *b = list2;  CaseClauseNode *clause;    while (a) {      clause = a->clause();      a = a->next();      v = clause->evaluate(exec);      KJS_CHECKEXCEPTION      if (strictEqual(exec, input, v)) {	res = clause->evalStatements(exec);	if (res.complType() != Normal)	  return res;	while (a) {	  res = a->clause()->evalStatements(exec);	  if (res.complType() != Normal)	    return res;	  a = a->next();	}	break;      }    }  while (b) {    clause = b->clause();    b = b->next();    v = clause->evaluate(exec);    KJS_CHECKEXCEPTION    if (strictEqual(exec, input, v)) {      res = clause->evalStatements(exec);      if (res.complType() != Normal)	return res;      goto step18;    }  }  // default clause  if (def) {    res = def->evalStatements(exec);    if (res.complType() != Normal)      return res;  }  b = list2; step18:  while (b) {    clause = b->clause();    res = clause->evalStatements(exec);    if (res.complType() != Normal)      return res;    b = b->next();  }  // bail out on error  KJS_CHECKEXCEPTION  return Completion(Normal);}void CaseBlockNode::processVarDecls(ExecState *exec){  if (list1)    list1->processVarDecls(exec);  if (def)    def->processVarDecls(exec);  if (list2)    list2->processVarDecls(exec);}// ------------------------------ SwitchNode -----------------------------------void SwitchNode::ref(){  Node::ref();  if ( expr )    expr->ref();  if ( block )    block->ref();}bool SwitchNode::deref(){  if ( expr && expr->deref() )    delete expr;  if ( block && block->deref() )    delete block;  return Node::deref();}// ECMA 12.11Completion SwitchNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTION  Completion res = block->evalBlock(exec,v);  if ((res.complType() == Break) && ls.contains(res.target()))    return Completion(Normal, res.value());  else    return res;}void SwitchNode::processVarDecls(ExecState *exec){  block->processVarDecls(exec);}// ------------------------------ LabelNode ------------------------------------void LabelNode::ref(){  Node::ref();  if ( statement )    statement->ref();}bool LabelNode::deref(){  if ( statement && statement->deref() )    delete statement;  return Node::deref();}// ECMA 12.12Completion LabelNode::execute(ExecState *exec){  Completion e;  if (!exec->context().imp()->seenLabels()->push(label)) {    return Completion( Throw,		       throwError(exec, SyntaxError, "Duplicated label %s found.", label));  };  e = statement->execute(exec);  exec->context().imp()->seenLabels()->pop();  if ((e.complType() == Break) && (e.target() == label))    return Completion(Normal, e.value());  else    return e;}void LabelNode::processVarDecls(ExecState *exec){  statement->processVarDecls(exec);}// ------------------------------ ThrowNode ------------------------------------void ThrowNode::ref(){  Node::ref();  if ( expr )    expr->ref();}bool ThrowNode::deref(){  if ( expr && expr->deref() )    delete expr;  return Node::deref();}// ECMA 12.13Completion ThrowNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTION  // bail out on error  KJS_CHECKEXCEPTION  return Completion(Throw, v);}// ------------------------------ CatchNode ------------------------------------void CatchNode::ref(){  Node::ref();  if ( block )    block->ref();}bool CatchNode::deref(){  if ( block && block->deref() )    delete block;  return Node::deref();}Completion CatchNode::execute(ExecState */*exec*/){  // should never be reached. execute(exec, arg) is used instead  assert(0L);  return Completion();}// ECMA 12.14Completion CatchNode::execute(ExecState *exec, const Value &arg){  /* TODO: correct ? Not part of the spec */  exec->clearException();  Object obj(new ObjectImp());  obj.put(exec, ident, arg, DontDelete);  exec->context().imp()->pushScope(obj);  Completion c = block->execute(exec);  exec->context().imp()->popScope();  return c;}void CatchNode::processVarDecls(ExecState *exec){  block->processVarDecls(exec);}// ------------------------------ FinallyNode ----------------------------------void FinallyNode::ref(){  Node::ref();  if ( block )    block->ref();}bool FinallyNode::deref(){  if ( block && block->deref() )    delete block;  return Node::deref();}// ECMA 12.14Completion FinallyNode::execute(ExecState *exec){  return block->execute(exec);}void FinallyNode::processVarDecls(ExecState *exec){  block->processVarDecls(exec);}// ------------------------------ TryNode --------------------------------------void TryNode::ref(){  Node::ref();  if ( block )    block->ref();  if ( _final )    _final->ref();  if ( _catch )    _catch->ref();}bool TryNode::deref(){  if ( block && block->deref() )    delete block;  if ( _final && _final->deref() )    delete _final;  if ( _catch && _catch->deref() )    delete _catch;  return Node::deref();}// ECMA 12.14Completion TryNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Completion c, c2;  c = block->execute(exec);  if (!_final) {    if (c.complType() != Throw)      return c;    return _catch->execute(exec,c.value());  }  if (!_catch) {    c2 = _final->execute(exec);    return (c2.complType() == Normal) ? c : c2;  }  if (c.complType() == Throw)    c = _catch->execute(exec,c.value());  c2 = _final->execute(exec);  return (c2.complType() == Normal) ? c : c2;}void TryNode::processVarDecls(ExecState *exec){  block->processVarDecls(exec);  if (_final)    _final->processVarDecls(exec);  if (_catch)    _catch->processVarDecls(exec);}// ------------------------------ ParameterNode --------------------------------void ParameterNode::ref(){  for (ParameterNode *n = this; n; n = n->next)    n->Node::ref();}bool ParameterNode::deref(){  ParameterNode *next;  for (ParameterNode *n = this; n; n = next) {    next = n->next;    if (n != this && n->Node::deref())      delete n;  }  return Node::deref();}// ECMA 13Value ParameterNode::evaluate(ExecState */*exec*/){  return Undefined();}// ------------------------------ FunctionBodyNode -----------------------------FunctionBodyNode::FunctionBodyNode(SourceElementsNode *s)  : BlockNode(s){  setLoc(-1, -1, -1);  //fprintf(stderr,"FunctionBodyNode::FunctionBodyNode %p\n",this);}void FunctionBodyNode::processFuncDecl(ExecState *exec){  if (source)    source->processFuncDecl(exec);}// ------------------------------ FuncDeclNode ---------------------------------void FuncDeclNode::ref(){  Node::ref();  if ( param )    param->ref();  if ( body )    body->ref();}bool FuncDeclNode::deref(){  if ( param && param->deref() )    delete param;  if ( body && body->deref() )    delete body;  return Node::deref();}// ECMA 13void FuncDeclNode::processFuncDecl(ExecState *exec){  // TODO: let this be an object with [[Class]] property "Function"  FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, exec->context().imp()->scopeChain());  Object func(fimp); // protect from GC  //  Value proto = exec->lexicalInterpreter()->builtinObject().construct(exec,List::empty());  List empty;  Object proto = exec->lexicalInterpreter()->builtinObject().construct(exec,empty);  proto.put(exec, constructorPropertyName, func, ReadOnly|DontDelete|DontEnum);  func.put(exec, prototypePropertyName, proto, Internal|DontDelete);  int plen = 0;  for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)    fimp->addParameter(p->ident());  func.put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum);  exec->context().imp()->variableObject().put(exec,ident,func);  if (body) {    // hack the scope so that the function gets put as a property of func, and it's scope    // contains the func as well as our current scope    Object oldVar = exec->context().imp()->variableObject();    exec->context().imp()->setVariableObject(func);    exec->context().imp()->pushScope(func);    body->processFuncDecl(exec);    exec->context().imp()->popScope();    exec->context().imp()->setVariableObject(oldVar);  }}// ------------------------------ FuncExprNode ---------------------------------void FuncExprNode::ref(){  Node::ref();  if ( param )    param->ref();  if ( body )    body->ref();}bool FuncExprNode::deref(){  if ( param && param->deref() )    delete param;  if ( body && body->deref() )    delete body;  return Node::deref();}// ECMA 13Value FuncExprNode::evaluate(ExecState *exec){  FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body, exec->context().imp()->scopeChain());  Value ret(fimp);  List empty;  Value proto = exec->lexicalInterpreter()->builtinObject().construct(exec,empty);  fimp->put(exec, prototypePropertyName, proto, Internal|DontDelete);  int plen = 0;  for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)    fimp->addParameter(p->ident());  return ret;}// ------------------------------ SourceElementsNode ---------------------------SourceElementsNode::SourceElementsNode(StatementNode *s1)  : element(s1), elements(this){  setLoc(s1->firstLine(), s1->lastLine(), s1->sourceId());} SourceElementsNode::SourceElementsNode(SourceElementsNode *s1, StatementNode *s2)  : element(s2), elements(s1->elements){  s1->elements = this;  setLoc(s1->firstLine(), s2->lastLine(), s1->sourceId());}void SourceElementsNode::ref(){  for (SourceElementsNode *n = this; n; n = n->elements) {    n->Node::ref();    if (n->element)      n->element->ref();  }}bool SourceElementsNode::deref(){  SourceElementsNode *next;  for (SourceElementsNode *n = this; n; n = next) {    next = n->elements;    if (n->element && n->element->deref())      delete n->element;    if (n != this && n->Node::deref())      delete n;  }  return Node::deref();}// ECMA 14Completion SourceElementsNode::execute(ExecState *exec){  KJS_CHECKEXCEPTION  Completion c1 = element->execute(exec);  KJS_CHECKEXCEPTION;  if (c1.complType() != Normal)    return c1;    for (SourceElementsNode *n = elements; n; n = n->elements) {    Completion c2 = n->element->execute(exec);    if (c2.complType() != Normal)      return c2;    // The spec says to return c2 here, but it seems that mozilla returns c1 if    // c2 doesn't have a value    if (!c2.value().isNull())      c1 = c2;  }    return c1;}// ECMA 14void SourceElementsNode::processFuncDecl(ExecState *exec){  for (SourceElementsNode *n = this; n; n = n->elements)    n->element->processFuncDecl(exec);}void SourceElementsNode::processVarDecls(ExecState *exec){  for (SourceElementsNode *n = this; n; n = n->elements)    n->element->processVarDecls(exec);}ProgramNode::ProgramNode(SourceElementsNode *s): FunctionBodyNode(s) {    //fprintf(stderr,"ProgramNode::ProgramNode %p\n",this);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -