Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: src/d8.cc

Issue 7586001: Fixed a known issue in D8 (read file), enabled D8 shared library build on Windows. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed the mess where d8 was getting the BUILDING_V8_SHARED compile flag. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/d8.h ('k') | src/v8threads.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 #ifdef USING_V8_SHARED // Defined when linking against shared lib on Windows.
30 #define USING_V8_SHARED 30 #define V8_SHARED
31 #endif 31 #endif
32 32
33 #ifdef COMPRESS_STARTUP_DATA_BZ2 33 #ifdef COMPRESS_STARTUP_DATA_BZ2
34 #include <bzlib.h> 34 #include <bzlib.h>
35 #endif 35 #endif
36 36
37 #include <errno.h> 37 #include <errno.h>
38 #include <stdlib.h> 38 #include <stdlib.h>
39 #include <string.h> 39 #include <string.h>
40 #include <sys/stat.h>
40 41
41 #ifdef USING_V8_SHARED 42 #ifdef V8_SHARED
42 #include <assert.h> 43 #include <assert.h>
43 #include "../include/v8-testing.h" 44 #include "../include/v8-testing.h"
44 #endif // USING_V8_SHARED 45 #endif // V8_SHARED
45 46
46 #include "d8.h" 47 #include "d8.h"
47 48
48 #ifndef USING_V8_SHARED 49 #ifndef V8_SHARED
49 #include "api.h" 50 #include "api.h"
50 #include "checks.h" 51 #include "checks.h"
51 #include "d8-debug.h" 52 #include "d8-debug.h"
52 #include "debug.h" 53 #include "debug.h"
53 #include "natives.h" 54 #include "natives.h"
54 #include "platform.h" 55 #include "platform.h"
55 #include "v8.h" 56 #include "v8.h"
56 #endif // USING_V8_SHARED 57 #endif // V8_SHARED
57 58
58 #if !defined(_WIN32) && !defined(_WIN64) 59 #if !defined(_WIN32) && !defined(_WIN64)
59 #include <unistd.h> // NOLINT 60 #include <unistd.h> // NOLINT
60 #endif 61 #endif
61 62
62 #ifdef USING_V8_SHARED 63 #ifndef ASSERT
63 #define ASSERT(condition) assert(condition) 64 #define ASSERT(condition) assert(condition)
64 #endif // USING_V8_SHARED 65 #endif
65 66
66 namespace v8 { 67 namespace v8 {
67 68
68 69
69 #ifndef USING_V8_SHARED 70 #ifndef V8_SHARED
70 LineEditor *LineEditor::first_ = NULL; 71 LineEditor *LineEditor::first_ = NULL;
71 const char* Shell::kHistoryFileName = ".d8_history"; 72 const char* Shell::kHistoryFileName = ".d8_history";
72 73
73 74
74 LineEditor::LineEditor(Type type, const char* name) 75 LineEditor::LineEditor(Type type, const char* name)
75 : type_(type), 76 : type_(type),
76 name_(name), 77 name_(name),
77 next_(first_) { 78 next_(first_) {
78 first_ = this; 79 first_ = this;
79 } 80 }
(...skipping 29 matching lines...) Expand all
109 return i::SmartPointer<char>(str ? i::StrDup(str) : str); 110 return i::SmartPointer<char>(str ? i::StrDup(str) : str);
110 } 111 }
111 112
112 113
113 CounterMap* Shell::counter_map_; 114 CounterMap* Shell::counter_map_;
114 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 115 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
115 CounterCollection Shell::local_counters_; 116 CounterCollection Shell::local_counters_;
116 CounterCollection* Shell::counters_ = &local_counters_; 117 CounterCollection* Shell::counters_ = &local_counters_;
117 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); 118 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
118 Persistent<Context> Shell::utility_context_; 119 Persistent<Context> Shell::utility_context_;
119 #endif // USING_V8_SHARED 120 #endif // V8_SHARED
120 121
121 Persistent<Context> Shell::evaluation_context_; 122 Persistent<Context> Shell::evaluation_context_;
122 ShellOptions Shell::options; 123 ShellOptions Shell::options;
123 const char* Shell::kPrompt = "d8> "; 124 const char* Shell::kPrompt = "d8> ";
124 125
125 126
126 #ifndef USING_V8_SHARED 127 #ifndef V8_SHARED
127 bool CounterMap::Match(void* key1, void* key2) { 128 bool CounterMap::Match(void* key1, void* key2) {
128 const char* name1 = reinterpret_cast<const char*>(key1); 129 const char* name1 = reinterpret_cast<const char*>(key1);
129 const char* name2 = reinterpret_cast<const char*>(key2); 130 const char* name2 = reinterpret_cast<const char*>(key2);
130 return strcmp(name1, name2) == 0; 131 return strcmp(name1, name2) == 0;
131 } 132 }
132 #endif // USING_V8_SHARED 133 #endif // V8_SHARED
133 134
134 135
135 // Converts a V8 value to a C string. 136 // Converts a V8 value to a C string.
136 const char* Shell::ToCString(const v8::String::Utf8Value& value) { 137 const char* Shell::ToCString(const v8::String::Utf8Value& value) {
137 return *value ? *value : "<string conversion failed>"; 138 return *value ? *value : "<string conversion failed>";
138 } 139 }
139 140
140 141
141 // Executes a string within the current v8 context. 142 // Executes a string within the current v8 context.
142 bool Shell::ExecuteString(Handle<String> source, 143 bool Shell::ExecuteString(Handle<String> source,
143 Handle<Value> name, 144 Handle<Value> name,
144 bool print_result, 145 bool print_result,
145 bool report_exceptions) { 146 bool report_exceptions) {
146 #ifndef USING_V8_SHARED 147 #ifndef V8_SHARED
147 bool FLAG_debugger = i::FLAG_debugger; 148 bool FLAG_debugger = i::FLAG_debugger;
148 #else 149 #else
149 bool FLAG_debugger = false; 150 bool FLAG_debugger = false;
150 #endif // USING_V8_SHARED 151 #endif // V8_SHARED
151 HandleScope handle_scope; 152 HandleScope handle_scope;
152 TryCatch try_catch; 153 TryCatch try_catch;
153 options.script_executed = true; 154 options.script_executed = true;
154 if (FLAG_debugger) { 155 if (FLAG_debugger) {
155 // When debugging make exceptions appear to be uncaught. 156 // When debugging make exceptions appear to be uncaught.
156 try_catch.SetVerbose(true); 157 try_catch.SetVerbose(true);
157 } 158 }
158 Handle<Script> script = Script::Compile(source, name); 159 Handle<Script> script = Script::Compile(source, name);
159 if (script.IsEmpty()) { 160 if (script.IsEmpty()) {
160 // Print errors that happened during compilation. 161 // Print errors that happened during compilation.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Handle<Value> Shell::CreateExternalArray(const Arguments& args, 270 Handle<Value> Shell::CreateExternalArray(const Arguments& args,
270 ExternalArrayType type, 271 ExternalArrayType type,
271 size_t element_size) { 272 size_t element_size) {
272 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 || 273 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 ||
273 element_size == 8); 274 element_size == 8);
274 if (args.Length() != 1) { 275 if (args.Length() != 1) {
275 return ThrowException( 276 return ThrowException(
276 String::New("Array constructor needs one parameter.")); 277 String::New("Array constructor needs one parameter."));
277 } 278 }
278 static const int kMaxLength = 0x3fffffff; 279 static const int kMaxLength = 0x3fffffff;
279 #ifndef USING_V8_SHARED 280 #ifndef V8_SHARED
280 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); 281 ASSERT(kMaxLength == i::ExternalArray::kMaxLength);
281 #endif // USING_V8_SHARED 282 #endif // V8_SHARED
282 size_t length = 0; 283 size_t length = 0;
283 if (args[0]->IsUint32()) { 284 if (args[0]->IsUint32()) {
284 length = args[0]->Uint32Value(); 285 length = args[0]->Uint32Value();
285 } else if (args[0]->IsNumber()) { 286 } else if (args[0]->IsNumber()) {
286 double raw_length = args[0]->NumberValue(); 287 double raw_length = args[0]->NumberValue();
287 if (raw_length < 0) { 288 if (raw_length < 0) {
288 return ThrowException(String::New("Array length must not be negative.")); 289 return ThrowException(String::New("Array length must not be negative."));
289 } 290 }
290 if (raw_length > kMaxLength) { 291 if (raw_length > kMaxLength) {
291 return ThrowException( 292 return ThrowException(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 372
372 373
373 Handle<Value> Shell::Yield(const Arguments& args) { 374 Handle<Value> Shell::Yield(const Arguments& args) {
374 v8::Unlocker unlocker; 375 v8::Unlocker unlocker;
375 return Undefined(); 376 return Undefined();
376 } 377 }
377 378
378 379
379 Handle<Value> Shell::Quit(const Arguments& args) { 380 Handle<Value> Shell::Quit(const Arguments& args) {
380 int exit_code = args[0]->Int32Value(); 381 int exit_code = args[0]->Int32Value();
381 #ifndef USING_V8_SHARED 382 #ifndef V8_SHARED
382 OnExit(); 383 OnExit();
383 #endif // USING_V8_SHARED 384 #endif // V8_SHARED
384 exit(exit_code); 385 exit(exit_code);
385 return Undefined(); 386 return Undefined();
386 } 387 }
387 388
388 389
389 Handle<Value> Shell::Version(const Arguments& args) { 390 Handle<Value> Shell::Version(const Arguments& args) {
390 return String::New(V8::GetVersion()); 391 return String::New(V8::GetVersion());
391 } 392 }
392 393
393 394
(...skipping 28 matching lines...) Expand all
422 printf("\n"); 423 printf("\n");
423 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); 424 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
424 if (stack_trace.length() > 0) { 425 if (stack_trace.length() > 0) {
425 const char* stack_trace_string = ToCString(stack_trace); 426 const char* stack_trace_string = ToCString(stack_trace);
426 printf("%s\n", stack_trace_string); 427 printf("%s\n", stack_trace_string);
427 } 428 }
428 } 429 }
429 } 430 }
430 431
431 432
432 #ifndef USING_V8_SHARED 433 #ifndef V8_SHARED
433 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) { 434 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
434 HandleScope handle_scope; 435 HandleScope handle_scope;
435 Context::Scope context_scope(utility_context_); 436 Context::Scope context_scope(utility_context_);
436 Handle<Object> global = utility_context_->Global(); 437 Handle<Object> global = utility_context_->Global();
437 Handle<Value> fun = global->Get(String::New("GetCompletions")); 438 Handle<Value> fun = global->Get(String::New("GetCompletions"));
438 static const int kArgc = 3; 439 static const int kArgc = 3;
439 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; 440 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full };
440 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 441 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
441 return handle_scope.Close(Handle<Array>::Cast(val)); 442 return handle_scope.Close(Handle<Array>::Cast(val));
442 } 443 }
(...skipping 14 matching lines...) Expand all
457 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { 458 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
458 Context::Scope context_scope(utility_context_); 459 Context::Scope context_scope(utility_context_);
459 Handle<Object> global = utility_context_->Global(); 460 Handle<Object> global = utility_context_->Global();
460 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); 461 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
461 static const int kArgc = 1; 462 static const int kArgc = 1;
462 Handle<Value> argv[kArgc] = { command }; 463 Handle<Value> argv[kArgc] = { command };
463 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 464 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
464 return val; 465 return val;
465 } 466 }
466 #endif // ENABLE_DEBUGGER_SUPPORT 467 #endif // ENABLE_DEBUGGER_SUPPORT
467 #endif // USING_V8_SHARED 468 #endif // V8_SHARED
468 469
469 470
470 #ifndef USING_V8_SHARED 471 #ifndef V8_SHARED
471 int32_t* Counter::Bind(const char* name, bool is_histogram) { 472 int32_t* Counter::Bind(const char* name, bool is_histogram) {
472 int i; 473 int i;
473 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 474 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
474 name_[i] = static_cast<char>(name[i]); 475 name_[i] = static_cast<char>(name[i]);
475 name_[i] = '\0'; 476 name_[i] = '\0';
476 is_histogram_ = is_histogram; 477 is_histogram_ = is_histogram;
477 return ptr(); 478 return ptr();
478 } 479 }
479 480
480 481
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 i::SharedFunctionInfo::cast(*compiled_script)->script())); 609 i::SharedFunctionInfo::cast(*compiled_script)->script()));
609 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); 610 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
610 611
611 #ifdef ENABLE_DEBUGGER_SUPPORT 612 #ifdef ENABLE_DEBUGGER_SUPPORT
612 // Start the in-process debugger if requested. 613 // Start the in-process debugger if requested.
613 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { 614 if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
614 v8::Debug::SetDebugEventListener(HandleDebugEvent); 615 v8::Debug::SetDebugEventListener(HandleDebugEvent);
615 } 616 }
616 #endif // ENABLE_DEBUGGER_SUPPORT 617 #endif // ENABLE_DEBUGGER_SUPPORT
617 } 618 }
618 #endif // USING_V8_SHARED 619 #endif // V8_SHARED
619 620
620 621
621 #ifdef COMPRESS_STARTUP_DATA_BZ2 622 #ifdef COMPRESS_STARTUP_DATA_BZ2
622 class BZip2Decompressor : public v8::StartupDataDecompressor { 623 class BZip2Decompressor : public v8::StartupDataDecompressor {
623 public: 624 public:
624 virtual ~BZip2Decompressor() { } 625 virtual ~BZip2Decompressor() { }
625 626
626 protected: 627 protected:
627 virtual int DecompressData(char* raw_data, 628 virtual int DecompressData(char* raw_data,
628 int* raw_data_size, 629 int* raw_data_size,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 FunctionTemplate::New(Float64Array)); 676 FunctionTemplate::New(Float64Array));
676 global_template->Set(String::New("PixelArray"), 677 global_template->Set(String::New("PixelArray"),
677 FunctionTemplate::New(PixelArray)); 678 FunctionTemplate::New(PixelArray));
678 679
679 #ifdef LIVE_OBJECT_LIST 680 #ifdef LIVE_OBJECT_LIST
680 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); 681 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
681 #else 682 #else
682 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); 683 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
683 #endif 684 #endif
684 685
685 #ifndef USING_V8_SHARED 686 #ifndef V8_SHARED
686 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 687 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
687 AddOSMethods(os_templ); 688 AddOSMethods(os_templ);
688 global_template->Set(String::New("os"), os_templ); 689 global_template->Set(String::New("os"), os_templ);
689 #endif // USING_V8_SHARED 690 #endif // V8_SHARED
690 691
691 return global_template; 692 return global_template;
692 } 693 }
693 694
694 695
695 void Shell::Initialize() { 696 void Shell::Initialize() {
696 #ifdef COMPRESS_STARTUP_DATA_BZ2 697 #ifdef COMPRESS_STARTUP_DATA_BZ2
697 BZip2Decompressor startup_data_decompressor; 698 BZip2Decompressor startup_data_decompressor;
698 int bz2_result = startup_data_decompressor.Decompress(); 699 int bz2_result = startup_data_decompressor.Decompress();
699 if (bz2_result != BZ_OK) { 700 if (bz2_result != BZ_OK) {
700 fprintf(stderr, "bzip error code: %d\n", bz2_result); 701 fprintf(stderr, "bzip error code: %d\n", bz2_result);
701 exit(1); 702 exit(1);
702 } 703 }
703 #endif 704 #endif
704 705
705 #ifndef USING_V8_SHARED 706 #ifndef V8_SHARED
706 Shell::counter_map_ = new CounterMap(); 707 Shell::counter_map_ = new CounterMap();
707 // Set up counters 708 // Set up counters
708 if (i::StrLength(i::FLAG_map_counters) != 0) 709 if (i::StrLength(i::FLAG_map_counters) != 0)
709 MapCounters(i::FLAG_map_counters); 710 MapCounters(i::FLAG_map_counters);
710 if (i::FLAG_dump_counters) { 711 if (i::FLAG_dump_counters) {
711 V8::SetCounterFunction(LookupCounter); 712 V8::SetCounterFunction(LookupCounter);
712 V8::SetCreateHistogramFunction(CreateHistogram); 713 V8::SetCreateHistogramFunction(CreateHistogram);
713 V8::SetAddHistogramSampleFunction(AddHistogramSample); 714 V8::SetAddHistogramSampleFunction(AddHistogramSample);
714 } 715 }
715 #endif // USING_V8_SHARED 716 #endif // V8_SHARED
716 if (options.test_shell) return; 717 if (options.test_shell) return;
717 718
718 #ifndef USING_V8_SHARED 719 #ifndef V8_SHARED
719 Locker lock; 720 Locker lock;
720 HandleScope scope; 721 HandleScope scope;
721 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 722 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
722 utility_context_ = Context::New(NULL, global_template); 723 utility_context_ = Context::New(NULL, global_template);
723 724
724 #ifdef ENABLE_DEBUGGER_SUPPORT 725 #ifdef ENABLE_DEBUGGER_SUPPORT
725 // Start the debugger agent if requested. 726 // Start the debugger agent if requested.
726 if (i::FLAG_debugger_agent) { 727 if (i::FLAG_debugger_agent) {
727 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); 728 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
728 } 729 }
729 #endif // ENABLE_DEBUGGER_SUPPORT 730 #endif // ENABLE_DEBUGGER_SUPPORT
730 #endif // USING_V8_SHARED 731 #endif // V8_SHARED
731 } 732 }
732 733
733 734
734 Persistent<Context> Shell::CreateEvaluationContext() { 735 Persistent<Context> Shell::CreateEvaluationContext() {
735 #ifndef USING_V8_SHARED 736 #ifndef V8_SHARED
736 // This needs to be a critical section since this is not thread-safe 737 // This needs to be a critical section since this is not thread-safe
737 i::ScopedLock lock(context_mutex_); 738 i::ScopedLock lock(context_mutex_);
738 #endif // USING_V8_SHARED 739 #endif // V8_SHARED
739 // Initialize the global objects 740 // Initialize the global objects
740 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 741 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
741 Persistent<Context> context = Context::New(NULL, global_template); 742 Persistent<Context> context = Context::New(NULL, global_template);
742 Context::Scope scope(context); 743 Context::Scope scope(context);
743 744
744 #ifndef USING_V8_SHARED 745 #ifndef V8_SHARED
745 i::JSArguments js_args = i::FLAG_js_arguments; 746 i::JSArguments js_args = i::FLAG_js_arguments;
746 i::Handle<i::FixedArray> arguments_array = 747 i::Handle<i::FixedArray> arguments_array =
747 FACTORY->NewFixedArray(js_args.argc()); 748 FACTORY->NewFixedArray(js_args.argc());
748 for (int j = 0; j < js_args.argc(); j++) { 749 for (int j = 0; j < js_args.argc(); j++) {
749 i::Handle<i::String> arg = 750 i::Handle<i::String> arg =
750 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); 751 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
751 arguments_array->set(j, *arg); 752 arguments_array->set(j, *arg);
752 } 753 }
753 i::Handle<i::JSArray> arguments_jsarray = 754 i::Handle<i::JSArray> arguments_jsarray =
754 FACTORY->NewJSArrayWithElements(arguments_array); 755 FACTORY->NewJSArrayWithElements(arguments_array);
755 context->Global()->Set(String::New("arguments"), 756 context->Global()->Set(String::New("arguments"),
756 Utils::ToLocal(arguments_jsarray)); 757 Utils::ToLocal(arguments_jsarray));
757 #endif // USING_V8_SHARED 758 #endif // V8_SHARED
758 return context; 759 return context;
759 } 760 }
760 761
761 762
762 #ifndef USING_V8_SHARED 763 #ifndef V8_SHARED
763 void Shell::OnExit() { 764 void Shell::OnExit() {
764 if (i::FLAG_dump_counters) { 765 if (i::FLAG_dump_counters) {
765 printf("+----------------------------------------+-------------+\n"); 766 printf("+----------------------------------------+-------------+\n");
766 printf("| Name | Value |\n"); 767 printf("| Name | Value |\n");
767 printf("+----------------------------------------+-------------+\n"); 768 printf("+----------------------------------------+-------------+\n");
768 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 769 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
769 Counter* counter = i.CurrentValue(); 770 Counter* counter = i.CurrentValue();
770 if (counter->is_histogram()) { 771 if (counter->is_histogram()) {
771 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); 772 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
772 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); 773 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total());
773 } else { 774 } else {
774 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); 775 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
775 } 776 }
776 } 777 }
777 printf("+----------------------------------------+-------------+\n"); 778 printf("+----------------------------------------+-------------+\n");
778 } 779 }
779 if (counters_file_ != NULL) 780 if (counters_file_ != NULL)
780 delete counters_file_; 781 delete counters_file_;
781 } 782 }
782 #endif // USING_V8_SHARED 783 #endif // V8_SHARED
784
785
786 static FILE* FOpen(const char* path, const char* mode) {
787 #if (defined(_WIN32) || defined(_WIN64))
788 FILE* result;
789 if (fopen_s(&result, path, mode) == 0) {
790 return result;
791 } else {
792 return NULL;
793 }
794 #else
795 FILE* file = fopen(path, mode);
796 if (file == NULL) return NULL;
797 struct stat file_stat;
798 if (fstat(fileno(file), &file_stat) != 0) return NULL;
799 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
800 if (is_regular_file) return file;
801 fclose(file);
802 return NULL;
803 #endif
804 }
783 805
784 806
785 static char* ReadChars(const char* name, int* size_out) { 807 static char* ReadChars(const char* name, int* size_out) {
786 // Release the V8 lock while reading files. 808 // Release the V8 lock while reading files.
787 v8::Unlocker unlocker(Isolate::GetCurrent()); 809 v8::Unlocker unlocker(Isolate::GetCurrent());
788 #ifndef USING_V8_SHARED 810 FILE* file = 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
794 if (file == NULL) return NULL; 811 if (file == NULL) return NULL;
795 812
796 fseek(file, 0, SEEK_END); 813 fseek(file, 0, SEEK_END);
797 int size = ftell(file); 814 int size = ftell(file);
798 rewind(file); 815 rewind(file);
799 816
800 char* chars = new char[size + 1]; 817 char* chars = new char[size + 1];
801 chars[size] = '\0'; 818 chars[size] = '\0';
802 for (int i = 0; i < size;) { 819 for (int i = 0; i < size;) {
803 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); 820 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
804 i += read; 821 i += read;
805 } 822 }
806 fclose(file); 823 fclose(file);
807 *size_out = size; 824 *size_out = size;
808 return chars; 825 return chars;
809 } 826 }
810 827
811 828
812 #ifndef USING_V8_SHARED 829 #ifndef V8_SHARED
813 static char* ReadToken(char* data, char token) { 830 static char* ReadToken(char* data, char token) {
814 char* next = i::OS::StrChr(data, token); 831 char* next = i::OS::StrChr(data, token);
815 if (next != NULL) { 832 if (next != NULL) {
816 *next = '\0'; 833 *next = '\0';
817 return (next + 1); 834 return (next + 1);
818 } 835 }
819 836
820 return NULL; 837 return NULL;
821 } 838 }
822 839
823 840
824 static char* ReadLine(char* data) { 841 static char* ReadLine(char* data) {
825 return ReadToken(data, '\n'); 842 return ReadToken(data, '\n');
826 } 843 }
827 844
828 845
829 static char* ReadWord(char* data) { 846 static char* ReadWord(char* data) {
830 return ReadToken(data, ' '); 847 return ReadToken(data, ' ');
831 } 848 }
832 #endif // USING_V8_SHARED 849 #endif // V8_SHARED
833 850
834 851
835 // Reads a file into a v8 string. 852 // Reads a file into a v8 string.
836 Handle<String> Shell::ReadFile(const char* name) { 853 Handle<String> Shell::ReadFile(const char* name) {
837 int size = 0; 854 int size = 0;
838 char* chars = ReadChars(name, &size); 855 char* chars = ReadChars(name, &size);
839 if (chars == NULL) return Handle<String>(); 856 if (chars == NULL) return Handle<String>();
840 Handle<String> result = String::New(chars); 857 Handle<String> result = String::New(chars);
841 delete[] chars; 858 delete[] chars;
842 return result; 859 return result;
843 } 860 }
844 861
845 862
846 void Shell::RunShell() { 863 void Shell::RunShell() {
847 Locker locker; 864 Locker locker;
848 Context::Scope context_scope(evaluation_context_); 865 Context::Scope context_scope(evaluation_context_);
849 HandleScope handle_scope; 866 HandleScope handle_scope;
850 Handle<String> name = String::New("(d8)"); 867 Handle<String> name = String::New("(d8)");
851 #ifndef USING_V8_SHARED 868 #ifndef V8_SHARED
852 LineEditor* editor = LineEditor::Get(); 869 LineEditor* editor = LineEditor::Get();
853 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); 870 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name());
854 if (i::FLAG_debugger) { 871 if (i::FLAG_debugger) {
855 printf("JavaScript debugger enabled\n"); 872 printf("JavaScript debugger enabled\n");
856 } 873 }
857 editor->Open(); 874 editor->Open();
858 while (true) { 875 while (true) {
859 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); 876 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt);
860 if (input.is_empty()) break; 877 if (input.is_empty()) break;
861 editor->AddHistory(*input); 878 editor->AddHistory(*input);
862 ExecuteString(String::New(*input), name, true, true); 879 ExecuteString(String::New(*input), name, true, true);
863 } 880 }
864 editor->Close(); 881 editor->Close();
865 #else 882 #else
866 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); 883 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion());
867 static const int kBufferSize = 256; 884 static const int kBufferSize = 256;
868 while (true) { 885 while (true) {
869 char buffer[kBufferSize]; 886 char buffer[kBufferSize];
870 printf("%s", Shell::kPrompt); 887 printf("%s", Shell::kPrompt);
871 if (fgets(buffer, kBufferSize, stdin) == NULL) break; 888 if (fgets(buffer, kBufferSize, stdin) == NULL) break;
872 ExecuteString(String::New(buffer), name, true, true); 889 ExecuteString(String::New(buffer), name, true, true);
873 } 890 }
874 #endif // USING_V8_SHARED 891 #endif // V8_SHARED
875 printf("\n"); 892 printf("\n");
876 } 893 }
877 894
878 895
879 #ifndef USING_V8_SHARED 896 #ifndef V8_SHARED
880 class ShellThread : public i::Thread { 897 class ShellThread : public i::Thread {
881 public: 898 public:
882 ShellThread(int no, i::Vector<const char> files) 899 ShellThread(int no, i::Vector<const char> files)
883 : Thread("d8:ShellThread"), 900 : Thread("d8:ShellThread"),
884 no_(no), files_(files) { } 901 no_(no), files_(files) { }
885 virtual void Run(); 902 virtual void Run();
886 private: 903 private:
887 int no_; 904 int no_;
888 i::Vector<const char> files_; 905 i::Vector<const char> files_;
889 }; 906 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 break; 939 break;
923 } 940 }
924 941
925 Shell::ExecuteString(str, String::New(filename), false, false); 942 Shell::ExecuteString(str, String::New(filename), false, false);
926 } 943 }
927 944
928 thread_context.Dispose(); 945 thread_context.Dispose();
929 ptr = next_line; 946 ptr = next_line;
930 } 947 }
931 } 948 }
932 #endif // USING_V8_SHARED 949 #endif // V8_SHARED
933 950
934 951
935 void SourceGroup::ExitShell(int exit_code) { 952 void SourceGroup::ExitShell(int exit_code) {
936 // Use _exit instead of exit to avoid races between isolate 953 // Use _exit instead of exit to avoid races between isolate
937 // threads and static destructors. 954 // threads and static destructors.
938 fflush(stdout); 955 fflush(stdout);
939 fflush(stderr); 956 fflush(stderr);
940 _exit(exit_code); 957 _exit(exit_code);
941 } 958 }
942 959
(...skipping 26 matching lines...) Expand all
969 if (!Shell::ExecuteString(source, file_name, false, true)) { 986 if (!Shell::ExecuteString(source, file_name, false, true)) {
970 ExitShell(1); 987 ExitShell(1);
971 return; 988 return;
972 } 989 }
973 } 990 }
974 } 991 }
975 } 992 }
976 993
977 994
978 Handle<String> SourceGroup::ReadFile(const char* name) { 995 Handle<String> SourceGroup::ReadFile(const char* name) {
979 #ifndef USING_V8_SHARED 996 int size;
980 FILE* file = i::OS::FOpen(name, "rb"); 997 const char* chars = ReadChars(name, &size);
981 #else 998 if (chars == NULL) return Handle<String>();
982 // TODO(yangguo@chromium.org): reading from a directory hangs!
983 FILE* file = fopen(name, "rb");
984 #endif // USING_V8_SHARED
985 if (file == NULL) return Handle<String>();
986
987 fseek(file, 0, SEEK_END);
988 int size = ftell(file);
989 rewind(file);
990
991 char* chars = new char[size + 1];
992 chars[size] = '\0';
993 for (int i = 0; i < size;) {
994 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
995 i += read;
996 }
997 fclose(file);
998 Handle<String> result = String::New(chars, size); 999 Handle<String> result = String::New(chars, size);
999 delete[] chars; 1000 delete[] chars;
1000 return result; 1001 return result;
1001 } 1002 }
1002 1003
1003 1004
1004 #ifndef USING_V8_SHARED 1005 #ifndef V8_SHARED
1005 i::Thread::Options SourceGroup::GetThreadOptions() { 1006 i::Thread::Options SourceGroup::GetThreadOptions() {
1006 i::Thread::Options options; 1007 i::Thread::Options options;
1007 options.name = "IsolateThread"; 1008 options.name = "IsolateThread";
1008 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less 1009 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less
1009 // which is not enough to parse the big literal expressions used in tests. 1010 // which is not enough to parse the big literal expressions used in tests.
1010 // The stack size should be at least StackGuard::kLimitSize + some 1011 // The stack size should be at least StackGuard::kLimitSize + some
1011 // OS-specific padding for thread startup code. 1012 // OS-specific padding for thread startup code.
1012 options.stack_size = 2 << 20; // 2 Mb seems to be enough 1013 options.stack_size = 2 << 20; // 2 Mb seems to be enough
1013 return options; 1014 return options;
1014 } 1015 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1047
1047 void SourceGroup::WaitForThread() { 1048 void SourceGroup::WaitForThread() {
1048 if (thread_ == NULL) return; 1049 if (thread_ == NULL) return;
1049 if (Shell::options.last_run) { 1050 if (Shell::options.last_run) {
1050 thread_->Join(); 1051 thread_->Join();
1051 thread_ = NULL; 1052 thread_ = NULL;
1052 } else { 1053 } else {
1053 done_semaphore_->Wait(); 1054 done_semaphore_->Wait();
1054 } 1055 }
1055 } 1056 }
1056 #endif // USING_V8_SHARED 1057 #endif // V8_SHARED
1057 1058
1058 1059
1059 bool Shell::SetOptions(int argc, char* argv[]) { 1060 bool Shell::SetOptions(int argc, char* argv[]) {
1060 for (int i = 0; i < argc; i++) { 1061 for (int i = 0; i < argc; i++) {
1061 if (strcmp(argv[i], "--stress-opt") == 0) { 1062 if (strcmp(argv[i], "--stress-opt") == 0) {
1062 options.stress_opt = true; 1063 options.stress_opt = true;
1063 argv[i] = NULL; 1064 argv[i] = NULL;
1064 } else if (strcmp(argv[i], "--stress-deopt") == 0) { 1065 } else if (strcmp(argv[i], "--stress-deopt") == 0) {
1065 options.stress_deopt = true; 1066 options.stress_deopt = true;
1066 argv[i] = NULL; 1067 argv[i] = NULL;
1067 } else if (strcmp(argv[i], "--noalways-opt") == 0) { 1068 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
1068 // No support for stressing if we can't use --always-opt. 1069 // No support for stressing if we can't use --always-opt.
1069 options.stress_opt = false; 1070 options.stress_opt = false;
1070 options.stress_deopt = false; 1071 options.stress_deopt = false;
1071 } else if (strcmp(argv[i], "--shell") == 0) { 1072 } else if (strcmp(argv[i], "--shell") == 0) {
1072 options.interactive_shell = true; 1073 options.interactive_shell = true;
1073 argv[i] = NULL; 1074 argv[i] = NULL;
1074 } else if (strcmp(argv[i], "--test") == 0) { 1075 } else if (strcmp(argv[i], "--test") == 0) {
1075 options.test_shell = true; 1076 options.test_shell = true;
1076 argv[i] = NULL; 1077 argv[i] = NULL;
1077 } else if (strcmp(argv[i], "--preemption") == 0) { 1078 } else if (strcmp(argv[i], "--preemption") == 0) {
1078 #ifdef USING_V8_SHARED 1079 #ifdef V8_SHARED
1079 printf("D8 with shared library does not support multi-threading\n"); 1080 printf("D8 with shared library does not support multi-threading\n");
1080 return false; 1081 return false;
1081 #else 1082 #else
1082 options.use_preemption = true; 1083 options.use_preemption = true;
1083 argv[i] = NULL; 1084 argv[i] = NULL;
1084 #endif // USING_V8_SHARED 1085 #endif // V8_SHARED
1085 } else if (strcmp(argv[i], "--no-preemption") == 0) { 1086 } else if (strcmp(argv[i], "--no-preemption") == 0) {
1086 #ifdef USING_V8_SHARED 1087 #ifdef V8_SHARED
1087 printf("D8 with shared library does not support multi-threading\n"); 1088 printf("D8 with shared library does not support multi-threading\n");
1088 return false; 1089 return false;
1089 #else 1090 #else
1090 options.use_preemption = false; 1091 options.use_preemption = false;
1091 argv[i] = NULL; 1092 argv[i] = NULL;
1092 #endif // USING_V8_SHARED 1093 #endif // V8_SHARED
1093 } else if (strcmp(argv[i], "--preemption-interval") == 0) { 1094 } else if (strcmp(argv[i], "--preemption-interval") == 0) {
1094 #ifdef USING_V8_SHARED 1095 #ifdef V8_SHARED
1095 printf("D8 with shared library does not support multi-threading\n"); 1096 printf("D8 with shared library does not support multi-threading\n");
1096 return false; 1097 return false;
1097 #else 1098 #else
1098 if (++i < argc) { 1099 if (++i < argc) {
1099 argv[i-1] = NULL; 1100 argv[i-1] = NULL;
1100 char* end = NULL; 1101 char* end = NULL;
1101 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT 1102 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT
1102 if (options.preemption_interval <= 0 1103 if (options.preemption_interval <= 0
1103 || *end != '\0' 1104 || *end != '\0'
1104 || errno == ERANGE) { 1105 || errno == ERANGE) {
1105 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); 1106 printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
1106 return false; 1107 return false;
1107 } 1108 }
1108 argv[i] = NULL; 1109 argv[i] = NULL;
1109 } else { 1110 } else {
1110 printf("Missing value for --preemption-interval\n"); 1111 printf("Missing value for --preemption-interval\n");
1111 return false; 1112 return false;
1112 } 1113 }
1113 #endif // USING_V8_SHARED 1114 #endif // V8_SHARED
1114 } else if (strcmp(argv[i], "-f") == 0) { 1115 } else if (strcmp(argv[i], "-f") == 0) {
1115 // Ignore any -f flags for compatibility with other stand-alone 1116 // Ignore any -f flags for compatibility with other stand-alone
1116 // JavaScript engines. 1117 // JavaScript engines.
1117 continue; 1118 continue;
1118 } else if (strcmp(argv[i], "--isolate") == 0) { 1119 } else if (strcmp(argv[i], "--isolate") == 0) {
1119 #ifdef USING_V8_SHARED 1120 #ifdef V8_SHARED
1120 printf("D8 with shared library does not support multi-threading\n"); 1121 printf("D8 with shared library does not support multi-threading\n");
1121 return false; 1122 return false;
1122 #endif // USING_V8_SHARED 1123 #endif // V8_SHARED
1123 options.num_isolates++; 1124 options.num_isolates++;
1124 } 1125 }
1125 #ifdef USING_V8_SHARED 1126 #ifdef V8_SHARED
1126 else if (strcmp(argv[i], "--dump-counters") == 0) { 1127 else if (strcmp(argv[i], "--dump-counters") == 0) {
1127 printf("D8 with shared library does not include counters\n"); 1128 printf("D8 with shared library does not include counters\n");
1128 return false; 1129 return false;
1129 } else if (strcmp(argv[i], "-p") == 0) { 1130 } else if (strcmp(argv[i], "-p") == 0) {
1130 printf("D8 with shared library does not support multi-threading\n"); 1131 printf("D8 with shared library does not support multi-threading\n");
1131 return false; 1132 return false;
1132 } else if (strcmp(argv[i], "--debugger") == 0) { 1133 } else if (strcmp(argv[i], "--debugger") == 0) {
1133 printf("Javascript debugger not included\n"); 1134 printf("Javascript debugger not included\n");
1134 return false; 1135 return false;
1135 } 1136 }
1136 #endif // USING_V8_SHARED 1137 #endif // V8_SHARED
1137 } 1138 }
1138 1139
1139 #ifndef USING_V8_SHARED 1140 #ifndef V8_SHARED
1140 // Run parallel threads if we are not using --isolate 1141 // Run parallel threads if we are not using --isolate
1141 for (int i = 1; i < argc; i++) { 1142 for (int i = 1; i < argc; i++) {
1142 if (argv[i] == NULL) continue; 1143 if (argv[i] == NULL) continue;
1143 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { 1144 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
1144 if (options.num_isolates > 1) { 1145 if (options.num_isolates > 1) {
1145 printf("-p is not compatible with --isolate\n"); 1146 printf("-p is not compatible with --isolate\n");
1146 return false; 1147 return false;
1147 } 1148 }
1148 argv[i] = NULL; 1149 argv[i] = NULL;
1149 if (options.parallel_files == NULL) { 1150 if (options.parallel_files == NULL) {
1150 options.parallel_files = new i::List<i::Vector<const char> >(); 1151 options.parallel_files = new i::List<i::Vector<const char> >();
1151 } 1152 }
1152 int size = 0; 1153 int size = 0;
1153 const char* files = ReadChars(argv[++i], &size); 1154 const char* files = ReadChars(argv[++i], &size);
1154 if (files == NULL) { 1155 if (files == NULL) {
1155 printf("-p option incomplete\n"); 1156 printf("-p option incomplete\n");
1156 return false; 1157 return false;
1157 } 1158 }
1158 argv[i] = NULL; 1159 argv[i] = NULL;
1159 options.parallel_files->Add(i::Vector<const char>(files, size)); 1160 options.parallel_files->Add(i::Vector<const char>(files, size));
1161 delete[] files;
1160 } 1162 }
1161 } 1163 }
1162 #endif // USING_V8_SHARED 1164 #endif // V8_SHARED
1163 1165
1164 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 1166 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1165 1167
1166 // set up isolated source groups 1168 // set up isolated source groups
1167 options.isolate_sources = new SourceGroup[options.num_isolates]; 1169 options.isolate_sources = new SourceGroup[options.num_isolates];
1168 SourceGroup* current = options.isolate_sources; 1170 SourceGroup* current = options.isolate_sources;
1169 current->Begin(argv, 1); 1171 current->Begin(argv, 1);
1170 for (int i = 1; i < argc; i++) { 1172 for (int i = 1; i < argc; i++) {
1171 const char* str = argv[i]; 1173 const char* str = argv[i];
1172 if (strcmp(str, "--isolate") == 0) { 1174 if (strcmp(str, "--isolate") == 0) {
1173 current->End(i); 1175 current->End(i);
1174 current++; 1176 current++;
1175 current->Begin(argv, i + 1); 1177 current->Begin(argv, i + 1);
1176 } else if (strncmp(argv[i], "--", 2) == 0) { 1178 } else if (strncmp(argv[i], "--", 2) == 0) {
1177 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); 1179 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
1178 } 1180 }
1179 } 1181 }
1180 current->End(argc); 1182 current->End(argc);
1181 1183
1182 return true; 1184 return true;
1183 } 1185 }
1184 1186
1185 1187
1186 int Shell::RunMain(int argc, char* argv[]) { 1188 int Shell::RunMain(int argc, char* argv[]) {
1187 #ifndef USING_V8_SHARED 1189 #ifndef V8_SHARED
1188 i::List<i::Thread*> threads(1); 1190 i::List<i::Thread*> threads(1);
1189 if (options.parallel_files != NULL) 1191 if (options.parallel_files != NULL)
1190 for (int i = 0; i < options.parallel_files->length(); i++) { 1192 for (int i = 0; i < options.parallel_files->length(); i++) {
1191 i::Vector<const char> files = options.parallel_files->at(i); 1193 i::Vector<const char> files = options.parallel_files->at(i);
1192 ShellThread* thread = new ShellThread(threads.length(), files); 1194 ShellThread* thread = new ShellThread(threads.length(), files);
1193 thread->Start(); 1195 thread->Start();
1194 threads.Add(thread); 1196 threads.Add(thread);
1195 } 1197 }
1196 1198
1197 for (int i = 1; i < options.num_isolates; ++i) { 1199 for (int i = 1; i < options.num_isolates; ++i) {
1198 options.isolate_sources[i].StartExecuteInThread(); 1200 options.isolate_sources[i].StartExecuteInThread();
1199 } 1201 }
1200 #endif // USING_V8_SHARED 1202 #endif // V8_SHARED
1201 { // NOLINT 1203 { // NOLINT
1202 Locker lock; 1204 Locker lock;
1203 HandleScope scope; 1205 HandleScope scope;
1204 Persistent<Context> context = CreateEvaluationContext(); 1206 Persistent<Context> context = CreateEvaluationContext();
1205 { 1207 {
1206 Context::Scope cscope(context); 1208 Context::Scope cscope(context);
1207 options.isolate_sources[0].Execute(); 1209 options.isolate_sources[0].Execute();
1208 } 1210 }
1209 if (options.last_run) { 1211 if (options.last_run) {
1210 // Keep using the same context in the interactive shell 1212 // Keep using the same context in the interactive shell
1211 evaluation_context_ = context; 1213 evaluation_context_ = context;
1212 } else { 1214 } else {
1213 context.Dispose(); 1215 context.Dispose();
1214 } 1216 }
1215 1217
1216 #ifndef USING_V8_SHARED 1218 #ifndef V8_SHARED
1217 // Start preemption if threads have been created and preemption is enabled. 1219 // Start preemption if threads have been created and preemption is enabled.
1218 if (options.parallel_files != NULL 1220 if (options.parallel_files != NULL
1219 && threads.length() > 0 1221 && threads.length() > 0
1220 && options.use_preemption) { 1222 && options.use_preemption) {
1221 Locker::StartPreemption(options.preemption_interval); 1223 Locker::StartPreemption(options.preemption_interval);
1222 } 1224 }
1223 #endif // USING_V8_SHARED 1225 #endif // V8_SHARED
1224 } 1226 }
1225 1227
1226 #ifndef USING_V8_SHARED 1228 #ifndef V8_SHARED
1227 for (int i = 1; i < options.num_isolates; ++i) { 1229 for (int i = 1; i < options.num_isolates; ++i) {
1228 options.isolate_sources[i].WaitForThread(); 1230 options.isolate_sources[i].WaitForThread();
1229 } 1231 }
1230 1232
1231 if (options.parallel_files != NULL) 1233 if (options.parallel_files != NULL)
1232 for (int i = 0; i < threads.length(); i++) { 1234 for (int i = 0; i < threads.length(); i++) {
1233 i::Thread* thread = threads[i]; 1235 i::Thread* thread = threads[i];
1234 thread->Join(); 1236 thread->Join();
1235 delete thread; 1237 delete thread;
1236 } 1238 }
1237 1239
1238 OnExit(); 1240 OnExit();
1239 #endif // USING_V8_SHARED 1241 #endif // V8_SHARED
1240 return 0; 1242 return 0;
1241 } 1243 }
1242 1244
1243 1245
1244 int Shell::Main(int argc, char* argv[]) { 1246 int Shell::Main(int argc, char* argv[]) {
1245 if (!SetOptions(argc, argv)) return 1; 1247 if (!SetOptions(argc, argv)) return 1;
1246 Initialize(); 1248 Initialize();
1247 1249
1248 int result = 0; 1250 int result = 0;
1249 if (options.stress_opt || options.stress_deopt) { 1251 if (options.stress_opt || options.stress_deopt) {
1250 Testing::SetStressRunType( 1252 Testing::SetStressRunType(
1251 options.stress_opt ? Testing::kStressTypeOpt 1253 options.stress_opt ? Testing::kStressTypeOpt
1252 : Testing::kStressTypeDeopt); 1254 : Testing::kStressTypeDeopt);
1253 int stress_runs = Testing::GetStressRuns(); 1255 int stress_runs = Testing::GetStressRuns();
1254 for (int i = 0; i < stress_runs && result == 0; i++) { 1256 for (int i = 0; i < stress_runs && result == 0; i++) {
1255 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); 1257 printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
1256 Testing::PrepareStressRun(i); 1258 Testing::PrepareStressRun(i);
1257 options.last_run = (i == stress_runs - 1); 1259 options.last_run = (i == stress_runs - 1);
1258 result = RunMain(argc, argv); 1260 result = RunMain(argc, argv);
1259 } 1261 }
1260 printf("======== Full Deoptimization =======\n"); 1262 printf("======== Full Deoptimization =======\n");
1261 Testing::DeoptimizeAll(); 1263 Testing::DeoptimizeAll();
1262 } else { 1264 } else {
1263 result = RunMain(argc, argv); 1265 result = RunMain(argc, argv);
1264 } 1266 }
1265 1267
1266 1268
1267 #if !defined(USING_V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 1269 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
1268 // Run remote debugger if requested, but never on --test 1270 // Run remote debugger if requested, but never on --test
1269 if (i::FLAG_remote_debugger && !options.test_shell) { 1271 if (i::FLAG_remote_debugger && !options.test_shell) {
1270 InstallUtilityScript(); 1272 InstallUtilityScript();
1271 RunRemoteDebugger(i::FLAG_debugger_port); 1273 RunRemoteDebugger(i::FLAG_debugger_port);
1272 return 0; 1274 return 0;
1273 } 1275 }
1274 #endif // !USING_V8_SHARED && ENABLE_DEBUGGER_SUPPORT 1276 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
1275 1277
1276 // Run interactive shell if explicitly requested or if no script has been 1278 // Run interactive shell if explicitly requested or if no script has been
1277 // executed, but never on --test 1279 // executed, but never on --test
1278 1280
1279 if (( options.interactive_shell 1281 if (( options.interactive_shell
1280 || !options.script_executed ) 1282 || !options.script_executed )
1281 && !options.test_shell ) { 1283 && !options.test_shell ) {
1282 #ifndef USING_V8_SHARED 1284 #ifndef V8_SHARED
1283 InstallUtilityScript(); 1285 InstallUtilityScript();
1284 #endif // USING_V8_SHARED 1286 #endif // V8_SHARED
1285 RunShell(); 1287 RunShell();
1286 } 1288 }
1287 1289
1288 V8::Dispose(); 1290 V8::Dispose();
1289 1291
1290 return result; 1292 return result;
1291 } 1293 }
1292 1294
1293 } // namespace v8 1295 } // namespace v8
1294 1296
1295 1297
1296 #ifndef GOOGLE3 1298 #ifndef GOOGLE3
1297 int main(int argc, char* argv[]) { 1299 int main(int argc, char* argv[]) {
1298 return v8::Shell::Main(argc, argv); 1300 return v8::Shell::Main(argc, argv);
1299 } 1301 }
1300 #endif 1302 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/v8threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698