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

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp

Issue 1924713002: [DevTools] Removed InjectedScriptHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-inspect-to-native
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
index bfaefe016730fc2f0a3aa5bab4199f94c00c5aaf..b324490216ab96cc5341a3dbbe89fe14541b094b 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
@@ -5,42 +5,55 @@
#include "platform/v8_inspector/V8InjectedScriptHost.h"
#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
-#include "platform/v8_inspector/InjectedScript.h"
-#include "platform/v8_inspector/InjectedScriptHost.h"
-#include "platform/v8_inspector/InspectorWrapper.h"
-#include "platform/v8_inspector/JavaScriptCallFrame.h"
+#include "platform/v8_inspector/InjectedScriptNative.h"
#include "platform/v8_inspector/V8Compat.h"
#include "platform/v8_inspector/V8DebuggerImpl.h"
#include "platform/v8_inspector/V8StringUtil.h"
#include "platform/v8_inspector/public/V8DebuggerClient.h"
#include "platform/v8_inspector/public/V8EventListenerInfo.h"
-#include "platform/v8_inspector/public/V8ToProtocolValue.h"
-#include <algorithm>
namespace blink {
namespace {
-template<typename CallbackInfo, typename S>
-inline void v8SetReturnValue(const CallbackInfo& info, const v8::Local<S> handle)
+void setFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8::Object> obj, const char* name, v8::FunctionCallback callback, v8::Local<v8::External> external)
{
- info.GetReturnValue().Set(handle);
+ v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate(), name);
+ v8::Local<v8::Function> func;
+ if (!v8::Function::New(context, callback, external).ToLocal(&func))
+ return;
+ func->SetName(funcName);
+ if (!obj->Set(context, funcName, func).FromMaybe(false))
+ return;
}
-template<typename CallbackInfo, typename S>
-inline void v8SetReturnValue(const CallbackInfo& info, v8::MaybeLocal<S> maybe)
+V8DebuggerImpl* unwrapDebugger(const v8::FunctionCallbackInfo<v8::Value>& info)
{
- if (LIKELY(!maybe.IsEmpty()))
- info.GetReturnValue().Set(maybe.ToLocalChecked());
+ ASSERT(!info.Data().IsEmpty());
+ ASSERT(info.Data()->IsExternal());
+ V8DebuggerImpl* debugger = static_cast<V8DebuggerImpl*>(info.Data().As<v8::External>()->Value());
+ ASSERT(debugger);
+ return debugger;
}
-template<typename CallbackInfo>
-inline void v8SetReturnValue(const CallbackInfo& info, bool value)
-{
- info.GetReturnValue().Set(value);
-}
+} // namespace
+v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> context, V8DebuggerImpl* debugger)
+{
+ v8::Isolate* isolate = debugger->isolate();
+ v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate);
+ v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugger);
+ setFunctionProperty(context, injectedScriptHost, "internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedScriptHost::isTypedArrayCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScriptHost::subtypeCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8InjectedScriptHost::collectionEntriesCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "getEventListeners", V8InjectedScriptHost::getEventListenersCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHost::bindCallback, debuggerExternal);
+ return injectedScriptHost;
}
void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -49,9 +62,7 @@ void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
return;
v8::Local<v8::Object> object = info[0].As<v8::Object>();
- v8::Local<v8::String> result = object->GetConstructorName();
-
- v8SetReturnValue(info, result);
+ info.GetReturnValue().Set(object->GetConstructorName());
}
void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -59,66 +70,60 @@ void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac
if (info.Length() < 1)
return;
- InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->GetCurrentContext(), info.Holder());
- if (!host->debugger())
- return;
- v8SetReturnValue(info, host->debugger()->client()->formatAccessorsAsProperties(info[0]));
+ info.GetReturnValue().Set(unwrapDebugger(info)->client()->formatAccessorsAsProperties(info[0]));
}
void V8InjectedScriptHost::isTypedArrayCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (info.Length() < 1)
return;
- v8SetReturnValue(info, info[0]->IsTypedArray());
+
+ info.GetReturnValue().Set(info[0]->IsTypedArray());
}
void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (info.Length() < 1)
return;
- v8::Isolate* isolate = info.GetIsolate();
+ v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Value> value = info[0];
if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "array"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "array"));
return;
}
if (value->IsDate()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "date"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "date"));
return;
}
if (value->IsRegExp()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "regexp"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp"));
return;
}
if (value->IsMap() || value->IsWeakMap()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "map"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "map"));
return;
}
if (value->IsSet() || value->IsWeakSet()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "set"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "set"));
return;
}
if (value->IsMapIterator() || value->IsSetIterator()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "iterator"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "iterator"));
return;
}
if (value->IsGeneratorObject()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "generator"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "generator"));
return;
}
if (value->IsNativeError()) {
- v8SetReturnValue(info, toV8StringInternalized(isolate, "error"));
+ info.GetReturnValue().Set(toV8StringInternalized(isolate, "error"));
return;
}
-
- InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->GetCurrentContext(), info.Holder());
- if (!host->debugger())
- return;
- String16 subtype = host->debugger()->client()->valueSubtype(value);
+ String16 subtype = unwrapDebugger(info)->client()->valueSubtype(value);
if (!subtype.isEmpty()) {
- v8SetReturnValue(info, toV8String(isolate, subtype));
+ info.GetReturnValue().Set(toV8String(isolate, subtype));
return;
}
}
@@ -128,12 +133,8 @@ void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI
if (info.Length() < 1 || !info[0]->IsObject())
return;
- v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
-
- InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->GetCurrentContext(), info.Holder());
- if (!host->debugger())
- return;
- v8SetReturnValue(info, host->debugger()->collectionEntries(object));
+ v8::Local<v8::Object> object = info[0].As<v8::Object>();
+ info.GetReturnValue().Set(unwrapDebugger(info)->collectionEntries(object));
}
void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -141,9 +142,10 @@ void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
if (info.Length() < 1 || !info[0]->IsObject())
return;
- v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
- v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info.GetIsolate(), object);
- v8SetReturnValue(info, properties);
+ v8::Local<v8::Object> object = info[0].As<v8::Object>();
+ v8::Local<v8::Array> properties;
+ if (v8::Debug::GetInternalProperties(info.GetIsolate(), object).ToLocal(&properties))
+ info.GetReturnValue().Set(properties);
}
static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const V8EventListenerInfoList& listeners, const String16& type)
@@ -168,10 +170,7 @@ void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
if (info.Length() < 1)
return;
- InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->GetCurrentContext(), info.Holder());
- if (!host->debugger())
- return;
- V8DebuggerClient* client = host->debugger()->client();
+ V8DebuggerClient* client = unwrapDebugger(info)->client();
V8EventListenerInfoList listenerInfo;
client->eventListeners(info[0], listenerInfo);
@@ -185,52 +184,47 @@ void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
continue;
result->Set(toV8String(info.GetIsolate(), it.first), listeners);
}
-
- v8SetReturnValue(info, result);
+ info.GetReturnValue().Set(result);
}
-void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) {
ASSERT_NOT_REACHED();
return;
}
-
- v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
- v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]);
- v8::Local<v8::Value> receiver = info[1];
-
- if (info.Length() < 3 || info[2]->IsUndefined()) {
- v8::Local<v8::Value> result = function->Call(receiver, 0, 0);
- v8SetReturnValue(info, result);
- return;
- }
-
- if (!info[2]->IsArray()) {
+ if (info.Length() > 2 && (!info[2]->IsArray() && !info[2]->IsUndefined())) {
ASSERT_NOT_REACHED();
return;
}
- v8::Local<v8::Array> arguments = v8::Local<v8::Array>::Cast(info[2]);
- size_t argc = arguments->Length();
- OwnPtr<v8::Local<v8::Value>[]> argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]);
- for (size_t i = 0; i < argc; ++i) {
- if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer::New(info.GetIsolate(), i)).ToLocal(&argv[i]))
- return;
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
+ v8::Local<v8::Function> function = info[0].As<v8::Function>();
+ v8::Local<v8::Value> receiver = info[1];
+ OwnPtr<v8::Local<v8::Value>[]> argv = nullptr;
+ size_t argc = 0;
+
+ if (info.Length() > 2 && info[2]->IsArray()) {
+ v8::Local<v8::Array> arguments = info[2].As<v8::Array>();
+ argc = arguments->Length();
+ argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]);
+ for (size_t i = 0; i < argc; ++i) {
+ if (!arguments->Get(context, i).ToLocal(&argv[i]))
+ return;
+ }
}
- v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get());
- v8SetReturnValue(info, result);
-}
+ V8DebuggerClient* client = unwrapDebugger(info)->client();
+ client->muteWarningsAndDeprecations();
-void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
-{
- InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->GetCurrentContext(), info.Holder());
- if (!host->debugger())
- return;
- host->debugger()->client()->muteWarningsAndDeprecations();
- callFunctionCallback(info);
- host->debugger()->client()->unmuteWarningsAndDeprecations();
+ v8::MicrotasksScope microtasks(isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
+ v8::Local<v8::Value> result;
+ if (function->Call(context, receiver, argc, argv.get()).ToLocal(&result))
+ info.GetReturnValue().Set(result);
+
+ client->unmuteWarningsAndDeprecations();
}
void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -267,44 +261,4 @@ bool V8Debugger::isRemoteObjectAPIMethod(const String16& name)
return name == "bindRemoteObject";
}
-namespace {
-
-char hiddenPropertyName[] = "v8inspector::InjectedScriptHost";
-char className[] = "V8InjectedScriptHost";
-using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPropertyName, className>;
-
-const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMethods[] = {
- {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback},
- {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsProperties},
- {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback},
- {"subtype", V8InjectedScriptHost::subtypeCallback},
- {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback},
- {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallback},
- {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback},
- {"callFunction", V8InjectedScriptHost::callFunctionCallback},
- {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback},
- {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback},
- {"bind", V8InjectedScriptHost::bindCallback}
-};
-
-} // namespace
-
-v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::Isolate* isolate)
-{
- protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH(V8InjectedScriptHostMethods));
- std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARRAY_LENGTH(V8InjectedScriptHostMethods), methods.begin());
- protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes;
- return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, attributes);
-}
-
-v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host)
-{
- return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host);
-}
-
-InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object)
-{
- return InjectedScriptHostWrapper::unwrap(context, object);
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698