Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: namespace usage #1810

Merged
merged 3 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

#include "ArgConverter.h"
#include "Util.h"
#include "Utils.h"

using namespace std;
using namespace tns;
using namespace v8;

using namespace v8_inspector;
using namespace inspector;

// Utility functions for converting between inspector StringView and UTF8 string

Expand Down Expand Up @@ -164,7 +166,7 @@ void JsV8InspectorClient::dispatchMessage(const std::string& message) {
if(!arg.IsEmpty() && arg->IsObject()) {
Local<Object> domainDebugger;
Local<Object> argObject = arg.As<Object>();
Local<v8::Function> domainMethodFunc = tns::Util::GetDebuggerFunctionFromObject(context, argObject, domainDebugger);
Local<v8::Function> domainMethodFunc = GetDebuggerFunctionFromObject(context, argObject, domainDebugger);

Local<Value> result;
success = this->CallDomainHandlerFunction(context, domainMethodFunc, argObject, domainDebugger, result);
Expand Down
74 changes: 37 additions & 37 deletions test-app/runtime/src/main/cpp/v8_inspector/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@

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>();
}


Local<v8::Function>
tns::inspector::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>();
}

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);
}
Isolate *isolate = context->GetIsolate();
domainDebugger = it->second->Get(isolate);

return Local<v8::Function>();
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>
tns::inspector::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>();
}
4 changes: 2 additions & 2 deletions test-app/runtime/src/main/cpp/v8_inspector/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace tns {
namespace inspector {
static v8::Local<v8::Function> GetDebuggerFunctionFromObject(v8::Local<v8::Context> context,
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>
v8::Local<v8::Function>
GetDebuggerFunction(v8::Local<v8::Context> context, std::string domain,
std::string functionName, v8::Local<v8::Object> &domainDebugger);
}
Expand Down
Loading