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

Unified Diff: runtime/vm/bootstrap.cc

Issue 1449163003: - Include sources in gen_snapshot and dart_no_snapshot to allow (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Simplify logic. Created 5 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 | « runtime/tools/gen_library_src_paths.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/bootstrap.cc
diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc
index 85fcf5296e2e7b61df53aeb592c5d26ddb01f104..5d7bdc39215736c950b92c1eae86059ba4324fb2 100644
--- a/runtime/vm/bootstrap.cc
+++ b/runtime/vm/bootstrap.cc
@@ -30,6 +30,14 @@ typedef struct {
} bootstrap_lib_props;
+enum {
+ kPathsUriOffset = 0,
+ kPathsFileOffset = 1,
+ kPathsSourceOffset = 2,
+ kPathsEntryLength = 3
+};
+
+
static bootstrap_lib_props bootstrap_libraries[] = {
INIT_LIBRARY(ObjectStore::kCore,
core,
@@ -86,7 +94,7 @@ static bootstrap_lib_props bootstrap_libraries[] = {
static RawString* GetLibrarySource(const Library& lib,
const String& uri,
bool patch) {
- // First check if this is a valid boot strap library and find it's index
+ // First check if this is a valid bootstrap library and find it's index
// in the 'bootstrap_libraries' table above.
intptr_t index;
const String& lib_uri = String::Handle(lib.url());
@@ -98,7 +106,7 @@ static RawString* GetLibrarySource(const Library& lib,
}
}
if (bootstrap_libraries[index].index_ == ObjectStore::kNone) {
- return String::null(); // Library is not a boot strap library.
+ return String::null(); // Library is not a bootstrap library.
}
// Try to read the source using the path specified for the uri.
@@ -109,38 +117,42 @@ static RawString* GetLibrarySource(const Library& lib,
return String::null(); // No path mapping information exists for library.
}
const char* source_path = NULL;
- for (intptr_t i = 0; source_paths[i] != NULL; i += 2) {
- if (uri.Equals(source_paths[i])) {
- source_path = source_paths[i + 1];
+ const char* source_data = NULL;
+ for (intptr_t i = 0; source_paths[i] != NULL; i += kPathsEntryLength) {
+ if (uri.Equals(source_paths[i + kPathsUriOffset])) {
+ source_path = source_paths[i + kPathsFileOffset];
+ source_data = source_paths[i + kPathsSourceOffset];
break;
}
}
- if (source_path == NULL) {
+ if ((source_path == NULL) && (source_data == NULL)) {
return String::null(); // Uri does not exist in path mapping information.
}
+ const uint8_t* utf8_array = NULL;
+ intptr_t file_length = -1;
+
Dart_FileOpenCallback file_open = Isolate::file_open_callback();
Dart_FileReadCallback file_read = Isolate::file_read_callback();
Dart_FileCloseCallback file_close = Isolate::file_close_callback();
- if (file_open == NULL || file_read == NULL || file_close == NULL) {
- return String::null(); // File operations are not supported.
- }
-
- void* stream = (*file_open)(source_path, false);
- if (stream == NULL) {
- return String::null();
+ if ((file_open != NULL) && (file_read != NULL) && (file_close != NULL)) {
+ // Try to open and read the file.
+ void* stream = (*file_open)(source_path, false);
+ if (stream != NULL) {
+ (*file_read)(&utf8_array, &file_length, stream);
+ (*file_close)(stream);
+ }
}
-
- const uint8_t* utf8_array = NULL;
- intptr_t file_length = -1;
- (*file_read)(&utf8_array, &file_length, stream);
if (file_length == -1) {
- return String::null();
+ if (source_data != NULL) {
+ file_length = strlen(source_data);
+ utf8_array = reinterpret_cast<const uint8_t*>(source_data);
+ } else {
+ return String::null();
+ }
}
ASSERT(utf8_array != NULL);
-
- (*file_close)(stream);
-
+ ASSERT(file_length >= 0);
return String::FromUTF8(utf8_array, file_length);
}
@@ -237,8 +249,8 @@ static RawError* LoadPatchFiles(Zone* zone,
const Array& strings = Array::Handle(zone, Array::New(3));
strings.SetAt(0, patch_uri);
strings.SetAt(1, Symbols::Slash());
- for (intptr_t j = 0; patch_files[j] != NULL; j += 2) {
- patch_file_uri = String::New(patch_files[j]);
+ for (intptr_t j = 0; patch_files[j] != NULL; j += kPathsEntryLength) {
+ patch_file_uri = String::New(patch_files[j + kPathsUriOffset]);
source = GetLibrarySource(lib, patch_file_uri, true);
if (source.IsNull()) {
const String& message = String::Handle(
« no previous file with comments | « runtime/tools/gen_library_src_paths.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698