forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_binary_file.cc
More file actions
131 lines (103 loc) · 3.99 KB
/
diff_binary_file.cc
File metadata and controls
131 lines (103 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// This is a generated file, modify: generate/templates/class_content.cc.
#include <nan.h>
#include <string.h>
extern "C" {
#include <git2.h>
}
#include "../include/functions/copy.h"
#include "../include/diff_binary_file.h"
#include "../include/functions/sleep_for_ms.h"
#include <iostream>
using namespace std;
using namespace v8;
using namespace node;
GitDiffBinaryFile::GitDiffBinaryFile(git_diff_binary_file *raw, bool selfFreeing) {
this->raw = raw;
this->selfFreeing = selfFreeing;
}
GitDiffBinaryFile::~GitDiffBinaryFile() {
// this will cause an error if you have a non-self-freeing object that also needs
// to save values. Since the object that will eventually free the object has no
// way of knowing to free these values.
}
void GitDiffBinaryFile::InitializeComponent(Local<v8::Object> target) {
Nan::HandleScope scope;
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(JSNewFunction);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(Nan::New("DiffBinaryFile").ToLocalChecked());
Nan::SetPrototypeMethod(tpl, "type", Type);
Nan::SetPrototypeMethod(tpl, "data", Data);
Nan::SetPrototypeMethod(tpl, "datalen", Datalen);
Nan::SetPrototypeMethod(tpl, "inflatedlen", Inflatedlen);
Local<Function> _constructor_template = Nan::GetFunction(tpl).ToLocalChecked();
constructor_template.Reset(_constructor_template);
Nan::Set(target, Nan::New("DiffBinaryFile").ToLocalChecked(), _constructor_template);
}
NAN_METHOD(GitDiffBinaryFile::JSNewFunction) {
if (info.Length() == 0 || !info[0]->IsExternal()) {
return Nan::ThrowError("A new GitDiffBinaryFile cannot be instantiated.");
}
GitDiffBinaryFile* object = new GitDiffBinaryFile(static_cast<git_diff_binary_file *>(Local<External>::Cast(info[0])->Value()), Nan::To<bool>(info[1]).FromJust());
object->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}
Local<v8::Value> GitDiffBinaryFile::New(void *raw, bool selfFreeing) {
Nan::EscapableHandleScope scope;
Local<v8::Value> argv[2] = { Nan::New<External>((void *)raw), Nan::New(selfFreeing) };
return scope.Escape(Nan::NewInstance(Nan::New(GitDiffBinaryFile::constructor_template), 2, argv).ToLocalChecked());
}
git_diff_binary_file *GitDiffBinaryFile::GetValue() {
return this->raw;
}
git_diff_binary_file **GitDiffBinaryFile::GetRefValue() {
return this->raw == NULL ? NULL : &this->raw;
}
void GitDiffBinaryFile::ClearValue() {
this->raw = NULL;
}
NAN_METHOD(GitDiffBinaryFile::Type) {
Local<v8::Value> to;
git_diff_binary_t
type =
Nan::ObjectWrap::Unwrap<GitDiffBinaryFile>(info.This())->GetValue()->type;
// start convert_to_v8 block
to = Nan::New<Number>( type);
// end convert_to_v8 block
info.GetReturnValue().Set(to);
}
NAN_METHOD(GitDiffBinaryFile::Data) {
Local<v8::Value> to;
const char *
data =
Nan::ObjectWrap::Unwrap<GitDiffBinaryFile>(info.This())->GetValue()->data;
// start convert_to_v8 block
if (data){
to = Nan::New<String>(data).ToLocalChecked();
}
else {
to = Nan::Null();
}
// end convert_to_v8 block
info.GetReturnValue().Set(to);
}
NAN_METHOD(GitDiffBinaryFile::Datalen) {
Local<v8::Value> to;
size_t
datalen =
Nan::ObjectWrap::Unwrap<GitDiffBinaryFile>(info.This())->GetValue()->datalen;
// start convert_to_v8 block
to = Nan::New<Number>( datalen);
// end convert_to_v8 block
info.GetReturnValue().Set(to);
}
NAN_METHOD(GitDiffBinaryFile::Inflatedlen) {
Local<v8::Value> to;
size_t
inflatedlen =
Nan::ObjectWrap::Unwrap<GitDiffBinaryFile>(info.This())->GetValue()->inflatedlen;
// start convert_to_v8 block
to = Nan::New<Number>( inflatedlen);
// end convert_to_v8 block
info.GetReturnValue().Set(to);
}
Nan::Persistent<Function> GitDiffBinaryFile::constructor_template;