@@ -243,7 +243,6 @@ Http2Session::Http2Settings::Http2Settings(Environment* env,
243243 : AsyncWrap(env, obj, PROVIDER_HTTP2SETTINGS),
244244 session_ (session),
245245 startTime_(start_time) {
246- RemoveCleanupHook (); // This object is owned by the Http2Session.
247246 Init ();
248247}
249248
@@ -586,8 +585,6 @@ Http2Session::Http2Session(Environment* env,
586585Http2Session::~Http2Session () {
587586 CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
588587 Debug (this , " freeing nghttp2 session" );
589- for (const auto & iter : streams_)
590- iter.second ->session_ = nullptr ;
591588 nghttp2_session_del (session_);
592589 CHECK_EQ (current_nghttp2_memory_, 0 );
593590}
@@ -695,7 +692,7 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
695692 // If there are outstanding pings, those will need to be canceled, do
696693 // so on the next iteration of the event loop to avoid calling out into
697694 // javascript since this may be called during garbage collection.
698- while (std::unique_ptr <Http2Ping> ping = PopPing ()) {
695+ while (BaseObjectPtr <Http2Ping> ping = PopPing ()) {
699696 ping->DetachFromSession ();
700697 env ()->SetImmediate (
701698 [ping = std::move (ping)](Environment* env) {
@@ -1451,7 +1448,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
14511448 Local<Value> arg;
14521449 bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
14531450 if (ack) {
1454- std::unique_ptr <Http2Ping> ping = PopPing ();
1451+ BaseObjectPtr <Http2Ping> ping = PopPing ();
14551452
14561453 if (!ping) {
14571454 // PING Ack is unsolicited. Treat as a connection error. The HTTP/2
@@ -1490,7 +1487,7 @@ void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
14901487
14911488 // If this is an acknowledgement, we should have an Http2Settings
14921489 // object for it.
1493- std::unique_ptr <Http2Settings> settings = PopSettings ();
1490+ BaseObjectPtr <Http2Settings> settings = PopSettings ();
14941491 if (settings) {
14951492 settings->Done (true );
14961493 return ;
@@ -1951,12 +1948,11 @@ Http2Stream::~Http2Stream() {
19511948 nghttp2_rcbuf_decref (header.value );
19521949 }
19531950
1954- if (session_ == nullptr )
1951+ if (! session_)
19551952 return ;
19561953 Debug (this , " tearing down stream" );
19571954 session_->DecrementCurrentSessionMemory (current_headers_length_);
19581955 session_->RemoveStream (this );
1959- session_ = nullptr ;
19601956}
19611957
19621958std::string Http2Stream::diagnostic_name () const {
@@ -2164,8 +2160,10 @@ Http2Stream* Http2Stream::SubmitPushPromise(nghttp2_nv* nva,
21642160 id_, nva, len, nullptr );
21652161 CHECK_NE (*ret, NGHTTP2_ERR_NOMEM);
21662162 Http2Stream* stream = nullptr ;
2167- if (*ret > 0 )
2168- stream = Http2Stream::New (session_, *ret, NGHTTP2_HCAT_HEADERS, options);
2163+ if (*ret > 0 ) {
2164+ stream = Http2Stream::New (
2165+ session_.get (), *ret, NGHTTP2_HCAT_HEADERS, options);
2166+ }
21692167
21702168 return stream;
21712169}
@@ -2832,7 +2830,8 @@ void Http2Session::Ping(const FunctionCallbackInfo<Value>& args) {
28322830 if (obj->Set (env->context (), env->ondone_string (), args[1 ]).IsNothing ())
28332831 return ;
28342832
2835- Http2Ping* ping = session->AddPing (std::make_unique<Http2Ping>(session, obj));
2833+ Http2Ping* ping = session->AddPing (
2834+ MakeDetachedBaseObject<Http2Ping>(session, obj));
28362835 // To prevent abuse, we strictly limit the number of unacknowledged PING
28372836 // frames that may be sent at any given time. This is configurable in the
28382837 // Options when creating a Http2Session.
@@ -2861,16 +2860,16 @@ void Http2Session::Settings(const FunctionCallbackInfo<Value>& args) {
28612860 if (obj->Set (env->context (), env->ondone_string (), args[0 ]).IsNothing ())
28622861 return ;
28632862
2864- Http2Session:: Http2Settings* settings = session->AddSettings (
2865- std::make_unique <Http2Settings>(session->env (), session, obj, 0 ));
2863+ Http2Settings* settings = session->AddSettings (
2864+ MakeDetachedBaseObject <Http2Settings>(session->env (), session, obj, 0 ));
28662865 if (settings == nullptr ) return args.GetReturnValue ().Set (false );
28672866
28682867 settings->Send ();
28692868 args.GetReturnValue ().Set (true );
28702869}
28712870
2872- std::unique_ptr <Http2Session::Http2Ping> Http2Session::PopPing () {
2873- std::unique_ptr <Http2Ping> ping;
2871+ BaseObjectPtr <Http2Session::Http2Ping> Http2Session::PopPing () {
2872+ BaseObjectPtr <Http2Ping> ping;
28742873 if (!outstanding_pings_.empty ()) {
28752874 ping = std::move (outstanding_pings_.front ());
28762875 outstanding_pings_.pop ();
@@ -2880,7 +2879,7 @@ std::unique_ptr<Http2Session::Http2Ping> Http2Session::PopPing() {
28802879}
28812880
28822881Http2Session::Http2Ping* Http2Session::AddPing (
2883- std::unique_ptr <Http2Session::Http2Ping> ping) {
2882+ BaseObjectPtr <Http2Session::Http2Ping> ping) {
28842883 if (outstanding_pings_.size () == max_outstanding_pings_) {
28852884 ping->Done (false );
28862885 return nullptr ;
@@ -2891,8 +2890,8 @@ Http2Session::Http2Ping* Http2Session::AddPing(
28912890 return ptr;
28922891}
28932892
2894- std::unique_ptr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2895- std::unique_ptr <Http2Settings> settings;
2893+ BaseObjectPtr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2894+ BaseObjectPtr <Http2Settings> settings;
28962895 if (!outstanding_settings_.empty ()) {
28972896 settings = std::move (outstanding_settings_.front ());
28982897 outstanding_settings_.pop ();
@@ -2902,7 +2901,7 @@ std::unique_ptr<Http2Session::Http2Settings> Http2Session::PopSettings() {
29022901}
29032902
29042903Http2Session::Http2Settings* Http2Session::AddSettings (
2905- std::unique_ptr <Http2Session::Http2Settings> settings) {
2904+ BaseObjectPtr <Http2Session::Http2Settings> settings) {
29062905 if (outstanding_settings_.size () == max_outstanding_settings_) {
29072906 settings->Done (false );
29082907 return nullptr ;
@@ -2917,7 +2916,6 @@ Http2Session::Http2Ping::Http2Ping(Http2Session* session, Local<Object> obj)
29172916 : AsyncWrap(session->env (), obj, AsyncWrap::PROVIDER_HTTP2PING),
29182917 session_(session),
29192918 startTime_(uv_hrtime()) {
2920- RemoveCleanupHook (); // This object is owned by the Http2Session.
29212919}
29222920
29232921void Http2Session::Http2Ping::Send (const uint8_t * payload) {
0 commit comments