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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp

Issue 1758313002: DevTools: introduce collections shim to be backed by non-wtf in v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 #include "platform/v8_inspector/V8InjectedScriptHost.h" 5 #include "platform/v8_inspector/V8InjectedScriptHost.h"
6 6
7 #include "platform/inspector_protocol/Values.h" 7 #include "platform/inspector_protocol/Values.h"
8 #include "platform/v8_inspector/InjectedScript.h" 8 #include "platform/v8_inspector/InjectedScript.h"
9 #include "platform/v8_inspector/InjectedScriptHost.h" 9 #include "platform/v8_inspector/InjectedScriptHost.h"
10 #include "platform/v8_inspector/InspectorWrapper.h" 10 #include "platform/v8_inspector/InspectorWrapper.h"
11 #include "platform/v8_inspector/JavaScriptCallFrame.h" 11 #include "platform/v8_inspector/JavaScriptCallFrame.h"
12 #include "platform/v8_inspector/V8DebuggerImpl.h" 12 #include "platform/v8_inspector/V8DebuggerImpl.h"
13 #include "platform/v8_inspector/V8StringUtil.h" 13 #include "platform/v8_inspector/V8StringUtil.h"
14 #include "platform/v8_inspector/public/V8DebuggerClient.h" 14 #include "platform/v8_inspector/public/V8DebuggerClient.h"
15 #include "platform/v8_inspector/public/V8EventListenerInfo.h" 15 #include "platform/v8_inspector/public/V8EventListenerInfo.h"
16 #include "platform/v8_inspector/public/V8ToProtocolValue.h" 16 #include "platform/v8_inspector/public/V8ToProtocolValue.h"
17 #include "wtf/HashSet.h"
18 #include "wtf/text/WTFString.h" 17 #include "wtf/text/WTFString.h"
19 #include <algorithm> 18 #include <algorithm>
20 19
21 namespace blink { 20 namespace blink {
22 21
23 namespace { 22 namespace {
24 23
25 template<typename CallbackInfo, typename S> 24 template<typename CallbackInfo, typename S>
26 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Local<S> handle ) 25 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Local<S> handle )
27 { 26 {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info) 214 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info)
216 { 215 {
217 if (info.Length() < 1 || !info[0]->IsObject()) 216 if (info.Length() < 1 || !info[0]->IsObject())
218 return; 217 return;
219 218
220 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 219 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
221 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info .GetIsolate(), object); 220 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info .GetIsolate(), object);
222 v8SetReturnValue(info, properties); 221 v8SetReturnValue(info, properties);
223 } 222 }
224 223
225 static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const Ve ctor<V8EventListenerInfo>& listeners) 224 static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const pr otocol::Vector<V8EventListenerInfo>& listeners)
226 { 225 {
227 v8::Local<v8::Array> result = v8::Array::New(isolate); 226 v8::Local<v8::Array> result = v8::Array::New(isolate);
228 size_t handlersCount = listeners.size(); 227 size_t handlersCount = listeners.size();
229 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { 228 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) {
230 v8::Local<v8::Object> function = listeners[i].handler; 229 v8::Local<v8::Object> function = listeners[i].handler;
231 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); 230 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate);
232 listenerEntry->Set(toV8StringInternalized(isolate, "listener"), function ); 231 listenerEntry->Set(toV8StringInternalized(isolate, "listener"), function );
233 listenerEntry->Set(toV8StringInternalized(isolate, "useCapture"), v8::Bo olean::New(isolate, listeners[i].useCapture)); 232 listenerEntry->Set(toV8StringInternalized(isolate, "useCapture"), v8::Bo olean::New(isolate, listeners[i].useCapture));
234 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); 233 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry);
235 } 234 }
236 return result; 235 return result;
237 } 236 }
238 237
239 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 238 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
240 { 239 {
241 if (info.Length() < 1) 240 if (info.Length() < 1)
242 return; 241 return;
243 242
244 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder()); 243 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder());
245 if (!host->debugger()) 244 if (!host->debugger())
246 return; 245 return;
247 V8DebuggerClient* client = host->debugger()->client(); 246 V8DebuggerClient* client = host->debugger()->client();
248 V8EventListenerInfoMap listenerInfo; 247 V8EventListenerInfoMap listenerInfo;
249 client->eventListeners(info[0], listenerInfo); 248 client->eventListeners(info[0], listenerInfo);
250 249
251 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); 250 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate());
252 Vector<String> types; 251 protocol::Vector<String> types;
253 for (auto& it : listenerInfo) 252 for (auto& it : listenerInfo)
254 types.append(it.key); 253 types.append(it.first);
255 std::sort(types.begin(), types.end(), WTF::codePointCompareLessThan); 254 std::sort(types.begin(), types.end(), WTF::codePointCompareLessThan);
256 for (const String& type : types) { 255 for (const String& type : types) {
257 v8::Local<v8::Array> listeners = wrapListenerFunctions(info.GetIsolate() , *listenerInfo.get(type)); 256 v8::Local<v8::Array> listeners = wrapListenerFunctions(info.GetIsolate() , *listenerInfo.get(type));
258 if (!listeners->Length()) 257 if (!listeners->Length())
259 continue; 258 continue;
260 result->Set(toV8String(info.GetIsolate(), type), listeners); 259 result->Set(toV8String(info.GetIsolate(), type), listeners);
261 } 260 }
262 261
263 v8SetReturnValue(info, result); 262 v8SetReturnValue(info, result);
264 } 263 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 info.GetReturnValue().Set(toV8String(info.GetIsolate(), groupName)); 536 info.GetReturnValue().Set(toV8String(info.GetIsolate(), groupName));
538 } 537 }
539 538
540 v8::Local<v8::Symbol> V8Debugger::commandLineAPISymbol(v8::Isolate* isolate) 539 v8::Local<v8::Symbol> V8Debugger::commandLineAPISymbol(v8::Isolate* isolate)
541 { 540 {
542 return v8::Symbol::ForApi(isolate, toV8StringInternalized(isolate, "commandL ineAPI")); 541 return v8::Symbol::ForApi(isolate, toV8StringInternalized(isolate, "commandL ineAPI"));
543 } 542 }
544 543
545 bool V8Debugger::isCommandLineAPIMethod(const AtomicString& name) 544 bool V8Debugger::isCommandLineAPIMethod(const AtomicString& name)
546 { 545 {
547 DEFINE_STATIC_LOCAL(HashSet<String>, methods, ()); 546 DEFINE_STATIC_LOCAL(protocol::HashSet<String>, methods, ());
548 if (methods.size() == 0) { 547 if (methods.size() == 0) {
549 const char* members[] = { "$", "$$", "$x", "dir", "dirxml", "keys", "val ues", "profile", "profileEnd", 548 const char* members[] = { "$", "$$", "$x", "dir", "dirxml", "keys", "val ues", "profile", "profileEnd",
550 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "get EventListeners", 549 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "get EventListeners",
551 "debug", "undebug", "monitor", "unmonitor", "table", "$_", "$0", "$1 ", "$2", "$3", "$4" }; 550 "debug", "undebug", "monitor", "unmonitor", "table", "$_", "$0", "$1 ", "$2", "$3", "$4" };
552 for (size_t i = 0; i < sizeof(members) / sizeof(const char*); ++i) 551 for (size_t i = 0; i < sizeof(members) / sizeof(const char*); ++i)
553 methods.add(members[i]); 552 methods.add(members[i]);
554 } 553 }
555 return methods.find(name) != methods.end(); 554 return methods.find(name) != methods.end();
556 } 555 }
557 556
(...skipping 28 matching lines...) Expand all
586 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback}, 585 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback},
587 {"bind", V8InjectedScriptHost::bindCallback}, 586 {"bind", V8InjectedScriptHost::bindCallback},
588 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, 587 {"objectForId", V8InjectedScriptHost::objectForIdCallback},
589 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, 588 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback},
590 }; 589 };
591 590
592 } // namespace 591 } // namespace
593 592
594 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate) 593 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate)
595 { 594 {
596 Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH (V8InjectedScriptHostMethods)); 595 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR RAY_LENGTH(V8InjectedScriptHostMethods));
597 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); 596 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin());
598 Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; 597 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes;
599 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes); 598 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes);
600 } 599 }
601 600
602 v8::Local<v8::Object> V8InjectedScriptHost::wrap(V8DebuggerClient* client, v8::L ocal<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) 601 v8::Local<v8::Object> V8InjectedScriptHost::wrap(V8DebuggerClient* client, v8::L ocal<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host)
603 { 602 {
604 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context, host); 603 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context, host);
605 } 604 }
606 605
607 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) 606 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object)
608 { 607 {
609 return InjectedScriptHostWrapper::unwrap(context, object); 608 return InjectedScriptHostWrapper::unwrap(context, object);
610 } 609 }
611 610
612 } // namespace blink 611 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698