Compile with v19

This commit is contained in:
Alex Hultman 2021-04-10 21:52:39 +02:00
parent 5d6a9c5194
commit 797286515a
9 changed files with 27 additions and 89 deletions

View File

@ -33,10 +33,7 @@ struct node_version {
char *name; char *name;
char *abi; char *abi;
} versions[] = { } versions[] = {
{"v10.17.0", "64"},
{"v11.15.0", "67"},
{"v12.13.0", "72"}, {"v12.13.0", "72"},
{"v13.1.0", "79"},
{"v14.0.0", "83"}, {"v14.0.0", "83"},
{"v15.0.0", "88"} {"v15.0.0", "88"}
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Authored by Alex Hultman, 2018-2020. * Authored by Alex Hultman, 2018-2021.
* Intellectual property of third-party. * Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -35,7 +35,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0); APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
/* This one is default constructed with defaults */ /* This one is default constructed with defaults */
typename APP::WebSocketBehavior behavior = {}; typename APP::template WebSocketBehavior<PerSocketData> behavior = {};
NativeString pattern(args.GetIsolate(), args[0]); NativeString pattern(args.GetIsolate(), args[0]);
if (pattern.isInvalid(args)) { if (pattern.isInvalid(args)) {
@ -179,7 +179,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
CallJS(isolate, Local<Function>::New(isolate, messagePf), 3, argv); CallJS(isolate, Local<Function>::New(isolate, messagePf), 3, argv);
/* Important: we clear the ArrayBuffer to make sure it is not invalidly used after return */ /* Important: we clear the ArrayBuffer to make sure it is not invalidly used after return */
NeuterArrayBuffer(messageArrayBuffer); messageArrayBuffer->Detach();
}; };
} }
@ -197,7 +197,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
/* Ping handler is always optional */ /* Ping handler is always optional */
if (pingPf != Undefined(isolate)) { if (pingPf != Undefined(isolate)) {
behavior.ping = [pingPf = std::move(pingPf), isolate](auto *ws) { behavior.ping = [pingPf = std::move(pingPf), isolate](auto *ws, std::string_view message) {
HandleScope hs(isolate); HandleScope hs(isolate);
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData(); PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
@ -208,7 +208,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
/* Pong handler is always optional */ /* Pong handler is always optional */
if (pongPf != Undefined(isolate)) { if (pongPf != Undefined(isolate)) {
behavior.pong = [pongPf = std::move(pongPf), isolate](auto *ws) { behavior.pong = [pongPf = std::move(pongPf), isolate](auto *ws, std::string_view message) {
HandleScope hs(isolate); HandleScope hs(isolate);
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData(); PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
@ -239,7 +239,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
perSocketData->socketPf.Reset(); perSocketData->socketPf.Reset();
/* Again, here we clear the buffer to avoid strange bugs */ /* Again, here we clear the buffer to avoid strange bugs */
NeuterArrayBuffer(messageArrayBuffer); messageArrayBuffer->Detach();
}; };
app->template ws<PerSocketData>(std::string(pattern.getString()), std::move(behavior)); app->template ws<PerSocketData>(std::string(pattern.getString()), std::move(behavior));
@ -355,7 +355,7 @@ void uWS_App_publish(const FunctionCallbackInfo<Value> &args) {
return; return;
} }
app->publish(topic.getString(), message.getString(), BooleanValue(isolate, args[2]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[3])); app->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate));
} }
/* This one modified per-thread static strings temporarily */ /* This one modified per-thread static strings temporarily */
@ -419,7 +419,7 @@ std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallb
} }
/* ssl_prefer_low_memory_usage */ /* ssl_prefer_low_memory_usage */
options.ssl_prefer_low_memory_usage = BooleanValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()); options.ssl_prefer_low_memory_usage = optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()->BooleanValue(isolate);
} }
return {options, true}; return {options, true};

View File

