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

Unified Diff: bin/gen_snapshot.cc

Issue 8673002: - Refactor the isolate callback mechanism to also include creation of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/builtin_nolib.cc ('k') | bin/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/gen_snapshot.cc
===================================================================
--- bin/gen_snapshot.cc (revision 1955)
+++ bin/gen_snapshot.cc (working copy)
@@ -20,6 +20,13 @@
// if so which file to write the snapshot into.
static const char* snapshot_filename = NULL;
+
+// Global state which contains a pointer to the script name for which
+// a snapshot needs to be created (NULL would result in the creation
+// of a generic snapshot that contains only the corelibs).
+static char* app_script_name = NULL;
+
+
// Global state that captures the URL mappings specified on the command line.
static CommandLineOptions* url_mapping = NULL;
@@ -172,31 +179,69 @@
static Dart_Handle LoadGenericSnapshotCreationScript() {
- Dart_Handle source = Builtin_Source();
+ Dart_Handle source = Builtin::Source();
if (Dart_IsError(source)) {
return source; // source contains the error string.
}
Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL);
Dart_Handle lib = Dart_LoadScript(url, source, BuiltinLibraryTagHandler);
if (!Dart_IsError(lib)) {
- Builtin_SetupLibrary(lib);
+ Builtin::SetupLibrary(lib);
}
return lib;
}
-static void* SnapshotCreateCallback(void* data) {
- const char* script_name = reinterpret_cast<const char*>(data);
+static void PrintUsage() {
+ fprintf(stderr,
+ "dart [<vm-flags>] "
+ "[<dart-script-file>]\n");
+}
+
+
+int main(int argc, char** argv) {
+ CommandLineOptions vm_options(argc);
+
+ // Initialize the URL mapping array.
+ CommandLineOptions url_mapping_array(argc);
+ url_mapping = &url_mapping_array;
+
+ // Parse command line arguments.
+ if (ParseArguments(argc,
+ argv,
+ &vm_options,
+ &app_script_name) < 0) {
+ PrintUsage();
+ return 255;
+ }
+
+ if (snapshot_filename == NULL) {
+ fprintf(stderr, "No snapshot output file specified\n");
+ return 255;
+ }
+
+ // Initialize the Dart VM.
+ // Note: We don't expect isolates to be created from dart code during
+ // snapshot generation.
+ Dart_Initialize(vm_options.count(), vm_options.arguments(), NULL);
+
+ char* error;
+ Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, &error);
+ if (isolate == NULL) {
+ fprintf(stderr, "%s", error);
+ free(error);
+ exit(255);
+ }
+
Dart_Handle result;
Dart_Handle library;
Dart_EnterScope();
ASSERT(snapshot_filename != NULL);
-
// Load up the script before a snapshot is created.
- if (script_name != NULL) {
+ if (app_script_name != NULL) {
// Load the specified script.
- library = LoadSnapshotCreationScript(script_name);
+ library = LoadSnapshotCreationScript(app_script_name);
} else {
// This is a generic dart snapshot which needs builtin library setup.
library = LoadGenericSnapshotCreationScript();
@@ -205,6 +250,7 @@
const char* err_msg = Dart_GetError(library);
fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg);
Dart_ExitScope();
+ Dart_ShutdownIsolate();
exit(255);
}
ASSERT(Dart_IsLibrary(library));
@@ -216,58 +262,13 @@
const char* err_msg = Dart_GetError(result);
fprintf(stderr, "Error while creating snapshot: %s\n", err_msg);
Dart_ExitScope();
+ Dart_ShutdownIsolate();
exit(255);
}
// Now write the snapshot out to specified file and exit.
WriteSnapshotFile(buffer, size);
Dart_ExitScope();
- return data;
-}
-
-static void PrintUsage() {
- fprintf(stderr,
- "dart [<vm-flags>] "
- "[<dart-script-file>]\n");
-}
-
-
-int main(int argc, char** argv) {
- CommandLineOptions vm_options(argc);
- char* script_name;
-
- // Initialize the URL mapping array.
- CommandLineOptions url_mapping_array(argc);
- url_mapping = &url_mapping_array;
-
- // Parse command line arguments.
- if (ParseArguments(argc,
- argv,
- &vm_options,
- &script_name) < 0) {
- PrintUsage();
- return 255;
- }
-
- if (snapshot_filename == NULL) {
- fprintf(stderr, "No snapshot output file specified\n");
- return 255;
- }
-
- // Initialize the Dart VM (TODO(asiva) - remove const_cast once
- // dart API is fixed to take a const char** in Dart_Initialize).
- Dart_Initialize(vm_options.count(),
- vm_options.arguments(),
- SnapshotCreateCallback);
-
- // Create an isolate. As a side effect, SnapshotCreateCallback
- // gets called, which loads the script (if one is specified), its libraries
- // and writes out a snapshot.
- Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name);
- if (isolate == NULL) {
- return 255;
- }
-
// Shutdown the isolate.
Dart_ShutdownIsolate();
return 0;
« no previous file with comments | « bin/builtin_nolib.cc ('k') | bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698