- From: Sean Hogan <shogun70@westnet.com.au>
- Date: Mon, 13 May 2013 10:38:29 +1000
- To: public-script-coord@w3.org, Boris Zbarsky <bzbarsky@MIT.EDU>
> 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. No, setTimeout doesn't do this. If I setTimeout a task, which itself setTimeout's a task, which setTimeout's a task, etc, etc then each task is delayed by, say 4, 8, 12, 16 msec. Moreover the page can be reflowed between tasks. I believe setImmediate also allows the page to reflow before the task is executed. If I queue a task, which itself queues a task, which queues a task, etc, etc then these tasks are executed asynchronously but not delayed. Also the page is not unnecessarily reflowed. Of course it is possible to produce a close emulation of queueing a task... But since all browsers already have this feature internally (or will need it for DOM Futures) why not expose it to the scripting environment? > > 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 Of course it is possible to jump through hoops to get this in current browsers. I already said (and did) this. To repeat what I said above: since all browsers already have this feature internally (or will need it for DOM Futures) why not expose it to the scripting environment? Sean
Received on Monday, 13 May 2013 00:38:56 UTC