Skip to content

Commit 35689a7

Browse files
committed
fix: Restore DOM and Network callback handlers
This restores the JS functions that were used to implement the DOM and Network inspector domains. The functions do nothing, but they are present so that using the corresponding UI features in the inspector doesn't crash.
1 parent 3e6070c commit 35689a7

File tree

6 files changed

+494
-492
lines changed

6 files changed

+494
-492
lines changed

test-app/runtime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
7171
INSPECTOR_SOURCES
7272

7373
src/main/cpp/com_tns_AndroidJsV8Inspector.cpp
74+
src/main/cpp/DOMDomainCallbackHandlers.cpp
7475
src/main/cpp/JsV8InspectorClient.cpp
76+
src/main/cpp/NetworkDomainCallbackHandlers.cpp
7577
)
7678
else ()
7779
# When building in Release mode we do not include the V8 inspector sources

test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.cpp

Lines changed: 159 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -2,184 +2,184 @@
22
// Created by pkanev on 5/10/2017.
33
//
44

5-
#include <sstream>
6-
#include <ArgConverter.h>
7-
#include <NativeScriptAssert.h>
5+
// #include <sstream>
6+
// #include <ArgConverter.h>
7+
// #include <NativeScriptAssert.h>
88

9-
#include <v8_inspector/src/inspector/protocol/Protocol.h>
10-
#include <v8_inspector/src/inspector/string-util.h>
11-
#include <v8_inspector/third_party/inspector_protocol/crdtp/error_support.h>
12-
#include <v8_inspector/third_party/inspector_protocol/crdtp/json.h>
9+
// #include <v8_inspector/src/inspector/protocol/Protocol.h>
10+
// #include <v8_inspector/src/inspector/string-util.h>
11+
// #include <v8_inspector/third_party/inspector_protocol/crdtp/error_support.h>
12+
// #include <v8_inspector/third_party/inspector_protocol/crdtp/json.h>
1313

1414
#include "DOMDomainCallbackHandlers.h"
1515

1616
using namespace tns;
1717

1818
void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19-
auto domAgentInstance = DOMAgentImpl::Instance;
19+
// auto domAgentInstance = DOMAgentImpl::Instance;
2020

21-
if (!domAgentInstance) {
22-
return;
23-
}
21+
// if (!domAgentInstance) {
22+
// return;
23+
// }
2424

25-
domAgentInstance->m_frontend.documentUpdated();
25+
// domAgentInstance->m_frontend.documentUpdated();
2626
}
2727

