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

Side by Side Diff: sdk/lib/_internal/lib/async_patch.dart

Issue 393843002: Revert "Implement scheduleImmediate on Chrome/Drt/Safari/Firefox." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | tests/html/html.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 requiresPreamble;
13 import 'dart:_isolate_helper' show 12 import 'dart:_isolate_helper' show
14 IsolateNatives, 13 IsolateNatives,
15 TimerImpl, 14 TimerImpl,
16 leaveJsAsync, 15 leaveJsAsync,
17 enterJsAsync, 16 enterJsAsync,
18 isWorker; 17 isWorker;
19 18
20 import 'dart:_foreign_helper' show JS; 19 import 'dart:_foreign_helper' show JS;
21 20
22 @patch 21 @patch
23 class _AsyncRun { 22 class _AsyncRun {
24 @patch 23 @patch
25 static void _scheduleImmediate(void callback()) { 24 static void _scheduleImmediate(void callback()) {
26 scheduleImmediateClosure(callback); 25 scheduleImmediateClosure(callback);
27 } 26 }
28 27
29 // Lazily initialized. 28 // Lazily initialized.
30 static final Function scheduleImmediateClosure = 29 static final Function scheduleImmediateClosure =
31 _initializeScheduleImmediate(); 30 _initializeScheduleImmediate();
32 31
33 static Function _initializeScheduleImmediate() { 32 static Function _initializeScheduleImmediate() {
34 requiresPreamble();
35 if (JS('', 'self.scheduleImmediate') != null) { 33 if (JS('', 'self.scheduleImmediate') != null) {
36 return _scheduleImmediateJsOverride; 34 return _scheduleImmediateJsOverride;
37 } 35 }
38 if (JS('', 'self.MutationObserver') != null &&
39 JS('', 'self.document') != null) {
40 // Use mutationObservers.
41 var div = JS('', 'self.document.createElement("div")');
42 var span = JS('', 'self.document.createElement("span")');
43 var storedCallback;
44
45 internalCallback(_) {
46 leaveJsAsync();
47 var f = storedCallback;
48 storedCallback = null;
49 f();
50 };
51
52 var observer = JS('', 'new self.MutationObserver(#)',
53 convertDartClosureToJS(internalCallback, 1));
54 JS('', '#.observe(#, { childList: true })',
55 observer, div);
56
57 return (void callback()) {
58 assert(storedCallback == null);
59 enterJsAsync();
60 storedCallback = callback;
61 // Because of a broken shadow-dom polyfill we have to change the
62 // children instead a cheap property.
63 // See https://github.com/Polymer/ShadowDOM/issues/468
64 JS('', '#.firstChild ? #.removeChild(#): #.appendChild(#)',
65 div, div, span, div, span);
66 };
67
68 }
69 // TODO(9002): don't use the Timer to enqueue the immediate callback. 36 // TODO(9002): don't use the Timer to enqueue the immediate callback.
70 // Also check for other JS options like setImmediate. 37 // Also check for other JS options like mutation observer or runImmediate.
71 // TODO(20055): We should use DOM promises when available.
72 return _scheduleImmediateWithTimer; 38 return _scheduleImmediateWithTimer;
73 } 39 }
74 40
75 static void _scheduleImmediateJsOverride(void callback()) { 41 static void _scheduleImmediateJsOverride(void callback()) {
76 internalCallback() { 42 internalCallback() {
77 leaveJsAsync(); 43 leaveJsAsync();
78 callback(); 44 callback();
79 }; 45 };
80 enterJsAsync(); 46 enterJsAsync();
81 JS('void', 'self.scheduleImmediate(#)', 47 JS('void', 'self.scheduleImmediate(#)',
(...skipping 25 matching lines...) Expand all
107 @patch 73 @patch
108 static Timer _createPeriodicTimer(Duration duration, 74 static Timer _createPeriodicTimer(Duration duration,
109 void callback(Timer timer)) { 75 void callback(Timer timer)) {
110 int milliseconds = duration.inMilliseconds; 76 int milliseconds = duration.inMilliseconds;
111 if (milliseconds < 0) milliseconds = 0; 77 if (milliseconds < 0) milliseconds = 0;
112 return new TimerImpl.periodic(milliseconds, callback); 78 return new TimerImpl.periodic(milliseconds, callback);
113 } 79 }
114 } 80 }
115 81
116 bool get _hasDocument => JS('String', 'typeof document') == 'object'; 82 bool get _hasDocument => JS('String', 'typeof document') == 'object';
OLDNEW
« no previous file with comments | « no previous file | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698