Search

1/07/2009

What determines that a script is long-running? | NCZOnline

What determines that a script is long-running? | NCZOnline
Internet Explorer determines that a script is long-running by the total amount of statements the JScript engine has executed. By default, the value is 5 million statements and can be altered via a registry setting. When your script exceeds this maximum number of statements, you’ll get this dialog:
IE Dialog: A script on this page is causing Internet Explorer to run slowly. If it continues to run, your compute rmay become unresponsive.
Firefox determines that a script is long-running by timing how long the script engine has been executing code continuously. The default time is set to 10 seconds and can be altered via about:config. Note that the amount of time modal dialogs, such as alerts, are displayed does not count against the script engine execution code. When this execution time has been reached, Firefox displays a dialog with the following message:
Firefox Dialog: A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
Safari also uses script engine execution time to determine when a script has become long-running. After some digging around in the WebKit source code, it looks like the default timeout is 5 seconds. When that threshold is reached, the following dialog is displayed:
Safari Dialog: A script on the page [url] is making Safari unresponsive. Do you want to continue running the script, or stop it?
Opera is an interesting case: it doesn’t appear to have a long-running script limit. I ran several tests that completed even after minutes of code execution. During the time, the browser remain mostly responsive, which is impressive. I’m not sure if this approach is a good thing or a bad thing at the moment, but it’s what is implemented.


function chunk(array, process, context) {
var items = array.concat(); //clone the array
setTimeout(function() {
var item = items.shift();
process.call(context, item);
if (items.length > 0) {
setTimeout(arguments.callee, 100);
}
},
100);
}

沒有留言: