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

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
« no previous file with comments | « bin/process_script.h ('k') | bin/run_vm_tests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/process_script.cc
===================================================================
--- bin/process_script.cc (revision 1549)
+++ bin/process_script.cc (working copy)
@@ -15,16 +15,8 @@
#include "bin/globals.h"
#include "bin/process_script.h"
-static const char* CanonicalizeUrl(const char* reference_dir,
- const char* filename) {
- static const char* kDartScheme = "dart:";
- static const intptr_t kDartSchemeLen = strlen(kDartScheme);
- // If the URL starts with "dart:" then it is not modified as it will be
- // handled by the VM internally.
- if (strncmp(filename, kDartScheme, kDartSchemeLen) == 0) {
- return strdup(filename);
- }
-
+const char* GetCanonicalPath(const char* reference_dir,
+ const char* filename) {
if (File::IsAbsolutePath(filename)) {
return strdup(filename);
}
@@ -57,39 +49,22 @@
}
-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);
+static const char* CanonicalizeUrl(const char* reference_dir,
+ const char* filename) {
+ static const char* kDartScheme = "dart:";
+ static const intptr_t kDartSchemeLen = strlen(kDartScheme);
+ // If the URL starts with "dart:" then it is not modified as it will be
+ // handled by the VM internally.
+ if (strncmp(filename, kDartScheme, kDartSchemeLen) == 0) {
+ return strdup(filename);
}
- 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;
+ return GetCanonicalPath(reference_dir, filename);
}
-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 +110,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 +120,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 +157,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);
-}
« no previous file with comments | « bin/process_script.h ('k') | bin/run_vm_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698