@@ -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
@@ -658,8 +657,6 @@ Http2Session::Http2Session(Environment* env,
658657Http2Session::~Http2Session () {
659658 CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
660659 Debug (this , " freeing nghttp2 session" );
661- for (const auto & iter : streams_)
662- iter.second ->session_ = nullptr ;
663660 nghttp2_session_del (session_);
664661 CHECK_EQ (current_nghttp2_memory_, 0 );
665662}
@@ -767,7 +764,7 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
767764 // If there are outstanding pings, those will need to be canceled, do
768765 // so on the next iteration of the event loop to avoid calling out into
769766 // javascript since this may be called during garbage collection.
770- while (std::unique_ptr <Http2Ping> ping = PopPing ()) {
767+ while (BaseObjectPtr <Http2Ping> ping = PopPing ()) {
771768 ping->DetachFromSession ();
772769 env ()->SetImmediate (
773770 [ping = std::move (ping)](Environment* env) {
@@ -1483,7 +1480,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
14831480 Local<Value> arg;
14841481 bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
14851482 if (ack) {
1486- std::unique_ptr <Http2Ping> ping = PopPing ();
1483+ BaseObjectPtr <Http2Ping> ping = PopPing ();
14871484
14881485 if (!ping) {
14891486 // PING Ack is unsolicited. Treat as a connection error. The HTTP/2
@@ -1522,7 +1519,7 @@ void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
15221519
15231520 // If this is an acknowledgement, we should have an Http2Settings
15241521 // object for it.
1525- std::unique_ptr <Http2Settings> settings = PopSettings ();
1522+ BaseObjectPtr <Http2Settings> settings = PopSettings ();
15261523 if (settings) {
15271524 settings->Done (true );
15281525 return ;
@@ -1982,12 +1979,11 @@ Http2Stream::~Http2Stream() {
19821979 nghttp2_rcbuf_decref (header.value );
19831980 }
19841981
1985- if (session_ == nullptr )
1982+ if (! session_)
19861983 return ;
19871984 Debug (this , " tearing down stream" );
19881985 session_->DecrementCurrentSessionMemory (current_headers_length_);
19891986 session_->RemoveStream (this );
1990- session_ = nullptr ;
19911987}
19921988
19931989std::string Http2Stream::diagnostic_name () const {
@@ -2189,8 +2185,10 @@ Http2Stream* Http2Stream::SubmitPushPromise(nghttp2_nv* nva,
21892185 id_, nva, len, nullptr );
21902186 CHECK_NE (*ret, NGHTTP2_ERR_NOMEM);
21912187 Http2Stream* stream = nullptr ;
2192- if (*ret > 0 )
2193- stream = Http2Stream::New (session_, *ret, NGHTTP2_HCAT_HEADERS, options);
2188+ if (*ret > 0 ) {
2189+ stream = Http2Stream::New (
2190+ session_.get (), *ret, NGHTTP2_HCAT_HEADERS, options);
2191+ }
21942192
21952193 return stream;
21962194}
@@ -2855,7 +2853,8 @@ void Http2Session::Ping(const FunctionCallbackInfo<Value>& args) {
28552853 if (obj->Set (env->context (), env->ondone_string (), args[1 ]).IsNothing ())
28562854 return ;
28572855
2858- Http2Ping* ping = session->AddPing (std::make_unique<Http2Ping>(session, obj));
2856+ Http2Ping* ping = session->AddPing (
2857+ MakeDetachedBaseObject<Http2Ping>(session, obj));
28592858 // To prevent abuse, we strictly limit the number of unacknowledged PING
28602859 // frames that may be sent at any given time. This is configurable in the
28612860 // Options when creating a Http2Session.
@@ -2884,16 +2883,16 @@ void Http2Session::Settings(const FunctionCallbackInfo<Value>& args) {
28842883 if (obj->Set (env->context (), env->ondone_string (), args[0 ]).IsNothing ())
28852884 return ;
28862885
2887- Http2Session:: Http2Settings* settings = session->AddSettings (
2888- std::make_unique <Http2Settings>(session->env (), session, obj, 0 ));
2886+ Http2Settings* settings = session->AddSettings (
2887+ MakeDetachedBaseObject <Http2Settings>(session->env (), session, obj, 0 ));
28892888 if (settings == nullptr ) return args.GetReturnValue ().Set (false );
28902889
28912890 settings->Send ();
28922891 args.GetReturnValue ().Set (true );
28932892}
28942893
2895- std::unique_ptr <Http2Session::Http2Ping> Http2Session::PopPing () {
2896- std::unique_ptr <Http2Ping> ping;
2894+ BaseObjectPtr <Http2Session::Http2Ping> Http2Session::PopPing () {
2895+ BaseObjectPtr <Http2Ping> ping;
28972896 if (!outstanding_pings_.empty ()) {
28982897 ping = std::move (outstanding_pings_.front ());
28992898 outstanding_pings_.pop ();
@@ -2903,7 +2902,7 @@ std::unique_ptr<Http2Session::Http2Ping> Http2Session::PopPing() {
29032902}
29042903
29052904Http2Session::Http2Ping* Http2Session::AddPing (
2906- std::unique_ptr <Http2Session::Http2Ping> ping) {
2905+ BaseObjectPtr <Http2Session::Http2Ping> ping) {
29072906 if (outstanding_pings_.size () == max_outstanding_pings_) {
29082907 ping->Done (false );
29092908 return nullptr ;
@@ -2914,8 +2913,8 @@ Http2Session::Http2Ping* Http2Session::AddPing(
29142913 return ptr;
29152914}
29162915
2917- std::unique_ptr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2918- std::unique_ptr <Http2Settings> settings;
2916+ BaseObjectPtr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2917+ BaseObjectPtr <Http2Settings> settings;
29192918 if (!outstanding_settings_.empty ()) {
29202919 settings = std::move (outstanding_settings_.front ());
29212920 outstanding_settings_.pop ();
@@ -2925,7 +2924,7 @@ std::unique_ptr<Http2Session::Http2Settings> Http2Session::PopSettings() {
29252924}
29262925
29272926Http2Session::Http2Settings* Http2Session::AddSettings (
2928- std::unique_ptr <Http2Session::Http2Settings> settings) {
2927+ BaseObjectPtr <Http2Session::Http2Settings> settings) {
29292928 if (outstanding_settings_.size () == max_outstanding_settings_) {
29302929 settings->Done (false );
29312930 return nullptr ;
@@ -2940,7 +2939,6 @@ Http2Session::Http2Ping::Http2Ping(Http2Session* session, Local<Object> obj)
29402939 : AsyncWrap(session->env (), obj, AsyncWrap::PROVIDER_HTTP2PING),
29412940 session_(session),
29422941 startTime_(uv_hrtime()) {
2943- RemoveCleanupHook (); // This object is owned by the Http2Session.
29442942}
29452943
29462944void Http2Session::Http2Ping::Send (const uint8_t * payload) {
0 commit comments