| OLD | NEW |
| 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 // Patch file for the dart:async library. | 5 // Patch file for the dart:async library. |
| 6 | 6 |
| 7 import 'dart:_js_helper' show | 7 import 'dart:_js_helper' show |
| 8 patch, | 8 patch, |
| 9 Primitives, | 9 Primitives, |
| 10 convertDartClosureToJS, | 10 convertDartClosureToJS, |
| 11 loadDeferredLibrary; | 11 loadDeferredLibrary; |
| 12 import 'dart:_isolate_helper' show | 12 import 'dart:_isolate_helper' show |
| 13 IsolateNatives, | 13 IsolateNatives, |
| 14 TimerImpl, | 14 TimerImpl, |
| 15 leaveJsAsync, | 15 leaveJsAsync, |
| 16 enterJsAsync, | 16 enterJsAsync, |
| 17 isWorker; | 17 isWorker; |
| 18 | 18 |
| 19 import 'dart:_foreign_helper' show JS; | 19 import 'dart:_foreign_helper' show JS; |
| 20 | 20 |
| 21 @patch | 21 @patch |
| 22 Timer _createTimer(Duration duration, void callback()) { | |
| 23 int milliseconds = duration.inMilliseconds; | |
| 24 if (milliseconds < 0) milliseconds = 0; | |
| 25 return new TimerImpl(milliseconds, callback); | |
| 26 } | |
| 27 | |
| 28 @patch | |
| 29 Timer _createPeriodicTimer(Duration duration, | |
| 30 void callback(Timer timer)) { | |
| 31 int milliseconds = duration.inMilliseconds; | |
| 32 if (milliseconds < 0) milliseconds = 0; | |
| 33 return new TimerImpl.periodic(milliseconds, callback); | |
| 34 } | |
| 35 | |
| 36 @patch | |
| 37 class _AsyncRun { | 22 class _AsyncRun { |
| 38 @patch | 23 @patch |
| 39 static void _scheduleImmediate(void callback()) { | 24 static void _scheduleImmediate(void callback()) { |
| 40 scheduleImmediateClosure(callback); | 25 scheduleImmediateClosure(callback); |
| 41 } | 26 } |
| 42 | 27 |
| 43 // Lazily initialized. | 28 // Lazily initialized. |
| 44 static final Function scheduleImmediateClosure = | 29 static final Function scheduleImmediateClosure = |
| 45 _initializeScheduleImmediate(); | 30 _initializeScheduleImmediate(); |
| 46 | 31 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 internalCallback() { | 42 internalCallback() { |
| 58 leaveJsAsync(); | 43 leaveJsAsync(); |
| 59 callback(); | 44 callback(); |
| 60 }; | 45 }; |
| 61 enterJsAsync(); | 46 enterJsAsync(); |
| 62 JS('void', 'self.scheduleImmediate(#)', | 47 JS('void', 'self.scheduleImmediate(#)', |
| 63 convertDartClosureToJS(internalCallback, 0)); | 48 convertDartClosureToJS(internalCallback, 0)); |
| 64 } | 49 } |
| 65 | 50 |
| 66 static void _scheduleImmediateWithTimer(void callback()) { | 51 static void _scheduleImmediateWithTimer(void callback()) { |
| 67 _createTimer(Duration.ZERO, callback); | 52 Timer._createTimer(Duration.ZERO, callback); |
| 68 } | 53 } |
| 69 } | 54 } |
| 70 | 55 |
| 71 @patch | 56 @patch |
| 72 class DeferredLibrary { | 57 class DeferredLibrary { |
| 73 @patch | 58 @patch |
| 74 Future<Null> load() { | 59 Future<Null> load() { |
| 75 return loadDeferredLibrary(libraryName, uri); | 60 return loadDeferredLibrary(libraryName, uri); |
| 76 } | 61 } |
| 77 } | 62 } |
| 78 | 63 |
| 64 @patch |
| 65 class Timer { |
| 66 @patch |
| 67 static Timer _createTimer(Duration duration, void callback()) { |
| 68 int milliseconds = duration.inMilliseconds; |
| 69 if (milliseconds < 0) milliseconds = 0; |
| 70 return new TimerImpl(milliseconds, callback); |
| 71 } |
| 72 |
| 73 @patch |
| 74 static Timer _createPeriodicTimer(Duration duration, |
| 75 void callback(Timer timer)) { |
| 76 int milliseconds = duration.inMilliseconds; |
| 77 if (milliseconds < 0) milliseconds = 0; |
| 78 return new TimerImpl.periodic(milliseconds, callback); |
| 79 } |
| 80 } |
| 81 |
| 79 bool get _hasDocument => JS('String', 'typeof document') == 'object'; | 82 bool get _hasDocument => JS('String', 'typeof document') == 'object'; |
| OLD | NEW |