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

Side by Side Diff: runtime/lib/isolate_patch.dart

Issue 1591573004: - Fix Isolate.spawn when running from snapshot. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Cleanup. Created 4 years, 11 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 | « runtime/lib/isolate.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 /* patch */ static Future<Uri> resolvePackageUri(Uri packageUri) { 293 /* patch */ static Future<Uri> resolvePackageUri(Uri packageUri) {
294 var hook = VMLibraryHooks.resolvePackageUriFuture; 294 var hook = VMLibraryHooks.resolvePackageUriFuture;
295 if (hook == null) { 295 if (hook == null) {
296 throw new UnsupportedError("Isolate.resolvePackageUri"); 296 throw new UnsupportedError("Isolate.resolvePackageUri");
297 } 297 }
298 return hook(packageUri); 298 return hook(packageUri);
299 } 299 }
300 300
301 static bool _packageSupported() => 301 static bool _packageSupported() =>
302 (VMLibraryHooks.packageRootUriFuture != null) && 302 (VMLibraryHooks.packageRootUriFuture != null) &&
303 (VMLibraryHooks.packageConfigUriFuture != null); 303 (VMLibraryHooks.packageConfigUriFuture != null) &&
304 (VMLibraryHooks.resolvePackageUriFuture != null);
304 305
305 /* patch */ static Future<Isolate> spawn( 306 /* patch */ static Future<Isolate> spawn(
306 void entryPoint(message), var message, 307 void entryPoint(message), var message,
307 {bool paused: false, bool errorsAreFatal, 308 {bool paused: false, bool errorsAreFatal,
308 SendPort onExit, SendPort onError}) async { 309 SendPort onExit, SendPort onError}) async {
309 // `paused` isn't handled yet. 310 // `paused` isn't handled yet.
310 RawReceivePort readyPort; 311 RawReceivePort readyPort;
311 try { 312 try {
312 // The VM will invoke [_startIsolate] with entryPoint as argument. 313 // The VM will invoke [_startIsolate] with entryPoint as argument.
313 readyPort = new RawReceivePort(); 314 readyPort = new RawReceivePort();
314 var packageRoot = null; 315 var packageRoot = null;
315 var packageConfig = null; 316 var packageConfig = null;
316 if (Isolate._packageSupported()) { 317 if (Isolate._packageSupported()) {
317 packageRoot = (await Isolate.packageRoot)?.toString(); 318 packageRoot = (await Isolate.packageRoot)?.toString();
318 packageConfig = (await Isolate.packageConfig)?.toString(); 319 packageConfig = (await Isolate.packageConfig)?.toString();
319 } 320 }
320 321
321 _spawnFunction(readyPort.sendPort, entryPoint, message, 322 var script = VMLibraryHooks.platformScript;
323 if (script != null) {
324 if (script.scheme == "package") {
325 script = await Isolate.resolvePackageUri(script);
326 }
327 }
328
329 _spawnFunction(readyPort.sendPort, script.toString(), entryPoint, message,
322 paused, errorsAreFatal, onExit, onError, 330 paused, errorsAreFatal, onExit, onError,
323 packageRoot, packageConfig); 331 packageRoot, packageConfig);
324 return await _spawnCommon(readyPort); 332 return await _spawnCommon(readyPort);
325 } catch (e, st) { 333 } catch (e, st) {
326 if (readyPort != null) { 334 if (readyPort != null) {
327 readyPort.close(); 335 readyPort.close();
328 } 336 }
329 return await new Future<Isolate>.error(e, st); 337 return await new Future<Isolate>.error(e, st);
330 } 338 }
331 } 339 }
(...skipping 26 matching lines...) Expand all
358 "automaticPackageResolution and specify a" 366 "automaticPackageResolution and specify a"
359 "packageConfig."); 367 "packageConfig.");
360 } 368 }
361 } else { 369 } else {
362 if ((packageRoot != null) && (packageConfig != null)) { 370 if ((packageRoot != null) && (packageConfig != null)) {
363 throw new ArgumentError("Cannot simultaneously specify a " 371 throw new ArgumentError("Cannot simultaneously specify a "
364 "packageRoot and a packageConfig."); 372 "packageRoot and a packageConfig.");
365 } 373 }
366 } 374 }
367 try { 375 try {
368 // Resolve the uri agains the current isolate's root Uri first. 376 // Resolve the uri against the current isolate's root Uri first.
369 var spawnedUri = _rootUri.resolveUri(uri); 377 var spawnedUri = _rootUri.resolveUri(uri);
370 378
371 // Inherit this isolate's package resolution setup if not overridden. 379 // Inherit this isolate's package resolution setup if not overridden.
372 if (!automaticPackageResolution && 380 if (!automaticPackageResolution &&
373 (packageRoot == null) && 381 (packageRoot == null) &&
374 (packageConfig == null)) { 382 (packageConfig == null)) {
375 if (Isolate._packageSupported()) { 383 if (Isolate._packageSupported()) {
376 packageRoot = await Isolate.packageRoot; 384 packageRoot = await Isolate.packageRoot;
377 packageConfig = await Isolate.packageConfig; 385 packageConfig = await Isolate.packageConfig;
378 } 386 }
379 } 387 }
380 388
381 // Ensure to resolve package: URIs being handed in as parameters. 389 // Ensure to resolve package: URIs being handed in as parameters.
382 packageRoot = (packageRoot == null) ? null : 390 if (packageRoot != null) {
383 await Isolate.resolvePackageUri(packageRoot); 391 // Avoid calling resolvePackageUri if not stricly necessary in case
384 packageConfig = (packageConfig == null) ? null : 392 // the API is not supported.
385 await Isolate.resolvePackageUri(packageConfig); 393 if (packageRoot.scheme == "package") {
394 packageRoot = await Isolate.resolvePackageUri(packageRoot);
395 }
396 } else if (packageConfig != null) {
397 // Avoid calling resolvePackageUri if not strictly necessary in case
398 // the API is not supported.
399 if (packageConfig.scheme == "package") {
400 packageConfig = await Isolate.resolvePackageUri(packageConfig);
401 }
402 }
386 403
387 // The VM will invoke [_startIsolate] and not `main`. 404 // The VM will invoke [_startIsolate] and not `main`.
388 readyPort = new RawReceivePort(); 405 readyPort = new RawReceivePort();
389 var packageRootString = packageRoot?.toString(); 406 var packageRootString = packageRoot?.toString();
390 var packageConfigString = packageConfig?.toString(); 407 var packageConfigString = packageConfig?.toString();
391 408
392 _spawnUri(readyPort.sendPort, spawnedUri.toString(), 409 _spawnUri(readyPort.sendPort, spawnedUri.toString(),
393 args, message, 410 args, message,
394 paused, onExit, onError, 411 paused, onExit, onError,
395 errorsAreFatal, checked, 412 errorsAreFatal, checked,
396 null, /* environment */ 413 null, /* environment */
397 packageRootString, packageConfigString); 414 packageRootString, packageConfigString);
398 return await _spawnCommon(readyPort); 415 return await _spawnCommon(readyPort);
399 } catch (e, st) { 416 } catch (e, st) {
400 if (readyPort != null) { 417 if (readyPort != null) {
401 readyPort.close(); 418 readyPort.close();
402 } 419 }
403 return await new Future<Isolate>.error(e, st); 420 rethrow;
404 } 421 }
405 } 422 }
406 423
407 static Future<Isolate> _spawnCommon(RawReceivePort readyPort) { 424 static Future<Isolate> _spawnCommon(RawReceivePort readyPort) {
408 Completer completer = new Completer<Isolate>.sync(); 425 Completer completer = new Completer<Isolate>.sync();
409 readyPort.handler = (readyMessage) { 426 readyPort.handler = (readyMessage) {
410 readyPort.close(); 427 readyPort.close();
411 if (readyMessage is List && readyMessage.length == 2) { 428 if (readyMessage is List && readyMessage.length == 2) {
412 SendPort controlPort = readyMessage[0]; 429 SendPort controlPort = readyMessage[0];
413 List capabilities = readyMessage[1]; 430 List capabilities = readyMessage[1];
(...skipping 21 matching lines...) Expand all
435 static const _RESUME = 2; 452 static const _RESUME = 2;
436 static const _PING = 3; 453 static const _PING = 3;
437 static const _KILL = 4; 454 static const _KILL = 4;
438 static const _ADD_EXIT = 5; 455 static const _ADD_EXIT = 5;
439 static const _DEL_EXIT = 6; 456 static const _DEL_EXIT = 6;
440 static const _ADD_ERROR = 7; 457 static const _ADD_ERROR = 7;
441 static const _DEL_ERROR = 8; 458 static const _DEL_ERROR = 8;
442 static const _ERROR_FATAL = 9; 459 static const _ERROR_FATAL = 9;
443 460
444 461
445 static void _spawnFunction(SendPort readyPort, Function topLevelFunction, 462 static void _spawnFunction(SendPort readyPort, String uri,
463 Function topLevelFunction,
446 var message, bool paused, bool errorsAreFatal, 464 var message, bool paused, bool errorsAreFatal,
447 SendPort onExit, SendPort onError, 465 SendPort onExit, SendPort onError,
448 String packageRoot, String packageConfig) 466 String packageRoot, String packageConfig)
449 native "Isolate_spawnFunction"; 467 native "Isolate_spawnFunction";
450 468
451 static void _spawnUri(SendPort readyPort, String uri, 469 static void _spawnUri(SendPort readyPort, String uri,
452 List<String> args, var message, 470 List<String> args, var message,
453 bool paused, SendPort onExit, SendPort onError, 471 bool paused, SendPort onExit, SendPort onError,
454 bool errorsAreFatal, bool checked, 472 bool errorsAreFatal, bool checked,
455 List environment, 473 List environment,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 try { 571 try {
554 return Uri.parse(_getCurrentRootUriStr()); 572 return Uri.parse(_getCurrentRootUriStr());
555 } catch (e, s) { 573 } catch (e, s) {
556 return null; 574 return null;
557 } 575 }
558 } 576 }
559 577
560 static String _getCurrentRootUriStr() 578 static String _getCurrentRootUriStr()
561 native "Isolate_getCurrentRootUriStr"; 579 native "Isolate_getCurrentRootUriStr";
562 } 580 }
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698