| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 Dart_Handle result = failed ? Dart_NewApiError(result_string) : | 263 Dart_Handle result = failed ? Dart_NewApiError(result_string) : |
| 264 DartUtils::NewString(result_string); | 264 DartUtils::NewString(result_string); |
| 265 free(result_string); | 265 free(result_string); |
| 266 return result; | 266 return result; |
| 267 } | 267 } |
| 268 | 268 |
| 269 | 269 |
| 270 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
| 271 if (DartUtils::IsDartBuiltinLibURL(url)) { |
| 272 return Builtin::kBuiltinLibrary; |
| 273 } |
| 274 if (DartUtils::IsDartIOLibURL(url)) { |
| 275 return Builtin::kIOLibrary; |
| 276 } |
| 277 return Builtin::kInvalidLibrary; |
| 278 } |
| 279 |
| 280 |
| 270 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 281 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
| 271 Dart_Handle library, | 282 Dart_Handle library, |
| 272 Dart_Handle url) { | 283 Dart_Handle url) { |
| 273 if (!Dart_IsLibrary(library)) { | 284 if (!Dart_IsLibrary(library)) { |
| 274 return Dart_Error("not a library"); | 285 return Dart_Error("not a library"); |
| 275 } | 286 } |
| 276 Dart_Handle library_url = Dart_LibraryUrl(library); | 287 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 277 if (Dart_IsError(library_url)) { | 288 if (Dart_IsError(library_url)) { |
| 278 return Dart_Error("accessing library url failed"); | 289 return Dart_Error("accessing library url failed"); |
| 279 } | 290 } |
| 280 const char* library_url_string = DartUtils::GetStringValue(library_url); | 291 const char* library_url_string = DartUtils::GetStringValue(library_url); |
| 281 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( | 292 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( |
| 282 url_mapping, library_url_string); | 293 url_mapping, library_url_string); |
| 283 if (mapped_library_url_string != NULL) { | 294 if (mapped_library_url_string != NULL) { |
| 284 library_url = ResolveScriptUri(mapped_library_url_string); | 295 library_url = ResolveScriptUri(mapped_library_url_string); |
| 285 library_url_string = DartUtils::GetStringValue(library_url); | 296 library_url_string = DartUtils::GetStringValue(library_url); |
| 286 } | 297 } |
| 287 | 298 |
| 288 if (!Dart_IsString(url)) { | 299 if (!Dart_IsString(url)) { |
| 289 return Dart_Error("url is not a string"); | 300 return Dart_Error("url is not a string"); |
| 290 } | 301 } |
| 291 const char* url_string = DartUtils::GetStringValue(url); | 302 const char* url_string = DartUtils::GetStringValue(url); |
| 292 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_mapping, | 303 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_mapping, |
| 293 url_string); | 304 url_string); |
| 294 | 305 |
| 306 Builtin::BuiltinLibraryId libraryBuiltinId = BuiltinId(library_url_string); |
| 295 if (tag == kCanonicalizeUrl) { | 307 if (tag == kCanonicalizeUrl) { |
| 296 // Keep original names for libraries that have a mapping (e.g. dart:io). | |
| 297 if (mapped_url_string) { | 308 if (mapped_url_string) { |
| 298 return url; | 309 return url; |
| 299 } | 310 } |
| 311 // Parts of internal libraries are handled internally. |
| 312 if (libraryBuiltinId != Builtin::kInvalidLibrary) { |
| 313 return url; |
| 314 } |
| 300 return ResolveUri(library_url_string, url_string); | 315 return ResolveUri(library_url_string, url_string); |
| 301 } | 316 } |
| 302 | 317 |
| 303 if (DartUtils::IsDartIOLibURL(url_string) && mapped_url_string == NULL) { | 318 Builtin::BuiltinLibraryId builtinId = BuiltinId(url_string); |
| 304 // No url mapping for dart:io. Load original version. | 319 if (builtinId != Builtin::kInvalidLibrary) { |
| 305 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 320 // Special case for importing a builtin library. |
| 321 if (tag == kImportTag) { |
| 322 return Builtin::LoadAndCheckLibrary(builtinId); |
| 323 } |
| 324 ASSERT(tag == kSourceTag); |
| 325 return Dart_Error("Unable to part '%s' ", url_string); |
| 326 } |
| 327 |
| 328 if (libraryBuiltinId != Builtin::kInvalidLibrary) { |
| 329 // Special case for parting sources of a builtin library. |
| 330 if (tag == kSourceTag) { |
| 331 return Dart_LoadSource( |
| 332 library, url, Builtin::PartSource(libraryBuiltinId, url_string)); |
| 333 } |
| 334 ASSERT(tag == kImportTag); |
| 335 return Dart_Error("Unable to import '%s' ", url_string); |
| 306 } | 336 } |
| 307 | 337 |
| 308 Dart_Handle resolved_url = url; | 338 Dart_Handle resolved_url = url; |
| 309 if (mapped_url_string != NULL) { | 339 if (mapped_url_string != NULL) { |
| 310 // Mapped urls are relative to working directory. | 340 // Mapped urls are relative to working directory. |
| 311 resolved_url = ResolveScriptUri(mapped_url_string); | 341 resolved_url = ResolveScriptUri(mapped_url_string); |
| 312 if (Dart_IsError(resolved_url)) { | 342 if (Dart_IsError(resolved_url)) { |
| 313 return resolved_url; | 343 return resolved_url; |
| 314 } | 344 } |
| 315 } | 345 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 565 } |
| 536 return 0; | 566 return 0; |
| 537 } | 567 } |
| 538 | 568 |
| 539 } // namespace bin | 569 } // namespace bin |
| 540 } // namespace dart | 570 } // namespace dart |
| 541 | 571 |
| 542 int main(int argc, char** argv) { | 572 int main(int argc, char** argv) { |
| 543 return dart::bin::main(argc, argv); | 573 return dart::bin::main(argc, argv); |
| 544 } | 574 } |
| OLD | NEW |