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 20 matching lines...) Expand all Loading... |
31 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); | 31 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); |
32 if (!Dart_IsString(patch_src)) { | 32 if (!Dart_IsString(patch_src)) { |
33 // In case reading the file caused an error, use the sources directly. | 33 // In case reading the file caused an error, use the sources directly. |
34 const char* source = patch_files[j + 2]; | 34 const char* source = patch_files[j + 2]; |
35 patch_src = Dart_NewStringFromUTF8( | 35 patch_src = Dart_NewStringFromUTF8( |
36 reinterpret_cast<const uint8_t*>(source), strlen(source)); | 36 reinterpret_cast<const uint8_t*>(source), strlen(source)); |
37 } | 37 } |
38 | 38 |
39 // Prepend the patch library URI to form a unique script URI for the patch. | 39 // Prepend the patch library URI to form a unique script URI for the patch. |
40 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); | 40 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); |
41 char* patch_filename = reinterpret_cast<char*>(malloc(len + 1)); | 41 char* patch_filename = DartUtils::ScopedCString(len + 1); |
42 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); | 42 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); |
43 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); | 43 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); |
44 free(patch_filename); | |
45 | 44 |
46 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); | 45 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); |
47 } | 46 } |
48 } | 47 } |
49 | 48 |
50 | 49 |
51 Dart_Handle Builtin::Source(BuiltinLibraryId id) { | 50 Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
52 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == | 51 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == |
53 kInvalidLibrary); | 52 kInvalidLibrary); |
54 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); | 53 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); | 120 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); |
122 Dart_Handle library = Dart_LookupLibrary(url); | 121 Dart_Handle library = Dart_LookupLibrary(url); |
123 if (Dart_IsError(library)) { | 122 if (Dart_IsError(library)) { |
124 library = LoadLibrary(url, id); | 123 library = LoadLibrary(url, id); |
125 } | 124 } |
126 return library; | 125 return library; |
127 } | 126 } |
128 | 127 |
129 } // namespace bin | 128 } // namespace bin |
130 } // namespace dart | 129 } // namespace dart |
OLD | NEW |