diff --git a/runtime/src/main/jni/ArgConverter.cpp b/runtime/src/main/jni/ArgConverter.cpp index 41be1b0fe..d6e6a2a45 100644 --- a/runtime/src/main/jni/ArgConverter.cpp +++ b/runtime/src/main/jni/ArgConverter.cpp @@ -244,6 +244,17 @@ string ArgConverter::ConvertToString(const v8::Local& s) { } } +u16string ArgConverter::ConvertToUtf16String(const v8::Local& s) { + if (s.IsEmpty()) { + return u16string(); + } else { + auto str = ConvertToString(s); + auto utf16str = Util::ConvertFromUtf8ToUtf16(str); + + return utf16str; + } +} + jstring ArgConverter::ConvertToJavaString(const Local& value) { JEnv env; String::Value stringValue(value); @@ -263,5 +274,18 @@ Local ArgConverter::ConvertToV8String(Isolate* isolate, const char* data return String::NewFromUtf8(isolate, (const char*) data, String::kNormalString, length); } +Local ArgConverter::ConvertToV8UTF16String(Isolate* isolate, const string& string) { + auto utf16str = Util::ConvertFromUtf8ToUtf16(string); + + return ConvertToV8UTF16String(isolate, utf16str); +} + +Local ArgConverter::ConvertToV8UTF16String(Isolate* isolate, const u16string& utf16string) { + return String::NewFromTwoByte(isolate, ((const uint16_t*) utf16string.data())); +} + +Local ArgConverter::ConvertToV8UTF16String(v8::Isolate* isolate, const uint16_t* utf16string, int size) { + return String::NewFromTwoByte(isolate, utf16string, NewStringType::kNormal, size).ToLocalChecked(); +} std::map ArgConverter::s_type_long_operations_cache; \ No newline at end of file diff --git a/runtime/src/main/jni/ArgConverter.h b/runtime/src/main/jni/ArgConverter.h index 0c7105240..a7d439296 100644 --- a/runtime/src/main/jni/ArgConverter.h +++ b/runtime/src/main/jni/ArgConverter.h @@ -30,6 +30,8 @@ class ArgConverter { static std::string ConvertToString(const v8::Local& s); + static std::u16string ConvertToUtf16String(const v8::Local& s); + static jstring ConvertToJavaString(const v8::Local& jsValue); static v8::Local ConvertToV8String(v8::Isolate* isolate, const jchar* data, int length); @@ -38,6 +40,12 @@ class ArgConverter { static v8::Local ConvertToV8String(v8::Isolate* isolate, const char* data, int length); + static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const std::string& string); + + static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const uint16_t* utf16string, int size); + + static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const std::u16string& utf16string); + private: // TODO: plamen5kov: rewrite logic for java long number operations in javascript (java long -> javascript number operations check) diff --git a/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp b/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp index f06cee3e4..fe4cecf0a 100644 --- a/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp +++ b/runtime/src/main/jni/DOMDomainCallbackHandlers.cpp @@ -9,7 +9,7 @@ using namespace tns; -void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallbackInfo &args) { +void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallbackInfo& args) { auto domAgentInstance = V8DOMAgentImpl::Instance; if (!domAgentInstance) { @@ -19,7 +19,7 @@ void DOMDomainCallbackHandlers::DocumentUpdatedCallback(const v8::FunctionCallba domAgentInstance->m_frontend.documentUpdated(); } -void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCallbackInfo &args) { +void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCallbackInfo& args) { try { auto domAgentInstance = V8DOMAgentImpl::Instance; @@ -39,9 +39,7 @@ void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCall auto lastId = args[1]->ToNumber(isolate); auto node = args[2]->ToString(isolate); - auto nodeString = ArgConverter::ConvertToString(node); - auto nodeCStr = nodeString.c_str(); - auto nodeJson = protocol::parseJSON(nodeCStr); + auto nodeJson = protocol::parseJSON(v8_inspector::toProtocolString(node)); protocol::ErrorSupport errorSupport; auto domNode = protocol::DOM::Node::parse(nodeJson.get(), &errorSupport); @@ -66,7 +64,7 @@ void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCall } } -void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallbackInfo &args) { +void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallbackInfo& args) { try { auto domAgentInstance = V8DOMAgentImpl::Instance; @@ -99,7 +97,7 @@ void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallb } } -void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo &args) { +void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo& args) { try { auto domAgentInstance = V8DOMAgentImpl::Instance; @@ -119,9 +117,9 @@ void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCall auto attributeName = args[1]->ToString(); auto attributeValue = args[2]->ToString(); - domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(), - ArgConverter::ConvertToString(attributeName).c_str(), - ArgConverter::ConvertToString(attributeValue).c_str()); + domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(), + v8_inspector::toProtocolString(attributeName), + v8_inspector::toProtocolString(attributeValue)); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { @@ -135,7 +133,7 @@ void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCall } } -void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo &args) { +void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo& args) { try { auto domAgentInstance = V8DOMAgentImpl::Instance; @@ -154,7 +152,7 @@ void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallb auto attributeName = args[1]->ToString(); domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(), - ArgConverter::ConvertToString(attributeName).c_str()); + v8_inspector::toProtocolString(attributeName)); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { diff --git a/runtime/src/main/jni/NetworkDomainCallbackHandlers.cpp b/runtime/src/main/jni/NetworkDomainCallbackHandlers.cpp index 6cf4a572d..0e6d1b828 100644 --- a/runtime/src/main/jni/NetworkDomainCallbackHandlers.cpp +++ b/runtime/src/main/jni/NetworkDomainCallbackHandlers.cpp @@ -49,9 +49,9 @@ void NetworkDomainCallbackHandlers::ResponseReceivedCallback(const v8::FunctionC throw NativeScriptException("`response` parameter not in the correct format."); } - auto responseJsonString = ArgConverter::ConvertToString(responseJson); - auto responseJsonCString = responseJsonString.c_str(); - auto protocolResponseJson = protocol::parseJSON(responseJsonCString); + auto responseJsonString = ArgConverter::ConvertToUtf16String(responseJson); + auto responseUtf16Data = responseJsonString.data(); + auto protocolResponseJson = protocol::parseJSON(String16((const uint16_t*) responseUtf16Data)); protocol::ErrorSupport errorSupport; @@ -133,9 +133,9 @@ void NetworkDomainCallbackHandlers::RequestWillBeSentCallback(const v8::Function throw NativeScriptException("`request` parameter not in the correct format."); } - auto requestJsonString = ArgConverter::ConvertToString(requestJson); - auto requestJsonCString = requestJsonString.c_str(); - auto protocolRequestJson = protocol::parseJSON(requestJsonCString); + auto requestJsonString = ArgConverter::ConvertToUtf16String(requestJson); + auto requestUtf16Data = requestJsonString.data(); + auto protocolRequestJson = protocol::parseJSON(String16((const uint16_t*) requestUtf16Data)); protocol::ErrorSupport errorSupport; @@ -207,7 +207,7 @@ void NetworkDomainCallbackHandlers::DataForRequestIdCallback(const v8::FunctionC auto hasTextContent = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "hasTextContent")).ToLocalChecked()->ToBoolean(); auto requestIdString = ArgConverter::ConvertToString(requestId).c_str(); - auto dataString = ArgConverter::ConvertToString(data); + auto dataString = ArgConverter::ConvertToUtf16String(data); auto hasTextContentBool = hasTextContent->BooleanValue(); auto responses = networkAgentInstance->m_responses; @@ -219,11 +219,7 @@ void NetworkDomainCallbackHandlers::DataForRequestIdCallback(const v8::FunctionC } else { v8_inspector::utils::NetworkRequestData* response = it->second; - if (!hasTextContentBool) { - response->setData(dataString); - } else { - response->setData(ArgConverter::ConvertToString(data)); - } + response->setData(dataString); response->setHasTextContent(hasTextContentBool); } diff --git a/runtime/src/main/jni/Util.cpp b/runtime/src/main/jni/Util.cpp index 0aeac3cf3..9a896e208 100644 --- a/runtime/src/main/jni/Util.cpp +++ b/runtime/src/main/jni/Util.cpp @@ -1,5 +1,7 @@ #include "Util.h" #include +#include +#include using namespace v8; using namespace std; @@ -77,28 +79,34 @@ bool Util::EndsWith(const string& str, const string& suffix) { return res; } -string Util::ConvertFromJniToCanonicalName(const std::string& name) { +string Util::ConvertFromJniToCanonicalName(const string& name) { string converted = name; replace(converted.begin(), converted.end(), '/', '.'); return converted; } -string Util::ConvertFromCanonicalToJniName(const std::string& name) { +string Util::ConvertFromCanonicalToJniName(const string& name) { string converted = name; replace(converted.begin(), converted.end(), '.', '/'); return converted; } -string Util::ReplaceAll(std::string& str, const std::string& from, const std::string& to) { +string Util::ReplaceAll(string& str, const string& from, const string& to) { if (from.empty()) { return str; } size_t start_pos = 0; - while ((start_pos = str.find(from, start_pos)) != std::string::npos) { + while ((start_pos = str.find(from, start_pos)) != string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); } return str; +} + +u16string Util::ConvertFromUtf8ToUtf16(const string& str) { + auto utf16String = std::wstring_convert, char16_t>().from_bytes(str); + + return utf16String; } \ No newline at end of file diff --git a/runtime/src/main/jni/Util.h b/runtime/src/main/jni/Util.h index d06505c88..4fc7898b8 100644 --- a/runtime/src/main/jni/Util.h +++ b/runtime/src/main/jni/Util.h @@ -19,6 +19,8 @@ class Util { static std::string ConvertFromCanonicalToJniName(const std::string& name); static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to); + + static std::u16string ConvertFromUtf8ToUtf16(const std::string& str); }; } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.cpp index 60cdafb91..611391182 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.cpp +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.cpp @@ -7,9 +7,9 @@ namespace v8_inspector { namespace utils { NetworkRequestData::NetworkRequestData() - : m_data(""), + : m_data(), m_hasTextContent(true) { } -NetworkRequestData::NetworkRequestData(std::string data, bool hasTextContent) +NetworkRequestData::NetworkRequestData(std::u16string data, bool hasTextContent) : m_data(data), m_hasTextContent(hasTextContent) { } } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.h b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.h index 1cafabfc0..684863580 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.h +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-network-request-data.h @@ -13,16 +13,16 @@ namespace utils { class NetworkRequestData { public: NetworkRequestData(); - NetworkRequestData(std::string data, bool hasTextContent); - const char* getData() { - return m_data.c_str(); + NetworkRequestData(std::u16string data, bool hasTextContent); + const char16_t* getData() { + return m_data.data(); }; const bool hasTextContent() { return m_hasTextContent; } - void setData(const std::string& data) { + void setData(const std::u16string& data) { m_data = data; } @@ -31,7 +31,7 @@ class NetworkRequestData { } private: - std::string m_data; + std::u16string m_data; bool m_hasTextContent; }; } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.cpp index 8d3923eb3..af3bb9698 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.cpp +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "base64.h" #include "v8_inspector/src/inspector/utils/v8-page-resources.h" #include "JEnv.h" @@ -19,7 +20,7 @@ namespace utils { PageResource::PageResource(std::string filePath, std::string mimeType) : m_filePath(filePath), m_mimeType(mimeType), - m_content("") { + m_content() { m_type = PageResource::resourceTypeByMimeType(m_mimeType); } @@ -82,15 +83,17 @@ String16 PageResource::getContent(protocol::ErrorString* errorString) { if (shouldEncode) { auto base64EncodedString = base64_encode(buff, size); - m_content = base64EncodedString; + m_content = tns::Util::ConvertFromUtf8ToUtf16(base64EncodedString); } else { - m_content = std::string(reinterpret_cast(buff)); + auto utf8Content = std::string(reinterpret_cast(buff)); + auto utf16Content = tns::Util::ConvertFromUtf8ToUtf16(utf8Content); + m_content = utf16Content; } free(buff); } - return m_content.c_str(); + return String16((const uint16_t*) m_content.data()); } const char* PageResource::resourceTypeByMimeType(std::string mimeType) { diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.h b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.h index ba760fd90..d89d22f46 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.h +++ b/runtime/src/main/jni/v8_inspector/src/inspector/utils/v8-page-resources.h @@ -46,7 +46,7 @@ class PageResource { private: std::string m_filePath; std::string m_mimeType; - std::string m_content; + std::u16string m_content; const char* m_type; static std::map s_mimeTypeMap; diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp index 6e6c6b822..c81341cc7 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp @@ -10,218 +10,225 @@ namespace v8_inspector { - using tns::Runtime; - using tns::ArgConverter; +using tns::Runtime; +using tns::ArgConverter; - namespace DOMAgentState { - static const char domEnabled[] = "domEnabled"; - } +namespace DOMAgentState { +static const char domEnabled[] = "domEnabled"; +} - V8DOMAgentImpl::V8DOMAgentImpl(V8InspectorSessionImpl *session, - protocol::FrontendChannel *frontendChannel, - protocol::DictionaryValue *state) - : m_session(session), - m_frontend(frontendChannel), - m_state(state), - m_enabled(false) { - Instance = this; - } +V8DOMAgentImpl::V8DOMAgentImpl(V8InspectorSessionImpl* session, + protocol::FrontendChannel* frontendChannel, + protocol::DictionaryValue* state) + : m_session(session), + m_frontend(frontendChannel), + m_state(state), + m_enabled(false) { + Instance = this; +} - V8DOMAgentImpl::~V8DOMAgentImpl() { } +V8DOMAgentImpl::~V8DOMAgentImpl() { } - void V8DOMAgentImpl::enable(ErrorString*) { - if (m_enabled) { - return; - } +void V8DOMAgentImpl::enable(ErrorString*) { + if (m_enabled) { + return; + } - m_state->setBoolean(DOMAgentState::domEnabled, true); + m_state->setBoolean(DOMAgentState::domEnabled, true); - m_enabled = true; + m_enabled = true; +} + +void V8DOMAgentImpl::disable(ErrorString*) { + if (!m_enabled) { + return; } - void V8DOMAgentImpl::disable(ErrorString*) { - if (!m_enabled) { - return; - } + m_state->setBoolean(DOMAgentState::domEnabled, false); - m_state->setBoolean(DOMAgentState::domEnabled, false); + m_enabled = false; +} - m_enabled = false; - } +void V8DOMAgentImpl::getDocument(ErrorString* errorString, std::unique_ptr* out_root) { + std::unique_ptr defaultNode = protocol::DOM::Node::create() + .setNodeId(0) + .setNodeType(9) + .setNodeName("Frame") + .setLocalName("Frame") + .setNodeValue("") + .build(); - void V8DOMAgentImpl::getDocument(ErrorString *errorString, std::unique_ptr* out_root) { - std::unique_ptr defaultNode = protocol::DOM::Node::create() - .setNodeId(0) - .setNodeType(9) - .setNodeName("Frame") - .setLocalName("Frame") - .setNodeValue("") - .build(); + std::string getDocumentFunctionString = "getDocument"; + // TODO: Pete: Find a better way to get a hold of the isolate + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); - std::string getDocumentFunctionString = "getDocument"; - // TODO: Pete: Find a better way to get a hold of the isolate - auto isolate = v8::Isolate::GetCurrent(); - auto context = isolate->GetCurrentContext(); - auto global = context->Global(); + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); - auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + if (!globalInspectorObject.IsEmpty()) { + auto getDocument = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, getDocumentFunctionString)); - if (!globalInspectorObject.IsEmpty()) { - auto getDocument = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, getDocumentFunctionString)); + if (!getDocument.IsEmpty() && getDocument->IsFunction()) { + auto getDocumentFunc = getDocument.As(); + v8::Local args[] = { }; + v8::TryCatch tc; - if (!getDocument.IsEmpty() && getDocument->IsFunction()) { - auto getDocumentFunc = getDocument.As(); - v8::Local args[] = { }; - v8::TryCatch tc; + auto maybeResult = getDocumentFunc->Call(context, global, 0, args); - auto maybeResult = getDocumentFunc->Call(context, global, 0, args); + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(getDocumentFunctionString, tc.Message()->Get()).c_str(); - if (tc.HasCaught()) { - *errorString = utils::Common::getJSCallErrorMessage(getDocumentFunctionString, tc.Message()->Get()).c_str(); + *out_root = std::move(defaultNode); + return; + } - *out_root = std::move(defaultNode); - return; - } + v8::Local outResult; - v8::Local outResult; + if (maybeResult.ToLocal(&outResult)) { + auto resultString = ArgConverter::ConvertToUtf16String(outResult->ToString()); - if (maybeResult.ToLocal(&outResult)) { - auto resultString = ArgConverter::ConvertToString(outResult->ToString()); - auto resultCStr = resultString.c_str(); - auto resultJson = protocol::parseJSON(resultCStr); + auto resultUtf16Data = resultString.data(); - protocol::ErrorSupport errorSupport; - auto domNode = protocol::DOM::Node::parse(resultJson.get(), &errorSupport); + auto resultJson = protocol::parseJSON(String16((const uint16_t*) resultUtf16Data)); - auto errorSupportString = errorSupport.errors().utf8(); - *errorString = errorSupportString.c_str(); - if (!errorSupportString.empty()) { - auto errorMessage = "Error while parsing debug `DOM Node` object. "; - DEBUG_WRITE_FORCE("JS Error: %s", errorMessage, errorSupportString.c_str()); - } else { - *out_root = std::move(domNode); + protocol::ErrorSupport errorSupport; + auto domNode = protocol::DOM::Node::parse(resultJson.get(), &errorSupport); - return; - } + auto errorSupportString = errorSupport.errors().utf8(); + *errorString = errorSupportString.c_str(); + if (!errorSupportString.empty()) { + auto errorMessage = "Error while parsing debug `DOM Node` object. "; + DEBUG_WRITE_FORCE("JS Error: %s", errorMessage, errorSupportString.c_str()); } else { - *errorString = "Didn't get a proper result from __getDocument call. Returning empty visual tree."; + *out_root = std::move(domNode); + + return; } + } else { + *errorString = "Didn't get a proper result from __getDocument call. Returning empty visual tree."; } } - - *out_root = std::move(defaultNode); } - void V8DOMAgentImpl::removeNode(ErrorString *errorString, int in_nodeId) { - std::string removeNodeFunctionString = "removeNode"; + *out_root = std::move(defaultNode); +} - // TODO: Pete: Find a better way to get a hold of the isolate - auto isolate = v8::Isolate::GetCurrent(); - auto context = isolate->GetCurrentContext(); - auto global = context->Global(); +void V8DOMAgentImpl::removeNode(ErrorString* errorString, int in_nodeId) { + std::string removeNodeFunctionString = "removeNode"; - auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + // TODO: Pete: Find a better way to get a hold of the isolate + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); - if (!globalInspectorObject.IsEmpty()) { - auto removeNode = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, removeNodeFunctionString)); + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); - if (!removeNode.IsEmpty() && removeNode->IsFunction()) { - auto removeNodeFunc = removeNode.As(); - v8::Local args[] = { v8::Number::New(isolate, in_nodeId) }; - v8::TryCatch tc; + if (!globalInspectorObject.IsEmpty()) { + auto removeNode = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, removeNodeFunctionString)); - removeNodeFunc->Call(context, global, 1, args); + if (!removeNode.IsEmpty() && removeNode->IsFunction()) { + auto removeNodeFunc = removeNode.As(); + v8::Local args[] = { v8::Number::New(isolate, in_nodeId) }; + v8::TryCatch tc; - if (tc.HasCaught()) { - *errorString = utils::Common::getJSCallErrorMessage(removeNodeFunctionString, tc.Message()->Get()).c_str(); - } + removeNodeFunc->Call(context, global, 1, args); - return; + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(removeNodeFunctionString, tc.Message()->Get()).c_str(); } - } - - *errorString = "Couldn't remove the selected DOMNode from the visual tree."; - } - - // Pete: return empty resolved object - prevents crashes when opening the 'properties', 'event listeners' tabs - // Not supported - void V8DOMAgentImpl::resolveNode(ErrorString*, int in_nodeId, const Maybe& in_objectGroup, std::unique_ptr* out_object) { - auto resolvedNode = protocol::Runtime::RemoteObject::create() - .setType("View") - .build(); - *out_object = std::move(resolvedNode); - } - - void V8DOMAgentImpl::setAttributeValue(ErrorString *errorString, int in_nodeId, const String &in_name, - const String &in_value) { - // Irrelevant + return; + } } - void V8DOMAgentImpl::setAttributesAsText(ErrorString *errorString, int in_nodeId, const String &in_text, - const Maybe &in_name) { - // call modules' View class methods to modify view's attribute - // TODO: Pete: Find a better way to get a hold of the isolate - std::string setAttributeAsTextFunctionString = "setAttributeAsText"; - auto isolate = v8::Isolate::GetCurrent(); - auto context = isolate->GetCurrentContext(); - auto global = context->Global(); - - auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); - - if (!globalInspectorObject.IsEmpty()) { - auto setAttributeAsText = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, setAttributeAsTextFunctionString)); + *errorString = "Couldn't remove the selected DOMNode from the visual tree."; +} - if (!setAttributeAsText.IsEmpty() && setAttributeAsText->IsFunction()) { - auto setAttributeAsTextFunc = setAttributeAsText.As(); - v8::Local args[] = { v8::Number::New(isolate, in_nodeId), ArgConverter::ConvertToV8String(isolate, in_text.utf8()), ArgConverter::ConvertToV8String(isolate, in_name.fromJust().utf8()) }; - v8::TryCatch tc; +// Pete: return empty resolved object - prevents crashes when opening the 'properties', 'event listeners' tabs +// Not supported +void V8DOMAgentImpl::resolveNode(ErrorString*, int in_nodeId, const Maybe& in_objectGroup, std::unique_ptr* out_object) { + auto resolvedNode = protocol::Runtime::RemoteObject::create() + .setType("View") + .build(); - setAttributeAsTextFunc->Call(context, global, 3, args); + *out_object = std::move(resolvedNode); +} - if (tc.HasCaught()) { - *errorString = utils::Common::getJSCallErrorMessage(setAttributeAsTextFunctionString, tc.Message()->Get()).c_str(); - } +void V8DOMAgentImpl::setAttributeValue(ErrorString* errorString, int in_nodeId, const String& in_name, + const String& in_value) { + // Irrelevant +} - return; +void V8DOMAgentImpl::setAttributesAsText(ErrorString* errorString, int in_nodeId, const String& in_text, + const Maybe& in_name) { + // call modules' View class methods to modify view's attribute + // TODO: Pete: Find a better way to get a hold of the isolate + std::string setAttributeAsTextFunctionString = "setAttributeAsText"; + auto isolate = v8::Isolate::GetCurrent(); + auto context = isolate->GetCurrentContext(); + auto global = context->Global(); + + auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate); + + if (!globalInspectorObject.IsEmpty()) { + auto setAttributeAsText = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, setAttributeAsTextFunctionString)); + + if (!setAttributeAsText.IsEmpty() && setAttributeAsText->IsFunction()) { + auto setAttributeAsTextFunc = setAttributeAsText.As(); + // TODO: Pete: Setting the content to contain utf-16 characters will still output garbage + v8::Local args[] = { + v8::Number::New(isolate, in_nodeId), + v8_inspector::toV8String(isolate, in_text), + v8_inspector::toV8String(isolate, in_name.fromJust()) + }; + v8::TryCatch tc; + + setAttributeAsTextFunc->Call(context, global, 3, args); + + if (tc.HasCaught()) { + *errorString = utils::Common::getJSCallErrorMessage(setAttributeAsTextFunctionString, tc.Message()->Get()).c_str(); } + + return; } } +} - void V8DOMAgentImpl::removeAttribute(ErrorString *errorString, int in_nodeId, const String &in_name) { - // Irrelevant - } +void V8DOMAgentImpl::removeAttribute(ErrorString* errorString, int in_nodeId, const String& in_name) { + // Irrelevant +} - // Not supported - void V8DOMAgentImpl::performSearch(ErrorString *, const String &in_query, - const Maybe> &in_nodeIds, - String *out_searchId, int *out_resultCount) { +// Not supported +void V8DOMAgentImpl::performSearch(ErrorString*, const String& in_query, + const Maybe>& in_nodeIds, + String* out_searchId, int* out_resultCount) { - } +} - // Not supported - void V8DOMAgentImpl::getSearchResults(ErrorString *, const String &in_searchId, int in_fromIndex, - int in_toIndex, - std::unique_ptr> *out_nodeIds) { +// Not supported +void V8DOMAgentImpl::getSearchResults(ErrorString*, const String& in_searchId, int in_fromIndex, + int in_toIndex, + std::unique_ptr>* out_nodeIds) { - } +} - // Not supported - void V8DOMAgentImpl::discardSearchResults(ErrorString *, const String &in_searchId) { +// Not supported +void V8DOMAgentImpl::discardSearchResults(ErrorString*, const String& in_searchId) { - } +} - // Not supported - void V8DOMAgentImpl::highlightNode(ErrorString *, - std::unique_ptr in_highlightConfig, - const Maybe &in_nodeId, - const Maybe &in_objectId) { +// Not supported +void V8DOMAgentImpl::highlightNode(ErrorString*, + std::unique_ptr in_highlightConfig, + const Maybe& in_nodeId, + const Maybe& in_objectId) { - } +} - void V8DOMAgentImpl::hideHighlight(ErrorString *) { +void V8DOMAgentImpl::hideHighlight(ErrorString*) { - } +} - V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0; +V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0; } diff --git a/runtime/src/main/jni/v8_inspector/src/inspector/v8-network-agent-impl.cpp b/runtime/src/main/jni/v8_inspector/src/inspector/v8-network-agent-impl.cpp index 383af4c33..db56a175a 100644 --- a/runtime/src/main/jni/v8_inspector/src/inspector/v8-network-agent-impl.cpp +++ b/runtime/src/main/jni/v8_inspector/src/inspector/v8-network-agent-impl.cpp @@ -55,7 +55,7 @@ void V8NetworkAgentImpl::getResponseBody(ErrorString* errorString, const String& *errorString = "Response not found for requestId = " + in_requestId; } else { v8_inspector::utils::NetworkRequestData* response = it->second; - *out_body = response->getData(); + *out_body = String16((const uint16_t*) response->getData()); *out_base64Encoded = !response->hasTextContent(); } }