Skip to content

Commit

Permalink
chore: move devtools only calls into inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Apr 7, 2024
1 parent 1470796 commit 5ab81d3
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 48 deletions.
1 change: 1 addition & 0 deletions test-app/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
src/main/cpp/com_tns_AndroidJsV8Inspector.cpp
src/main/cpp/JsV8InspectorClient.cpp
src/main/cpp/v8_inspector/ns-v8-tracing-agent-impl.cpp
src/main/cpp/v8_inspector/Utils.cpp
)
else ()
# When building in Release mode we do not include the V8 inspector sources
Expand Down
2 changes: 0 additions & 2 deletions test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,6 @@ void JsV8InspectorClient::InspectorIsConnectedGetterCallback(v8::Local<v8::Strin
JsV8InspectorClient* JsV8InspectorClient::instance = nullptr;




bool JsV8InspectorClient::CallDomainHandlerFunction(Local<Context> context, Local<Function> domainMethodFunc, const Local<Object>& arg, Local<Object>& domainDebugger, Local<Value>& result) {
if(domainMethodFunc.IsEmpty() || !domainMethodFunc->IsFunction()) {
return false;
Expand Down
1 change: 0 additions & 1 deletion test-app/runtime/src/main/cpp/JsV8InspectorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class JsV8InspectorClient : V8InspectorClient, v8_inspector::V8Inspector::Channe
void runMessageLoopOnPause(int context_group_id) override;
void quitMessageLoopOnPause() override;

static void attachInspectorCallbacks(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& globalObjectTemplate);
static bool inspectorIsConnected() {
return JsV8InspectorClient::GetInstance()->isConnected_;
}
Expand Down
37 changes: 0 additions & 37 deletions test-app/runtime/src/main/cpp/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,41 +440,4 @@ namespace tns {
std::vector<uint16_t> vector(begin, end);
return vector;
}


Local<v8::Function> Util::GetDebuggerFunction(Local<Context> context, std::string domain, std::string functionName, Local<Object>& domainDebugger) {
auto it = JsV8InspectorClient::Domains.find(domain);
if (it == JsV8InspectorClient::Domains.end()) {
return Local<v8::Function>();
}

Isolate* isolate = context->GetIsolate();
domainDebugger = it->second->Get(isolate);

Local<Value> value;
auto funcName = v8::String::NewFromUtf8(isolate, functionName.c_str(), v8::NewStringType::kNormal, (int)functionName.length()).ToLocalChecked();
bool success = domainDebugger->Get(context, funcName).ToLocal(&value);
if (success && !value.IsEmpty() && value->IsFunction()) {
return value.As<v8::Function>();
}

return Local<v8::Function>();
}

Local<v8::Function> Util::GetDebuggerFunctionFromObject(Local<Context> context, const Local<Object>& object, Local<Object>& domainDebugger) {
Isolate* isolate = context->GetIsolate();
auto methodKey = v8::String::NewFromUtf8(isolate, "method", v8::NewStringType::kNormal).ToLocalChecked();
auto method = object->Get(context, methodKey).ToLocalChecked();
auto methodString = ToString(isolate, method);
auto domainSeparatorIndex = methodString.find(".");
auto domain = methodString.substr(0, domainSeparatorIndex);
auto domainMethod = methodString.substr(domainSeparatorIndex + 1, methodString.size());

if(domain.size() > 0) {
return GetDebuggerFunction(context, domain, domainMethod, domainDebugger);
}

return Local<v8::Function>();
}

};
8 changes: 0 additions & 8 deletions test-app/runtime/src/main/cpp/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ class Util {
return std::string(*result, result.length());
}


static v8::Local<v8::Function> GetDebuggerFunctionFromObject(v8::Local<v8::Context> context,
const v8::Local<v8::Object> &object,
v8::Local<v8::Object> &domainDebugger);

static v8::Local<v8::Function>
GetDebuggerFunction(v8::Local<v8::Context> context, std::string domain,
std::string functionName, v8::Local<v8::Object> &domainDebugger);
};


Expand Down
50 changes: 50 additions & 0 deletions test-app/runtime/src/main/cpp/v8_inspector/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "Utils.h"
#include "JsV8InspectorClient.h"
#include "Util.h"

using namespace v8;
using namespace std;
namespace tns {

Local <v8::Function>
GetDebuggerFunction(Local <Context> context, std::string domain, std::string functionName,
Local <Object> &domainDebugger) {
auto it = JsV8InspectorClient::Domains.find(domain);
if (it == JsV8InspectorClient::Domains.end()) {
return Local<v8::Function>();
}

Isolate *isolate = context->GetIsolate();
domainDebugger = it->second->Get(isolate);

Local <Value> value;
auto funcName = v8::String::NewFromUtf8(isolate, functionName.c_str(),
v8::NewStringType::kNormal,
(int) functionName.length()).ToLocalChecked();
bool success = domainDebugger->Get(context, funcName).ToLocal(&value);
if (success && !value.IsEmpty() && value->IsFunction()) {
return value.As<v8::Function>();
}

return Local<v8::Function>();
}

Local <v8::Function>
GetDebuggerFunctionFromObject(Local <Context> context, const Local <Object> &object,
Local <Object> &domainDebugger) {
Isolate *isolate = context->GetIsolate();
auto methodKey = v8::String::NewFromUtf8(isolate, "method",
v8::NewStringType::kNormal).ToLocalChecked();
auto method = object->Get(context, methodKey).ToLocalChecked();
auto methodString = Util::ToString(isolate, method);
auto domainSeparatorIndex = methodString.find(".");
auto domain = methodString.substr(0, domainSeparatorIndex);
auto domainMethod = methodString.substr(domainSeparatorIndex + 1, methodString.size());

if (domain.size() > 0) {
return GetDebuggerFunction(context, domain, domainMethod, domainDebugger);
}

return Local<v8::Function>();
}
}
21 changes: 21 additions & 0 deletions test-app/runtime/src/main/cpp/v8_inspector/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <string>
#include <vector>

#ifndef UTILS_H_
#define UTILS_H_

#include "include/v8-inspector.h"

namespace tns {
namespace inspector {
static v8::Local<v8::Function> GetDebuggerFunctionFromObject(v8::Local<v8::Context> context,
const v8::Local<v8::Object> &object,
v8::Local<v8::Object> &domainDebugger);

static v8::Local<v8::Function>
GetDebuggerFunction(v8::Local<v8::Context> context, std::string domain,
std::string functionName, v8::Local<v8::Object> &domainDebugger);
}
}

#endif /* UTILS_H_ */

0 comments on commit 5ab81d3

Please sign in to comment.