FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #1106 from nodegit/v8-5.2-compat · codercatdev/nodegit@35cd564 · GitHub

Repository navigation

Commit 35cd564

Browse files
authored
Merge pull request nodegit#1106 from nodegit/v8-5.2-compat
Preempt nan to fix deprecated calls to Get/SetHiddenValue
2 parents adf88fa + 38bcb34 commit 35cd564

8 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎generate/templates/manual/include/nodegit.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
55

66
extern ThreadPool libgit2ThreadPool;
77

8+
v8::Local<v8::Value> GetPrivate(v8::Local<v8::Object> object,
9+
v8::Local<v8::String> key);
10+
11+
void SetPrivate(v8::Local<v8::Object> object,
12+
v8::Local<v8::String> key,
13+
v8::Local<v8::Value> value);
14+
815
#endif

‎generate/templates/manual/revwalk/fast_walk.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void GitRevwalk::FastWalkWorker::HandleOKCallback()
124124
}
125125

126126
Local<v8::Object> nodeObj = node->ToObject();
127-
Local<v8::Value> checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked());
127+
Local<v8::Value> checkValue = GetPrivate(nodeObj, Nan::New("NodeGitPromiseError").ToLocalChecked());
128128

129129
if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined())
130130
{

‎generate/templates/partials/async_function.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
192192
}
193193

194194
Local<v8::Object> nodeObj = node->ToObject();
195-
Local<v8::Value> checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked());
195+
Local<v8::Value> checkValue = GetPrivate(nodeObj, Nan::New("NodeGitPromiseError").ToLocalChecked());
196196

197197
if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined()) {
198198
Local<v8::Value> argv[1] = {

‎generate/templates/partials/callback_helpers.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_promiseComp
128128
{% if arg.payload == true %}{{arg.name}}{% elsif arg.lastArg %}{{arg.name}}{% endif %}
129129
{% endeach %});
130130
Local<v8::Object> parent = instance->handle();
131-
parent->SetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked(), result);
131+
SetPrivate(parent, Nan::New("NodeGitPromiseError").ToLocalChecked(), result);
132132

133133
baton->result = {{ cbFunction.return.error }};
134134
}

‎generate/templates/partials/field_accessors.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
{% if arg.payload == true %}{{arg.name}}{% elsif arg.lastArg %}{{arg.name}}{% endif %}
250250
{% endeach %});
251251
Local<v8::Object> parent = instance->handle();
252-
parent->SetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked(), result);
252+
SetPrivate(parent, Nan::New("NodeGitPromiseError").ToLocalChecked(), result);
253253

254254
baton->result = {{ field.return.error }};
255255
}

‎generate/templates/templates/class_content.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88
{% endeach %}
99
}
1010

11+
#include "../include/nodegit.h"
1112
#include "../include/lock_master.h"
1213
#include "../include/functions/copy.h"
1314
#include "../include/{{ filename }}.h"

‎generate/templates/templates/nodegit.cc‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,44 @@
2222
#include "../include/convenient_patch.h"
2323
#include "../include/convenient_hunk.h"
2424

25+
#if (NODE_MODULE_VERSION > 48)
26+
v8::Local<v8::Value> GetPrivate(v8::Local<v8::Object> object,
27+
v8::Local<v8::String> key) {
28+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
29+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
30+
v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, key);
31+
v8::Local<v8::Value> value;
32+
v8::Maybe<bool> result = object->HasPrivate(context, privateKey);
33+
if (!(result.IsJust() && result.FromJust()))
34+
return v8::Local<v8::Value>();
35+
if (object->GetPrivate(context, privateKey).ToLocal(&value))
36+
return value;
37+
return v8::Local<v8::Value>();
38+
}
39+
40+
void SetPrivate(v8::Local<v8::Object> object,
41+
v8::Local<v8::String> key,
42+
v8::Local<v8::Value> value) {
43+
if (value.IsEmpty())
44+
return;
45+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
46+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
47+
v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, key);
48+
object->SetPrivate(context, privateKey, value);
49+
}
50+
#else
51+
v8::Local<v8::Value> GetPrivate(v8::Local<v8::Object> object,
52+
v8::Local<v8::String> key) {
53+
return object->GetHiddenValue(key);
54+
}
55+
56+
void SetPrivate(v8::Local<v8::Object> object,
57+
v8::Local<v8::String> key,
58+
v8::Local<v8::Value> value) {
59+
object->SetHiddenValue(key, value);
60+
}
61+
#endif
62+
2563
void LockMasterEnable(const FunctionCallbackInfo<Value>& info) {
2664
LockMaster::Enable();
2765
}

‎generate/templates/templates/struct_content.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414
}
1515

1616
#include <iostream>
17+
#include "../include/nodegit.h"
1718
#include "../include/lock_master.h"
1819
#include "../include/functions/copy.h"
1920
#include "../include/{{ filename }}.h"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL