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

Unified Diff: tools/dom/src/native_DOMImplementation.dart

Issue 13185006: Redirect pure isolate print to helper isolate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/html/dart2js/html_dart2js.dart ('K') | « tools/dom/src/Timer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index 3ef960a2ae570346ef041ed830065ef463a7d37a..8bcab03d4f5f5bc7de7dbed328ab2b22792e5083 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -58,7 +58,6 @@ class _Utils {
}
static window() native "Utils_window";
- static print(String message) native "Utils_print";
static forwardingPrint(String message) native "Utils_forwardingPrint";
static void spawnDomFunction(Function topLevelFunction, int replyTo) native "Utils_spawnDomFunction";
static int _getNewIsolateId() native "Utils_getNewIsolateId";
@@ -132,12 +131,41 @@ class _DOMStringMap extends NativeFieldWrapperClass1 implements Map<String, Stri
bool get isEmpty => Maps.isEmpty(this);
}
-get _printClosure => (s) {
- try {
- window.console.log(s);
- } catch (_) {
- _Utils.print(s);
- }
+final Future<SendPort> _HELPER_ISOLATE_PORT =
+ spawnDomFunction(_helperIsolateMain);
+
+final _TIMER_REGISTRY = new Map<SendPort, Timer>();
+
+const _NEW_TIMER = 'NEW_TIMER';
+const _CANCEL_TIMER = 'CANCEL_TIMER';
+const _TIMER_PING = 'TIMER_PING';
+const _PRINT = 'PRINT';
+
+_helperIsolateMain() {
+ port.receive((msg, replyTo) {
+ final cmd = msg[0];
+ if (cmd == _NEW_TIMER) {
+ final duration = new Duration(milliseconds: msg[1]);
+ bool periodic = msg[2];
+ final callback = () { replyTo.send(_TIMER_PING); };
+ _TIMER_REGISTRY[replyTo] = periodic ?
+ new Timer.periodic(duration, callback) :
+ new Timer(duration, callback);
+ } else if (cmd == _CANCEL_TIMER) {
+ _TIMER_REGISTRY.remove(replyTo).cancel();
+ } else if (cmd == _PRINT) {
+ final message = msg[1];
+ // TODO(antonm): we need somehow identify those isolates.
+ print('[From isolate] $message');
vsm 2013/03/29 14:14:54 We have the id we're using for interop (_Utils._ge
Anton Muhin 2013/03/29 16:14:33 Sorry, no, I do not immediately now. Ideally we s
+ }
+ });
+}
+
+final _printClosure = window.console.log;
vsm 2013/03/29 14:14:54 Is there a way at the Dart-level to programmatical
Anton Muhin 2013/03/29 16:14:33 Not right now. We can expose it via Utils, but I
+final _pureIsolatePrintClosure = (s) {
+ _HELPER_ISOLATE_PORT.then((sendPort) {
+ sendPort.send([_PRINT, s]);
+ });
};
final _forwardingPrintClosure = _Utils.forwardingPrint;
« sdk/lib/html/dart2js/html_dart2js.dart ('K') | « tools/dom/src/Timer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698