Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
http2: refactor Http2Scope to use BaseObjectPtr
Signed-off-by: James M Snell <jasnell@gmail.com>
  • Loading branch information
jasnell committed Apr 16, 2020
commit 7aefc8f43142c344472dd65e806c51f9ee2a9685
24 changes: 8 additions & 16 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,20 @@ const Http2Session::Callbacks Http2Session::callback_struct_saved[2] = {
// call Http2Session::MaybeScheduleWrite().
Http2Scope::Http2Scope(Http2Stream* stream) : Http2Scope(stream->session()) {}

Http2Scope::Http2Scope(Http2Session* session) {
if (session == nullptr)
return;
Http2Scope::Http2Scope(Http2Session* session) : session_(session) {
if (!session_) return;

if (session->is_in_scope() | session->is_write_scheduled()) {
// There is another scope further below on the stack, or it is already
// known that a write is scheduled. In either case, there is nothing to do.
// If there is another scope further below on the stack, or
// a write is already scheduled, there's nothing to do.
if (session_->is_in_scope() || session_->is_write_scheduled()) {
session_.reset();
return;
}
session->set_in_scope();
session_ = session;

// Always keep the session object alive for at least as long as
// this scope is active.
session_handle_ = session->object();
CHECK(!session_handle_.IsEmpty());
session_->set_in_scope();
}

Http2Scope::~Http2Scope() {
if (session_ == nullptr)
return;

if (!session_) return;
session_->set_in_scope(false);
session_->MaybeScheduleWrite();
}
Expand Down
3 changes: 1 addition & 2 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ class Http2Scope {
~Http2Scope();

private:
Http2Session* session_ = nullptr;
v8::Local<v8::Object> session_handle_;
BaseObjectPtr<Http2Session> session_;
};

// The Http2Options class is used to parse the options object passed in to
Expand Down