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


Ignore:
Timestamp:
Jun 16, 2006, 4:47:20 PM (19 years ago)
Author:
andersca
Message:

2006-06-17 Anders Carlsson <[email protected]>

Reviewed by Maciej and Geoff.

http://bugzilla.opendarwin.org/show_bug.cgi?id=7080
Provide some way to stop a JavaScript infinite loop


  • kjs/completion.h: (KJS::): Add Interrupted completion type.


  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction): Only set the exception on the new ExecState if the current one has had one.


  • kjs/interpreter.cpp: (KJS::TimeoutChecker::startTimeoutCheck): (KJS::TimeoutChecker::stopTimeoutCheck): (KJS::TimeoutChecker::alarmHandler): (KJS::TimeoutChecker::pauseTimeoutCheck): (KJS::TimeoutChecker::resumeTimeoutCheck): New TimeoutChecker class which handles setting Interpreter::m_timedOut flag after a given period of time. This currently only works on Unix platforms where setitimer and signals are used.


(KJS::Interpreter::Interpreter):
Initialize new member variables.


(KJS::Interpreter::~Interpreter):
Destroy the timeout checker.


(KJS::Interpreter::startTimeoutCheck):
(KJS::Interpreter::stopTimeoutCheck):
(KJS::Interpreter::pauseTimeoutCheck):
(KJS::Interpreter::resumeTimeoutCheck):
Call the timeout checker.


(KJS::Interpreter::handleTimeout):
Called on timeout. Resets the m_timedOut flag and calls shouldInterruptScript.


  • kjs/interpreter.h: (KJS::Interpreter::setTimeoutTime): New function for setting the timeout time.


(KJS::Interpreter::shouldInterruptScript):
New function. The idea is that this should be overridden by subclasses in order to for example
pop up a dialog asking the user if the script should be interrupted.


(KJS::Interpreter::checkTimeout):
New function which checks the m_timedOut flag and calls handleTimeout if it's set.


  • kjs/nodes.cpp: (DoWhileNode::execute): (WhileNode::execute): (ForNode::execute): Call Interpreter::checkTimeout after each iteration of the loop.
File:
1 edited

Legend:

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

    r14834 r14893  
    17131713    c = statement->execute(exec);
    17141714    exec->context()->popIteration();
     1715   
     1716    if (exec->dynamicInterpreter()->checkTimeout())
     1717        return Completion(Interrupted);
     1718
    17151719    if (!((c.complType() == Continue) && ls.contains(c.target()))) {
    17161720      if ((c.complType() == Break) && ls.contains(c.target()))
     
    17571761    c = statement->execute(exec);
    17581762    exec->context()->popIteration();
     1763
     1764    if (exec->dynamicInterpreter()->checkTimeout())
     1765        return Completion(Interrupted);
     1766   
    17591767    if (c.isValueCompletion())
    17601768      value = c.value();
     
    18081816      return c;
    18091817    }
     1818   
     1819    if (exec->dynamicInterpreter()->checkTimeout())
     1820        return Completion(Interrupted);
     1821   
    18101822    if (expr3) {
    18111823      v = expr3->evaluate(exec);
Note: See TracChangeset for help on using the changeset viewer.