| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include <fcntl.h> | 34 #include <fcntl.h> |
| 35 #include <string.h> | 35 #include <string.h> |
| 36 #include <stdio.h> | 36 #include <stdio.h> |
| 37 #include <stdlib.h> | 37 #include <stdlib.h> |
| 38 | 38 |
| 39 // When building with V8 in a shared library we cannot use functions which | 39 // When building with V8 in a shared library we cannot use functions which |
| 40 // is not explicitly a part of the public V8 API. This extensive use of | 40 // is not explicitly a part of the public V8 API. This extensive use of |
| 41 // #ifndef USING_V8_SHARED/#endif is a hack until we can resolve whether to | 41 // #ifndef USING_V8_SHARED/#endif is a hack until we can resolve whether to |
| 42 // still use the shell sample for testing or change to use the developer | 42 // still use the shell sample for testing or change to use the developer |
| 43 // shell d8 TODO(1272). | 43 // shell d8 TODO(1272). |
| 44 #ifndef USING_V8_SHARED | 44 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 45 #include "../src/v8.h" | 45 #include "../src/v8.h" |
| 46 #endif // USING_V8_SHARED | 46 #endif // USING_V8_SHARED |
| 47 | 47 |
| 48 #if !defined(_WIN32) && !defined(_WIN64) | 48 #if !defined(_WIN32) && !defined(_WIN64) |
| 49 #include <unistd.h> // NOLINT | 49 #include <unistd.h> // NOLINT |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 static void ExitShell(int exit_code) { | 52 static void ExitShell(int exit_code) { |
| 53 // Use _exit instead of exit to avoid races between isolate | 53 // Use _exit instead of exit to avoid races between isolate |
| 54 // threads and static destructors. | 54 // threads and static destructors. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 79 v8::Handle<v8::Value> PixelArray(const v8::Arguments& args); | 79 v8::Handle<v8::Value> PixelArray(const v8::Arguments& args); |
| 80 v8::Handle<v8::String> ReadFile(const char* name); | 80 v8::Handle<v8::String> ReadFile(const char* name); |
| 81 void ReportException(v8::TryCatch* handler); | 81 void ReportException(v8::TryCatch* handler); |
| 82 | 82 |
| 83 | 83 |
| 84 static bool last_run = true; | 84 static bool last_run = true; |
| 85 | 85 |
| 86 class SourceGroup { | 86 class SourceGroup { |
| 87 public: | 87 public: |
| 88 SourceGroup() : | 88 SourceGroup() : |
| 89 #ifndef USING_V8_SHARED | 89 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 90 next_semaphore_(v8::internal::OS::CreateSemaphore(0)), | 90 next_semaphore_(v8::internal::OS::CreateSemaphore(0)), |
| 91 done_semaphore_(v8::internal::OS::CreateSemaphore(0)), | 91 done_semaphore_(v8::internal::OS::CreateSemaphore(0)), |
| 92 thread_(NULL), | 92 thread_(NULL), |
| 93 #endif // USING_V8_SHARED | 93 #endif // USING_V8_SHARED |
| 94 argv_(NULL), | 94 argv_(NULL), |
| 95 begin_offset_(0), | 95 begin_offset_(0), |
| 96 end_offset_(0) { } | 96 end_offset_(0) { } |
| 97 | 97 |
| 98 void Begin(char** argv, int offset) { | 98 void Begin(char** argv, int offset) { |
| 99 argv_ = const_cast<const char**>(argv); | 99 argv_ = const_cast<const char**>(argv); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 127 continue; | 127 continue; |
| 128 } | 128 } |
| 129 if (!ExecuteString(source, file_name, false, true)) { | 129 if (!ExecuteString(source, file_name, false, true)) { |
| 130 ExitShell(1); | 130 ExitShell(1); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 #ifndef USING_V8_SHARED | 137 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 138 void StartExecuteInThread() { | 138 void StartExecuteInThread() { |
| 139 if (thread_ == NULL) { | 139 if (thread_ == NULL) { |
| 140 thread_ = new IsolateThread(this); | 140 thread_ = new IsolateThread(this); |
| 141 thread_->Start(); | 141 thread_->Start(); |
| 142 } | 142 } |
| 143 next_semaphore_->Signal(); | 143 next_semaphore_->Signal(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void WaitForThread() { | 146 void WaitForThread() { |
| 147 if (thread_ == NULL) return; | 147 if (thread_ == NULL) return; |
| 148 if (last_run) { | 148 if (last_run) { |
| 149 thread_->Join(); | 149 thread_->Join(); |
| 150 thread_ = NULL; | 150 thread_ = NULL; |
| 151 } else { | 151 } else { |
| 152 done_semaphore_->Wait(); | 152 done_semaphore_->Wait(); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 #endif // USING_V8_SHARED | 155 #endif // USING_V8_SHARED |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 #ifndef USING_V8_SHARED | 158 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 159 static v8::internal::Thread::Options GetThreadOptions() { | 159 static v8::internal::Thread::Options GetThreadOptions() { |
| 160 v8::internal::Thread::Options options; | 160 v8::internal::Thread::Options options; |
| 161 options.name = "IsolateThread"; | 161 options.name = "IsolateThread"; |
| 162 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less | 162 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less |
| 163 // which is not enough to parse the big literal expressions used in tests. | 163 // which is not enough to parse the big literal expressions used in tests. |
| 164 // The stack size should be at least StackGuard::kLimitSize + some | 164 // The stack size should be at least StackGuard::kLimitSize + some |
| 165 // OS-specific padding for thread startup code. | 165 // OS-specific padding for thread startup code. |
| 166 options.stack_size = 2 << 20; // 2 Mb seems to be enough | 166 options.stack_size = 2 << 20; // 2 Mb seems to be enough |
| 167 return options; | 167 return options; |
| 168 } | 168 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 context->Enter(); | 221 context->Enter(); |
| 222 if (context.IsEmpty()) { | 222 if (context.IsEmpty()) { |
| 223 printf("Error creating context\n"); | 223 printf("Error creating context\n"); |
| 224 return 1; | 224 return 1; |
| 225 } | 225 } |
| 226 | 226 |
| 227 bool run_shell = (argc == 1); | 227 bool run_shell = (argc == 1); |
| 228 int num_isolates = 1; | 228 int num_isolates = 1; |
| 229 for (int i = 1; i < argc; i++) { | 229 for (int i = 1; i < argc; i++) { |
| 230 if (strcmp(argv[i], "--isolate") == 0) { | 230 if (strcmp(argv[i], "--isolate") == 0) { |
| 231 #ifndef USING_V8_SHARED | 231 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 232 ++num_isolates; | 232 ++num_isolates; |
| 233 #else // USING_V8_SHARED | 233 #else // USING_V8_SHARED |
| 234 printf("Error: --isolate not supported when linked with shared " | 234 printf("Error: --isolate not supported when linked with shared " |
| 235 "library\n"); | 235 "library\n"); |
| 236 ExitShell(1); | 236 ExitShell(1); |
| 237 #endif // USING_V8_SHARED | 237 #endif // USING_V8_SHARED |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 if (isolate_sources == NULL) { | 240 if (isolate_sources == NULL) { |
| 241 isolate_sources = new SourceGroup[num_isolates]; | 241 isolate_sources = new SourceGroup[num_isolates]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 252 } else if (strcmp(str, "-f") == 0) { | 252 } else if (strcmp(str, "-f") == 0) { |
| 253 // Ignore any -f flags for compatibility with the other stand- | 253 // Ignore any -f flags for compatibility with the other stand- |
| 254 // alone JavaScript engines. | 254 // alone JavaScript engines. |
| 255 continue; | 255 continue; |
| 256 } else if (strncmp(str, "--", 2) == 0) { | 256 } else if (strncmp(str, "--", 2) == 0) { |
| 257 printf("Warning: unknown flag %s.\nTry --help for options\n", str); | 257 printf("Warning: unknown flag %s.\nTry --help for options\n", str); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 current->End(argc); | 260 current->End(argc); |
| 261 } | 261 } |
| 262 #ifndef USING_V8_SHARED | 262 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 263 for (int i = 1; i < num_isolates; ++i) { | 263 for (int i = 1; i < num_isolates; ++i) { |
| 264 isolate_sources[i].StartExecuteInThread(); | 264 isolate_sources[i].StartExecuteInThread(); |
| 265 } | 265 } |
| 266 #endif // USING_V8_SHARED | 266 #endif // USING_V8_SHARED |
| 267 isolate_sources[0].Execute(); | 267 isolate_sources[0].Execute(); |
| 268 if (run_shell) RunShell(context); | 268 if (run_shell) RunShell(context); |
| 269 #ifndef USING_V8_SHARED | 269 #if !(defined(USING_V8_SHARED) || defined(V8_SHARED)) |
| 270 for (int i = 1; i < num_isolates; ++i) { | 270 for (int i = 1; i < num_isolates; ++i) { |
| 271 isolate_sources[i].WaitForThread(); | 271 isolate_sources[i].WaitForThread(); |
| 272 } | 272 } |
| 273 #endif // USING_V8_SHARED | 273 #endif // USING_V8_SHARED |
| 274 if (last_run) { | 274 if (last_run) { |
| 275 delete[] isolate_sources; | 275 delete[] isolate_sources; |
| 276 isolate_sources = NULL; | 276 isolate_sources = NULL; |
| 277 } | 277 } |
| 278 context->Exit(); | 278 context->Exit(); |
| 279 context.Dispose(); | 279 context.Dispose(); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 printf("^"); | 671 printf("^"); |
| 672 } | 672 } |
| 673 printf("\n"); | 673 printf("\n"); |
| 674 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 674 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
| 675 if (stack_trace.length() > 0) { | 675 if (stack_trace.length() > 0) { |
| 676 const char* stack_trace_string = ToCString(stack_trace); | 676 const char* stack_trace_string = ToCString(stack_trace); |
| 677 printf("%s\n", stack_trace_string); | 677 printf("%s\n", stack_trace_string); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 } | 680 } |
| OLD | NEW |