| 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 builtin; | 5 library builtin; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 // import 'root_library'; happens here from C Code | 9 // import 'root_library'; happens here from C Code |
| 10 | 10 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 var baseUri = Uri.parse(base); | 156 var baseUri = Uri.parse(base); |
| 157 if (userString.startsWith(_DART_EXT)) { | 157 if (userString.startsWith(_DART_EXT)) { |
| 158 var uri = userString.substring(_DART_EXT.length); | 158 var uri = userString.substring(_DART_EXT.length); |
| 159 return '$_DART_EXT${baseUri.resolve(uri)}'; | 159 return '$_DART_EXT${baseUri.resolve(uri)}'; |
| 160 } else { | 160 } else { |
| 161 return baseUri.resolve(userString).toString(); | 161 return baseUri.resolve(userString).toString(); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 // Returns either a file path or a URI starting with http:, as a String. | 166 // Returns either a file path or a URI starting with http[s]:, as a String. |
| 167 String _filePathFromUri(String userUri) { | 167 String _filePathFromUri(String userUri) { |
| 168 var uri = Uri.parse(userUri); | 168 var uri = Uri.parse(userUri); |
| 169 if (_logBuiltin) { | 169 if (_logBuiltin) { |
| 170 _print('# Getting file path from: $uri'); | 170 _print('# Getting file path from: $uri'); |
| 171 } | 171 } |
| 172 | 172 |
| 173 var path; | 173 var path; |
| 174 switch (uri.scheme) { | 174 switch (uri.scheme) { |
| 175 case '': | 175 case '': |
| 176 case 'file': | 176 case 'file': |
| 177 return uri.toFilePath(); | 177 return uri.toFilePath(); |
| 178 case 'package': | 178 case 'package': |
| 179 return _filePathFromUri(_resolvePackageUri(uri).toString()); | 179 return _filePathFromUri(_resolvePackageUri(uri).toString()); |
| 180 case 'http': | 180 case 'http': |
| 181 case 'https': |
| 181 return uri.toString(); | 182 return uri.toString(); |
| 182 default: | 183 default: |
| 183 // Only handling file, http, and package URIs | 184 // Only handling file, http, and package URIs |
| 184 // in standalone binary. | 185 // in standalone binary. |
| 185 if (_logBuiltin) { | 186 if (_logBuiltin) { |
| 186 _print('# Unknown scheme (${uri.scheme}) in $uri.'); | 187 _print('# Unknown scheme (${uri.scheme}) in $uri.'); |
| 187 } | 188 } |
| 188 throw 'Not a known scheme: $uri'; | 189 throw 'Not a known scheme: $uri'; |
| 189 } | 190 } |
| 190 } | 191 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 Uri _createUri(String userUri) { | 295 Uri _createUri(String userUri) { |
| 295 var uri = Uri.parse(userUri); | 296 var uri = Uri.parse(userUri); |
| 296 if (_logBuiltin) { | 297 if (_logBuiltin) { |
| 297 _print('# Creating uri for: $uri'); | 298 _print('# Creating uri for: $uri'); |
| 298 } | 299 } |
| 299 | 300 |
| 300 switch (uri.scheme) { | 301 switch (uri.scheme) { |
| 301 case '': | 302 case '': |
| 302 case 'file': | 303 case 'file': |
| 303 case 'http': | 304 case 'http': |
| 305 case 'https': |
| 304 return uri; | 306 return uri; |
| 305 case 'package': | 307 case 'package': |
| 306 return _resolvePackageUri(uri); | 308 return _resolvePackageUri(uri); |
| 307 default: | 309 default: |
| 308 // Only handling file, http, and package URIs | 310 // Only handling file, http[s], and package URIs |
| 309 // in standalone binary. | 311 // in standalone binary. |
| 310 if (_logBuiltin) { | 312 if (_logBuiltin) { |
| 311 _print('# Unknown scheme (${uri.scheme}) in $uri.'); | 313 _print('# Unknown scheme (${uri.scheme}) in $uri.'); |
| 312 } | 314 } |
| 313 throw 'Not a known scheme: $uri'; | 315 throw 'Not a known scheme: $uri'; |
| 314 } | 316 } |
| 315 } | 317 } |
| 316 | 318 |
| 317 | 319 |
| 318 // Asynchronously loads script data through a http or file uri. | 320 // Asynchronously loads script data through a http[s] or file uri. |
| 319 _loadDataAsync(int tag, String uri, String libraryUri) { | 321 _loadDataAsync(int tag, String uri, String libraryUri) { |
| 320 if (tag == null) { | 322 if (tag == null) { |
| 321 uri = _resolveScriptUri(uri); | 323 uri = _resolveScriptUri(uri); |
| 322 } | 324 } |
| 323 Uri resourceUri = _createUri(uri); | 325 Uri resourceUri = _createUri(uri); |
| 324 _numOutstandingLoadRequests++; | 326 _numOutstandingLoadRequests++; |
| 325 if (_logBuiltin) { | 327 if (_logBuiltin) { |
| 326 _print("_loadDataAsync($uri), " | 328 _print("_loadDataAsync($uri), " |
| 327 "${_numOutstandingLoadRequests} requests outstanding"); | 329 "${_numOutstandingLoadRequests} requests outstanding"); |
| 328 } | 330 } |
| 329 if (resourceUri.scheme == 'http') { | 331 if ((resourceUri.scheme == 'http') || (resourceUri.scheme == 'https')) { |
| 330 _httpGet(resourceUri, libraryUri, (data) { | 332 _httpGet(resourceUri, libraryUri, (data) { |
| 331 _loadScript(tag, uri, libraryUri, data); | 333 _loadScript(tag, uri, libraryUri, data); |
| 332 }); | 334 }); |
| 333 } else { | 335 } else { |
| 334 var sourceFile = new File(resourceUri.toFilePath()); | 336 var sourceFile = new File(resourceUri.toFilePath()); |
| 335 sourceFile.readAsBytes().then((data) { | 337 sourceFile.readAsBytes().then((data) { |
| 336 _loadScript(tag, uri, libraryUri, data); | 338 _loadScript(tag, uri, libraryUri, data); |
| 337 }, | 339 }, |
| 338 onError: (e) { | 340 onError: (e) { |
| 339 _asyncLoadError(uri, libraryUri, e); | 341 _asyncLoadError(uri, libraryUri, e); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 filename = '$name.dll'; | 382 filename = '$name.dll'; |
| 381 } else { | 383 } else { |
| 382 if (_logBuiltin) { | 384 if (_logBuiltin) { |
| 383 _print('Native extensions not supported on ${Platform.operatingSystem}'); | 385 _print('Native extensions not supported on ${Platform.operatingSystem}'); |
| 384 } | 386 } |
| 385 throw 'Native extensions not supported on ${Platform.operatingSystem}'; | 387 throw 'Native extensions not supported on ${Platform.operatingSystem}'; |
| 386 } | 388 } |
| 387 | 389 |
| 388 return [path, filename, name]; | 390 return [path, filename, name]; |
| 389 } | 391 } |
| OLD | NEW |