OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 v8::Handle<v8::String> ReadFile(const char* name); | 60 v8::Handle<v8::String> ReadFile(const char* name); |
61 void ReportException(v8::TryCatch* handler); | 61 void ReportException(v8::TryCatch* handler); |
62 | 62 |
63 | 63 |
64 static bool run_shell; | 64 static bool run_shell; |
65 | 65 |
66 | 66 |
67 int main(int argc, char* argv[]) { | 67 int main(int argc, char* argv[]) { |
68 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 68 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
69 run_shell = (argc == 1); | 69 run_shell = (argc == 1); |
70 v8::HandleScope handle_scope; | 70 int result; |
71 v8::Persistent<v8::Context> context = CreateShellContext(); | 71 { |
72 if (context.IsEmpty()) { | 72 v8::HandleScope handle_scope; |
73 printf("Error creating context\n"); | 73 v8::Persistent<v8::Context> context = CreateShellContext(); |
74 return 1; | 74 if (context.IsEmpty()) { |
| 75 printf("Error creating context\n"); |
| 76 return 1; |
| 77 } |
| 78 context->Enter(); |
| 79 result = RunMain(argc, argv); |
| 80 if (run_shell) RunShell(context); |
| 81 context->Exit(); |
| 82 context.Dispose(); |
75 } | 83 } |
76 context->Enter(); | |
77 int result = RunMain(argc, argv); | |
78 if (run_shell) RunShell(context); | |
79 context->Exit(); | |
80 context.Dispose(); | |
81 v8::V8::Dispose(); | 84 v8::V8::Dispose(); |
82 return result; | 85 return result; |
83 } | 86 } |
84 | 87 |
85 | 88 |
86 // Extracts a C string from a V8 Utf8Value. | 89 // Extracts a C string from a V8 Utf8Value. |
87 const char* ToCString(const v8::String::Utf8Value& value) { | 90 const char* ToCString(const v8::String::Utf8Value& value) { |
88 return *value ? *value : "<string conversion failed>"; | 91 return *value ? *value : "<string conversion failed>"; |
89 } | 92 } |
90 | 93 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 printf("^"); | 331 printf("^"); |
329 } | 332 } |
330 printf("\n"); | 333 printf("\n"); |
331 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 334 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
332 if (stack_trace.length() > 0) { | 335 if (stack_trace.length() > 0) { |
333 const char* stack_trace_string = ToCString(stack_trace); | 336 const char* stack_trace_string = ToCString(stack_trace); |
334 printf("%s\n", stack_trace_string); | 337 printf("%s\n", stack_trace_string); |
335 } | 338 } |
336 } | 339 } |
337 } | 340 } |
OLD | NEW |