Skip to content

Commit

Permalink
Avoid deprecation warnings in Nan::JSON
Browse files Browse the repository at this point in the history
This only affects older versions which do not support async_hooks
but it seemed easiest to set them up anyway.
  • Loading branch information
kkoopa committed Feb 22, 2018
1 parent 372b14d commit 3bc294b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions nan_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,17 @@ class JSON {
#if NAN_JSON_H_NEED_PARSE
inline v8::Local<v8::Value> parse(v8::Local<v8::Value> arg) {
assert(!parse_cb_.IsEmpty() && "parse_cb_ is empty");
return parse_cb_.Call(1, &arg);
AsyncResource resource("nan:JSON.parse");
return parse_cb_.Call(1, &arg, &resource).FromMaybe(v8::Local<v8::Value>());
}
#endif // NAN_JSON_H_NEED_PARSE

#if NAN_JSON_H_NEED_STRINGIFY
inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg) {
assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
return stringify_cb_.Call(1, &arg);
AsyncResource resource("nan:JSON.stringify");
return stringify_cb_.Call(1, &arg, &resource)
.FromMaybe(v8::Local<v8::Value>());
}

inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg,
Expand All @@ -153,7 +156,9 @@ class JSON {
Nan::Null(),
gap
};
return stringify_cb_.Call(3, argv);
AsyncResource resource("nan:JSON.stringify");
return stringify_cb_.Call(3, argv, &resource)
.FromMaybe(v8::Local<v8::Value>());
}
#endif // NAN_JSON_H_NEED_STRINGIFY
};
Expand Down

0 comments on commit 3bc294b

Please sign in to comment.