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

Side by Side Diff: src/d8.cc

Issue 15837007: remove use of context scope with persistent argument (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 | « samples/process.cc ('k') | test/cctest/test-api.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 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (!result->IsUndefined()) { 236 if (!result->IsUndefined()) {
237 // If all went well and the result wasn't undefined then print 237 // If all went well and the result wasn't undefined then print
238 // the returned value. 238 // the returned value.
239 v8::String::Utf8Value str(result); 239 v8::String::Utf8Value str(result);
240 fwrite(*str, sizeof(**str), str.length(), stdout); 240 fwrite(*str, sizeof(**str), str.length(), stdout);
241 printf("\n"); 241 printf("\n");
242 } 242 }
243 #if !defined(V8_SHARED) 243 #if !defined(V8_SHARED)
244 } else { 244 } else {
245 v8::TryCatch try_catch; 245 v8::TryCatch try_catch;
246 Context::Scope context_scope(isolate, utility_context_); 246 v8::Local<v8::Context> context =
247 v8::Local<v8::Context>::New(isolate, utility_context_);
248 v8::Context::Scope context_scope(context);
247 Handle<Object> global = utility_context_->Global(); 249 Handle<Object> global = utility_context_->Global();
248 Handle<Value> fun = global->Get(String::New("Stringify")); 250 Handle<Value> fun = global->Get(String::New("Stringify"));
249 Handle<Value> argv[1] = { result }; 251 Handle<Value> argv[1] = { result };
250 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); 252 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv);
251 if (try_catch.HasCaught()) return true; 253 if (try_catch.HasCaught()) return true;
252 v8::String::Utf8Value str(s); 254 v8::String::Utf8Value str(s);
253 fwrite(*str, sizeof(**str), str.length(), stdout); 255 fwrite(*str, sizeof(**str), str.length(), stdout);
254 printf("\n"); 256 printf("\n");
255 } 257 }
256 #endif 258 #endif
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (enter_context) utility_context_->Exit(); 587 if (enter_context) utility_context_->Exit();
586 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 588 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
587 } 589 }
588 590
589 591
590 #ifndef V8_SHARED 592 #ifndef V8_SHARED
591 Handle<Array> Shell::GetCompletions(Isolate* isolate, 593 Handle<Array> Shell::GetCompletions(Isolate* isolate,
592 Handle<String> text, 594 Handle<String> text,
593 Handle<String> full) { 595 Handle<String> full) {
594 HandleScope handle_scope(isolate); 596 HandleScope handle_scope(isolate);
595 Context::Scope context_scope(isolate, utility_context_); 597 v8::Local<v8::Context> context =
598 v8::Local<v8::Context>::New(isolate, utility_context_);
599 v8::Context::Scope context_scope(context);
596 Handle<Object> global = utility_context_->Global(); 600 Handle<Object> global = utility_context_->Global();
597 Handle<Value> fun = global->Get(String::New("GetCompletions")); 601 Handle<Value> fun = global->Get(String::New("GetCompletions"));
598 static const int kArgc = 3; 602 static const int kArgc = 3;
599 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; 603 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full };
600 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 604 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
601 return handle_scope.Close(Handle<Array>::Cast(val)); 605 return handle_scope.Close(Handle<Array>::Cast(val));
602 } 606 }
603 607
604 608
605 #ifdef ENABLE_DEBUGGER_SUPPORT 609 #ifdef ENABLE_DEBUGGER_SUPPORT
606 Handle<Object> Shell::DebugMessageDetails(Isolate* isolate, 610 Handle<Object> Shell::DebugMessageDetails(Isolate* isolate,
607 Handle<String> message) { 611 Handle<String> message) {
608 HandleScope handle_scope(isolate); 612 HandleScope handle_scope(isolate);
609 Context::Scope context_scope(isolate, utility_context_); 613 v8::Local<v8::Context> context =
614 v8::Local<v8::Context>::New(isolate, utility_context_);
615 v8::Context::Scope context_scope(context);
610 Handle<Object> global = utility_context_->Global(); 616 Handle<Object> global = utility_context_->Global();
611 Handle<Value> fun = global->Get(String::New("DebugMessageDetails")); 617 Handle<Value> fun = global->Get(String::New("DebugMessageDetails"));
612 static const int kArgc = 1; 618 static const int kArgc = 1;
613 Handle<Value> argv[kArgc] = { message }; 619 Handle<Value> argv[kArgc] = { message };
614 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 620 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
615 return Handle<Object>::Cast(val); 621 return Handle<Object>::Cast(val);
616 } 622 }
617 623
618 624
619 Handle<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate, 625 Handle<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate,
620 Handle<String> command) { 626 Handle<String> command) {
621 HandleScope handle_scope(isolate); 627 HandleScope handle_scope(isolate);
622 Context::Scope context_scope(isolate, utility_context_); 628 v8::Local<v8::Context> context =
629 v8::Local<v8::Context>::New(isolate, utility_context_);
630 v8::Context::Scope context_scope(context);
623 Handle<Object> global = utility_context_->Global(); 631 Handle<Object> global = utility_context_->Global();
624 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); 632 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
625 static const int kArgc = 1; 633 static const int kArgc = 1;
626 Handle<Value> argv[kArgc] = { command }; 634 Handle<Value> argv[kArgc] = { command };
627 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 635 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
628 return val; 636 return val;
629 } 637 }
630 638
631 639
632 void Shell::DispatchDebugMessages() { 640 void Shell::DispatchDebugMessages() {
633 Isolate* isolate = v8::Isolate::GetCurrent(); 641 Isolate* isolate = v8::Isolate::GetCurrent();
634 HandleScope handle_scope(isolate); 642 HandleScope handle_scope(isolate);
635 v8::Context::Scope scope(isolate, Shell::evaluation_context_); 643 v8::Local<v8::Context> context =
644 v8::Local<v8::Context>::New(isolate, Shell::evaluation_context_);
645 v8::Context::Scope context_scope(context);
636 v8::Debug::ProcessDebugMessages(); 646 v8::Debug::ProcessDebugMessages();
637 } 647 }
638 #endif // ENABLE_DEBUGGER_SUPPORT 648 #endif // ENABLE_DEBUGGER_SUPPORT
639 #endif // V8_SHARED 649 #endif // V8_SHARED
640 650
641 651
642 #ifndef V8_SHARED 652 #ifndef V8_SHARED
643 int32_t* Counter::Bind(const char* name, bool is_histogram) { 653 int32_t* Counter::Bind(const char* name, bool is_histogram) {
644 int i; 654 int i;
645 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 655 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 748 }
739 749
740 750
741 void Shell::InstallUtilityScript(Isolate* isolate) { 751 void Shell::InstallUtilityScript(Isolate* isolate) {
742 Locker lock(isolate); 752 Locker lock(isolate);
743 HandleScope scope(isolate); 753 HandleScope scope(isolate);
744 // If we use the utility context, we have to set the security tokens so that 754 // If we use the utility context, we have to set the security tokens so that
745 // utility, evaluation and debug context can all access each other. 755 // utility, evaluation and debug context can all access each other.
746 utility_context_->SetSecurityToken(Undefined(isolate)); 756 utility_context_->SetSecurityToken(Undefined(isolate));
747 evaluation_context_->SetSecurityToken(Undefined(isolate)); 757 evaluation_context_->SetSecurityToken(Undefined(isolate));
748 Context::Scope utility_scope(isolate, utility_context_); 758 v8::Local<v8::Context> context =
759 v8::Local<v8::Context>::New(isolate, utility_context_);
760 v8::Context::Scope context_scope(context);
749 761
750 #ifdef ENABLE_DEBUGGER_SUPPORT 762 #ifdef ENABLE_DEBUGGER_SUPPORT
751 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); 763 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
752 // Install the debugger object in the utility scope 764 // Install the debugger object in the utility scope
753 i::Debug* debug = i::Isolate::Current()->debug(); 765 i::Debug* debug = i::Isolate::Current()->debug();
754 debug->Load(); 766 debug->Load();
755 i::Handle<i::JSObject> js_debug 767 i::Handle<i::JSObject> js_debug
756 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); 768 = i::Handle<i::JSObject>(debug->debug_context()->global_object());
757 utility_context_->Global()->Set(String::New("$debug"), 769 utility_context_->Global()->Set(String::New("$debug"),
758 Utils::ToLocal(js_debug)); 770 Utils::ToLocal(js_debug));
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 if (chars == NULL) return Handle<String>(); 1126 if (chars == NULL) return Handle<String>();
1115 Handle<String> result = String::New(chars, size); 1127 Handle<String> result = String::New(chars, size);
1116 delete[] chars; 1128 delete[] chars;
1117 return result; 1129 return result;
1118 } 1130 }
1119 1131
1120 1132
1121 void Shell::RunShell(Isolate* isolate) { 1133 void Shell::RunShell(Isolate* isolate) {
1122 Locker locker(isolate); 1134 Locker locker(isolate);
1123 HandleScope outer_scope(isolate); 1135 HandleScope outer_scope(isolate);
1124 Context::Scope context_scope(isolate, evaluation_context_); 1136 v8::Local<v8::Context> context =
1137 v8::Local<v8::Context>::New(isolate, evaluation_context_);
1138 v8::Context::Scope context_scope(context);
1125 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); 1139 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1126 Handle<String> name = String::New("(d8)"); 1140 Handle<String> name = String::New("(d8)");
1127 LineEditor* console = LineEditor::Get(); 1141 LineEditor* console = LineEditor::Get();
1128 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); 1142 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
1129 console->Open(isolate); 1143 console->Open(isolate);
1130 while (true) { 1144 while (true) {
1131 HandleScope inner_scope(isolate); 1145 HandleScope inner_scope(isolate);
1132 Handle<String> input = console->Prompt(Shell::kPrompt); 1146 Handle<String> input = console->Prompt(Shell::kPrompt);
1133 if (input.IsEmpty()) break; 1147 if (input.IsEmpty()) break;
1134 ExecuteString(isolate, input, name, true, true); 1148 ExecuteString(isolate, input, name, true, true);
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 } 1631 }
1618 1632
1619 } // namespace v8 1633 } // namespace v8
1620 1634
1621 1635
1622 #ifndef GOOGLE3 1636 #ifndef GOOGLE3
1623 int main(int argc, char* argv[]) { 1637 int main(int argc, char* argv[]) {
1624 return v8::Shell::Main(argc, argv); 1638 return v8::Shell::Main(argc, argv);
1625 } 1639 }
1626 #endif 1640 #endif
OLDNEW
« no previous file with comments | « samples/process.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698