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 <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2019-02-15 11:25:02 +01:00
parent 586318aa9f
commit 783c65ebc4
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 6 additions and 0 deletions

View File

@ -139,6 +139,11 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
Local<Value> argv[], Local<Value> argv[],
async_context asyncContext) { async_context asyncContext) {
CHECK(!recv.IsEmpty()); CHECK(!recv.IsEmpty());
#ifdef DEBUG
for (int i = 0; i < argc; i++)
CHECK(!argv[i].IsEmpty());
#endif
InternalCallbackScope scope(env, recv, asyncContext); InternalCallbackScope scope(env, recv, asyncContext);
if (scope.Failed()) { if (scope.Failed()) {
return MaybeLocal<Value>(); return MaybeLocal<Value>();

View File

@ -710,6 +710,7 @@ void DecorateErrorStack(Environment* env,
void FatalException(Isolate* isolate, void FatalException(Isolate* isolate,
Local<Value> error, Local<Value> error,
Local<Message> message) { Local<Message> message) {
CHECK(!error.IsEmpty());
HandleScope scope(isolate); HandleScope scope(isolate);
Environment* env = Environment::GetCurrent(isolate); Environment* env = Environment::GetCurrent(isolate);