Skip to content

Commit c85dd26

Browse files
committed
expose attributeRemoved and attributeModified on the __inspector object
1 parent f8c0c19 commit c85dd26

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

runtime/src/main/jni/DOMDomainCallbackHandlers.cpp

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,70 @@ void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallb
100100
}
101101

102102
void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
103-
auto domAgentInstance = V8DOMAgentImpl::Instance;
103+
try {
104+
auto domAgentInstance = V8DOMAgentImpl::Instance;
104105

105-
if (!domAgentInstance) {
106-
return;
106+
if (!domAgentInstance) {
107+
return;
108+
}
109+
110+
auto isolate = args.GetIsolate();
111+
112+
v8::HandleScope scope(isolate);
113+
114+
if (args.Length() != 3 || !(args[0]->IsNumber() && args[1]->IsString() && args[2]->IsString())) {
115+
throw NativeScriptException("Calling AttributeModified with invalid arguments. Required params: nodeId: number, name: string, value: string");
116+
}
117+
118+
auto nodeId = args[0]->ToNumber(isolate);
119+
auto attributeName = args[1]->ToString();
120+
auto attributeValue = args[2]->ToString();
121+
122+
domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(),
123+
ArgConverter::ConvertToString(attributeName).c_str(),
124+
ArgConverter::ConvertToString(attributeValue).c_str());
125+
} catch (NativeScriptException& e) {
126+
e.ReThrowToV8();
127+
} catch (std::exception e) {
128+
std::stringstream ss;
129+
ss << "Error: c exception: " << e.what() << std::endl;
130+
NativeScriptException nsEx(ss.str());
131+
nsEx.ReThrowToV8();
132+
} catch (...) {
133+
NativeScriptException nsEx(std::string("Error: c exception!"));
134+
nsEx.ReThrowToV8();
107135
}
136+
}
137+
138+
void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value> &args) {
139+
try {
140+
auto domAgentInstance = V8DOMAgentImpl::Instance;
141+
142+
if (!domAgentInstance) {
143+
return;
144+
}
145+
auto isolate = args.GetIsolate();
146+
147+
v8::HandleScope scope(isolate);
148+
149+
if (args.Length() != 2 || !(args[0]->IsNumber() && args[1]->IsString())) {
150+
throw NativeScriptException("Calling AttributeRemoved with invalid arguments. Required params: nodeId: number, name: string");
151+
}
108152

153+
auto nodeId = args[0]->ToNumber(isolate);
154+
auto attributeName = args[1]->ToString();
109155

110-
// domAgentInstance->m_frontend.attributeModified();
111-
}
156+
domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(),
157+
ArgConverter::ConvertToString(attributeName).c_str());
158+
} catch (NativeScriptException& e) {
159+
e.ReThrowToV8();
160+
} catch (std::exception e) {
161+
std::stringstream ss;
162+
ss << "Error: c exception: " << e.what() << std::endl;
163+
NativeScriptException nsEx(ss.str());
164+
nsEx.ReThrowToV8();
165+
} catch (...) {
166+
NativeScriptException nsEx(std::string("Error: c exception!"));
167+
nsEx.ReThrowToV8();
168+
}
169+
}

runtime/src/main/jni/DOMDomainCallbackHandlers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace tns {
1818
static void ChildNodeInsertedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
1919
static void ChildNodeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
2020
static void AttributeModifiedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
21+
static void AttributeRemovedCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
2122
};
2223
}
2324

runtime/src/main/jni/JsV8InspectorClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ void JsV8InspectorClient::attachInspectorCallbacks(Isolate* isolate,
277277
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeInserted"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeInsertedCallback));
278278
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeRemovedCallback));
279279
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeModified"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeModifiedCallback));
280+
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeRemovedCallback));
280281

281282
globalObjectTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorJSObject);
282283
}

0 commit comments

Comments
 (0)