nodes.cpp

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C++ 代码 · 共 3,000 行 · 第 1/5 页

CPP
3,000 行
字号
  Value v = value->evaluate(exec);  KJS_CHECKEXCEPTION  return Completion(ReturnValue, v);}// ----------------------------- WithNode -------------------------------------void WithNode::ref(){  StatementNode::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 StatementNode::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) const{  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTIONVALUE  return v;}// ECMA 12.11Completion CaseClauseNode::evalStatements(ExecState *exec) const{  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*/) const{  /* 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){  def = d;  if (l1) {    list1 = l1->nx;    l1->nx = 0;  } else {    list1 = 0;  }  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*/) const{  /* should never be called */  assert(false);  return Value();}// ECMA 12.11Completion CaseBlockNode::evalBlock(ExecState *exec, const Value& input) const{  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(){  StatementNode::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 StatementNode::deref();}// ECMA 12.11Completion SwitchNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTION  exec->context().imp()->seenLabels()->pushSwitch();  Completion res = block->evalBlock(exec,v);  exec->context().imp()->seenLabels()->popSwitch();  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(){  StatementNode::ref();  if ( statement )    statement->ref();}bool LabelNode::deref(){  if ( statement && statement->deref() )    delete statement;  return StatementNode::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(){  StatementNode::ref();  if ( expr )    expr->ref();}bool ThrowNode::deref(){  if ( expr && expr->deref() )    delete expr;  return StatementNode::deref();}// ECMA 12.13Completion ThrowNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Value v = expr->evaluate(exec);  KJS_CHECKEXCEPTION  // bail out on error  KJS_CHECKEXCEPTION  Debugger *dbg = exec->interpreter()->imp()->debugger();  if (dbg)    dbg->exception(exec,v,exec->context().imp()->inTryCatch());  return Completion(Throw, v);}// ----------------------------- CatchNode ------------------------------------void CatchNode::ref(){  StatementNode::ref();  if ( block )    block->ref();}bool CatchNode::deref(){  if ( block && block->deref() )    delete block;  return StatementNode::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(){  StatementNode::ref();  if ( block )    block->ref();}bool FinallyNode::deref(){  if ( block && block->deref() )    delete block;  return StatementNode::deref();}// ECMA 12.14Completion FinallyNode::execute(ExecState *exec){  return block->execute(exec);}void FinallyNode::processVarDecls(ExecState *exec){  block->processVarDecls(exec);}// ----------------------------- TryNode --------------------------------------void TryNode::ref(){  StatementNode::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 StatementNode::deref();}// ECMA 12.14Completion TryNode::execute(ExecState *exec){  KJS_BREAKPOINT;  Completion c, c2;  if (_catch)    exec->context().imp()->pushTryCatch();  c = block->execute(exec);  if (_catch)    exec->context().imp()->popTryCatch();  if (!_final) {    if (c.complType() != Throw)      return c;    return _catch->execute(exec,c.value());  }  if (!_catch) {    Value exception = exec->_exception;    exec->_exception = Value();    c2 = _final->execute(exec);    if (!exec->hadException() && c2.complType() != Throw)      exec->_exception = exception;    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*/) const{  return Undefined();}// ----------------------------- FunctionBodyNode -----------------------------FunctionBodyNode::FunctionBodyNode(SourceElementsNode *s)  : BlockNode(s){  //fprintf(stderr,"FunctionBodyNode::FunctionBodyNode %p\n",this);}void FunctionBodyNode::processFuncDecl(ExecState *exec){  if (source)    source->processFuncDecl(exec);}// ----------------------------- FuncDeclNode ---------------------------------void FuncDeclNode::ref(){  StatementNode::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 StatementNode::deref();}// ECMA 13void FuncDeclNode::processFuncDecl(ExecState *exec){  ContextImp *ctx = exec->context().imp();  // 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(const ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)    fimp->addParameter(p->ident());  func.put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum);#ifdef KJS_VERBOSE  fprintf(stderr,"KJS: new function %s in %p\n", ident.ustring().cstring().c_str(), ctx->variableObject().imp());#endif  if (exec->_context->codeType() == EvalCode) {      // ECMA 10.2.2      ctx->variableObject().put(exec, ident, func, Internal);  } else {      ctx->variableObject().put(exec, ident, func, DontDelete | Internal);  }  if (body) {    

⌨️ 快捷键说明

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