| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 {"dart:web_audio", web_audio_source_paths_, NULL, NULL, true}, | 35 {"dart:web_audio", web_audio_source_paths_, NULL, NULL, true}, |
| 36 #endif // defined(DART_NO_SNAPSHOT) | 36 #endif // defined(DART_NO_SNAPSHOT) |
| 37 | 37 |
| 38 // End marker. | 38 // End marker. |
| 39 {NULL, NULL, NULL, NULL, false}}; | 39 {NULL, NULL, NULL, NULL, false}}; |
| 40 | 40 |
| 41 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; | 41 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; |
| 42 const int Builtin::num_libs_ = | 42 const int Builtin::num_libs_ = |
| 43 sizeof(Builtin::builtin_libraries_) / sizeof(Builtin::builtin_lib_props); | 43 sizeof(Builtin::builtin_libraries_) / sizeof(Builtin::builtin_lib_props); |
| 44 | 44 |
| 45 static const bool use_builtin_source_paths = false; |
| 46 |
| 45 // Patch all the specified patch files in the array 'patch_files' into the | 47 // Patch all the specified patch files in the array 'patch_files' into the |
| 46 // library specified in 'library'. | 48 // library specified in 'library'. |
| 47 static void LoadPatchFiles(Dart_Handle library, | 49 static void LoadPatchFiles(Dart_Handle library, |
| 48 const char* patch_uri, | 50 const char* patch_uri, |
| 49 const char** patch_files) { | 51 const char** patch_files) { |
| 50 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { | 52 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { |
| 51 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); | 53 Dart_Handle patch_src = Dart_Null(); |
| 54 if (use_builtin_source_paths) { |
| 55 patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); |
| 56 } |
| 52 if (!Dart_IsString(patch_src)) { | 57 if (!Dart_IsString(patch_src)) { |
| 53 // In case reading the file caused an error, use the sources directly. | 58 // If use_builtin_source_paths is false or reading the file caused |
| 59 // an error, use the sources linked in the binary. |
| 54 const char* source = patch_files[j + 2]; | 60 const char* source = patch_files[j + 2]; |
| 55 patch_src = Dart_NewStringFromUTF8( | 61 patch_src = Dart_NewStringFromUTF8( |
| 56 reinterpret_cast<const uint8_t*>(source), strlen(source)); | 62 reinterpret_cast<const uint8_t*>(source), strlen(source)); |
| 57 } | 63 } |
| 58 | 64 |
| 59 // Prepend the patch library URI to form a unique script URI for the patch. | 65 // Prepend the patch library URI to form a unique script URI for the patch. |
| 60 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); | 66 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); |
| 61 char* patch_filename = DartUtils::ScopedCString(len + 1); | 67 char* patch_filename = DartUtils::ScopedCString(len + 1); |
| 62 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); | 68 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); |
| 63 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); | 69 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 88 } | 94 } |
| 89 | 95 |
| 90 | 96 |
| 91 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { | 97 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { |
| 92 if (source_paths == NULL) { | 98 if (source_paths == NULL) { |
| 93 return Dart_Null(); // No path mapping information exists for library. | 99 return Dart_Null(); // No path mapping information exists for library. |
| 94 } | 100 } |
| 95 for (intptr_t i = 0; source_paths[i] != NULL; i += 3) { | 101 for (intptr_t i = 0; source_paths[i] != NULL; i += 3) { |
| 96 if (!strcmp(uri, source_paths[i])) { | 102 if (!strcmp(uri, source_paths[i])) { |
| 97 const char* source_path = source_paths[i + 1]; | 103 const char* source_path = source_paths[i + 1]; |
| 98 Dart_Handle src = DartUtils::ReadStringFromFile(source_path); | 104 Dart_Handle src = Dart_Null(); |
| 105 if (use_builtin_source_paths) { |
| 106 src = DartUtils::ReadStringFromFile(source_path); |
| 107 } |
| 99 if (!Dart_IsString(src)) { | 108 if (!Dart_IsString(src)) { |
| 100 // In case reading the file caused an error, use the sources directly. | 109 // If use_builtin_source_paths is false or reading the file caused |
| 110 // an error, use the sources linked in the binary. |
| 101 const char* source = source_paths[i + 2]; | 111 const char* source = source_paths[i + 2]; |
| 102 src = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(source), | 112 src = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(source), |
| 103 strlen(source)); | 113 strlen(source)); |
| 104 } | 114 } |
| 105 return src; | 115 return src; |
| 106 } | 116 } |
| 107 } | 117 } |
| 108 return Dart_Null(); // Uri does not exist in path mapping information. | 118 return Dart_Null(); // Uri does not exist in path mapping information. |
| 109 } | 119 } |
| 110 | 120 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); | 174 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); |
| 165 Dart_Handle library = Dart_LookupLibrary(url); | 175 Dart_Handle library = Dart_LookupLibrary(url); |
| 166 if (Dart_IsError(library)) { | 176 if (Dart_IsError(library)) { |
| 167 library = LoadLibrary(url, id); | 177 library = LoadLibrary(url, id); |
| 168 } | 178 } |
| 169 return library; | 179 return library; |
| 170 } | 180 } |
| 171 | 181 |
| 172 } // namespace bin | 182 } // namespace bin |
| 173 } // namespace dart | 183 } // namespace dart |
| OLD | NEW |