Changeset 9551 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Jun 30, 2005, 5:45:50 PM (20 years ago)
Author:
ggaren
Message:

-rolled in KDE fix to <rdar://problem/4167660> JavaScript fails to
throw exceptions for invalid break/continue statements

No layout tests because it's already covered by the Mozilla suite

Reviewed by mjs.

  • kjs/internal.h: LabelStack now tracks where you are relative to switch and iteration (loop) statements

(KJS::LabelStack::LabelStack):
(KJS::LabelStack::pushIteration):
(KJS::LabelStack::popIteration):
(KJS::LabelStack::inIteration):
(KJS::LabelStack::pushSwitch):
(KJS::LabelStack::popSwitch):
(KJS::LabelStack::inSwitch):

  • kjs/nodes.cpp: These files were updated to use the new LabelStack: (DoWhileNode::execute): (WhileNode::execute): (ForNode::execute): (ForInNode::execute): (SwitchNode::execute):

These files were updated to throw exceptions for invalid
break/continue statements:
(BreakNode::execute):
(ContinueNode::execute):

  • tests/mozilla/expected.html: Updated expected results to reflect fix
File:
1 edited

Legend:

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

    r9518 r9551  
    18941894    KJS_CHECKEXCEPTION
    18951895
     1896    exec->context().imp()->seenLabels()->pushIteration();
    18961897    c = statement->execute(exec);
     1898    exec->context().imp()->seenLabels()->popIteration();
    18971899    if (!((c.complType() == Continue) && ls.contains(c.target()))) {
    18981900      if ((c.complType() == Break) && ls.contains(c.target()))
     
    19541956      return Completion(Normal, value);
    19551957
     1958    exec->context().imp()->seenLabels()->pushIteration();
    19561959    c = statement->execute(exec);
     1960    exec->context().imp()->seenLabels()->popIteration();
    19571961    if (c.isValueCompletion())
    19581962      value = c.value();
     
    20212025    KJS_CHECKEXCEPTION
    20222026
     2027    exec->context().imp()->seenLabels()->pushIteration();
    20232028    Completion c = statement->execute(exec);
     2029    exec->context().imp()->seenLabels()->popIteration();
    20242030    if (c.isValueCompletion())
    20252031      cval = c.value();
     
    21322138    ref.putValue(exec, String(name.ustring()));
    21332139
     2140    exec->context().imp()->seenLabels()->pushIteration();
    21342141    c = statement->execute(exec);
     2142    exec->context().imp()->seenLabels()->popIteration();
    21352143    if (c.isValueCompletion())
    21362144      retval = c.value();
     
    21662174
    21672175  Value dummy;
    2168   return exec->context().imp()->seenLabels()->contains(ident) ?
    2169     Completion(Continue, dummy, ident) :
    2170     Completion(Throw,
    2171                throwError(exec, SyntaxError, "Label %s not found in containing block. Can't continue.", ident));
     2176
     2177  if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration())
     2178    return Completion(Throw,
     2179                      throwError(exec, SyntaxError, "Invalid continue statement."));
     2180  else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident))
     2181    return Completion(Throw,
     2182                      throwError(exec, SyntaxError, "Label %s not found.", ident));
     2183  else
     2184    return Completion(Continue, dummy, ident);
    21722185}
    21732186
     
    21802193
    21812194  Value dummy;
    2182   return exec->context().imp()->seenLabels()->contains(ident) ?
    2183     Completion(Break, dummy, ident) :
    2184     Completion(Throw,
    2185                throwError(exec, SyntaxError, "Label %s not found in containing block. Can't break.", ident));
     2195
     2196  if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration() &&
     2197      !exec->context().imp()->seenLabels()->inSwitch())
     2198    return Completion(Throw,
     2199                      throwError(exec, SyntaxError, "Invalid break statement."));
     2200  else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident))
     2201    return Completion(Throw,
     2202                      throwError(exec, SyntaxError, "Label %s not found.", ident));
     2203  else
     2204    return Completion(Break, dummy, ident);
    21862205}
    21872206
     
    24902509  Value v = expr->evaluate(exec);
    24912510  KJS_CHECKEXCEPTION
     2511
     2512  exec->context().imp()->seenLabels()->pushSwitch();
    24922513  Completion res = block->evalBlock(exec,v);
     2514  exec->context().imp()->seenLabels()->popSwitch();
    24932515
    24942516  if ((res.complType() == Break) && ls.contains(res.target()))
Note: See TracChangeset for help on using the changeset viewer.