1
+ #include " Utils.h"
2
+ #include " JsV8InspectorClient.h"
3
+ #include " Util.h"
4
+
5
+ using namespace v8 ;
6
+ using namespace std ;
7
+ namespace tns {
8
+
9
+ Local <v8::Function>
10
+ GetDebuggerFunction (Local <Context> context, std::string domain, std::string functionName,
11
+ Local <Object> &domainDebugger) {
12
+ auto it = JsV8InspectorClient::Domains.find (domain);
13
+ if (it == JsV8InspectorClient::Domains.end ()) {
14
+ return Local<v8::Function>();
15
+ }
16
+
17
+ Isolate *isolate = context->GetIsolate ();
18
+ domainDebugger = it->second ->Get (isolate);
19
+
20
+ Local <Value> value;
21
+ auto funcName = v8::String::NewFromUtf8 (isolate, functionName.c_str (),
22
+ v8::NewStringType::kNormal ,
23
+ (int ) functionName.length ()).ToLocalChecked ();
24
+ bool success = domainDebugger->Get (context, funcName).ToLocal (&value);
25
+ if (success && !value.IsEmpty () && value->IsFunction ()) {
26
+ return value.As <v8::Function>();
27
+ }
28
+
29
+ return Local<v8::Function>();
30
+ }
31
+
32
+ Local <v8::Function>
33
+ GetDebuggerFunctionFromObject (Local <Context> context, const Local <Object> &object,
34
+ Local <Object> &domainDebugger) {
35
+ Isolate *isolate = context->GetIsolate ();
36
+ auto methodKey = v8::String::NewFromUtf8 (isolate, " method" ,
37
+ v8::NewStringType::kNormal ).ToLocalChecked ();
38
+ auto method = object->Get (context, methodKey).ToLocalChecked ();
39
+ auto methodString = Util::ToString (isolate, method);
40
+ auto domainSeparatorIndex = methodString.find (" ." );
41
+ auto domain = methodString.substr (0 , domainSeparatorIndex);
42
+ auto domainMethod = methodString.substr (domainSeparatorIndex + 1 , methodString.size ());
43
+
44
+ if (domain.size () > 0 ) {
45
+ return GetDebuggerFunction (context, domain, domainMethod, domainDebugger);
46
+ }
47
+
48
+ return Local<v8::Function>();
49
+ }
50
+ }
0 commit comments