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

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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 249 }
256 250
257 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 251 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
258 252
259 // Initialize the Dart VM. 253 // Initialize the Dart VM.
260 // Note: We don't expect isolates to be created from dart code during 254 // Note: We don't expect isolates to be created from dart code during
261 // snapshot generation. 255 // snapshot generation.
262 Dart_Initialize(NULL, NULL); 256 Dart_Initialize(NULL, NULL);
263 257
264 char* error; 258 char* error;
265 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, &error); 259 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
266 if (isolate == NULL) { 260 if (isolate == NULL) {
267 fprintf(stderr, "%s", error); 261 fprintf(stderr, "%s", error);
268 free(error); 262 free(error);
269 exit(255); 263 exit(255);
270 } 264 }
271 265
272 Dart_Handle result; 266 Dart_Handle result;
273 Dart_Handle library; 267 Dart_Handle library;
274 Dart_EnterScope(); 268 Dart_EnterScope();
275 269
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 exit(255); 316 exit(255);
323 } 317 }
324 // Now write the snapshot out to specified file and exit. 318 // Now write the snapshot out to specified file and exit.
325 WriteSnapshotFile(buffer, size); 319 WriteSnapshotFile(buffer, size);
326 Dart_ExitScope(); 320 Dart_ExitScope();
327 321
328 // Shutdown the isolate. 322 // Shutdown the isolate.
329 Dart_ShutdownIsolate(); 323 Dart_ShutdownIsolate();
330 return 0; 324 return 0;
331 } 325 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/main.cc » ('j') | runtime/lib/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698