Throw an exception for slow scripts

RESOLVED FIXED in mozilla36

Status

()

Core
DOM
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: tobytailor, Assigned: tobytailor)

Tracking

unspecified
mozilla36
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
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.

Comment 1

3 years ago
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...
(Assignee)

Comment 3

3 years ago
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.  ;)
(Assignee)

Comment 5

3 years ago
Created attachment 8526537 [details] [diff] [review]
Checks for a pref to always stop slow scripts

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+
(Assignee)

Updated

3 years ago
Keywords: checkin-needed
Hi Tobias would it be possible to provide a try run, thanks!
Assignee: nobody → schneider
Flags: needinfo?(schneider)
Keywords: checkin-needed
(Assignee)

Updated

3 years ago
Flags: needinfo?(schneider)
(Assignee)

Updated

3 years ago
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/b98e55fb98b7
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla36
You need to log in before you can comment on or make changes to this bug.