• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "webview_javascript_result_callback.h"
16 
17 #include <sys/mman.h>
18 #include <unistd.h>
19 
20 #include "webview_log.h"
21 #include "ohos_adapter_helper.h"
22 
23 #define MAX_FLOWBUF_DATA_SIZE 52428800 /* 50MB */
24 #define MAX_ENTRIES 10
25 #define HEADER_SIZE (MAX_ENTRIES * 8)  /* 10 * (int position + int length) */
26 #define INDEX_SIZE 2
27 
28 using namespace OHOS::NWeb;
29 
30 namespace OHOS::Webview {
31 
32 std::unordered_map<int32_t, WebviewJavaScriptResultCallBackImpl*> g_webviewJsResultCallbackMap;
33 std::mutex g_objectMtx;
34 
vectorEqual(const std::vector<std::string> & v1,const std::vector<std::string> & v2)35 bool vectorEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2)
36 {
37     if (v1.size() != v2.size()) {
38         return false;
39     }
40     int size = static_cast<int>(v1.size());
41     for (int i = 0; i < size; i++) {
42         if (v1[i] != v2[i]) {
43             return false;
44         }
45     }
46     return true;
47 }
48 
WebviewJavaScriptResultCallBackImpl(int32_t nwebId)49 WebviewJavaScriptResultCallBackImpl::WebviewJavaScriptResultCallBackImpl(int32_t nwebId) : nwebId_(nwebId)
50 {
51     std::unique_lock<std::mutex> lk(g_objectMtx);
52     g_webviewJsResultCallbackMap.emplace(nwebId, this);
53 }
54 
~WebviewJavaScriptResultCallBackImpl()55 WebviewJavaScriptResultCallBackImpl::~WebviewJavaScriptResultCallBackImpl()
56 {
57     std::unique_lock<std::mutex> lk(g_objectMtx);
58     g_webviewJsResultCallbackMap.erase(nwebId_);
59 }
60 
FindObjectIdInJsTd(const std::vector<std::function<char * (const char *)>> & cjFuncs,const std::vector<std::string> & methodList,JavaScriptOb::ObjectID & objectId)61 bool WebviewJavaScriptResultCallBackImpl::FindObjectIdInJsTd(
62     const std::vector<std::function<char*(const char*)>>& cjFuncs,
63     const std::vector<std::string>& methodList, JavaScriptOb::ObjectID& objectId)
64 {
65     objectId = static_cast<JavaScriptOb::ObjectID>(JavaScriptOb::JavaScriptObjIdErrorCode::WEBVIEWCONTROLLERERROR);
66     for (const auto& pair : objects_) {
67         bool result;
68         if (pair.second == nullptr) {
69             result = false;
70         } else {
71             result = (pair.second->GetFuncs().size() == cjFuncs.size())
72                 && vectorEqual(pair.second->GetMethodNames(), methodList);
73         }
74         if (result) {
75             objectId = pair.first;
76             return true;
77         }
78     }
79     return false;
80 }
81 
AddObject(const std::vector<std::function<char * (const char *)>> & cjFuncs)82 JavaScriptOb::ObjectID WebviewJavaScriptResultCallBackImpl::AddObject(
83     const std::vector<std::function<char*(const char*)>>& cjFuncs)
84 {
85     JavaScriptOb::ObjectID objectId;
86     {
87         auto new_object = JavaScriptOb::CreateNamed(cjFuncs);
88         objectId = nextObjectId_++;
89         WEBVIEWLOGD("WebviewJavaScriptResultCallBackImpl::AddObject objectId = "
90                 "%{public}d",
91             static_cast<int32_t>(objectId));
92         objects_[objectId] = new_object;
93     }
94     return objectId;
95 }
96 
AddNamedObject(const std::vector<std::function<char * (const char *)>> & cjFuncs,const std::vector<std::string> & methodList,const std::string & objName)97 JavaScriptOb::ObjectID WebviewJavaScriptResultCallBackImpl::AddNamedObject(
98     const std::vector<std::function<char*(const char*)>>& cjFuncs,
99     const std::vector<std::string>& methodList, const std::string& objName)
100 {
101     JavaScriptOb::ObjectID objectId;
102     NamedObjectMap::iterator iter = namedObjects_.find(objName);
103     bool methodName = FindObjectIdInJsTd(cjFuncs, methodList, objectId);
104     if (methodName && iter != namedObjects_.end() && iter->second == objectId) {
105         // Nothing to do.
106         return objectId;
107     }
108     if (iter != namedObjects_.end()) {
109         RemoveNamedObject(iter->first);
110     }
111     if (methodName && objects_[objectId] != nullptr) {
112         objects_[objectId]->AddName();
113     } else {
114         objectId = AddObject(cjFuncs);
115     }
116     namedObjects_[objName] = objectId;
117     return objectId;
118 }
119 
RemoveNamedObject(const std::string & name)120 bool WebviewJavaScriptResultCallBackImpl::RemoveNamedObject(const std::string& name)
121 {
122     WEBVIEWLOGD("WebviewJavaScriptResultCallBackImpl::RemoveNamedObject called, "
123             "name = %{public}s",
124         name.c_str());
125     NamedObjectMap::iterator iter = namedObjects_.find(name);
126     if (iter == namedObjects_.end()) {
127         return false;
128     }
129     if (objects_[iter->second]) {
130         objects_[iter->second]->RemoveName();
131     }
132     namedObjects_.erase(iter);
133     return true;
134 }
135 
RegisterJavaScriptProxy(const std::vector<std::function<char * (const char *)>> & cjFuncs,const std::string & objName,const std::vector<std::string> & methodList,const std::string & permission)136 JavaScriptOb::ObjectID WebviewJavaScriptResultCallBackImpl::RegisterJavaScriptProxy(
137     const std::vector<std::function<char*(const char*)>>& cjFuncs,
138     const std::string& objName, const std::vector<std::string>& methodList, const std::string& permission)
139 {
140     JavaScriptOb::ObjectID objId = AddNamedObject(cjFuncs, methodList, objName);
141     // set up named object method
142     if (namedObjects_.find(objName) != namedObjects_.end() && objects_[namedObjects_[objName]]) {
143         objects_[namedObjects_[objName]]->SetMethods(methodList);
144         objects_[namedObjects_[objName]]->SetPermission(permission);
145     }
146     WEBVIEWLOGD("WebviewJavaScriptResultCallBackImpl::RegisterJavaScriptProxy called, "
147             "objectId = %{public}d",
148         static_cast<int32_t>(objId));
149     return objId;
150 }
151 
FindObject(JavaScriptOb::ObjectID objectId)152 std::shared_ptr<JavaScriptOb> WebviewJavaScriptResultCallBackImpl::FindObject(JavaScriptOb::ObjectID objectId)
153 {
154     auto iter = objects_.find(objectId);
155     if (iter != objects_.end()) {
156         return iter->second;
157     }
158     WEBVIEWLOGE("WebviewJavaScriptResultCallBackImpl::FindObject Unknown object: objectId = "
159             "%{public}d",
160         objectId);
161     return nullptr;
162 }
163 
GetJavaScriptResultSelf(std::vector<std::shared_ptr<NWebValue>> args,const std::string & method,const std::string & objName,int32_t routingId,int32_t objectId)164 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultSelf(
165     std::vector<std::shared_ptr<NWebValue>> args, const std::string& method, const std::string& objName,
166     int32_t routingId, int32_t objectId)
167 {
168     std::shared_ptr<NWebValue> ret = std::make_shared<NWebValue>(NWebValue::Type::NONE);
169     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
170     if (!jsObj) {
171         return ret;
172     }
173     WEBVIEWLOGI("WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultSelf");
174     std::string argv;
175     if (args.size() == 0) {
176         argv = "";
177     } else {
178         argv = args[0]->GetString();
179     }
180     auto callback = jsObj->FindMethod(method);
181     if (!callback) {
182         WEBVIEWLOGE("WebviewJavaScriptResultCallBackImpl::ExecuteGetJavaScriptResult callback null");
183         return ret;
184     }
185     auto argCj = MallocCString(argv);
186     if (argCj == nullptr) {
187         return ret;
188     }
189     char* cjRet = callback(argCj);
190     std::string strVal = std::string(cjRet);
191     free(cjRet);
192     ret->SetType(NWebValue::Type::STRING);
193     ret->SetString(strVal);
194     return ret;
195 }
196 
GetJavaScriptResult(std::vector<std::shared_ptr<NWebValue>> args,const std::string & method,const std::string & objName,int32_t routingId,int32_t objectId)197 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptResult(
198     std::vector<std::shared_ptr<NWebValue>> args, const std::string& method, const std::string& objName,
199     int32_t routingId, int32_t objectId)
200 {
201     WEBVIEWLOGD("GetJavaScriptResult method = %{public}s", method.c_str());
202     std::shared_ptr<NWebValue> ret = std::make_shared<NWebValue>(NWebValue::Type::NONE);
203     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
204     if (!jsObj || jsObj->HasMethod(method) == -1) {
205         return ret;
206     }
207 
208     return GetJavaScriptResultSelf(args, method, objName, routingId, objectId);
209 }
210 
FlowbufStrAtIndex(void * mem,int flowbufIndex,int * argIndex,int * strLen)211 char* WebviewJavaScriptResultCallBackImpl::FlowbufStrAtIndex(
212     void* mem, int flowbufIndex, int* argIndex, int* strLen)
213 {
214     int* header = static_cast<int*>(mem); // Cast the memory block to int* for easier access
215     int offset = 0;
216     if (argIndex == nullptr) {
217         return nullptr;
218     }
219     if (flowbufIndex >=  MAX_ENTRIES) {
220         *argIndex = -1;
221         return nullptr;
222     }
223 
224     int* entry = header + (flowbufIndex * INDEX_SIZE);
225     if (entry == nullptr) {
226         return nullptr;
227     }
228     if (*(entry + 1) == 0) { // Check if length is 0, indicating unused entry
229         *argIndex = -1;
230         return nullptr;
231     }
232 
233     int i = 0;
234     for (i = 0; i < flowbufIndex; i++) {
235         offset += *(header + (i * INDEX_SIZE) + 1);
236     }
237     if (strLen == nullptr) {
238         return nullptr;
239     }
240     *strLen = *(header + (i * INDEX_SIZE) + 1) - 1;
241 
242     *argIndex = *entry;
243 
244     char* dataSegment = static_cast<char*>(mem) + HEADER_SIZE;
245     char* currentString = dataSegment + offset;
246     return currentString;
247 }
248 
ConstructArgv(void * ashmem,std::vector<std::shared_ptr<NWebValue>> args,std::vector<std::string> & argv,std::shared_ptr<JavaScriptOb> jsObj,int32_t routingId)249 bool WebviewJavaScriptResultCallBackImpl::ConstructArgv(void* ashmem,
250     std::vector<std::shared_ptr<NWebValue>> args,
251     std::vector<std::string>& argv,
252     std::shared_ptr<JavaScriptOb> jsObj,
253     int32_t routingId)
254 {
255     int argIndex = -1;
256     int currIndex = 0;
257     int flowbufIndex = 0;
258     int strLen = 0;
259     char* flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
260     flowbufIndex++;
261     while (argIndex == currIndex) {
262         argv.push_back(std::string(flowbufStr));
263         currIndex ++;
264         flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
265         flowbufIndex++;
266     }
267 
268     for (std::shared_ptr<NWebValue> input : args) {
269         while (argIndex == currIndex) {
270             argv.push_back(std::string(flowbufStr));
271             currIndex ++;
272             flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
273             flowbufIndex++;
274         }
275         argv.push_back(input->GetString());
276         currIndex++;
277     }
278 
279     while (argIndex == currIndex) {
280         argv.push_back(std::string(flowbufStr));
281         currIndex ++;
282         flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
283         flowbufIndex++;
284     }
285     return true;
286 }
287 
GetJavaScriptResultSelfHelper(std::shared_ptr<JavaScriptOb> jsObj,const std::string & method,int32_t routingId,std::vector<std::string> argv)288 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultSelfHelper(
289     std::shared_ptr<JavaScriptOb> jsObj,
290     const std::string& method,
291     int32_t routingId,
292     std::vector<std::string> argv)
293 {
294     std::shared_ptr<NWebValue> ret = std::make_shared<NWebValue>(NWebValue::Type::NONE);
295     auto callback = jsObj->FindMethod(method);
296     if (!callback) {
297         WEBVIEWLOGE("WebviewJavaScriptResultCallBack::ExecuteGetJavaScriptResult callback null");
298         return ret;
299     }
300     std::string arg;
301     if (argv.size() == 0) {
302         arg = "";
303     } else {
304         arg = argv[0];
305     }
306     auto argCj = MallocCString(arg);
307     if (argCj == nullptr) {
308         return ret;
309     }
310     char* cjRet = callback(argCj);
311     std::string strVal = std::string(cjRet);
312     free(cjRet);
313     ret->SetType(NWebValue::Type::STRING);
314     ret->SetString(strVal);
315     return ret;
316 }
317 
GetJavaScriptResultSelfFlowbuf(std::vector<std::shared_ptr<NWebValue>> args,const std::string & method,const std::string & objName,int fd,int32_t routingId,int32_t objectId)318 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultSelfFlowbuf(
319     std::vector<std::shared_ptr<NWebValue>> args, const std::string& method, const std::string& objName, int fd,
320     int32_t routingId, int32_t objectId)
321 {
322     std::shared_ptr<NWebValue> ret = std::make_shared<NWebValue>(NWebValue::Type::NONE);
323     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
324     auto flowbufferAdapter = OhosAdapterHelper::GetInstance().CreateFlowbufferAdapter();
325     if (!flowbufferAdapter) {
326         return ret;
327     }
328     auto ashmem = flowbufferAdapter->CreateAshmemWithFd(fd, MAX_FLOWBUF_DATA_SIZE + HEADER_SIZE, PROT_READ);
329     if (!ashmem) {
330         return ret;
331     }
332 
333     std::vector<std::string> argv = {};
334     if (!ConstructArgv(ashmem, args, argv, jsObj, routingId)) {
335         return ret;
336     }
337     close(fd);
338 
339     ret = GetJavaScriptResultSelfHelper(jsObj, method, routingId, argv);
340     return ret;
341 }
342 
GetJavaScriptResultFlowbuf(std::vector<std::shared_ptr<NWebValue>> args,const std::string & method,const std::string & objName,int fd,int32_t routingId,int32_t objectId)343 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultFlowbuf(
344     std::vector<std::shared_ptr<NWebValue>> args, const std::string& method, const std::string& objName, int fd,
345     int32_t routingId, int32_t objectId)
346 {
347     (void)objName; // to be compatible with older webcotroller, classname may be empty
348     WEBVIEWLOGD("GetJavaScriptResult method = %{public}s", method.c_str());
349     std::shared_ptr<NWebValue> ret = std::make_shared<NWebValue>(NWebValue::Type::NONE);
350     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
351     if (!jsObj || jsObj->HasMethod(method) == -1) {
352         return ret;
353     }
354     return GetJavaScriptResultSelfFlowbuf(args, method, objName,fd, routingId, objectId);
355 }
356 
GetJavaScriptObjectMethods(int32_t objectId)357 std::shared_ptr<NWebValue> WebviewJavaScriptResultCallBackImpl::GetJavaScriptObjectMethods(int32_t objectId)
358 {
359     auto ret = std::make_shared<NWebValue>(NWebValue::Type::LIST);
360     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
361     if (!jsObj) {
362         return ret;
363     }
364     auto methods = jsObj->GetMethodNames();
365     for (auto& method : methods) {
366         ret->AddListValue(NWebValue(method));
367     }
368     return ret;
369 }
370 
HasJavaScriptObjectMethods(int32_t objectId,const std::string & methodName)371 bool WebviewJavaScriptResultCallBackImpl::HasJavaScriptObjectMethods(int32_t objectId, const std::string& methodName)
372 {
373     bool ret = false;
374     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
375     if (!jsObj) {
376         return false;
377     }
378     if (jsObj->HasMethod(methodName) != -1) {
379         ret = true;
380     } else {
381         WEBVIEWLOGD("WebviewJavaScriptResultCallBackImpl::HasJavaScriptObjectMethods cannot find "
382                 "object");
383     }
384     return ret;
385 }
386 
DeleteJavaScriptRegister(const std::string & objName)387 bool WebviewJavaScriptResultCallBackImpl::DeleteJavaScriptRegister(const std::string &objName)
388 {
389     return RemoveNamedObject(objName);
390 }
391 
RemoveJavaScriptObjectHolder(int32_t holder,JavaScriptOb::ObjectID objectId)392 void WebviewJavaScriptResultCallBackImpl::RemoveJavaScriptObjectHolder(int32_t holder, JavaScriptOb::ObjectID objectId)
393 {}
394 
RemoveTransientJavaScriptObject()395 void WebviewJavaScriptResultCallBackImpl::RemoveTransientJavaScriptObject()
396 {}
397 
ConstructArgvV2(void * ashmem,const std::vector<std::shared_ptr<NWebHapValue>> & args,std::vector<std::string> & argv,std::shared_ptr<JavaScriptOb> jsObj,int32_t routingId)398 void WebviewJavaScriptResultCallBackImpl::ConstructArgvV2(void* ashmem,
399     const std::vector<std::shared_ptr<NWebHapValue>>& args, std::vector<std::string>& argv,
400     std::shared_ptr<JavaScriptOb> jsObj, int32_t routingId)
401 {
402     int argIndex = -1;
403     int currIndex = 0;
404     int flowbufIndex = 0;
405     int strLen = 0;
406     char* flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
407     flowbufIndex++;
408     while (argIndex == currIndex) {
409         argv.push_back(std::string(flowbufStr));
410         currIndex++;
411         flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
412         flowbufIndex++;
413     }
414 
415     for (auto& input : args) {
416         while (argIndex == currIndex) {
417             argv.push_back(std::string(flowbufStr));
418             currIndex++;
419             flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
420             flowbufIndex++;
421         }
422         argv.push_back(input->GetString());
423         currIndex++;
424     }
425 
426     while (argIndex == currIndex) {
427         argv.push_back(std::string(flowbufStr));
428         currIndex++;
429         flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen);
430         flowbufIndex++;
431     }
432 }
433 
GetJavaScriptResultSelfHelperV2(std::shared_ptr<JavaScriptOb> jsObj,const std::string & method,int32_t routingId,const std::vector<std::string> & argv,std::shared_ptr<NWebHapValue> result)434 void WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultSelfHelperV2(std::shared_ptr<JavaScriptOb> jsObj,
435     const std::string& method, int32_t routingId, const std::vector<std::string>& argv,
436     std::shared_ptr<NWebHapValue> result)
437 {
438     auto callback = jsObj->FindMethod(method);
439     if (!callback) {
440         WEBVIEWLOGE("WebviewJavaScriptResultCallBack::ExecuteGetJavaScriptResult callback null");
441         return;
442     }
443 
444     std::string arg = (argv.size() == 0) ? "" : argv[0];
445     auto argCj = MallocCString(arg);
446     if (argCj == nullptr) {
447         return;
448     }
449 
450     char* cjRet = callback(argCj);
451     result->SetType(NWebHapValue::Type::STRING);
452     result->SetString(cjRet);
453     free(cjRet);
454 }
455 
GetJavaScriptResultV2(const std::vector<std::shared_ptr<NWebHapValue>> & args,const std::string & method,const std::string & objectName,int32_t routingId,int32_t objectId,std::shared_ptr<NWebHapValue> result)456 void WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultV2(const std::vector<std::shared_ptr<NWebHapValue>>& args,
457     const std::string& method, const std::string& objectName, int32_t routingId, int32_t objectId,
458     std::shared_ptr<NWebHapValue> result)
459 {
460     if (!result) {
461         return;
462     }
463 
464     WEBVIEWLOGD("GetJavaScriptResult method = %{public}s", method.c_str());
465     result->SetType(NWebHapValue::Type::NONE);
466     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
467     if (!jsObj || jsObj->HasMethod(method) == -1) {
468         return;
469     }
470 
471     WEBVIEWLOGI("WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultV2");
472     auto callback = jsObj->FindMethod(method);
473     if (!callback) {
474         WEBVIEWLOGE("WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultV2 callback null");
475         return;
476     }
477 
478     std::string argv = (args.size() == 0) ? "" : args[0]->GetString();
479     auto argCj = MallocCString(argv);
480     if (argCj == nullptr) {
481         return;
482     }
483 
484     char* cjRet = callback(argCj);
485     result->SetType(NWebHapValue::Type::STRING);
486     result->SetString(cjRet);
487     free(cjRet);
488 }
489 
GetJavaScriptResultFlowbufV2(const std::vector<std::shared_ptr<NWebHapValue>> & args,const std::string & method,const std::string & objectName,int fd,int32_t routingId,int32_t objectId,std::shared_ptr<NWebHapValue> result)490 void WebviewJavaScriptResultCallBackImpl::GetJavaScriptResultFlowbufV2(
491     const std::vector<std::shared_ptr<NWebHapValue>>& args, const std::string& method, const std::string& objectName,
492     int fd, int32_t routingId, int32_t objectId, std::shared_ptr<NWebHapValue> result)
493 {
494     if (!result) {
495         return;
496     }
497     (void)objectName; // to be compatible with older webcotroller, classname may be empty
498 
499     WEBVIEWLOGD("GetJavaScriptResult method = %{public}s", method.c_str());
500     result->SetType(NWebHapValue::Type::NONE);
501     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
502     if (!jsObj || jsObj->HasMethod(method) == -1) {
503         return;
504     }
505 
506     auto flowbufferAdapter = OhosAdapterHelper::GetInstance().CreateFlowbufferAdapter();
507     if (!flowbufferAdapter) {
508         return;
509     }
510 
511     auto ashmem = flowbufferAdapter->CreateAshmemWithFd(fd, MAX_FLOWBUF_DATA_SIZE + HEADER_SIZE, PROT_READ);
512     if (!ashmem) {
513         return;
514     }
515 
516     std::vector<std::string> argv = {};
517     ConstructArgvV2(ashmem, args, argv, jsObj, routingId);
518     close(fd);
519 
520     GetJavaScriptResultSelfHelperV2(jsObj, method, routingId, argv, result);
521 }
522 
GetJavaScriptObjectMethodsV2(int32_t objectId,std::shared_ptr<NWebHapValue> result)523 void WebviewJavaScriptResultCallBackImpl::GetJavaScriptObjectMethodsV2(
524     int32_t objectId, std::shared_ptr<NWebHapValue> result)
525 {
526     if (!result) {
527         return;
528     }
529 
530     result->SetType(NWebHapValue::Type::NONE);
531     std::shared_ptr<JavaScriptOb> jsObj = FindObject(objectId);
532     if (!jsObj) {
533         return;
534     }
535 
536     auto methods = jsObj->GetMethodNames();
537     for (auto& method : methods) {
538         std::shared_ptr<NWebHapValue> child = result->NewChildValue();
539         if (child) {
540             child->SetString(method);
541             result->SaveListChildValue();
542         }
543     }
544 }
545 
546 } // namespace OHOS::Webview
547