| 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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
| 6 import "dart:_internal"; | 6 import "dart:_internal"; |
| 7 | 7 |
| 8 @patch class ReceivePort { | 8 @patch class ReceivePort { |
| 9 @patch factory ReceivePort() = _ReceivePortImpl; | 9 @patch factory ReceivePort() = _ReceivePortImpl; |
| 10 | 10 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 186 } |
| 187 | 187 |
| 188 /*--- private implementation ---*/ | 188 /*--- private implementation ---*/ |
| 189 _get_id() native "SendPortImpl_get_id"; | 189 _get_id() native "SendPortImpl_get_id"; |
| 190 _get_hashcode() native "SendPortImpl_get_hashcode"; | 190 _get_hashcode() native "SendPortImpl_get_hashcode"; |
| 191 | 191 |
| 192 // Forward the implementation of sending messages to the VM. | 192 // Forward the implementation of sending messages to the VM. |
| 193 void _sendInternal(var message) native "SendPortImpl_sendInternal_"; | 193 void _sendInternal(var message) native "SendPortImpl_sendInternal_"; |
| 194 } | 194 } |
| 195 | 195 |
| 196 typedef _MainFunction(); | 196 typedef _NullaryFunction(); |
| 197 typedef _MainFunctionArgs(args); | 197 typedef _UnaryFunction(args); |
| 198 typedef _MainFunctionArgsMessage(args, message); | 198 typedef _BinaryFunction(args, message); |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * Takes the real entry point as argument and invokes it with the | 201 * Takes the real entry point as argument and invokes it with the |
| 202 * initial message. Defers execution of the entry point until the | 202 * initial message. Defers execution of the entry point until the |
| 203 * isolate is in the message loop. | 203 * isolate is in the message loop. |
| 204 */ | 204 */ |
| 205 void _startMainIsolate(Function entryPoint, | 205 void _startMainIsolate(Function entryPoint, |
| 206 List<String> args) { | 206 List<String> args) { |
| 207 _startIsolate(null, // no parent port | 207 _startIsolate(null, // no parent port |
| 208 entryPoint, | 208 entryPoint, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 assert(capabilities == null); | 246 assert(capabilities == null); |
| 247 | 247 |
| 248 // Delay all user code handling to the next run of the message loop. This | 248 // Delay all user code handling to the next run of the message loop. This |
| 249 // allows us to intercept certain conditions in the event dispatch, such as | 249 // allows us to intercept certain conditions in the event dispatch, such as |
| 250 // starting in paused state. | 250 // starting in paused state. |
| 251 RawReceivePort port = new RawReceivePort(); | 251 RawReceivePort port = new RawReceivePort(); |
| 252 port.handler = (_) { | 252 port.handler = (_) { |
| 253 port.close(); | 253 port.close(); |
| 254 | 254 |
| 255 if (isSpawnUri) { | 255 if (isSpawnUri) { |
| 256 if (entryPoint is _MainFunctionArgsMessage) { | 256 if (entryPoint is _BinaryFunction) { |
| 257 entryPoint(args, message); | 257 entryPoint(args, message); |
| 258 } else if (entryPoint is _MainFunctionArgs) { | 258 } else if (entryPoint is _UnaryFunction) { |
| 259 entryPoint(args); | 259 entryPoint(args); |
| 260 } else { | 260 } else { |
| 261 entryPoint(); | 261 entryPoint(); |
| 262 } | 262 } |
| 263 } else { | 263 } else { |
| 264 entryPoint(message); | 264 entryPoint(message); |
| 265 } | 265 } |
| 266 }; | 266 }; |
| 267 // Make sure the message handler is triggered. | 267 // Make sure the message handler is triggered. |
| 268 port.sendPort.send(null); | 268 port.sendPort.send(null); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 (VMLibraryHooks.packageConfigUriFuture != null) && | 303 (VMLibraryHooks.packageConfigUriFuture != null) && |
| 304 (VMLibraryHooks.resolvePackageUriFuture != null); | 304 (VMLibraryHooks.resolvePackageUriFuture != null); |
| 305 | 305 |
| 306 @patch static Future<Isolate> spawn( | 306 @patch static Future<Isolate> spawn( |
| 307 void entryPoint(message), var message, | 307 void entryPoint(message), var message, |
| 308 {bool paused: false, bool errorsAreFatal, | 308 {bool paused: false, bool errorsAreFatal, |
| 309 SendPort onExit, SendPort onError}) async { | 309 SendPort onExit, SendPort onError}) async { |
| 310 // `paused` isn't handled yet. | 310 // `paused` isn't handled yet. |
| 311 RawReceivePort readyPort; | 311 RawReceivePort readyPort; |
| 312 try { | 312 try { |
| 313 // Check for the type of `entryPoint` on the spawning isolate to make |
| 314 // error-handling easier. |
| 315 if (entryPoint is! _UnaryFunction) { |
| 316 throw new ArgumentError(entryPoint); |
| 317 } |
| 313 // The VM will invoke [_startIsolate] with entryPoint as argument. | 318 // The VM will invoke [_startIsolate] with entryPoint as argument. |
| 314 readyPort = new RawReceivePort(); | 319 readyPort = new RawReceivePort(); |
| 315 | 320 |
| 316 // We do not inherit the package root or package config settings | 321 // We do not inherit the package root or package config settings |
| 317 // from the parent isolate, instead we use the values that were | 322 // from the parent isolate, instead we use the values that were |
| 318 // set on the command line. | 323 // set on the command line. |
| 319 var packageRoot = VMLibraryHooks.packageRootString; | 324 var packageRoot = VMLibraryHooks.packageRootString; |
| 320 var packageConfig = VMLibraryHooks.packageConfigString; | 325 var packageConfig = VMLibraryHooks.packageConfigString; |
| 321 var script = VMLibraryHooks.platformScript; | 326 var script = VMLibraryHooks.platformScript; |
| 322 if (script == null) { | 327 if (script == null) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 try { | 578 try { |
| 574 return Uri.parse(_getCurrentRootUriStr()); | 579 return Uri.parse(_getCurrentRootUriStr()); |
| 575 } catch (e, s) { | 580 } catch (e, s) { |
| 576 return null; | 581 return null; |
| 577 } | 582 } |
| 578 } | 583 } |
| 579 | 584 |
| 580 static String _getCurrentRootUriStr() | 585 static String _getCurrentRootUriStr() |
| 581 native "Isolate_getCurrentRootUriStr"; | 586 native "Isolate_getCurrentRootUriStr"; |
| 582 } | 587 } |
| OLD | NEW |