FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/src/wrapper.cc at v0.1.0 · nodegit/nodegit · GitHub
nodegit
nodegit
Repository navigation
Code
Issues
344
(344)
Pull requests
21
(21)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
src
/
wrapper.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (53 loc) · 2 KB
Breadcrumbs
nodegit
/
src
/
wrapper.cc
Copy path
File metadata and controls
77 lines (53 loc) · 2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
*
* This code is auto-generated; unless you know what you're doing, do not modify!
*
*/
#
include
<
v8.h
>
#
include
<
node.h
>
#
include
<
string
>
#
include
"
../include/wrapper.h
"
#
include
"
node_buffer.h
"
using
namespace
v8
;
using
namespace
node
;
Wrapper::Wrapper
(
void
*raw) {
this
->
raw
= raw;
}
void
Wrapper::Initialize
(Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> tpl =
FunctionTemplate::New
(New);
tpl->
InstanceTemplate
()->
SetInternalFieldCount
(
1
);
tpl->
SetClassName
(
String::NewSymbol
(
"
Wrapper
"
));
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
toBuffer
"
, ToBuffer);
constructor_template = Persistent<Function>::
New
(tpl->
GetFunction
());
target->
Set
(
String::NewSymbol
(
"
Wrapper
"
), constructor_template);
}
Handle<Value>
Wrapper::New
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsExternal
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
void * is required.
"
)));
}
Wrapper* object =
new
Wrapper
(
External::Unwrap
(args[
0
]));
object->
Wrap
(args.
This
());
return
scope.
Close
(args.
This
());
}
Handle<Value>
Wrapper::New
(
void
*raw) {
HandleScope scope;
Handle<Value> argv[
1
] = {
External::New
((
void
*)raw) };
return
scope.
Close
(Wrapper::constructor_template->
NewInstance
(
1
, argv));
}
void
*
Wrapper::GetValue
() {
return
this
->
raw
;
}
Handle<Value>
Wrapper::ToBuffer
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsNumber
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Number is required.
"
)));
}
int
len = args[
0
]->
ToNumber
()->
Value
();
Local<Function> bufferConstructor = Local<Function>::
Cast
(
Context::GetCurrent
()->
Global
()->
Get
(
String::New
(
"
Buffer
"
)));
Handle<Value> constructorArgs[
1
] = {
Integer::New
(len) };
Local<Object> nodeBuffer = bufferConstructor->
NewInstance
(
1
, constructorArgs);
memcpy
(
node::Buffer::Data
(nodeBuffer), ObjectWrap::Unwrap<Wrapper>(args.
This
())->
GetValue
(), len);
return
scope.
Close
(nodeBuffer);
}
Persistent<Function> Wrapper::constructor_template;
Back
|
FazBrowse Home
|
New Git URL