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

Side by Side Diff: lib/src/util/dart.dart

Issue 2269403002: Add a packageResolver parameter to runInIsolate(). (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Bump pubspec and changelog. Created 4 years, 3 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 | « CHANGELOG.md ('k') | pubspec.yaml » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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:async'; 5 import 'dart:async';
6 import 'dart:isolate'; 6 import 'dart:isolate';
7 7
8 import 'package:analyzer/analyzer.dart'; 8 import 'package:analyzer/analyzer.dart';
9 import 'package:package_resolver/package_resolver.dart';
9 import 'package:source_span/source_span.dart'; 10 import 'package:source_span/source_span.dart';
10 11
11 import 'string_literal_iterator.dart'; 12 import 'string_literal_iterator.dart';
12 13
13 /// Runs [code] in an isolate. 14 /// Runs [code] in an isolate.
14 /// 15 ///
15 /// [code] should be the contents of a Dart entrypoint. It may contain imports; 16 /// [code] should be the contents of a Dart entrypoint. It may contain imports;
16 /// they will be resolved in the same context as the host isolate. [message] is 17 /// they will be resolved in the same context as the host isolate. [message] is
17 /// passed to the [main] method of the code being run; the caller is responsible 18 /// passed to the [main] method of the code being run; the caller is responsible
18 /// for using this to establish communication with the isolate. 19 /// for using this to establish communication with the isolate.
19 Future<Isolate> runInIsolate(String code, message, {bool checked}) async { 20 ///
21 /// If [resolver] is passed, its package resolution strategy is used to resolve
22 /// code in the spawned isolate. It defaults to [PackageResolver.current].
23 Future<Isolate> runInIsolate(String code, message, {PackageResolver resolver,
24 bool checked}) async {
25 resolver ??= PackageResolver.current;
20 return await Isolate.spawnUri( 26 return await Isolate.spawnUri(
21 Uri.parse('data:application/dart;charset=utf-8,' + Uri.encodeFull(code)), 27 Uri.parse('data:application/dart;charset=utf-8,' + Uri.encodeFull(code)),
22 [], 28 [],
23 message, 29 message,
24 packageRoot: await Isolate.packageRoot, 30 packageRoot: await resolver.packageRoot,
25 packageConfig: await Isolate.packageConfig, 31 packageConfig: await resolver.packageConfigUri,
26 checked: checked); 32 checked: checked);
27 } 33 }
28 34
29 // TODO(nweiz): Move this into the analyzer once it starts using SourceSpan 35 // TODO(nweiz): Move this into the analyzer once it starts using SourceSpan
30 // (issue 22977). 36 // (issue 22977).
31 /// Takes a span whose source is the value of a string that has been parsed from 37 /// Takes a span whose source is the value of a string that has been parsed from
32 /// a Dart file and returns the corresponding span from within that Dart file. 38 /// a Dart file and returns the corresponding span from within that Dart file.
33 /// 39 ///
34 /// For example, suppose a Dart file contains `@Eval("1 + a")`. The 40 /// For example, suppose a Dart file contains `@Eval("1 + a")`. The
35 /// [StringLiteral] `"1 + a"` is extracted; this is [context]. Its contents are 41 /// [StringLiteral] `"1 + a"` is extracted; this is [context]. Its contents are
(...skipping 26 matching lines...) Expand all
62 } 68 }
63 69
64 var start = contextRunes.offset; 70 var start = contextRunes.offset;
65 for (var spanRune in span.text.runes) { 71 for (var spanRune in span.text.runes) {
66 if (spanRune != contextRunes.current) return null; 72 if (spanRune != contextRunes.current) return null;
67 contextRunes.moveNext(); 73 contextRunes.moveNext();
68 } 74 }
69 75
70 return file.span(start, contextRunes.offset); 76 return file.span(start, contextRunes.offset);
71 } 77 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698