diff --git a/build.c b/build.c index 9451755..4121562 100644 --- a/build.c +++ b/build.c @@ -33,9 +33,10 @@ struct node_version { char *name; char *abi; } versions[] = { - {"v10.0.0", "64"}, - {"v11.1.0", "67"}, - {"v12.0.0", "72"} + {"v10.17.0", "64"}, + {"v11.15.0", "67"}, + {"v12.13.0", "72"}, + {"v13.1.0", "79"} }; /* Downloads headers, creates folders */ diff --git a/src/AppWrapper.h b/src/AppWrapper.h index abaf0ae..93cba34 100644 --- a/src/AppWrapper.h +++ b/src/AppWrapper.h @@ -29,37 +29,37 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { Local behaviorObject = Local::Cast(args[1]); /* maxPayloadLength or default */ - MaybeLocal maybeMaxPayloadLength = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxPayloadLength")); + MaybeLocal maybeMaxPayloadLength = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxPayloadLength", NewStringType::kNormal).ToLocalChecked()); if (!maybeMaxPayloadLength.IsEmpty() && !maybeMaxPayloadLength.ToLocalChecked()->IsUndefined()) { behavior.maxPayloadLength = maybeMaxPayloadLength.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); } /* idleTimeout or default */ - MaybeLocal maybeIdleTimeout = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "idleTimeout")); + MaybeLocal maybeIdleTimeout = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "idleTimeout", NewStringType::kNormal).ToLocalChecked()); if (!maybeIdleTimeout.IsEmpty() && !maybeIdleTimeout.ToLocalChecked()->IsUndefined()) { behavior.idleTimeout = maybeIdleTimeout.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); } /* Compression or default, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */ - MaybeLocal maybeCompression = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "compression")); + MaybeLocal maybeCompression = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "compression", NewStringType::kNormal).ToLocalChecked()); if (!maybeCompression.IsEmpty() && !maybeCompression.ToLocalChecked()->IsUndefined()) { behavior.compression = (uWS::CompressOptions) maybeCompression.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); } /* maxBackpressure or default */ - MaybeLocal maybeMaxBackpressure = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxBackpressure")); + MaybeLocal maybeMaxBackpressure = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxBackpressure", NewStringType::kNormal).ToLocalChecked()); if (!maybeMaxBackpressure.IsEmpty() && !maybeMaxBackpressure.ToLocalChecked()->IsUndefined()) { behavior.maxBackpressure = maybeMaxBackpressure.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); } /* Open */ - openPf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "open")))); + openPf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "open", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked())); /* Message */ - messagePf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "message")))); + messagePf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "message", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked())); /* Drain */ - drainPf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "drain")))); + drainPf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "drain", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked())); /* Close */ - closePf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "close")))); + closePf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked())); } /* Open handler is NOT optional for the wrapper */ @@ -198,7 +198,7 @@ void uWS_App_listen(const FunctionCallbackInfo &args) { /* Require at least two arguments */ if (args.Length() < 2) { /* Throw here */ - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App.listen requires port and callback"))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App.listen requires port and callback", NewStringType::kNormal).ToLocalChecked())); return; } @@ -238,7 +238,7 @@ void uWS_App_publish(const FunctionCallbackInfo &args) { NativeString topic(isolate, args[0]); NativeString message(isolate, args[1]); - app->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate->GetCurrentContext()).ToChecked()); + app->publish(topic.getString(), message.getString(), BooleanValue(isolate, args[2]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[3])); } template @@ -249,7 +249,7 @@ void uWS_App(const FunctionCallbackInfo &args) { /* Name differs based on type */ if (std::is_same::value) { - appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLApp")); + appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLApp", NewStringType::kNormal).ToLocalChecked()); /* We fill these below */ us_socket_context_options_t ssl_options = {}; @@ -261,8 +261,11 @@ void uWS_App(const FunctionCallbackInfo &args) { /* Read the options object (SSL options) */ if (args.Length() == 1) { + + Local optionsObject = Local::Cast(args[0]); + /* Key file name */ - NativeString keyFileNameValue(isolate, Local::Cast(args[0])->Get(String::NewFromUtf8(isolate, "key_file_name"))); + NativeString keyFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "key_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); if (keyFileNameValue.isInvalid(args)) { return; } @@ -272,7 +275,7 @@ void uWS_App(const FunctionCallbackInfo &args) { } /* Cert file name */ - NativeString certFileNameValue(isolate, Local::Cast(args[0])->Get(String::NewFromUtf8(isolate, "cert_file_name"))); + NativeString certFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "cert_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); if (certFileNameValue.isInvalid(args)) { return; } @@ -282,7 +285,7 @@ void uWS_App(const FunctionCallbackInfo &args) { } /* Passphrase */ - NativeString passphraseValue(isolate, Local::Cast(args[0])->Get(String::NewFromUtf8(isolate, "passphrase"))); + NativeString passphraseValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "passphrase", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); if (passphraseValue.isInvalid(args)) { return; } @@ -292,7 +295,7 @@ void uWS_App(const FunctionCallbackInfo &args) { } /* DH params file name */ - NativeString dhParamsFileNameValue(isolate, Local::Cast(args[0])->Get(String::NewFromUtf8(isolate, "dh_params_file_name"))); + NativeString dhParamsFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "dh_params_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); if (dhParamsFileNameValue.isInvalid(args)) { return; } @@ -302,70 +305,70 @@ void uWS_App(const FunctionCallbackInfo &args) { } /* ssl_prefer_low_memory_usage */ - ssl_options.ssl_prefer_low_memory_usage = Local::Cast(args[0])->Get(String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage"))->BooleanValue(isolate->GetCurrentContext()).ToChecked(); + ssl_options.ssl_prefer_low_memory_usage = BooleanValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); } app = new APP(ssl_options); } else { - appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.App")); + appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.App", NewStringType::kNormal).ToLocalChecked()); app = new APP; } /* Throw if we failed to construct the app */ if (app->constructorFailed()) { delete app; - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App construction failed"))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App construction failed", NewStringType::kNormal).ToLocalChecked())); return; } appTemplate->InstanceTemplate()->SetInternalFieldCount(1); /* All the http methods */ - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "get"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "get", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::get, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "post"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "post", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::post, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "options"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "options", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::options, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "del"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "del", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::del, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "patch"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "patch", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::patch, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "put"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "put", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::put, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "head"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "head", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::head, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "connect"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "connect", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::connect, args); })); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "trace"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "trace", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::trace, args); })); /* Any http method */ - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "any"), FunctionTemplate::New(isolate, [](auto &args) { + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "any", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, [](auto &args) { uWS_App_get(&APP::any, args); })); /* ws, listen */ - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ws"), FunctionTemplate::New(isolate, uWS_App_ws)); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "listen"), FunctionTemplate::New(isolate, uWS_App_listen)); - appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish"), FunctionTemplate::New(isolate, uWS_App_publish)); + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ws", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_ws)); + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "listen", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_listen)); + appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_publish)); Local localApp = appTemplate->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); localApp->SetAlignedPointerInInternalField(0, app); diff --git a/src/HttpRequestWrapper.h b/src/HttpRequestWrapper.h index 3ba3591..eb2d4b2 100644 --- a/src/HttpRequestWrapper.h +++ b/src/HttpRequestWrapper.h @@ -11,7 +11,7 @@ struct HttpRequestWrapper { /* Thow on deleted request */ auto *req = (uWS::HttpRequest *) args.Holder()->GetAlignedPointerFromInternalField(0); if (!req) { - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Using uWS.HttpRequest past its request handler return is forbidden (it is stack allocated)."))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Using uWS.HttpRequest past its request handler return is forbidden (it is stack allocated).", NewStringType::kNormal).ToLocalChecked())); } return req; } @@ -23,8 +23,8 @@ struct HttpRequestWrapper { Local cb = Local::Cast(args[0]); 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())}; + Local argv[] = {String::NewFromUtf8(isolate, p.first.data(), NewStringType::kNormal, p.first.length()).ToLocalChecked(), + String::NewFromUtf8(isolate, p.second.data(), NewStringType::kNormal, p.second.length()).ToLocalChecked()}; cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv).IsEmpty(); } } @@ -37,7 +37,7 @@ struct HttpRequestWrapper { int index = args[0]->Uint32Value(isolate->GetCurrentContext()).ToChecked(); std::string_view parameter = req->getParameter(index); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, parameter.data(), v8::String::kNormalString, parameter.length())); + args.GetReturnValue().Set(String::NewFromUtf8(isolate, parameter.data(), NewStringType::kNormal, parameter.length()).ToLocalChecked()); } } @@ -47,7 +47,7 @@ struct HttpRequestWrapper { if (req) { std::string_view url = req->getUrl(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, url.data(), v8::String::kNormalString, url.length())); + args.GetReturnValue().Set(String::NewFromUtf8(isolate, url.data(), NewStringType::kNormal, url.length()).ToLocalChecked()); } } @@ -62,7 +62,7 @@ struct HttpRequestWrapper { std::string_view header = req->getHeader(data.getString()); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, header.data(), v8::String::kNormalString, header.length())); + args.GetReturnValue().Set(String::NewFromUtf8(isolate, header.data(), NewStringType::kNormal, header.length()).ToLocalChecked()); } } @@ -72,7 +72,7 @@ struct HttpRequestWrapper { if (req) { std::string_view method = req->getMethod(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, method.data(), v8::String::kNormalString, method.length())); + args.GetReturnValue().Set(String::NewFromUtf8(isolate, method.data(), NewStringType::kNormal, method.length()).ToLocalChecked()); } } @@ -81,23 +81,23 @@ struct HttpRequestWrapper { if (req) { std::string_view query = req->getQuery(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, query.data(), v8::String::kNormalString, query.length())); + args.GetReturnValue().Set(String::NewFromUtf8(isolate, query.data(), NewStringType::kNormal, query.length()).ToLocalChecked()); } } static void initReqTemplate() { /* We do clone every request object, we could share them, they are illegal to use outside the function anyways */ Local reqTemplateLocal = FunctionTemplate::New(isolate); - reqTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.HttpRequest")); + reqTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.HttpRequest", NewStringType::kNormal).ToLocalChecked()); reqTemplateLocal->InstanceTemplate()->SetInternalFieldCount(1); /* Register our functions */ - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getHeader"), FunctionTemplate::New(isolate, req_getHeader)); - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getParameter"), FunctionTemplate::New(isolate, req_getParameter)); - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getUrl"), FunctionTemplate::New(isolate, req_getUrl)); - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getMethod"), FunctionTemplate::New(isolate, req_getMethod)); - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getQuery"), FunctionTemplate::New(isolate, req_getQuery)); - reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "forEach"), FunctionTemplate::New(isolate, req_forEach)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getHeader", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_getHeader)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getParameter", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_getParameter)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getUrl", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_getUrl)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getMethod", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_getMethod)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getQuery", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_getQuery)); + reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "forEach", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, req_forEach)); /* Create the template */ Local reqObjectLocal = reqTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); diff --git a/src/HttpResponseWrapper.h b/src/HttpResponseWrapper.h index ecdcee4..38c1143 100644 --- a/src/HttpResponseWrapper.h +++ b/src/HttpResponseWrapper.h @@ -10,7 +10,7 @@ struct HttpResponseWrapper { static inline uWS::HttpResponse *getHttpResponse(const FunctionCallbackInfo &args) { auto *res = (uWS::HttpResponse *) args.Holder()->GetAlignedPointerFromInternalField(0); if (!res) { - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse."))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.", NewStringType::kNormal).ToLocalChecked())); } return res; } @@ -107,7 +107,7 @@ struct HttpResponseWrapper { /* This thing perfectly fits in with unique_function, and will Reset on destructor */ UniquePersistent p(isolate, Local::Cast(args[0])); - res->onWritable([p = std::move(p)](int offset) { + res->onWritable([p = std::move(p)](int offset) -> bool { HandleScope hs(isolate); Local argv[] = {Integer::NewFromUnsigned(isolate, offset)}; @@ -119,7 +119,7 @@ struct HttpResponseWrapper { exit(-1); } - return maybeBoolean.ToLocalChecked()->BooleanValue(isolate->GetCurrentContext()).ToChecked(); + return BooleanValue(isolate, maybeBoolean.ToLocalChecked()); /* How important is this return? */ }); @@ -182,8 +182,8 @@ struct HttpResponseWrapper { /* This is a quick fix, it will need updating in µWS later on */ Local array = Array::New(isolate, 2); - array->Set(0, Boolean::New(isolate, ok)); - array->Set(1, Boolean::New(isolate, hasResponded)); + array->Set(isolate->GetCurrentContext(), 0, Boolean::New(isolate, ok)).ToChecked(); + array->Set(isolate->GetCurrentContext(), 1, Boolean::New(isolate, hasResponded)).ToChecked(); args.GetReturnValue().Set(array); } @@ -241,25 +241,25 @@ struct HttpResponseWrapper { static void initResTemplate() { Local resTemplateLocal = FunctionTemplate::New(isolate); if (SSL) { - resTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLHttpResponse")); + resTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLHttpResponse", NewStringType::kNormal).ToLocalChecked()); } else { - resTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.HttpResponse")); + resTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.HttpResponse", NewStringType::kNormal).ToLocalChecked()); } resTemplateLocal->InstanceTemplate()->SetInternalFieldCount(1); /* Register our functions */ - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "writeStatus"), FunctionTemplate::New(isolate, res_writeStatus)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end"), FunctionTemplate::New(isolate, res_end)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "tryEnd"), FunctionTemplate::New(isolate, res_tryEnd)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "write"), FunctionTemplate::New(isolate, res_write)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "writeHeader"), FunctionTemplate::New(isolate, res_writeHeader)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close"), FunctionTemplate::New(isolate, res_close)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getWriteOffset"), FunctionTemplate::New(isolate, res_getWriteOffset)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onWritable"), FunctionTemplate::New(isolate, res_onWritable)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onAborted"), FunctionTemplate::New(isolate, res_onAborted)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onData"), FunctionTemplate::New(isolate, res_onData)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress"), FunctionTemplate::New(isolate, res_getRemoteAddress)); - resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "experimental_cork"), FunctionTemplate::New(isolate, res_cork)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "writeStatus", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_writeStatus)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_end)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "tryEnd", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_tryEnd)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "write", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_write)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "writeHeader", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_writeHeader)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_close)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getWriteOffset", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getWriteOffset)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onWritable", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_onWritable)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onAborted", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_onAborted)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onData", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_onData)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddress)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "experimental_cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork)); /* Create our template */ Local resObjectLocal = resTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); diff --git a/src/Utilities.h b/src/Utilities.h index fb33b4a..9c5f998 100644 --- a/src/Utilities.h +++ b/src/Utilities.h @@ -36,7 +36,7 @@ public: bool isInvalid(const FunctionCallbackInfo &args) { if (invalid) { - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Text and data can only be passed by String, ArrayBuffer or TypedArray."))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Text and data can only be passed by String, ArrayBuffer or TypedArray.", NewStringType::kNormal).ToLocalChecked())); } return invalid; } diff --git a/src/WebSocketWrapper.h b/src/WebSocketWrapper.h index 80e19ec..bc47669 100644 --- a/src/WebSocketWrapper.h +++ b/src/WebSocketWrapper.h @@ -12,7 +12,7 @@ struct WebSocketWrapper { static inline uWS::WebSocket *getWebSocket(const FunctionCallbackInfo &args) { auto *ws = (uWS::WebSocket *) args.Holder()->GetAlignedPointerFromInternalField(0); if (!ws) { - args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of closed uWS.WebSocket/SSLWebSocket."))); + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of closed uWS.WebSocket/SSLWebSocket.", NewStringType::kNormal).ToLocalChecked())); } return ws; } @@ -55,7 +55,7 @@ struct WebSocketWrapper { if (ws) { NativeString topic(isolate, args[0]); NativeString message(isolate, args[1]); - ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate->GetCurrentContext()).ToChecked()); + ws->publish(topic.getString(), message.getString(), BooleanValue(isolate, args[2]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[3])); } } @@ -124,7 +124,7 @@ struct WebSocketWrapper { return; } - bool ok = ws->send(message.getString(), args[1]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate->GetCurrentContext()).ToChecked()); + bool ok = ws->send(message.getString(), BooleanValue(isolate, args[1]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[2])); args.GetReturnValue().Set(Boolean::New(isolate, ok)); } @@ -134,21 +134,21 @@ struct WebSocketWrapper { static void initWsTemplate() { Local wsTemplateLocal = FunctionTemplate::New(isolate); if (SSL) { - wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLWebSocket")); + wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLWebSocket", NewStringType::kNormal).ToLocalChecked()); } else { - wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.WebSocket")); + wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.WebSocket", NewStringType::kNormal).ToLocalChecked()); } wsTemplateLocal->InstanceTemplate()->SetInternalFieldCount(1); /* Register our functions */ - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send"), FunctionTemplate::New(isolate, uWS_WebSocket_send)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end"), FunctionTemplate::New(isolate, uWS_WebSocket_end)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close"), FunctionTemplate::New(isolate, uWS_WebSocket_close)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getBufferedAmount"), FunctionTemplate::New(isolate, uWS_WebSocket_getBufferedAmount)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress"), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddress)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe"), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribe"), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribe)); - wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish"), FunctionTemplate::New(isolate, uWS_WebSocket_publish)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_send)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_end)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_close)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getBufferedAmount", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getBufferedAmount)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddress)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribe)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_publish)); /* Create the template */ Local wsObjectLocal = wsTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); diff --git a/src/addon.cpp b/src/addon.cpp index 000f015..646df04 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -31,6 +31,18 @@ bool valid = true; std::vector> apps; std::vector> sslApps; +/* Compatibility for V8 7.0 and earlier */ +#include +bool BooleanValue(Isolate *isolate, Local value) { + #if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0) + /* Old */ + return value->BooleanValue(isolate->GetCurrentContext()).ToChecked(); + #else + /* Node.js 12, 13 */ + return value->BooleanValue(isolate); + #endif +} + #include "Utilities.h" #include "WebSocketWrapper.h" #include "HttpResponseWrapper.h" @@ -71,20 +83,20 @@ void Main(Local exports) { uWS::Loop::get(uv_default_loop()); /* 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()); - exports->Set(String::NewFromUtf8(isolate, "free"), FunctionTemplate::New(isolate, uWS_free)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "App", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()).ToChecked(); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "SSLApp", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()).ToChecked(); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "free", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_free)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()).ToChecked(); /* Expose some µSockets functions directly under uWS namespace */ - exports->Set(String::NewFromUtf8(isolate, "us_listen_socket_close"), FunctionTemplate::New(isolate, uWS_us_listen_socket_close)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "us_listen_socket_close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_us_listen_socket_close)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()).ToChecked(); /* Compression enum */ - exports->Set(String::NewFromUtf8(isolate, "DISABLED"), Integer::NewFromUnsigned(isolate, uWS::DISABLED)); - exports->Set(String::NewFromUtf8(isolate, "SHARED_COMPRESSOR"), Integer::NewFromUnsigned(isolate, uWS::SHARED_COMPRESSOR)); - exports->Set(String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR"), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR)); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DISABLED", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DISABLED)).ToChecked(); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "SHARED_COMPRESSOR", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::SHARED_COMPRESSOR)).ToChecked(); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR)).ToChecked(); /* Listen options */ - exports->Set(String::NewFromUtf8(isolate, "LIBUS_LISTEN_EXCLUSIVE_PORT"), Integer::NewFromUnsigned(isolate, LIBUS_LISTEN_EXCLUSIVE_PORT)); + exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "LIBUS_LISTEN_EXCLUSIVE_PORT", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, LIBUS_LISTEN_EXCLUSIVE_PORT)).ToChecked(); /* The template for websockets */ WebSocketWrapper::initWsTemplate<0>();