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

Side by Side Diff: runtime/bin/builtin.dart

Issue 983713002: Remove 'dart:io' import in builtin.dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/builtin_natives.cc » ('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 library builtin; 5 library builtin;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:isolate'; 8 import 'dart:isolate';
Ivan Posva 2015/03/05 17:58:36 Please make a note here to NOT import dart:io.
Cutch 2015/03/06 00:02:18 Done.
9 9
10 10
11 //////////////////////
12 /* Support for loading within the isolate via dart:io */
13 import 'dart:io';
14
15 // Enable by setting the #define LOAD_VIA_SERVICE_ISOLATE (see dartutils.cc)
16 bool _load_via_service_isolate = false;
17
18 var _httpClient;
19 void _httpGet(int tag,
20 Uri uri,
21 String libraryUri,
22 loadCallback(List<int> data)) {
23 if (_httpClient == null) {
24 _httpClient = new HttpClient()..maxConnectionsPerHost = 6;
25 }
26 _httpClient.getUrl(uri)
27 .then((HttpClientRequest request) => request.close())
28 .then((HttpClientResponse response) {
29 var builder = new BytesBuilder(copy: false);
30 response.listen(
31 builder.add,
32 onDone: () {
33 if (response.statusCode != 200) {
34 var msg = 'Failure getting $uri: '
35 '${response.statusCode} ${response.reasonPhrase}';
36 _asyncLoadError(tag, uri.toString(), libraryUri, msg);
37 }
38 loadCallback(builder.takeBytes());
39 },
40 onError: (error) {
41 _asyncLoadError(tag, uri.toString(), libraryUri, error);
42 });
43 })
44 .catchError((error) {
45 _asyncLoadError(tag, uri.toString(), libraryUri, error);
46 });
47 // TODO(floitsch): remove this line. It's just here to push an event on the
48 // event loop so that we invoke the scheduled microtasks. Also remove the
49 // import of dart:async when this line is not needed anymore.
50 Timer.run(() {});
51 }
52
53
54 void _cleanup() {
55 if (_httpClient != null) {
56 _httpClient.close();
57 _httpClient = null;
58 }
59 }
60
61 _loadDataAsyncDartIO(int tag,
62 String uri,
63 String libraryUri,
64 Uri resourceUri) {
65 _startingOneLoadRequest(uri);
66 if ((resourceUri.scheme == 'http') || (resourceUri.scheme == 'https')) {
67 _httpGet(tag, resourceUri, libraryUri, (data) {
68 _loadScript(tag, uri, libraryUri, data);
69 });
70 } else {
71 var sourceFile = new File(resourceUri.toFilePath());
72 sourceFile.readAsBytes().then((data) {
73 _loadScript(tag, uri, libraryUri, data);
74 },
75 onError: (e) {
76 _asyncLoadError(tag, uri, libraryUri, e);
77 });
78 }
79 }
80
81 //////////////////////
82
83 /* See Dart_LibraryTag in dart_api.h */ 11 /* See Dart_LibraryTag in dart_api.h */
84 const Dart_kScriptTag = null; 12 const Dart_kScriptTag = null;
85 const Dart_kImportTag = 0; 13 const Dart_kImportTag = 0;
86 const Dart_kSourceTag = 1; 14 const Dart_kSourceTag = 1;
87 const Dart_kCanonicalizeUrl = 2; 15 const Dart_kCanonicalizeUrl = 2;
88 16
89 // Dart native extension scheme. 17 // Dart native extension scheme.
90 const _DART_EXT = 'dart-ext:'; 18 const _DART_EXT = 'dart-ext:';
91 19
92 // import 'root_library'; happens here from C Code 20 // import 'root_library'; happens here from C Code
(...skipping 12 matching lines...) Expand all
105 void _print(arg) { 33 void _print(arg) {
106 _Logger._printString(arg.toString()); 34 _Logger._printString(arg.toString());
107 } 35 }
108 36
109 class _Logger { 37 class _Logger {
110 static void _printString(String s) native "Logger_PrintString"; 38 static void _printString(String s) native "Logger_PrintString";
111 } 39 }
112 40
113 _getPrintClosure() => _print; 41 _getPrintClosure() => _print;
114 42
115 _getCurrentDirectoryPath() native "Directory_Current"; 43 _getCurrentDirectoryPath() native "Builtin_GetCurrentDirectory";
116 44
117 // Corelib 'Uri.base' implementation. 45 // Corelib 'Uri.base' implementation.
118 Uri _uriBase() { 46 Uri _uriBase() {
119 // We are not using Dircetory.current here to limit the dependency 47 // We are not using Dircetory.current here to limit the dependency
120 // on dart:io. This code is the same as: 48 // on dart:io. This code is the same as:
121 // return new Uri.file(Directory.current.path + "/"); 49 // return new Uri.file(Directory.current.path + "/");
122 var result = _getCurrentDirectoryPath(); 50 var result = _getCurrentDirectoryPath();
123 if (result is OSError) {
124 throw new FileSystemException(
125 "Getting current working directory failed", "", result);
126 }
127 return new Uri.file(result + "/"); 51 return new Uri.file(result + "/");
128 } 52 }
129 53
130 _getUriBaseClosure() => _uriBase; 54 _getUriBaseClosure() => _uriBase;
131 55
132 56
133 // Are we running on Windows? 57 // Are we running on Windows?
134 var _isWindows; 58 var _isWindows;
135 var _workingWindowsDrivePrefix; 59 var _workingWindowsDrivePrefix;
136 // The current working directory 60 // The current working directory
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 int _numOutstandingLoadRequests = 0; 233 int _numOutstandingLoadRequests = 0;
310 void _finishedOneLoadRequest(String uri) { 234 void _finishedOneLoadRequest(String uri) {
311 assert(_numOutstandingLoadRequests > 0); 235 assert(_numOutstandingLoadRequests > 0);
312 _numOutstandingLoadRequests--; 236 _numOutstandingLoadRequests--;
313 if (_logBuiltin) { 237 if (_logBuiltin) {
314 _print("Loading of $uri finished, " 238 _print("Loading of $uri finished, "
315 "${_numOutstandingLoadRequests} requests remaining"); 239 "${_numOutstandingLoadRequests} requests remaining");
316 } 240 }
317 if (_numOutstandingLoadRequests == 0) { 241 if (_numOutstandingLoadRequests == 0) {
318 _signalDoneLoading(); 242 _signalDoneLoading();
319 _cleanup();
320 } 243 }
321 } 244 }
322 245
323 void _startingOneLoadRequest(String uri) { 246 void _startingOneLoadRequest(String uri) {
324 assert(_numOutstandingLoadRequests >= 0); 247 assert(_numOutstandingLoadRequests >= 0);
325 _numOutstandingLoadRequests++; 248 _numOutstandingLoadRequests++;
326 if (_logBuiltin) { 249 if (_logBuiltin) {
327 _print("Loading of $uri started, " 250 _print("Loading of $uri started, "
328 "${_numOutstandingLoadRequests} requests outstanding"); 251 "${_numOutstandingLoadRequests} requests outstanding");
329 } 252 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 316 }
394 317
395 // Asynchronously loads script data through a http[s] or file uri. 318 // Asynchronously loads script data through a http[s] or file uri.
396 _loadDataAsync(int tag, String uri, String libraryUri) { 319 _loadDataAsync(int tag, String uri, String libraryUri) {
397 if (tag == Dart_kScriptTag) { 320 if (tag == Dart_kScriptTag) {
398 uri = _resolveScriptUri(uri); 321 uri = _resolveScriptUri(uri);
399 } 322 }
400 323
401 Uri resourceUri = _createUri(uri); 324 Uri resourceUri = _createUri(uri);
402 325
403 if (_load_via_service_isolate) { 326 _loadDataAsyncLoadPort(tag, uri, libraryUri, resourceUri);
404 _loadDataAsyncLoadPort(tag, uri, libraryUri, resourceUri);
405 } else {
406 _loadDataAsyncDartIO(tag, uri, libraryUri, resourceUri);
407 }
408
409 } 327 }
410 328
411 // Returns either a file path or a URI starting with http[s]:, as a String. 329 // Returns either a file path or a URI starting with http[s]:, as a String.
412 String _filePathFromUri(String userUri) { 330 String _filePathFromUri(String userUri) {
413 var uri = Uri.parse(userUri); 331 var uri = Uri.parse(userUri);
414 if (_logBuiltin) { 332 if (_logBuiltin) {
415 _print('# Getting file path from: $uri'); 333 _print('# Getting file path from: $uri');
416 } 334 }
417 335
418 var path; 336 var path;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } else { 392 } else {
475 name = userUri.substring(index + 1); 393 name = userUri.substring(index + 1);
476 path = userUri.substring(0, index + 1); 394 path = userUri.substring(0, index + 1);
477 } 395 }
478 396
479 path = _filePathFromUri(path); 397 path = _filePathFromUri(path);
480 var filename = _platformExtensionFileName(name); 398 var filename = _platformExtensionFileName(name);
481 399
482 return [path, filename, name]; 400 return [path, filename, name];
483 } 401 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/builtin_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698