| OLD | NEW |
| 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 #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 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Parse out options to be passed to dart main. | 144 // Parse out options to be passed to dart main. |
| 145 while (i < argc) { | 145 while (i < argc) { |
| 146 dart_options->AddArgument(argv[i]); | 146 dart_options->AddArgument(argv[i]); |
| 147 i += 1; | 147 i += 1; |
| 148 } | 148 } |
| 149 | 149 |
| 150 return 0; | 150 return 0; |
| 151 } | 151 } |
| 152 | 152 |
| 153 | 153 |
| 154 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options) { | 154 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, |
| 155 char* script_name) { |
| 155 int options_count = options->count(); | 156 int options_count = options->count(); |
| 157 Dart_Handle dart_script = Dart_NewString(script_name); |
| 158 if (Dart_IsError(dart_script)) { |
| 159 return dart_script; |
| 160 } |
| 156 Dart_Handle dart_arguments = Dart_NewList(options_count); | 161 Dart_Handle dart_arguments = Dart_NewList(options_count); |
| 157 if (Dart_IsError(dart_arguments)) { | 162 if (Dart_IsError(dart_arguments)) { |
| 158 return dart_arguments; | 163 return dart_arguments; |
| 159 } | 164 } |
| 160 for (int i = 0; i < options_count; i++) { | 165 for (int i = 0; i < options_count; i++) { |
| 161 Dart_Handle argument_value = Dart_NewString(options->GetArgument(i)); | 166 Dart_Handle argument_value = Dart_NewString(options->GetArgument(i)); |
| 162 if (Dart_IsError(argument_value)) { | 167 if (Dart_IsError(argument_value)) { |
| 163 return argument_value; | 168 return argument_value; |
| 164 } | 169 } |
| 165 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); | 170 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 177 } | 182 } |
| 178 Dart_Handle runtime_options_class_name = Dart_NewString("RuntimeOptions"); | 183 Dart_Handle runtime_options_class_name = Dart_NewString("RuntimeOptions"); |
| 179 if (Dart_IsError(runtime_options_class_name)) { | 184 if (Dart_IsError(runtime_options_class_name)) { |
| 180 return runtime_options_class_name; | 185 return runtime_options_class_name; |
| 181 } | 186 } |
| 182 Dart_Handle runtime_options_class = Dart_GetClass( | 187 Dart_Handle runtime_options_class = Dart_GetClass( |
| 183 core_lib, runtime_options_class_name); | 188 core_lib, runtime_options_class_name); |
| 184 if (Dart_IsError(runtime_options_class)) { | 189 if (Dart_IsError(runtime_options_class)) { |
| 185 return runtime_options_class; | 190 return runtime_options_class; |
| 186 } | 191 } |
| 192 Dart_Handle script_name_name = Dart_NewString("_nativeScript"); |
| 193 if (Dart_IsError(script_name_name)) { |
| 194 return script_name_name; |
| 195 } |
| 196 Dart_Handle set_script_name = |
| 197 Dart_SetStaticField(runtime_options_class, script_name_name, dart_script); |
| 198 if (Dart_IsError(set_script_name)) { |
| 199 return set_script_name; |
| 200 } |
| 187 Dart_Handle native_name = Dart_NewString("_nativeArguments"); | 201 Dart_Handle native_name = Dart_NewString("_nativeArguments"); |
| 188 if (Dart_IsError(native_name)) { | 202 if (Dart_IsError(native_name)) { |
| 189 return native_name; | 203 return native_name; |
| 190 } | 204 } |
| 191 | 205 |
| 192 return Dart_SetStaticField(runtime_options_class, | 206 return Dart_SetStaticField(runtime_options_class, |
| 193 native_name, | 207 native_name, |
| 194 dart_arguments); | 208 dart_arguments); |
| 195 } | 209 } |
| 196 | 210 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 if (Dart_IsError(result)) { | 496 if (Dart_IsError(result)) { |
| 483 fprintf(stderr, "%s\n", Dart_GetError(result)); | 497 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 484 Dart_ExitScope(); | 498 Dart_ExitScope(); |
| 485 Dart_ShutdownIsolate(); | 499 Dart_ShutdownIsolate(); |
| 486 free(canonical_script_name); | 500 free(canonical_script_name); |
| 487 return 255; // Indicates we encountered an error. | 501 return 255; // Indicates we encountered an error. |
| 488 } | 502 } |
| 489 } | 503 } |
| 490 | 504 |
| 491 // Create a dart options object that can be accessed from dart code. | 505 // Create a dart options object that can be accessed from dart code. |
| 492 Dart_Handle options_result = SetupRuntimeOptions(&dart_options); | 506 Dart_Handle options_result = |
| 507 SetupRuntimeOptions(&dart_options, canonical_script_name); |
| 493 if (Dart_IsError(options_result)) { | 508 if (Dart_IsError(options_result)) { |
| 494 fprintf(stderr, "%s\n", Dart_GetError(options_result)); | 509 fprintf(stderr, "%s\n", Dart_GetError(options_result)); |
| 495 Dart_ExitScope(); | 510 Dart_ExitScope(); |
| 496 Dart_ShutdownIsolate(); | 511 Dart_ShutdownIsolate(); |
| 497 free(canonical_script_name); | 512 free(canonical_script_name); |
| 498 return 255; // Indicates we encountered an error. | 513 return 255; // Indicates we encountered an error. |
| 499 } | 514 } |
| 500 // Lookup the library of the main script. | 515 // Lookup the library of the main script. |
| 501 Dart_Handle script_url = Dart_NewString(canonical_script_name); | 516 Dart_Handle script_url = Dart_NewString(canonical_script_name); |
| 502 Dart_Handle library = Dart_LookupLibrary(script_url); | 517 Dart_Handle library = Dart_LookupLibrary(script_url); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 Dart_ExitScope(); | 561 Dart_ExitScope(); |
| 547 // Dump symbol information for the profiler. | 562 // Dump symbol information for the profiler. |
| 548 DumpPprofSymbolInfo(); | 563 DumpPprofSymbolInfo(); |
| 549 // Shutdown the isolate. | 564 // Shutdown the isolate. |
| 550 Dart_ShutdownIsolate(); | 565 Dart_ShutdownIsolate(); |
| 551 // Terminate event handler. | 566 // Terminate event handler. |
| 552 EventHandler::Terminate(); | 567 EventHandler::Terminate(); |
| 553 | 568 |
| 554 return 0; | 569 return 0; |
| 555 } | 570 } |
| OLD | NEW |