| OLD | NEW |
| 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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 pprof_file->WriteFully(buffer, buffer_size); | 103 pprof_file->WriteFully(buffer, buffer_size); |
| 104 } | 104 } |
| 105 delete pprof_file; // Closes the file. | 105 delete pprof_file; // Closes the file. |
| 106 Dart_ExitScope(); | 106 Dart_ExitScope(); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 static void* MainIsolateInitCallback(void* data) { | 111 static void* MainIsolateInitCallback(void* data) { |
| 112 const char* script_name = reinterpret_cast<const char*>(data); | 112 const char* script_name = reinterpret_cast<const char*>(data); |
| 113 Dart_Result result; | 113 Dart_Handle library; |
| 114 Dart_EnterScope(); | 114 Dart_EnterScope(); |
| 115 | 115 |
| 116 // Load the specified script. | 116 // Load the specified script. |
| 117 result = LoadScript(script_name); | 117 library = LoadScript(script_name); |
| 118 if (!Dart_IsValidResult(result)) { | 118 if (!Dart_IsValid(library)) { |
| 119 const char* err_msg = Dart_GetErrorCString(result); | 119 const char* err_msg = Dart_GetError(library); |
| 120 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); | 120 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| 121 Dart_ExitScope(); | 121 Dart_ExitScope(); |
| 122 exit(255); | 122 exit(255); |
| 123 } | 123 } |
| 124 | 124 |
| 125 Dart_Handle library = Dart_GetResult(result); | |
| 126 if (!Dart_IsLibrary(library)) { | 125 if (!Dart_IsLibrary(library)) { |
| 127 fprintf(stderr, | 126 fprintf(stderr, |
| 128 "Expected a library when loading script: %s", | 127 "Expected a library when loading script: %s", |
| 129 script_name); | 128 script_name); |
| 130 Dart_ExitScope(); | 129 Dart_ExitScope(); |
| 131 exit(255); | 130 exit(255); |
| 132 } | 131 } |
| 133 Builtin_ImportLibrary(library); | 132 Builtin_ImportLibrary(library); |
| 134 // Setup the native resolver for built in library functions. | 133 // Setup the native resolver for built in library functions. |
| 135 Builtin_SetNativeResolver(); | 134 Builtin_SetNativeResolver(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 149 for (int i = 0; i < options.count(); i++) { | 148 for (int i = 0; i < options.count(); i++) { |
| 150 if (strcmp(options.GetArgument(i), "--compile_all") == 0) { | 149 if (strcmp(options.GetArgument(i), "--compile_all") == 0) { |
| 151 return true; | 150 return true; |
| 152 } | 151 } |
| 153 } | 152 } |
| 154 return false; | 153 return false; |
| 155 } | 154 } |
| 156 | 155 |
| 157 | 156 |
| 158 static void PrintObject(FILE* out, Dart_Handle object) { | 157 static void PrintObject(FILE* out, Dart_Handle object) { |
| 159 Dart_Result result = Dart_ObjectToString(object); | 158 Dart_Handle result = Dart_ObjectToString(object); |
| 160 if (Dart_IsValidResult(result)) { | 159 if (Dart_IsValid(result)) { |
| 161 Dart_Handle string = Dart_GetResult(result); | 160 PrintString(out, result); |
| 162 PrintString(out, string); | |
| 163 } else { | 161 } else { |
| 164 fprintf(out, "%s\n", Dart_GetErrorCString(result)); | 162 fprintf(out, "%s\n", Dart_GetError(result)); |
| 165 } | 163 } |
| 166 } | 164 } |
| 167 | 165 |
| 168 | 166 |
| 169 int main(int argc, char** argv) { | 167 int main(int argc, char** argv) { |
| 170 char* script_name; | 168 char* script_name; |
| 171 CommandLineOptions vm_options(argc); | 169 CommandLineOptions vm_options(argc); |
| 172 CommandLineOptions dart_options(argc); | 170 CommandLineOptions dart_options(argc); |
| 173 | 171 |
| 174 // Parse command line arguments. | 172 // Parse command line arguments. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 197 canonical_script_name); | 195 canonical_script_name); |
| 198 if (isolate == NULL) { | 196 if (isolate == NULL) { |
| 199 free(canonical_script_name); | 197 free(canonical_script_name); |
| 200 return 255; | 198 return 255; |
| 201 } | 199 } |
| 202 | 200 |
| 203 Dart_EnterScope(); | 201 Dart_EnterScope(); |
| 204 // TODO(asiva): Create a dart options object that can be accessed from | 202 // TODO(asiva): Create a dart options object that can be accessed from |
| 205 // dart code. | 203 // dart code. |
| 206 if (HasCompileAll(vm_options)) { | 204 if (HasCompileAll(vm_options)) { |
| 207 Dart_Result result = Dart_CompileAll(); | 205 Dart_Handle result = Dart_CompileAll(); |
| 208 if (!Dart_IsValidResult(result)) { | 206 if (!Dart_IsValid(result)) { |
| 209 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 207 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 210 Dart_ExitScope(); | 208 Dart_ExitScope(); |
| 211 Dart_ShutdownIsolate(); | 209 Dart_ShutdownIsolate(); |
| 212 free(canonical_script_name); | 210 free(canonical_script_name); |
| 213 return 255; // Indicates we encountered an error. | 211 return 255; // Indicates we encountered an error. |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 // Lookup and invoke the top level main function. | 215 // Lookup and invoke the top level main function. |
| 218 Dart_Handle script_url = Dart_NewString(canonical_script_name); | 216 Dart_Handle script_url = Dart_NewString(canonical_script_name); |
| 219 Dart_Result result = Dart_LookupLibrary(script_url); | 217 Dart_Handle library = Dart_LookupLibrary(script_url); |
| 220 if (!Dart_IsValidResult(result)) { | 218 if (!Dart_IsValid(library)) { |
| 221 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 219 fprintf(stderr, "%s\n", Dart_GetError(library)); |
| 222 Dart_ExitScope(); | 220 Dart_ExitScope(); |
| 223 Dart_ShutdownIsolate(); | 221 Dart_ShutdownIsolate(); |
| 224 free(canonical_script_name); | 222 free(canonical_script_name); |
| 225 return 255; // Indicates we encountered an error. | 223 return 255; // Indicates we encountered an error. |
| 226 } | 224 } |
| 227 Dart_Handle library = Dart_GetResult(result); | 225 Dart_Handle result = Dart_InvokeStatic(library, |
| 228 result = Dart_InvokeStatic(library, | 226 Dart_NewString(""), |
| 229 Dart_NewString(""), | 227 Dart_NewString("main"), |
| 230 Dart_NewString("main"), | 228 0, |
| 231 0, | 229 NULL); |
| 232 NULL); | 230 if (Dart_IsValid(result)) { |
| 233 | 231 if (Dart_ExceptionOccurred(result)) { |
| 234 if (Dart_IsValidResult(result)) { | |
| 235 Dart_Handle result_obj = Dart_GetResult(result); | |
| 236 if (Dart_ExceptionOccurred(result_obj)) { | |
| 237 // Print the exception object. | 232 // Print the exception object. |
| 238 fprintf(stderr, "An unhandled exception has been thrown\n"); | 233 fprintf(stderr, "An unhandled exception has been thrown\n"); |
| 239 Dart_Result exception_result = Dart_GetException(result_obj); | 234 Dart_Handle exception_result = Dart_GetException(result); |
| 240 ASSERT(Dart_IsValidResult(exception_result)); | 235 ASSERT(Dart_IsValid(exception_result)); |
| 241 PrintObject(stderr, Dart_GetResult(exception_result)); | 236 PrintObject(stderr, exception_result); |
| 242 // Print the stack trace. | 237 // Print the stack trace. |
| 243 Dart_Result stacktrace = Dart_GetStacktrace(result_obj); | 238 Dart_Handle stacktrace = Dart_GetStacktrace(result); |
| 244 ASSERT(Dart_IsValidResult(stacktrace)); | 239 ASSERT(Dart_IsValid(stacktrace)); |
| 245 PrintObject(stderr, Dart_GetResult(stacktrace)); | 240 PrintObject(stderr, stacktrace); |
| 246 fprintf(stderr, "\n"); | 241 fprintf(stderr, "\n"); |
| 247 Dart_ExitScope(); | 242 Dart_ExitScope(); |
| 248 Dart_ShutdownIsolate(); | 243 Dart_ShutdownIsolate(); |
| 249 free(canonical_script_name); | 244 free(canonical_script_name); |
| 250 return 255; // We had an unhandled exception, hence indicate an error. | 245 return 255; // We had an unhandled exception, hence indicate an error. |
| 251 } | 246 } |
| 252 } else { | 247 } else { |
| 253 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 248 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 254 Dart_ExitScope(); | 249 Dart_ExitScope(); |
| 255 Dart_ShutdownIsolate(); | 250 Dart_ShutdownIsolate(); |
| 256 free(canonical_script_name); | 251 free(canonical_script_name); |
| 257 return 255; // Indicates we encountered an error. | 252 return 255; // Indicates we encountered an error. |
| 258 } | 253 } |
| 259 // Keep handling messages until the last active receive port is closed. | 254 // Keep handling messages until the last active receive port is closed. |
| 260 result = Dart_RunLoop(); | 255 result = Dart_RunLoop(); |
| 261 if (!Dart_IsValidResult(result)) { | 256 if (!Dart_IsValid(result)) { |
| 262 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 257 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 263 Dart_ExitScope(); | 258 Dart_ExitScope(); |
| 264 Dart_ShutdownIsolate(); | 259 Dart_ShutdownIsolate(); |
| 265 free(canonical_script_name); | 260 free(canonical_script_name); |
| 266 return 255; // Indicates we encountered an error. | 261 return 255; // Indicates we encountered an error. |
| 267 } | 262 } |
| 268 free(canonical_script_name); | 263 free(canonical_script_name); |
| 269 Dart_ExitScope(); | 264 Dart_ExitScope(); |
| 270 // Dump symbol information for the profiler. | 265 // Dump symbol information for the profiler. |
| 271 DumpPprofSymbolInfo(); | 266 DumpPprofSymbolInfo(); |
| 272 // Shutdown the isolate. | 267 // Shutdown the isolate. |
| 273 Dart_ShutdownIsolate(); | 268 Dart_ShutdownIsolate(); |
| 274 return 0; | 269 return 0; |
| 275 } | 270 } |
| OLD | NEW |