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 part of html; | 5 part of html; |
6 | 6 |
7 class _Utils { | 7 class _Utils { |
8 static double dateTimeToDouble(DateTime dateTime) => | 8 static double dateTimeToDouble(DateTime dateTime) => |
9 dateTime.millisecondsSinceEpoch.toDouble(); | 9 dateTime.millisecondsSinceEpoch.toDouble(); |
10 static DateTime doubleToDateTime(double dateTime) { | 10 static DateTime doubleToDateTime(double dateTime) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 51 |
52 static bool isMap(obj) => obj is Map; | 52 static bool isMap(obj) => obj is Map; |
53 | 53 |
54 static Map createMap() => {}; | 54 static Map createMap() => {}; |
55 | 55 |
56 static makeUnimplementedError(String fileName, int lineNo) { | 56 static makeUnimplementedError(String fileName, int lineNo) { |
57 return new UnsupportedError('[info: $fileName:$lineNo]'); | 57 return new UnsupportedError('[info: $fileName:$lineNo]'); |
58 } | 58 } |
59 | 59 |
60 static window() native "Utils_window"; | 60 static window() native "Utils_window"; |
61 static print(String message) native "Utils_print"; | |
62 static forwardingPrint(String message) native "Utils_forwardingPrint"; | 61 static forwardingPrint(String message) native "Utils_forwardingPrint"; |
63 static void spawnDomFunction(Function topLevelFunction, int replyTo) native "U tils_spawnDomFunction"; | 62 static void spawnDomFunction(Function topLevelFunction, int replyTo) native "U tils_spawnDomFunction"; |
64 static int _getNewIsolateId() native "Utils_getNewIsolateId"; | 63 static int _getNewIsolateId() native "Utils_getNewIsolateId"; |
65 static bool shadowRootSupported(Document document) native "Utils_shadowRootSup ported"; | 64 static bool shadowRootSupported(Document document) native "Utils_shadowRootSup ported"; |
66 } | 65 } |
67 | 66 |
68 class _NPObject extends NativeFieldWrapperClass1 { | 67 class _NPObject extends NativeFieldWrapperClass1 { |
69 _NPObject.internal(); | 68 _NPObject.internal(); |
70 static _NPObject retrieve(String key) native "NPObject_retrieve"; | 69 static _NPObject retrieve(String key) native "NPObject_retrieve"; |
71 property(String propertyName) native "NPObject_property"; | 70 property(String propertyName) native "NPObject_property"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke y, ifAbsent); | 124 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke y, ifAbsent); |
126 String remove(String key) native "DOMStringMap_remove_Callback"; | 125 String remove(String key) native "DOMStringMap_remove_Callback"; |
127 void clear() => Maps.clear(this); | 126 void clear() => Maps.clear(this); |
128 void forEach(void f(String key, String value)) => Maps.forEach(this, f); | 127 void forEach(void f(String key, String value)) => Maps.forEach(this, f); |
129 Collection<String> get keys native "DOMStringMap_getKeys_Callback"; | 128 Collection<String> get keys native "DOMStringMap_getKeys_Callback"; |
130 Collection<String> get values => Maps.getValues(this); | 129 Collection<String> get values => Maps.getValues(this); |
131 int get length => Maps.length(this); | 130 int get length => Maps.length(this); |
132 bool get isEmpty => Maps.isEmpty(this); | 131 bool get isEmpty => Maps.isEmpty(this); |
133 } | 132 } |
134 | 133 |
135 get _printClosure => (s) { | 134 final Future<SendPort> _HELPER_ISOLATE_PORT = |
136 try { | 135 spawnDomFunction(_helperIsolateMain); |
137 window.console.log(s); | 136 |
138 } catch (_) { | 137 final _TIMER_REGISTRY = new Map<SendPort, Timer>(); |
139 _Utils.print(s); | 138 |
140 } | 139 const _NEW_TIMER = 'NEW_TIMER'; |
140 const _CANCEL_TIMER = 'CANCEL_TIMER'; | |
141 const _TIMER_PING = 'TIMER_PING'; | |
142 const _PRINT = 'PRINT'; | |
143 | |
144 _helperIsolateMain() { | |
145 port.receive((msg, replyTo) { | |
146 final cmd = msg[0]; | |
147 if (cmd == _NEW_TIMER) { | |
148 final duration = new Duration(milliseconds: msg[1]); | |
149 bool periodic = msg[2]; | |
150 final callback = () { replyTo.send(_TIMER_PING); }; | |
151 _TIMER_REGISTRY[replyTo] = periodic ? | |
152 new Timer.periodic(duration, callback) : | |
153 new Timer(duration, callback); | |
154 } else if (cmd == _CANCEL_TIMER) { | |
155 _TIMER_REGISTRY.remove(replyTo).cancel(); | |
156 } else if (cmd == _PRINT) { | |
157 final message = msg[1]; | |
158 // TODO(antonm): we need somehow identify those isolates. | |
159 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
| |
160 } | |
161 }); | |
162 } | |
163 | |
164 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
| |
165 final _pureIsolatePrintClosure = (s) { | |
166 _HELPER_ISOLATE_PORT.then((sendPort) { | |
167 sendPort.send([_PRINT, s]); | |
168 }); | |
141 }; | 169 }; |
142 | 170 |
143 final _forwardingPrintClosure = _Utils.forwardingPrint; | 171 final _forwardingPrintClosure = _Utils.forwardingPrint; |
OLD | NEW |