Skip to content

Commit ff27f8e

Browse files
authored
re-add DataView support, update RecognizedString type (#1274)
1 parent 407223a commit ff27f8e

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

docs/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ export interface AppDescriptor {
4242

4343
/** Recognized string types, things C++ can read and understand as strings.
4444
* "String" does not have to mean "text", it can also be "binary".
45-
*
45+
*
4646
* Ironically, JavaScript strings are the least performant of all options, to pass or receive to/from C++.
47-
* This because we expect UTF-8, which is packed in 8-byte chars. JavaScript strings are UTF-16 internally meaning extra copies and reinterpretation are required.
48-
*
47+
* This because we expect UTF-8. JavaScript strings are Latin-1 or UTF-16 internally meaning extra copies and reinterpretation are required.
4948
* That's why all events pass data by ArrayBuffer and not JavaScript strings, as they allow zero-copy data passing.
50-
*
5149
* You can always do Buffer.from(arrayBuffer).toString(), but keeping things binary and as ArrayBuffer is preferred.
50+
*
51+
* The ArrayBufferView type includes Node.js Buffer, DataView, and TypedArray (Uint8Array, Uint16Array, ...).
5252
*/
53-
export type RecognizedString = string | ArrayBuffer | Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
53+
export type RecognizedString = string | ArrayBuffer | SharedArrayBuffer | ArrayBufferView;
5454

5555
/** A WebSocket connection that is valid from open to close event.
5656
* Read more about this in the user manual.

docs/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"files": [ "index.d.ts" ],
3+
"compilerOptions": {
4+
"lib": [ "es2017" ]
5+
},
36
"typedocOptions": {
47
"name":"uWebSockets.js v20.61.0 documentation",
58
"entryPoints": [ "index.d.ts" ],

src/Utilities.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class NativeString {
174174
allocated = true;
175175
string->WriteUtf8(isolate, data, length, nullptr, String::WriteOptions::NO_NULL_TERMINATION);
176176

177-
} else if (value->IsTypedArray()) {
177+
} else if (value->IsArrayBufferView()) { /* DataView or TypedArray */
178178
Local<ArrayBufferView> arrayBufferView = Local<ArrayBufferView>::Cast(value);
179179
auto contents = arrayBufferView->Buffer()->GetBackingStore();
180180
length = arrayBufferView->ByteLength();
@@ -196,7 +196,7 @@ class NativeString {
196196

197197
bool isInvalid(const FunctionCallbackInfo<Value> &args) {
198198
if (invalid) {
199-
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), "Text and data can only be passed by String, ArrayBuffer or TypedArray.", NewStringType::kNormal).ToLocalChecked())));
199+
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(v8::Exception::Error(String::NewFromUtf8(args.GetIsolate(), "Text and data can only be passed by String, ArrayBuffer or ArrayBufferView.", NewStringType::kNormal).ToLocalChecked())));
200200
}
201201
return invalid;
202202
}

0 commit comments

Comments
 (0)