Skip to content

Commit f89f659

Browse files
bnoordhuisMylesBorins
authored andcommitted
src: remove unnecessary Reset() calls
The previous commit made persistent handles auto-reset on destruction. This commit removes the Reset() calls that are now no longer necessary. Backport-PR-URL: #19185 PR-URL: #18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 67a9742 commit f89f659

22 files changed

+2
-100
lines changed

src/async_wrap.cc

-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo<DestroyParam>& info) {
426426
if (val->IsFalse()) {
427427
AsyncWrap::EmitDestroy(env, p->asyncId);
428428
}
429-
p->target.Reset();
430-
p->propBag.Reset();
431429
delete p;
432430
}
433431

src/base_object-inl.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
4242
}
4343

4444

45-
inline BaseObject::~BaseObject() {
46-
CHECK(persistent_handle_.IsEmpty());
47-
}
48-
49-
5045
inline Persistent<v8::Object>& BaseObject::persistent() {
5146
return persistent_handle_;
5247
}
@@ -65,8 +60,7 @@ inline Environment* BaseObject::env() const {
6560
template <typename Type>
6661
inline void BaseObject::WeakCallback(
6762
const v8::WeakCallbackInfo<Type>& data) {
68-
std::unique_ptr<Type> self(data.GetParameter());
69-
self->persistent().Reset();
63+
delete data.GetParameter();
7064
}
7165

7266

src/base_object.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Environment;
3434
class BaseObject {
3535
public:
3636
inline BaseObject(Environment* env, v8::Local<v8::Object> handle);
37-
inline virtual ~BaseObject();
37+
virtual ~BaseObject() = default;
3838

3939
// Returns the wrapped object. Returns an empty handle when
4040
// persistent.IsEmpty() is true.

src/cares_wrap.cc

-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ class QueryWrap : public AsyncWrap {
598598
~QueryWrap() override {
599599
CHECK_EQ(false, persistent().IsEmpty());
600600
ClearWrap(object());
601-
persistent().Reset();
602601
}
603602

604603
// Subclasses should implement the appropriate Send method.

src/env-inl.h

-3
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ inline Environment::~Environment() {
357357

358358
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
359359
nullptr);
360-
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
361-
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
362-
#undef V
363360

364361
delete[] heap_statistics_buffer_;
365362
delete[] heap_space_statistics_buffer_;

src/env.cc

-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ void Environment::RunAndClearNativeImmediates() {
300300
v8::TryCatch try_catch(isolate());
301301
for (auto it = list.begin(); it != list.end(); ++it) {
302302
it->cb_(this, it->data_);
303-
if (it->keep_alive_)
304-
it->keep_alive_->Reset();
305303
if (it->refed_)
306304
ref_count++;
307305
if (UNLIKELY(try_catch.HasCaught())) {

src/handle_wrap.cc

-6
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ HandleWrap::HandleWrap(Environment* env,
9898
}
9999

100100

101-
HandleWrap::~HandleWrap() {
102-
CHECK(persistent().IsEmpty());
103-
}
104-
105-
106101
void HandleWrap::OnClose(uv_handle_t* handle) {
107102
HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
108103
Environment* env = wrap->env();
@@ -120,7 +115,6 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
120115
wrap->MakeCallback(env->onclose_string(), 0, nullptr);
121116

122117
ClearWrap(wrap->object());
123-
wrap->persistent().Reset();
124118
delete wrap;
125119
}
126120

src/handle_wrap.h

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class HandleWrap : public AsyncWrap {
7575
v8::Local<v8::Object> object,
7676
uv_handle_t* handle,
7777
AsyncWrap::ProviderType provider);
78-
~HandleWrap() override;
7978

8079
private:
8180
friend class Environment;

src/inspector_js_api.cc

-5
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ class JSBindingsConnection : public AsyncWrap {
8484
inspector->Connect(&delegate_);
8585
}
8686

87-
~JSBindingsConnection() override {
88-
callback_.Reset();
89-
}
90-
9187
void OnMessage(Local<Value> value) {
9288
MakeCallback(callback_.Get(env()->isolate()), 1, &value);
9389
}
@@ -111,7 +107,6 @@ class JSBindingsConnection : public AsyncWrap {
111107
delegate_.Disconnect();
112108
if (!persistent().IsEmpty()) {
113109
ClearWrap(object());
114-
persistent().Reset();
115110
}
116111
delete this;
117112
}

src/module_wrap.cc

-5
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ ModuleWrap::~ModuleWrap() {
5959
break;
6060
}
6161
}
62-
63-
module_.Reset();
64-
context_.Reset();
6562
}
6663

6764
void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
@@ -215,8 +212,6 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
215212
module->InstantiateModule(context, ModuleWrap::ResolveCallback);
216213

217214
// clear resolve cache on instantiate
218-
for (auto& entry : obj->resolve_cache_)
219-
entry.second.Reset();
220215
obj->resolve_cache_.clear();
221216

222217
if (!ok.FromMaybe(false)) {

src/node_api.cc

-17
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ struct napi_env__ {
3131
: isolate(_isolate),
3232
last_error(),
3333
loop(_loop) {}
34-
~napi_env__() {
35-
last_exception.Reset();
36-
wrap_template.Reset();
37-
function_data_template.Reset();
38-
accessor_data_template.Reset();
39-
}
4034
v8::Isolate* isolate;
4135
node::Persistent<v8::Value> last_exception;
4236
node::Persistent<v8::ObjectTemplate> wrap_template;
@@ -381,16 +375,6 @@ class Reference : private Finalizer {
381375
}
382376
}
383377

384-
~Reference() {
385-
// The V8 Persistent class currently does not reset in its destructor:
386-
// see NonCopyablePersistentTraits::kResetInDestructor = false.
387-
// (Comments there claim that might change in the future.)
388-
// To avoid memory leaks, it is better to reset at this time, however
389-
// care must be taken to avoid attempting this after the Isolate has
390-
// shut down, for example via a static (atexit) destructor.
391-
_persistent.Reset();
392-
}
393-
394378
public:
395379
void* Data() {
396380
return _finalize_data;
@@ -857,7 +841,6 @@ napi_status ConcludeDeferred(napi_env env,
857841
v8_resolver->Resolve(context, v8impl::V8LocalValueFromJsValue(result)) :
858842
v8_resolver->Reject(context, v8impl::V8LocalValueFromJsValue(result));
859843

860-
deferred_ref->Reset();
861844
delete deferred_ref;
862845

863846
RETURN_STATUS_IF_FALSE(env, success.FromMaybe(false), napi_generic_failure);

src/node_buffer.cc

-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class CallbackInfo {
102102
FreeCallback callback,
103103
char* data,
104104
void* hint);
105-
~CallbackInfo();
106105
Persistent<ArrayBuffer> persistent_;
107106
FreeCallback const callback_;
108107
char* const data_;
@@ -146,11 +145,6 @@ CallbackInfo::CallbackInfo(Isolate* isolate,
146145
}
147146

148147

149-
CallbackInfo::~CallbackInfo() {
150-
persistent_.Reset();
151-
}
152-
153-
154148
void CallbackInfo::WeakCallback(
155149
const WeakCallbackInfo<CallbackInfo>& data) {
156150
CallbackInfo* self = data.GetParameter();

src/node_contextify.cc

-10
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ ContextifyContext::ContextifyContext(
109109
}
110110

111111

112-
ContextifyContext::~ContextifyContext() {
113-
context_.Reset();
114-
}
115-
116-
117112
// This is an object that just keeps an internal pointer to this
118113
// ContextifyContext. It's passed to the NamedPropertyHandler. If we
119114
// pass the main JavaScript context object we're embedded in, then the
@@ -1157,11 +1152,6 @@ class ContextifyScript : public BaseObject {
11571152
: BaseObject(env, object) {
11581153
MakeWeak<ContextifyScript>(this);
11591154
}
1160-
1161-
1162-
~ContextifyScript() override {
1163-
script_.Reset();
1164-
}
11651155
};
11661156

11671157

src/node_contextify.h

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ContextifyContext {
2121
ContextifyContext(Environment* env,
2222
v8::Local<v8::Object> sandbox_obj,
2323
v8::Local<v8::Object> options_obj);
24-
~ContextifyContext();
2524

2625
v8::Local<v8::Value> CreateDataWrapper(Environment* env);
2726
v8::Local<v8::Context> CreateV8Context(Environment* env,

src/node_crypto.cc

-3
Original file line numberDiff line numberDiff line change
@@ -2826,7 +2826,6 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
28262826
if (cons->HasInstance(ctx)) {
28272827
SecureContext* sc;
28282828
ASSIGN_OR_RETURN_UNWRAP(&sc, ctx.As<Object>());
2829-
w->sni_context_.Reset();
28302829
w->sni_context_.Reset(env->isolate(), ctx);
28312830

28322831
int rv;
@@ -5580,7 +5579,6 @@ class PBKDF2Request : public AsyncWrap {
55805579
keylen_ = 0;
55815580

55825581
ClearWrap(object());
5583-
persistent().Reset();
55845582
}
55855583

55865584
uv_work_t* work_req() {
@@ -5747,7 +5745,6 @@ class RandomBytesRequest : public AsyncWrap {
57475745

57485746
~RandomBytesRequest() override {
57495747
ClearWrap(object());
5750-
persistent().Reset();
57515748
}
57525749

57535750
uv_work_t* work_req() {

src/node_crypto.h

-8
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,6 @@ class SSLWrap {
225225
SSL_SESSION_free(next_sess_);
226226
next_sess_ = nullptr;
227227
}
228-
229-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
230-
sni_context_.Reset();
231-
#endif
232-
233-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
234-
ocsp_response_.Reset();
235-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
236228
}
237229

238230
inline SSL* ssl() const { return ssl_; }

src/node_http2.cc

-8
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ Http2Session::Http2Settings::Http2Settings(
278278
Http2Session::Http2Settings::~Http2Settings() {
279279
if (!object().IsEmpty())
280280
ClearWrap(object());
281-
persistent().Reset();
282-
CHECK(persistent().IsEmpty());
283281
}
284282

285283
// Generates a Buffer that contains the serialized payload of a SETTINGS
@@ -535,8 +533,6 @@ Http2Session::~Http2Session() {
535533
CHECK_EQ(flags_ & SESSION_STATE_HAS_SCOPE, 0);
536534
if (!object().IsEmpty())
537535
ClearWrap(object());
538-
persistent().Reset();
539-
CHECK(persistent().IsEmpty());
540536
DEBUG_HTTP2SESSION(this, "freeing nghttp2 session");
541537
nghttp2_session_del(session_);
542538
}
@@ -1766,8 +1762,6 @@ Http2Stream::~Http2Stream() {
17661762

17671763
if (!object().IsEmpty())
17681764
ClearWrap(object());
1769-
persistent().Reset();
1770-
CHECK(persistent().IsEmpty());
17711765
}
17721766

17731767
// Notify the Http2Stream that a new block of HEADERS is being processed.
@@ -2784,8 +2778,6 @@ Http2Session::Http2Ping::Http2Ping(
27842778
Http2Session::Http2Ping::~Http2Ping() {
27852779
if (!object().IsEmpty())
27862780
ClearWrap(object());
2787-
persistent().Reset();
2788-
CHECK(persistent().IsEmpty());
27892781
}
27902782

27912783
void Http2Session::Http2Ping::Send(uint8_t* payload) {

src/node_http_parser.cc

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class Parser : public AsyncWrap, public StreamListener {
157157

158158
~Parser() override {
159159
ClearWrap(object());
160-
persistent().Reset();
161160
}
162161

163162

src/req_wrap-inl.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ template <typename T>
2525
ReqWrap<T>::~ReqWrap() {
2626
CHECK_EQ(req_.data, this); // Assert that someone has called Dispatched().
2727
CHECK_EQ(false, persistent().IsEmpty());
28-
persistent().Reset();
2928
}
3029

3130
template <typename T>

src/tcp_wrap.cc

-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ TCPWrap::TCPWrap(Environment* env, Local<Object> object, ProviderType provider)
174174
}
175175

176176

177-
TCPWrap::~TCPWrap() {
178-
CHECK(persistent().IsEmpty());
179-
}
180-
181-
182177
void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
183178
TCPWrap* wrap;
184179
ASSIGN_OR_RETURN_UNWRAP(&wrap,

src/tcp_wrap.h

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
5555

5656
TCPWrap(Environment* env, v8::Local<v8::Object> object,
5757
ProviderType provider);
58-
~TCPWrap();
5958

6059
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
6160
static void SetNoDelay(const v8::FunctionCallbackInfo<v8::Value>& args);

src/tls_wrap.cc

-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ TLSWrap::TLSWrap(Environment* env,
8686
TLSWrap::~TLSWrap() {
8787
enc_in_ = nullptr;
8888
enc_out_ = nullptr;
89-
9089
sc_ = nullptr;
91-
92-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
93-
sni_context_.Reset();
94-
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
9590
}
9691

9792

@@ -852,7 +847,6 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
852847
return SSL_TLSEXT_ERR_NOACK;
853848
}
854849

855-
p->sni_context_.Reset();
856850
p->sni_context_.Reset(env->isolate(), ctx);
857851

858852
SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>());

0 commit comments

Comments
 (0)