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

Side by Side Diff: tool/input_sdk/patch/async_patch.dart

Issue 1200233004: fixes #168, dart:js implementation with a test (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix error (window not defined) Created 5 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
« no previous file with comments | « tool/input_sdk/lib/js/dart2js/js_dart2js.dart ('k') | tool/input_sdk/patch/core_patch.dart » ('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;
11 import 'dart:_isolate_helper' show 10 import 'dart:_isolate_helper' show
12 IsolateNatives, 11 IsolateNatives,
13 TimerImpl, 12 TimerImpl,
14 leaveJsAsync, 13 leaveJsAsync,
15 enterJsAsync, 14 enterJsAsync,
16 isWorker; 15 isWorker;
17 16
18 import 'dart:_foreign_helper' show JS; 17 import 'dart:_foreign_helper' show JS;
19 18
20 @patch 19 @patch
(...skipping 18 matching lines...) Expand all
39 var span = JS('', 'self.document.createElement("span")'); 38 var span = JS('', 'self.document.createElement("span")');
40 var storedCallback; 39 var storedCallback;
41 40
42 internalCallback(_) { 41 internalCallback(_) {
43 leaveJsAsync(); 42 leaveJsAsync();
44 var f = storedCallback; 43 var f = storedCallback;
45 storedCallback = null; 44 storedCallback = null;
46 f(); 45 f();
47 }; 46 };
48 47
49 var observer = JS('', 'new self.MutationObserver(#)', 48 var observer = JS('', 'new self.MutationObserver(#)', internalCallback);
50 convertDartClosureToJS(internalCallback, 1));
51 JS('', '#.observe(#, { childList: true })', 49 JS('', '#.observe(#, { childList: true })',
52 observer, div); 50 observer, div);
53 51
54 return (void callback()) { 52 return (void callback()) {
55 assert(storedCallback == null); 53 assert(storedCallback == null);
56 enterJsAsync(); 54 enterJsAsync();
57 storedCallback = callback; 55 storedCallback = callback;
58 // Because of a broken shadow-dom polyfill we have to change the 56 // Because of a broken shadow-dom polyfill we have to change the
59 // children instead a cheap property. 57 // children instead a cheap property.
60 // See https://github.com/Polymer/ShadowDOM/issues/468 58 // See https://github.com/Polymer/ShadowDOM/issues/468
61 JS('', '#.firstChild ? #.removeChild(#): #.appendChild(#)', 59 JS('', '#.firstChild ? #.removeChild(#): #.appendChild(#)',
62 div, div, span, div, span); 60 div, div, span, div, span);
63 }; 61 };
64 } else if (JS('', 'self.setImmediate') != null) { 62 } else if (JS('', 'self.setImmediate') != null) {
65 return _scheduleImmediateWithSetImmediate; 63 return _scheduleImmediateWithSetImmediate;
66 } 64 }
67 // TODO(20055): We should use DOM promises when available. 65 // TODO(20055): We should use DOM promises when available.
68 return _scheduleImmediateWithTimer; 66 return _scheduleImmediateWithTimer;
69 } 67 }
70 68
71 static void _scheduleImmediateJsOverride(void callback()) { 69 static void _scheduleImmediateJsOverride(void callback()) {
72 internalCallback() { 70 internalCallback() {
73 leaveJsAsync(); 71 leaveJsAsync();
74 callback(); 72 callback();
75 }; 73 };
76 enterJsAsync(); 74 enterJsAsync();
77 JS('void', 'self.scheduleImmediate(#)', 75 JS('void', 'self.scheduleImmediate(#)', internalCallback);
78 convertDartClosureToJS(internalCallback, 0));
79 } 76 }
80 77
81 static void _scheduleImmediateWithSetImmediate(void callback()) { 78 static void _scheduleImmediateWithSetImmediate(void callback()) {
82 internalCallback() { 79 internalCallback() {
83 leaveJsAsync(); 80 leaveJsAsync();
84 callback(); 81 callback();
85 }; 82 };
86 enterJsAsync(); 83 enterJsAsync();
87 JS('void', 'self.setImmediate(#)', 84 JS('void', 'self.setImmediate(#)', internalCallback);
88 convertDartClosureToJS(internalCallback, 0));
89 } 85 }
90 86
91 static void _scheduleImmediateWithTimer(void callback()) { 87 static void _scheduleImmediateWithTimer(void callback()) {
92 Timer._createTimer(Duration.ZERO, callback); 88 Timer._createTimer(Duration.ZERO, callback);
93 } 89 }
94 } 90 }
95 91
96 @patch 92 @patch
97 class DeferredLibrary { 93 class DeferredLibrary {
98 @patch 94 @patch
(...skipping 15 matching lines...) Expand all
114 @patch 110 @patch
115 static Timer _createPeriodicTimer(Duration duration, 111 static Timer _createPeriodicTimer(Duration duration,
116 void callback(Timer timer)) { 112 void callback(Timer timer)) {
117 int milliseconds = duration.inMilliseconds; 113 int milliseconds = duration.inMilliseconds;
118 if (milliseconds < 0) milliseconds = 0; 114 if (milliseconds < 0) milliseconds = 0;
119 return new TimerImpl.periodic(milliseconds, callback); 115 return new TimerImpl.periodic(milliseconds, callback);
120 } 116 }
121 } 117 }
122 118
123 bool get _hasDocument => JS('String', 'typeof document') == 'object'; 119 bool get _hasDocument => JS('String', 'typeof document') == 'object';
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/js/dart2js/js_dart2js.dart ('k') | tool/input_sdk/patch/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698