Skip to content

Commit 1da865b

Browse files
committed
add removeNode command for calling through the inspector frontend
1 parent 6d6547c commit 1da865b

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

runtime/src/main/jni/v8_inspector/src/inspector/v8-css-agent-impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace v8_inspector {
157157

158158
if (!getComputedStylesForNode.IsEmpty() && getComputedStylesForNode->IsFunction()) {
159159
auto getComputedStylesForNodeFunc = getComputedStylesForNode.As<v8::Function>();
160-
v8::Local<v8::Value> args[] = {v8::Number::New(isolate, in_nodeId)};
160+
v8::Local<v8::Value> args[] = { v8::Number::New(isolate, in_nodeId) };
161161
auto maybeResult = getComputedStylesForNodeFunc->Call(context, global, 1, args);
162162
v8::Local<v8::Value> outResult;
163163

runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,32 @@ namespace v8_inspector {
9898
}
9999
}
100100
}
101+
101102
*out_root = std::move(defaultNode);
102103
}
103104

104-
void V8DOMAgentImpl::removeNode(ErrorString*, int in_nodeId) {
105-
// TODO: Pete: call modules' View class methods to remove view from parent view
105+
void V8DOMAgentImpl::removeNode(ErrorString *errorString, int in_nodeId) {
106+
auto removeNodeFunctionString = "removeNode";
107+
// TODO: Pete: Find a better way to get a hold of the isolate
108+
auto isolate = v8::Isolate::GetCurrent();
109+
auto context = isolate->GetCurrentContext();
110+
auto global = context->Global();
111+
112+
auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate);
113+
114+
if (!globalInspectorObject.IsEmpty()) {
115+
auto removeNode = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, removeNodeFunctionString));
116+
117+
if (!removeNode.IsEmpty() && removeNode->IsFunction()) {
118+
auto removeNodeFunc = removeNode.As<v8::Function>();
119+
v8::Local<v8::Value> args[] = { v8::Number::New(isolate, in_nodeId) };
120+
removeNodeFunc->Call(context, global, 1, args);
121+
122+
return;
123+
}
124+
}
125+
126+
*errorString = "Couldn't remove the selected DOMNode from the visual tree.";
106127
}
107128

108129
// Pete: return empty resolved object - prevents crashes when opening the 'properties', 'event listeners' tabs
@@ -114,8 +135,6 @@ namespace v8_inspector {
114135
*out_object = std::move(resolvedNode);
115136
}
116137

117-
V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0;
118-
119138
void V8DOMAgentImpl::setAttributeValue(ErrorString *, int in_nodeId, const String &in_name,
120139
const String &in_value) {
121140
// TODO: Pete: call modules' View class methods to set view's attribute
@@ -156,4 +175,6 @@ namespace v8_inspector {
156175
void V8DOMAgentImpl::hideHighlight(ErrorString *) {
157176

158177
}
178+
179+
V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0;
159180
}

0 commit comments

Comments
 (0)