Skip to content

Commit 0ee66e7

Browse files
committed
implement setAttributeAsText when editting view attributes for calling through the inspector frontend
1 parent c85dd26 commit 0ee66e7

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

runtime/src/main/jni/v8_inspector/src/inspector/v8-dom-agent-impl.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,43 @@ namespace v8_inspector {
152152
*out_object = std::move(resolvedNode);
153153
}
154154

155-
void V8DOMAgentImpl::setAttributeValue(ErrorString *, int in_nodeId, const String &in_name,
155+
void V8DOMAgentImpl::setAttributeValue(ErrorString *errorString, int in_nodeId, const String &in_name,
156156
const String &in_value) {
157-
// TODO: Pete: call modules' View class methods to set view's attribute
157+
// Irrelevant
158158
}
159159

160-
void V8DOMAgentImpl::setAttributesAsText(ErrorString *, int in_nodeId, const String &in_text,
160+
void V8DOMAgentImpl::setAttributesAsText(ErrorString *errorString, int in_nodeId, const String &in_text,
161161
const Maybe<String> &in_name) {
162-
// TODO: Pete: call modules' View class methods to set view's attribute
162+
// call modules' View class methods to modify view's attribute
163+
// TODO: Pete: Find a better way to get a hold of the isolate
164+
std::string setAttributeAsTextFunctionString = "setAttributeAsText";
165+
auto isolate = v8::Isolate::GetCurrent();
166+
auto context = isolate->GetCurrentContext();
167+
auto global = context->Global();
168+
169+
auto globalInspectorObject = utils::Common::getGlobalInspectorObject(isolate);
170+
171+
if (!globalInspectorObject.IsEmpty()) {
172+
auto setAttributeAsText = globalInspectorObject->Get(ArgConverter::ConvertToV8String(isolate, setAttributeAsTextFunctionString));
173+
174+
if (!setAttributeAsText.IsEmpty() && setAttributeAsText->IsFunction()) {
175+
auto setAttributeAsTextFunc = setAttributeAsText.As<v8::Function>();
176+
v8::Local<v8::Value> args[] = { v8::Number::New(isolate, in_nodeId), ArgConverter::ConvertToV8String(isolate, in_text.utf8()), ArgConverter::ConvertToV8String(isolate, in_name.fromJust().utf8()) };
177+
v8::TryCatch tc;
178+
179+
setAttributeAsTextFunc->Call(context, global, 3, args);
180+
181+
if (tc.HasCaught()) {
182+
*errorString = utils::Common::getJSCallErrorMessage(setAttributeAsTextFunctionString, tc.Message()->Get()).c_str();
183+
}
184+
185+
return;
186+
}
187+
}
163188
}
164189

165-
void V8DOMAgentImpl::removeAttribute(ErrorString *, int in_nodeId, const String &in_name) {
166-
// TODO: Pete: call modules' View class methods to modify view's attribute
190+
void V8DOMAgentImpl::removeAttribute(ErrorString *errorString, int in_nodeId, const String &in_name) {
191+
// Irrelevant
167192
}
168193

169194
void V8DOMAgentImpl::performSearch(ErrorString *, const String &in_query,

0 commit comments

Comments
 (0)