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

Side by Side Diff: src/d8.cc

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 V(buffer, "buffer") \ 86 V(buffer, "buffer") \
87 V(byteLength, "byteLength") \ 87 V(byteLength, "byteLength") \
88 V(byteOffset, "byteOffset") \ 88 V(byteOffset, "byteOffset") \
89 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ 89 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \
90 V(length, "length") 90 V(length, "length")
91 91
92 92
93 class Symbols { 93 class Symbols {
94 public: 94 public:
95 explicit Symbols(Isolate* isolate) : isolate_(isolate) { 95 explicit Symbols(Isolate* isolate) : isolate_(isolate) {
96 HandleScope scope; 96 HandleScope scope(isolate);
97 #define INIT_SYMBOL(name, value) \ 97 #define INIT_SYMBOL(name, value) \
98 name##_ = Persistent<String>::New(isolate, String::NewSymbol(value)); 98 name##_ = Persistent<String>::New(isolate, String::NewSymbol(value));
99 FOR_EACH_SYMBOL(INIT_SYMBOL) 99 FOR_EACH_SYMBOL(INIT_SYMBOL)
100 #undef INIT_SYMBOL 100 #undef INIT_SYMBOL
101 isolate->SetData(this); 101 isolate->SetData(this);
102 } 102 }
103 103
104 ~Symbols() { 104 ~Symbols() {
105 #define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_); 105 #define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_);
106 FOR_EACH_SYMBOL(DISPOSE_SYMBOL) 106 FOR_EACH_SYMBOL(DISPOSE_SYMBOL)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #endif // V8_SHARED 174 #endif // V8_SHARED
175 175
176 176
177 // Converts a V8 value to a C string. 177 // Converts a V8 value to a C string.
178 const char* Shell::ToCString(const v8::String::Utf8Value& value) { 178 const char* Shell::ToCString(const v8::String::Utf8Value& value) {
179 return *value ? *value : "<string conversion failed>"; 179 return *value ? *value : "<string conversion failed>";
180 } 180 }
181 181
182 182
183 // Executes a string within the current v8 context. 183 // Executes a string within the current v8 context.
184 bool Shell::ExecuteString(Handle<String> source, 184 bool Shell::ExecuteString(Isolate* isolate,
185 Handle<String> source,
185 Handle<Value> name, 186 Handle<Value> name,
186 bool print_result, 187 bool print_result,
187 bool report_exceptions) { 188 bool report_exceptions) {
188 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 189 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
189 bool FLAG_debugger = i::FLAG_debugger; 190 bool FLAG_debugger = i::FLAG_debugger;
190 #else 191 #else
191 bool FLAG_debugger = false; 192 bool FLAG_debugger = false;
192 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 193 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
193 HandleScope handle_scope; 194 HandleScope handle_scope(isolate);
194 TryCatch try_catch; 195 TryCatch try_catch;
195 options.script_executed = true; 196 options.script_executed = true;
196 if (FLAG_debugger) { 197 if (FLAG_debugger) {
197 // When debugging make exceptions appear to be uncaught. 198 // When debugging make exceptions appear to be uncaught.
198 try_catch.SetVerbose(true); 199 try_catch.SetVerbose(true);
199 } 200 }
200 Handle<Script> script = Script::Compile(source, name); 201 Handle<Script> script = Script::Compile(source, name);
201 if (script.IsEmpty()) { 202 if (script.IsEmpty()) {
202 // Print errors that happened during compilation. 203 // Print errors that happened during compilation.
203 if (report_exceptions && !FLAG_debugger) 204 if (report_exceptions && !FLAG_debugger)
204 ReportException(&try_catch); 205 ReportException(isolate, &try_catch);
205 return false; 206 return false;
206 } else { 207 } else {
207 Handle<Value> result = script->Run(); 208 Handle<Value> result = script->Run();
208 if (result.IsEmpty()) { 209 if (result.IsEmpty()) {
209 ASSERT(try_catch.HasCaught()); 210 ASSERT(try_catch.HasCaught());
210 // Print errors that happened during execution. 211 // Print errors that happened during execution.
211 if (report_exceptions && !FLAG_debugger) 212 if (report_exceptions && !FLAG_debugger)
212 ReportException(&try_catch); 213 ReportException(isolate, &try_catch);
213 return false; 214 return false;
214 } else { 215 } else {
215 ASSERT(!try_catch.HasCaught()); 216 ASSERT(!try_catch.HasCaught());
216 if (print_result && !result->IsUndefined()) { 217 if (print_result && !result->IsUndefined()) {
217 // If all went well and the result wasn't undefined then print 218 // If all went well and the result wasn't undefined then print
218 // the returned value. 219 // the returned value.
219 v8::String::Utf8Value str(result); 220 v8::String::Utf8Value str(result);
220 size_t count = fwrite(*str, sizeof(**str), str.length(), stdout); 221 size_t count = fwrite(*str, sizeof(**str), str.length(), stdout);
221 (void) count; // Silence GCC-4.5.x "unused result" warning. 222 (void) count; // Silence GCC-4.5.x "unused result" warning.
222 printf("\n"); 223 printf("\n");
223 } 224 }
224 return true; 225 return true;
225 } 226 }
226 } 227 }
227 } 228 }
228 229
229 230
230 Handle<Value> Shell::Print(const Arguments& args) { 231 Handle<Value> Shell::Print(const Arguments& args) {
231 Handle<Value> val = Write(args); 232 Handle<Value> val = Write(args);
232 printf("\n"); 233 printf("\n");
233 fflush(stdout); 234 fflush(stdout);
234 return val; 235 return val;
235 } 236 }
236 237
237 238
238 Handle<Value> Shell::Write(const Arguments& args) { 239 Handle<Value> Shell::Write(const Arguments& args) {
239 for (int i = 0; i < args.Length(); i++) { 240 for (int i = 0; i < args.Length(); i++) {
240 HandleScope handle_scope; 241 HandleScope handle_scope(args.GetIsolate());
241 if (i != 0) { 242 if (i != 0) {
242 printf(" "); 243 printf(" ");
243 } 244 }
244 245
245 // Explicitly catch potential exceptions in toString(). 246 // Explicitly catch potential exceptions in toString().
246 v8::TryCatch try_catch; 247 v8::TryCatch try_catch;
247 Handle<String> str_obj = args[i]->ToString(); 248 Handle<String> str_obj = args[i]->ToString();
248 if (try_catch.HasCaught()) return try_catch.ReThrow(); 249 if (try_catch.HasCaught()) return try_catch.ReThrow();
249 250
250 v8::String::Utf8Value str(str_obj); 251 v8::String::Utf8Value str(str_obj);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); 309 accumulator = String::Concat(accumulator, String::New(buffer, length-1));
309 } else { 310 } else {
310 return String::Concat(accumulator, String::New(buffer, length-1)); 311 return String::Concat(accumulator, String::New(buffer, length-1));
311 } 312 }
312 } 313 }
313 } 314 }
314 315
315 316
316 Handle<Value> Shell::Load(const Arguments& args) { 317 Handle<Value> Shell::Load(const Arguments& args) {
317 for (int i = 0; i < args.Length(); i++) { 318 for (int i = 0; i < args.Length(); i++) {
318 HandleScope handle_scope; 319 HandleScope handle_scope(args.GetIsolate());
319 String::Utf8Value file(args[i]); 320 String::Utf8Value file(args[i]);
320 if (*file == NULL) { 321 if (*file == NULL) {
321 return Throw("Error loading file"); 322 return Throw("Error loading file");
322 } 323 }
323 Handle<String> source = ReadFile(args.GetIsolate(), *file); 324 Handle<String> source = ReadFile(args.GetIsolate(), *file);
324 if (source.IsEmpty()) { 325 if (source.IsEmpty()) {
325 return Throw("Error loading file"); 326 return Throw("Error loading file");
326 } 327 }
327 if (!ExecuteString(source, String::New(*file), false, true)) { 328 if (!ExecuteString(args.GetIsolate(),
329 source,
330 String::New(*file),
331 false,
332 true)) {
328 return Throw("Error executing file"); 333 return Throw("Error executing file");
329 } 334 }
330 } 335 }
331 return Undefined(args.GetIsolate()); 336 return Undefined(args.GetIsolate());
332 } 337 }
333 338
334 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) { 339 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) {
335 if (value_in->IsInt32()) { 340 if (value_in->IsInt32()) {
336 return value_in->Int32Value(); 341 return value_in->Int32Value();
337 } 342 }
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 825 }
821 } 826 }
822 827
823 return Undefined(args.GetIsolate()); 828 return Undefined(args.GetIsolate());
824 } 829 }
825 830
826 831
827 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, 832 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
828 Persistent<Value> object, 833 Persistent<Value> object,
829 void* data) { 834 void* data) {
830 HandleScope scope; 835 HandleScope scope(isolate);
831 int32_t length = 836 int32_t length =
832 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); 837 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value();
833 V8::AdjustAmountOfExternalAllocatedMemory(-length); 838 V8::AdjustAmountOfExternalAllocatedMemory(-length);
834 delete[] static_cast<uint8_t*>(data); 839 delete[] static_cast<uint8_t*>(data);
835 object.Dispose(isolate); 840 object.Dispose(isolate);
836 } 841 }
837 842
838 843
839 Handle<Value> Shell::Int8Array(const Arguments& args) { 844 Handle<Value> Shell::Int8Array(const Arguments& args) {
840 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); 845 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 exit(exit_code); 901 exit(exit_code);
897 return Undefined(args.GetIsolate()); 902 return Undefined(args.GetIsolate());
898 } 903 }
899 904
900 905
901 Handle<Value> Shell::Version(const Arguments& args) { 906 Handle<Value> Shell::Version(const Arguments& args) {
902 return String::New(V8::GetVersion()); 907 return String::New(V8::GetVersion());
903 } 908 }
904 909
905 910
906 void Shell::ReportException(v8::TryCatch* try_catch) { 911 void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
907 HandleScope handle_scope; 912 HandleScope handle_scope(isolate);
908 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 913 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
909 bool enter_context = !Context::InContext(); 914 bool enter_context = !Context::InContext();
910 if (enter_context) utility_context_->Enter(); 915 if (enter_context) utility_context_->Enter();
911 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 916 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
912 v8::String::Utf8Value exception(try_catch->Exception()); 917 v8::String::Utf8Value exception(try_catch->Exception());
913 const char* exception_string = ToCString(exception); 918 const char* exception_string = ToCString(exception);
914 Handle<Message> message = try_catch->Message(); 919 Handle<Message> message = try_catch->Message();
915 if (message.IsEmpty()) { 920 if (message.IsEmpty()) {
916 // V8 didn't provide any extra information about this error; just 921 // V8 didn't provide any extra information about this error; just
917 // print the exception. 922 // print the exception.
(...skipping 25 matching lines...) Expand all
943 } 948 }
944 } 949 }
945 printf("\n"); 950 printf("\n");
946 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 951 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
947 if (enter_context) utility_context_->Exit(); 952 if (enter_context) utility_context_->Exit();
948 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 953 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
949 } 954 }
950 955
951 956
952 #ifndef V8_SHARED 957 #ifndef V8_SHARED
953 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) { 958 Handle<Array> Shell::GetCompletions(Isolate* isolate,
954 HandleScope handle_scope; 959 Handle<String> text,
960 Handle<String> full) {
961 HandleScope handle_scope(isolate);
955 Context::Scope context_scope(utility_context_); 962 Context::Scope context_scope(utility_context_);
956 Handle<Object> global = utility_context_->Global(); 963 Handle<Object> global = utility_context_->Global();
957 Handle<Value> fun = global->Get(String::New("GetCompletions")); 964 Handle<Value> fun = global->Get(String::New("GetCompletions"));
958 static const int kArgc = 3; 965 static const int kArgc = 3;
959 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; 966 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full };
960 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 967 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
961 return handle_scope.Close(Handle<Array>::Cast(val)); 968 return handle_scope.Close(Handle<Array>::Cast(val));
962 } 969 }
963 970
964 971
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1094
1088 1095
1089 void Shell::AddHistogramSample(void* histogram, int sample) { 1096 void Shell::AddHistogramSample(void* histogram, int sample) {
1090 Counter* counter = reinterpret_cast<Counter*>(histogram); 1097 Counter* counter = reinterpret_cast<Counter*>(histogram);
1091 counter->AddSample(sample); 1098 counter->AddSample(sample);
1092 } 1099 }
1093 1100
1094 1101
1095 void Shell::InstallUtilityScript(Isolate* isolate) { 1102 void Shell::InstallUtilityScript(Isolate* isolate) {
1096 Locker lock(isolate); 1103 Locker lock(isolate);
1097 HandleScope scope; 1104 HandleScope scope(isolate);
1098 // If we use the utility context, we have to set the security tokens so that 1105 // If we use the utility context, we have to set the security tokens so that
1099 // utility, evaluation and debug context can all access each other. 1106 // utility, evaluation and debug context can all access each other.
1100 utility_context_->SetSecurityToken(Undefined(isolate)); 1107 utility_context_->SetSecurityToken(Undefined(isolate));
1101 evaluation_context_->SetSecurityToken(Undefined(isolate)); 1108 evaluation_context_->SetSecurityToken(Undefined(isolate));
1102 Context::Scope utility_scope(utility_context_); 1109 Context::Scope utility_scope(utility_context_);
1103 1110
1104 #ifdef ENABLE_DEBUGGER_SUPPORT 1111 #ifdef ENABLE_DEBUGGER_SUPPORT
1105 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); 1112 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
1106 // Install the debugger object in the utility scope 1113 // Install the debugger object in the utility scope
1107 i::Debug* debug = i::Isolate::Current()->debug(); 1114 i::Debug* debug = i::Isolate::Current()->debug();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 V8::SetAddHistogramSampleFunction(AddHistogramSample); 1272 V8::SetAddHistogramSampleFunction(AddHistogramSample);
1266 } 1273 }
1267 #endif // V8_SHARED 1274 #endif // V8_SHARED
1268 } 1275 }
1269 1276
1270 1277
1271 void Shell::InitializeDebugger(Isolate* isolate) { 1278 void Shell::InitializeDebugger(Isolate* isolate) {
1272 if (options.test_shell) return; 1279 if (options.test_shell) return;
1273 #ifndef V8_SHARED 1280 #ifndef V8_SHARED
1274 Locker lock(isolate); 1281 Locker lock(isolate);
1275 HandleScope scope; 1282 HandleScope scope(isolate);
1276 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); 1283 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
1277 utility_context_ = Context::New(NULL, global_template); 1284 utility_context_ = Context::New(NULL, global_template);
1278 1285
1279 #ifdef ENABLE_DEBUGGER_SUPPORT 1286 #ifdef ENABLE_DEBUGGER_SUPPORT
1280 // Start the debugger agent if requested. 1287 // Start the debugger agent if requested.
1281 if (i::FLAG_debugger_agent) { 1288 if (i::FLAG_debugger_agent) {
1282 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); 1289 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
1283 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); 1290 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
1284 } 1291 }
1285 #endif // ENABLE_DEBUGGER_SUPPORT 1292 #endif // ENABLE_DEBUGGER_SUPPORT
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 if (chars == NULL) return Handle<String>(); 1493 if (chars == NULL) return Handle<String>();
1487 Handle<String> result = String::New(chars, size); 1494 Handle<String> result = String::New(chars, size);
1488 delete[] chars; 1495 delete[] chars;
1489 return result; 1496 return result;
1490 } 1497 }
1491 1498
1492 1499
1493 void Shell::RunShell(Isolate* isolate) { 1500 void Shell::RunShell(Isolate* isolate) {
1494 Locker locker(isolate); 1501 Locker locker(isolate);
1495 Context::Scope context_scope(evaluation_context_); 1502 Context::Scope context_scope(evaluation_context_);
1496 HandleScope outer_scope; 1503 HandleScope outer_scope(isolate);
1497 Handle<String> name = String::New("(d8)"); 1504 Handle<String> name = String::New("(d8)");
1498 LineEditor* console = LineEditor::Get(); 1505 LineEditor* console = LineEditor::Get();
1499 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); 1506 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
1500 console->Open(isolate); 1507 console->Open(isolate);
1501 while (true) { 1508 while (true) {
1502 HandleScope inner_scope; 1509 HandleScope inner_scope(isolate);
1503 Handle<String> input = console->Prompt(Shell::kPrompt); 1510 Handle<String> input = console->Prompt(Shell::kPrompt);
1504 if (input.IsEmpty()) break; 1511 if (input.IsEmpty()) break;
1505 ExecuteString(input, name, true, true); 1512 ExecuteString(isolate, input, name, true, true);
1506 } 1513 }
1507 printf("\n"); 1514 printf("\n");
1508 } 1515 }
1509 1516
1510 1517
1511 #ifndef V8_SHARED 1518 #ifndef V8_SHARED
1512 class ShellThread : public i::Thread { 1519 class ShellThread : public i::Thread {
1513 public: 1520 public:
1514 // Takes ownership of the underlying char array of |files|. 1521 // Takes ownership of the underlying char array of |files|.
1515 ShellThread(Isolate* isolate, char* files) 1522 ShellThread(Isolate* isolate, char* files)
(...skipping 18 matching lines...) Expand all
1534 char* next_line = ReadLine(ptr); 1541 char* next_line = ReadLine(ptr);
1535 1542
1536 if (*ptr == '#') { 1543 if (*ptr == '#') {
1537 // Skip comment lines. 1544 // Skip comment lines.
1538 ptr = next_line; 1545 ptr = next_line;
1539 continue; 1546 continue;
1540 } 1547 }
1541 1548
1542 // Prepare the context for this thread. 1549 // Prepare the context for this thread.
1543 Locker locker(isolate_); 1550 Locker locker(isolate_);
1544 HandleScope outer_scope; 1551 HandleScope outer_scope(isolate_);
1545 Persistent<Context> thread_context = 1552 Persistent<Context> thread_context =
1546 Shell::CreateEvaluationContext(isolate_); 1553 Shell::CreateEvaluationContext(isolate_);
1547 Context::Scope context_scope(thread_context); 1554 Context::Scope context_scope(thread_context);
1548 1555
1549 while ((ptr != NULL) && (*ptr != '\0')) { 1556 while ((ptr != NULL) && (*ptr != '\0')) {
1550 HandleScope inner_scope; 1557 HandleScope inner_scope(isolate_);
1551 char* filename = ptr; 1558 char* filename = ptr;
1552 ptr = ReadWord(ptr); 1559 ptr = ReadWord(ptr);
1553 1560
1554 // Skip empty strings. 1561 // Skip empty strings.
1555 if (strlen(filename) == 0) { 1562 if (strlen(filename) == 0) {
1556 continue; 1563 continue;
1557 } 1564 }
1558 1565
1559 Handle<String> str = Shell::ReadFile(isolate_, filename); 1566 Handle<String> str = Shell::ReadFile(isolate_, filename);
1560 if (str.IsEmpty()) { 1567 if (str.IsEmpty()) {
1561 printf("File '%s' not found\n", filename); 1568 printf("File '%s' not found\n", filename);
1562 Shell::Exit(1); 1569 Shell::Exit(1);
1563 } 1570 }
1564 1571
1565 Shell::ExecuteString(str, String::New(filename), false, false); 1572 Shell::ExecuteString(isolate_, str, String::New(filename), false, false);
1566 } 1573 }
1567 1574
1568 thread_context.Dispose(thread_context->GetIsolate()); 1575 thread_context.Dispose(thread_context->GetIsolate());
1569 ptr = next_line; 1576 ptr = next_line;
1570 } 1577 }
1571 } 1578 }
1572 #endif // V8_SHARED 1579 #endif // V8_SHARED
1573 1580
1574 1581
1575 SourceGroup::~SourceGroup() { 1582 SourceGroup::~SourceGroup() {
1576 #ifndef V8_SHARED 1583 #ifndef V8_SHARED
1577 delete next_semaphore_; 1584 delete next_semaphore_;
1578 next_semaphore_ = NULL; 1585 next_semaphore_ = NULL;
1579 delete done_semaphore_; 1586 delete done_semaphore_;
1580 done_semaphore_ = NULL; 1587 done_semaphore_ = NULL;
1581 delete thread_; 1588 delete thread_;
1582 thread_ = NULL; 1589 thread_ = NULL;
1583 #endif // V8_SHARED 1590 #endif // V8_SHARED
1584 } 1591 }
1585 1592
1586 1593
1587 void SourceGroup::Execute(Isolate* isolate) { 1594 void SourceGroup::Execute(Isolate* isolate) {
1588 for (int i = begin_offset_; i < end_offset_; ++i) { 1595 for (int i = begin_offset_; i < end_offset_; ++i) {
1589 const char* arg = argv_[i]; 1596 const char* arg = argv_[i];
1590 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { 1597 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
1591 // Execute argument given to -e option directly. 1598 // Execute argument given to -e option directly.
1592 HandleScope handle_scope; 1599 HandleScope handle_scope(isolate);
1593 Handle<String> file_name = String::New("unnamed"); 1600 Handle<String> file_name = String::New("unnamed");
1594 Handle<String> source = String::New(argv_[i + 1]); 1601 Handle<String> source = String::New(argv_[i + 1]);
1595 if (!Shell::ExecuteString(source, file_name, false, true)) { 1602 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
1596 Shell::Exit(1); 1603 Shell::Exit(1);
1597 } 1604 }
1598 ++i; 1605 ++i;
1599 } else if (arg[0] == '-') { 1606 } else if (arg[0] == '-') {
1600 // Ignore other options. They have been parsed already. 1607 // Ignore other options. They have been parsed already.
1601 } else { 1608 } else {
1602 // Use all other arguments as names of files to load and run. 1609 // Use all other arguments as names of files to load and run.
1603 HandleScope handle_scope; 1610 HandleScope handle_scope(isolate);
1604 Handle<String> file_name = String::New(arg); 1611 Handle<String> file_name = String::New(arg);
1605 Handle<String> source = ReadFile(isolate, arg); 1612 Handle<String> source = ReadFile(isolate, arg);
1606 if (source.IsEmpty()) { 1613 if (source.IsEmpty()) {
1607 printf("Error reading '%s'\n", arg); 1614 printf("Error reading '%s'\n", arg);
1608 Shell::Exit(1); 1615 Shell::Exit(1);
1609 } 1616 }
1610 if (!Shell::ExecuteString(source, file_name, false, true)) { 1617 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
1611 Shell::Exit(1); 1618 Shell::Exit(1);
1612 } 1619 }
1613 } 1620 }
1614 } 1621 }
1615 } 1622 }
1616 1623
1617 1624
1618 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { 1625 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) {
1619 int size; 1626 int size;
1620 char* chars = ReadChars(isolate, name, &size); 1627 char* chars = ReadChars(isolate, name, &size);
(...skipping 14 matching lines...) Expand all
1635 } 1642 }
1636 1643
1637 1644
1638 void SourceGroup::ExecuteInThread() { 1645 void SourceGroup::ExecuteInThread() {
1639 Isolate* isolate = Isolate::New(); 1646 Isolate* isolate = Isolate::New();
1640 do { 1647 do {
1641 if (next_semaphore_ != NULL) next_semaphore_->Wait(); 1648 if (next_semaphore_ != NULL) next_semaphore_->Wait();
1642 { 1649 {
1643 Isolate::Scope iscope(isolate); 1650 Isolate::Scope iscope(isolate);
1644 Locker lock(isolate); 1651 Locker lock(isolate);
1645 HandleScope scope; 1652 HandleScope scope(isolate);
1646 Symbols symbols(isolate); 1653 Symbols symbols(isolate);
1647 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); 1654 Persistent<Context> context = Shell::CreateEvaluationContext(isolate);
1648 { 1655 {
1649 Context::Scope cscope(context); 1656 Context::Scope cscope(context);
1650 Execute(isolate); 1657 Execute(isolate);
1651 } 1658 }
1652 context.Dispose(isolate); 1659 context.Dispose(isolate);
1653 if (Shell::options.send_idle_notification) { 1660 if (Shell::options.send_idle_notification) {
1654 const int kLongIdlePauseInMs = 1000; 1661 const int kLongIdlePauseInMs = 1000;
1655 V8::ContextDisposedNotification(); 1662 V8::ContextDisposedNotification();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 thread->Start(); 1840 thread->Start();
1834 threads.Add(thread); 1841 threads.Add(thread);
1835 } 1842 }
1836 } 1843 }
1837 for (int i = 1; i < options.num_isolates; ++i) { 1844 for (int i = 1; i < options.num_isolates; ++i) {
1838 options.isolate_sources[i].StartExecuteInThread(); 1845 options.isolate_sources[i].StartExecuteInThread();
1839 } 1846 }
1840 #endif // V8_SHARED 1847 #endif // V8_SHARED
1841 { // NOLINT 1848 { // NOLINT
1842 Locker lock(isolate); 1849 Locker lock(isolate);
1843 HandleScope scope; 1850 HandleScope scope(isolate);
1844 Persistent<Context> context = CreateEvaluationContext(isolate); 1851 Persistent<Context> context = CreateEvaluationContext(isolate);
1845 if (options.last_run) { 1852 if (options.last_run) {
1846 // Keep using the same context in the interactive shell. 1853 // Keep using the same context in the interactive shell.
1847 evaluation_context_ = context; 1854 evaluation_context_ = context;
1848 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 1855 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
1849 // If the interactive debugger is enabled make sure to activate 1856 // If the interactive debugger is enabled make sure to activate
1850 // it before running the files passed on the command line. 1857 // it before running the files passed on the command line.
1851 if (i::FLAG_debugger) { 1858 if (i::FLAG_debugger) {
1852 InstallUtilityScript(isolate); 1859 InstallUtilityScript(isolate);
1853 } 1860 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 #endif 1936 #endif
1930 } else { 1937 } else {
1931 result = RunMain(isolate, argc, argv); 1938 result = RunMain(isolate, argc, argv);
1932 } 1939 }
1933 1940
1934 1941
1935 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 1942 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
1936 // Run remote debugger if requested, but never on --test 1943 // Run remote debugger if requested, but never on --test
1937 if (i::FLAG_remote_debugger && !options.test_shell) { 1944 if (i::FLAG_remote_debugger && !options.test_shell) {
1938 InstallUtilityScript(isolate); 1945 InstallUtilityScript(isolate);
1939 RunRemoteDebugger(i::FLAG_debugger_port); 1946 RunRemoteDebugger(isolate, i::FLAG_debugger_port);
1940 return 0; 1947 return 0;
1941 } 1948 }
1942 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 1949 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
1943 1950
1944 // Run interactive shell if explicitly requested or if no script has been 1951 // Run interactive shell if explicitly requested or if no script has been
1945 // executed, but never on --test 1952 // executed, but never on --test
1946 1953
1947 if (( options.interactive_shell || !options.script_executed ) 1954 if (( options.interactive_shell || !options.script_executed )
1948 && !options.test_shell ) { 1955 && !options.test_shell ) {
1949 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 1956 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
(...skipping 12 matching lines...) Expand all
1962 } 1969 }
1963 1970
1964 } // namespace v8 1971 } // namespace v8
1965 1972
1966 1973
1967 #ifndef GOOGLE3 1974 #ifndef GOOGLE3
1968 int main(int argc, char* argv[]) { 1975 int main(int argc, char* argv[]) {
1969 return v8::Shell::Main(argc, argv); 1976 return v8::Shell::Main(argc, argv);
1970 } 1977 }
1971 #endif 1978 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698