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

Unified Diff: bin/process_script.cc

Issue 8439061: Support command line parameters to specify a url to file name mapping. This is used during snapsh... (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
Index: bin/process_script.cc
===================================================================
--- bin/process_script.cc (revision 1494)
+++ bin/process_script.cc (working copy)
@@ -57,39 +57,9 @@
}
-static Dart_Handle ReadStringFromFile(const char* filename) {
- File* file = File::Open(filename, false);
- if (file == NULL) {
- const char* format = "Unable to open file: %s";
- intptr_t len = snprintf(NULL, 0, format, filename);
- // TODO(iposva): Allocate from the zone instead of leaking error string
- // here. On the other hand the binary is about the exit anyway.
- char* error_msg = reinterpret_cast<char*>(malloc(len + 1));
- snprintf(error_msg, len + 1, format, filename);
- return Dart_Error(error_msg);
- }
- intptr_t len = file->Length();
- char* text_buffer = reinterpret_cast<char*>(malloc(len + 1));
- if (text_buffer == NULL) {
- delete file;
- return Dart_Error("Unable to allocate buffer");
- }
- if (!file->ReadFully(text_buffer, len)) {
- delete file;
- return Dart_Error("Unable to fully read contents");
- }
- text_buffer[len] = '\0';
- delete file;
- Dart_Handle str = Dart_NewString(text_buffer);
- free(text_buffer);
- return str;
-}
-
-
-static Dart_Handle LibraryTagHandlerHelper(Dart_LibraryTag tag,
- Dart_Handle library,
- Dart_Handle url,
- bool import_builtin_lib) {
+static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
+ Dart_Handle library,
+ Dart_Handle url) {
if (!Dart_IsLibrary(library)) {
return Dart_Error("not a library");
}
@@ -135,7 +105,7 @@
}
if (tag == kImportTag) {
Dart_Handle new_lib = Dart_LoadLibrary(url, source);
- if (import_builtin_lib && !Dart_IsError(new_lib)) {
+ if (!Dart_IsError(new_lib)) {
Builtin_ImportLibrary(new_lib);
}
return new_lib; // Return library object or an error string.
@@ -145,19 +115,33 @@
return Dart_Error("wrong tag");
}
-static Dart_Handle MainLibraryTagHandler(Dart_LibraryTag tag,
- Dart_Handle library,
- Dart_Handle url) {
- const bool kImportBuiltinLib = true; // Import builtin library.
- return LibraryTagHandlerHelper(tag, library, url, kImportBuiltinLib);
-}
-
-static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
- Dart_Handle library,
- Dart_Handle url) {
- const bool kDontImportBuiltinLib = false; // Do not import builtin lib.
- return LibraryTagHandlerHelper(tag, library, url, kDontImportBuiltinLib);
+Dart_Handle ReadStringFromFile(const char* filename) {
+ File* file = File::Open(filename, false);
+ if (file == NULL) {
+ const char* format = "Unable to open file: %s";
+ intptr_t len = snprintf(NULL, 0, format, filename);
+ // TODO(iposva): Allocate from the zone instead of leaking error string
+ // here. On the other hand the binary is about the exit anyway.
+ char* error_msg = reinterpret_cast<char*>(malloc(len + 1));
+ snprintf(error_msg, len + 1, format, filename);
+ return Dart_Error(error_msg);
+ }
+ intptr_t len = file->Length();
+ char* text_buffer = reinterpret_cast<char*>(malloc(len + 1));
+ if (text_buffer == NULL) {
+ delete file;
+ return Dart_Error("Unable to allocate buffer");
+ }
+ if (!file->ReadFully(text_buffer, len)) {
+ delete file;
+ return Dart_Error("Unable to fully read contents");
+ }
+ text_buffer[len] = '\0';
+ delete file;
+ Dart_Handle str = Dart_NewString(text_buffer);
+ free(text_buffer);
+ return str;
}
@@ -168,16 +152,5 @@
}
Dart_Handle url = Dart_NewString(script_name);
- return Dart_LoadScript(url, source, MainLibraryTagHandler);
+ return Dart_LoadScript(url, source, LibraryTagHandler);
}
-
-
-Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
- Dart_Handle source = ReadStringFromFile(script_name);
- if (Dart_IsError(source)) {
- return source;
- }
- Dart_Handle url = Dart_NewString(script_name);
-
- return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler);
-}

Powered by Google App Engine
This is Rietveld 408576698