Stricter callback checks for app.get
This commit is contained in:
parent
efc5a4ee72
commit
a2da9d8dd8
@ -242,14 +242,21 @@ template <typename APP, typename F>
|
|||||||
void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {
|
void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {
|
||||||
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
|
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
|
||||||
|
|
||||||
|
/* Pattern */
|
||||||
NativeString pattern(args.GetIsolate(), args[0]);
|
NativeString pattern(args.GetIsolate(), args[0]);
|
||||||
if (pattern.isInvalid(args)) {
|
if (pattern.isInvalid(args)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handler */
|
||||||
|
Callback checkedCallback(args[1]);
|
||||||
|
if (checkedCallback.isInvalid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UniquePersistent<Function> cb = checkedCallback.getFunction();
|
||||||
|
|
||||||
/* This function requires perContextData */
|
/* This function requires perContextData */
|
||||||
PerContextData *perContextData = (PerContextData *) Local<External>::Cast(args.Data())->Value();
|
PerContextData *perContextData = (PerContextData *) Local<External>::Cast(args.Data())->Value();
|
||||||
UniquePersistent<Function> cb(args.GetIsolate(), Local<Function>::Cast(args[1]));
|
|
||||||
|
|
||||||
(app->*f)(std::string(pattern.getString()), [cb = std::move(cb), perContextData](auto *res, auto *req) {
|
(app->*f)(std::string(pattern.getString()), [cb = std::move(cb), perContextData](auto *res, auto *req) {
|
||||||
Isolate *isolate = perContextData->isolate;
|
Isolate *isolate = perContextData->isolate;
|
||||||
|
@ -55,6 +55,31 @@ static constexpr int getAppTypeIndex() {
|
|||||||
return std::is_same<APP, uWS::SSLApp>::value;
|
return std::is_same<APP, uWS::SSLApp>::value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Callback {
|
||||||
|
bool invalid = false;
|
||||||
|
UniquePersistent<Function> f;
|
||||||
|
Callback(Isolate *isolate, const Local<Value> &value) {
|
||||||
|
|
||||||
|
if (!value->IsFunction()) {
|
||||||
|
invalid = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Reset(isolate, Local<Function>::Cast(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInvalid(const FunctionCallbackInfo<Value> &args) {
|
||||||
|
if (invalid) {
|
||||||
|
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(String::NewFromUtf8(args.GetIsolate(), "Passed callback is not a valid function.", NewStringType::kNormal).ToLocalChecked()));
|
||||||
|
}
|
||||||
|
return invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
UniquePersistent<Function> &&getFunction() {
|
||||||
|
return std::move(f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class NativeString {
|
class NativeString {
|
||||||
char *data;
|
char *data;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
Loading…
Reference in New Issue
Block a user