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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library _isolate_helper; 5 library _isolate_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 ReceivePort lazyPort; 10 ReceivePort lazyPort;
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 throw "Unexpected serialized object"; 1247 throw "Unexpected serialized object";
1248 } 1248 }
1249 } 1249 }
1250 1250
1251 class TimerImpl implements Timer { 1251 class TimerImpl implements Timer {
1252 final bool _once; 1252 final bool _once;
1253 int _handle; 1253 int _handle;
1254 1254
1255 TimerImpl(int milliseconds, void callback(Timer timer)) 1255 TimerImpl(int milliseconds, void callback(Timer timer))
1256 : _once = true { 1256 : _once = true {
1257 _handle = JS('int', '#.setTimeout(#, #)', 1257 if (hasTimer() && !_globalState.isWorker) {
1258 globalThis, 1258 _handle = JS('int', '#.setTimeout(#, #)',
1259 convertDartClosureToJS(() => callback(this), 0), 1259 globalThis,
1260 milliseconds); 1260 convertDartClosureToJS(() => callback(this), 0),
1261 milliseconds);
1262 } else if (milliseconds != 0) {
1263 throw new UnsupportedError("Non DOM isolate with timer greater than 0.");
1264 } else {
1265 // This makes a dependency between the async library and the
1266 // event loop of the isolate library. The compiler makes sure
1267 // that the event loop is compiled if [Timer] is used.
1268 _globalState.topEventLoop.enqueue(_globalState.currentContext, () {
1269 callback(this);
1270 }, 'timer');
1271 }
1261 } 1272 }
1262 1273
1263 TimerImpl.repeating(int milliseconds, void callback(Timer timer)) 1274 TimerImpl.repeating(int milliseconds, void callback(Timer timer))
1264 : _once = false { 1275 : _once = false {
1265 _handle = JS('int', '#.setInterval(#, #)', 1276 if (hasTimer() && !_globalState.isWorker) {
1266 globalThis, 1277 _handle = JS('int', '#.setInterval(#, #)',
1267 convertDartClosureToJS(() => callback(this), 0), 1278 globalThis,
1268 milliseconds); 1279 convertDartClosureToJS(() => callback(this), 0),
1280 milliseconds);
1281 } else {
1282 throw new UnsupportedError("Non DOM isolate with repeating timer.");
1283 }
1269 } 1284 }
1270 1285
1271 void cancel() { 1286 void cancel() {
1272 if (_once) { 1287 if (hasTimer() && !_globalState.isWorker) {
1273 JS('void', '#.clearTimeout(#)', globalThis, _handle); 1288 if (_once) {
1289 JS('void', '#.clearTimeout(#)', globalThis, _handle);
1290 } else {
1291 JS('void', '#.clearInterval(#)', globalThis, _handle);
1292 }
1274 } else { 1293 } else {
1275 JS('void', '#.clearInterval(#)', globalThis, _handle); 1294 throw new UnsupportedError("Canceling a timer on a non DOM isolate.");
1276 } 1295 }
1277 } 1296 }
1278 } 1297 }
1279 1298
1280 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; 1299 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null;
OLDNEW
« 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