@@ -239,7 +239,6 @@ Http2Session::Http2Settings::Http2Settings(Environment* env,
239239 : AsyncWrap(env, obj, PROVIDER_HTTP2SETTINGS),
240240 session_ (session),
241241 startTime_(start_time) {
242- RemoveCleanupHook (); // This object is owned by the Http2Session.
243242 Init ();
244243}
245244
@@ -655,8 +654,6 @@ Http2Session::Http2Session(Environment* env,
655654Http2Session::~Http2Session () {
656655 CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
657656 Debug (this , " freeing nghttp2 session" );
658- for (const auto & iter : streams_)
659- iter.second ->session_ = nullptr ;
660657 nghttp2_session_del (session_);
661658 CHECK_EQ (current_nghttp2_memory_, 0 );
662659}
@@ -764,7 +761,7 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
764761 // If there are outstanding pings, those will need to be canceled, do
765762 // so on the next iteration of the event loop to avoid calling out into
766763 // javascript since this may be called during garbage collection.
767- while (std::unique_ptr <Http2Ping> ping = PopPing ()) {
764+ while (BaseObjectPtr <Http2Ping> ping = PopPing ()) {
768765 ping->DetachFromSession ();
769766 env ()->SetImmediate (
770767 [ping = std::move (ping)](Environment* env) {
@@ -1480,7 +1477,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
14801477 Local<Value> arg;
14811478 bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
14821479 if (ack) {
1483- std::unique_ptr <Http2Ping> ping = PopPing ();
1480+ BaseObjectPtr <Http2Ping> ping = PopPing ();
14841481
14851482 if (!ping) {
14861483 // PING Ack is unsolicited. Treat as a connection error. The HTTP/2
@@ -1519,7 +1516,7 @@ void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
15191516
15201517 // If this is an acknowledgement, we should have an Http2Settings
15211518 // object for it.
1522- std::unique_ptr <Http2Settings> settings = PopSettings ();
1519+ BaseObjectPtr <Http2Settings> settings = PopSettings ();
15231520 if (settings) {
15241521 settings->Done (true );
15251522 return ;
@@ -1979,12 +1976,11 @@ Http2Stream::~Http2Stream() {
19791976 nghttp2_rcbuf_decref (header.value );
19801977 }
19811978
1982- if (session_ == nullptr )
1979+ if (! session_)
19831980 return ;
19841981 Debug (this , " tearing down stream" );
19851982 session_->DecrementCurrentSessionMemory (current_headers_length_);
19861983 session_->RemoveStream (this );
1987- session_ = nullptr ;
19881984}
19891985
19901986std::string Http2Stream::diagnostic_name () const {
@@ -2186,8 +2182,10 @@ Http2Stream* Http2Stream::SubmitPushPromise(nghttp2_nv* nva,
21862182 id_, nva, len, nullptr );
21872183 CHECK_NE (*ret, NGHTTP2_ERR_NOMEM);
21882184 Http2Stream* stream = nullptr ;
2189- if (*ret > 0 )
2190- stream = Http2Stream::New (session_, *ret, NGHTTP2_HCAT_HEADERS, options);
2185+ if (*ret > 0 ) {
2186+ stream = Http2Stream::New (
2187+ session_.get (), *ret, NGHTTP2_HCAT_HEADERS, options);
2188+ }
21912189
21922190 return stream;
21932191}
@@ -2852,7 +2850,8 @@ void Http2Session::Ping(const FunctionCallbackInfo<Value>& args) {
28522850 if (obj->Set (env->context (), env->ondone_string (), args[1 ]).IsNothing ())
28532851 return ;
28542852
2855- Http2Ping* ping = session->AddPing (std::make_unique<Http2Ping>(session, obj));
2853+ Http2Ping* ping = session->AddPing (
2854+ MakeDetachedBaseObject<Http2Ping>(session, obj));
28562855 // To prevent abuse, we strictly limit the number of unacknowledged PING
28572856 // frames that may be sent at any given time. This is configurable in the
28582857 // Options when creating a Http2Session.
@@ -2881,16 +2880,16 @@ void Http2Session::Settings(const FunctionCallbackInfo<Value>& args) {
28812880 if (obj->Set (env->context (), env->ondone_string (), args[0 ]).IsNothing ())
28822881 return ;
28832882
2884- Http2Session:: Http2Settings* settings = session->AddSettings (
2885- std::make_unique <Http2Settings>(session->env (), session, obj, 0 ));
2883+ Http2Settings* settings = session->AddSettings (
2884+ MakeDetachedBaseObject <Http2Settings>(session->env (), session, obj, 0 ));
28862885 if (settings == nullptr ) return args.GetReturnValue ().Set (false );
28872886
28882887 settings->Send ();
28892888 args.GetReturnValue ().Set (true );
28902889}
28912890
2892- std::unique_ptr <Http2Session::Http2Ping> Http2Session::PopPing () {
2893- std::unique_ptr <Http2Ping> ping;
2891+ BaseObjectPtr <Http2Session::Http2Ping> Http2Session::PopPing () {
2892+ BaseObjectPtr <Http2Ping> ping;
28942893 if (!outstanding_pings_.empty ()) {
28952894 ping = std::move (outstanding_pings_.front ());
28962895 outstanding_pings_.pop ();
@@ -2900,7 +2899,7 @@ std::unique_ptr<Http2Session::Http2Ping> Http2Session::PopPing() {
29002899}
29012900
29022901Http2Session::Http2Ping* Http2Session::AddPing (
2903- std::unique_ptr <Http2Session::Http2Ping> ping) {
2902+ BaseObjectPtr <Http2Session::Http2Ping> ping) {
29042903 if (outstanding_pings_.size () == max_outstanding_pings_) {
29052904 ping->Done (false );
29062905 return nullptr ;
@@ -2911,8 +2910,8 @@ Http2Session::Http2Ping* Http2Session::AddPing(
29112910 return ptr;
29122911}
29132912
2914- std::unique_ptr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2915- std::unique_ptr <Http2Settings> settings;
2913+ BaseObjectPtr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2914+ BaseObjectPtr <Http2Settings> settings;
29162915 if (!outstanding_settings_.empty ()) {
29172916 settings = std::move (outstanding_settings_.front ());
29182917 outstanding_settings_.pop ();
@@ -2922,7 +2921,7 @@ std::unique_ptr<Http2Session::Http2Settings> Http2Session::PopSettings() {
29222921}
29232922
29242923Http2Session::Http2Settings* Http2Session::AddSettings (
2925- std::unique_ptr <Http2Session::Http2Settings> settings) {
2924+ BaseObjectPtr <Http2Session::Http2Settings> settings) {
29262925 if (outstanding_settings_.size () == max_outstanding_settings_) {
29272926 settings->Done (false );
29282927 return nullptr ;
@@ -2937,7 +2936,6 @@ Http2Session::Http2Ping::Http2Ping(Http2Session* session, Local<Object> obj)
29372936 : AsyncWrap(session->env (), obj, AsyncWrap::PROVIDER_HTTP2PING),
29382937 session_(session),
29392938 startTime_(uv_hrtime()) {
2940- RemoveCleanupHook (); // This object is owned by the Http2Session.
29412939}
29422940
29432941void Http2Session::Http2Ping::Send (const uint8_t * payload) {
0 commit comments