@@ -1960,14 +1960,17 @@ int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s,
19601960 HandleScope handle_scope (env->isolate ());
19611961 Context::Scope context_scope (env->context ());
19621962
1963- if (w->npn_protos_ .IsEmpty ()) {
1963+ Local<Value> npn_buffer =
1964+ w->object ()->GetHiddenValue (env->npn_buffer_string ());
1965+
1966+ if (npn_buffer.IsEmpty ()) {
19641967 // No initialization - no NPN protocols
19651968 *data = reinterpret_cast <const unsigned char *>(" " );
19661969 *len = 0 ;
19671970 } else {
1968- Local<Object> obj = PersistentToLocal (env-> isolate (), w-> npn_protos_ );
1969- *data = reinterpret_cast <const unsigned char *>(Buffer::Data (obj ));
1970- *len = Buffer::Length (obj );
1971+ CHECK ( Buffer::HasInstance (npn_buffer) );
1972+ *data = reinterpret_cast <const unsigned char *>(Buffer::Data (npn_buffer ));
1973+ *len = Buffer::Length (npn_buffer );
19711974 }
19721975
19731976 return SSL_TLSEXT_ERR_OK;
@@ -1986,25 +1989,27 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
19861989 HandleScope handle_scope (env->isolate ());
19871990 Context::Scope context_scope (env->context ());
19881991
1989- // Release old protocol handler if present
1990- w->selected_npn_proto_ . Reset ( );
1992+ Local<Value> npn_buffer =
1993+ w->object ()-> GetHiddenValue (env-> npn_buffer_string () );
19911994
1992- if (w-> npn_protos_ .IsEmpty ()) {
1995+ if (npn_buffer .IsEmpty ()) {
19931996 // We should at least select one protocol
19941997 // If server is using NPN
19951998 *out = reinterpret_cast <unsigned char *>(const_cast <char *>(" http/1.1" ));
19961999 *outlen = 8 ;
19972000
19982001 // set status: unsupported
1999- w->selected_npn_proto_ .Reset (env->isolate (), False (env->isolate ()));
2002+ bool r = w->object ()->SetHiddenValue (env->selected_npn_buffer_string (),
2003+ False (env->isolate ()));
2004+ CHECK (r);
20002005
20012006 return SSL_TLSEXT_ERR_OK;
20022007 }
20032008
2004- Local<Object> obj = PersistentToLocal (env-> isolate (), w-> npn_protos_ );
2009+ CHECK ( Buffer::HasInstance (npn_buffer) );
20052010 const unsigned char * npn_protos =
2006- reinterpret_cast <const unsigned char *>(Buffer::Data (obj ));
2007- size_t len = Buffer::Length (obj );
2011+ reinterpret_cast <const unsigned char *>(Buffer::Data (npn_buffer ));
2012+ size_t len = Buffer::Length (npn_buffer );
20082013
20092014 int status = SSL_select_next_proto (out, outlen, in, inlen, npn_protos, len);
20102015 Local<Value> result;
@@ -2022,8 +2027,9 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
20222027 break ;
20232028 }
20242029
2025- if (!result.IsEmpty ())
2026- w->selected_npn_proto_ .Reset (env->isolate (), result);
2030+ bool r = w->object ()->SetHiddenValue (env->selected_npn_buffer_string (),
2031+ result);
2032+ CHECK (r);
20272033
20282034 return SSL_TLSEXT_ERR_OK;
20292035}
@@ -2036,9 +2042,12 @@ void SSLWrap<Base>::GetNegotiatedProto(
20362042 ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
20372043
20382044 if (w->is_client ()) {
2039- if (w->selected_npn_proto_ .IsEmpty () == false ) {
2040- args.GetReturnValue ().Set (w->selected_npn_proto_ );
2041- }
2045+ Local<Value> selected_npn_buffer =
2046+ w->object ()->GetHiddenValue (w->env ()->selected_npn_buffer_string ());
2047+
2048+ if (selected_npn_buffer.IsEmpty () == false )
2049+ args.GetReturnValue ().Set (selected_npn_buffer);
2050+
20422051 return ;
20432052 }
20442053
@@ -2062,9 +2071,11 @@ void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
20622071 Environment* env = w->ssl_env ();
20632072
20642073 if (args.Length () < 1 || !Buffer::HasInstance (args[0 ]))
2065- return w-> env () ->ThrowTypeError (" Must give a Buffer as first argument" );
2074+ return env->ThrowTypeError (" Must give a Buffer as first argument" );
20662075
2067- w->npn_protos_ .Reset (args.GetIsolate (), args[0 ].As <Object>());
2076+ Local<Value> npn_buffer = Local<Value>::New (env->isolate (), args[0 ]);
2077+ bool r = w->object ()->SetHiddenValue (env->npn_buffer_string (), npn_buffer);
2078+ CHECK (r);
20682079}
20692080#endif // OPENSSL_NPN_NEGOTIATED
20702081
0 commit comments