@ -95,7 +95,7 @@ struct HttpRequestWrapper {
Isolate *isolate = args.GetIsolate(); Isolate *isolate = args.GetIsolate();
auto *req = getHttpRequest(args); auto *req = getHttpRequest(args);
if (req) { if (req) {
bool yield = BooleanValue(args.GetIsolate(), args[0]); bool yield = args[0]->BooleanValue(isolate);
req->setYield(yield); req->setYield(yield);
args.GetReturnValue().Set(args.Holder()); args.GetReturnValue().Set(args.Holder());

View File

@ -66,7 +66,7 @@ struct HttpResponseWrapper {
Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)}; Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)};
CallJS(isolate, Local<Function>::New(isolate, p), 2, argv); CallJS(isolate, Local<Function>::New(isolate, p), 2, argv);
NeuterArrayBuffer(dataArrayBuffer); dataArrayBuffer->Detach();
}); });
args.GetReturnValue().Set(args.Holder()); args.GetReturnValue().Set(args.Holder());
@ -181,7 +181,7 @@ struct HttpResponseWrapper {
exit(-1); exit(-1);
} }
return BooleanValue(isolate, maybeBoolean.ToLocalChecked()); return maybeBoolean.ToLocalChecked()->BooleanValue(isolate);
/* How important is this return? */ /* How important is this return? */
}); });
@ -216,7 +216,7 @@ struct HttpResponseWrapper {
bool closeConnection = false; bool closeConnection = false;
if (args.Length() >= 2) { if (args.Length() >= 2) {
closeConnection = BooleanValue(args.GetIsolate(), args[1]); closeConnection = args[1]->BooleanValue(args.GetIsolate());
} }
invalidateResObject(args); invalidateResObject(args);

View File

@ -1,5 +1,5 @@
/* /*
* Authored by Alex Hultman, 2018-2020. * Authored by Alex Hultman, 2018-2021.
* Intellectual property of third-party. * Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -25,14 +25,9 @@ using namespace v8;
#include <node.h> #include <node.h>
MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Value> *argv) { MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Value> *argv) {
if (experimental_fastcall) {
/* Fast path */
return f->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), argc, argv);
} else {
/* Slow path */ /* Slow path */
return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0}); return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0});
} }
}
struct PerSocketData { struct PerSocketData {
UniquePersistent<Object> socketPf; UniquePersistent<Object> socketPf;

View File

@ -26,9 +26,9 @@ using namespace v8;
struct WebSocketWrapper { struct WebSocketWrapper {
template <bool SSL> template <bool SSL>
static inline uWS::WebSocket<SSL, true> *getWebSocket(const FunctionCallbackInfo<Value> &args) { static inline uWS::WebSocket<SSL, true, PerSocketData> *getWebSocket(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate(); Isolate *isolate = args.GetIsolate();
auto *ws = (uWS::WebSocket<SSL, true> *) args.Holder()->GetAlignedPointerFromInternalField(0); auto *ws = (uWS::WebSocket<SSL, true, PerSocketData> *) args.Holder()->GetAlignedPointerFromInternalField(0);
if (!ws) { if (!ws) {
args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of closed uWS.WebSocket/SSLWebSocket.", NewStringType::kNormal).ToLocalChecked())); args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "Invalid access of closed uWS.WebSocket/SSLWebSocket.", NewStringType::kNormal).ToLocalChecked()));
} }
@ -49,7 +49,7 @@ struct WebSocketWrapper {
if (topic.isInvalid(args)) { if (topic.isInvalid(args)) {
return; return;
} }
bool nonStrict = args.Length() > 1 && BooleanValue(isolate, args[1]); bool nonStrict = args.Length() > 1 && args[1]->BooleanValue(isolate);
ws->subscribe(topic.getString(), nonStrict); ws->subscribe(topic.getString(), nonStrict);
} }
} }
@ -64,7 +64,7 @@ struct WebSocketWrapper {
if (topic.isInvalid(args)) { if (topic.isInvalid(args)) {
return; return;
} }
bool nonStrict = args.Length() > 1 && BooleanValue(isolate, args[1]); bool nonStrict = args.Length() > 1 && args[1]->BooleanValue(isolate);
bool success = ws->unsubscribe(topic.getString(), nonStrict); bool success = ws->unsubscribe(topic.getString(), nonStrict);
args.GetReturnValue().Set(Boolean::New(isolate, success)); args.GetReturnValue().Set(Boolean::New(isolate, success));
} }
@ -89,7 +89,7 @@ struct WebSocketWrapper {
return; return;
} }
ws->publish(topic.getString(), message.getString(), BooleanValue(isolate, args[2]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[3])); ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate));
} }
} }
@ -175,7 +175,7 @@ struct WebSocketWrapper {
return; return;
} }
bool ok = ws->send(message.getString(), BooleanValue(isolate, args[1]) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, BooleanValue(isolate, args[2])); bool ok = ws->send(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate));
args.GetReturnValue().Set(Boolean::New(isolate, ok)); args.GetReturnValue().Set(Boolean::New(isolate, ok));
} }
@ -199,17 +199,6 @@ struct WebSocketWrapper {
} }
} }
/* Takes nothing, returns this */
template <bool SSL>
static void uWS_WebSocket_unsubscribeAll(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *ws = getWebSocket<SSL>(args);
if (ws) {
ws->unsubscribeAll();
args.GetReturnValue().Set(args.Holder());
}
}
/* Takes function, returns this */ /* Takes function, returns this */
template <bool SSL> template <bool SSL>
static void uWS_WebSocket_cork(const FunctionCallbackInfo<Value> &args) { static void uWS_WebSocket_cork(const FunctionCallbackInfo<Value> &args) {
@ -245,7 +234,6 @@ struct WebSocketWrapper {
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribe<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribe<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribeAll", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribeAll<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_cork<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_cork<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ping", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_ping<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ping", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_ping<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddressAsText<SSL>)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddressAsText<SSL>));

View File

@ -22,34 +22,9 @@
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
/* This one can never change for the duration of this process, so never mind per context data:ing it, yes that is a word now */
bool experimental_fastcall = 0;
#include <v8.h> #include <v8.h>
using namespace v8; using namespace v8;
/* Compatibility for V8 7.0 and earlier */
#include <v8-version.h>
bool BooleanValue(Isolate *isolate, Local<Value> 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
}
void NeuterArrayBuffer(Local<ArrayBuffer> ab) {
#if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0)
/* Old */
ab->Neuter();
#else
/* Node.js 12, 13 */
ab->Detach();
#endif
}
#include "Utilities.h" #include "Utilities.h"
#include "WebSocketWrapper.h" #include "WebSocketWrapper.h"
#include "HttpResponseWrapper.h" #include "HttpResponseWrapper.h"
@ -351,18 +326,9 @@ void uWS_unlock(const FunctionCallbackInfo<Value> &args) {
PerContextData *Main(Local<Object> exports) { PerContextData *Main(Local<Object> exports) {
/* We only care if it is defined, not what it says */
experimental_fastcall = getenv("EXPERIMENTAL_FASTCALL") != nullptr;
/* We pass isolate everywhere */ /* We pass isolate everywhere */
Isolate *isolate = exports->GetIsolate(); Isolate *isolate = exports->GetIsolate();
if (experimental_fastcall) {
/* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */
/* Settings this crashes Node.js while debugging with breakpoints */
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto);
}
/* Init the template objects, SSL and non-SSL, store it in per context data */ /* Init the template objects, SSL and non-SSL, store it in per context data */
PerContextData *perContextData = new PerContextData; PerContextData *perContextData = new PerContextData;
perContextData->isolate = isolate; perContextData->isolate = isolate;

View File

@ -1,5 +1,5 @@
/* /*
* Authored by Alex Hultman, 2018-2020. * Authored by Alex Hultman, 2018-2021.
* Intellectual property of third-party. * Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -17,15 +17,7 @@
module.exports = (() => { module.exports = (() => {
try { try {
const uWS = require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node'); return require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node');
if (process.env.EXPERIMENTAL_FASTCALL) {
process.nextTick = (f, ...args) => {
Promise.resolve().then(() => {
f(...args);
});
};
}
return uWS;
} catch (e) { } catch (e) {
throw new Error('This version of µWS is not compatible with your Node.js build:\n\n' + e.toString()); throw new Error('This version of µWS is not compatible with your Node.js build:\n\n' + e.toString());
} }

@ -1 +1 @@
Subproject commit a17a6a7268ee6d17c7aec51afa27264c1981aec6 Subproject commit 65d1498774af82b201ad15e42a43554a583de147