| 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 // 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (Dart_IsError(result)) { | 176 if (Dart_IsError(result)) { |
| 177 return result; | 177 return result; |
| 178 } | 178 } |
| 179 // We only support canonicalization of "dart:". | 179 // We only support canonicalization of "dart:". |
| 180 if (DartUtils::IsDartSchemeURL(url_string)) { | 180 if (DartUtils::IsDartSchemeURL(url_string)) { |
| 181 if (tag == kCanonicalizeUrl) { | 181 if (tag == kCanonicalizeUrl) { |
| 182 return url; | 182 return url; |
| 183 } | 183 } |
| 184 ASSERT(tag == kImportTag); | 184 ASSERT(tag == kImportTag); |
| 185 // Handle imports of other built-in libraries present in the SDK. | 185 // Handle imports of other built-in libraries present in the SDK. |
| 186 if (DartUtils::IsDartIOLibURL(url_string)) { | 186 if (DartUtils::IsDartCryptoLibURL(url_string)) { |
| 187 return Builtin::LoadLibrary(Builtin::kCryptoLibrary); |
| 188 } else if (DartUtils::IsDartIOLibURL(url_string)) { |
| 187 return Builtin::LoadLibrary(Builtin::kIOLibrary); | 189 return Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 188 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 190 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| 189 return Builtin::LoadLibrary(Builtin::kJsonLibrary); | 191 return Builtin::LoadLibrary(Builtin::kJsonLibrary); |
| 190 } else if (DartUtils::IsDartUriLibURL(url_string)) { | 192 } else if (DartUtils::IsDartUriLibURL(url_string)) { |
| 191 return Builtin::LoadLibrary(Builtin::kUriLibrary); | 193 return Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 192 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | 194 } else if (DartUtils::IsDartUtfLibURL(url_string)) { |
| 193 return Builtin::LoadLibrary(Builtin::kUtfLibrary); | 195 return Builtin::LoadLibrary(Builtin::kUtfLibrary); |
| 194 } | 196 } |
| 195 } | 197 } |
| 196 return Dart_Error("unexpected tag encountered %d", tag); | 198 return Dart_Error("unexpected tag encountered %d", tag); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (Dart_IsError(result)) { | 295 if (Dart_IsError(result)) { |
| 294 fprintf(stderr, "%s", Dart_GetError(result)); | 296 fprintf(stderr, "%s", Dart_GetError(result)); |
| 295 Dart_ExitScope(); | 297 Dart_ExitScope(); |
| 296 Dart_ShutdownIsolate(); | 298 Dart_ShutdownIsolate(); |
| 297 exit(255); | 299 exit(255); |
| 298 } | 300 } |
| 299 // This is a generic dart snapshot which needs builtin library setup. | 301 // This is a generic dart snapshot which needs builtin library setup. |
| 300 Dart_Handle library = | 302 Dart_Handle library = |
| 301 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 303 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
| 302 VerifyLoaded(library); | 304 VerifyLoaded(library); |
| 305 library = LoadGenericSnapshotCreationScript(Builtin::kCryptoLibrary); |
| 306 VerifyLoaded(library); |
| 303 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); | 307 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); |
| 304 VerifyLoaded(library); | 308 VerifyLoaded(library); |
| 305 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); | 309 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); |
| 306 VerifyLoaded(library); | 310 VerifyLoaded(library); |
| 307 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); | 311 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); |
| 308 VerifyLoaded(library); | 312 VerifyLoaded(library); |
| 309 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); | 313 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); |
| 310 VerifyLoaded(library); | 314 VerifyLoaded(library); |
| 311 } | 315 } |
| 312 | 316 |
| 313 uint8_t* buffer = NULL; | 317 uint8_t* buffer = NULL; |
| 314 intptr_t size = 0; | 318 intptr_t size = 0; |
| 315 // First create the snapshot. | 319 // First create the snapshot. |
| 316 result = Dart_CreateSnapshot(&buffer, &size); | 320 result = Dart_CreateSnapshot(&buffer, &size); |
| 317 if (Dart_IsError(result)) { | 321 if (Dart_IsError(result)) { |
| 318 const char* err_msg = Dart_GetError(result); | 322 const char* err_msg = Dart_GetError(result); |
| 319 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); | 323 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); |
| 320 Dart_ExitScope(); | 324 Dart_ExitScope(); |
| 321 Dart_ShutdownIsolate(); | 325 Dart_ShutdownIsolate(); |
| 322 exit(255); | 326 exit(255); |
| 323 } | 327 } |
| 324 // Now write the snapshot out to specified file and exit. | 328 // Now write the snapshot out to specified file and exit. |
| 325 WriteSnapshotFile(buffer, size); | 329 WriteSnapshotFile(buffer, size); |
| 326 Dart_ExitScope(); | 330 Dart_ExitScope(); |
| 327 | 331 |
| 328 // Shutdown the isolate. | 332 // Shutdown the isolate. |
| 329 Dart_ShutdownIsolate(); | 333 Dart_ShutdownIsolate(); |
| 330 return 0; | 334 return 0; |
| 331 } | 335 } |
| OLD | NEW |