Closed Bug 1101124 Opened 10 years ago Closed 9 years ago

Throw an exception for slow scripts

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla36

People

(Reporter: tschneider, Assigned: tschneider)

Details

Attachments

(1 file)

When doing automated testing (in our case testing the Shumway extension on crawled SWFs using Selenium/WebDrivers), infinite loops or slow scripts are leading to unresponsive browser instances. Showing a prompt to decide whether to stop or continuing such a script blocks all subsequent tests (using the same instance), waiting for manual interaction. To avoid that, and being able to react to test cases where scripts are running too slowly, I want to propose adding a preference that, when set, makes the browser throwing an exception instead of showing the slow script dialog.
Where would the exception be thrown?
Say you have
while(true);
What should actually throw?

We could make http://mxr.mozilla.org/mozilla-aurora/source/dom/base/nsGlobalWindow.cpp#10960 to
dispatch a chrome only event if needed. Would that help?
Do we want an exception, or do we want to act the same way we do if the user clicks "stop script" in the dialog (i.e. an uncatchable script termination)?

The problem with an exception is that something like this:

  while (true) {
    try {
      while (true);
    } catch (e) {}
  }

will simply suppress it and keep ilooping...
That's a good point. An "always stop" pref at least helps us getting back control of the blocked browser instance. We might also want to consider setting that flag after a user chose "Stop script" + "Don't ask me again" in the slow script dialog.
OK.  An "always stop" pref is trivial to implement.  If you want it to only affect Window instances and sandboxes that have a window prototype, just have nsGlobalWindow::ShowSlowScriptDialog check the pref and return KillSlowScript if set.  If you want it to also affect JSMs, it needs to go in XPCJSRuntime::InterruptCallback.  I'm happy to review.  ;)
This adds a check in nsGlobalWindow::ShowSlowScriptDialog for a pref named dom.always_stop_slow_scripts and returns KillSlowScript if set.
Attachment #8526537 - Flags: review?(bzbarsky)
Comment on attachment 8526537 [details] [diff] [review]
Checks for a pref to always stop slow scripts

r=me
Attachment #8526537 - Flags: review?(bzbarsky) → review+
Keywords: checkin-needed
Hi Tobias would it be possible to provide a try run, thanks!
Assignee: nobody → schneider
Flags: needinfo?(schneider)
Keywords: checkin-needed
Flags: needinfo?(schneider)
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/b98e55fb98b7
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla36
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.