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

Side by Side Diff: bin/main.cc

Issue 8549009: Refactor the library tag handler to share code between standalone dart and the snapshot generator. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « bin/gen_snapshot.cc ('k') | bin/process_script.h » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 10
11 #include "bin/builtin.h" 11 #include "bin/builtin.h"
12 #include "bin/dartutils.h"
12 #include "bin/file.h" 13 #include "bin/file.h"
13 #include "bin/globals.h" 14 #include "bin/globals.h"
14 #include "bin/process_script.h"
15 15
16 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 16 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
17 // it is initialized to NULL. 17 // it is initialized to NULL.
18 extern const uint8_t* snapshot_buffer; 18 extern const uint8_t* snapshot_buffer;
19 19
20 20
21 // Global state that indicates whether pprof symbol information is 21 // Global state that indicates whether pprof symbol information is
22 // to be generated or not. 22 // to be generated or not.
23 static const char* generate_pprof_symbols_filename = NULL; 23 static const char* generate_pprof_symbols_filename = NULL;
24 24
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (buffer_size > 0) { 150 if (buffer_size > 0) {
151 ASSERT(buffer != NULL); 151 ASSERT(buffer != NULL);
152 pprof_file->WriteFully(buffer, buffer_size); 152 pprof_file->WriteFully(buffer, buffer_size);
153 } 153 }
154 delete pprof_file; // Closes the file. 154 delete pprof_file; // Closes the file.
155 Dart_ExitScope(); 155 Dart_ExitScope();
156 } 156 }
157 } 157 }
158 158
159 159
160 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
161 Dart_Handle library,
162 Dart_Handle url) {
163 if (!Dart_IsLibrary(library)) {
164 return Dart_Error("not a library");
165 }
166 if (!Dart_IsString8(url)) {
167 return Dart_Error("url is not a string");
168 }
169 const char* url_string = NULL;
170 Dart_Handle result = Dart_StringToCString(url, &url_string);
171 if (Dart_IsError(result)) {
172 return Dart_Error("accessing url characters failed");
173 }
174 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
175 if (tag == kCanonicalizeUrl) {
176 // If this is a Dart Scheme URL then it is not modified as it will be
177 // handled by the VM internally.
178 if (is_dart_scheme_url) {
179 return url;
180 }
181 // Create a canonical path based on the including library and current url.
182 return DartUtils::CanonicalizeURL(NULL, library, url_string);
183 }
184 if (is_dart_scheme_url) {
185 return Dart_Error("Do not know how to load '%s'", url_string);
186 }
187 result = DartUtils::LoadSource(NULL, library, url, tag, url_string);
188 if (!Dart_IsError(result) && (tag == kImportTag)) {
189 Builtin_ImportLibrary(result);
190 }
191 return result;
192 }
193
194
195 static Dart_Handle LoadScript(const char* script_name) {
196 Dart_Handle source = DartUtils::ReadStringFromFile(script_name);
197 if (Dart_IsError(source)) {
198 return source;
199 }
200 Dart_Handle url = Dart_NewString(script_name);
201
202 return Dart_LoadScript(url, source, LibraryTagHandler);
203 }
204
205
160 static void* MainIsolateInitCallback(void* data) { 206 static void* MainIsolateInitCallback(void* data) {
161 const char* script_name = reinterpret_cast<const char*>(data); 207 const char* script_name = reinterpret_cast<const char*>(data);
162 Dart_Handle library; 208 Dart_Handle library;
163 Dart_EnterScope(); 209 Dart_EnterScope();
164 210
165 // Load the specified script. 211 // Load the specified script.
166 library = LoadScript(script_name); 212 library = LoadScript(script_name);
167 if (Dart_IsError(library)) { 213 if (Dart_IsError(library)) {
168 const char* err_msg = Dart_GetError(library); 214 const char* err_msg = Dart_GetError(library);
169 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); 215 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return 255; // Indicates we encountered an error. 341 return 255; // Indicates we encountered an error.
296 } 342 }
297 free(canonical_script_name); 343 free(canonical_script_name);
298 Dart_ExitScope(); 344 Dart_ExitScope();
299 // Dump symbol information for the profiler. 345 // Dump symbol information for the profiler.
300 DumpPprofSymbolInfo(); 346 DumpPprofSymbolInfo();
301 // Shutdown the isolate. 347 // Shutdown the isolate.
302 Dart_ShutdownIsolate(); 348 Dart_ShutdownIsolate();
303 return 0; 349 return 0;
304 } 350 }
OLDNEW
« no previous file with comments | « bin/gen_snapshot.cc ('k') | bin/process_script.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698