Skip to content

A couple of UX fixes: wait to disconnect and file name readability. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// wrap it
source = Module.wrap(source);
// compile the script, this will throw if it fails
new vm.Script(source, {filename: filename, displayErrors: true});
new vm.Script(source, {filename: 'file://' + filename, displayErrors: true});
process.exit(0);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ Module.prototype._compile = function(content, filename) {
var wrapper = Module.wrap(content);

var compiledWrapper = vm.runInThisContext(wrapper, {
filename: filename,
filename: 'file://' + filename,
lineOffset: 0,
displayErrors: true
});
Expand Down
24 changes: 23 additions & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AsyncWriteRequest {
AsyncWriteRequest(Agent* agent, const String16& message) :
agent_(agent), message_(message) {}
void perform() {
inspector_socket_t* socket = agent_->client_socket();
inspector_socket_t* socket = agent_->client_socket_;
if (socket) {
inspector_write(socket, message_.utf8().c_str(), message_.length());
}
Expand All @@ -94,6 +94,21 @@ class AsyncWriteRequest {
const String16 message_;
};

class SetConnectedTask : public v8::Task {
public:
SetConnectedTask(Agent* agent, bool connected)
: agent_(agent),
connected_(connected) {}

void Run() override {
agent_->connected_ = connected_;
}

private:
Agent* agent_;
bool connected_;
};

static void DisposeAsyncCb(uv_handle_t* handle) {
free(handle);
}
Expand Down Expand Up @@ -171,6 +186,7 @@ static void SendTargentsListResponse(inspector_socket_t* socket) {

Agent::Agent(Environment* env) : port_(5858),
wait_(false),
connected_(false),
parent_env_(env),
client_socket_(nullptr),
platform_(nullptr) {
Expand Down Expand Up @@ -281,6 +297,10 @@ void Agent::OnRemoteData(uv_stream_t* stream, ssize_t read, const uv_buf_t* b) {
agent->client_socket_ = nullptr;
}
DisconnectAndDispose(socket);
} else {
// EOF
agent->platform_->CallOnForegroundThread(agent->parent_env()->isolate(),
new SetConnectedTask(agent, false));
}
}

Expand All @@ -306,6 +326,8 @@ void Agent::OnInspectorConnection(inspector_socket_t* socket) {
client_socket_ = socket;
inspector_read_start(socket, OnBufferAlloc, OnRemoteData);
uv_sem_post(&start_sem_);
platform_->CallOnForegroundThread(parent_env()->isolate(),
new SetConnectedTask(this, true));
}

bool Agent::RespondToGet(inspector_socket_t* socket, const char* path) {
Expand Down
6 changes: 5 additions & 1 deletion src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Agent {

void PostMessages();

inspector_socket_t* client_socket() { return client_socket_; }
bool connected() { return connected_; }

protected:
inline node::Environment* parent_env() { return parent_env_; }
void InitAdaptor(Environment* env);
Expand All @@ -74,6 +75,7 @@ class Agent {

int port_;
bool wait_;
bool connected_;

uv_thread_t thread_;
node::Environment* parent_env_;
Expand Down Expand Up @@ -101,7 +103,9 @@ class Agent {
void OnInspectorConnection(inspector_socket_t* socket);
void write(const blink::protocol::String16& message);

friend class AsyncWriteRequest;
friend class ChannelImpl;
friend class SetConnectedTask;
};

} // namespace inspector
Expand Down
1 change: 1 addition & 0 deletions src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ static void on_close_frame_written(uv_write_t* write, int status) {
static void close_frame_received(inspector_socket_t* inspector) {
inspector->ws_state->received_close = true;
if (!inspector->ws_state->close_sent) {
invoke_read_callback(inspector, 0, 0);
write_to_client(inspector, CLOSE_FRAME, sizeof(CLOSE_FRAME),
on_close_frame_written);
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4433,6 +4433,14 @@ static void StartNodeInstance(void* arg) {
} while (more == true);
}

#if HAVE_INSPECTOR
if (env->inspector_agent()->connected())
fprintf(stderr, "Waiting for the debugger to disconnect...\n");
while (env->inspector_agent()->connected()) {
v8::platform::PumpMessageLoop(default_platform, isolate);
}
#endif

env->set_trace_sync_io(false);

int exit_code = EmitExit(env);
Expand Down