Chromium Code Reviews| 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 Primitives, convertDartClosureToJS; | 7 import 'dart:_js_helper' show Primitives, convertDartClosureToJS; |
| 8 import 'dart:_isolate_helper' show | 8 import 'dart:_isolate_helper' show |
| 9 IsolateNatives, | 9 IsolateNatives, |
| 10 TimerImpl, | 10 TimerImpl, |
| 11 leaveJsAsync, | 11 leaveJsAsync, |
| 12 enterJsAsync, | 12 enterJsAsync, |
| 13 isWorker; | 13 isWorker, |
| 14 globalThis; | |
| 14 | 15 |
| 15 import 'dart:_foreign_helper' show JS; | 16 import 'dart:_foreign_helper' show JS; |
| 16 | 17 |
| 17 patch Timer _createTimer(Duration duration, void callback()) { | 18 patch Timer _createTimer(Duration duration, void callback()) { |
| 18 int milliseconds = duration.inMilliseconds; | 19 int milliseconds = duration.inMilliseconds; |
| 19 if (milliseconds < 0) milliseconds = 0; | 20 if (milliseconds < 0) milliseconds = 0; |
| 21 if (milliseconds > 0) print("T: $milliseconds"); | |
|
floitsch
2014/03/18 13:18:23
debug code. (just fyi).
Lasse Reichstein Nielsen
2014/03/19 10:24:41
Done.
| |
| 20 return new TimerImpl(milliseconds, callback); | 22 return new TimerImpl(milliseconds, callback); |
| 21 } | 23 } |
| 22 | 24 |
| 23 patch Timer _createPeriodicTimer(Duration duration, | 25 patch Timer _createPeriodicTimer(Duration duration, |
| 24 void callback(Timer timer)) { | 26 void callback(Timer timer)) { |
| 25 int milliseconds = duration.inMilliseconds; | 27 int milliseconds = duration.inMilliseconds; |
| 26 if (milliseconds < 0) milliseconds = 0; | 28 if (milliseconds < 0) milliseconds = 0; |
| 27 return new TimerImpl.periodic(milliseconds, callback); | 29 return new TimerImpl.periodic(milliseconds, callback); |
| 28 } | 30 } |
| 29 | 31 |
| 30 patch class _AsyncRun { | 32 patch class _AsyncRun { |
| 31 patch static void _scheduleImmediate(void callback()) { | 33 patch static void _scheduleImmediate(void callback()) { |
| 34 scheduleImmediateClosure(callback); | |
| 35 } | |
| 36 | |
| 37 // Lazily initialized. | |
| 38 static final Function scheduleImmediateClosure = | |
| 39 _initializeScheduleImmediate(); | |
| 40 | |
| 41 static Function _initializeScheduleImmediate() { | |
| 42 if (JS('', '#.scheduleImmediate', globalThis) != null) { | |
| 43 return _scheduleImmediateJsOverride; | |
| 44 } | |
| 32 // TODO(9002): don't use the Timer to enqueue the immediate callback. | 45 // TODO(9002): don't use the Timer to enqueue the immediate callback. |
| 46 // Also check for other JS options like mutation observer or runImmediate. | |
| 47 return _scheduleImmediateWithTimer; | |
| 48 } | |
| 49 | |
| 50 static void _scheduleImmediateJsOverride(void callback()) { | |
| 51 JS('void', '#.scheduleImmediate(#)', | |
| 52 globalThis, | |
| 53 convertDartClosureToJS(callback, 0)); | |
| 54 } | |
| 55 | |
| 56 static void _scheduleImmediateWithTimer(void callback()) { | |
| 33 _createTimer(Duration.ZERO, callback); | 57 _createTimer(Duration.ZERO, callback); |
| 34 } | 58 } |
| 35 } | 59 } |
| 36 | 60 |
| 37 patch class DeferredLibrary { | 61 patch class DeferredLibrary { |
| 38 patch Future<bool> load() { | 62 patch Future<bool> load() { |
| 39 List hunkNames = new List(); | 63 List hunkNames = new List(); |
| 40 if (JS('bool', '\$.libraries_to_load[#] === undefined', libraryName)) { | 64 if (JS('bool', '\$.libraries_to_load[#] === undefined', libraryName)) { |
| 41 return new Future(() => false); | 65 return new Future(() => false); |
| 42 } | 66 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 completer.completeError( | 168 completer.completeError( |
| 145 new DeferredLoadException("Loading $uri failed.")); | 169 new DeferredLoadException("Loading $uri failed.")); |
| 146 }, 1)); | 170 }, 1)); |
| 147 JS('', 'document.body.appendChild(#)', script); | 171 JS('', 'document.body.appendChild(#)', script); |
| 148 | 172 |
| 149 return completer.future; | 173 return completer.future; |
| 150 }); | 174 }); |
| 151 } | 175 } |
| 152 | 176 |
| 153 bool get _hasDocument => JS('String', 'typeof document') == 'object'; | 177 bool get _hasDocument => JS('String', 'typeof document') == 'object'; |
| OLD | NEW |