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

Side by Side Diff: runtime/bin/builtin.cc

Issue 1952903002: - Fix loading of dart:html. - Remove debug print in VM service. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/builtin.h ('k') | runtime/bin/builtin_nolib.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 { "dart:web_sql", websql_source_paths_, NULL, NULL, true }, 32 { "dart:web_sql", websql_source_paths_, NULL, NULL, true },
33 { "dart:svg", svg_source_paths_, NULL, NULL, true }, 33 { "dart:svg", svg_source_paths_, NULL, NULL, true },
34 { "dart:web_audio", webaudio_source_paths_, NULL, NULL, true }, 34 { "dart:web_audio", webaudio_source_paths_, NULL, NULL, true },
35 #endif // defined(DART_NO_SNAPSHOT) 35 #endif // defined(DART_NO_SNAPSHOT)
36 36
37 // End marker. 37 // End marker.
38 { NULL, NULL, NULL, NULL, false } 38 { NULL, NULL, NULL, NULL, false }
39 }; 39 };
40 40
41 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; 41 Dart_Port Builtin::load_port_ = ILLEGAL_PORT;
42 const int Builtin::num_libs_ =
43 sizeof(Builtin::builtin_libraries_) / sizeof(Builtin::builtin_lib_props);
42 44
43 // 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
44 // library specified in 'library'. 46 // library specified in 'library'.
45 static void LoadPatchFiles(Dart_Handle library, 47 static void LoadPatchFiles(Dart_Handle library,
46 const char* patch_uri, 48 const char* patch_uri,
47 const char** patch_files) { 49 const char** patch_files) {
48 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { 50 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) {
49 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); 51 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]);
50 if (!Dart_IsString(patch_src)) { 52 if (!Dart_IsString(patch_src)) {
51 // In case reading the file caused an error, use the sources directly. 53 // In case reading the file caused an error, use the sources directly.
52 const char* source = patch_files[j + 2]; 54 const char* source = patch_files[j + 2];
53 patch_src = Dart_NewStringFromUTF8( 55 patch_src = Dart_NewStringFromUTF8(
54 reinterpret_cast<const uint8_t*>(source), strlen(source)); 56 reinterpret_cast<const uint8_t*>(source), strlen(source));
55 } 57 }
56 58
57 // Prepend the patch library URI to form a unique script URI for the patch. 59 // Prepend the patch library URI to form a unique script URI for the patch.
58 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); 60 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]);
59 char* patch_filename = DartUtils::ScopedCString(len + 1); 61 char* patch_filename = DartUtils::ScopedCString(len + 1);
60 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); 62 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]);
61 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); 63 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename);
62 64
63 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); 65 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src));
64 } 66 }
65 } 67 }
66 68
67 69
68 Dart_Handle Builtin::Source(BuiltinLibraryId id) { 70 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
69 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 71 ASSERT(static_cast<int>(id) >= 0);
70 kInvalidLibrary + 1); 72 ASSERT(static_cast<int>(id) < num_libs_);
71 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
72 73
73 // Try to read the source using the path specified for the uri. 74 // Try to read the source using the path specified for the uri.
74 const char* uri = builtin_libraries_[id].url_; 75 const char* uri = builtin_libraries_[id].url_;
75 const char** source_paths = builtin_libraries_[id].source_paths_; 76 const char** source_paths = builtin_libraries_[id].source_paths_;
76 return GetSource(source_paths, uri); 77 return GetSource(source_paths, uri);
77 } 78 }
78 79
79 80
80 Dart_Handle Builtin::PartSource(BuiltinLibraryId id, const char* part_uri) { 81 Dart_Handle Builtin::PartSource(BuiltinLibraryId id, const char* part_uri) {
81 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 82 ASSERT(static_cast<int>(id) >= 0);
82 kInvalidLibrary + 1); 83 ASSERT(static_cast<int>(id) < num_libs_);
83 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
84 84
85 // Try to read the source using the path specified for the uri. 85 // Try to read the source using the path specified for the uri.
86 const char** source_paths = builtin_libraries_[id].source_paths_; 86 const char** source_paths = builtin_libraries_[id].source_paths_;
87 return GetSource(source_paths, part_uri); 87 return GetSource(source_paths, part_uri);
88 } 88 }
89 89
90 90
91 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { 91 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) {
92 if (source_paths == NULL) { 92 if (source_paths == NULL) {
93 return Dart_Null(); // No path mapping information exists for library. 93 return Dart_Null(); // No path mapping information exists for library.
(...skipping 15 matching lines...) Expand all
109 } 109 }
110 110
111 111
112 void Builtin::SetNativeResolver(BuiltinLibraryId id) { 112 void Builtin::SetNativeResolver(BuiltinLibraryId id) {
113 UNREACHABLE(); 113 UNREACHABLE();
114 } 114 }
115 115
116 116
117 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) { 117 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) {
118 ASSERT(static_cast<int>(id) >= 0); 118 ASSERT(static_cast<int>(id) >= 0);
119 ASSERT(static_cast<int>(id) < kInvalidLibrary); 119 ASSERT(static_cast<int>(id) < num_libs_);
120 120
121 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0); 121 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0);
122 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) { 122 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) {
123 // Setup the native resolver for built in library functions. 123 // Setup the native resolver for built in library functions.
124 DART_CHECK_VALID( 124 DART_CHECK_VALID(
125 Dart_SetNativeResolver(library, NativeLookup, NativeSymbol)); 125 Dart_SetNativeResolver(library, NativeLookup, NativeSymbol));
126 } 126 }
127 if (builtin_libraries_[id].patch_url_ != NULL) { 127 if (builtin_libraries_[id].patch_url_ != NULL) {
128 ASSERT(builtin_libraries_[id].patch_paths_ != NULL); 128 ASSERT(builtin_libraries_[id].patch_paths_ != NULL);
129 LoadPatchFiles(library, 129 LoadPatchFiles(library,
(...skipping 12 matching lines...) Expand all
142 } 142 }
143 if (strcmp(url_string, builtin_libraries_[id].url_) == 0) { 143 if (strcmp(url_string, builtin_libraries_[id].url_) == 0) {
144 return static_cast<BuiltinLibraryId>(id); 144 return static_cast<BuiltinLibraryId>(id);
145 } 145 }
146 id++; 146 id++;
147 } 147 }
148 } 148 }
149 149
150 150
151 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) { 151 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
152 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 152 ASSERT(static_cast<int>(id) >= 0);
153 kInvalidLibrary + 1); 153 ASSERT(static_cast<int>(id) < num_libs_);
154 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); 154
155 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); 155 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
156 Dart_Handle library = Dart_LookupLibrary(url); 156 Dart_Handle library = Dart_LookupLibrary(url);
157 if (Dart_IsError(library)) { 157 if (Dart_IsError(library)) {
158 library = LoadLibrary(url, id); 158 library = LoadLibrary(url, id);
159 } 159 }
160 return library; 160 return library;
161 } 161 }
162 162
163 } // namespace bin 163 } // namespace bin
164 } // namespace dart 164 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin.h ('k') | runtime/bin/builtin_nolib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698