From fd884ed1c0aeb9d0173c5d3444531f52e84beb5c Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 18 Aug 2019 21:49:06 +0200 Subject: [PATCH] Fix all warnings, add onWritable error message --- src/AppWrapper.h | 12 ++++++------ src/HttpRequestWrapper.h | 2 +- src/HttpResponseWrapper.h | 16 ++++++++++++---- src/addon.cpp | 9 --------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/AppWrapper.h b/src/AppWrapper.h index 581d66c..ad92ad5 100644 --- a/src/AppWrapper.h +++ b/src/AppWrapper.h @@ -66,7 +66,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { Local openLf = Local::New(isolate, openPf); if (!openLf->IsUndefined()) { Local argv[] = {wsObject, reqObject}; - openLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv); + openLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv).IsEmpty(); } }; @@ -81,7 +81,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { Local argv[3] = {Local::New(isolate, *(perSocketData->socketPf)), messageArrayBuffer, Boolean::New(isolate, opCode == uWS::OpCode::BINARY)}; - Local::New(isolate, messagePf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv); + Local::New(isolate, messagePf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv).IsEmpty(); /* Important: we clear the ArrayBuffer to make sure it is not invalidly used after return */ messageArrayBuffer->Neuter(); @@ -96,7 +96,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { PerSocketData *perSocketData = (PerSocketData *) ws->getUserData(); Local argv[1] = {Local::New(isolate, *(perSocketData->socketPf)) }; - Local::New(isolate, drainPf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv); + Local::New(isolate, drainPf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv).IsEmpty(); }; } @@ -124,7 +124,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { Local closeLf = Local::New(isolate, closePf); if (!closeLf->IsUndefined()) { Local argv[3] = {wsObject, Integer::New(isolate, code), messageArrayBuffer}; - closeLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv); + closeLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv).IsEmpty(); } delete perSocketData->socketPf; @@ -163,7 +163,7 @@ void uWS_App_get(F f, const FunctionCallbackInfo &args) { reqObject->SetAlignedPointerInInternalField(0, req); Local argv[] = {resObject, reqObject}; - Local::New(isolate, *pf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv); + Local::New(isolate, *pf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv).IsEmpty(); /* Properly invalidate req */ reqObject->SetAlignedPointerInInternalField(0, nullptr); @@ -190,7 +190,7 @@ void uWS_App_listen(const FunctionCallbackInfo &args) { auto cb = [&args](auto *token) { /* Return a false boolean if listen failed */ Local argv[] = {token ? Local::Cast(External::New(isolate, token)) : Local::Cast(Boolean::New(isolate, false))}; - Local::Cast(args[args.Length() - 1])->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv); + Local::Cast(args[args.Length() - 1])->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv).IsEmpty(); }; /* Host is first, if present */ diff --git a/src/HttpRequestWrapper.h b/src/HttpRequestWrapper.h index 887514c..3ba3591 100644 --- a/src/HttpRequestWrapper.h +++ b/src/HttpRequestWrapper.h @@ -25,7 +25,7 @@ struct HttpRequestWrapper { for (auto p : *req) { Local argv[] = {String::NewFromUtf8(isolate, p.first.data(), String::kNormalString, p.first.length()), String::NewFromUtf8(isolate, p.second.data(), String::kNormalString, p.second.length())}; - cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv); + cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv).IsEmpty(); } } } diff --git a/src/HttpResponseWrapper.h b/src/HttpResponseWrapper.h index 6adb5a8..ecdcee4 100644 --- a/src/HttpResponseWrapper.h +++ b/src/HttpResponseWrapper.h @@ -45,7 +45,7 @@ struct HttpResponseWrapper { Local dataArrayBuffer = ArrayBuffer::New(isolate, (void *) data.data(), data.length()); Local argv[] = {dataArrayBuffer, Boolean::New(isolate, last)}; - Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv); + Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv).IsEmpty(); dataArrayBuffer->Neuter(); }); @@ -71,7 +71,7 @@ struct HttpResponseWrapper { /* Mark this resObject invalid */ Local::New(isolate, resObject)->SetAlignedPointerInInternalField(0, nullptr); - Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr); + Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr).IsEmpty(); }); args.GetReturnValue().Set(args.Holder()); @@ -111,7 +111,15 @@ struct HttpResponseWrapper { HandleScope hs(isolate); Local argv[] = {Integer::NewFromUnsigned(isolate, offset)}; - return Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv).ToLocalChecked()->BooleanValue(isolate->GetCurrentContext()).ToChecked(); + + /* We should check if this is really here! */ + MaybeLocal maybeBoolean = Local::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv); + if (maybeBoolean.IsEmpty()) { + std::cerr << "ERROR! onWritable must return a boolean value according to documentation!" << std::endl; + exit(-1); + } + + return maybeBoolean.ToLocalChecked()->BooleanValue(isolate->GetCurrentContext()).ToChecked(); /* How important is this return? */ }); @@ -222,7 +230,7 @@ struct HttpResponseWrapper { if (res) { res->cork([cb = Local::Cast(args[0])]() { - cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr); + cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr).IsEmpty(); }); args.GetReturnValue().Set(args.Holder()); diff --git a/src/addon.cpp b/src/addon.cpp index fd350a8..000f015 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -70,15 +70,6 @@ void Main(Local exports) { /* Integrate with existing libuv loop, we just pass a boolean basically */ uWS::Loop::get(uv_default_loop()); - // instead, for now we call this manually like before: - /*uWS::Loop::get()->setPostHandler([](uWS::Loop *) { - isolate->RunMicrotasks(); - }); - - uWS::Loop::get()->setPreHandler([](uWS::Loop *) { - isolate->RunMicrotasks(); - });*/ - /* uWS namespace */ exports->Set(String::NewFromUtf8(isolate, "App"), FunctionTemplate::New(isolate, uWS_App)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()); exports->Set(String::NewFromUtf8(isolate, "SSLApp"), FunctionTemplate::New(isolate, uWS_App)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());