Port to Node.js 10, 11 and 12
This commit is contained in:
parent
3f00f89ee6
commit
f4bc7b38d1
@ -28,13 +28,13 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
Local<Object> behaviorObject = Local<Object>::Cast(args[1]);
|
||||
|
||||
/* maxPayloadLength */
|
||||
behavior.maxPayloadLength = behaviorObject->Get(String::NewFromUtf8(isolate, "maxPayloadLength"))->Int32Value();
|
||||
behavior.maxPayloadLength = behaviorObject->Get(String::NewFromUtf8(isolate, "maxPayloadLength"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
|
||||
/* idleTimeout */
|
||||
behavior.idleTimeout = behaviorObject->Get(String::NewFromUtf8(isolate, "idleTimeout"))->Int32Value();
|
||||
behavior.idleTimeout = behaviorObject->Get(String::NewFromUtf8(isolate, "idleTimeout"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
|
||||
/* Compression, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */
|
||||
behavior.compression = (uWS::CompressOptions) behaviorObject->Get(String::NewFromUtf8(isolate, "compression"))->Int32Value();
|
||||
behavior.compression = (uWS::CompressOptions) behaviorObject->Get(String::NewFromUtf8(isolate, "compression"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
|
||||
/* Open */
|
||||
openPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "open"))));
|
||||
@ -66,7 +66,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
Local<Function> openLf = Local<Function>::New(isolate, openPf);
|
||||
if (!openLf->IsUndefined()) {
|
||||
Local<Value> argv[] = {wsObject, reqObject};
|
||||
openLf->Call(isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
openLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
}
|
||||
};
|
||||
|
||||
@ -81,7 +81,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
Local<Value> argv[3] = {Local<Object>::New(isolate, *(perSocketData->socketPf)),
|
||||
messageArrayBuffer,
|
||||
Boolean::New(isolate, opCode == uWS::OpCode::BINARY)};
|
||||
Local<Function>::New(isolate, messagePf)->Call(isolate->GetCurrentContext()->Global(), 3, argv);
|
||||
Local<Function>::New(isolate, messagePf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv);
|
||||
|
||||
/* 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<Value> &args) {
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))
|
||||
};
|
||||
Local<Function>::New(isolate, drainPf)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
|
||||
Local<Function>::New(isolate, drainPf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv);
|
||||
};
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
Local<Function> closeLf = Local<Function>::New(isolate, closePf);
|
||||
if (!closeLf->IsUndefined()) {
|
||||
Local<Value> argv[3] = {wsObject, Integer::New(isolate, code), messageArrayBuffer};
|
||||
closeLf->Call(isolate->GetCurrentContext()->Global(), 3, argv);
|
||||
closeLf->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 3, argv);
|
||||
}
|
||||
|
||||
delete perSocketData->socketPf;
|
||||
@ -163,7 +163,7 @@ void uWS_App_get(F f, const FunctionCallbackInfo<Value> &args) {
|
||||
reqObject->SetAlignedPointerInInternalField(0, req);
|
||||
|
||||
Local<Value> argv[] = {resObject, reqObject};
|
||||
Local<Function>::New(isolate, *pf)->Call(isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
Local<Function>::New(isolate, *pf)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
/* Properly invalidate req */
|
||||
reqObject->SetAlignedPointerInInternalField(0, nullptr);
|
||||
@ -190,7 +190,7 @@ void uWS_App_listen(const FunctionCallbackInfo<Value> &args) {
|
||||
auto cb = [&args](auto *token) {
|
||||
/* Return a false boolean if listen failed */
|
||||
Local<Value> argv[] = {token ? Local<Value>::Cast(External::New(isolate, token)) : Local<Value>::Cast(Boolean::New(isolate, false))};
|
||||
Local<Function>::Cast(args[args.Length() - 1])->Call(isolate->GetCurrentContext()->Global(), 1, argv);
|
||||
Local<Function>::Cast(args[args.Length() - 1])->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv);
|
||||
};
|
||||
|
||||
/* Host is first, if present */
|
||||
@ -277,7 +277,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
|
||||
}
|
||||
|
||||
/* ssl_prefer_low_memory_usage */
|
||||
ssl_options.ssl_prefer_low_memory_usage = Local<Object>::Cast(args[0])->Get(String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage"))->BooleanValue();
|
||||
ssl_options.ssl_prefer_low_memory_usage = Local<Object>::Cast(args[0])->Get(String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage"))->BooleanValue(isolate->GetCurrentContext()).ToChecked();
|
||||
}
|
||||
|
||||
app = new APP(ssl_options);
|
||||
@ -341,7 +341,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ws"), FunctionTemplate::New(isolate, uWS_App_ws<APP>));
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "listen"), FunctionTemplate::New(isolate, uWS_App_listen<APP>));
|
||||
|
||||
Local<Object> localApp = appTemplate->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
Local<Object> localApp = appTemplate->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
localApp->SetAlignedPointerInInternalField(0, app);
|
||||
|
||||
/* Add this to our delete list */
|
||||
|
@ -25,7 +25,7 @@ struct HttpRequestWrapper {
|
||||
for (auto p : *req) {
|
||||
Local<Value> 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()->Global(), 2, argv);
|
||||
cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ struct HttpRequestWrapper {
|
||||
static void req_getParameter(const FunctionCallbackInfo<Value> &args) {
|
||||
auto *req = getHttpRequest(args);
|
||||
if (req) {
|
||||
int index = args[0]->Uint32Value();
|
||||
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()));
|
||||
@ -100,7 +100,7 @@ struct HttpRequestWrapper {
|
||||
reqTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "forEach"), FunctionTemplate::New(isolate, req_forEach));
|
||||
|
||||
/* Create the template */
|
||||
Local<Object> reqObjectLocal = reqTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
Local<Object> reqObjectLocal = reqTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
reqTemplate.Reset(isolate, reqObjectLocal);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ struct HttpResponseWrapper {
|
||||
Local<ArrayBuffer> dataArrayBuffer = ArrayBuffer::New(isolate, (void *) data.data(), data.length());
|
||||
|
||||
Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)};
|
||||
Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
dataArrayBuffer->Neuter();
|
||||
});
|
||||
@ -71,7 +71,7 @@ struct HttpResponseWrapper {
|
||||
/* Mark this resObject invalid */
|
||||
Local<Object>::New(isolate, resObject)->SetAlignedPointerInInternalField(0, nullptr);
|
||||
|
||||
Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext()->Global(), 0, nullptr);
|
||||
Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr);
|
||||
});
|
||||
|
||||
args.GetReturnValue().Set(args.Holder());
|
||||
@ -111,7 +111,7 @@ struct HttpResponseWrapper {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
Local<Value> argv[] = {Integer::NewFromUnsigned(isolate, offset)};
|
||||
return Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext()->Global(), 1, argv)->BooleanValue();
|
||||
return Local<Function>::New(isolate, p)->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv).ToLocalChecked()->BooleanValue(isolate->GetCurrentContext()).ToChecked();
|
||||
/* How important is this return? */
|
||||
});
|
||||
|
||||
@ -162,7 +162,7 @@ struct HttpResponseWrapper {
|
||||
|
||||
int totalSize = 0;
|
||||
if (args.Length() > 1) {
|
||||
totalSize = args[1]->Uint32Value();
|
||||
totalSize = args[1]->Uint32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
}
|
||||
|
||||
auto [ok, hasResponded] = res->tryEnd(data.getString(), totalSize);
|
||||
@ -222,7 +222,7 @@ struct HttpResponseWrapper {
|
||||
if (res) {
|
||||
|
||||
res->cork([cb = Local<Function>::Cast(args[0])]() {
|
||||
cb->Call(isolate->GetCurrentContext()->Global(), 0, nullptr);
|
||||
cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr);
|
||||
});
|
||||
|
||||
args.GetReturnValue().Set(args.Holder());
|
||||
@ -254,7 +254,7 @@ struct HttpResponseWrapper {
|
||||
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "experimental_cork"), FunctionTemplate::New(isolate, res_cork<SSL>));
|
||||
|
||||
/* Create our template */
|
||||
Local<Object> resObjectLocal = resTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
Local<Object> resObjectLocal = resTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
resTemplate[SSL].Reset(isolate, resObjectLocal);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ struct WebSocketWrapper {
|
||||
if (ws) {
|
||||
int code = 0;
|
||||
if (args.Length() >= 1) {
|
||||
code = args[0]->Uint32Value();
|
||||
code = args[0]->Uint32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
}
|
||||
|
||||
NativeString message(args.GetIsolate(), args[1]);
|
||||
@ -107,7 +107,7 @@ struct WebSocketWrapper {
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok = ws->send(message.getString(), args[1]->BooleanValue() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT);
|
||||
bool ok = ws->send(message.getString(), args[1]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT);
|
||||
|
||||
args.GetReturnValue().Set(Boolean::New(isolate, ok));
|
||||
}
|
||||
@ -133,7 +133,7 @@ struct WebSocketWrapper {
|
||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish"), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
|
||||
|
||||
/* Create the template */
|
||||
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
wsTemplate[SSL].Reset(isolate, wsObjectLocal);
|
||||
}
|
||||
|
||||
|
@ -77,12 +77,12 @@ void Main(Local<Object> exports) {
|
||||
});*/
|
||||
|
||||
/* uWS namespace */
|
||||
exports->Set(String::NewFromUtf8(isolate, "App"), FunctionTemplate::New(isolate, uWS_App<uWS::App>)->GetFunction());
|
||||
exports->Set(String::NewFromUtf8(isolate, "SSLApp"), FunctionTemplate::New(isolate, uWS_App<uWS::SSLApp>)->GetFunction());
|
||||
exports->Set(String::NewFromUtf8(isolate, "free"), FunctionTemplate::New(isolate, uWS_free)->GetFunction());
|
||||
exports->Set(String::NewFromUtf8(isolate, "App"), FunctionTemplate::New(isolate, uWS_App<uWS::App>)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());
|
||||
exports->Set(String::NewFromUtf8(isolate, "SSLApp"), FunctionTemplate::New(isolate, uWS_App<uWS::SSLApp>)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());
|
||||
exports->Set(String::NewFromUtf8(isolate, "free"), FunctionTemplate::New(isolate, uWS_free)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());
|
||||
|
||||
/* 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());
|
||||
exports->Set(String::NewFromUtf8(isolate, "us_listen_socket_close"), FunctionTemplate::New(isolate, uWS_us_listen_socket_close)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());
|
||||
|
||||
/* Compression enum */
|
||||
exports->Set(String::NewFromUtf8(isolate, "DISABLED"), Integer::NewFromUnsigned(isolate, uWS::DISABLED));
|
||||
|
Loading…
Reference in New Issue
Block a user