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

Side by Side Diff: test/inspector/inspector-test.cc

Issue 2828143002: [test/inspector] migrate utils to ObjectTemplate (Closed)
Patch Set: say no for deprecated methods! Created 3 years, 8 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
« no previous file with comments | « no previous file | test/inspector/protocol-test.js » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if !defined(_WIN32) && !defined(_WIN64) 5 #if !defined(_WIN32) && !defined(_WIN64)
6 #include <unistd.h> // NOLINT 6 #include <unistd.h> // NOLINT
7 #endif // !defined(_WIN32) && !defined(_WIN64) 7 #endif // !defined(_WIN32) && !defined(_WIN64)
8 8
9 #include <locale.h> 9 #include <locale.h>
10 10
(...skipping 28 matching lines...) Expand all
39 Terminate(); 39 Terminate();
40 } 40 }
41 41
42 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { 42 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
43 v8::internal::Vector<uint16_t> buffer = 43 v8::internal::Vector<uint16_t> buffer =
44 v8::internal::Vector<uint16_t>::New(str->Length()); 44 v8::internal::Vector<uint16_t>::New(str->Length());
45 str->Write(buffer.start(), 0, str->Length()); 45 str->Write(buffer.start(), 0, str->Length());
46 return buffer; 46 return buffer;
47 } 47 }
48 48
49 class UtilsExtension : public v8::Extension { 49 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) {
50 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal)
51 .ToLocalChecked();
52 }
53
54 class UtilsExtension : public TaskRunner::Task {
50 public: 55 public:
51 UtilsExtension() 56 ~UtilsExtension() override = default;
52 : v8::Extension("v8_inspector/utils", 57 bool is_inspector_task() override { return true; }
53 "native function print();" 58 void Run(v8::Isolate* isolate,
54 "native function quit();" 59 const v8::Global<v8::Context>& context) override {
55 "native function setlocale();" 60 v8::HandleScope handle_scope(isolate);
56 "native function read();" 61 v8::Local<v8::Context> local_context = context.Get(isolate);
57 "native function load();" 62 v8::Context::Scope context_scope(local_context);
58 "native function compileAndRunWithOrigin();" 63 v8::Local<v8::ObjectTemplate> utils = v8::ObjectTemplate::New(isolate);
59 "native function setCurrentTimeMSForTest();" 64 utils->Set(ToV8String(isolate, "print"),
60 "native function setMemoryInfoForTest();" 65 v8::FunctionTemplate::New(isolate, &UtilsExtension::Print));
61 "native function schedulePauseOnNextStatement();" 66 utils->Set(ToV8String(isolate, "quit"),
62 "native function cancelPauseOnNextStatement();" 67 v8::FunctionTemplate::New(isolate, &UtilsExtension::Quit));
63 "native function reconnect();" 68 utils->Set(ToV8String(isolate, "setlocale"),
64 "native function setLogConsoleApiMessageCalls();" 69 v8::FunctionTemplate::New(isolate, &UtilsExtension::Setlocale));
65 "native function createContextGroup();") {} 70 utils->Set(ToV8String(isolate, "read"),
66 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 71 v8::FunctionTemplate::New(isolate, &UtilsExtension::Read));
67 v8::Isolate* isolate, v8::Local<v8::String> name) { 72 utils->Set(ToV8String(isolate, "load"),
68 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 73 v8::FunctionTemplate::New(isolate, &UtilsExtension::Load));
69 if (name->Equals(context, v8::String::NewFromUtf8( 74 utils->Set(ToV8String(isolate, "compileAndRunWithOrigin"),
70 isolate, "print", v8::NewStringType::kNormal) 75 v8::FunctionTemplate::New(
71 .ToLocalChecked()) 76 isolate, &UtilsExtension::CompileAndRunWithOrigin));
72 .FromJust()) { 77 utils->Set(ToV8String(isolate, "setCurrentTimeMSForTest"),
73 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); 78 v8::FunctionTemplate::New(
74 } else if (name->Equals(context, 79 isolate, &UtilsExtension::SetCurrentTimeMSForTest));
75 v8::String::NewFromUtf8(isolate, "quit", 80 utils->Set(ToV8String(isolate, "setMemoryInfoForTest"),
76 v8::NewStringType::kNormal) 81 v8::FunctionTemplate::New(
77 .ToLocalChecked()) 82 isolate, &UtilsExtension::SetMemoryInfoForTest));
78 .FromJust()) { 83 utils->Set(ToV8String(isolate, "schedulePauseOnNextStatement"),
79 return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit); 84 v8::FunctionTemplate::New(
80 } else if (name->Equals(context, 85 isolate, &UtilsExtension::SchedulePauseOnNextStatement));
81 v8::String::NewFromUtf8(isolate, "setlocale", 86 utils->Set(ToV8String(isolate, "cancelPauseOnNextStatement"),
82 v8::NewStringType::kNormal) 87 v8::FunctionTemplate::New(
83 .ToLocalChecked()) 88 isolate, &UtilsExtension::CancelPauseOnNextStatement));
84 .FromJust()) { 89 utils->Set(ToV8String(isolate, "reconnect"),
85 return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale); 90 v8::FunctionTemplate::New(isolate, &UtilsExtension::Reconnect));
86 } else if (name->Equals(context, 91 utils->Set(ToV8String(isolate, "setLogConsoleApiMessageCalls"),
87 v8::String::NewFromUtf8(isolate, "read", 92 v8::FunctionTemplate::New(
88 v8::NewStringType::kNormal) 93 isolate, &UtilsExtension::SetLogConsoleApiMessageCalls));
89 .ToLocalChecked()) 94 utils->Set(ToV8String(isolate, "createContextGroup"),
90 .FromJust()) { 95 v8::FunctionTemplate::New(isolate,
91 return v8::FunctionTemplate::New(isolate, UtilsExtension::Read); 96 &UtilsExtension::CreateContextGroup));
92 } else if (name->Equals(context, 97 local_context->Global()
93 v8::String::NewFromUtf8(isolate, "load", 98 ->Set(local_context, ToV8String(isolate, "utils"),
94 v8::NewStringType::kNormal) 99 utils->NewInstance(local_context).ToLocalChecked())
95 .ToLocalChecked()) 100 .ToChecked();
96 .FromJust()) {
97 return v8::FunctionTemplate::New(isolate, UtilsExtension::Load);
98 } else if (name->Equals(context, v8::String::NewFromUtf8(
99 isolate, "compileAndRunWithOrigin",
100 v8::NewStringType::kNormal)
101 .ToLocalChecked())
102 .FromJust()) {
103 return v8::FunctionTemplate::New(isolate,
104 UtilsExtension::CompileAndRunWithOrigin);
105 } else if (name->Equals(context, v8::String::NewFromUtf8(
106 isolate, "setCurrentTimeMSForTest",
107 v8::NewStringType::kNormal)
108 .ToLocalChecked())
109 .FromJust()) {
110 return v8::FunctionTemplate::New(isolate,
111 UtilsExtension::SetCurrentTimeMSForTest);
112 } else if (name->Equals(context, v8::String::NewFromUtf8(
113 isolate, "setMemoryInfoForTest",
114 v8::NewStringType::kNormal)
115 .ToLocalChecked())
116 .FromJust()) {
117 return v8::FunctionTemplate::New(isolate,
118 UtilsExtension::SetMemoryInfoForTest);
119 } else if (name->Equals(context,
120 v8::String::NewFromUtf8(
121 isolate, "schedulePauseOnNextStatement",
122 v8::NewStringType::kNormal)
123 .ToLocalChecked())
124 .FromJust()) {
125 return v8::FunctionTemplate::New(
126 isolate, UtilsExtension::SchedulePauseOnNextStatement);
127 } else if (name->Equals(context, v8::String::NewFromUtf8(
128 isolate, "cancelPauseOnNextStatement",
129 v8::NewStringType::kNormal)
130 .ToLocalChecked())
131 .FromJust()) {
132 return v8::FunctionTemplate::New(
133 isolate, UtilsExtension::CancelPauseOnNextStatement);
134 } else if (name->Equals(context,
135 v8::String::NewFromUtf8(isolate, "reconnect",
136 v8::NewStringType::kNormal)
137 .ToLocalChecked())
138 .FromJust()) {
139 return v8::FunctionTemplate::New(isolate, UtilsExtension::Reconnect);
140 } else if (name->Equals(context,
141 v8::String::NewFromUtf8(
142 isolate, "setLogConsoleApiMessageCalls",
143 v8::NewStringType::kNormal)
144 .ToLocalChecked())
145 .FromJust()) {
146 return v8::FunctionTemplate::New(
147 isolate, UtilsExtension::SetLogConsoleApiMessageCalls);
148 } else if (name->Equals(context, v8::String::NewFromUtf8(
149 isolate, "createContextGroup",
150 v8::NewStringType::kNormal)
151 .ToLocalChecked())
152 .FromJust()) {
153 return v8::FunctionTemplate::New(isolate,
154 UtilsExtension::CreateContextGroup);
155 }
156 return v8::Local<v8::FunctionTemplate>();
157 } 101 }
158 102
159 static void set_backend_task_runner(TaskRunner* runner) { 103 static void set_backend_task_runner(TaskRunner* runner) {
160 backend_runner_ = runner; 104 backend_runner_ = runner;
161 } 105 }
162 106
163 static void set_inspector_client(InspectorClientImpl* client) { 107 static void set_inspector_client(InspectorClientImpl* client) {
164 inspector_client_ = client; 108 inspector_client_ = client;
165 } 109 }
166 110
(...skipping 29 matching lines...) Expand all
196 printf("Error in fwrite\n"); 140 printf("Error in fwrite\n");
197 Quit(args); 141 Quit(args);
198 } 142 }
199 } 143 }
200 printf("\n"); 144 printf("\n");
201 fflush(stdout); 145 fflush(stdout);
202 } 146 }
203 147
204 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); } 148 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); }
205 149
206 static void SetLocale(const v8::FunctionCallbackInfo<v8::Value>& args) { 150 static void Setlocale(const v8::FunctionCallbackInfo<v8::Value>& args) {
207 if (args.Length() != 1 || !args[0]->IsString()) { 151 if (args.Length() != 1 || !args[0]->IsString()) {
208 fprintf(stderr, "Internal error: setlocale get one string argument."); 152 fprintf(stderr, "Internal error: setlocale get one string argument.");
209 Exit(); 153 Exit();
210 } 154 }
211 v8::String::Utf8Value str(args[0]); 155 v8::String::Utf8Value str(args[0]);
212 setlocale(LC_NUMERIC, *str); 156 setlocale(LC_NUMERIC, *str);
213 } 157 }
214 158
215 static bool ReadFile(v8::Isolate* isolate, v8::Local<v8::Value> name, 159 static bool ReadFile(v8::Isolate* isolate, v8::Local<v8::Value> name,
216 v8::internal::Vector<const char>* chars) { 160 v8::internal::Vector<const char>* chars) {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 631 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
688 v8::V8::InitializePlatform(platform); 632 v8::V8::InitializePlatform(platform);
689 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 633 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
690 v8::V8::InitializeExternalStartupData(argv[0]); 634 v8::V8::InitializeExternalStartupData(argv[0]);
691 v8::V8::Initialize(); 635 v8::V8::Initialize();
692 636
693 SetTimeoutExtension set_timeout_extension; 637 SetTimeoutExtension set_timeout_extension;
694 v8::RegisterExtension(&set_timeout_extension); 638 v8::RegisterExtension(&set_timeout_extension);
695 InspectorExtension inspector_extension; 639 InspectorExtension inspector_extension;
696 v8::RegisterExtension(&inspector_extension); 640 v8::RegisterExtension(&inspector_extension);
697 UtilsExtension utils_extension;
698 v8::RegisterExtension(&utils_extension);
699 SendMessageToBackendExtension send_message_to_backend_extension; 641 SendMessageToBackendExtension send_message_to_backend_extension;
700 v8::RegisterExtension(&send_message_to_backend_extension); 642 v8::RegisterExtension(&send_message_to_backend_extension);
701 643
702 v8::base::Semaphore ready_semaphore(0); 644 v8::base::Semaphore ready_semaphore(0);
703 645
704 const char* backend_extensions[] = {"v8_inspector/setTimeout", 646 const char* backend_extensions[] = {"v8_inspector/setTimeout",
705 "v8_inspector/inspector"}; 647 "v8_inspector/inspector"};
706 v8::ExtensionConfiguration backend_configuration( 648 v8::ExtensionConfiguration backend_configuration(
707 arraysize(backend_extensions), backend_extensions); 649 arraysize(backend_extensions), backend_extensions);
708 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); 650 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore);
709 ready_semaphore.Wait(); 651 ready_semaphore.Wait();
710 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); 652 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner);
711 UtilsExtension::set_backend_task_runner(&backend_runner); 653 UtilsExtension::set_backend_task_runner(&backend_runner);
712 654
713 const char* frontend_extensions[] = {"v8_inspector/utils", 655 const char* frontend_extensions[] = {"v8_inspector/frontend"};
714 "v8_inspector/frontend"};
715 v8::ExtensionConfiguration frontend_configuration( 656 v8::ExtensionConfiguration frontend_configuration(
716 arraysize(frontend_extensions), frontend_extensions); 657 arraysize(frontend_extensions), frontend_extensions);
717 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); 658 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore);
718 ready_semaphore.Wait(); 659 ready_semaphore.Wait();
660 frontend_runner.Append(new UtilsExtension());
719 661
720 FrontendChannelImpl frontend_channel(&frontend_runner); 662 FrontendChannelImpl frontend_channel(&frontend_runner);
721 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, 663 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel,
722 &ready_semaphore); 664 &ready_semaphore);
723 ready_semaphore.Wait(); 665 ready_semaphore.Wait();
724 UtilsExtension::set_inspector_client(&inspector_client); 666 UtilsExtension::set_inspector_client(&inspector_client);
725 667
726 task_runners.push_back(&frontend_runner); 668 task_runners.push_back(&frontend_runner);
727 task_runners.push_back(&backend_runner); 669 task_runners.push_back(&backend_runner);
728 670
729 for (int i = 1; i < argc; ++i) { 671 for (int i = 1; i < argc; ++i) {
730 // Ignore unknown flags. 672 // Ignore unknown flags.
731 if (argv[i][0] == '-') continue; 673 if (argv[i][0] == '-') continue;
732 674
733 bool exists = false; 675 bool exists = false;
734 v8::internal::Vector<const char> chars = 676 v8::internal::Vector<const char> chars =
735 v8::internal::ReadFile(argv[i], &exists, true); 677 v8::internal::ReadFile(argv[i], &exists, true);
736 if (!exists) { 678 if (!exists) {
737 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", 679 fprintf(stderr, "Internal error: script file doesn't exists: %s\n",
738 argv[i]); 680 argv[i]);
739 Exit(); 681 Exit();
740 } 682 }
741 frontend_runner.Append(new ExecuteStringTask(chars)); 683 frontend_runner.Append(new ExecuteStringTask(chars));
742 } 684 }
743 685
744 frontend_runner.Join(); 686 frontend_runner.Join();
745 backend_runner.Join(); 687 backend_runner.Join();
746 return 0; 688 return 0;
747 } 689 }
OLDNEW
« no previous file with comments | « no previous file | test/inspector/protocol-test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698