Skip to content

Commit 1f0c547

Browse files
committed
format
1 parent 9eb4d66 commit 1f0c547

File tree

7 files changed

+12
-125
lines changed

7 files changed

+12
-125
lines changed

src/inspector/io_agent.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ DispatchResponse IoAgent::read(const String& in_handle,
3838
bool is_number = std::all_of(in_handle_str.begin(),
3939
in_handle_str.end(),
4040
::isdigit);
41-
if (is_number) {
42-
stream_id = std::stoi(in_handle_str);
43-
} else {
41+
if (!is_number) {
4442
out_data = new String("");
4543
*out_eof = true;
44+
return DispatchResponse::Success();
4645
}
46+
stream_id = std::stoi(in_handle_str);
4747

4848
std::string txt = data_map_[stream_id];
4949
int offset = 0;

src/inspector/network_agent.cc

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ std::unique_ptr<protocol::Network::Response> createResponseFromObject(
183183
}
184184

185185
NetworkAgent::NetworkAgent(NetworkInspector* inspector,
186-
v8_inspector::V8Inspector* v8_inspector,
187-
Environment* env)
186+
v8_inspector::V8Inspector* v8_inspector)
188187
: inspector_(inspector),
189-
v8_inspector_(v8_inspector),
190-
env_(env) {
188+
v8_inspector_(v8_inspector) {
191189
event_notifier_map_["requestWillBeSent"] = &NetworkAgent::requestWillBeSent;
192190
event_notifier_map_["responseReceived"] = &NetworkAgent::responseReceived;
193191
event_notifier_map_["loadingFailed"] = &NetworkAgent::loadingFailed;
@@ -244,105 +242,6 @@ protocol::DispatchResponse NetworkAgent::streamResourceContent(
244242
return protocol::DispatchResponse::Success();
245243
}
246244

247-
std::tuple<int, std::string, std::string> NetworkAgent::spawnFetchProcess(
248-
std::string_view code, Environment* env, std::string_view url) {
249-
std::string stdout_result;
250-
std::string stderr_result;
251-
uv_loop_t* loop = new uv_loop_t;
252-
uv_loop_init(loop);
253-
uv_process_t child;
254-
uv_pipe_t stdout_pipe;
255-
uv_pipe_init(loop, &stdout_pipe, 0);
256-
uv_pipe_t stderr_pipe;
257-
uv_pipe_init(loop, &stderr_pipe, 0);
258-
259-
uv_process_options_t uv_process_options;
260-
std::string command =
261-
env->exec_path() + " --eval \"" + code.data() + "\" -- " + url.data();
262-
263-
const char* file = env->exec_path().c_str();
264-
char* args[] = {const_cast<char*>(file),
265-
const_cast<char*>("--eval"),
266-
reinterpret_cast<char*>(const_cast<char*>(code.data())),
267-
reinterpret_cast<char*>(const_cast<char*>(url.data())),
268-
nullptr};
269-
270-
uv_stdio_container_t stdio[3];
271-
uv_process_options.file = file;
272-
uv_process_options.args = args;
273-
uv_process_options.flags = 0;
274-
uv_process_options.stdio_count = 3;
275-
uv_process_options.stdio = stdio;
276-
uv_process_options.cwd = nullptr;
277-
uv_process_options.env = nullptr;
278-
279-
uv_process_options.exit_cb =
280-
[](uv_process_t* req, int64_t exit_status, int term_signal) {
281-
uv_close(reinterpret_cast<uv_handle_t*>(req), nullptr);
282-
};
283-
284-
stdio[0].flags = UV_INHERIT_FD;
285-
stdio[0].data.fd = 0;
286-
stdio[1].flags =
287-
static_cast<uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
288-
stdio[1].data.stream = reinterpret_cast<uv_stream_t*>(&stdout_pipe);
289-
stdio[2].flags =
290-
static_cast<uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
291-
stdio[2].data.stream = reinterpret_cast<uv_stream_t*>(&stderr_pipe);
292-
293-
int r = uv_spawn(loop, &child, &uv_process_options);
294-
295-
if (r != 0) {
296-
uv_loop_close(loop);
297-
delete loop;
298-
return {r, stdout_result, stderr_result};
299-
}
300-
301-
auto alloc_cb =
302-
[](uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
303-
buf->base = static_cast<char*>(malloc(suggested_size));
304-
buf->len = suggested_size;
305-
};
306-
307-
auto read_cb = [](uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
308-
auto* response = static_cast<std::string*>(stream->data);
309-
if (nread > 0) {
310-
response->append(buf->base, nread);
311-
} else if (nread < 0) {
312-
if (!response->empty() && response->back() == '\n') {
313-
response->pop_back();
314-
}
315-
uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);
316-
}
317-
if (buf->base) free(buf->base);
318-
};
319-
320-
stdout_pipe.data = &stdout_result;
321-
uv_read_start(
322-
reinterpret_cast<uv_stream_t*>(&stdout_pipe), alloc_cb, read_cb);
323-
324-
stderr_pipe.data = &stderr_result;
325-
uv_read_start(
326-
reinterpret_cast<uv_stream_t*>(&stderr_pipe), alloc_cb, read_cb);
327-
328-
uv_run(loop, UV_RUN_DEFAULT);
329-
330-
uv_walk(
331-
loop,
332-
[](uv_handle_t* handle, void*) {
333-
if (!uv_is_closing(handle)) {
334-
uv_close(handle, nullptr);
335-
}
336-
},
337-
nullptr);
338-
339-
uv_run(loop, UV_RUN_DEFAULT);
340-
341-
uv_loop_close(loop);
342-
delete loop;
343-
return {r, stdout_result, stderr_result};
344-
}
345-
346245
protocol::DispatchResponse NetworkAgent::loadNetworkResource(
347246
const protocol::String& in_url,
348247
std::unique_ptr<protocol::Network::LoadNetworkResourcePageResult>*

src/inspector/network_agent.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ struct RequestEntry {
2323
class NetworkAgent : public protocol::Network::Backend {
2424
public:
2525
explicit NetworkAgent(NetworkInspector* inspector,
26-
v8_inspector::V8Inspector* v8_inspector,
27-
Environment* env);
26+
v8_inspector::V8Inspector* v8_inspector);
2827

2928
void Wire(protocol::UberDispatcher* dispatcher);
3029

@@ -61,12 +60,9 @@ class NetworkAgent : public protocol::Network::Backend {
6160
v8::Local<v8::Object> params);
6261

6362
private:
64-
std::tuple<int, std::string, std::string> spawnFetchProcess(
65-
std::string_view code, Environment* env, std::string_view url);
6663
NetworkInspector* inspector_;
6764
v8_inspector::V8Inspector* v8_inspector_;
6865
std::shared_ptr<protocol::Network::Frontend> frontend_;
69-
Environment* env_;
7066
using EventNotifier = void (NetworkAgent::*)(v8::Local<v8::Context> context,
7167
v8::Local<v8::Object>);
7268
std::unordered_map<protocol::String, EventNotifier> event_notifier_map_;

src/inspector/network_inspector.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NetworkInspector::NetworkInspector(Environment* env,
77
v8_inspector::V8Inspector* v8_inspector)
88
: enabled_(false), env_(env) {
99
network_agent_ =
10-
std::make_unique<NetworkAgent>(this, v8_inspector, env);
10+
std::make_unique<NetworkAgent>(this, v8_inspector);
1111
}
1212
NetworkInspector::~NetworkInspector() {
1313
network_agent_.reset();

src/inspector_agent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
442442
main_thread_->Post(
443443
std::unique_ptr<Request>(
444444
new FallThroughRequest(
445-
session_id_, call_id, method_str, json)));
445+
session_id_, call_id, method_str, json)));
446446
}
447447

448448
std::unique_ptr<protocol::RuntimeAgent> runtime_agent_;

src/inspector_agent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class Agent {
7979
v8::Local<v8::Object> params);
8080

8181
void EmitProtocolResponse(int call_id,
82-
std::string_view params,
83-
int session_id);
82+
std::string_view params,
83+
int session_id);
8484
void EmitProtocolResponseInParent(
8585
int session_id, std::string_view params, int call_id);
8686

