| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 | 28 |
| 29 #ifdef V8_SHARED |
| 30 #define USING_V8_SHARED |
| 31 #endif |
| 32 |
| 29 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 33 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 30 #include <bzlib.h> | 34 #include <bzlib.h> |
| 31 #endif | 35 #endif |
| 36 |
| 32 #include <errno.h> | 37 #include <errno.h> |
| 33 #include <stdlib.h> | 38 #include <stdlib.h> |
| 39 #include <string.h> |
| 34 | 40 |
| 35 #include "v8.h" | 41 #ifdef USING_V8_SHARED |
| 42 #include <assert.h> |
| 43 #include "../include/v8-testing.h" |
| 44 #endif // USING_V8_SHARED |
| 36 | 45 |
| 37 #include "d8.h" | 46 #include "d8.h" |
| 47 |
| 48 #ifndef USING_V8_SHARED |
| 49 #include "api.h" |
| 50 #include "checks.h" |
| 38 #include "d8-debug.h" | 51 #include "d8-debug.h" |
| 39 #include "debug.h" | 52 #include "debug.h" |
| 40 #include "api.h" | |
| 41 #include "natives.h" | 53 #include "natives.h" |
| 42 #include "platform.h" | 54 #include "platform.h" |
| 55 #include "v8.h" |
| 56 #endif // USING_V8_SHARED |
| 43 | 57 |
| 44 #if !defined(_WIN32) && !defined(_WIN64) | 58 #if !defined(_WIN32) && !defined(_WIN64) |
| 45 #include <unistd.h> // NOLINT | 59 #include <unistd.h> // NOLINT |
| 46 #endif | 60 #endif |
| 47 | 61 |
| 62 #ifdef USING_V8_SHARED |
| 63 #define ASSERT(condition) assert(condition) |
| 64 #endif // USING_V8_SHARED |
| 65 |
| 48 namespace v8 { | 66 namespace v8 { |
| 49 | 67 |
| 50 | 68 |
| 69 #ifndef USING_V8_SHARED |
| 70 LineEditor *LineEditor::first_ = NULL; |
| 51 const char* Shell::kHistoryFileName = ".d8_history"; | 71 const char* Shell::kHistoryFileName = ".d8_history"; |
| 52 const char* Shell::kPrompt = "d8> "; | |
| 53 | |
| 54 | |
| 55 LineEditor *LineEditor::first_ = NULL; | |
| 56 | 72 |
| 57 | 73 |
| 58 LineEditor::LineEditor(Type type, const char* name) | 74 LineEditor::LineEditor(Type type, const char* name) |
| 59 : type_(type), | 75 : type_(type), |
| 60 name_(name), | 76 name_(name), |
| 61 next_(first_) { | 77 next_(first_) { |
| 62 first_ = this; | 78 first_ = this; |
| 63 } | 79 } |
| 64 | 80 |
| 65 | 81 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 91 printf("%s", prompt); | 107 printf("%s", prompt); |
| 92 char* str = fgets(buffer, kBufferSize, stdin); | 108 char* str = fgets(buffer, kBufferSize, stdin); |
| 93 return i::SmartPointer<char>(str ? i::StrDup(str) : str); | 109 return i::SmartPointer<char>(str ? i::StrDup(str) : str); |
| 94 } | 110 } |
| 95 | 111 |
| 96 | 112 |
| 97 CounterMap* Shell::counter_map_; | 113 CounterMap* Shell::counter_map_; |
| 98 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 114 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; |
| 99 CounterCollection Shell::local_counters_; | 115 CounterCollection Shell::local_counters_; |
| 100 CounterCollection* Shell::counters_ = &local_counters_; | 116 CounterCollection* Shell::counters_ = &local_counters_; |
| 117 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); |
| 101 Persistent<Context> Shell::utility_context_; | 118 Persistent<Context> Shell::utility_context_; |
| 119 #endif // USING_V8_SHARED |
| 120 |
| 102 Persistent<Context> Shell::evaluation_context_; | 121 Persistent<Context> Shell::evaluation_context_; |
| 103 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); | |
| 104 ShellOptions Shell::options; | 122 ShellOptions Shell::options; |
| 123 const char* Shell::kPrompt = "d8> "; |
| 105 | 124 |
| 106 | 125 |
| 126 #ifndef USING_V8_SHARED |
| 107 bool CounterMap::Match(void* key1, void* key2) { | 127 bool CounterMap::Match(void* key1, void* key2) { |
| 108 const char* name1 = reinterpret_cast<const char*>(key1); | 128 const char* name1 = reinterpret_cast<const char*>(key1); |
| 109 const char* name2 = reinterpret_cast<const char*>(key2); | 129 const char* name2 = reinterpret_cast<const char*>(key2); |
| 110 return strcmp(name1, name2) == 0; | 130 return strcmp(name1, name2) == 0; |
| 111 } | 131 } |
| 132 #endif // USING_V8_SHARED |
| 112 | 133 |
| 113 | 134 |
| 114 // Converts a V8 value to a C string. | 135 // Converts a V8 value to a C string. |
| 115 const char* Shell::ToCString(const v8::String::Utf8Value& value) { | 136 const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
| 116 return *value ? *value : "<string conversion failed>"; | 137 return *value ? *value : "<string conversion failed>"; |
| 117 } | 138 } |
| 118 | 139 |
| 119 | 140 |
| 120 // Executes a string within the current v8 context. | 141 // Executes a string within the current v8 context. |
| 121 bool Shell::ExecuteString(Handle<String> source, | 142 bool Shell::ExecuteString(Handle<String> source, |
| 122 Handle<Value> name, | 143 Handle<Value> name, |
| 123 bool print_result, | 144 bool print_result, |
| 124 bool report_exceptions) { | 145 bool report_exceptions) { |
| 146 #ifndef USING_V8_SHARED |
| 147 bool FLAG_debugger = i::FLAG_debugger; |
| 148 #else |
| 149 bool FLAG_debugger = false; |
| 150 #endif // USING_V8_SHARED |
| 125 HandleScope handle_scope; | 151 HandleScope handle_scope; |
| 126 TryCatch try_catch; | 152 TryCatch try_catch; |
| 127 options.script_executed = true; | 153 options.script_executed = true; |
| 128 if (i::FLAG_debugger) { | 154 if (FLAG_debugger) { |
| 129 // When debugging make exceptions appear to be uncaught. | 155 // When debugging make exceptions appear to be uncaught. |
| 130 try_catch.SetVerbose(true); | 156 try_catch.SetVerbose(true); |
| 131 } | 157 } |
| 132 Handle<Script> script = Script::Compile(source, name); | 158 Handle<Script> script = Script::Compile(source, name); |
| 133 if (script.IsEmpty()) { | 159 if (script.IsEmpty()) { |
| 134 // Print errors that happened during compilation. | 160 // Print errors that happened during compilation. |
| 135 if (report_exceptions && !i::FLAG_debugger) | 161 if (report_exceptions && !FLAG_debugger) |
| 136 ReportException(&try_catch); | 162 ReportException(&try_catch); |
| 137 return false; | 163 return false; |
| 138 } else { | 164 } else { |
| 139 Handle<Value> result = script->Run(); | 165 Handle<Value> result = script->Run(); |
| 140 if (result.IsEmpty()) { | 166 if (result.IsEmpty()) { |
| 141 ASSERT(try_catch.HasCaught()); | 167 ASSERT(try_catch.HasCaught()); |
| 142 // Print errors that happened during execution. | 168 // Print errors that happened during execution. |
| 143 if (report_exceptions && !i::FLAG_debugger) | 169 if (report_exceptions && !FLAG_debugger) |
| 144 ReportException(&try_catch); | 170 ReportException(&try_catch); |
| 145 return false; | 171 return false; |
| 146 } else { | 172 } else { |
| 147 ASSERT(!try_catch.HasCaught()); | 173 ASSERT(!try_catch.HasCaught()); |
| 148 if (print_result && !result->IsUndefined()) { | 174 if (print_result && !result->IsUndefined()) { |
| 149 // If all went well and the result wasn't undefined then print | 175 // If all went well and the result wasn't undefined then print |
| 150 // the returned value. | 176 // the returned value. |
| 151 v8::String::Utf8Value str(result); | 177 v8::String::Utf8Value str(result); |
| 152 const char* cstr = ToCString(str); | 178 const char* cstr = ToCString(str); |
| 153 printf("%s\n", cstr); | 179 printf("%s\n", cstr); |
| 154 } | 180 } |
| 155 return true; | 181 return true; |
| 156 } | 182 } |
| 157 } | 183 } |
| 158 } | 184 } |
| 159 | 185 |
| 160 | 186 |
| 161 Handle<Value> Shell::Print(const Arguments& args) { | 187 Handle<Value> Shell::Print(const Arguments& args) { |
| 162 Handle<Value> val = Write(args); | 188 Handle<Value> val = Write(args); |
| 163 printf("\n"); | 189 printf("\n"); |
| 190 fflush(stdout); |
| 164 return val; | 191 return val; |
| 165 } | 192 } |
| 166 | 193 |
| 167 | 194 |
| 168 Handle<Value> Shell::Write(const Arguments& args) { | 195 Handle<Value> Shell::Write(const Arguments& args) { |
| 169 for (int i = 0; i < args.Length(); i++) { | 196 for (int i = 0; i < args.Length(); i++) { |
| 170 HandleScope handle_scope; | 197 HandleScope handle_scope; |
| 171 if (i != 0) { | 198 if (i != 0) { |
| 172 printf(" "); | 199 printf(" "); |
| 173 } | 200 } |
| 174 v8::String::Utf8Value str(args[i]); | 201 v8::String::Utf8Value str(args[i]); |
| 175 int n = fwrite(*str, sizeof(**str), str.length(), stdout); | 202 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); |
| 176 if (n != str.length()) { | 203 if (n != str.length()) { |
| 177 printf("Error in fwrite\n"); | 204 printf("Error in fwrite\n"); |
| 178 exit(1); | 205 exit(1); |
| 179 } | 206 } |
| 180 } | 207 } |
| 181 return Undefined(); | 208 return Undefined(); |
| 182 } | 209 } |
| 183 | 210 |
| 184 | 211 |
| 185 Handle<Value> Shell::Read(const Arguments& args) { | 212 Handle<Value> Shell::Read(const Arguments& args) { |
| 186 String::Utf8Value file(args[0]); | 213 String::Utf8Value file(args[0]); |
| 187 if (*file == NULL) { | 214 if (*file == NULL) { |
| 188 return ThrowException(String::New("Error loading file")); | 215 return ThrowException(String::New("Error loading file")); |
| 189 } | 216 } |
| 190 Handle<String> source = ReadFile(*file); | 217 Handle<String> source = ReadFile(*file); |
| 191 if (source.IsEmpty()) { | 218 if (source.IsEmpty()) { |
| 192 return ThrowException(String::New("Error loading file")); | 219 return ThrowException(String::New("Error loading file")); |
| 193 } | 220 } |
| 194 return source; | 221 return source; |
| 195 } | 222 } |
| 196 | 223 |
| 197 | 224 |
| 198 Handle<Value> Shell::ReadLine(const Arguments& args) { | 225 Handle<Value> Shell::ReadLine(const Arguments& args) { |
| 199 i::SmartPointer<char> line(i::ReadLine("")); | 226 static const int kBufferSize = 256; |
| 200 if (*line == NULL) { | 227 char buffer[kBufferSize]; |
| 201 return Null(); | 228 Handle<String> accumulator = String::New(""); |
| 229 int length; |
| 230 while (true) { |
| 231 // Continue reading if the line ends with an escape '\\' or the line has |
| 232 // not been fully read into the buffer yet (does not end with '\n'). |
| 233 // If fgets gets an error, just give up. |
| 234 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); |
| 235 length = static_cast<int>(strlen(buffer)); |
| 236 if (length == 0) { |
| 237 return accumulator; |
| 238 } else if (buffer[length-1] != '\n') { |
| 239 accumulator = String::Concat(accumulator, String::New(buffer, length)); |
| 240 } else if (length > 1 && buffer[length-2] == '\\') { |
| 241 buffer[length-2] = '\n'; |
| 242 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); |
| 243 } else { |
| 244 return String::Concat(accumulator, String::New(buffer, length-1)); |
| 245 } |
| 202 } | 246 } |
| 203 size_t len = strlen(*line); | |
| 204 if (len > 0 && line[len - 1] == '\n') { | |
| 205 --len; | |
| 206 } | |
| 207 return String::New(*line, len); | |
| 208 } | 247 } |
| 209 | 248 |
| 210 | 249 |
| 211 Handle<Value> Shell::Load(const Arguments& args) { | 250 Handle<Value> Shell::Load(const Arguments& args) { |
| 212 for (int i = 0; i < args.Length(); i++) { | 251 for (int i = 0; i < args.Length(); i++) { |
| 213 HandleScope handle_scope; | 252 HandleScope handle_scope; |
| 214 String::Utf8Value file(args[i]); | 253 String::Utf8Value file(args[i]); |
| 215 if (*file == NULL) { | 254 if (*file == NULL) { |
| 216 return ThrowException(String::New("Error loading file")); | 255 return ThrowException(String::New("Error loading file")); |
| 217 } | 256 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 229 | 268 |
| 230 Handle<Value> Shell::CreateExternalArray(const Arguments& args, | 269 Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
| 231 ExternalArrayType type, | 270 ExternalArrayType type, |
| 232 size_t element_size) { | 271 size_t element_size) { |
| 233 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 || | 272 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 || |
| 234 element_size == 8); | 273 element_size == 8); |
| 235 if (args.Length() != 1) { | 274 if (args.Length() != 1) { |
| 236 return ThrowException( | 275 return ThrowException( |
| 237 String::New("Array constructor needs one parameter.")); | 276 String::New("Array constructor needs one parameter.")); |
| 238 } | 277 } |
| 278 static const int kMaxLength = 0x3fffffff; |
| 279 #ifndef USING_V8_SHARED |
| 280 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); |
| 281 #endif // USING_V8_SHARED |
| 239 size_t length = 0; | 282 size_t length = 0; |
| 240 if (args[0]->IsUint32()) { | 283 if (args[0]->IsUint32()) { |
| 241 length = args[0]->Uint32Value(); | 284 length = args[0]->Uint32Value(); |
| 242 } else if (args[0]->IsNumber()) { | 285 } else if (args[0]->IsNumber()) { |
| 243 double raw_length = args[0]->NumberValue(); | 286 double raw_length = args[0]->NumberValue(); |
| 244 if (raw_length < 0) { | 287 if (raw_length < 0) { |
| 245 return ThrowException(String::New("Array length must not be negative.")); | 288 return ThrowException(String::New("Array length must not be negative.")); |
| 246 } | 289 } |
| 247 if (raw_length > i::ExternalArray::kMaxLength) { | 290 if (raw_length > kMaxLength) { |
| 248 return ThrowException( | 291 return ThrowException( |
| 249 String::New("Array length exceeds maximum length.")); | 292 String::New("Array length exceeds maximum length.")); |
| 250 } | 293 } |
| 251 length = static_cast<size_t>(raw_length); | 294 length = static_cast<size_t>(raw_length); |
| 252 } else { | 295 } else { |
| 253 return ThrowException(String::New("Array length must be a number.")); | 296 return ThrowException(String::New("Array length must be a number.")); |
| 254 } | 297 } |
| 255 if (length > static_cast<size_t>(i::ExternalArray::kMaxLength)) { | 298 if (length > static_cast<size_t>(kMaxLength)) { |
| 256 return ThrowException(String::New("Array length exceeds maximum length.")); | 299 return ThrowException(String::New("Array length exceeds maximum length.")); |
| 257 } | 300 } |
| 258 void* data = calloc(length, element_size); | 301 void* data = calloc(length, element_size); |
| 259 if (data == NULL) { | 302 if (data == NULL) { |
| 260 return ThrowException(String::New("Memory allocation failed.")); | 303 return ThrowException(String::New("Memory allocation failed.")); |
| 261 } | 304 } |
| 262 Handle<Object> array = Object::New(); | 305 Handle<Object> array = Object::New(); |
| 263 Persistent<Object> persistent_array = Persistent<Object>::New(array); | 306 Persistent<Object> persistent_array = Persistent<Object>::New(array); |
| 264 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 307 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); |
| 265 persistent_array.MarkIndependent(); | 308 persistent_array.MarkIndependent(); |
| 266 array->SetIndexedPropertiesToExternalArrayData(data, type, length); | 309 array->SetIndexedPropertiesToExternalArrayData(data, type, |
| 267 array->Set(String::New("length"), Int32::New(length), ReadOnly); | 310 static_cast<int>(length)); |
| 268 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); | 311 array->Set(String::New("length"), |
| 312 Int32::New(static_cast<int32_t>(length)), ReadOnly); |
| 313 array->Set(String::New("BYTES_PER_ELEMENT"), |
| 314 Int32::New(static_cast<int32_t>(element_size))); |
| 269 return array; | 315 return array; |
| 270 } | 316 } |
| 271 | 317 |
| 272 | 318 |
| 273 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 319 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
| 274 free(data); | 320 free(data); |
| 275 object.Dispose(); | 321 object.Dispose(); |
| 276 } | 322 } |
| 277 | 323 |
| 278 | 324 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 371 |
| 326 | 372 |
| 327 Handle<Value> Shell::Yield(const Arguments& args) { | 373 Handle<Value> Shell::Yield(const Arguments& args) { |
| 328 v8::Unlocker unlocker; | 374 v8::Unlocker unlocker; |
| 329 return Undefined(); | 375 return Undefined(); |
| 330 } | 376 } |
| 331 | 377 |
| 332 | 378 |
| 333 Handle<Value> Shell::Quit(const Arguments& args) { | 379 Handle<Value> Shell::Quit(const Arguments& args) { |
| 334 int exit_code = args[0]->Int32Value(); | 380 int exit_code = args[0]->Int32Value(); |
| 381 #ifndef USING_V8_SHARED |
| 335 OnExit(); | 382 OnExit(); |
| 383 #endif // USING_V8_SHARED |
| 336 exit(exit_code); | 384 exit(exit_code); |
| 337 return Undefined(); | 385 return Undefined(); |
| 338 } | 386 } |
| 339 | 387 |
| 340 | 388 |
| 341 Handle<Value> Shell::Version(const Arguments& args) { | 389 Handle<Value> Shell::Version(const Arguments& args) { |
| 342 return String::New(V8::GetVersion()); | 390 return String::New(V8::GetVersion()); |
| 343 } | 391 } |
| 344 | 392 |
| 345 | 393 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 374 printf("\n"); | 422 printf("\n"); |
| 375 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 423 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
| 376 if (stack_trace.length() > 0) { | 424 if (stack_trace.length() > 0) { |
| 377 const char* stack_trace_string = ToCString(stack_trace); | 425 const char* stack_trace_string = ToCString(stack_trace); |
| 378 printf("%s\n", stack_trace_string); | 426 printf("%s\n", stack_trace_string); |
| 379 } | 427 } |
| 380 } | 428 } |
| 381 } | 429 } |
| 382 | 430 |
| 383 | 431 |
| 432 #ifndef USING_V8_SHARED |
| 384 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) { | 433 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) { |
| 385 HandleScope handle_scope; | 434 HandleScope handle_scope; |
| 386 Context::Scope context_scope(utility_context_); | 435 Context::Scope context_scope(utility_context_); |
| 387 Handle<Object> global = utility_context_->Global(); | 436 Handle<Object> global = utility_context_->Global(); |
| 388 Handle<Value> fun = global->Get(String::New("GetCompletions")); | 437 Handle<Value> fun = global->Get(String::New("GetCompletions")); |
| 389 static const int kArgc = 3; | 438 static const int kArgc = 3; |
| 390 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; | 439 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; |
| 391 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 440 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 392 return handle_scope.Close(Handle<Array>::Cast(val)); | 441 return handle_scope.Close(Handle<Array>::Cast(val)); |
| 393 } | 442 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 407 | 456 |
| 408 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { | 457 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { |
| 409 Context::Scope context_scope(utility_context_); | 458 Context::Scope context_scope(utility_context_); |
| 410 Handle<Object> global = utility_context_->Global(); | 459 Handle<Object> global = utility_context_->Global(); |
| 411 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); | 460 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); |
| 412 static const int kArgc = 1; | 461 static const int kArgc = 1; |
| 413 Handle<Value> argv[kArgc] = { command }; | 462 Handle<Value> argv[kArgc] = { command }; |
| 414 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 463 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 415 return val; | 464 return val; |
| 416 } | 465 } |
| 417 #endif | 466 #endif // ENABLE_DEBUGGER_SUPPORT |
| 467 #endif // USING_V8_SHARED |
| 418 | 468 |
| 419 | 469 |
| 470 #ifndef USING_V8_SHARED |
| 420 int32_t* Counter::Bind(const char* name, bool is_histogram) { | 471 int32_t* Counter::Bind(const char* name, bool is_histogram) { |
| 421 int i; | 472 int i; |
| 422 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 473 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |
| 423 name_[i] = static_cast<char>(name[i]); | 474 name_[i] = static_cast<char>(name[i]); |
| 424 name_[i] = '\0'; | 475 name_[i] = '\0'; |
| 425 is_histogram_ = is_histogram; | 476 is_histogram_ = is_histogram; |
| 426 return ptr(); | 477 return ptr(); |
| 427 } | 478 } |
| 428 | 479 |
| 429 | 480 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 441 } | 492 } |
| 442 | 493 |
| 443 | 494 |
| 444 Counter* CounterCollection::GetNextCounter() { | 495 Counter* CounterCollection::GetNextCounter() { |
| 445 if (counters_in_use_ == kMaxCounters) return NULL; | 496 if (counters_in_use_ == kMaxCounters) return NULL; |
| 446 return &counters_[counters_in_use_++]; | 497 return &counters_[counters_in_use_++]; |
| 447 } | 498 } |
| 448 | 499 |
| 449 | 500 |
| 450 void Shell::MapCounters(const char* name) { | 501 void Shell::MapCounters(const char* name) { |
| 451 counters_file_ = i::OS::MemoryMappedFile::create(name, | 502 counters_file_ = i::OS::MemoryMappedFile::create( |
| 452 sizeof(CounterCollection), &local_counters_); | 503 name, sizeof(CounterCollection), &local_counters_); |
| 453 void* memory = (counters_file_ == NULL) ? | 504 void* memory = (counters_file_ == NULL) ? |
| 454 NULL : counters_file_->memory(); | 505 NULL : counters_file_->memory(); |
| 455 if (memory == NULL) { | 506 if (memory == NULL) { |
| 456 printf("Could not map counters file %s\n", name); | 507 printf("Could not map counters file %s\n", name); |
| 457 exit(1); | 508 exit(1); |
| 458 } | 509 } |
| 459 counters_ = static_cast<CounterCollection*>(memory); | 510 counters_ = static_cast<CounterCollection*>(memory); |
| 460 V8::SetCounterFunction(LookupCounter); | 511 V8::SetCounterFunction(LookupCounter); |
| 461 V8::SetCreateHistogramFunction(CreateHistogram); | 512 V8::SetCreateHistogramFunction(CreateHistogram); |
| 462 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 513 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 size_t buckets) { | 558 size_t buckets) { |
| 508 return GetCounter(name, true); | 559 return GetCounter(name, true); |
| 509 } | 560 } |
| 510 | 561 |
| 511 | 562 |
| 512 void Shell::AddHistogramSample(void* histogram, int sample) { | 563 void Shell::AddHistogramSample(void* histogram, int sample) { |
| 513 Counter* counter = reinterpret_cast<Counter*>(histogram); | 564 Counter* counter = reinterpret_cast<Counter*>(histogram); |
| 514 counter->AddSample(sample); | 565 counter->AddSample(sample); |
| 515 } | 566 } |
| 516 | 567 |
| 568 |
| 517 void Shell::InstallUtilityScript() { | 569 void Shell::InstallUtilityScript() { |
| 518 Locker lock; | 570 Locker lock; |
| 519 HandleScope scope; | 571 HandleScope scope; |
| 520 // If we use the utility context, we have to set the security tokens so that | 572 // If we use the utility context, we have to set the security tokens so that |
| 521 // utility, evaluation and debug context can all access each other. | 573 // utility, evaluation and debug context can all access each other. |
| 522 utility_context_->SetSecurityToken(Undefined()); | 574 utility_context_->SetSecurityToken(Undefined()); |
| 523 evaluation_context_->SetSecurityToken(Undefined()); | 575 evaluation_context_->SetSecurityToken(Undefined()); |
| 524 Context::Scope utility_scope(utility_context_); | 576 Context::Scope utility_scope(utility_context_); |
| 525 | 577 |
| 526 #ifdef ENABLE_DEBUGGER_SUPPORT | 578 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 527 // Install the debugger object in the utility scope | 579 // Install the debugger object in the utility scope |
| 528 i::Debug* debug = i::Isolate::Current()->debug(); | 580 i::Debug* debug = i::Isolate::Current()->debug(); |
| 529 debug->Load(); | 581 debug->Load(); |
| 530 i::Handle<i::JSObject> js_debug | 582 i::Handle<i::JSObject> js_debug |
| 531 = i::Handle<i::JSObject>(debug->debug_context()->global()); | 583 = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| 532 utility_context_->Global()->Set(String::New("$debug"), | 584 utility_context_->Global()->Set(String::New("$debug"), |
| 533 Utils::ToLocal(js_debug)); | 585 Utils::ToLocal(js_debug)); |
| 534 debug->debug_context()->set_security_token(HEAP->undefined_value()); | 586 debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| 535 #endif | 587 #endif // ENABLE_DEBUGGER_SUPPORT |
| 536 | 588 |
| 537 // Run the d8 shell utility script in the utility context | 589 // Run the d8 shell utility script in the utility context |
| 538 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 590 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |
| 539 i::Vector<const char> shell_source = | 591 i::Vector<const char> shell_source = |
| 540 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | 592 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); |
| 541 i::Vector<const char> shell_source_name = | 593 i::Vector<const char> shell_source_name = |
| 542 i::NativesCollection<i::D8>::GetScriptName(source_index); | 594 i::NativesCollection<i::D8>::GetScriptName(source_index); |
| 543 Handle<String> source = String::New(shell_source.start(), | 595 Handle<String> source = String::New(shell_source.start(), |
| 544 shell_source.length()); | 596 shell_source.length()); |
| 545 Handle<String> name = String::New(shell_source_name.start(), | 597 Handle<String> name = String::New(shell_source_name.start(), |
| 546 shell_source_name.length()); | 598 shell_source_name.length()); |
| 547 Handle<Script> script = Script::Compile(source, name); | 599 Handle<Script> script = Script::Compile(source, name); |
| 548 script->Run(); | 600 script->Run(); |
| 549 // Mark the d8 shell script as native to avoid it showing up as normal source | 601 // Mark the d8 shell script as native to avoid it showing up as normal source |
| 550 // in the debugger. | 602 // in the debugger. |
| 551 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); | 603 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); |
| 552 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() | 604 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() |
| 553 ? i::Handle<i::Script>(i::Script::cast( | 605 ? i::Handle<i::Script>(i::Script::cast( |
| 554 i::JSFunction::cast(*compiled_script)->shared()->script())) | 606 i::JSFunction::cast(*compiled_script)->shared()->script())) |
| 555 : i::Handle<i::Script>(i::Script::cast( | 607 : i::Handle<i::Script>(i::Script::cast( |
| 556 i::SharedFunctionInfo::cast(*compiled_script)->script())); | 608 i::SharedFunctionInfo::cast(*compiled_script)->script())); |
| 557 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); | 609 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); |
| 558 | 610 |
| 559 #ifdef ENABLE_DEBUGGER_SUPPORT | 611 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 560 // Start the in-process debugger if requested. | 612 // Start the in-process debugger if requested. |
| 561 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 613 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
| 562 v8::Debug::SetDebugEventListener(HandleDebugEvent); | 614 v8::Debug::SetDebugEventListener(HandleDebugEvent); |
| 563 } | 615 } |
| 564 #endif | 616 #endif // ENABLE_DEBUGGER_SUPPORT |
| 565 } | 617 } |
| 618 #endif // USING_V8_SHARED |
| 566 | 619 |
| 567 | 620 |
| 568 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 621 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 569 class BZip2Decompressor : public v8::StartupDataDecompressor { | 622 class BZip2Decompressor : public v8::StartupDataDecompressor { |
| 570 public: | 623 public: |
| 571 virtual ~BZip2Decompressor() { } | 624 virtual ~BZip2Decompressor() { } |
| 572 | 625 |
| 573 protected: | 626 protected: |
| 574 virtual int DecompressData(char* raw_data, | 627 virtual int DecompressData(char* raw_data, |
| 575 int* raw_data_size, | 628 int* raw_data_size, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 FunctionTemplate::New(Float64Array)); | 675 FunctionTemplate::New(Float64Array)); |
| 623 global_template->Set(String::New("PixelArray"), | 676 global_template->Set(String::New("PixelArray"), |
| 624 FunctionTemplate::New(PixelArray)); | 677 FunctionTemplate::New(PixelArray)); |
| 625 | 678 |
| 626 #ifdef LIVE_OBJECT_LIST | 679 #ifdef LIVE_OBJECT_LIST |
| 627 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); | 680 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); |
| 628 #else | 681 #else |
| 629 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 682 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); |
| 630 #endif | 683 #endif |
| 631 | 684 |
| 685 #ifndef USING_V8_SHARED |
| 632 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 686 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 633 AddOSMethods(os_templ); | 687 AddOSMethods(os_templ); |
| 634 global_template->Set(String::New("os"), os_templ); | 688 global_template->Set(String::New("os"), os_templ); |
| 689 #endif // USING_V8_SHARED |
| 635 | 690 |
| 636 return global_template; | 691 return global_template; |
| 637 } | 692 } |
| 638 | 693 |
| 639 | 694 |
| 640 void Shell::Initialize() { | 695 void Shell::Initialize() { |
| 641 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 696 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 642 BZip2Decompressor startup_data_decompressor; | 697 BZip2Decompressor startup_data_decompressor; |
| 643 int bz2_result = startup_data_decompressor.Decompress(); | 698 int bz2_result = startup_data_decompressor.Decompress(); |
| 644 if (bz2_result != BZ_OK) { | 699 if (bz2_result != BZ_OK) { |
| 645 fprintf(stderr, "bzip error code: %d\n", bz2_result); | 700 fprintf(stderr, "bzip error code: %d\n", bz2_result); |
| 646 exit(1); | 701 exit(1); |
| 647 } | 702 } |
| 648 #endif | 703 #endif |
| 649 | 704 |
| 705 #ifndef USING_V8_SHARED |
| 650 Shell::counter_map_ = new CounterMap(); | 706 Shell::counter_map_ = new CounterMap(); |
| 651 // Set up counters | 707 // Set up counters |
| 652 if (i::StrLength(i::FLAG_map_counters) != 0) | 708 if (i::StrLength(i::FLAG_map_counters) != 0) |
| 653 MapCounters(i::FLAG_map_counters); | 709 MapCounters(i::FLAG_map_counters); |
| 654 if (i::FLAG_dump_counters) { | 710 if (i::FLAG_dump_counters) { |
| 655 V8::SetCounterFunction(LookupCounter); | 711 V8::SetCounterFunction(LookupCounter); |
| 656 V8::SetCreateHistogramFunction(CreateHistogram); | 712 V8::SetCreateHistogramFunction(CreateHistogram); |
| 657 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 713 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 658 } | 714 } |
| 659 | 715 #endif // USING_V8_SHARED |
| 660 if (options.test_shell) return; | 716 if (options.test_shell) return; |
| 661 | 717 |
| 718 #ifndef USING_V8_SHARED |
| 662 Locker lock; | 719 Locker lock; |
| 663 HandleScope scope; | 720 HandleScope scope; |
| 664 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 721 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| 665 utility_context_ = Context::New(NULL, global_template); | 722 utility_context_ = Context::New(NULL, global_template); |
| 666 | 723 |
| 667 #ifdef ENABLE_DEBUGGER_SUPPORT | 724 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 668 // Start the debugger agent if requested. | 725 // Start the debugger agent if requested. |
| 669 if (i::FLAG_debugger_agent) { | 726 if (i::FLAG_debugger_agent) { |
| 670 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 727 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| 671 } | 728 } |
| 672 #endif | 729 #endif // ENABLE_DEBUGGER_SUPPORT |
| 730 #endif // USING_V8_SHARED |
| 673 } | 731 } |
| 674 | 732 |
| 675 | 733 |
| 676 Persistent<Context> Shell::CreateEvaluationContext() { | 734 Persistent<Context> Shell::CreateEvaluationContext() { |
| 735 #ifndef USING_V8_SHARED |
| 677 // This needs to be a critical section since this is not thread-safe | 736 // This needs to be a critical section since this is not thread-safe |
| 678 i::ScopedLock lock(context_mutex_); | 737 i::ScopedLock lock(context_mutex_); |
| 738 #endif // USING_V8_SHARED |
| 679 // Initialize the global objects | 739 // Initialize the global objects |
| 680 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 740 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| 681 Persistent<Context> context = Context::New(NULL, global_template); | 741 Persistent<Context> context = Context::New(NULL, global_template); |
| 682 Context::Scope scope(context); | 742 Context::Scope scope(context); |
| 683 | 743 |
| 744 #ifndef USING_V8_SHARED |
| 684 i::JSArguments js_args = i::FLAG_js_arguments; | 745 i::JSArguments js_args = i::FLAG_js_arguments; |
| 685 i::Handle<i::FixedArray> arguments_array = | 746 i::Handle<i::FixedArray> arguments_array = |
| 686 FACTORY->NewFixedArray(js_args.argc()); | 747 FACTORY->NewFixedArray(js_args.argc()); |
| 687 for (int j = 0; j < js_args.argc(); j++) { | 748 for (int j = 0; j < js_args.argc(); j++) { |
| 688 i::Handle<i::String> arg = | 749 i::Handle<i::String> arg = |
| 689 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 750 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
| 690 arguments_array->set(j, *arg); | 751 arguments_array->set(j, *arg); |
| 691 } | 752 } |
| 692 i::Handle<i::JSArray> arguments_jsarray = | 753 i::Handle<i::JSArray> arguments_jsarray = |
| 693 FACTORY->NewJSArrayWithElements(arguments_array); | 754 FACTORY->NewJSArrayWithElements(arguments_array); |
| 694 context->Global()->Set(String::New("arguments"), | 755 context->Global()->Set(String::New("arguments"), |
| 695 Utils::ToLocal(arguments_jsarray)); | 756 Utils::ToLocal(arguments_jsarray)); |
| 757 #endif // USING_V8_SHARED |
| 696 return context; | 758 return context; |
| 697 } | 759 } |
| 698 | 760 |
| 699 | 761 |
| 762 #ifndef USING_V8_SHARED |
| 700 void Shell::OnExit() { | 763 void Shell::OnExit() { |
| 701 if (i::FLAG_dump_counters) { | 764 if (i::FLAG_dump_counters) { |
| 702 printf("+----------------------------------------+-------------+\n"); | 765 printf("+----------------------------------------+-------------+\n"); |
| 703 printf("| Name | Value |\n"); | 766 printf("| Name | Value |\n"); |
| 704 printf("+----------------------------------------+-------------+\n"); | 767 printf("+----------------------------------------+-------------+\n"); |
| 705 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 768 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { |
| 706 Counter* counter = i.CurrentValue(); | 769 Counter* counter = i.CurrentValue(); |
| 707 if (counter->is_histogram()) { | 770 if (counter->is_histogram()) { |
| 708 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); | 771 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); |
| 709 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); | 772 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); |
| 710 } else { | 773 } else { |
| 711 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); | 774 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); |
| 712 } | 775 } |
| 713 } | 776 } |
| 714 printf("+----------------------------------------+-------------+\n"); | 777 printf("+----------------------------------------+-------------+\n"); |
| 715 } | 778 } |
| 716 if (counters_file_ != NULL) | 779 if (counters_file_ != NULL) |
| 717 delete counters_file_; | 780 delete counters_file_; |
| 718 } | 781 } |
| 782 #endif // USING_V8_SHARED |
| 719 | 783 |
| 720 | 784 |
| 721 static char* ReadChars(const char* name, int* size_out) { | 785 static char* ReadChars(const char* name, int* size_out) { |
| 722 // Release the V8 lock while reading files. | 786 // Release the V8 lock while reading files. |
| 723 v8::Unlocker unlocker(Isolate::GetCurrent()); | 787 v8::Unlocker unlocker(Isolate::GetCurrent()); |
| 788 #ifndef USING_V8_SHARED |
| 724 FILE* file = i::OS::FOpen(name, "rb"); | 789 FILE* file = i::OS::FOpen(name, "rb"); |
| 790 #else |
| 791 // TODO(yangguo@chromium.org): reading from a directory hangs! |
| 792 FILE* file = fopen(name, "rb"); |
| 793 #endif // USING_V8_SHARED |
| 725 if (file == NULL) return NULL; | 794 if (file == NULL) return NULL; |
| 726 | 795 |
| 727 fseek(file, 0, SEEK_END); | 796 fseek(file, 0, SEEK_END); |
| 728 int size = ftell(file); | 797 int size = ftell(file); |
| 729 rewind(file); | 798 rewind(file); |
| 730 | 799 |
| 731 char* chars = new char[size + 1]; | 800 char* chars = new char[size + 1]; |
| 732 chars[size] = '\0'; | 801 chars[size] = '\0'; |
| 733 for (int i = 0; i < size;) { | 802 for (int i = 0; i < size;) { |
| 734 int read = fread(&chars[i], 1, size - i, file); | 803 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 735 i += read; | 804 i += read; |
| 736 } | 805 } |
| 737 fclose(file); | 806 fclose(file); |
| 738 *size_out = size; | 807 *size_out = size; |
| 739 return chars; | 808 return chars; |
| 740 } | 809 } |
| 741 | 810 |
| 742 | 811 |
| 812 #ifndef USING_V8_SHARED |
| 743 static char* ReadToken(char* data, char token) { | 813 static char* ReadToken(char* data, char token) { |
| 744 char* next = i::OS::StrChr(data, token); | 814 char* next = i::OS::StrChr(data, token); |
| 745 if (next != NULL) { | 815 if (next != NULL) { |
| 746 *next = '\0'; | 816 *next = '\0'; |
| 747 return (next + 1); | 817 return (next + 1); |
| 748 } | 818 } |
| 749 | 819 |
| 750 return NULL; | 820 return NULL; |
| 751 } | 821 } |
| 752 | 822 |
| 753 | 823 |
| 754 static char* ReadLine(char* data) { | 824 static char* ReadLine(char* data) { |
| 755 return ReadToken(data, '\n'); | 825 return ReadToken(data, '\n'); |
| 756 } | 826 } |
| 757 | 827 |
| 758 | 828 |
| 759 static char* ReadWord(char* data) { | 829 static char* ReadWord(char* data) { |
| 760 return ReadToken(data, ' '); | 830 return ReadToken(data, ' '); |
| 761 } | 831 } |
| 832 #endif // USING_V8_SHARED |
| 762 | 833 |
| 763 | 834 |
| 764 // Reads a file into a v8 string. | 835 // Reads a file into a v8 string. |
| 765 Handle<String> Shell::ReadFile(const char* name) { | 836 Handle<String> Shell::ReadFile(const char* name) { |
| 766 int size = 0; | 837 int size = 0; |
| 767 char* chars = ReadChars(name, &size); | 838 char* chars = ReadChars(name, &size); |
| 768 if (chars == NULL) return Handle<String>(); | 839 if (chars == NULL) return Handle<String>(); |
| 769 Handle<String> result = String::New(chars); | 840 Handle<String> result = String::New(chars); |
| 770 delete[] chars; | 841 delete[] chars; |
| 771 return result; | 842 return result; |
| 772 } | 843 } |
| 773 | 844 |
| 774 | 845 |
| 775 void Shell::RunShell() { | 846 void Shell::RunShell() { |
| 847 Locker locker; |
| 848 Context::Scope context_scope(evaluation_context_); |
| 849 HandleScope handle_scope; |
| 850 Handle<String> name = String::New("(d8)"); |
| 851 #ifndef USING_V8_SHARED |
| 776 LineEditor* editor = LineEditor::Get(); | 852 LineEditor* editor = LineEditor::Get(); |
| 777 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); | 853 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); |
| 778 if (i::FLAG_debugger) { | 854 if (i::FLAG_debugger) { |
| 779 printf("JavaScript debugger enabled\n"); | 855 printf("JavaScript debugger enabled\n"); |
| 780 } | 856 } |
| 781 | |
| 782 editor->Open(); | 857 editor->Open(); |
| 783 while (true) { | 858 while (true) { |
| 784 Locker locker; | |
| 785 HandleScope handle_scope; | |
| 786 Context::Scope context_scope(evaluation_context_); | |
| 787 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); | 859 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); |
| 788 if (input.is_empty()) | 860 if (input.is_empty()) break; |
| 789 break; | |
| 790 editor->AddHistory(*input); | 861 editor->AddHistory(*input); |
| 791 Handle<String> name = String::New("(d8)"); | |
| 792 ExecuteString(String::New(*input), name, true, true); | 862 ExecuteString(String::New(*input), name, true, true); |
| 793 } | 863 } |
| 794 editor->Close(); | 864 editor->Close(); |
| 865 #else |
| 866 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); |
| 867 static const int kBufferSize = 256; |
| 868 while (true) { |
| 869 char buffer[kBufferSize]; |
| 870 printf("%s", Shell::kPrompt); |
| 871 if (fgets(buffer, kBufferSize, stdin) == NULL) break; |
| 872 ExecuteString(String::New(buffer), name, true, true); |
| 873 } |
| 874 #endif // USING_V8_SHARED |
| 795 printf("\n"); | 875 printf("\n"); |
| 796 } | 876 } |
| 797 | 877 |
| 798 | 878 |
| 879 #ifndef USING_V8_SHARED |
| 799 class ShellThread : public i::Thread { | 880 class ShellThread : public i::Thread { |
| 800 public: | 881 public: |
| 801 ShellThread(int no, i::Vector<const char> files) | 882 ShellThread(int no, i::Vector<const char> files) |
| 802 : Thread("d8:ShellThread"), | 883 : Thread("d8:ShellThread"), |
| 803 no_(no), files_(files) { } | 884 no_(no), files_(files) { } |
| 804 virtual void Run(); | 885 virtual void Run(); |
| 805 private: | 886 private: |
| 806 int no_; | 887 int no_; |
| 807 i::Vector<const char> files_; | 888 i::Vector<const char> files_; |
| 808 }; | 889 }; |
| 809 | 890 |
| 810 | 891 |
| 811 void ShellThread::Run() { | 892 void ShellThread::Run() { |
| 812 char* ptr = const_cast<char*>(files_.start()); | 893 char* ptr = const_cast<char*>(files_.start()); |
| 813 while ((ptr != NULL) && (*ptr != '\0')) { | 894 while ((ptr != NULL) && (*ptr != '\0')) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 841 break; | 922 break; |
| 842 } | 923 } |
| 843 | 924 |
| 844 Shell::ExecuteString(str, String::New(filename), false, false); | 925 Shell::ExecuteString(str, String::New(filename), false, false); |
| 845 } | 926 } |
| 846 | 927 |
| 847 thread_context.Dispose(); | 928 thread_context.Dispose(); |
| 848 ptr = next_line; | 929 ptr = next_line; |
| 849 } | 930 } |
| 850 } | 931 } |
| 932 #endif // USING_V8_SHARED |
| 851 | 933 |
| 852 | 934 |
| 853 void SourceGroup::ExitShell(int exit_code) { | 935 void SourceGroup::ExitShell(int exit_code) { |
| 854 // Use _exit instead of exit to avoid races between isolate | 936 // Use _exit instead of exit to avoid races between isolate |
| 855 // threads and static destructors. | 937 // threads and static destructors. |
| 856 fflush(stdout); | 938 fflush(stdout); |
| 857 fflush(stderr); | 939 fflush(stderr); |
| 858 _exit(exit_code); | 940 _exit(exit_code); |
| 859 } | 941 } |
| 860 | 942 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 887 if (!Shell::ExecuteString(source, file_name, false, true)) { | 969 if (!Shell::ExecuteString(source, file_name, false, true)) { |
| 888 ExitShell(1); | 970 ExitShell(1); |
| 889 return; | 971 return; |
| 890 } | 972 } |
| 891 } | 973 } |
| 892 } | 974 } |
| 893 } | 975 } |
| 894 | 976 |
| 895 | 977 |
| 896 Handle<String> SourceGroup::ReadFile(const char* name) { | 978 Handle<String> SourceGroup::ReadFile(const char* name) { |
| 979 #ifndef USING_V8_SHARED |
| 980 FILE* file = i::OS::FOpen(name, "rb"); |
| 981 #else |
| 982 // TODO(yangguo@chromium.org): reading from a directory hangs! |
| 897 FILE* file = fopen(name, "rb"); | 983 FILE* file = fopen(name, "rb"); |
| 984 #endif // USING_V8_SHARED |
| 898 if (file == NULL) return Handle<String>(); | 985 if (file == NULL) return Handle<String>(); |
| 899 | 986 |
| 900 fseek(file, 0, SEEK_END); | 987 fseek(file, 0, SEEK_END); |
| 901 int size = ftell(file); | 988 int size = ftell(file); |
| 902 rewind(file); | 989 rewind(file); |
| 903 | 990 |
| 904 char* chars = new char[size + 1]; | 991 char* chars = new char[size + 1]; |
| 905 chars[size] = '\0'; | 992 chars[size] = '\0'; |
| 906 for (int i = 0; i < size;) { | 993 for (int i = 0; i < size;) { |
| 907 int read = fread(&chars[i], 1, size - i, file); | 994 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 908 i += read; | 995 i += read; |
| 909 } | 996 } |
| 910 fclose(file); | 997 fclose(file); |
| 911 Handle<String> result = String::New(chars, size); | 998 Handle<String> result = String::New(chars, size); |
| 912 delete[] chars; | 999 delete[] chars; |
| 913 return result; | 1000 return result; |
| 914 } | 1001 } |
| 915 | 1002 |
| 916 | 1003 |
| 1004 #ifndef USING_V8_SHARED |
| 917 i::Thread::Options SourceGroup::GetThreadOptions() { | 1005 i::Thread::Options SourceGroup::GetThreadOptions() { |
| 918 i::Thread::Options options; | 1006 i::Thread::Options options; |
| 919 options.name = "IsolateThread"; | 1007 options.name = "IsolateThread"; |
| 920 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less | 1008 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less |
| 921 // which is not enough to parse the big literal expressions used in tests. | 1009 // which is not enough to parse the big literal expressions used in tests. |
| 922 // The stack size should be at least StackGuard::kLimitSize + some | 1010 // The stack size should be at least StackGuard::kLimitSize + some |
| 923 // OS-specific padding for thread startup code. | 1011 // OS-specific padding for thread startup code. |
| 924 options.stack_size = 2 << 20; // 2 Mb seems to be enough | 1012 options.stack_size = 2 << 20; // 2 Mb seems to be enough |
| 925 return options; | 1013 return options; |
| 926 } | 1014 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 | 1046 |
| 959 void SourceGroup::WaitForThread() { | 1047 void SourceGroup::WaitForThread() { |
| 960 if (thread_ == NULL) return; | 1048 if (thread_ == NULL) return; |
| 961 if (Shell::options.last_run) { | 1049 if (Shell::options.last_run) { |
| 962 thread_->Join(); | 1050 thread_->Join(); |
| 963 thread_ = NULL; | 1051 thread_ = NULL; |
| 964 } else { | 1052 } else { |
| 965 done_semaphore_->Wait(); | 1053 done_semaphore_->Wait(); |
| 966 } | 1054 } |
| 967 } | 1055 } |
| 1056 #endif // USING_V8_SHARED |
| 968 | 1057 |
| 969 | 1058 |
| 970 bool Shell::SetOptions(int argc, char* argv[]) { | 1059 bool Shell::SetOptions(int argc, char* argv[]) { |
| 971 for (int i = 0; i < argc; i++) { | 1060 for (int i = 0; i < argc; i++) { |
| 972 if (strcmp(argv[i], "--stress-opt") == 0) { | 1061 if (strcmp(argv[i], "--stress-opt") == 0) { |
| 973 options.stress_opt = true; | 1062 options.stress_opt = true; |
| 974 argv[i] = NULL; | 1063 argv[i] = NULL; |
| 975 } else if (strcmp(argv[i], "--stress-deopt") == 0) { | 1064 } else if (strcmp(argv[i], "--stress-deopt") == 0) { |
| 976 options.stress_deopt = true; | 1065 options.stress_deopt = true; |
| 977 argv[i] = NULL; | 1066 argv[i] = NULL; |
| 978 } else if (strcmp(argv[i], "--noalways-opt") == 0) { | 1067 } else if (strcmp(argv[i], "--noalways-opt") == 0) { |
| 979 // No support for stressing if we can't use --always-opt. | 1068 // No support for stressing if we can't use --always-opt. |
| 980 options.stress_opt = false; | 1069 options.stress_opt = false; |
| 981 options.stress_deopt = false; | 1070 options.stress_deopt = false; |
| 982 } else if (strcmp(argv[i], "--shell") == 0) { | 1071 } else if (strcmp(argv[i], "--shell") == 0) { |
| 983 options.interactive_shell = true; | 1072 options.interactive_shell = true; |
| 984 argv[i] = NULL; | 1073 argv[i] = NULL; |
| 985 } else if (strcmp(argv[i], "--test") == 0) { | 1074 } else if (strcmp(argv[i], "--test") == 0) { |
| 986 options.test_shell = true; | 1075 options.test_shell = true; |
| 987 argv[i] = NULL; | 1076 argv[i] = NULL; |
| 988 } else if (strcmp(argv[i], "--preemption") == 0) { | 1077 } else if (strcmp(argv[i], "--preemption") == 0) { |
| 1078 #ifdef USING_V8_SHARED |
| 1079 printf("D8 with shared library does not support multi-threading\n"); |
| 1080 return false; |
| 1081 #else |
| 989 options.use_preemption = true; | 1082 options.use_preemption = true; |
| 990 argv[i] = NULL; | 1083 argv[i] = NULL; |
| 1084 #endif // USING_V8_SHARED |
| 991 } else if (strcmp(argv[i], "--no-preemption") == 0) { | 1085 } else if (strcmp(argv[i], "--no-preemption") == 0) { |
| 1086 #ifdef USING_V8_SHARED |
| 1087 printf("D8 with shared library does not support multi-threading\n"); |
| 1088 return false; |
| 1089 #else |
| 992 options.use_preemption = false; | 1090 options.use_preemption = false; |
| 993 argv[i] = NULL; | 1091 argv[i] = NULL; |
| 1092 #endif // USING_V8_SHARED |
| 994 } else if (strcmp(argv[i], "--preemption-interval") == 0) { | 1093 } else if (strcmp(argv[i], "--preemption-interval") == 0) { |
| 1094 #ifdef USING_V8_SHARED |
| 1095 printf("D8 with shared library does not support multi-threading\n"); |
| 1096 return false; |
| 1097 #else |
| 995 if (++i < argc) { | 1098 if (++i < argc) { |
| 996 argv[i-1] = NULL; | 1099 argv[i-1] = NULL; |
| 997 char* end = NULL; | 1100 char* end = NULL; |
| 998 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT | 1101 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT |
| 999 if (options.preemption_interval <= 0 | 1102 if (options.preemption_interval <= 0 |
| 1000 || *end != '\0' | 1103 || *end != '\0' |
| 1001 || errno == ERANGE) { | 1104 || errno == ERANGE) { |
| 1002 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); | 1105 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); |
| 1003 return false; | 1106 return false; |
| 1004 } | 1107 } |
| 1005 argv[i] = NULL; | 1108 argv[i] = NULL; |
| 1006 } else { | 1109 } else { |
| 1007 printf("Missing value for --preemption-interval\n"); | 1110 printf("Missing value for --preemption-interval\n"); |
| 1008 return false; | 1111 return false; |
| 1009 } | 1112 } |
| 1113 #endif // USING_V8_SHARED |
| 1010 } else if (strcmp(argv[i], "-f") == 0) { | 1114 } else if (strcmp(argv[i], "-f") == 0) { |
| 1011 // Ignore any -f flags for compatibility with other stand-alone | 1115 // Ignore any -f flags for compatibility with other stand-alone |
| 1012 // JavaScript engines. | 1116 // JavaScript engines. |
| 1013 continue; | 1117 continue; |
| 1014 } else if (strcmp(argv[i], "--isolate") == 0) { | 1118 } else if (strcmp(argv[i], "--isolate") == 0) { |
| 1119 #ifdef USING_V8_SHARED |
| 1120 printf("D8 with shared library does not support multi-threading\n"); |
| 1121 return false; |
| 1122 #endif // USING_V8_SHARED |
| 1015 options.num_isolates++; | 1123 options.num_isolates++; |
| 1016 } | 1124 } |
| 1125 #ifdef USING_V8_SHARED |
| 1126 else if (strcmp(argv[i], "--dump-counters") == 0) { |
| 1127 printf("D8 with shared library does not include counters\n"); |
| 1128 return false; |
| 1129 } else if (strcmp(argv[i], "-p") == 0) { |
| 1130 printf("D8 with shared library does not support multi-threading\n"); |
| 1131 return false; |
| 1132 } else if (strcmp(argv[i], "--debugger") == 0) { |
| 1133 printf("Javascript debugger not included\n"); |
| 1134 return false; |
| 1135 } |
| 1136 #endif // USING_V8_SHARED |
| 1017 } | 1137 } |
| 1018 | 1138 |
| 1139 #ifndef USING_V8_SHARED |
| 1019 // Run parallel threads if we are not using --isolate | 1140 // Run parallel threads if we are not using --isolate |
| 1020 for (int i = 1; i < argc; i++) { | 1141 for (int i = 1; i < argc; i++) { |
| 1021 if (argv[i] == NULL) continue; | 1142 if (argv[i] == NULL) continue; |
| 1022 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { | 1143 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { |
| 1023 if (options.num_isolates > 1) { | 1144 if (options.num_isolates > 1) { |
| 1024 printf("-p is not compatible with --isolate\n"); | 1145 printf("-p is not compatible with --isolate\n"); |
| 1025 return false; | 1146 return false; |
| 1026 } | 1147 } |
| 1027 argv[i] = NULL; | 1148 argv[i] = NULL; |
| 1028 if (options.parallel_files == NULL) { | 1149 if (options.parallel_files == NULL) { |
| 1029 options.parallel_files = new i::List<i::Vector<const char> >(); | 1150 options.parallel_files = new i::List<i::Vector<const char> >(); |
| 1030 } | 1151 } |
| 1031 int size = 0; | 1152 int size = 0; |
| 1032 const char* files = ReadChars(argv[++i], &size); | 1153 const char* files = ReadChars(argv[++i], &size); |
| 1033 if (files == NULL) { | 1154 if (files == NULL) { |
| 1034 printf("-p option incomplete\n"); | 1155 printf("-p option incomplete\n"); |
| 1035 return false; | 1156 return false; |
| 1036 } | 1157 } |
| 1037 argv[i] = NULL; | 1158 argv[i] = NULL; |
| 1038 options.parallel_files->Add(i::Vector<const char>(files, size)); | 1159 options.parallel_files->Add(i::Vector<const char>(files, size)); |
| 1039 } | 1160 } |
| 1040 } | 1161 } |
| 1162 #endif // USING_V8_SHARED |
| 1041 | 1163 |
| 1042 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 1164 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 1043 | 1165 |
| 1044 // set up isolated source groups | 1166 // set up isolated source groups |
| 1045 options.isolate_sources = new SourceGroup[options.num_isolates]; | 1167 options.isolate_sources = new SourceGroup[options.num_isolates]; |
| 1046 SourceGroup* current = options.isolate_sources; | 1168 SourceGroup* current = options.isolate_sources; |
| 1047 current->Begin(argv, 1); | 1169 current->Begin(argv, 1); |
| 1048 for (int i = 1; i < argc; i++) { | 1170 for (int i = 1; i < argc; i++) { |
| 1049 const char* str = argv[i]; | 1171 const char* str = argv[i]; |
| 1050 if (strcmp(str, "--isolate") == 0) { | 1172 if (strcmp(str, "--isolate") == 0) { |
| 1051 current->End(i); | 1173 current->End(i); |
| 1052 current++; | 1174 current++; |
| 1053 current->Begin(argv, i + 1); | 1175 current->Begin(argv, i + 1); |
| 1054 } else if (strncmp(argv[i], "--", 2) == 0) { | 1176 } else if (strncmp(argv[i], "--", 2) == 0) { |
| 1055 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); | 1177 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); |
| 1056 } | 1178 } |
| 1057 } | 1179 } |
| 1058 current->End(argc); | 1180 current->End(argc); |
| 1059 | 1181 |
| 1060 return true; | 1182 return true; |
| 1061 } | 1183 } |
| 1062 | 1184 |
| 1063 | 1185 |
| 1064 int Shell::RunMain(int argc, char* argv[]) { | 1186 int Shell::RunMain(int argc, char* argv[]) { |
| 1187 #ifndef USING_V8_SHARED |
| 1065 i::List<i::Thread*> threads(1); | 1188 i::List<i::Thread*> threads(1); |
| 1066 | 1189 if (options.parallel_files != NULL) |
| 1067 { | 1190 for (int i = 0; i < options.parallel_files->length(); i++) { |
| 1068 if (options.parallel_files != NULL) | 1191 i::Vector<const char> files = options.parallel_files->at(i); |
| 1069 for (int i = 0; i < options.parallel_files->length(); i++) { | 1192 ShellThread* thread = new ShellThread(threads.length(), files); |
| 1070 i::Vector<const char> files = options.parallel_files->at(i); | 1193 thread->Start(); |
| 1071 ShellThread* thread = new ShellThread(threads.length(), files); | 1194 threads.Add(thread); |
| 1072 thread->Start(); | |
| 1073 threads.Add(thread); | |
| 1074 } | |
| 1075 | |
| 1076 for (int i = 1; i < options.num_isolates; ++i) { | |
| 1077 options.isolate_sources[i].StartExecuteInThread(); | |
| 1078 } | 1195 } |
| 1079 | 1196 |
| 1197 for (int i = 1; i < options.num_isolates; ++i) { |
| 1198 options.isolate_sources[i].StartExecuteInThread(); |
| 1199 } |
| 1200 #endif // USING_V8_SHARED |
| 1201 { // NOLINT |
| 1080 Locker lock; | 1202 Locker lock; |
| 1081 HandleScope scope; | 1203 HandleScope scope; |
| 1082 Persistent<Context> context = CreateEvaluationContext(); | 1204 Persistent<Context> context = CreateEvaluationContext(); |
| 1083 { | 1205 { |
| 1084 Context::Scope cscope(context); | 1206 Context::Scope cscope(context); |
| 1085 options.isolate_sources[0].Execute(); | 1207 options.isolate_sources[0].Execute(); |
| 1086 } | 1208 } |
| 1087 if (options.last_run) { | 1209 if (options.last_run) { |
| 1088 // Keep using the same context in the interactive shell | 1210 // Keep using the same context in the interactive shell |
| 1089 evaluation_context_ = context; | 1211 evaluation_context_ = context; |
| 1090 } else { | 1212 } else { |
| 1091 context.Dispose(); | 1213 context.Dispose(); |
| 1092 } | 1214 } |
| 1215 |
| 1216 #ifndef USING_V8_SHARED |
| 1093 // Start preemption if threads have been created and preemption is enabled. | 1217 // Start preemption if threads have been created and preemption is enabled. |
| 1094 if (options.parallel_files != NULL | 1218 if (options.parallel_files != NULL |
| 1095 && threads.length() > 0 | 1219 && threads.length() > 0 |
| 1096 && options.use_preemption) { | 1220 && options.use_preemption) { |
| 1097 Locker::StartPreemption(options.preemption_interval); | 1221 Locker::StartPreemption(options.preemption_interval); |
| 1098 } | 1222 } |
| 1223 #endif // USING_V8_SHARED |
| 1099 } | 1224 } |
| 1100 | 1225 |
| 1226 #ifndef USING_V8_SHARED |
| 1101 for (int i = 1; i < options.num_isolates; ++i) { | 1227 for (int i = 1; i < options.num_isolates; ++i) { |
| 1102 options.isolate_sources[i].WaitForThread(); | 1228 options.isolate_sources[i].WaitForThread(); |
| 1103 } | 1229 } |
| 1104 | 1230 |
| 1105 if (options.parallel_files != NULL) | 1231 if (options.parallel_files != NULL) |
| 1106 for (int i = 0; i < threads.length(); i++) { | 1232 for (int i = 0; i < threads.length(); i++) { |
| 1107 i::Thread* thread = threads[i]; | 1233 i::Thread* thread = threads[i]; |
| 1108 thread->Join(); | 1234 thread->Join(); |
| 1109 delete thread; | 1235 delete thread; |
| 1110 } | 1236 } |
| 1111 | 1237 |
| 1112 OnExit(); | 1238 OnExit(); |
| 1239 #endif // USING_V8_SHARED |
| 1113 return 0; | 1240 return 0; |
| 1114 } | 1241 } |
| 1115 | 1242 |
| 1116 | 1243 |
| 1117 int Shell::Main(int argc, char* argv[]) { | 1244 int Shell::Main(int argc, char* argv[]) { |
| 1118 if (!SetOptions(argc, argv)) return 1; | 1245 if (!SetOptions(argc, argv)) return 1; |
| 1119 Initialize(); | 1246 Initialize(); |
| 1120 | 1247 |
| 1121 int result = 0; | 1248 int result = 0; |
| 1122 if (options.stress_opt || options.stress_deopt) { | 1249 if (options.stress_opt || options.stress_deopt) { |
| 1123 Testing::SetStressRunType( | 1250 Testing::SetStressRunType( |
| 1124 options.stress_opt ? Testing::kStressTypeOpt | 1251 options.stress_opt ? Testing::kStressTypeOpt |
| 1125 : Testing::kStressTypeDeopt); | 1252 : Testing::kStressTypeDeopt); |
| 1126 int stress_runs = Testing::GetStressRuns(); | 1253 int stress_runs = Testing::GetStressRuns(); |
| 1127 for (int i = 0; i < stress_runs && result == 0; i++) { | 1254 for (int i = 0; i < stress_runs && result == 0; i++) { |
| 1128 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | 1255 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); |
| 1129 Testing::PrepareStressRun(i); | 1256 Testing::PrepareStressRun(i); |
| 1130 options.last_run = (i == stress_runs - 1); | 1257 options.last_run = (i == stress_runs - 1); |
| 1131 result = RunMain(argc, argv); | 1258 result = RunMain(argc, argv); |
| 1132 } | 1259 } |
| 1133 printf("======== Full Deoptimization =======\n"); | 1260 printf("======== Full Deoptimization =======\n"); |
| 1134 Testing::DeoptimizeAll(); | 1261 Testing::DeoptimizeAll(); |
| 1135 } else { | 1262 } else { |
| 1136 result = RunMain(argc, argv); | 1263 result = RunMain(argc, argv); |
| 1137 } | 1264 } |
| 1138 | 1265 |
| 1139 #ifdef ENABLE_DEBUGGER_SUPPORT | 1266 |
| 1267 #if !defined(USING_V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 1140 // Run remote debugger if requested, but never on --test | 1268 // Run remote debugger if requested, but never on --test |
| 1141 if (i::FLAG_remote_debugger && !options.test_shell) { | 1269 if (i::FLAG_remote_debugger && !options.test_shell) { |
| 1142 InstallUtilityScript(); | 1270 InstallUtilityScript(); |
| 1143 RunRemoteDebugger(i::FLAG_debugger_port); | 1271 RunRemoteDebugger(i::FLAG_debugger_port); |
| 1144 return 0; | 1272 return 0; |
| 1145 } | 1273 } |
| 1146 #endif | 1274 #endif // !USING_V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1147 | 1275 |
| 1148 // Run interactive shell if explicitly requested or if no script has been | 1276 // Run interactive shell if explicitly requested or if no script has been |
| 1149 // executed, but never on --test | 1277 // executed, but never on --test |
| 1150 | 1278 |
| 1151 if (( options.interactive_shell | 1279 if (( options.interactive_shell |
| 1152 || !options.script_executed ) | 1280 || !options.script_executed ) |
| 1153 && !options.test_shell ) { | 1281 && !options.test_shell ) { |
| 1282 #ifndef USING_V8_SHARED |
| 1154 InstallUtilityScript(); | 1283 InstallUtilityScript(); |
| 1284 #endif // USING_V8_SHARED |
| 1155 RunShell(); | 1285 RunShell(); |
| 1156 } | 1286 } |
| 1157 | 1287 |
| 1158 V8::Dispose(); | 1288 V8::Dispose(); |
| 1159 | 1289 |
| 1160 return result; | 1290 return result; |
| 1161 } | 1291 } |
| 1162 | 1292 |
| 1163 } // namespace v8 | 1293 } // namespace v8 |
| 1164 | 1294 |
| 1165 | 1295 |
| 1166 #ifndef GOOGLE3 | 1296 #ifndef GOOGLE3 |
| 1167 int main(int argc, char* argv[]) { | 1297 int main(int argc, char* argv[]) { |
| 1168 return v8::Shell::Main(argc, argv); | 1298 return v8::Shell::Main(argc, argv); |
| 1169 } | 1299 } |
| 1170 #endif | 1300 #endif |
| OLD | NEW |