Chromium Code Reviews| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 const char* url_string = NULL; | 175 const char* url_string = NULL; |
| 176 Dart_Handle result = Dart_StringToCString(url, &url_string); | 176 Dart_Handle result = Dart_StringToCString(url, &url_string); |
| 177 if (Dart_IsError(result)) { | 177 if (Dart_IsError(result)) { |
| 178 return Dart_Error("accessing url characters failed"); | 178 return Dart_Error("accessing url characters failed"); |
| 179 } | 179 } |
| 180 // We only support canonicalization of "dart:". | 180 // We only support canonicalization of "dart:". |
| 181 if (DartUtils::IsDartSchemeURL(url_string)) { | 181 if (DartUtils::IsDartSchemeURL(url_string)) { |
| 182 if (tag == kCanonicalizeUrl) { | 182 if (tag == kCanonicalizeUrl) { |
| 183 return url; | 183 return url; |
| 184 } | 184 } |
| 185 return Dart_Error("unsupported url encountered %s", url_string); | 185 // TODO(iposva): Make sure only the known libraries are being added. |
| 186 return Dart_True(); | |
| 186 } | 187 } |
| 187 return Dart_Error("unexpected tag encountered %d", tag); | 188 return Dart_Error("unexpected tag encountered %d", tag); |
| 188 } | 189 } |
| 189 | 190 |
| 190 | 191 |
| 191 static Dart_Handle LoadGenericSnapshotCreationScript( | 192 static Dart_Handle LoadGenericSnapshotCreationScript( |
| 192 Builtin::BuiltinLibraryId id) { | 193 Builtin::BuiltinLibraryId id) { |
| 193 Dart_Handle source = Builtin::Source(id); | 194 Dart_Handle source = Builtin::Source(id); |
| 194 if (Dart_IsError(source)) { | 195 if (Dart_IsError(source)) { |
| 195 return source; // source contains the error string. | 196 return source; // source contains the error string. |
| 196 } | 197 } |
| 197 Dart_Handle lib; | 198 Dart_Handle lib; |
| 198 if (id == Builtin::kBuiltinLibrary) { | 199 // Load the builtin library to make it available in the snapshot |
| 199 // Load the dart:builtin library as the script. | 200 // for importing. |
| 200 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 201 lib = Builtin::LoadLibrary(id); |
| 201 Dart_Handle import_map = Dart_NewList(0); | |
| 202 lib = Dart_LoadScript(url, | |
| 203 source, | |
| 204 BuiltinLibraryTagHandler, | |
| 205 import_map); | |
| 206 } else { | |
| 207 // Load the builtin library to make it available in the snapshot | |
| 208 // for importing. | |
| 209 lib = Builtin::LoadLibrary(id); | |
| 210 } | |
| 211 if (!Dart_IsError(lib)) { | 202 if (!Dart_IsError(lib)) { |
| 212 Builtin::SetupLibrary(lib, id); | 203 Builtin::SetupLibrary(lib, id); |
| 213 } | 204 } |
| 214 return lib; | 205 return lib; |
| 215 } | 206 } |
| 216 | 207 |
| 217 | 208 |
| 218 static void PrintUsage() { | 209 static void PrintUsage() { |
| 219 fprintf(stderr, | 210 fprintf(stderr, |
| 220 "dart [<vm-flags>] " | 211 "dart [<vm-flags>] " |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 Dart_Handle library; | 265 Dart_Handle library; |
| 275 Dart_EnterScope(); | 266 Dart_EnterScope(); |
| 276 | 267 |
| 277 ASSERT(snapshot_filename != NULL); | 268 ASSERT(snapshot_filename != NULL); |
| 278 // Load up the script before a snapshot is created. | 269 // Load up the script before a snapshot is created. |
| 279 if (app_script_name != NULL) { | 270 if (app_script_name != NULL) { |
| 280 // Load the specified script. | 271 // Load the specified script. |
| 281 library = LoadSnapshotCreationScript(app_script_name); | 272 library = LoadSnapshotCreationScript(app_script_name); |
| 282 VerifyLoaded(library); | 273 VerifyLoaded(library); |
| 283 } else { | 274 } else { |
| 275 // Load a dummy script as the script to setup the tag handler. | |
| 276 Dart_Handle empty_string = Dart_NewString(""); | |
| 277 Dart_Handle import_map = Dart_NewList(0); | |
|
siva
2012/03/07 18:32:17
import_map = Dart_Null();
Ivan Posva
2012/03/08 00:49:33
Done.
| |
| 278 Dart_Handle lib = Dart_LoadScript(empty_string, | |
| 279 empty_string, | |
| 280 BuiltinLibraryTagHandler, | |
| 281 import_map); | |
| 284 // This is a generic dart snapshot which needs builtin library setup. | 282 // This is a generic dart snapshot which needs builtin library setup. |
| 285 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 283 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
| 286 VerifyLoaded(library); | 284 VerifyLoaded(library); |
| 287 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); | 285 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); |
| 288 VerifyLoaded(library); | 286 VerifyLoaded(library); |
| 289 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); | 287 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); |
| 290 VerifyLoaded(library); | 288 VerifyLoaded(library); |
| 291 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); | 289 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); |
| 292 VerifyLoaded(library); | 290 VerifyLoaded(library); |
| 293 library = LoadGenericSnapshotCreationScript(Builtin::kUtf8Library); | 291 library = LoadGenericSnapshotCreationScript(Builtin::kUtf8Library); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 306 exit(255); | 304 exit(255); |
| 307 } | 305 } |
| 308 // Now write the snapshot out to specified file and exit. | 306 // Now write the snapshot out to specified file and exit. |
| 309 WriteSnapshotFile(buffer, size); | 307 WriteSnapshotFile(buffer, size); |
| 310 Dart_ExitScope(); | 308 Dart_ExitScope(); |
| 311 | 309 |
| 312 // Shutdown the isolate. | 310 // Shutdown the isolate. |
| 313 Dart_ShutdownIsolate(); | 311 Dart_ShutdownIsolate(); |
| 314 return 0; | 312 return 0; |
| 315 } | 313 } |
| OLD | NEW |