Skip to content

Commit 2ce0f90

Browse files
bnoordhuistobespc
authored andcommitted
Fix two deprecation warnings (#456)
* Fix deprecation warning, use Nan::TryCatch. Fixes the following compiler warning: Release/obj.target/appmetrics/geni/appmetrics.cpp: In function 'void emitMessage(uv_async_t*, int)': Release/obj.target/appmetrics/geni/appmetrics.cpp:396:18: warning: 'v8::TryCatch::TryCatch()' is deprecated: Use isolate version [-Wdeprecated-declarations] TryCatch try_catch; * Fix deprecation warning, use Nan::CallAsFunction(). Fixes the following compiler warning: Release/obj.target/appmetrics/geni/appmetrics.cpp: In function 'v8::Local<v8::Object> getRequireCache(v8::Local<v8::Object>)': Release/obj.target/appmetrics/geni/appmetrics.cpp:597:151: warning: 'v8::Local<v8::Value> v8::Object::CallAsFunction(v8::Local<v8::Value>, int, v8::Local<v8::Value>*)' is deprecated: Use maybe version [-Wdeprecated-declarations] Local<Value> m = module->Get(Nan::New<String>("require").ToLocalChecked())->ToObject()->CallAsFunction(Nan::GetCurrentContext()->Global(), 1, args);
1 parent 68ff88b commit 2ce0f90

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/appmetrics.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void emitMessage(uv_async_t *handle, int status) {
393393
uv_mutex_unlock(messageListMutex);
394394

395395
while(currentMessage != NULL ) {
396-
TryCatch try_catch;
396+
Nan::TryCatch try_catch;
397397
const unsigned argc = 2;
398398
Local<Value> argv[argc];
399399
const char * source = (*currentMessage->source).c_str();
@@ -404,11 +404,7 @@ static void emitMessage(uv_async_t *handle, int status) {
404404

405405
listener->callback->Call(argc, argv);
406406
if (try_catch.HasCaught()) {
407-
#if NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
408-
node::FatalException(v8::Isolate::GetCurrent(), try_catch);
409-
#else
410-
node::FatalException(try_catch);
411-
#endif
407+
Nan::FatalException(try_catch);
412408
}
413409
MessageData* nextMessage = currentMessage->next;
414410
freePayload(currentMessage);
@@ -594,9 +590,16 @@ void lrtime(const Nan::FunctionCallbackInfo<v8::Value>& info) {
594590
static Local<Object> getRequireCache(Local<Object> module) {
595591
Nan::EscapableHandleScope scope;
596592
Local<Value> args[] = { Nan::New<String>("module").ToLocalChecked() };
597-
Local<Value> m = module->Get(Nan::New<String>("require").ToLocalChecked())->ToObject()->CallAsFunction(Nan::GetCurrentContext()->Global(), 1, args);
598-
Local<Object> cache = m->ToObject()->Get(Nan::New<String>("_cache").ToLocalChecked())->ToObject();
599-
return scope.Escape(cache);
593+
Local<String> require_string = Nan::New<String>("require").ToLocalChecked();
594+
Local<Value> require_v = Nan::Get(module, require_string).ToLocalChecked();
595+
Local<Object> require_obj = Nan::To<Object>(require_v).ToLocalChecked();
596+
Local<Object> global_obj = Nan::GetCurrentContext()->Global();
597+
Local<Value> module_v = Nan::CallAsFunction(require_obj, global_obj, 1, args).ToLocalChecked();
598+
Local<Object> module_obj = Nan::To<Object>(module_v).ToLocalChecked();
599+
Local<String> cache_string = Nan::New<String>("_cache").ToLocalChecked();
600+
Local<Value> cache_v = Nan::Get(module_obj, cache_string).ToLocalChecked();
601+
Local<Object> cache_obj = Nan::To<Object>(cache_v).ToLocalChecked();
602+
return scope.Escape(cache_obj);
600603
}
601604

602605
// Check whether the filepath given looks like it's a file in the

0 commit comments

Comments
 (0)