Skip to content

Commit

Permalink
Fix v8::JSON::Parse() deprecation warning.
Browse files Browse the repository at this point in the history
Use the non-deprecated overload that takes a `v8::Isolate` pointer and
returns a `v8::MaybeLocal<v8::Value>` when building against node <= 6.

Fixes: #663
  • Loading branch information
bnoordhuis authored and kkoopa committed Apr 12, 2017
1 parent b9ba8a5 commit 87f6a3c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nan_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ class JSON {
Nan::EscapableHandleScope scope;
#if NAN_JSON_H_NEED_PARSE
return scope.Escape(parse(json_string));
#else
Nan::MaybeLocal<v8::Value> result;
#if NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
result = v8::JSON::Parse(json_string);
#else
#if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
Nan::MaybeLocal<v8::Value> result =
v8::JSON::Parse(Nan::GetCurrentContext(), json_string);

if (result.IsEmpty()) return v8::Local<v8::Value>();
return scope.Escape(result.ToLocalChecked());
v8::Local<v8::Context> context_or_isolate = Nan::GetCurrentContext();
#else
return scope.Escape(v8::JSON::Parse(json_string));
v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent();
#endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
result = v8::JSON::Parse(context_or_isolate, json_string);
#endif // NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
if (result.IsEmpty()) return v8::Local<v8::Value>();
return scope.Escape(result.ToLocalChecked());
#endif // NAN_JSON_H_NEED_PARSE
}

Expand Down

0 comments on commit 87f6a3c

Please sign in to comment.