Skip to content

Commit f0b3c58

Browse files
authoredApr 7, 2024··
chore: move devtool only calls into inspector (#1809)
1 parent 1470796 commit f0b3c58

File tree

7 files changed

+72
-48
lines changed

7 files changed

+72
-48
lines changed
 

‎test-app/runtime/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
7272
src/main/cpp/com_tns_AndroidJsV8Inspector.cpp
7373
src/main/cpp/JsV8InspectorClient.cpp
7474
src/main/cpp/v8_inspector/ns-v8-tracing-agent-impl.cpp
75+
src/main/cpp/v8_inspector/Utils.cpp
7576
)
7677
else ()
7778
# When building in Release mode we do not include the V8 inspector sources

‎test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ void JsV8InspectorClient::InspectorIsConnectedGetterCallback(v8::Local<v8::Strin
417417
JsV8InspectorClient* JsV8InspectorClient::instance = nullptr;
418418

419419

420-
421-
422420
bool JsV8InspectorClient::CallDomainHandlerFunction(Local<Context> context, Local<Function> domainMethodFunc, const Local<Object>& arg, Local<Object>& domainDebugger, Local<Value>& result) {
423421
if(domainMethodFunc.IsEmpty() || !domainMethodFunc->IsFunction()) {
424422
return false;

‎test-app/runtime/src/main/cpp/JsV8InspectorClient.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class JsV8InspectorClient : V8InspectorClient, v8_inspector::V8Inspector::Channe
3939
void runMessageLoopOnPause(int context_group_id) override;
4040
void quitMessageLoopOnPause() override;
4141

42-
static void attachInspectorCallbacks(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& globalObjectTemplate);
4342
static bool inspectorIsConnected() {
4443
return JsV8InspectorClient::GetInstance()->isConnected_;
4544
}

‎test-app/runtime/src/main/cpp/Util.cpp

-37
Original file line numberDiff line numberDiff line change
@@ -440,41 +440,4 @@ namespace tns {
440440
std::vector<uint16_t> vector(begin, end);
441441
return vector;
442442
}
443-
444-
445-
Local<v8::Function> Util::GetDebuggerFunction(Local<Context> context, std::string domain, std::string functionName, Local<Object>& domainDebugger) {
446-
auto it = JsV8InspectorClient::Domains.find(domain);
447-
if (it == JsV8InspectorClient::Domains.end()) {
448-
return Local<v8::Function>();
449-
}
450-
451-
Isolate* isolate = context->GetIsolate();
452-
domainDebugger = it->second->Get(isolate);
453-
454-
Local<Value> value;
455-
auto funcName = v8::String::NewFromUtf8(isolate, functionName.c_str(), v8::NewStringType::kNormal, (int)functionName.length()).ToLocalChecked();
456-
bool success = domainDebugger->Get(context, funcName).ToLocal(&value);
457-
if (success && !value.IsEmpty() && value->IsFunction()) {
458-
return value.As<v8::Function>();
459-
}
460-
461-
return Local<v8::Function>();
462-
}
463-
464-
Local<v8::Function> Util::GetDebuggerFunctionFromObject(Local<Context> context, const Local<Object>& object, Local<Object>& domainDebugger) {
465-
Isolate* isolate = context->GetIsolate();
466-
auto methodKey = v8::String::NewFromUtf8(isolate, "method", v8::NewStringType::kNormal).ToLocalChecked();
467-
auto method = object->Get(context, methodKey).ToLocalChecked();
468-
auto methodString = ToString(isolate, method);
469-
auto domainSeparatorIndex = methodString.find(".");
470-
auto domain = methodString.substr(0, domainSeparatorIndex);
471-
auto domainMethod = methodString.substr(domainSeparatorIndex + 1, methodString.size());
472-
473-
if(domain.size() > 0) {
474-
return GetDebuggerFunction(context, domain, domainMethod, domainDebugger);
475-
}
476-
477-
return Local<v8::Function>();
478-
}
479-
480443
};

‎test-app/runtime/src/main/cpp/Util.h

-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ class Util {
4848
return std::string(*result, result.length());
4949
}
5050

51-
52-
static v8::Local<v8::Function> GetDebuggerFunctionFromObject(v8::Local<v8::Context> context,
53-
const v8::Local<v8::Object> &object,
54-
v8::Local<v8::Object> &domainDebugger);
55-
56-
static v8::Local<v8::Function>
57-
GetDebuggerFunction(v8::Local<v8::Context> context, std::string domain,
58-
std::string functionName, v8::Local<v8::Object> &domainDebugger);
5951
};
6052

6153

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "Utils.h"
2+
#include "JsV8InspectorClient.h"
3+
#include "Util.h"
4+
5+
using namespace v8;
6+
using namespace std;
7+
namespace tns {
8+
9+
Local <v8::Function>
10+
GetDebuggerFunction(Local <Context> context, std::string domain, std::string functionName,
11+
Local <Object> &domainDebugger) {
12+
auto it = JsV8InspectorClient::Domains.find(domain);
13+
if (it == JsV8InspectorClient::Domains.end()) {
14+
return Local<v8::Function>();
15+
}
16+
17+
Isolate *isolate = context->GetIsolate();
18+
domainDebugger = it->second->Get(isolate);
19+
20+
Local <Value> value;
21+
auto funcName = v8::String::NewFromUtf8(isolate, functionName.c_str(),
22+
v8::NewStringType::kNormal,
23+
(int) functionName.length()).ToLocalChecked();
24+
bool success = domainDebugger->Get(context, funcName).ToLocal(&value);
25+
if (success && !value.IsEmpty() && value->IsFunction()) {
26+
return value.As<v8::Function>();
27+
}
28+
29+
return Local<v8::Function>();
30+
}
31+
32+
Local <v8::Function>
33+
GetDebuggerFunctionFromObject(Local <Context> context, const Local <Object> &object,
34+
Local <Object> &domainDebugger) {
35+
Isolate *isolate = context->GetIsolate();
36+
auto methodKey = v8::String::NewFromUtf8(isolate, "method",
37+
v8::NewStringType::kNormal).ToLocalChecked();
38+
auto method = object->Get(context, methodKey).ToLocalChecked();
39+
auto methodString = Util::ToString(isolate, method);
40+
auto domainSeparatorIndex = methodString.find(".");
41+
auto domain = methodString.substr(0, domainSeparatorIndex);
42+
auto domainMethod = methodString.substr(domainSeparatorIndex + 1, methodString.size());
43+
44+
if (domain.size() > 0) {
45+
return GetDebuggerFunction(context, domain, domainMethod, domainDebugger);
46+
}
47+
48+
return Local<v8::Function>();
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <string>
2+
#include <vector>
3+
4+
#ifndef UTILS_H_
5+
#define UTILS_H_
6+
7+
#include "include/v8-inspector.h"
8+
9+
namespace tns {
10+
namespace inspector {
11+
static v8::Local<v8::Function> GetDebuggerFunctionFromObject(v8::Local<v8::Context> context,
12+
const v8::Local<v8::Object> &object,
13+
v8::Local<v8::Object> &domainDebugger);
14+
15+
static v8::Local<v8::Function>
16+
GetDebuggerFunction(v8::Local<v8::Context> context, std::string domain,
17+
std::string functionName, v8::Local<v8::Object> &domainDebugger);
18+
}
19+
}
20+
21+
#endif /* UTILS_H_ */

0 commit comments

Comments
 (0)
Please sign in to comment.