2828
void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
29-
try {
30-
auto domAgentInstance = DOMAgentImpl::Instance;
31-
32-
if (!domAgentInstance) {
33-
return;
34-
}
35-
36-
auto isolate = args.GetIsolate();
37-
38-
v8::HandleScope scope(isolate);
39-
40-
if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsString())) {
41-
throw NativeScriptException("Calling ChildNodeInserted with invalid arguments. Required params: parentId: number, lastId: number, node: JSON String");
42-
}
43-
44-
auto context = isolate->GetCurrentContext();
45-
auto parentId = args[0]->ToNumber(context).ToLocalChecked();
46-
auto lastId = args[1]->ToNumber(context).ToLocalChecked();
47-
auto node = args[2]->ToString(context).ToLocalChecked();
48-
49-
auto resultString = DOMAgentImpl::AddBackendNodeIdProperty(isolate, node);
50-
auto nodeUtf16Data = resultString.data();
51-
const v8_inspector::String16& nodeString16 = v8_inspector::String16((const uint16_t*) nodeUtf16Data);
52-
std::vector<uint8_t> cbor;
53-
v8_crdtp::json::ConvertJSONToCBOR(v8_crdtp::span<uint16_t>(nodeString16.characters16(), nodeString16.length()), &cbor);
54-
std::unique_ptr<protocol::Value> protocolNodeJson = protocol::Value::parseBinary(cbor.data(), cbor.size());
55-
56-
v8_crdtp::ErrorSupport errorSupport;
57-
auto domNode = protocol::DOM::Node::fromValue(protocolNodeJson.get(), &errorSupport);
58-
59-
std::vector<uint8_t> json;
60-
v8_crdtp::json::ConvertCBORToJSON(errorSupport.Errors(), &json);
61-
auto errorSupportString = String16(reinterpret_cast<const char*>(json.data()), json.size()).utf8();
62-
if (!errorSupportString.empty()) {
63-
auto errorMessage = "Error while parsing debug `DOM Node` object. ";
64-
DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str());
65-
return;
66-
}
67-
68-
domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(context).ToChecked(), lastId->Int32Value(context).ToChecked(), std::move(domNode));
69-
} catch (NativeScriptException& e) {
70-
e.ReThrowToV8();
71-
} catch (std::exception e) {
72-
std::stringstream ss;
73-
ss << "Error: c exception: " << e.what() << std::endl;
74-
NativeScriptException nsEx(ss.str());
75-
nsEx.ReThrowToV8();
76-
} catch (...) {
77-
NativeScriptException nsEx(std::string("Error: c exception!"));
78-
nsEx.ReThrowToV8();
79-
}
29+
// try {
30+
// auto domAgentInstance = DOMAgentImpl::Instance;
31+
32+
// if (!domAgentInstance) {
33+
// return;
34+
// }
35+
36+
// auto isolate = args.GetIsolate();
37+
38+
// v8::HandleScope scope(isolate);
39+
40+
// if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsString())) {
41+
// throw NativeScriptException("Calling ChildNodeInserted with invalid arguments. Required params: parentId: number, lastId: number, node: JSON String");
42+
// }
43+
44+
// auto context = isolate->GetCurrentContext();
45+
// auto parentId = args[0]->ToNumber(context).ToLocalChecked();
46+
// auto lastId = args[1]->ToNumber(context).ToLocalChecked();
47+
// auto node = args[2]->ToString(context).ToLocalChecked();
48+
49+
// auto resultString = DOMAgentImpl::AddBackendNodeIdProperty(isolate, node);
50+
// auto nodeUtf16Data = resultString.data();
51+
// const v8_inspector::String16& nodeString16 = v8_inspector::String16((const uint16_t*) nodeUtf16Data);
52+
// std::vector<uint8_t> cbor;
53+
// v8_crdtp::json::ConvertJSONToCBOR(v8_crdtp::span<uint16_t>(nodeString16.characters16(), nodeString16.length()), &cbor);
54+
// std::unique_ptr<protocol::Value> protocolNodeJson = protocol::Value::parseBinary(cbor.data(), cbor.size());
55+
56+
// v8_crdtp::ErrorSupport errorSupport;
57+
// auto domNode = protocol::DOM::Node::fromValue(protocolNodeJson.get(), &errorSupport);
58+
59+
// std::vector<uint8_t> json;
60+
// v8_crdtp::json::ConvertCBORToJSON(errorSupport.Errors(), &json);
61+
// auto errorSupportString = String16(reinterpret_cast<const char*>(json.data()), json.size()).utf8();
62+
// if (!errorSupportString.empty()) {
63+
// auto errorMessage = "Error while parsing debug `DOM Node` object. ";
64+
// DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str());
65+
// return;
66+
// }
67+
68+
// domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(context).ToChecked(), lastId->Int32Value(context).ToChecked(), std::move(domNode));
69+
// } catch (NativeScriptException& e) {
70+
// e.ReThrowToV8();
71+
// } catch (std::exception e) {
72+
// std::stringstream ss;
73+
// ss << "Error: c exception: " << e.what() << std::endl;
74+
// NativeScriptException nsEx(ss.str());
75+
// nsEx.ReThrowToV8();
76+
// } catch (...) {
77+
// NativeScriptException nsEx(std::string("Error: c exception!"));
78+
// nsEx.ReThrowToV8();
79+
// }
8080
}
8181

