@@ -95,42 +95,7 @@ DispatchResponse V8DOMAgentImpl::getDocument(Maybe<int> in_depth, Maybe<bool> in
95
95
96
96
if (!outResult->ToObject ()->Has (context, ArgConverter::ConvertToV8String (isolate, " backendNodeId" )).FromMaybe (false )) {
97
97
// Using an older version of the modules which doesn't set the backendNodeId required property
98
- auto scriptSource =
99
- " (function () {"
100
- " function addBackendNodeId(node) {"
101
- " if (!node.backendNodeId) {"
102
- " node.backendNodeId = 0;"
103
- " }"
104
- " if (node.children) {"
105
- " for (var i = 0; i < node.children.length; i++) {"
106
- " addBackendNodeId(node.children[i]);"
107
- " }"
108
- " }"
109
- " }"
110
- " return function(stringifiedNode) {"
111
- " try {"
112
- " const node = JSON.parse(stringifiedNode);"
113
- " addBackendNodeId(node);"
114
- " return JSON.stringify(node);"
115
- " } catch (e) {"
116
- " return stringifiedNode;"
117
- " }"
118
- " }"
119
- " })()" ;
120
-
121
- auto source = ArgConverter::ConvertToV8String (isolate, scriptSource);
122
- v8::Local<v8::Script> script;
123
- v8::Script::Compile (context, source).ToLocal (&script);
124
-
125
- v8::Local<v8::Value> result;
126
- script->Run (context).ToLocal (&result);
127
- auto addBackendNodeIdFunction = result.As <v8::Function>();
128
-
129
- v8::Local<v8::Value> args[] = { outResult };
130
- v8::Local<v8::Value> scriptResult;
131
- addBackendNodeIdFunction->Call (context, context->Global (), 1 , args).ToLocal (&scriptResult);
132
-
133
- resultString = ArgConverter::ConvertToUtf16String (scriptResult->ToString ());
98
+ resultString = AddBackendNodeIdProperty (isolate, outResult);
134
99
}
135
100
136
101
auto resultUtf16Data = resultString.data ();
@@ -363,5 +328,46 @@ DispatchResponse V8DOMAgentImpl::getFrameOwner(const String& in_frameId, int* ou
363
328
return utils::Common::protocolCommandNotSupportedDispatchResponse ();
364
329
}
365
330
331
+ std::u16string V8DOMAgentImpl::AddBackendNodeIdProperty (v8::Isolate* isolate, v8::Local<v8::Value> jsonInput) {
332
+ auto scriptSource =
333
+ " (function () {"
334
+ " function addBackendNodeId(node) {"
335
+ " if (!node.backendNodeId) {"
336
+ " node.backendNodeId = 0;"
337
+ " }"
338
+ " if (node.children) {"
339
+ " for (var i = 0; i < node.children.length; i++) {"
340
+ " addBackendNodeId(node.children[i]);"
341
+ " }"
342
+ " }"
343
+ " }"
344
+ " return function(stringifiedNode) {"
345
+ " try {"
346
+ " const node = JSON.parse(stringifiedNode);"
347
+ " addBackendNodeId(node);"
348
+ " return JSON.stringify(node);"
349
+ " } catch (e) {"
350
+ " return stringifiedNode;"
351
+ " }"
352
+ " }"
353
+ " })()" ;
354
+
355
+ auto source = ArgConverter::ConvertToV8String (isolate, scriptSource);
356
+ v8::Local<v8::Script> script;
357
+ auto context = isolate->GetCurrentContext ();
358
+ v8::Script::Compile (context, source).ToLocal (&script);
359
+
360
+ v8::Local<v8::Value> result;
361
+ script->Run (context).ToLocal (&result);
362
+ auto addBackendNodeIdFunction = result.As <v8::Function>();
363
+
364
+ v8::Local<v8::Value> funcArguments[] = { jsonInput };
365
+ v8::Local<v8::Value> scriptResult;
366
+ addBackendNodeIdFunction->Call (context, context->Global (), 1 , funcArguments).ToLocal (&scriptResult);
367
+
368
+ auto resultString = ArgConverter::ConvertToUtf16String (scriptResult->ToString ());
369
+ return resultString;
370
+ }
371
+
366
372
V8DOMAgentImpl* V8DOMAgentImpl::Instance = 0 ;
367
373
}
0 commit comments