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

Side by Side Diff: bin/main.cc

Issue 8371016: Fix infinite recursion when dealing with cyclic library dependencies. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 2 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 | « bin/file_win.cc ('k') | bin/process_script.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) 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 <assert.h> 5 #include <assert.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return 255; 182 return 255;
183 } 183 }
184 184
185 // Initialize the Dart VM. 185 // Initialize the Dart VM.
186 Dart_Initialize(vm_options.count(), 186 Dart_Initialize(vm_options.count(),
187 vm_options.arguments(), 187 vm_options.arguments(),
188 MainIsolateInitCallback); 188 MainIsolateInitCallback);
189 189
190 // Create an isolate. As a side effect, MainIsolateInitCallback 190 // Create an isolate. As a side effect, MainIsolateInitCallback
191 // gets called, which loads the scripts and libraries. 191 // gets called, which loads the scripts and libraries.
192 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, script_name); 192 char* canonical_script_name = File::GetCanonicalPath(script_name);
193 if (canonical_script_name == NULL) {
194 fprintf(stderr, "Unable to find '%s'\n", script_name);
195 return 255; // Indicates we encountered an error.
196 }
197 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer,
198 canonical_script_name);
193 if (isolate == NULL) { 199 if (isolate == NULL) {
200 free(canonical_script_name);
194 return 255; 201 return 255;
195 } 202 }
196 203
197 Dart_EnterScope(); 204 Dart_EnterScope();
198 // TODO(asiva): Create a dart options object that can be accessed from 205 // TODO(asiva): Create a dart options object that can be accessed from
199 // dart code. 206 // dart code.
200 if (HasCompileAll(vm_options)) { 207 if (HasCompileAll(vm_options)) {
201 Dart_Result result = Dart_CompileAll(); 208 Dart_Result result = Dart_CompileAll();
202 if (!Dart_IsValidResult(result)) { 209 if (!Dart_IsValidResult(result)) {
203 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); 210 fprintf(stderr, "%s\n", Dart_GetErrorCString(result));
204 Dart_ExitScope(); 211 Dart_ExitScope();
205 Dart_ShutdownIsolate(); 212 Dart_ShutdownIsolate();
213 free(canonical_script_name);
206 return 255; // Indicates we encountered an error. 214 return 255; // Indicates we encountered an error.
207 } 215 }
208 } 216 }
209 217
210 // Lookup and invoke the top level main function. 218 // Lookup and invoke the top level main function.
211 Dart_Handle script_url = Dart_NewString(script_name); 219 Dart_Handle script_url = Dart_NewString(canonical_script_name);
212 Dart_Result result = Dart_LookupLibrary(script_url); 220 Dart_Result result = Dart_LookupLibrary(script_url);
213 if (!Dart_IsValidResult(result)) { 221 if (!Dart_IsValidResult(result)) {
214 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); 222 fprintf(stderr, "%s\n", Dart_GetErrorCString(result));
215 Dart_ExitScope(); 223 Dart_ExitScope();
216 Dart_ShutdownIsolate(); 224 Dart_ShutdownIsolate();
225 free(canonical_script_name);
217 return 255; // Indicates we encountered an error. 226 return 255; // Indicates we encountered an error.
218 } 227 }
219 Dart_Handle library = Dart_GetResult(result); 228 Dart_Handle library = Dart_GetResult(result);
220 result = Dart_InvokeStatic(library, 229 result = Dart_InvokeStatic(library,
221 Dart_NewString(""), 230 Dart_NewString(""),
222 Dart_NewString("main"), 231 Dart_NewString("main"),
223 0, 232 0,
224 NULL); 233 NULL);
225 234
226 if (Dart_IsValidResult(result)) { 235 if (Dart_IsValidResult(result)) {
227 Dart_Handle result_obj = Dart_GetResult(result); 236 Dart_Handle result_obj = Dart_GetResult(result);
228 if (Dart_ExceptionOccurred(result_obj)) { 237 if (Dart_ExceptionOccurred(result_obj)) {
229 // Print the exception object. 238 // Print the exception object.
230 fprintf(stderr, "An unhandled exception has been thrown\n"); 239 fprintf(stderr, "An unhandled exception has been thrown\n");
231 Dart_Result exception_result = Dart_GetException(result_obj); 240 Dart_Result exception_result = Dart_GetException(result_obj);
232 assert(Dart_IsValidResult(exception_result)); 241 assert(Dart_IsValidResult(exception_result));
233 PrintObject(stderr, Dart_GetResult(exception_result)); 242 PrintObject(stderr, Dart_GetResult(exception_result));
234 // Print the stack trace. 243 // Print the stack trace.
235 Dart_Result stacktrace = Dart_GetStacktrace(result_obj); 244 Dart_Result stacktrace = Dart_GetStacktrace(result_obj);
236 assert(Dart_IsValidResult(stacktrace)); 245 assert(Dart_IsValidResult(stacktrace));
237 PrintObject(stderr, Dart_GetResult(stacktrace)); 246 PrintObject(stderr, Dart_GetResult(stacktrace));
238 fprintf(stderr, "\n"); 247 fprintf(stderr, "\n");
239 Dart_ExitScope(); 248 Dart_ExitScope();
240 Dart_ShutdownIsolate(); 249 Dart_ShutdownIsolate();
250 free(canonical_script_name);
241 return 255; // We had an unhandled exception, hence indicate an error. 251 return 255; // We had an unhandled exception, hence indicate an error.
242 } 252 }
243 } else { 253 } else {
244 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); 254 fprintf(stderr, "%s\n", Dart_GetErrorCString(result));
245 Dart_ExitScope(); 255 Dart_ExitScope();
246 Dart_ShutdownIsolate(); 256 Dart_ShutdownIsolate();
257 free(canonical_script_name);
247 return 255; // Indicates we encountered an error. 258 return 255; // Indicates we encountered an error.
248 } 259 }
249 // Keep handling messages until the last active receive port is closed. 260 // Keep handling messages until the last active receive port is closed.
250 result = Dart_RunLoop(); 261 result = Dart_RunLoop();
251 if (!Dart_IsValidResult(result)) { 262 if (!Dart_IsValidResult(result)) {
252 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); 263 fprintf(stderr, "%s\n", Dart_GetErrorCString(result));
253 Dart_ExitScope(); 264 Dart_ExitScope();
254 Dart_ShutdownIsolate(); 265 Dart_ShutdownIsolate();
266 free(canonical_script_name);
255 return 255; // Indicates we encountered an error. 267 return 255; // Indicates we encountered an error.
256 } 268 }
269 free(canonical_script_name);
257 Dart_ExitScope(); 270 Dart_ExitScope();
258 // Dump symbol information for the profiler. 271 // Dump symbol information for the profiler.
259 DumpPprofSymbolInfo(); 272 DumpPprofSymbolInfo();
260 // Shutdown the isolate. 273 // Shutdown the isolate.
261 Dart_ShutdownIsolate(); 274 Dart_ShutdownIsolate();
262 return 0; 275 return 0;
263 } 276 }
OLDNEW
« no previous file with comments | « bin/file_win.cc ('k') | bin/process_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698