| OLD | NEW |
| 1 // Copyright 2012 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 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 #ifndef V8_SHARED | 61 #ifndef V8_SHARED |
| 62 #include "api.h" | 62 #include "api.h" |
| 63 #include "checks.h" | 63 #include "checks.h" |
| 64 #include "cpu.h" | 64 #include "cpu.h" |
| 65 #include "d8-debug.h" | 65 #include "d8-debug.h" |
| 66 #include "debug.h" | 66 #include "debug.h" |
| 67 #include "natives.h" | 67 #include "natives.h" |
| 68 #include "platform.h" | 68 #include "platform.h" |
| 69 #include "v8.h" | 69 #include "v8.h" |
| 70 #endif // V8_SHARED | 70 #endif // !V8_SHARED |
| 71 | 71 |
| 72 #if !defined(_WIN32) && !defined(_WIN64) | 72 #if !defined(_WIN32) && !defined(_WIN64) |
| 73 #include <unistd.h> // NOLINT | 73 #include <unistd.h> // NOLINT |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 #ifndef ASSERT | 76 #ifndef ASSERT |
| 77 #define ASSERT(condition) assert(condition) | 77 #define ASSERT(condition) assert(condition) |
| 78 #endif | 78 #endif |
| 79 | 79 |
| 80 namespace v8 { | 80 namespace v8 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 | 157 |
| 158 #ifndef V8_SHARED | 158 #ifndef V8_SHARED |
| 159 CounterMap* Shell::counter_map_; | 159 CounterMap* Shell::counter_map_; |
| 160 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 160 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; |
| 161 CounterCollection Shell::local_counters_; | 161 CounterCollection Shell::local_counters_; |
| 162 CounterCollection* Shell::counters_ = &local_counters_; | 162 CounterCollection* Shell::counters_ = &local_counters_; |
| 163 i::Mutex Shell::context_mutex_; | 163 i::Mutex Shell::context_mutex_; |
| 164 const i::TimeTicks Shell::kInitialTicks = i::TimeTicks::HighResolutionNow(); | 164 const i::TimeTicks Shell::kInitialTicks = i::TimeTicks::HighResolutionNow(); |
| 165 Persistent<Context> Shell::utility_context_; | 165 Persistent<Context> Shell::utility_context_; |
| 166 #endif // V8_SHARED | 166 #endif // !V8_SHARED |
| 167 | 167 |
| 168 Persistent<Context> Shell::evaluation_context_; | 168 Persistent<Context> Shell::evaluation_context_; |
| 169 ShellOptions Shell::options; | 169 ShellOptions Shell::options; |
| 170 const char* Shell::kPrompt = "d8> "; | 170 const char* Shell::kPrompt = "d8> "; |
| 171 | 171 |
| 172 | 172 |
| 173 #ifndef V8_SHARED | 173 #ifndef V8_SHARED |
| 174 const int MB = 1024 * 1024; | 174 const int MB = 1024 * 1024; |
| 175 | 175 |
| 176 bool CounterMap::Match(void* key1, void* key2) { | 176 bool CounterMap::Match(void* key1, void* key2) { |
| 177 const char* name1 = reinterpret_cast<const char*>(key1); | 177 const char* name1 = reinterpret_cast<const char*>(key1); |
| 178 const char* name2 = reinterpret_cast<const char*>(key2); | 178 const char* name2 = reinterpret_cast<const char*>(key2); |
| 179 return strcmp(name1, name2) == 0; | 179 return strcmp(name1, name2) == 0; |
| 180 } | 180 } |
| 181 #endif // V8_SHARED | 181 #endif // !V8_SHARED |
| 182 | 182 |
| 183 | 183 |
| 184 // Converts a V8 value to a C string. | 184 // Converts a V8 value to a C string. |
| 185 const char* Shell::ToCString(const v8::String::Utf8Value& value) { | 185 const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
| 186 return *value ? *value : "<string conversion failed>"; | 186 return *value ? *value : "<string conversion failed>"; |
| 187 } | 187 } |
| 188 | 188 |
| 189 | 189 |
| 190 // Executes a string within the current v8 context. | 190 // Executes a string within the current v8 context. |
| 191 bool Shell::ExecuteString(Isolate* isolate, | 191 bool Shell::ExecuteString(Isolate* isolate, |
| 192 Handle<String> source, | 192 Handle<String> source, |
| 193 Handle<Value> name, | 193 Handle<Value> name, |
| 194 bool print_result, | 194 bool print_result, |
| 195 bool report_exceptions) { | 195 bool report_exceptions) { |
| 196 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 196 #ifndef V8_SHARED |
| 197 bool FLAG_debugger = i::FLAG_debugger; | 197 bool FLAG_debugger = i::FLAG_debugger; |
| 198 #else | 198 #else |
| 199 bool FLAG_debugger = false; | 199 bool FLAG_debugger = false; |
| 200 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 200 #endif // !V8_SHARED |
| 201 HandleScope handle_scope(isolate); | 201 HandleScope handle_scope(isolate); |
| 202 TryCatch try_catch; | 202 TryCatch try_catch; |
| 203 options.script_executed = true; | 203 options.script_executed = true; |
| 204 if (FLAG_debugger) { | 204 if (FLAG_debugger) { |
| 205 // When debugging make exceptions appear to be uncaught. | 205 // When debugging make exceptions appear to be uncaught. |
| 206 try_catch.SetVerbose(true); | 206 try_catch.SetVerbose(true); |
| 207 } | 207 } |
| 208 ScriptOrigin origin(name); | 208 ScriptOrigin origin(name); |
| 209 ScriptCompiler::Source script_source(source, origin); | 209 ScriptCompiler::Source script_source(source, origin); |
| 210 Handle<UnboundScript> script = | 210 Handle<UnboundScript> script = |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 return index; | 310 return index; |
| 311 } | 311 } |
| 312 | 312 |
| 313 | 313 |
| 314 #ifndef V8_SHARED | 314 #ifndef V8_SHARED |
| 315 // performance.now() returns a time stamp as double, measured in milliseconds. | 315 // performance.now() returns a time stamp as double, measured in milliseconds. |
| 316 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { | 316 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 317 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks; | 317 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks; |
| 318 args.GetReturnValue().Set(delta.InMillisecondsF()); | 318 args.GetReturnValue().Set(delta.InMillisecondsF()); |
| 319 } | 319 } |
| 320 #endif // V8_SHARED | 320 #endif // !V8_SHARED |
| 321 | 321 |
| 322 | 322 |
| 323 // Realm.current() returns the index of the currently active realm. | 323 // Realm.current() returns the index of the currently active realm. |
| 324 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) { | 324 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 325 Isolate* isolate = args.GetIsolate(); | 325 Isolate* isolate = args.GetIsolate(); |
| 326 PerIsolateData* data = PerIsolateData::Get(isolate); | 326 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 327 int index = data->RealmFind(isolate->GetEnteredContext()); | 327 int index = data->RealmFind(isolate->GetEnteredContext()); |
| 328 if (index == -1) return; | 328 if (index == -1) return; |
| 329 args.GetReturnValue().Set(index); | 329 args.GetReturnValue().Set(index); |
| 330 } | 330 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 554 |
| 555 | 555 |
| 556 void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) { | 556 void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 557 args.GetReturnValue().Set( | 557 args.GetReturnValue().Set( |
| 558 String::NewFromUtf8(args.GetIsolate(), V8::GetVersion())); | 558 String::NewFromUtf8(args.GetIsolate(), V8::GetVersion())); |
| 559 } | 559 } |
| 560 | 560 |
| 561 | 561 |
| 562 void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { | 562 void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { |
| 563 HandleScope handle_scope(isolate); | 563 HandleScope handle_scope(isolate); |
| 564 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 564 #ifndef V8_SHARED |
| 565 Handle<Context> utility_context; | 565 Handle<Context> utility_context; |
| 566 bool enter_context = !isolate->InContext(); | 566 bool enter_context = !isolate->InContext(); |
| 567 if (enter_context) { | 567 if (enter_context) { |
| 568 utility_context = Local<Context>::New(isolate, utility_context_); | 568 utility_context = Local<Context>::New(isolate, utility_context_); |
| 569 utility_context->Enter(); | 569 utility_context->Enter(); |
| 570 } | 570 } |
| 571 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 571 #endif // !V8_SHARED |
| 572 v8::String::Utf8Value exception(try_catch->Exception()); | 572 v8::String::Utf8Value exception(try_catch->Exception()); |
| 573 const char* exception_string = ToCString(exception); | 573 const char* exception_string = ToCString(exception); |
| 574 Handle<Message> message = try_catch->Message(); | 574 Handle<Message> message = try_catch->Message(); |
| 575 if (message.IsEmpty()) { | 575 if (message.IsEmpty()) { |
| 576 // V8 didn't provide any extra information about this error; just | 576 // V8 didn't provide any extra information about this error; just |
| 577 // print the exception. | 577 // print the exception. |
| 578 printf("%s\n", exception_string); | 578 printf("%s\n", exception_string); |
| 579 } else { | 579 } else { |
| 580 // Print (filename):(line number): (message). | 580 // Print (filename):(line number): (message). |
| 581 v8::String::Utf8Value filename(message->GetScriptResourceName()); | 581 v8::String::Utf8Value filename(message->GetScriptResourceName()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 596 printf("^"); | 596 printf("^"); |
| 597 } | 597 } |
| 598 printf("\n"); | 598 printf("\n"); |
| 599 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 599 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
| 600 if (stack_trace.length() > 0) { | 600 if (stack_trace.length() > 0) { |
| 601 const char* stack_trace_string = ToCString(stack_trace); | 601 const char* stack_trace_string = ToCString(stack_trace); |
| 602 printf("%s\n", stack_trace_string); | 602 printf("%s\n", stack_trace_string); |
| 603 } | 603 } |
| 604 } | 604 } |
| 605 printf("\n"); | 605 printf("\n"); |
| 606 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 606 #ifndef V8_SHARED |
| 607 if (enter_context) utility_context->Exit(); | 607 if (enter_context) utility_context->Exit(); |
| 608 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 608 #endif // !V8_SHARED |
| 609 } | 609 } |
| 610 | 610 |
| 611 | 611 |
| 612 #ifndef V8_SHARED | 612 #ifndef V8_SHARED |
| 613 Handle<Array> Shell::GetCompletions(Isolate* isolate, | 613 Handle<Array> Shell::GetCompletions(Isolate* isolate, |
| 614 Handle<String> text, | 614 Handle<String> text, |
| 615 Handle<String> full) { | 615 Handle<String> full) { |
| 616 EscapableHandleScope handle_scope(isolate); | 616 EscapableHandleScope handle_scope(isolate); |
| 617 v8::Local<v8::Context> utility_context = | 617 v8::Local<v8::Context> utility_context = |
| 618 v8::Local<v8::Context>::New(isolate, utility_context_); | 618 v8::Local<v8::Context>::New(isolate, utility_context_); |
| 619 v8::Context::Scope context_scope(utility_context); | 619 v8::Context::Scope context_scope(utility_context); |
| 620 Handle<Object> global = utility_context->Global(); | 620 Handle<Object> global = utility_context->Global(); |
| 621 Local<Value> fun = | 621 Local<Value> fun = |
| 622 global->Get(String::NewFromUtf8(isolate, "GetCompletions")); | 622 global->Get(String::NewFromUtf8(isolate, "GetCompletions")); |
| 623 static const int kArgc = 3; | 623 static const int kArgc = 3; |
| 624 v8::Local<v8::Context> evaluation_context = | 624 v8::Local<v8::Context> evaluation_context = |
| 625 v8::Local<v8::Context>::New(isolate, evaluation_context_); | 625 v8::Local<v8::Context>::New(isolate, evaluation_context_); |
| 626 Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full }; | 626 Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full }; |
| 627 Local<Value> val = Local<Function>::Cast(fun)->Call(global, kArgc, argv); | 627 Local<Value> val = Local<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 628 return handle_scope.Escape(Local<Array>::Cast(val)); | 628 return handle_scope.Escape(Local<Array>::Cast(val)); |
| 629 } | 629 } |
| 630 | 630 |
| 631 | 631 |
| 632 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 633 Local<Object> Shell::DebugMessageDetails(Isolate* isolate, | 632 Local<Object> Shell::DebugMessageDetails(Isolate* isolate, |
| 634 Handle<String> message) { | 633 Handle<String> message) { |
| 635 EscapableHandleScope handle_scope(isolate); | 634 EscapableHandleScope handle_scope(isolate); |
| 636 v8::Local<v8::Context> context = | 635 v8::Local<v8::Context> context = |
| 637 v8::Local<v8::Context>::New(isolate, utility_context_); | 636 v8::Local<v8::Context>::New(isolate, utility_context_); |
| 638 v8::Context::Scope context_scope(context); | 637 v8::Context::Scope context_scope(context); |
| 639 Handle<Object> global = context->Global(); | 638 Handle<Object> global = context->Global(); |
| 640 Handle<Value> fun = | 639 Handle<Value> fun = |
| 641 global->Get(String::NewFromUtf8(isolate, "DebugMessageDetails")); | 640 global->Get(String::NewFromUtf8(isolate, "DebugMessageDetails")); |
| 642 static const int kArgc = 1; | 641 static const int kArgc = 1; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 663 | 662 |
| 664 | 663 |
| 665 void Shell::DispatchDebugMessages() { | 664 void Shell::DispatchDebugMessages() { |
| 666 Isolate* isolate = v8::Isolate::GetCurrent(); | 665 Isolate* isolate = v8::Isolate::GetCurrent(); |
| 667 HandleScope handle_scope(isolate); | 666 HandleScope handle_scope(isolate); |
| 668 v8::Local<v8::Context> context = | 667 v8::Local<v8::Context> context = |
| 669 v8::Local<v8::Context>::New(isolate, Shell::evaluation_context_); | 668 v8::Local<v8::Context>::New(isolate, Shell::evaluation_context_); |
| 670 v8::Context::Scope context_scope(context); | 669 v8::Context::Scope context_scope(context); |
| 671 v8::Debug::ProcessDebugMessages(); | 670 v8::Debug::ProcessDebugMessages(); |
| 672 } | 671 } |
| 673 #endif // ENABLE_DEBUGGER_SUPPORT | |
| 674 #endif // V8_SHARED | |
| 675 | 672 |
| 676 | 673 |
| 677 #ifndef V8_SHARED | |
| 678 int32_t* Counter::Bind(const char* name, bool is_histogram) { | 674 int32_t* Counter::Bind(const char* name, bool is_histogram) { |
| 679 int i; | 675 int i; |
| 680 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 676 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |
| 681 name_[i] = static_cast<char>(name[i]); | 677 name_[i] = static_cast<char>(name[i]); |
| 682 name_[i] = '\0'; | 678 name_[i] = '\0'; |
| 683 is_histogram_ = is_histogram; | 679 is_histogram_ = is_histogram; |
| 684 return ptr(); | 680 return ptr(); |
| 685 } | 681 } |
| 686 | 682 |
| 687 | 683 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 // If we use the utility context, we have to set the security tokens so that | 775 // If we use the utility context, we have to set the security tokens so that |
| 780 // utility, evaluation and debug context can all access each other. | 776 // utility, evaluation and debug context can all access each other. |
| 781 v8::Local<v8::Context> utility_context = | 777 v8::Local<v8::Context> utility_context = |
| 782 v8::Local<v8::Context>::New(isolate, utility_context_); | 778 v8::Local<v8::Context>::New(isolate, utility_context_); |
| 783 v8::Local<v8::Context> evaluation_context = | 779 v8::Local<v8::Context> evaluation_context = |
| 784 v8::Local<v8::Context>::New(isolate, evaluation_context_); | 780 v8::Local<v8::Context>::New(isolate, evaluation_context_); |
| 785 utility_context->SetSecurityToken(Undefined(isolate)); | 781 utility_context->SetSecurityToken(Undefined(isolate)); |
| 786 evaluation_context->SetSecurityToken(Undefined(isolate)); | 782 evaluation_context->SetSecurityToken(Undefined(isolate)); |
| 787 v8::Context::Scope context_scope(utility_context); | 783 v8::Context::Scope context_scope(utility_context); |
| 788 | 784 |
| 789 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 790 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); | 785 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); |
| 791 // Install the debugger object in the utility scope | 786 // Install the debugger object in the utility scope |
| 792 i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug(); | 787 i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug(); |
| 793 debug->Load(); | 788 debug->Load(); |
| 794 i::Handle<i::JSObject> js_debug | 789 i::Handle<i::JSObject> js_debug |
| 795 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); | 790 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); |
| 796 utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"), | 791 utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"), |
| 797 Utils::ToLocal(js_debug)); | 792 Utils::ToLocal(js_debug)); |
| 798 debug->debug_context()->set_security_token( | 793 debug->debug_context()->set_security_token( |
| 799 reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value()); | 794 reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value()); |
| 800 #endif // ENABLE_DEBUGGER_SUPPORT | |
| 801 | 795 |
| 802 // Run the d8 shell utility script in the utility context | 796 // Run the d8 shell utility script in the utility context |
| 803 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 797 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |
| 804 i::Vector<const char> shell_source = | 798 i::Vector<const char> shell_source = |
| 805 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | 799 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); |
| 806 i::Vector<const char> shell_source_name = | 800 i::Vector<const char> shell_source_name = |
| 807 i::NativesCollection<i::D8>::GetScriptName(source_index); | 801 i::NativesCollection<i::D8>::GetScriptName(source_index); |
| 808 Handle<String> source = | 802 Handle<String> source = |
| 809 String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString, | 803 String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString, |
| 810 shell_source.length()); | 804 shell_source.length()); |
| 811 Handle<String> name = | 805 Handle<String> name = |
| 812 String::NewFromUtf8(isolate, shell_source_name.start(), | 806 String::NewFromUtf8(isolate, shell_source_name.start(), |
| 813 String::kNormalString, shell_source_name.length()); | 807 String::kNormalString, shell_source_name.length()); |
| 814 ScriptOrigin origin(name); | 808 ScriptOrigin origin(name); |
| 815 Handle<Script> script = Script::Compile(source, &origin); | 809 Handle<Script> script = Script::Compile(source, &origin); |
| 816 script->Run(); | 810 script->Run(); |
| 817 // Mark the d8 shell script as native to avoid it showing up as normal source | 811 // Mark the d8 shell script as native to avoid it showing up as normal source |
| 818 // in the debugger. | 812 // in the debugger. |
| 819 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); | 813 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); |
| 820 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() | 814 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() |
| 821 ? i::Handle<i::Script>(i::Script::cast( | 815 ? i::Handle<i::Script>(i::Script::cast( |
| 822 i::JSFunction::cast(*compiled_script)->shared()->script())) | 816 i::JSFunction::cast(*compiled_script)->shared()->script())) |
| 823 : i::Handle<i::Script>(i::Script::cast( | 817 : i::Handle<i::Script>(i::Script::cast( |
| 824 i::SharedFunctionInfo::cast(*compiled_script)->script())); | 818 i::SharedFunctionInfo::cast(*compiled_script)->script())); |
| 825 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); | 819 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); |
| 826 | 820 |
| 827 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 828 // Start the in-process debugger if requested. | 821 // Start the in-process debugger if requested. |
| 829 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 822 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
| 830 v8::Debug::SetDebugEventListener2(HandleDebugEvent); | 823 v8::Debug::SetDebugEventListener2(HandleDebugEvent); |
| 831 } | 824 } |
| 832 #endif // ENABLE_DEBUGGER_SUPPORT | |
| 833 } | 825 } |
| 834 #endif // V8_SHARED | 826 #endif // !V8_SHARED |
| 835 | 827 |
| 836 | 828 |
| 837 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 829 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 838 class BZip2Decompressor : public v8::StartupDataDecompressor { | 830 class BZip2Decompressor : public v8::StartupDataDecompressor { |
| 839 public: | 831 public: |
| 840 virtual ~BZip2Decompressor() { } | 832 virtual ~BZip2Decompressor() { } |
| 841 | 833 |
| 842 protected: | 834 protected: |
| 843 virtual int DecompressData(char* raw_data, | 835 virtual int DecompressData(char* raw_data, |
| 844 int* raw_data_size, | 836 int* raw_data_size, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 realm_template->SetAccessor(String::NewFromUtf8(isolate, "shared"), | 892 realm_template->SetAccessor(String::NewFromUtf8(isolate, "shared"), |
| 901 RealmSharedGet, RealmSharedSet); | 893 RealmSharedGet, RealmSharedSet); |
| 902 global_template->Set(String::NewFromUtf8(isolate, "Realm"), realm_template); | 894 global_template->Set(String::NewFromUtf8(isolate, "Realm"), realm_template); |
| 903 | 895 |
| 904 #ifndef V8_SHARED | 896 #ifndef V8_SHARED |
| 905 Handle<ObjectTemplate> performance_template = ObjectTemplate::New(isolate); | 897 Handle<ObjectTemplate> performance_template = ObjectTemplate::New(isolate); |
| 906 performance_template->Set(String::NewFromUtf8(isolate, "now"), | 898 performance_template->Set(String::NewFromUtf8(isolate, "now"), |
| 907 FunctionTemplate::New(isolate, PerformanceNow)); | 899 FunctionTemplate::New(isolate, PerformanceNow)); |
| 908 global_template->Set(String::NewFromUtf8(isolate, "performance"), | 900 global_template->Set(String::NewFromUtf8(isolate, "performance"), |
| 909 performance_template); | 901 performance_template); |
| 910 #endif // V8_SHARED | 902 #endif // !V8_SHARED |
| 911 | 903 |
| 912 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) | 904 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) |
| 913 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(isolate); | 905 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(isolate); |
| 914 AddOSMethods(isolate, os_templ); | 906 AddOSMethods(isolate, os_templ); |
| 915 global_template->Set(String::NewFromUtf8(isolate, "os"), os_templ); | 907 global_template->Set(String::NewFromUtf8(isolate, "os"), os_templ); |
| 916 #endif // V8_SHARED | 908 #endif // !V8_SHARED && !_WIN32 && !_WIN64 |
| 917 | 909 |
| 918 return global_template; | 910 return global_template; |
| 919 } | 911 } |
| 920 | 912 |
| 921 | 913 |
| 922 void Shell::Initialize(Isolate* isolate) { | 914 void Shell::Initialize(Isolate* isolate) { |
| 923 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 915 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 924 BZip2Decompressor startup_data_decompressor; | 916 BZip2Decompressor startup_data_decompressor; |
| 925 int bz2_result = startup_data_decompressor.Decompress(); | 917 int bz2_result = startup_data_decompressor.Decompress(); |
| 926 if (bz2_result != BZ_OK) { | 918 if (bz2_result != BZ_OK) { |
| 927 fprintf(stderr, "bzip error code: %d\n", bz2_result); | 919 fprintf(stderr, "bzip error code: %d\n", bz2_result); |
| 928 Exit(1); | 920 Exit(1); |
| 929 } | 921 } |
| 930 #endif | 922 #endif |
| 931 | 923 |
| 932 #ifndef V8_SHARED | 924 #ifndef V8_SHARED |
| 933 Shell::counter_map_ = new CounterMap(); | 925 Shell::counter_map_ = new CounterMap(); |
| 934 // Set up counters | 926 // Set up counters |
| 935 if (i::StrLength(i::FLAG_map_counters) != 0) | 927 if (i::StrLength(i::FLAG_map_counters) != 0) |
| 936 MapCounters(i::FLAG_map_counters); | 928 MapCounters(i::FLAG_map_counters); |
| 937 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { | 929 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { |
| 938 V8::SetCounterFunction(LookupCounter); | 930 V8::SetCounterFunction(LookupCounter); |
| 939 V8::SetCreateHistogramFunction(CreateHistogram); | 931 V8::SetCreateHistogramFunction(CreateHistogram); |
| 940 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 932 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 941 } | 933 } |
| 942 #endif // V8_SHARED | 934 #endif // !V8_SHARED |
| 943 } | 935 } |
| 944 | 936 |
| 945 | 937 |
| 946 void Shell::InitializeDebugger(Isolate* isolate) { | 938 void Shell::InitializeDebugger(Isolate* isolate) { |
| 947 if (options.test_shell) return; | 939 if (options.test_shell) return; |
| 948 #ifndef V8_SHARED | 940 #ifndef V8_SHARED |
| 949 Locker lock(isolate); | 941 Locker lock(isolate); |
| 950 HandleScope scope(isolate); | 942 HandleScope scope(isolate); |
| 951 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 943 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
| 952 utility_context_.Reset(isolate, | 944 utility_context_.Reset(isolate, |
| 953 Context::New(isolate, NULL, global_template)); | 945 Context::New(isolate, NULL, global_template)); |
| 954 | 946 |
| 955 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 956 // Start the debugger agent if requested. | 947 // Start the debugger agent if requested. |
| 957 if (i::FLAG_debugger_agent) { | 948 if (i::FLAG_debugger_agent) { |
| 958 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 949 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| 959 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); | 950 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); |
| 960 } | 951 } |
| 961 #endif // ENABLE_DEBUGGER_SUPPORT | 952 #endif // !V8_SHARED |
| 962 #endif // V8_SHARED | |
| 963 } | 953 } |
| 964 | 954 |
| 965 | 955 |
| 966 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 956 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
| 967 #ifndef V8_SHARED | 957 #ifndef V8_SHARED |
| 968 // This needs to be a critical section since this is not thread-safe | 958 // This needs to be a critical section since this is not thread-safe |
| 969 i::LockGuard<i::Mutex> lock_guard(&context_mutex_); | 959 i::LockGuard<i::Mutex> lock_guard(&context_mutex_); |
| 970 #endif // V8_SHARED | 960 #endif // !V8_SHARED |
| 971 // Initialize the global objects | 961 // Initialize the global objects |
| 972 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 962 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
| 973 EscapableHandleScope handle_scope(isolate); | 963 EscapableHandleScope handle_scope(isolate); |
| 974 Local<Context> context = Context::New(isolate, NULL, global_template); | 964 Local<Context> context = Context::New(isolate, NULL, global_template); |
| 975 ASSERT(!context.IsEmpty()); | 965 ASSERT(!context.IsEmpty()); |
| 976 Context::Scope scope(context); | 966 Context::Scope scope(context); |
| 977 | 967 |
| 978 #ifndef V8_SHARED | 968 #ifndef V8_SHARED |
| 979 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); | 969 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); |
| 980 i::JSArguments js_args = i::FLAG_js_arguments; | 970 i::JSArguments js_args = i::FLAG_js_arguments; |
| 981 i::Handle<i::FixedArray> arguments_array = | 971 i::Handle<i::FixedArray> arguments_array = |
| 982 factory->NewFixedArray(js_args.argc); | 972 factory->NewFixedArray(js_args.argc); |
| 983 for (int j = 0; j < js_args.argc; j++) { | 973 for (int j = 0; j < js_args.argc; j++) { |
| 984 i::Handle<i::String> arg = | 974 i::Handle<i::String> arg = |
| 985 factory->NewStringFromUtf8(i::CStrVector(js_args[j])).ToHandleChecked(); | 975 factory->NewStringFromUtf8(i::CStrVector(js_args[j])).ToHandleChecked(); |
| 986 arguments_array->set(j, *arg); | 976 arguments_array->set(j, *arg); |
| 987 } | 977 } |
| 988 i::Handle<i::JSArray> arguments_jsarray = | 978 i::Handle<i::JSArray> arguments_jsarray = |
| 989 factory->NewJSArrayWithElements(arguments_array); | 979 factory->NewJSArrayWithElements(arguments_array); |
| 990 context->Global()->Set(String::NewFromUtf8(isolate, "arguments"), | 980 context->Global()->Set(String::NewFromUtf8(isolate, "arguments"), |
| 991 Utils::ToLocal(arguments_jsarray)); | 981 Utils::ToLocal(arguments_jsarray)); |
| 992 #endif // V8_SHARED | 982 #endif // !V8_SHARED |
| 993 return handle_scope.Escape(context); | 983 return handle_scope.Escape(context); |
| 994 } | 984 } |
| 995 | 985 |
| 996 | 986 |
| 997 void Shell::Exit(int exit_code) { | 987 void Shell::Exit(int exit_code) { |
| 998 // Use _exit instead of exit to avoid races between isolate | 988 // Use _exit instead of exit to avoid races between isolate |
| 999 // threads and static destructors. | 989 // threads and static destructors. |
| 1000 fflush(stdout); | 990 fflush(stdout); |
| 1001 fflush(stderr); | 991 fflush(stderr); |
| 1002 _exit(exit_code); | 992 _exit(exit_code); |
| 1003 } | 993 } |
| 1004 | 994 |
| 1005 | 995 |
| 1006 #ifndef V8_SHARED | 996 #ifndef V8_SHARED |
| 1007 struct CounterAndKey { | 997 struct CounterAndKey { |
| 1008 Counter* counter; | 998 Counter* counter; |
| 1009 const char* key; | 999 const char* key; |
| 1010 }; | 1000 }; |
| 1011 | 1001 |
| 1012 | 1002 |
| 1013 inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) { | 1003 inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) { |
| 1014 return strcmp(lhs.key, rhs.key) < 0; | 1004 return strcmp(lhs.key, rhs.key) < 0; |
| 1015 } | 1005 } |
| 1016 #endif // V8_SHARED | 1006 #endif // !V8_SHARED |
| 1017 | 1007 |
| 1018 | 1008 |
| 1019 void Shell::OnExit() { | 1009 void Shell::OnExit() { |
| 1020 LineEditor* line_editor = LineEditor::Get(); | 1010 LineEditor* line_editor = LineEditor::Get(); |
| 1021 if (line_editor) line_editor->Close(); | 1011 if (line_editor) line_editor->Close(); |
| 1022 #ifndef V8_SHARED | 1012 #ifndef V8_SHARED |
| 1023 if (i::FLAG_dump_counters) { | 1013 if (i::FLAG_dump_counters) { |
| 1024 int number_of_counters = 0; | 1014 int number_of_counters = 0; |
| 1025 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 1015 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { |
| 1026 number_of_counters++; | 1016 number_of_counters++; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1047 } else { | 1037 } else { |
| 1048 printf("| %-62s | %11i |\n", key, counter->count()); | 1038 printf("| %-62s | %11i |\n", key, counter->count()); |
| 1049 } | 1039 } |
| 1050 } | 1040 } |
| 1051 printf("+----------------------------------------------------------------+" | 1041 printf("+----------------------------------------------------------------+" |
| 1052 "-------------+\n"); | 1042 "-------------+\n"); |
| 1053 delete [] counters; | 1043 delete [] counters; |
| 1054 } | 1044 } |
| 1055 delete counters_file_; | 1045 delete counters_file_; |
| 1056 delete counter_map_; | 1046 delete counter_map_; |
| 1057 #endif // V8_SHARED | 1047 #endif // !V8_SHARED |
| 1058 } | 1048 } |
| 1059 | 1049 |
| 1060 | 1050 |
| 1061 | 1051 |
| 1062 static FILE* FOpen(const char* path, const char* mode) { | 1052 static FILE* FOpen(const char* path, const char* mode) { |
| 1063 #if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) | 1053 #if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) |
| 1064 FILE* result; | 1054 FILE* result; |
| 1065 if (fopen_s(&result, path, mode) == 0) { | 1055 if (fopen_s(&result, path, mode) == 0) { |
| 1066 return result; | 1056 return result; |
| 1067 } else { | 1057 } else { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 | 1152 |
| 1163 | 1153 |
| 1164 static char* ReadLine(char* data) { | 1154 static char* ReadLine(char* data) { |
| 1165 return ReadToken(data, '\n'); | 1155 return ReadToken(data, '\n'); |
| 1166 } | 1156 } |
| 1167 | 1157 |
| 1168 | 1158 |
| 1169 static char* ReadWord(char* data) { | 1159 static char* ReadWord(char* data) { |
| 1170 return ReadToken(data, ' '); | 1160 return ReadToken(data, ' '); |
| 1171 } | 1161 } |
| 1172 #endif // V8_SHARED | 1162 #endif // !V8_SHARED |
| 1173 | 1163 |
| 1174 | 1164 |
| 1175 // Reads a file into a v8 string. | 1165 // Reads a file into a v8 string. |
| 1176 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { | 1166 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { |
| 1177 int size = 0; | 1167 int size = 0; |
| 1178 char* chars = ReadChars(isolate, name, &size); | 1168 char* chars = ReadChars(isolate, name, &size); |
| 1179 if (chars == NULL) return Handle<String>(); | 1169 if (chars == NULL) return Handle<String>(); |
| 1180 Handle<String> result = | 1170 Handle<String> result = |
| 1181 String::NewFromUtf8(isolate, chars, String::kNormalString, size); | 1171 String::NewFromUtf8(isolate, chars, String::kNormalString, size); |
| 1182 delete[] chars; | 1172 delete[] chars; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 Shell::Exit(1); | 1250 Shell::Exit(1); |
| 1261 } | 1251 } |
| 1262 | 1252 |
| 1263 Shell::ExecuteString( | 1253 Shell::ExecuteString( |
| 1264 isolate_, str, String::NewFromUtf8(isolate_, filename), false, false); | 1254 isolate_, str, String::NewFromUtf8(isolate_, filename), false, false); |
| 1265 } | 1255 } |
| 1266 | 1256 |
| 1267 ptr = next_line; | 1257 ptr = next_line; |
| 1268 } | 1258 } |
| 1269 } | 1259 } |
| 1270 #endif // V8_SHARED | 1260 #endif // !V8_SHARED |
| 1271 | 1261 |
| 1272 | 1262 |
| 1273 SourceGroup::~SourceGroup() { | 1263 SourceGroup::~SourceGroup() { |
| 1274 #ifndef V8_SHARED | 1264 #ifndef V8_SHARED |
| 1275 delete thread_; | 1265 delete thread_; |
| 1276 thread_ = NULL; | 1266 thread_ = NULL; |
| 1277 #endif // V8_SHARED | 1267 #endif // !V8_SHARED |
| 1278 } | 1268 } |
| 1279 | 1269 |
| 1280 | 1270 |
| 1281 void SourceGroup::Execute(Isolate* isolate) { | 1271 void SourceGroup::Execute(Isolate* isolate) { |
| 1282 bool exception_was_thrown = false; | 1272 bool exception_was_thrown = false; |
| 1283 for (int i = begin_offset_; i < end_offset_; ++i) { | 1273 for (int i = begin_offset_; i < end_offset_; ++i) { |
| 1284 const char* arg = argv_[i]; | 1274 const char* arg = argv_[i]; |
| 1285 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { | 1275 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { |
| 1286 // Execute argument given to -e option directly. | 1276 // Execute argument given to -e option directly. |
| 1287 HandleScope handle_scope(isolate); | 1277 HandleScope handle_scope(isolate); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 | 1365 |
| 1376 | 1366 |
| 1377 void SourceGroup::WaitForThread() { | 1367 void SourceGroup::WaitForThread() { |
| 1378 if (thread_ == NULL) return; | 1368 if (thread_ == NULL) return; |
| 1379 if (Shell::options.last_run) { | 1369 if (Shell::options.last_run) { |
| 1380 thread_->Join(); | 1370 thread_->Join(); |
| 1381 } else { | 1371 } else { |
| 1382 done_semaphore_.Wait(); | 1372 done_semaphore_.Wait(); |
| 1383 } | 1373 } |
| 1384 } | 1374 } |
| 1385 #endif // V8_SHARED | 1375 #endif // !V8_SHARED |
| 1386 | 1376 |
| 1387 | 1377 |
| 1388 bool Shell::SetOptions(int argc, char* argv[]) { | 1378 bool Shell::SetOptions(int argc, char* argv[]) { |
| 1389 for (int i = 0; i < argc; i++) { | 1379 for (int i = 0; i < argc; i++) { |
| 1390 if (strcmp(argv[i], "--stress-opt") == 0) { | 1380 if (strcmp(argv[i], "--stress-opt") == 0) { |
| 1391 options.stress_opt = true; | 1381 options.stress_opt = true; |
| 1392 argv[i] = NULL; | 1382 argv[i] = NULL; |
| 1393 } else if (strcmp(argv[i], "--nostress-opt") == 0) { | 1383 } else if (strcmp(argv[i], "--nostress-opt") == 0) { |
| 1394 options.stress_opt = false; | 1384 options.stress_opt = false; |
| 1395 argv[i] = NULL; | 1385 argv[i] = NULL; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 #else | 1419 #else |
| 1430 options.num_parallel_files++; | 1420 options.num_parallel_files++; |
| 1431 #endif // V8_SHARED | 1421 #endif // V8_SHARED |
| 1432 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { | 1422 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { |
| 1433 #ifdef V8_SHARED | 1423 #ifdef V8_SHARED |
| 1434 printf("D8 with shared library does not support constant dumping\n"); | 1424 printf("D8 with shared library does not support constant dumping\n"); |
| 1435 return false; | 1425 return false; |
| 1436 #else | 1426 #else |
| 1437 options.dump_heap_constants = true; | 1427 options.dump_heap_constants = true; |
| 1438 argv[i] = NULL; | 1428 argv[i] = NULL; |
| 1439 #endif | 1429 #endif // V8_SHARED |
| 1440 } else if (strcmp(argv[i], "--throws") == 0) { | 1430 } else if (strcmp(argv[i], "--throws") == 0) { |
| 1441 options.expected_to_throw = true; | 1431 options.expected_to_throw = true; |
| 1442 argv[i] = NULL; | 1432 argv[i] = NULL; |
| 1443 } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { | 1433 } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { |
| 1444 options.icu_data_file = argv[i] + 16; | 1434 options.icu_data_file = argv[i] + 16; |
| 1445 argv[i] = NULL; | 1435 argv[i] = NULL; |
| 1446 } | 1436 } |
| 1447 #ifdef V8_SHARED | 1437 #ifdef V8_SHARED |
| 1448 else if (strcmp(argv[i], "--dump-counters") == 0) { | 1438 else if (strcmp(argv[i], "--dump-counters") == 0) { |
| 1449 printf("D8 with shared library does not include counters\n"); | 1439 printf("D8 with shared library does not include counters\n"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1470 i++; | 1460 i++; |
| 1471 options.parallel_files[parallel_files_set] = argv[i]; | 1461 options.parallel_files[parallel_files_set] = argv[i]; |
| 1472 parallel_files_set++; | 1462 parallel_files_set++; |
| 1473 argv[i] = NULL; | 1463 argv[i] = NULL; |
| 1474 } | 1464 } |
| 1475 } | 1465 } |
| 1476 if (parallel_files_set != options.num_parallel_files) { | 1466 if (parallel_files_set != options.num_parallel_files) { |
| 1477 printf("-p requires a file containing a list of files as parameter\n"); | 1467 printf("-p requires a file containing a list of files as parameter\n"); |
| 1478 return false; | 1468 return false; |
| 1479 } | 1469 } |
| 1480 #endif // V8_SHARED | 1470 #endif // !V8_SHARED |
| 1481 | 1471 |
| 1482 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 1472 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 1483 | 1473 |
| 1484 // Set up isolated source groups. | 1474 // Set up isolated source groups. |
| 1485 options.isolate_sources = new SourceGroup[options.num_isolates]; | 1475 options.isolate_sources = new SourceGroup[options.num_isolates]; |
| 1486 SourceGroup* current = options.isolate_sources; | 1476 SourceGroup* current = options.isolate_sources; |
| 1487 current->Begin(argv, 1); | 1477 current->Begin(argv, 1); |
| 1488 for (int i = 1; i < argc; i++) { | 1478 for (int i = 1; i < argc; i++) { |
| 1489 const char* str = argv[i]; | 1479 const char* str = argv[i]; |
| 1490 if (strcmp(str, "--isolate") == 0) { | 1480 if (strcmp(str, "--isolate") == 0) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1516 Exit(1); | 1506 Exit(1); |
| 1517 } | 1507 } |
| 1518 ShellThread* thread = new ShellThread(isolate, files); | 1508 ShellThread* thread = new ShellThread(isolate, files); |
| 1519 thread->Start(); | 1509 thread->Start(); |
| 1520 threads.Add(thread); | 1510 threads.Add(thread); |
| 1521 } | 1511 } |
| 1522 } | 1512 } |
| 1523 for (int i = 1; i < options.num_isolates; ++i) { | 1513 for (int i = 1; i < options.num_isolates; ++i) { |
| 1524 options.isolate_sources[i].StartExecuteInThread(); | 1514 options.isolate_sources[i].StartExecuteInThread(); |
| 1525 } | 1515 } |
| 1526 #endif // V8_SHARED | 1516 #endif // !V8_SHARED |
| 1527 { // NOLINT | 1517 { // NOLINT |
| 1528 Locker lock(isolate); | 1518 Locker lock(isolate); |
| 1529 { | 1519 { |
| 1530 HandleScope scope(isolate); | 1520 HandleScope scope(isolate); |
| 1531 Local<Context> context = CreateEvaluationContext(isolate); | 1521 Local<Context> context = CreateEvaluationContext(isolate); |
| 1532 if (options.last_run) { | 1522 if (options.last_run) { |
| 1533 // Keep using the same context in the interactive shell. | 1523 // Keep using the same context in the interactive shell. |
| 1534 evaluation_context_.Reset(isolate, context); | 1524 evaluation_context_.Reset(isolate, context); |
| 1535 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1525 #ifndef V8_SHARED |
| 1536 // If the interactive debugger is enabled make sure to activate | 1526 // If the interactive debugger is enabled make sure to activate |
| 1537 // it before running the files passed on the command line. | 1527 // it before running the files passed on the command line. |
| 1538 if (i::FLAG_debugger) { | 1528 if (i::FLAG_debugger) { |
| 1539 InstallUtilityScript(isolate); | 1529 InstallUtilityScript(isolate); |
| 1540 } | 1530 } |
| 1541 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1531 #endif // !V8_SHARED |
| 1542 } | 1532 } |
| 1543 { | 1533 { |
| 1544 Context::Scope cscope(context); | 1534 Context::Scope cscope(context); |
| 1545 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 1535 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
| 1546 options.isolate_sources[0].Execute(isolate); | 1536 options.isolate_sources[0].Execute(isolate); |
| 1547 } | 1537 } |
| 1548 } | 1538 } |
| 1549 if (!options.last_run) { | 1539 if (!options.last_run) { |
| 1550 if (options.send_idle_notification) { | 1540 if (options.send_idle_notification) { |
| 1551 const int kLongIdlePauseInMs = 1000; | 1541 const int kLongIdlePauseInMs = 1000; |
| 1552 V8::ContextDisposedNotification(); | 1542 V8::ContextDisposedNotification(); |
| 1553 V8::IdleNotification(kLongIdlePauseInMs); | 1543 V8::IdleNotification(kLongIdlePauseInMs); |
| 1554 } | 1544 } |
| 1555 } | 1545 } |
| 1556 } | 1546 } |
| 1557 | 1547 |
| 1558 #ifndef V8_SHARED | 1548 #ifndef V8_SHARED |
| 1559 for (int i = 1; i < options.num_isolates; ++i) { | 1549 for (int i = 1; i < options.num_isolates; ++i) { |
| 1560 options.isolate_sources[i].WaitForThread(); | 1550 options.isolate_sources[i].WaitForThread(); |
| 1561 } | 1551 } |
| 1562 | 1552 |
| 1563 for (int i = 0; i < threads.length(); i++) { | 1553 for (int i = 0; i < threads.length(); i++) { |
| 1564 i::Thread* thread = threads[i]; | 1554 i::Thread* thread = threads[i]; |
| 1565 thread->Join(); | 1555 thread->Join(); |
| 1566 delete thread; | 1556 delete thread; |
| 1567 } | 1557 } |
| 1568 #endif // V8_SHARED | 1558 #endif // !V8_SHARED |
| 1569 return 0; | 1559 return 0; |
| 1570 } | 1560 } |
| 1571 | 1561 |
| 1572 | 1562 |
| 1573 #ifdef V8_SHARED | 1563 #ifdef V8_SHARED |
| 1574 static void SetStandaloneFlagsViaCommandLine() { | 1564 static void SetStandaloneFlagsViaCommandLine() { |
| 1575 int fake_argc = 3; | 1565 int fake_argc = 3; |
| 1576 char **fake_argv = new char*[3]; | 1566 char **fake_argv = new char*[3]; |
| 1577 fake_argv[0] = NULL; | 1567 fake_argv[0] = NULL; |
| 1578 fake_argv[1] = strdup("--trace-hydrogen-file=hydrogen.cfg"); | 1568 fake_argv[1] = strdup("--trace-hydrogen-file=hydrogen.cfg"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 const char* n = NULL; | 1622 const char* n = NULL; |
| 1633 intptr_t p = reinterpret_cast<intptr_t>(o) & 0xfffff; | 1623 intptr_t p = reinterpret_cast<intptr_t>(o) & 0xfffff; |
| 1634 ROOT_LIST(ROOT_LIST_CASE) | 1624 ROOT_LIST(ROOT_LIST_CASE) |
| 1635 if (n == NULL) continue; | 1625 if (n == NULL) continue; |
| 1636 printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n); | 1626 printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n); |
| 1637 } | 1627 } |
| 1638 } | 1628 } |
| 1639 printf("}\n"); | 1629 printf("}\n"); |
| 1640 #undef ROOT_LIST_CASE | 1630 #undef ROOT_LIST_CASE |
| 1641 } | 1631 } |
| 1642 #endif // V8_SHARED | 1632 #endif // !V8_SHARED |
| 1643 | 1633 |
| 1644 | 1634 |
| 1645 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 1635 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 1646 public: | 1636 public: |
| 1647 virtual void* Allocate(size_t length) { | 1637 virtual void* Allocate(size_t length) { |
| 1648 void* result = malloc(length); | 1638 void* result = malloc(length); |
| 1649 memset(result, 0, length); | 1639 memset(result, 0, length); |
| 1650 return result; | 1640 return result; |
| 1651 } | 1641 } |
| 1652 virtual void* AllocateUninitialized(size_t length) { | 1642 virtual void* AllocateUninitialized(size_t length) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 printf("============ Run %d/%d ============\n", i + 1, stress_runs); | 1726 printf("============ Run %d/%d ============\n", i + 1, stress_runs); |
| 1737 options.last_run = (i == stress_runs - 1); | 1727 options.last_run = (i == stress_runs - 1); |
| 1738 result = RunMain(isolate, argc, argv); | 1728 result = RunMain(isolate, argc, argv); |
| 1739 } | 1729 } |
| 1740 #endif | 1730 #endif |
| 1741 } else { | 1731 } else { |
| 1742 result = RunMain(isolate, argc, argv); | 1732 result = RunMain(isolate, argc, argv); |
| 1743 } | 1733 } |
| 1744 | 1734 |
| 1745 | 1735 |
| 1746 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1736 #ifndef V8_SHARED |
| 1747 // Run remote debugger if requested, but never on --test | 1737 // Run remote debugger if requested, but never on --test |
| 1748 if (i::FLAG_remote_debugger && !options.test_shell) { | 1738 if (i::FLAG_remote_debugger && !options.test_shell) { |
| 1749 InstallUtilityScript(isolate); | 1739 InstallUtilityScript(isolate); |
| 1750 RunRemoteDebugger(isolate, i::FLAG_debugger_port); | 1740 RunRemoteDebugger(isolate, i::FLAG_debugger_port); |
| 1751 return 0; | 1741 return 0; |
| 1752 } | 1742 } |
| 1753 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1743 #endif // !V8_SHARED |
| 1754 | 1744 |
| 1755 // Run interactive shell if explicitly requested or if no script has been | 1745 // Run interactive shell if explicitly requested or if no script has been |
| 1756 // executed, but never on --test | 1746 // executed, but never on --test |
| 1757 | 1747 |
| 1758 if (( options.interactive_shell || !options.script_executed ) | 1748 if (( options.interactive_shell || !options.script_executed ) |
| 1759 && !options.test_shell ) { | 1749 && !options.test_shell ) { |
| 1760 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1750 #ifndef V8_SHARED |
| 1761 if (!i::FLAG_debugger) { | 1751 if (!i::FLAG_debugger) { |
| 1762 InstallUtilityScript(isolate); | 1752 InstallUtilityScript(isolate); |
| 1763 } | 1753 } |
| 1764 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1754 #endif // !V8_SHARED |
| 1765 RunShell(isolate); | 1755 RunShell(isolate); |
| 1766 } | 1756 } |
| 1767 } | 1757 } |
| 1768 V8::Dispose(); | 1758 V8::Dispose(); |
| 1769 | 1759 |
| 1770 OnExit(); | 1760 OnExit(); |
| 1771 | 1761 |
| 1772 return result; | 1762 return result; |
| 1773 } | 1763 } |
| 1774 | 1764 |
| 1775 } // namespace v8 | 1765 } // namespace v8 |
| 1776 | 1766 |
| 1777 | 1767 |
| 1778 #ifndef GOOGLE3 | 1768 #ifndef GOOGLE3 |
| 1779 int main(int argc, char* argv[]) { | 1769 int main(int argc, char* argv[]) { |
| 1780 return v8::Shell::Main(argc, argv); | 1770 return v8::Shell::Main(argc, argv); |
| 1781 } | 1771 } |
| 1782 #endif | 1772 #endif |
| OLD | NEW |