mirror of
https://github.com/hanzoai/node-dtrace-provider.git
synced 2026-09-23 23:48:45 +00:00
chrisa/node-dtrace-provider#125 Nodejs 12 support
Reviewed by: Cody Peter Mello <[email protected]>
This commit is contained in:
committed by
Cody Peter Mello
parent
ee86dd42d6
commit
3cbb3c8218
+1
-1
@@ -20,7 +20,7 @@
|
||||
"node": ">=0.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": "^2.10.0"
|
||||
"nan": "^2.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "0.7.1"
|
||||
|
||||
+10
-8
@@ -8,16 +8,16 @@ namespace node {
|
||||
// Integer Argument
|
||||
|
||||
#ifdef __x86_64__
|
||||
# define INTMETHOD ToInteger()
|
||||
# define INTMETHOD int64_t
|
||||
#else
|
||||
# define INTMETHOD ToInt32()
|
||||
# define INTMETHOD int32_t
|
||||
#endif
|
||||
|
||||
void * DTraceIntegerArgument::ArgumentValue(v8::Local<Value> value) {
|
||||
if (value->IsUndefined())
|
||||
return 0;
|
||||
else
|
||||
return (void *)(long) value->INTMETHOD->Value();
|
||||
return (void *)(long) Nan::To<INTMETHOD>(value).FromJust();
|
||||
}
|
||||
|
||||
void DTraceIntegerArgument::FreeArgument(void *arg) {
|
||||
@@ -33,7 +33,7 @@ namespace node {
|
||||
if (value->IsUndefined())
|
||||
return (void *) strdup("undefined");
|
||||
|
||||
String::Utf8Value str(value->ToString());
|
||||
Nan::Utf8String str(value);
|
||||
return (void *) strdup(*str);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ namespace node {
|
||||
Nan::HandleScope scope;
|
||||
v8::Local<Context> context = Nan::GetCurrentContext();
|
||||
v8::Local<Object> global = context->Global();
|
||||
v8::Local<Object> l_JSON = global->Get(Nan::New<String>("JSON").ToLocalChecked())->ToObject();
|
||||
v8::Local<String> json = Nan::New<String>("JSON").ToLocalChecked();
|
||||
v8::Local<Object> l_JSON = Nan::To<v8::Object>(global->Get(json)).ToLocalChecked();
|
||||
v8::Local<Function> l_JSON_stringify
|
||||
= v8::Local<Function>::Cast(l_JSON->Get(Nan::New<String>("stringify").ToLocalChecked()));
|
||||
JSON.Reset(l_JSON);
|
||||
@@ -71,13 +72,14 @@ namespace node {
|
||||
|
||||
v8::Local<Value> info[1];
|
||||
info[0] = value;
|
||||
v8::Local<Value> j = Nan::New<Function>(JSON_stringify)->Call(
|
||||
Nan::New<Object>(JSON), 1, info);
|
||||
v8::Local<Function> cb = Nan::New<Function>(JSON_stringify);
|
||||
v8::Local<Object> obj = Nan::New<Object>(JSON);
|
||||
Local<Value> j = Nan::Call(cb, obj, 1, info).ToLocalChecked();
|
||||
|
||||
if (*j == NULL)
|
||||
return (void *) strdup("{ \"error\": \"stringify failed\" }");
|
||||
|
||||
String::Utf8Value json(j->ToString());
|
||||
Nan::Utf8String json(j);
|
||||
return (void *) strdup(*json);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -28,7 +28,7 @@ namespace node {
|
||||
|
||||
Nan::SetPrototypeMethod(t, "fire", DTraceProbe::Fire);
|
||||
|
||||
target->Set(Nan::New<String>("DTraceProbe").ToLocalChecked(), t->GetFunction());
|
||||
target->Set(Nan::New<String>("DTraceProbe").ToLocalChecked(), Nan::GetFunction(t).ToLocalChecked());
|
||||
}
|
||||
|
||||
NAN_METHOD(DTraceProbe::New) {
|
||||
@@ -68,7 +68,12 @@ namespace node {
|
||||
}
|
||||
|
||||
Local<Function> cb = Local<Function>::Cast(argsinfo[fnidx]);
|
||||
Local<Value> probe_args = cb->Call(this->handle(), cblen, cbargs);
|
||||
Nan::MaybeLocal<Value> maybe = Nan::Call(cb, this->handle(), cblen, cbargs);
|
||||
if (maybe.IsEmpty()) {
|
||||
Nan::ThrowTypeError("Failed to invoke fire callback");
|
||||
return Nan::Undefined();
|
||||
}
|
||||
Local<Value> probe_args = maybe.ToLocalChecked();
|
||||
|
||||
delete [] cbargs;
|
||||
|
||||
|
||||
+14
-12
@@ -32,7 +32,7 @@ namespace node {
|
||||
Nan::SetPrototypeMethod(t, "disable", DTraceProvider::Disable);
|
||||
Nan::SetPrototypeMethod(t, "fire", DTraceProvider::Fire);
|
||||
|
||||
target->Set(Nan::New<String>("DTraceProvider").ToLocalChecked(), t->GetFunction());
|
||||
target->Set(Nan::New<String>("DTraceProvider").ToLocalChecked(), Nan::GetFunction(t).ToLocalChecked());
|
||||
|
||||
DTraceProbe::Initialize(target);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace node {
|
||||
return;
|
||||
}
|
||||
|
||||
String::Utf8Value name(info[0]->ToString());
|
||||
Nan::Utf8String name(info[0]);
|
||||
|
||||
if (info.Length() == 2) {
|
||||
if (!info[1]->IsString()) {
|
||||
@@ -57,7 +57,7 @@ namespace node {
|
||||
return;
|
||||
}
|
||||
|
||||
String::Utf8Value mod(info[1]->ToString());
|
||||
Nan::Utf8String mod(info[1]);
|
||||
(void) snprintf(module, sizeof (module), "%s", *mod);
|
||||
} else if (info.Length() == 1) {
|
||||
// If no module name is provided, develop a synthetic module name based
|
||||
@@ -84,22 +84,23 @@ namespace node {
|
||||
DTraceProvider *provider = Nan::ObjectWrap::Unwrap<DTraceProvider>(obj);
|
||||
|
||||
// create a DTraceProbe object
|
||||
v8::Local<Function> klass =
|
||||
Nan::New<FunctionTemplate>(DTraceProbe::constructor_template)->GetFunction();
|
||||
v8::Local<FunctionTemplate> tmpl =
|
||||
Nan::New<FunctionTemplate>(DTraceProbe::constructor_template);
|
||||
v8::Local<Function> klass = Nan::GetFunction(tmpl).ToLocalChecked();
|
||||
v8::Local<Object> pd = Nan::NewInstance(klass).ToLocalChecked();
|
||||
|
||||
// store in provider object
|
||||
DTraceProbe *probe = Nan::ObjectWrap::Unwrap<DTraceProbe>(pd->ToObject());
|
||||
obj->Set(info[0]->ToString(), pd);
|
||||
DTraceProbe *probe = Nan::ObjectWrap::Unwrap<DTraceProbe>(Nan::To<v8::Object>(pd).ToLocalChecked());
|
||||
obj->Set(Nan::To<v8::String>(info[0]).ToLocalChecked(), pd);
|
||||
|
||||
// reference the provider to avoid GC'ing it when only probes remain in scope.
|
||||
Nan::ForceSet(pd, Nan::New<String>("__prov__").ToLocalChecked(), obj,
|
||||
Nan::DefineOwnProperty(pd, Nan::New<String>("__prov__").ToLocalChecked(), obj,
|
||||
static_cast<PropertyAttribute>(DontEnum | ReadOnly | DontDelete));
|
||||
|
||||
// add probe to provider
|
||||
for (int i = 0; i < USDT_ARG_MAX; i++) {
|
||||
if (i < info.Length() - 1) {
|
||||
String::Utf8Value type(info[i + 1]->ToString());
|
||||
Nan::Utf8String type(info[i + 1]);
|
||||
|
||||
if (strncmp("json", *type, 4) == 0)
|
||||
probe->arguments[i] = new DTraceJsonArgument();
|
||||
@@ -115,7 +116,7 @@ namespace node {
|
||||
}
|
||||
}
|
||||
|
||||
String::Utf8Value name(info[0]->ToString());
|
||||
Nan::Utf8String name(info[0]);
|
||||
probe->probedef = usdt_create_probe(*name, *name, probe->argc, types);
|
||||
Nan::SetInternalFieldPointer(pd, 1, provider);
|
||||
usdt_provider_add_probe(provider->provider, probe->probedef);
|
||||
@@ -136,8 +137,9 @@ namespace node {
|
||||
v8::Local<Object> probe_obj = Local<Object>::Cast(info[0]);
|
||||
DTraceProbe *probe = Nan::ObjectWrap::Unwrap<DTraceProbe>(probe_obj);
|
||||
|
||||
v8::Local<String> name = Nan::New<String>(probe->probedef->name).ToLocalChecked();
|
||||
provider_obj->Delete(name);
|
||||
v8::Local<String> name =
|
||||
Nan::New<String>(probe->probedef->name).ToLocalChecked();
|
||||
Nan::Delete(provider_obj, name);
|
||||
|
||||
if (usdt_provider_remove_probe(provider->provider, probe->probedef) != 0) {
|
||||
Nan::ThrowError(usdt_errstr(provider->provider));
|
||||
|
||||
Reference in New Issue
Block a user