8282
void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
83-
try {
84-
auto domAgentInstance = DOMAgentImpl::Instance;
85-
86-
if (!domAgentInstance) {
87-
return;
88-
}
89-
90-
auto isolate = args.GetIsolate();
91-
92-
v8::HandleScope scope(isolate);
93-
94-
if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsNumber())) {
95-
throw NativeScriptException("Calling ChildNodeRemoved with invalid arguments. Required params: parentId: number, nodeId: number");
96-
}
97-
98-
auto context = isolate->GetCurrentContext();
99-
auto parentId = args[0]->ToNumber(context).ToLocalChecked();
100-
auto nodeId = args[1]->ToNumber(context).ToLocalChecked();
101-
102-
domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(context).ToChecked(), nodeId->Int32Value(context).ToChecked());
103-
} catch (NativeScriptException& e) {
104-
e.ReThrowToV8();
105-
} catch (std::exception e) {
106-
std::stringstream ss;
107-
ss << "Error: c exception: " << e.what() << std::endl;
108-
NativeScriptException nsEx(ss.str());
109-
nsEx.ReThrowToV8();
110-
} catch (...) {
111-
NativeScriptException nsEx(std::string("Error: c exception!"));
112-
nsEx.ReThrowToV8();
113-
}
83+
// try {
84+
// auto domAgentInstance = DOMAgentImpl::Instance;
85+
86+
// if (!domAgentInstance) {
87+
// return;
88+
// }
89+
90+
// auto isolate = args.GetIsolate();
91+
92+
// v8::HandleScope scope(isolate);
93+
94+
// if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsNumber())) {
95+
// throw NativeScriptException("Calling ChildNodeRemoved with invalid arguments. Required params: parentId: number, nodeId: number");
96+
// }
97+
98+
// auto context = isolate->GetCurrentContext();
99+
// auto parentId = args[0]->ToNumber(context).ToLocalChecked();
100+
// auto nodeId = args[1]->ToNumber(context).ToLocalChecked();
101+
102+
// domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(context).ToChecked(), nodeId->Int32Value(context).ToChecked());
103+
// } catch (NativeScriptException& e) {
104+
// e.ReThrowToV8();
105+
// } catch (std::exception e) {
106+
// std::stringstream ss;
107+
// ss << "Error: c exception: " << e.what() << std::endl;
108+
// NativeScriptException nsEx(ss.str());
109+
// nsEx.ReThrowToV8();
110+
// } catch (...) {
111+
// NativeScriptException nsEx(std::string("Error: c exception!"));
112+
// nsEx.ReThrowToV8();
113+
// }
114114
}
115115

116116
void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
117-
try {
118-
auto domAgentInstance = DOMAgentImpl::Instance;
119-
120-
if (!domAgentInstance) {
121-
return;
122-
}
123-
124-
auto isolate = args.GetIsolate();
125-
126-
v8::HandleScope scope(isolate);
127-
128-
if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsString() && args[2]->IsString())) {
129-
throw NativeScriptException("Calling AttributeModified with invalid arguments. Required params: nodeId: number, name: string, value: string");
130-
}
131-
132-
auto context = isolate->GetCurrentContext();
133-
auto nodeId = args[0]->ToNumber(context).ToLocalChecked();
134-
auto attributeName = args[1]->ToString(context).ToLocalChecked();
135-
auto attributeValue = args[2]->ToString(context).ToLocalChecked();
136-
137-
domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(context).ToChecked(),
138-
v8_inspector::toProtocolString(isolate, attributeName),
139-
v8_inspector::toProtocolString(isolate, attributeValue));
140-
} catch (NativeScriptException& e) {
141-
e.ReThrowToV8();
142-
} catch (std::exception e) {
143-
std::stringstream ss;
144-
ss << "Error: c exception: " << e.what() << std::endl;
145-
NativeScriptException nsEx(ss.str());
146-
nsEx.ReThrowToV8();
147-
} catch (...) {
148-
NativeScriptException nsEx(std::string("Error: c exception!"));
149-
nsEx.ReThrowToV8();
150-
}
117+
// try {
118+
// auto domAgentInstance = DOMAgentImpl::Instance;
119+
120+
// if (!domAgentInstance) {
121+
// return;
122+
// }
123+
124+
// auto isolate = args.GetIsolate();
125+
126+
// v8::HandleScope scope(isolate);
127+
128+
// if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsString() && args[2]->IsString())) {
129+
// throw NativeScriptException("Calling AttributeModified with invalid arguments. Required params: nodeId: number, name: string, value: string");
130+
// }
131+
132+
// auto context = isolate->GetCurrentContext();
133+
// auto nodeId = args[0]->ToNumber(context).ToLocalChecked();
134+
// auto attributeName = args[1]->ToString(context).ToLocalChecked();
135+
// auto attributeValue = args[2]->ToString(context).ToLocalChecked();
136+
137+
// domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(context).ToChecked(),
138+
// v8_inspector::toProtocolString(isolate, attributeName),
139+
// v8_inspector::toProtocolString(isolate, attributeValue));
140+
// } catch (NativeScriptException& e) {
141+
// e.ReThrowToV8();
142+
// } catch (std::exception e) {
143+
// std::stringstream ss;
144+
// ss << "Error: c exception: " << e.what() << std::endl;
145+
// NativeScriptException nsEx(ss.str());
146+
// nsEx.ReThrowToV8();
147+
// } catch (...) {
148+
// NativeScriptException nsEx(std::string("Error: c exception!"));
149+
// nsEx.ReThrowToV8();
150+
// }
151151
}
152152

