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 library _isolate_helper; | 5 library _isolate_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection' show Queue, HashMap; | 8 import 'dart:collection' show Queue, HashMap; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:_js_helper' show | 10 import 'dart:_js_helper' show |
| 11 Closure, | 11 Closure, |
| 12 Null, | 12 Null, |
| 13 Primitives, | 13 Primitives, |
| 14 convertDartClosureToJS; | 14 convertDartClosureToJS; |
| 15 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, | 15 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, |
| 16 JS, | 16 JS, |
| 17 JS_CREATE_ISOLATE, | 17 JS_CREATE_ISOLATE, |
| 18 JS_CURRENT_ISOLATE_CONTEXT, | 18 JS_CURRENT_ISOLATE_CONTEXT, |
| 19 JS_CURRENT_ISOLATE, | 19 JS_CURRENT_ISOLATE, |
| 20 JS_SET_CURRENT_ISOLATE, | 20 JS_SET_CURRENT_ISOLATE, |
| 21 IsolateContext; | 21 IsolateContext; |
| 22 import 'dart:_interceptors' show JSExtendableArray; | 22 import 'dart:_interceptors' show JSExtendableArray; |
| 23 | 23 |
| 24 ReceivePort controlPort; | 24 ReceivePort controlPort; |
| 25 | 25 |
| 26 class IsolateDeserializationError extends Error { | |
| 27 final String _message; | |
| 28 IsolateDeserializationError(this._message); | |
| 29 | |
| 30 toString() => "IsolateDeserializationError: $_message"; | |
| 31 } | |
| 32 | |
| 26 /** | 33 /** |
| 27 * Called by the compiler to support switching | 34 * Called by the compiler to support switching |
| 28 * between isolates when we get a callback from the DOM. | 35 * between isolates when we get a callback from the DOM. |
| 29 */ | 36 */ |
| 30 _callInIsolate(_IsolateContext isolate, Function function) { | 37 _callInIsolate(_IsolateContext isolate, Function function) { |
| 31 var result = isolate.eval(function); | 38 var result = isolate.eval(function); |
| 32 _globalState.topEventLoop.run(); | 39 _globalState.topEventLoop.run(); |
| 33 return result; | 40 return result; |
| 34 } | 41 } |
| 35 | 42 |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 // Overridable fallback. | 1077 // Overridable fallback. |
| 1071 return visitObject(x); | 1078 return visitObject(x); |
| 1072 } | 1079 } |
| 1073 | 1080 |
| 1074 visitPrimitive(x); | 1081 visitPrimitive(x); |
| 1075 visitList(List x); | 1082 visitList(List x); |
| 1076 visitMap(Map x); | 1083 visitMap(Map x); |
| 1077 visitSendPort(SendPort x); | 1084 visitSendPort(SendPort x); |
| 1078 | 1085 |
| 1079 visitObject(Object x) { | 1086 visitObject(Object x) { |
| 1080 // TODO(floitsch): make this a real exception. (which one)? | 1087 throw new IsolateMessageException("Illegal value $x passed"); |
|
Lasse Reichstein Nielsen
2013/12/11 10:38:28
Could we put the value of x into the object?
If th
floitsch
2013/12/11 12:14:16
Yes. I would like that.
The problem is that it wou
| |
| 1081 throw "Message serialization: Illegal value $x passed"; | |
| 1082 } | 1088 } |
| 1083 | 1089 |
| 1084 static bool isPrimitive(x) { | 1090 static bool isPrimitive(x) { |
| 1085 return (x == null) || (x is String) || (x is num) || (x is bool); | 1091 return (x == null) || (x is String) || (x is num) || (x is bool); |
| 1086 } | 1092 } |
| 1087 } | 1093 } |
| 1088 | 1094 |
| 1089 | 1095 |
| 1090 /** A visitor that recursively copies a message. */ | 1096 /** A visitor that recursively copies a message. */ |
| 1091 class _Copier extends _MessageTraverser { | 1097 class _Copier extends _MessageTraverser { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 var key = _deserializeHelper(keys[i]); | 1232 var key = _deserializeHelper(keys[i]); |
| 1227 var value = _deserializeHelper(values[i]); | 1233 var value = _deserializeHelper(values[i]); |
| 1228 result[key] = value; | 1234 result[key] = value; |
| 1229 } | 1235 } |
| 1230 return result; | 1236 return result; |
| 1231 } | 1237 } |
| 1232 | 1238 |
| 1233 deserializeSendPort(List x); | 1239 deserializeSendPort(List x); |
| 1234 | 1240 |
| 1235 deserializeObject(List x) { | 1241 deserializeObject(List x) { |
| 1236 // TODO(floitsch): Use real exception (which one?). | 1242 throw new IsolateDeserializationError("Unexpected serialized object"); |
|
Lasse Reichstein Nielsen
2013/12/11 10:38:28
How does this error occur?
It happens during dese
floitsch
2013/12/11 12:14:16
It's a sanity check, and could happen once we have
| |
| 1237 throw "Unexpected serialized object"; | |
| 1238 } | 1243 } |
| 1239 } | 1244 } |
| 1240 | 1245 |
| 1241 class TimerImpl implements Timer { | 1246 class TimerImpl implements Timer { |
| 1242 final bool _once; | 1247 final bool _once; |
| 1243 bool _inEventLoop = false; | 1248 bool _inEventLoop = false; |
| 1244 int _handle; | 1249 int _handle; |
| 1245 | 1250 |
| 1246 TimerImpl(int milliseconds, void callback()) | 1251 TimerImpl(int milliseconds, void callback()) |
| 1247 : _once = true { | 1252 : _once = true { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1312 _handle = null; | 1317 _handle = null; |
| 1313 } else { | 1318 } else { |
| 1314 throw new UnsupportedError("Canceling a timer."); | 1319 throw new UnsupportedError("Canceling a timer."); |
| 1315 } | 1320 } |
| 1316 } | 1321 } |
| 1317 | 1322 |
| 1318 bool get isActive => _handle != null; | 1323 bool get isActive => _handle != null; |
| 1319 } | 1324 } |
| 1320 | 1325 |
| 1321 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; | 1326 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; |
| OLD | NEW |