Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1010)

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart

Issue 11866003: Support Timer with 0 millisecond delay in dart2js running in the command line. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/async_patch.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart (revision 16956)
+++ sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart (working copy)
@@ -1254,25 +1254,44 @@
TimerImpl(int milliseconds, void callback(Timer timer))
: _once = true {
- _handle = JS('int', '#.setTimeout(#, #)',
- globalThis,
- convertDartClosureToJS(() => callback(this), 0),
- milliseconds);
+ if (hasTimer() && !_globalState.isWorker) {
+ _handle = JS('int', '#.setTimeout(#, #)',
+ globalThis,
+ convertDartClosureToJS(() => callback(this), 0),
+ milliseconds);
+ } else if (milliseconds != 0) {
+ throw new UnsupportedError("Non DOM isolate with timer greater than 0.");
+ } else {
+ // This makes a dependency between the async library and the
+ // event loop of the isolate library. The compiler makes sure
+ // that the event loop is compiled if [Timer] is used.
+ _globalState.topEventLoop.enqueue(_globalState.currentContext, () {
+ callback(this);
+ }, 'timer');
+ }
}
TimerImpl.repeating(int milliseconds, void callback(Timer timer))
: _once = false {
- _handle = JS('int', '#.setInterval(#, #)',
- globalThis,
- convertDartClosureToJS(() => callback(this), 0),
- milliseconds);
+ if (hasTimer() && !_globalState.isWorker) {
+ _handle = JS('int', '#.setInterval(#, #)',
+ globalThis,
+ convertDartClosureToJS(() => callback(this), 0),
+ milliseconds);
+ } else {
+ throw new UnsupportedError("Non DOM isolate with repeating timer.");
+ }
}
void cancel() {
- if (_once) {
- JS('void', '#.clearTimeout(#)', globalThis, _handle);
+ if (hasTimer() && !_globalState.isWorker) {
+ if (_once) {
+ JS('void', '#.clearTimeout(#)', globalThis, _handle);
+ } else {
+ JS('void', '#.clearInterval(#)', globalThis, _handle);
+ }
} else {
- JS('void', '#.clearInterval(#)', globalThis, _handle);
+ throw new UnsupportedError("Canceling a timer on a non DOM isolate.");
}
}
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/async_patch.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698