| 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 |  | 
| 47 // Patch all the specified patch files in the array 'patch_files' into the | 45 // Patch all the specified patch files in the array 'patch_files' into the | 
| 48 // library specified in 'library'. | 46 // library specified in 'library'. | 
| 49 static void LoadPatchFiles(Dart_Handle library, | 47 static void LoadPatchFiles(Dart_Handle library, | 
| 50                            const char* patch_uri, | 48                            const char* patch_uri, | 
| 51                            const char** patch_files) { | 49                            const char** patch_files) { | 
| 52   for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { | 50   for (intptr_t j = 0; patch_files[j] != NULL; j += 2) { | 
| 53     Dart_Handle patch_src = Dart_Null(); | 51     // Use the sources linked in the binary. | 
| 54     if (use_builtin_source_paths) { | 52     const char* source = patch_files[j + 1]; | 
| 55       patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); | 53     Dart_Handle patch_src = Dart_NewStringFromUTF8( | 
| 56     } | 54         reinterpret_cast<const uint8_t*>(source), strlen(source)); | 
| 57     if (!Dart_IsString(patch_src)) { |  | 
| 58       // If use_builtin_source_paths is false or reading the file caused |  | 
| 59       // an error, use the sources linked in the binary. |  | 
| 60       const char* source = patch_files[j + 2]; |  | 
| 61       patch_src = Dart_NewStringFromUTF8( |  | 
| 62           reinterpret_cast<const uint8_t*>(source), strlen(source)); |  | 
| 63     } |  | 
| 64 | 55 | 
| 65     // Prepend the patch library URI to form a unique script URI for the patch. | 56     // Prepend the patch library URI to form a unique script URI for the patch. | 
| 66     intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); | 57     intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); | 
| 67     char* patch_filename = DartUtils::ScopedCString(len + 1); | 58     char* patch_filename = DartUtils::ScopedCString(len + 1); | 
| 68     snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); | 59     snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); | 
| 69     Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); | 60     Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); | 
| 70 | 61 | 
| 71     DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); | 62     DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); | 
| 72   } | 63   } | 
| 73 } | 64 } | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 91   // Try to read the source using the path specified for the uri. | 82   // Try to read the source using the path specified for the uri. | 
| 92   const char** source_paths = builtin_libraries_[id].source_paths_; | 83   const char** source_paths = builtin_libraries_[id].source_paths_; | 
| 93   return GetSource(source_paths, part_uri); | 84   return GetSource(source_paths, part_uri); | 
| 94 } | 85 } | 
| 95 | 86 | 
| 96 | 87 | 
| 97 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { | 88 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { | 
| 98   if (source_paths == NULL) { | 89   if (source_paths == NULL) { | 
| 99     return Dart_Null();  // No path mapping information exists for library. | 90     return Dart_Null();  // No path mapping information exists for library. | 
| 100   } | 91   } | 
| 101   for (intptr_t i = 0; source_paths[i] != NULL; i += 3) { | 92   for (intptr_t i = 0; source_paths[i] != NULL; i += 2) { | 
| 102     if (!strcmp(uri, source_paths[i])) { | 93     if (!strcmp(uri, source_paths[i])) { | 
| 103       const char* source_path = source_paths[i + 1]; | 94       // Use the sources linked in the binary. | 
| 104       Dart_Handle src = Dart_Null(); | 95       const char* source = source_paths[i + 1]; | 
| 105       if (use_builtin_source_paths) { | 96       return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(source), | 
| 106         src = DartUtils::ReadStringFromFile(source_path); | 97                                     strlen(source)); | 
| 107       } |  | 
| 108       if (!Dart_IsString(src)) { |  | 
| 109         // If use_builtin_source_paths is false or reading the file caused |  | 
| 110         // an error, use the sources linked in the binary. |  | 
| 111         const char* source = source_paths[i + 2]; |  | 
| 112         src = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(source), |  | 
| 113                                      strlen(source)); |  | 
| 114       } |  | 
| 115       return src; |  | 
| 116     } | 98     } | 
| 117   } | 99   } | 
| 118   return Dart_Null();  // Uri does not exist in path mapping information. | 100   return Dart_Null();  // Uri does not exist in path mapping information. | 
| 119 } | 101 } | 
| 120 | 102 | 
| 121 | 103 | 
| 122 void Builtin::SetNativeResolver(BuiltinLibraryId id) { | 104 void Builtin::SetNativeResolver(BuiltinLibraryId id) { | 
| 123   ASSERT(static_cast<int>(id) >= 0); | 105   ASSERT(static_cast<int>(id) >= 0); | 
| 124   ASSERT(static_cast<int>(id) < num_libs_); | 106   ASSERT(static_cast<int>(id) < num_libs_); | 
| 125 | 107 | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 174   Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); | 156   Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); | 
| 175   Dart_Handle library = Dart_LookupLibrary(url); | 157   Dart_Handle library = Dart_LookupLibrary(url); | 
| 176   if (Dart_IsError(library)) { | 158   if (Dart_IsError(library)) { | 
| 177     library = LoadLibrary(url, id); | 159     library = LoadLibrary(url, id); | 
| 178   } | 160   } | 
| 179   return library; | 161   return library; | 
| 180 } | 162 } | 
| 181 | 163 | 
| 182 }  // namespace bin | 164 }  // namespace bin | 
| 183 }  // namespace dart | 165 }  // namespace dart | 
| OLD | NEW | 
|---|