Skip to content

Commit

Permalink
src: remove unnecessary Reset() calls
Browse files Browse the repository at this point in the history
The previous commit made persistent handles auto-reset on destruction.
This commit removes the Reset() calls that are now no longer necessary.

PR-URL: nodejs#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>
  • Loading branch information
bnoordhuis authored and MayaLekova committed May 8, 2018
1 parent 2ce5dfb commit e33b4f3
Show file tree
Hide file tree
Showing 23 changed files with 2 additions and 101 deletions.
2 changes: 0 additions & 2 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo<DestroyParam>& info) {
if (val->IsFalse()) {
AsyncWrap::EmitDestroy(env, p->asyncId);
}
p->target.Reset();
p->propBag.Reset();
delete p;
}

Expand Down
8 changes: 1 addition & 7 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
}


inline BaseObject::~BaseObject() {
CHECK(persistent_handle_.IsEmpty());
}


inline Persistent<v8::Object>& BaseObject::persistent() {
return persistent_handle_;
}
Expand All @@ -65,8 +60,7 @@ inline Environment* BaseObject::env() const {
template <typename Type>
inline void BaseObject::WeakCallback(
const v8::WeakCallbackInfo<Type>& data) {
std::unique_ptr<Type> self(data.GetParameter());
self->persistent().Reset();
delete data.GetParameter();
}


Expand Down
2 changes: 1 addition & 1 deletion src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Environment;
class BaseObject {
public:
inline BaseObject(Environment* env, v8::Local<v8::Object> handle);
inline virtual ~BaseObject();
virtual ~BaseObject() = default;

// Returns the wrapped object. Returns an empty handle when
// persistent.IsEmpty() is true.
Expand Down
1 change: 0 additions & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ class QueryWrap : public AsyncWrap {
~QueryWrap() override {
CHECK_EQ(false, persistent().IsEmpty());
ClearWrap(object());
persistent().Reset();
}

// Subclasses should implement the appropriate Send method.
Expand Down
3 changes: 0 additions & 3 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ inline Environment::~Environment() {

context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
nullptr);
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
#undef V

delete[] heap_statistics_buffer_;
delete[] heap_space_statistics_buffer_;
Expand Down
2 changes: 0 additions & 2 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ void Environment::RunAndClearNativeImmediates() {
v8::TryCatch try_catch(isolate());
for (auto it = list.begin(); it != list.end(); ++it) {
it->cb_(this, it->data_);
if (it->keep_alive_)
it->keep_alive_->Reset();
if (it->refed_)
ref_count++;
if (UNLIKELY(try_catch.HasCaught())) {
Expand Down
6 changes: 0 additions & 6 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ HandleWrap::HandleWrap(Environment* env,
}


HandleWrap::~HandleWrap() {
CHECK(persistent().IsEmpty());
}


void HandleWrap::OnClose(uv_handle_t* handle) {
HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
Environment* env = wrap->env();
Expand All @@ -120,7 +115,6 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
wrap->MakeCallback(env->onclose_string(), 0, nullptr);

ClearWrap(wrap->object());
wrap->persistent().Reset();
delete wrap;
}

Expand Down
1 change: 0 additions & 1 deletion src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class HandleWrap : public AsyncWrap {
v8::Local<v8::Object> object,
uv_handle_t* handle,
AsyncWrap::ProviderType provider);
~HandleWrap() override;

private:
friend class Environment;
Expand Down
5 changes: 0 additions & 5 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ class JSBindingsConnection : public AsyncWrap {
inspector->Connect(&delegate_);
}

~JSBindingsConnection() override {
callback_.Reset();
}

void OnMessage(Local<Value> value) {
MakeCallback(callback_.Get(env()->isolate()), 1, &value);
}
Expand All @@ -111,7 +107,6 @@ class JSBindingsConnection : public AsyncWrap {
delegate_.Disconnect();
if (!persistent().IsEmpty()) {
ClearWrap(object());
persistent().Reset();
}
delete this;
}
Expand Down
5 changes: 0 additions & 5 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ ModuleWrap::~ModuleWrap() {
break;
}
}

module_.Reset();
context_.Reset();
}

ModuleWrap* ModuleWrap::GetFromModule(Environment* env,
Expand Down Expand Up @@ -227,8 +224,6 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
module->InstantiateModule(context, ModuleWrap::ResolveCallback);

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

if (!ok.FromMaybe(false)) {
Expand Down
17 changes: 0 additions & 17 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ struct napi_env__ {
: isolate(_isolate),
last_error(),
loop(_loop) {}
~napi_env__() {
last_exception.Reset();
wrap_template.Reset();
function_data_template.Reset();
accessor_data_template.Reset();
}
v8::Isolate* isolate;
node::Persistent<v8::Value> last_exception;
node::Persistent<v8::ObjectTemplate> wrap_template;
Expand Down Expand Up @@ -381,16 +375,6 @@ class Reference : private Finalizer {
}
}

~Reference() {
// The V8 Persistent class currently does not reset in its destructor:
// see NonCopyablePersistentTraits::kResetInDestructor = false.
// (Comments there claim that might change in the future.)
// To avoid memory leaks, it is better to reset at this time, however
// care must be taken to avoid attempting this after the Isolate has
// shut down, for example via a static (atexit) destructor.
_persistent.Reset();
}

public:
void* Data() {
return _finalize_data;
Expand Down Expand Up @@ -857,7 +841,6 @@ napi_status ConcludeDeferred(napi_env env,
v8_resolver->Resolve(context, v8impl::V8LocalValueFromJsValue(result)) :
v8_resolver->Reject(context, v8impl::V8LocalValueFromJsValue(result));

deferred_ref->Reset();
delete deferred_ref;

RETURN_STATUS_IF_FALSE(env, success.FromMaybe(false), napi_generic_failure);
Expand Down
6 changes: 0 additions & 6 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class CallbackInfo {
FreeCallback callback,
char* data,
void* hint);
~CallbackInfo();
Persistent<ArrayBuffer> persistent_;
FreeCallback const callback_;
char* const data_;
Expand Down Expand Up @@ -146,11 +145,6 @@ CallbackInfo::CallbackInfo(Isolate* isolate,
}


CallbackInfo::~CallbackInfo() {
persistent_.Reset();
}


void CallbackInfo::WeakCallback(
const WeakCallbackInfo<CallbackInfo>& data) {
CallbackInfo* self = data.GetParameter();
Expand Down
10 changes: 0 additions & 10 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ ContextifyContext::ContextifyContext(
}


ContextifyContext::~ContextifyContext() {
context_.Reset();
}


// This is an object that just keeps an internal pointer to this
// ContextifyContext. It's passed to the NamedPropertyHandler. If we
// pass the main JavaScript context object we're embedded in, then the
Expand Down Expand Up @@ -1123,11 +1118,6 @@ class ContextifyScript : public BaseObject {
: BaseObject(env, object) {
MakeWeak<ContextifyScript>(this);
}


~ContextifyScript() override {
script_.Reset();
}
};


Expand Down
1 change: 0 additions & 1 deletion src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ContextifyContext {
ContextifyContext(Environment* env,
v8::Local<v8::Object> sandbox_obj,
v8::Local<v8::Object> options_obj);
~ContextifyContext();

v8::Local<v8::Value> CreateDataWrapper(Environment* env);
v8::Local<v8::Context> CreateV8Context(Environment* env,
Expand Down
3 changes: 0 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,6 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
if (cons->HasInstance(ctx)) {
SecureContext* sc;
ASSIGN_OR_RETURN_UNWRAP(&sc, ctx.As<Object>());
w->sni_context_.Reset();
w->sni_context_.Reset(env->isolate(), ctx);

int rv;
Expand Down Expand Up @@ -4912,7 +4911,6 @@ class PBKDF2Request : public AsyncWrap {
keylen_ = 0;

ClearWrap(object());
persistent().Reset();
}

uv_work_t* work_req() {
Expand Down Expand Up @@ -5079,7 +5077,6 @@ class RandomBytesRequest : public AsyncWrap {

~RandomBytesRequest() override {
ClearWrap(object());
persistent().Reset();
}

uv_work_t* work_req() {
Expand Down
8 changes: 0 additions & 8 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,6 @@ class SSLWrap {
SSL_SESSION_free(next_sess_);
next_sess_ = nullptr;
}

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
sni_context_.Reset();
#endif

#ifdef NODE__HAVE_TLSEXT_STATUS_CB
ocsp_response_.Reset();
#endif // NODE__HAVE_TLSEXT_STATUS_CB
}

inline SSL* ssl() const { return ssl_; }
Expand Down
1 change: 0 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ FileHandle::~FileHandle() {
CHECK(!closing_); // We should not be deleting while explicitly closing!
Close(); // Close synchronously and emit warning
CHECK(closed_); // We have to be closed at the point
CHECK(persistent().IsEmpty());
}


Expand Down
8 changes: 0 additions & 8 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ Http2Session::Http2Settings::Http2Settings(
Http2Session::Http2Settings::~Http2Settings() {
if (!object().IsEmpty())
ClearWrap(object());
persistent().Reset();
CHECK(persistent().IsEmpty());
}

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

if (!object().IsEmpty())
ClearWrap(object());
persistent().Reset();
CHECK(persistent().IsEmpty());
}

// Notify the Http2Stream that a new block of HEADERS is being processed.
Expand Down Expand Up @@ -2772,8 +2766,6 @@ Http2Session::Http2Ping::Http2Ping(
Http2Session::Http2Ping::~Http2Ping() {
if (!object().IsEmpty())
ClearWrap(object());
persistent().Reset();
CHECK(persistent().IsEmpty());
}

void Http2Session::Http2Ping::Send(uint8_t* payload) {
Expand Down
1 change: 0 additions & 1 deletion src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class Parser : public AsyncWrap, public StreamListener {

~Parser() override {
ClearWrap(object());
persistent().Reset();
}


Expand Down
1 change: 0 additions & 1 deletion src/req_wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ template <typename T>
ReqWrap<T>::~ReqWrap() {
CHECK_EQ(req_.data, this); // Assert that someone has called Dispatched().
CHECK_EQ(false, persistent().IsEmpty());
persistent().Reset();
}

template <typename T>
Expand Down
5 changes: 0 additions & 5 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ TCPWrap::TCPWrap(Environment* env, Local<Object> object, ProviderType provider)
}


TCPWrap::~TCPWrap() {
CHECK(persistent().IsEmpty());
}


void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
TCPWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap,
Expand Down
1 change: 0 additions & 1 deletion src/tcp_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {

TCPWrap(Environment* env, v8::Local<v8::Object> object,
ProviderType provider);
~TCPWrap();

static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetNoDelay(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
6 changes: 0 additions & 6 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ TLSWrap::TLSWrap(Environment* env,
TLSWrap::~TLSWrap() {
enc_in_ = nullptr;
enc_out_ = nullptr;

sc_ = nullptr;

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
sni_context_.Reset();
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
}


Expand Down Expand Up @@ -835,7 +830,6 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
return SSL_TLSEXT_ERR_NOACK;
}

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

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

0 comments on commit e33b4f3

Please sign in to comment.