Port to Nodejs 17
This commit is contained in:
parent
4b30a36b6c
commit
c680b1297b
7 changed files with 28 additions and 23 deletions
|
@ -169,7 +169,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||
behavior.message = [messagePf = std::move(messagePf), isolate](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer_New(isolate, (void *) message.data(), message.length());
|
||||
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
Local<Value> argv[3] = {Local<Object>::New(isolate, perSocketData->socketPf),
|
||||
|
@ -221,7 +221,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||
behavior.close = [closePf = std::move(closePf), isolate](auto *ws, int code, std::string_view message) {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer_New(isolate, (void *) message.data(), message.length());
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
Local<Object> wsObject = Local<Object>::New(isolate, perSocketData->socketPf);
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ struct HttpResponseWrapper {
|
|||
res->onData([p = std::move(p), isolate](std::string_view data, bool last) {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
Local<ArrayBuffer> dataArrayBuffer = ArrayBuffer::New(isolate, (void *) data.data(), data.length());
|
||||
Local<ArrayBuffer> dataArrayBuffer = ArrayBuffer_New(isolate, (void *) data.data(), data.length());
|
||||
|
||||
Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)};
|
||||
CallJS(isolate, Local<Function>::New(isolate, p), 2, argv);
|
||||
|
@ -107,7 +107,7 @@ struct HttpResponseWrapper {
|
|||
std::string_view ip = res->getRemoteAddress();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ struct HttpResponseWrapper {
|
|||
std::string_view ip = res->getRemoteAddressAsText();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ struct HttpResponseWrapper {
|
|||
std::string_view ip = res->getProxiedRemoteAddress();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ struct HttpResponseWrapper {
|
|||
std::string_view ip = res->getProxiedRemoteAddressAsText();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,11 @@ MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Va
|
|||
return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0});
|
||||
}
|
||||
|
||||
Local<v8::ArrayBuffer> ArrayBuffer_New(Isolate *isolate, void *data, size_t length) {
|
||||
std::unique_ptr<BackingStore> backingStore = ArrayBuffer::NewBackingStore(data, length, [](void* data, size_t length, void* deleter_data) {}, nullptr);
|
||||
return ArrayBuffer::New(isolate, std::shared_ptr<BackingStore>(backingStore.release()));
|
||||
}
|
||||
|
||||
struct PerSocketData {
|
||||
UniquePersistent<Object> socketPf;
|
||||
};
|
||||
|
@ -103,19 +108,19 @@ public:
|
|||
length = utf8Value->length();
|
||||
} else if (value->IsTypedArray()) {
|
||||
Local<ArrayBufferView> arrayBufferView = Local<ArrayBufferView>::Cast(value);
|
||||
ArrayBuffer::Contents contents = arrayBufferView->Buffer()->GetContents();
|
||||
auto contents = arrayBufferView->Buffer()->GetBackingStore();
|
||||
length = arrayBufferView->ByteLength();
|
||||
data = (char *) contents.Data() + arrayBufferView->ByteOffset();
|
||||
data = (char *) contents->Data() + arrayBufferView->ByteOffset();
|
||||
} else if (value->IsArrayBuffer()) {
|
||||
Local<ArrayBuffer> arrayBuffer = Local<ArrayBuffer>::Cast(value);
|
||||
ArrayBuffer::Contents contents = arrayBuffer->GetContents();
|
||||
length = contents.ByteLength();
|
||||
data = (char *) contents.Data();
|
||||
auto contents = arrayBuffer->GetBackingStore();
|
||||
length = contents->ByteLength();
|
||||
data = (char *) contents->Data();
|
||||
} else if (value->IsSharedArrayBuffer()) {
|
||||
Local<SharedArrayBuffer> arrayBuffer = Local<SharedArrayBuffer>::Cast(value);
|
||||
SharedArrayBuffer::Contents contents = arrayBuffer->GetContents();
|
||||
length = contents.ByteLength();
|
||||
data = (char *) contents.Data();
|
||||
auto contents = arrayBuffer->GetBackingStore();
|
||||
length = contents->ByteLength();
|
||||
data = (char *) contents->Data();
|
||||
} else {
|
||||
invalid = true;
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ struct WebSocketWrapper {
|
|||
std::string_view ip = ws->getRemoteAddress();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ struct WebSocketWrapper {
|
|||
std::string_view ip = ws->getRemoteAddressAsText();
|
||||
|
||||
/* Todo: we need to pass a copy here */
|
||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ void uWS_getParts(const FunctionCallbackInfo<Value> &args) {
|
|||
|
||||
std::string_view part = optionalPart.value();
|
||||
|
||||
Local<ArrayBuffer> partArrayBuffer = ArrayBuffer::New(isolate, (void *) part.data(), part.length());
|
||||
Local<ArrayBuffer> partArrayBuffer = ArrayBuffer_New(isolate, (void *) part.data(), part.length());
|
||||
/* Map is 30% faster in this case, but a static Object could be faster still */
|
||||
Local<Object> partMap = Object::New(isolate);
|
||||
partMap->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "data", NewStringType::kNormal).ToLocalChecked(), partArrayBuffer).IsNothing();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue