From cbd3cf083a7a4bffa499ed080dfbe457b5e27bec Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 15 Feb 2019 11:25:02 +0100 Subject: [PATCH] src: add debug CHECKs against empty handles These checks were useful while investigating other issues; using empty `Local<>`s can be very un-debuggable, because that typically does not lead to assertions with debugging information but rather crashes based on accessing invalid memory. PR-URL: https://github.com/nodejs/node/pull/26125 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/api/callback.cc | 5 +++++ src/node_errors.cc | 1 + 2 files changed, 6 insertions(+) diff --git a/src/api/callback.cc b/src/api/callback.cc index 885134799fe019..4bcccb960c5556 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -139,6 +139,11 @@ MaybeLocal InternalMakeCallback(Environment* env, Local argv[], async_context asyncContext) { CHECK(!recv.IsEmpty()); +#ifdef DEBUG + for (int i = 0; i < argc; i++) + CHECK(!argv[i].IsEmpty()); +#endif + InternalCallbackScope scope(env, recv, asyncContext); if (scope.Failed()) { return MaybeLocal(); diff --git a/src/node_errors.cc b/src/node_errors.cc index 42e19f690514ff..39673abf7f0e41 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -710,6 +710,7 @@ void DecorateErrorStack(Environment* env, void FatalException(Isolate* isolate, Local error, Local message) { + CHECK(!error.IsEmpty()); HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate);