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/interpreter.h

    r14834 r14893  
    3737  class SavedBuiltins;
    3838  class ScopeChain;
    39 
     39  class TimeoutChecker;
     40 
    4041  namespace Bindings {
    4142    class RootObject;
     
    5051  class Interpreter {
    5152      friend class Collector;
     53      friend class TimeoutChecker;
    5254  public:
    5355    /**
     
    323325   
    324326    static Interpreter* interpreterWithGlobalObject(JSObject*);
     327   
     328    void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }
     329
     330    void startTimeoutCheck();
     331    void stopTimeoutCheck();
     332
     333    void pauseTimeoutCheck();
     334    void resumeTimeoutCheck();
     335   
     336    bool checkTimeout();
     337   
     338protected:
     339    virtual bool shouldInterruptScript() { return true; }
     340    long m_timeoutTime;
     341
    325342private:
     343    bool handleTimeout();
    326344    void init();
    327345   
     
    355373    Context* m_context;
    356374    CompatMode m_compatMode;
     375
     376    TimeoutChecker* m_timeoutChecker;
     377    bool m_timedOut;
     378
     379    unsigned m_startTimeoutCheckCount;
     380    unsigned m_pauseTimeoutCheckCount;
    357381
    358382    ProtectedPtr<JSObject> m_Object;
     
    391415  };
    392416
     417  inline bool Interpreter::checkTimeout()
     418  {
     419    if (!m_timedOut)
     420      return false;
     421
     422    return handleTimeout();
     423  }
     424 
    393425} // namespace
    394426
Note: See TracChangeset for help on using the changeset viewer.