Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions src/AppWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
typename APP::template WebSocketBehavior<PerSocketData> behavior = {};

NativeString pattern(args.GetIsolate(), args[0]);
if (pattern.isInvalid(args)) {
if (pattern.isInvalid()) {
return;
}

Expand Down Expand Up @@ -320,7 +320,7 @@ void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {

/* Pattern */
NativeString pattern(args.GetIsolate(), args[0]);
if (pattern.isInvalid(args)) {
if (pattern.isInvalid()) {
return;
}

Expand All @@ -334,7 +334,7 @@ void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {
/* If the handler is String */
if (args[1]->IsArrayBuffer()) {
NativeString constantString(args.GetIsolate(), args[1]);
if (constantString.isInvalid(args)) {
if (constantString.isInvalid()) {
return;
}

Expand Down Expand Up @@ -456,7 +456,7 @@ void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {

/* Handler */
Callback checkedCallback(args.GetIsolate(), args[1]);
if (checkedCallback.isInvalid(args)) {
if (checkedCallback.isInvalid()) {
return;
}
NoexceptPersistent<Function> cb = checkedCallback.getFunction();
Expand Down Expand Up @@ -522,7 +522,7 @@ void uWS_App_listen_unix(const FunctionCallbackInfo<Value> &args) {
/* Path is last */
std::string path;
NativeString h(isolate, args[args.Length() - 1]);
if (h.isInvalid(args)) {
if (h.isInvalid()) {
return;
}
path = h.getString();
Expand Down Expand Up @@ -556,7 +556,7 @@ void uWS_App_listen(const FunctionCallbackInfo<Value> &args) {
int firstNumber = 0;
if (!args[0]->IsNumber()) {
NativeString h(isolate, args[0]);
if (h.isInvalid(args)) {
if (h.isInvalid()) {
return;
}
host = h.getString();
Expand All @@ -582,7 +582,7 @@ void uWS_App_filter(const FunctionCallbackInfo<Value> &args) {

/* Handler */
Callback checkedCallback(args.GetIsolate(), args[0]);
if (checkedCallback.isInvalid(args)) {
if (checkedCallback.isInvalid()) {
return;
}
NoexceptPersistent<Function> cb = checkedCallback.getFunction();
Expand Down Expand Up @@ -617,7 +617,7 @@ void uWS_App_domain(const FunctionCallbackInfo<Value> &args) {
}

NativeString serverName(isolate, args[0]);
if (serverName.isInvalid(args)) {
if (serverName.isInvalid()) {
return;
}

Expand All @@ -638,12 +638,12 @@ void uWS_App_publish(const FunctionCallbackInfo<Value> &args) {
}

NativeString topic(isolate, args[0]);
if (topic.isInvalid(args)) {
if (topic.isInvalid()) {
return;
}

NativeString message(isolate, args[1]);
if (message.isInvalid(args)) {
if (message.isInvalid()) {
return;
}

Expand All @@ -664,7 +664,7 @@ void uWS_App_numSubscribers(const FunctionCallbackInfo<Value> &args) {
}

NativeString topic(isolate, args[0]);
if (topic.isInvalid(args)) {
if (topic.isInvalid()) {
return;
}

Expand All @@ -680,15 +680,15 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb
if (args.Length() > index && !args[index]->IsUndefined() && !args[index]->IsNull()) {

if (!args[index]->IsObject()) {
args.GetReturnValue().Set(isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8(isolate, "Options must be an object.", NewStringType::kNormal).ToLocalChecked())));
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "Options must be an object.")));
return {};
}

Local<Object> optionsObject = Local<Object>::Cast(args[index]);

/* Key file name */
NativeString keyFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "key_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (keyFileNameValue.isInvalid(args)) {
if (keyFileNameValue.isInvalid()) {
return {};
}
if (keyFileNameValue.getString().length()) {
Expand All @@ -698,7 +698,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb

/* Cert file name */
NativeString certFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "cert_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (certFileNameValue.isInvalid(args)) {
if (certFileNameValue.isInvalid()) {
return {};
}
if (certFileNameValue.getString().length()) {
Expand All @@ -708,7 +708,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb

/* Passphrase */
NativeString passphraseValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "passphrase", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (passphraseValue.isInvalid(args)) {
if (passphraseValue.isInvalid()) {
return {};
}
if (passphraseValue.getString().length()) {
Expand All @@ -718,7 +718,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb

/* 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)) {
if (dhParamsFileNameValue.isInvalid()) {
return {};
}
if (dhParamsFileNameValue.getString().length()) {
Expand All @@ -728,7 +728,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb

/* CA file name */
NativeString caFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ca_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (caFileNameValue.isInvalid(args)) {
if (caFileNameValue.isInvalid()) {
return {};
}
if (caFileNameValue.getString().length()) {
Expand All @@ -741,7 +741,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb

/* ssl_ciphers */
NativeString sslCiphersValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_ciphers", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (sslCiphersValue.isInvalid(args)) {
if (sslCiphersValue.isInvalid()) {
return {};
}
if (sslCiphersValue.getString().length()) {
Expand All @@ -762,7 +762,7 @@ void uWS_App_adoptSocket(const FunctionCallbackInfo<Value> &args) {
int32_t fd = args[0]->Int32Value(isolate->GetCurrentContext()).ToChecked();

NativeString ip(isolate, args[1]);
if (ip.isInvalid(args)) {
if (ip.isInvalid()) {
return;
}

Expand Down Expand Up @@ -841,7 +841,7 @@ void uWS_App_addServerName(const FunctionCallbackInfo<Value> &args) {

Isolate *isolate = args.GetIsolate();
NativeString hostnamePatternValue(isolate, args[0]);
if (hostnamePatternValue.isInvalid(args)) {
if (hostnamePatternValue.isInvalid()) {
return;
}
std::string hostnamePattern;
Expand All @@ -865,7 +865,7 @@ void uWS_App_removeServerName(const FunctionCallbackInfo<Value> &args) {

Isolate *isolate = args.GetIsolate();
NativeString hostnamePatternValue(isolate, args[0]);
if (hostnamePatternValue.isInvalid(args)) {
if (hostnamePatternValue.isInvalid()) {
return;
}
std::string hostnamePattern;
Expand Down Expand Up @@ -919,7 +919,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
/* Throw if we failed to construct the app */
if (app->constructorFailed()) {
delete app;
args.GetReturnValue().Set(isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8(isolate, "App construction failed", NewStringType::kNormal).ToLocalChecked())));
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "App construction failed")));
return;
}

Expand Down Expand Up @@ -949,8 +949,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {

// 1. Ensure args[2] is an Object
if (!args[2]->IsObject()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Cache options must be an object").ToLocalChecked()));
isolate->ThrowException(v8::Exception::TypeError(String::NewFromUtf8Literal(isolate, "Cache options must be an object")));
return;
}

Expand Down Expand Up @@ -980,13 +979,13 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {

/* Pattern */
NativeString pattern(args.GetIsolate(), args[0]);
if (pattern.isInvalid(args)) {
if (pattern.isInvalid()) {
return;
}

/* Handler */
Callback checkedCallback(args.GetIsolate(), args[1]);
if (checkedCallback.isInvalid(args)) {
if (checkedCallback.isInvalid()) {
return;
}
NoexceptPersistent<Function> cb = checkedCallback.getFunction();
Expand Down
8 changes: 4 additions & 4 deletions src/HttpRequestWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct HttpRequestWrapper {
/* Thow on deleted request */
auto *req = (uWS::HttpRequest *) getInternalPointer(args.This());//->GetAlignedPointerFromInternalField(0);
if (!req) {
args.GetReturnValue().Set(isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8(isolate, "uWS.HttpRequest must not be accessed after await or route handler return. See documentation for uWS.HttpRequest and consult the user manual.", NewStringType::kNormal).ToLocalChecked())));
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "uWS.HttpRequest must not be accessed after await or route handler return. See documentation for uWS.HttpRequest and consult the user manual.")));
}

if constexpr (QUIC) {
Expand Down Expand Up @@ -72,7 +72,7 @@ struct HttpRequestWrapper {
parameter = req->getParameter(index);
} else {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}
parameter = req->getParameter(data.getString());
Expand Down Expand Up @@ -101,7 +101,7 @@ struct HttpRequestWrapper {
auto *req = getHttpRequest<QUIC>(args);
if (req) {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ struct HttpRequestWrapper {
/* Do we have a key argument? */
if (args.Length() == 1) {
NativeString<true> keyString(isolate, args[0]);
if (keyString.isInvalid(args)) {
if (keyString.isInvalid()) {
return;
}

Expand Down
20 changes: 10 additions & 10 deletions src/HttpResponseWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct HttpResponseWrapper {
Isolate *isolate = args.GetIsolate();
void *res = getInternalPointer(args.This());//->GetAlignedPointerFromInternalField(0);
if (!res) {
args.GetReturnValue().Set(isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8(isolate, "uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback, or after a successful response. See documentation for uWS.HttpResponse and consult the user manual.", NewStringType::kNormal).ToLocalChecked())));
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback, or after a successful response. See documentation for uWS.HttpResponse and consult the user manual.")));
}

if constexpr (PROTOCOL == 2) {
Expand Down Expand Up @@ -373,7 +373,7 @@ struct HttpResponseWrapper {
auto *res = getHttpResponse<SSL>(args);
if (res) {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}

Expand Down Expand Up @@ -413,7 +413,7 @@ struct HttpResponseWrapper {
auto *res = getHttpResponse<PROTOCOL>(args);
if (res) {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}

Expand All @@ -437,7 +437,7 @@ struct HttpResponseWrapper {
auto *res = getHttpResponse<PROTOCOL>(args);
if (res) {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}

Expand Down Expand Up @@ -467,7 +467,7 @@ struct HttpResponseWrapper {
auto *res = getHttpResponse<PROTOCOL>(args);
if (res) {
NativeString<true> data(args.GetIsolate(), args[0]);
if (data.isInvalid(args)) {
if (data.isInvalid()) {
return;
}
assumeCorked();
Expand Down Expand Up @@ -499,11 +499,11 @@ struct HttpResponseWrapper {
// Optimization: writeHeader never calls JS or allocated on the GC
// use zero copy string view in best case
NativeString<true> header(args.GetIsolate(), args[0]);
if (header.isInvalid(args)) {
if (header.isInvalid()) {
return;
}
NativeString<true> value(args.GetIsolate(), args[1]);
if (value.isInvalid(args)) {
if (value.isInvalid()) {
return;
}
assumeCorked();
Expand Down Expand Up @@ -543,17 +543,17 @@ struct HttpResponseWrapper {
}

NativeString secWebSocketKey(args.GetIsolate(), args[1]);
if (secWebSocketKey.isInvalid(args)) {
if (secWebSocketKey.isInvalid()) {
return;
}

NativeString secWebSocketProtocol(args.GetIsolate(), args[2]);
if (secWebSocketProtocol.isInvalid(args)) {
if (secWebSocketProtocol.isInvalid()) {
return;
}

NativeString secWebSocketExtensions(args.GetIsolate(), args[3]);
if (secWebSocketExtensions.isInvalid(args)) {
if (secWebSocketExtensions.isInvalid()) {
return;
}

Expand Down
14 changes: 5 additions & 9 deletions src/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static inline bool missingArguments(int length, const FunctionCallbackInfo<Value
std::string message = "Function requires at least ";
message += std::to_string(length);
message += " arguments.";
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), message.c_str(), NewStringType::kNormal).ToLocalChecked())));
args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), message.c_str(), NewStringType::kNormal).ToLocalChecked()));
return true;
}
return false;
Expand All @@ -156,16 +156,14 @@ struct Callback {

if (!value->IsFunction()) {
invalid = true;
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "Passed callback is not a valid function.")));
return;
}

f.Reset(isolate, Local<Function>::Cast(value));
}

bool isInvalid(const FunctionCallbackInfo<Value> &args) {
if (invalid) {
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), "Passed callback is not a valid function.", NewStringType::kNormal).ToLocalChecked())));
}
bool isInvalid() {
return invalid;
}

Expand Down Expand Up @@ -280,13 +278,11 @@ class NativeString {
data = (char *) arrayBuffer->Data();
} else {
invalid = true;
isolate->ThrowException(v8::Exception::Error(String::NewFromUtf8Literal(isolate, "Text and data can only be passed by String, ArrayBuffer or ArrayBufferView.")));
}
}

bool isInvalid(const FunctionCallbackInfo<Value> &args) {
if (invalid) {
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), "Text and data can only be passed by String, ArrayBuffer or ArrayBufferView.", NewStringType::kNormal).ToLocalChecked())));
}
bool isInvalid() {
return invalid;
}

Expand Down
Loading