Skip to content

Commit

Permalink
Replace removed v8 methods with Nan substitutes for nodejs 12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Kieslich committed Jul 8, 2019
1 parent f31f9c1 commit fbaa985
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 8 additions & 10 deletions src/dtrace_argument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand All @@ -51,9 +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<Function> l_JSON_stringify
= v8::Local<Function>::Cast(l_JSON->Get(Nan::New<String>("stringify").ToLocalChecked()));
v8::Local<Object> l_JSON = Nan::To<v8::Object>(global->Get(Nan::New<String>("JSON").ToLocalChecked())).ToLocalChecked();
v8::Local<Function> l_JSON_stringify = v8::Local<Function>::Cast(l_JSON->Get(Nan::New<String>("stringify").ToLocalChecked()));
JSON.Reset(l_JSON);
JSON_stringify.Reset(l_JSON_stringify);
}
Expand All @@ -71,13 +70,12 @@ 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<Value> j = Nan::Callback(Nan::New<Function>(JSON_stringify)).Call(Nan::New<Object>(JSON), 1, info);

if (*j == NULL)
return (void *) strdup("{ \"error\": \"stringify failed\" }");

String::Utf8Value json(j->ToString());
Nan::Utf8String json(j);
return (void *) strdup(*json);
}

Expand Down
5 changes: 3 additions & 2 deletions src/dtrace_probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -68,7 +68,8 @@ namespace node {
}

Local<Function> cb = Local<Function>::Cast(argsinfo[fnidx]);
Local<Value> probe_args = cb->Call(this->handle(), cblen, cbargs);
Nan::Callback callback(cb);
Local<Value> probe_args = callback.Call(this->handle(), cblen, cbargs);

delete [] cbargs;

Expand Down
23 changes: 12 additions & 11 deletions src/dtrace_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -49,16 +49,16 @@ namespace node {
return;
}

String::Utf8Value name(info[0]->ToString());
Nan::Utf8String name(info[0]);

if (info.Length() == 2) {
if (!info[1]->IsString()) {
Nan::ThrowTypeError("Must give module name as argument");
return;
}

String::Utf8Value mod(info[1]->ToString());
(void) snprintf(module, sizeof (module), "%s", *mod);
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
// on our address
Expand All @@ -85,12 +85,12 @@ namespace node {

// create a DTraceProbe object
v8::Local<Function> klass =
Nan::New<FunctionTemplate>(DTraceProbe::constructor_template)->GetFunction();
Nan::GetFunction(Nan::New<FunctionTemplate>(DTraceProbe::constructor_template)).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,
Expand All @@ -99,7 +99,7 @@ namespace node {
// 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();
Expand All @@ -115,7 +115,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);
Expand All @@ -136,8 +136,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));
Expand Down

0 comments on commit fbaa985

Please sign in to comment.