153153
void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
154-
try {
155-
auto domAgentInstance = DOMAgentImpl::Instance;
156-
157-
if (!domAgentInstance) {
158-
return;
159-
}
160-
auto isolate = args.GetIsolate();
161-
162-
v8::HandleScope scope(isolate);
163-
164-
if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsString())) {
165-
throw NativeScriptException("Calling AttributeRemoved with invalid arguments. Required params: nodeId: number, name: string");
166-
}
167-
168-
auto context = isolate->GetCurrentContext();
169-
auto nodeId = args[0]->ToNumber(context).ToLocalChecked();
170-
auto attributeName = args[1]->ToString(context).ToLocalChecked();
171-
172-
domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(context).ToChecked(),
173-
v8_inspector::toProtocolString(isolate, attributeName));
174-
} catch (NativeScriptException& e) {
175-
e.ReThrowToV8();
176-
} catch (std::exception e) {
177-
std::stringstream ss;
178-
ss << "Error: c exception: " << e.what() << std::endl;
179-
NativeScriptException nsEx(ss.str());
180-
nsEx.ReThrowToV8();
181-
} catch (...) {
182-
NativeScriptException nsEx(std::string("Error: c exception!"));
183-
nsEx.ReThrowToV8();
184-
}
154+
// try {
155+
// auto domAgentInstance = DOMAgentImpl::Instance;
156+
157+
// if (!domAgentInstance) {
158+
// return;
159+
// }
160+
// auto isolate = args.GetIsolate();
161+
162+
// v8::HandleScope scope(isolate);
163+
164+
// if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsString())) {
165+
// throw NativeScriptException("Calling AttributeRemoved with invalid arguments. Required params: nodeId: number, name: string");
166+
// }
167+
168+
// auto context = isolate->GetCurrentContext();
169+
// auto nodeId = args[0]->ToNumber(context).ToLocalChecked();
170+
// auto attributeName = args[1]->ToString(context).ToLocalChecked();
171+
172+
// domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(context).ToChecked(),
173+
// v8_inspector::toProtocolString(isolate, attributeName));
174+
// } catch (NativeScriptException& e) {
175+
// e.ReThrowToV8();
176+
// } catch (std::exception e) {
177+
// std::stringstream ss;
178+
// ss << "Error: c exception: " << e.what() << std::endl;
179+
// NativeScriptException nsEx(ss.str());
180+
// nsEx.ReThrowToV8();
181+
// } catch (...) {
182+
// NativeScriptException nsEx(std::string("Error: c exception!"));
183+
// nsEx.ReThrowToV8();
184+
// }
185185
}

test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#define DOMDOMAINCALLBACKHANDLERS_H
77

88
#include <include/v8.h>
9-
#include "DOMAgentImpl.h"
10-
#include "JsV8InspectorClient.h"
11-
#include "NativeScriptException.h"
9+
// #include "DOMAgentImpl.h"
10+
// #include "JsV8InspectorClient.h"
11+
// #include "NativeScriptException.h"
1212

1313
namespace tns {
1414
class DOMDomainCallbackHandlers {

0 commit comments

Comments
 (0)