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 #include "vm/bootstrap.h" | 5 #include "vm/bootstrap.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/bootstrap_natives.h" | 9 #include "vm/bootstrap_natives.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 typedef struct { | 24 typedef struct { |
| 25 ObjectStore::BootstrapLibraryId index_; | 25 ObjectStore::BootstrapLibraryId index_; |
| 26 const char* uri_; | 26 const char* uri_; |
| 27 const char** source_paths_; | 27 const char** source_paths_; |
| 28 const char* patch_uri_; | 28 const char* patch_uri_; |
| 29 const char** patch_paths_; | 29 const char** patch_paths_; |
| 30 } bootstrap_lib_props; | 30 } bootstrap_lib_props; |
| 31 | 31 |
| 32 | 32 |
| 33 enum { | |
| 34 kPathsUriOffset = 0, | |
| 35 kPathsFileOffset = 1, | |
| 36 kPathsSourceOffset = 2, | |
| 37 kPathsEntryLength = 3 | |
| 38 }; | |
| 39 | |
| 40 | |
| 33 static bootstrap_lib_props bootstrap_libraries[] = { | 41 static bootstrap_lib_props bootstrap_libraries[] = { |
| 34 INIT_LIBRARY(ObjectStore::kCore, | 42 INIT_LIBRARY(ObjectStore::kCore, |
| 35 core, | 43 core, |
| 36 Bootstrap::core_source_paths_, | 44 Bootstrap::core_source_paths_, |
| 37 Bootstrap::core_patch_paths_), | 45 Bootstrap::core_patch_paths_), |
| 38 INIT_LIBRARY(ObjectStore::kAsync, | 46 INIT_LIBRARY(ObjectStore::kAsync, |
| 39 async, | 47 async, |
| 40 Bootstrap::async_source_paths_, | 48 Bootstrap::async_source_paths_, |
| 41 Bootstrap::async_patch_paths_), | 49 Bootstrap::async_patch_paths_), |
| 42 INIT_LIBRARY(ObjectStore::kConvert, | 50 INIT_LIBRARY(ObjectStore::kConvert, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 _vmservice, | 87 _vmservice, |
| 80 Bootstrap::_vmservice_source_paths_, | 88 Bootstrap::_vmservice_source_paths_, |
| 81 Bootstrap::_vmservice_patch_paths_), | 89 Bootstrap::_vmservice_patch_paths_), |
| 82 { ObjectStore::kNone, NULL, NULL, NULL, NULL } | 90 { ObjectStore::kNone, NULL, NULL, NULL, NULL } |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 | 93 |
| 86 static RawString* GetLibrarySource(const Library& lib, | 94 static RawString* GetLibrarySource(const Library& lib, |
| 87 const String& uri, | 95 const String& uri, |
| 88 bool patch) { | 96 bool patch) { |
| 89 // First check if this is a valid boot strap library and find it's index | 97 // First check if this is a valid bootstrap library and find it's index |
| 90 // in the 'bootstrap_libraries' table above. | 98 // in the 'bootstrap_libraries' table above. |
| 91 intptr_t index; | 99 intptr_t index; |
| 92 const String& lib_uri = String::Handle(lib.url()); | 100 const String& lib_uri = String::Handle(lib.url()); |
| 93 for (index = 0; | 101 for (index = 0; |
| 94 bootstrap_libraries[index].index_ != ObjectStore::kNone; | 102 bootstrap_libraries[index].index_ != ObjectStore::kNone; |
| 95 ++index) { | 103 ++index) { |
| 96 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) { | 104 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) { |
| 97 break; | 105 break; |
| 98 } | 106 } |
| 99 } | 107 } |
| 100 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) { | 108 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) { |
| 101 return String::null(); // Library is not a boot strap library. | 109 return String::null(); // Library is not a bootstrap library. |
| 102 } | 110 } |
| 103 | 111 |
| 104 // Try to read the source using the path specified for the uri. | 112 // Try to read the source using the path specified for the uri. |
| 105 const char** source_paths = patch ? | 113 const char** source_paths = patch ? |
| 106 bootstrap_libraries[index].patch_paths_ : | 114 bootstrap_libraries[index].patch_paths_ : |
| 107 bootstrap_libraries[index].source_paths_; | 115 bootstrap_libraries[index].source_paths_; |
| 108 if (source_paths == NULL) { | 116 if (source_paths == NULL) { |
| 109 return String::null(); // No path mapping information exists for library. | 117 return String::null(); // No path mapping information exists for library. |
| 110 } | 118 } |
| 111 const char* source_path = NULL; | 119 const char* source_path = NULL; |
| 112 for (intptr_t i = 0; source_paths[i] != NULL; i += 2) { | 120 const char* source_data = NULL; |
| 113 if (uri.Equals(source_paths[i])) { | 121 for (intptr_t i = 0; source_paths[i] != NULL; i += kPathsEntryLength) { |
| 114 source_path = source_paths[i + 1]; | 122 if (uri.Equals(source_paths[i + kPathsUriOffset])) { |
| 123 source_path = source_paths[i + kPathsFileOffset]; | |
| 124 source_data = source_paths[i + kPathsSourceOffset]; | |
| 115 break; | 125 break; |
| 116 } | 126 } |
| 117 } | 127 } |
| 118 if (source_path == NULL) { | 128 if ((source_path == NULL) && (source_data == NULL)) { |
| 119 return String::null(); // Uri does not exist in path mapping information. | 129 return String::null(); // Uri does not exist in path mapping information. |
| 120 } | 130 } |
| 121 | 131 |
| 132 const uint8_t* utf8_array = NULL; | |
| 133 intptr_t file_length = -1; | |
| 134 | |
| 122 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 135 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
| 123 Dart_FileReadCallback file_read = Isolate::file_read_callback(); | 136 Dart_FileReadCallback file_read = Isolate::file_read_callback(); |
| 124 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 137 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
| 125 if (file_open == NULL || file_read == NULL || file_close == NULL) { | 138 if ((file_open == NULL || file_read == NULL || file_close == NULL)) { |
| 126 return String::null(); // File operations are not supported. | 139 if (source_data == NULL) { |
| 140 return String::null(); | |
| 141 } | |
| 142 file_length = strlen(source_data); | |
| 143 utf8_array = reinterpret_cast<const uint8_t*>(source_data); | |
| 144 } else { | |
| 145 void* stream = (*file_open)(source_path, false); | |
| 146 if (stream == NULL) { | |
| 147 if (source_data == NULL) { | |
| 148 return String::null(); | |
| 149 } | |
| 150 file_length = strlen(source_data); | |
| 151 utf8_array = reinterpret_cast<const uint8_t*>(source_data); | |
| 152 } else { | |
| 153 (*file_read)(&utf8_array, &file_length, stream); | |
| 154 (*file_close)(stream); | |
| 155 if (file_length == -1) { | |
| 156 return String::null(); | |
| 157 } | |
| 158 ASSERT(utf8_array != NULL); | |
|
siva
2015/11/17 19:37:55
This assert can move down to the else block as it
Ivan Posva
2015/11/17 22:50:26
Simplified the whole logic around here. Did not li
| |
| 159 } | |
| 127 } | 160 } |
| 128 | |
| 129 void* stream = (*file_open)(source_path, false); | |
| 130 if (stream == NULL) { | |
| 131 return String::null(); | |
| 132 } | |
| 133 | |
| 134 const uint8_t* utf8_array = NULL; | |
| 135 intptr_t file_length = -1; | |
| 136 (*file_read)(&utf8_array, &file_length, stream); | |
| 137 if (file_length == -1) { | |
| 138 return String::null(); | |
| 139 } | |
| 140 ASSERT(utf8_array != NULL); | |
| 141 | |
| 142 (*file_close)(stream); | |
| 143 | |
| 144 return String::FromUTF8(utf8_array, file_length); | 161 return String::FromUTF8(utf8_array, file_length); |
| 145 } | 162 } |
| 146 | 163 |
| 147 | 164 |
| 148 static RawError* Compile(const Library& library, const Script& script) { | 165 static RawError* Compile(const Library& library, const Script& script) { |
| 149 bool update_lib_status = (script.kind() == RawScript::kScriptTag || | 166 bool update_lib_status = (script.kind() == RawScript::kScriptTag || |
| 150 script.kind() == RawScript::kLibraryTag); | 167 script.kind() == RawScript::kLibraryTag); |
| 151 if (update_lib_status) { | 168 if (update_lib_status) { |
| 152 library.SetLoadInProgress(); | 169 library.SetLoadInProgress(); |
| 153 } | 170 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 const Library& lib, | 247 const Library& lib, |
| 231 const String& patch_uri, | 248 const String& patch_uri, |
| 232 const char** patch_files) { | 249 const char** patch_files) { |
| 233 String& patch_file_uri = String::Handle(zone); | 250 String& patch_file_uri = String::Handle(zone); |
| 234 String& source = String::Handle(zone); | 251 String& source = String::Handle(zone); |
| 235 Script& script = Script::Handle(zone); | 252 Script& script = Script::Handle(zone); |
| 236 Error& error = Error::Handle(zone); | 253 Error& error = Error::Handle(zone); |
| 237 const Array& strings = Array::Handle(zone, Array::New(3)); | 254 const Array& strings = Array::Handle(zone, Array::New(3)); |
| 238 strings.SetAt(0, patch_uri); | 255 strings.SetAt(0, patch_uri); |
| 239 strings.SetAt(1, Symbols::Slash()); | 256 strings.SetAt(1, Symbols::Slash()); |
| 240 for (intptr_t j = 0; patch_files[j] != NULL; j += 2) { | 257 for (intptr_t j = 0; patch_files[j] != NULL; j += kPathsEntryLength) { |
| 241 patch_file_uri = String::New(patch_files[j]); | 258 patch_file_uri = String::New(patch_files[j + kPathsUriOffset]); |
| 242 source = GetLibrarySource(lib, patch_file_uri, true); | 259 source = GetLibrarySource(lib, patch_file_uri, true); |
| 243 if (source.IsNull()) { | 260 if (source.IsNull()) { |
| 244 const String& message = String::Handle( | 261 const String& message = String::Handle( |
| 245 String::NewFormatted("Unable to find dart patch source for %s", | 262 String::NewFormatted("Unable to find dart patch source for %s", |
| 246 patch_file_uri.ToCString())); | 263 patch_file_uri.ToCString())); |
| 247 return ApiError::New(message); | 264 return ApiError::New(message); |
| 248 } | 265 } |
| 249 // Prepend the patch library URI to form a unique script URI for the patch. | 266 // Prepend the patch library URI to form a unique script URI for the patch. |
| 250 strings.SetAt(2, patch_file_uri); | 267 strings.SetAt(2, patch_file_uri); |
| 251 patch_file_uri = String::ConcatAll(strings); | 268 patch_file_uri = String::ConcatAll(strings); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 Compiler::CompileClass(cls); | 355 Compiler::CompileClass(cls); |
| 339 } | 356 } |
| 340 | 357 |
| 341 // Restore the library tag handler for the isolate. | 358 // Restore the library tag handler for the isolate. |
| 342 isolate->set_library_tag_handler(saved_tag_handler); | 359 isolate->set_library_tag_handler(saved_tag_handler); |
| 343 | 360 |
| 344 return error.raw(); | 361 return error.raw(); |
| 345 } | 362 } |
| 346 | 363 |
| 347 } // namespace dart | 364 } // namespace dart |
| OLD | NEW |