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

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

Issue 10386107: Implement spawnUri from dart:isolate. This function allows us to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/main.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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 ASSERT(file != NULL); 109 ASSERT(file != NULL);
110 for (intptr_t i = 0; i < size; i++) { 110 for (intptr_t i = 0; i < size; i++) {
111 file->WriteByte(buffer[i]); 111 file->WriteByte(buffer[i]);
112 } 112 }
113 delete file; 113 delete file;
114 } 114 }
115 115
116 116
117 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, 117 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
118 Dart_Handle library, 118 Dart_Handle library,
119 Dart_Handle url, 119 Dart_Handle url) {
120 Dart_Handle import_map) {
121 if (!Dart_IsLibrary(library)) { 120 if (!Dart_IsLibrary(library)) {
122 return Dart_Error("not a library"); 121 return Dart_Error("not a library");
123 } 122 }
124 if (!Dart_IsString8(url)) { 123 if (!Dart_IsString8(url)) {
125 return Dart_Error("url is not a string"); 124 return Dart_Error("url is not a string");
126 } 125 }
127 const char* url_string = NULL; 126 const char* url_string = NULL;
128 Dart_Handle result = Dart_StringToCString(url, &url_string); 127 Dart_Handle result = Dart_StringToCString(url, &url_string);
129 if (Dart_IsError(result)) { 128 if (Dart_IsError(result)) {
130 return result; 129 return result;
131 } 130 }
132 131
133 // If the URL starts with "dart:" then it is handled specially. 132 // If the URL starts with "dart:" then it is handled specially.
134 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); 133 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
135 if (tag == kCanonicalizeUrl) { 134 if (tag == kCanonicalizeUrl) {
136 if (is_dart_scheme_url) { 135 if (is_dart_scheme_url) {
137 return url; 136 return url;
138 } 137 }
139 return DartUtils::CanonicalizeURL(url_mapping, library, url_string); 138 return DartUtils::CanonicalizeURL(url_mapping, library, url_string);
140 } 139 }
141 return DartUtils::LoadSource(url_mapping, 140 return DartUtils::LoadSource(url_mapping,
142 library, 141 library,
143 url, 142 url,
144 tag, 143 tag,
145 url_string, 144 url_string);
146 import_map);
147 } 145 }
148 146
149 147
150 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { 148 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
151 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); 149 Dart_Handle source = DartUtils::ReadStringFromFile(script_name);
152 if (Dart_IsError(source)) { 150 if (Dart_IsError(source)) {
153 return source; // source contains the error string. 151 return source; // source contains the error string.
154 } 152 }
155 Dart_Handle url = Dart_NewString(script_name); 153 Dart_Handle url = Dart_NewString(script_name);
156 Dart_Handle import_map = Dart_NewList(0);
157 154
158 return Dart_LoadScript(url, 155 return Dart_LoadScript(url, source);
159 source,
160 import_map);
161 } 156 }
162 157
163 158
164 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, 159 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag,
165 Dart_Handle library, 160 Dart_Handle library,
166 Dart_Handle url, 161 Dart_Handle url) {
167 Dart_Handle import_map) {
168 if (!Dart_IsLibrary(library)) { 162 if (!Dart_IsLibrary(library)) {
169 return Dart_Error("not a library"); 163 return Dart_Error("not a library");
170 } 164 }
171 if (!Dart_IsString8(url)) { 165 if (!Dart_IsString8(url)) {
172 return Dart_Error("url is not a string"); 166 return Dart_Error("url is not a string");
173 } 167 }
174 const char* url_string = NULL; 168 const char* url_string = NULL;
175 Dart_Handle result = Dart_StringToCString(url, &url_string); 169 Dart_Handle result = Dart_StringToCString(url, &url_string);
176 if (Dart_IsError(result)) { 170 if (Dart_IsError(result)) {
177 return result; 171 return result;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 251 }
258 252
259 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 253 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
260 254
261 // Initialize the Dart VM. 255 // Initialize the Dart VM.
262 // Note: We don't expect isolates to be created from dart code during 256 // Note: We don't expect isolates to be created from dart code during
263 // snapshot generation. 257 // snapshot generation.
264 Dart_Initialize(NULL, NULL); 258 Dart_Initialize(NULL, NULL);
265 259
266 char* error; 260 char* error;
267 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, &error); 261 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
268 if (isolate == NULL) { 262 if (isolate == NULL) {
269 fprintf(stderr, "%s", error); 263 fprintf(stderr, "%s", error);
270 free(error); 264 free(error);
271 exit(255); 265 exit(255);
272 } 266 }
273 267
274 Dart_Handle result; 268 Dart_Handle result;
275 Dart_Handle library; 269 Dart_Handle library;
276 Dart_EnterScope(); 270 Dart_EnterScope();
277 271
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 exit(255); 320 exit(255);
327 } 321 }
328 // Now write the snapshot out to specified file and exit. 322 // Now write the snapshot out to specified file and exit.
329 WriteSnapshotFile(buffer, size); 323 WriteSnapshotFile(buffer, size);
330 Dart_ExitScope(); 324 Dart_ExitScope();
331 325
332 // Shutdown the isolate. 326 // Shutdown the isolate.
333 Dart_ShutdownIsolate(); 327 Dart_ShutdownIsolate();
334 return 0; 328 return 0;
335 } 329 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698