-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy patherror.cc
More file actions
executable file
·49 lines (34 loc) · 1.26 KB
/
error.cc
File metadata and controls
executable file
·49 lines (34 loc) · 1.26 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
/*
Copyright (c) 2011, Tim Branyen @tbranyen <[email protected]>
*/
#include <v8.h>
#include <node.h>
#include <node_events.h>
#include "../vendor/libgit2/include/git2.h"
#include "error.h"
using namespace v8;
using namespace node;
void Error::Initialize (Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Error"));
NODE_SET_PROTOTYPE_METHOD(constructor_template, "strError", StrError);
target->Set(String::NewSymbol("Error"), constructor_template->GetFunction());
}
Handle<Value> Error::New(const Arguments& args) {
HandleScope scope;
Error *error = new Error();
error->Wrap(args.This());
return args.This();
}
Handle<Value> Error::StrError(const Arguments& args) {
HandleScope scope;
if(args.Length() == 0 || !args[0]->IsNumber()) {
return ThrowException(Exception::Error(String::New("Error is required and must be a Number.")));
}
Local<Integer> err = Local<Integer>::Cast(args[0]);
return String::New(git_strerror(err->Value()));
}
Persistent<FunctionTemplate> Error::constructor_template;