From bd9007eee067a6943db99e5c410e21bc79e138a4 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Thu, 23 Apr 2020 21:57:38 +0200 Subject: [PATCH] Support Node.js 14 --- build.c | 3 ++- src/AppWrapper.h | 4 ++-- src/HttpResponseWrapper.h | 2 +- src/addon.cpp | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/build.c b/build.c index ce686d5..4b508e2 100644 --- a/build.c +++ b/build.c @@ -36,7 +36,8 @@ struct node_version { {"v10.17.0", "64"}, {"v11.15.0", "67"}, {"v12.13.0", "72"}, - {"v13.1.0", "79"} + {"v13.1.0", "79"}, + {"v14.0.0", "83"} }; /* Downloads headers, creates folders */ diff --git a/src/AppWrapper.h b/src/AppWrapper.h index ea373da..e198ce9 100644 --- a/src/AppWrapper.h +++ b/src/AppWrapper.h @@ -114,7 +114,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { CallJS(isolate, Local::New(isolate, messagePf), 3, argv); /* Important: we clear the ArrayBuffer to make sure it is not invalidly used after return */ - messageArrayBuffer->Neuter(); + NeuterArrayBuffer(messageArrayBuffer); }; } @@ -173,7 +173,7 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { delete perSocketData->socketPf; /* Again, here we clear the buffer to avoid strange bugs */ - messageArrayBuffer->Neuter(); + NeuterArrayBuffer(messageArrayBuffer); }; app->template ws(std::string(pattern.getString()), std::move(behavior)); diff --git a/src/HttpResponseWrapper.h b/src/HttpResponseWrapper.h index 689b28b..c9099f5 100644 --- a/src/HttpResponseWrapper.h +++ b/src/HttpResponseWrapper.h @@ -49,7 +49,7 @@ struct HttpResponseWrapper { Local argv[] = {dataArrayBuffer, Boolean::New(isolate, last)}; CallJS(isolate, Local::New(isolate, p), 2, argv); - dataArrayBuffer->Neuter(); + NeuterArrayBuffer(dataArrayBuffer); }); args.GetReturnValue().Set(args.Holder()); diff --git a/src/addon.cpp b/src/addon.cpp index 210faaa..88b17e5 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -40,6 +40,16 @@ bool BooleanValue(Isolate *isolate, Local value) { #endif } +void NeuterArrayBuffer(Local 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 "WebSocketWrapper.h" #include "HttpResponseWrapper.h"