-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpledge.cc
52 lines (41 loc) · 1.21 KB
/
pledge.cc
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
#include <unistd.h>
#include <node.h>
#include <string.h>
#include <err.h>
#include <errno.h>
namespace openbsdPledge {
using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void Pledge(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (args.Length() < 1) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments",
v8::NewStringType::kNormal).ToLocalChecked()));
return;
}
if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong arguments",
v8::NewStringType::kNormal).ToLocalChecked()));
return;
}
const int num = pledge(*String::Utf8Value(isolate, args[0]), NULL);
if (num == -1) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Pledge Error",
v8::NewStringType::kNormal).ToLocalChecked()));
return;
}
args.GetReturnValue().Set(num);
}
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "init", Pledge);
}
NODE_MODULE(addon, Init)
} // namespace openbsdPledge