src/inspector_js_api.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ void AddFallThroughListener(const FunctionCallbackInfo<Value>& args) {
381381
});
382382
}
383383

384-
void RegisterInspectWorker(const FunctionCallbackInfo<Value>& args) {
385-
worker::Worker* w;
386-
auto js_worker = args[0];
387-
ASSIGN_OR_RETURN_UNWRAP(&w, js_worker);
388-
}
389-
390384
void EmitProtocolResponseInParent(const FunctionCallbackInfo<Value>& args) {
391385
Environment* env = Environment::GetCurrent(args);
392386
auto isolate = env->isolate();
@@ -463,12 +457,11 @@ void Initialize(Local<Object> target, Local<Value> unused,
463457
SetMethodNoSideEffect(context, target, "isEnabled", IsEnabled);
464458
SetMethod(context, target, "emitProtocolEvent", EmitProtocolEvent);
465459
SetMethod(context,
466-
target,
467-
"emitProtocolResponseInParent",
460+
target,
461+
"emitProtocolResponseInParent",
468462
EmitProtocolResponseInParent);
469463
SetMethod(context, target, "setupNetworkTracking", SetupNetworkTracking);
470464
SetMethod(context, target, "addFallThroughListener", AddFallThroughListener);
471-
SetMethod(context, target, "registerInspectWorker", RegisterInspectWorker);
472465
SetMethod(context, target, "addIoData", AddIoData);
473466

474467
Local<String> console_string = FIXED_ONE_BYTE_STRING(isolate, "console");
@@ -507,7 +500,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
507500
registry->Register(EmitProtocolResponseInParent);
508501
registry->Register(SetupNetworkTracking);
509502
registry->Register(AddFallThroughListener);
510-
registry->Register(RegisterInspectWorker);
511503
registry->Register(AddIoData);
512504

513505
registry->Register(JSBindingsConnection<LocalConnection>::New);

0 commit comments

Comments
 (0)