- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Tue, 07 May 2013 22:05:27 -0400
- To: public-script-coord@w3.org
On 5/7/13 9:27 PM, Sean Hogan wrote:
> a. Queueing a task - that is, asynchronously executing a function
setTimeout does this, no? If we really feel that the minimum 4ms delay
it imposes is not OK, there have been proposals for a setImmediate,
though I'd like to see some indication that it won't be abused like
setTimeout has been.
> b. Isolating a task - that is, synchronously executing a function in
> such a way that errors are detected but not prevented from going to the
> console
This is also already possible, as far as I can tell, modulo a slight bug
in Chrome. Consider this testcase:
<script>
function isolate(f) {
try {
f();
} catch (e) {
setTimeout(function() { throw e; }, 0);
}
}
function g() {
nonexistent();
}
isolate(g);
</script>
The "nonexistent()" call is on line 10; the throw statement on line 6.
The question is what goes to the console.
In Firefox, I get: ReferenceError: nonexistent is not defined @
file:///whatever.html:10
In Chrome I get: Uncaught ReferenceError: nonexistent is not defined.
whatever.html:10 (though only if the console is open before I run the
testcase; if I open it after running the testcase, Chrome gets the line
number wrong and claims it was on line 6).
In Opera I get: Uncaught exception: ReferenceError: Undefined variable:
nonexistent
Error thrown at line 6, column 43 in <anonymous function>() in
whatever.html:
throw e;
Error initially occurred at line 10, column 4 in g() in whatever.html:
nonexistent();
In Safari I get: ReferenceError: Can't find variable: nonexistent.
whatever.html:10
In IE9 I get: SCRIPT5009: 'nonexistent' is undefined
whatever.html, line 10 character 5
If synchronous reporting to the console is desired, that should also be
possible, actually, like so:
var reporter = document.createElement("div");
function isolate(f) {
try {
f();
} catch (e) {
reporter.onclick = function() { throw e; };
reporter.dispatchEvent(new Event("click"));
}
}
(with createEvent and whatnot as needed for older UAs).
-Boris
Received on Wednesday, 8 May 2013 02:05:56 UTC