From 3a245dd248676bf80b1f1d769f6abfc1a48ff2b1 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 12 Aug 2024 23:17:17 -0700 Subject: [PATCH] upgrade webkit (#13192) Co-authored-by: Dylan Conway Co-authored-by: Zack Radisic --- .vscode/settings.json | 1 + CMakeLists.txt | 3 +- docs/api/binary-data.md | 5 ++ src/bun.js/ConsoleObject.zig | 10 ++- src/bun.js/api/BunObject.zig | 1 + src/bun.js/api/bun/udp_socket.zig | 13 ++-- src/bun.js/base.zig | 12 ++- src/bun.js/bindings/JSBuffer.cpp | 1 + src/bun.js/bindings/KeyObject.cpp | 4 + src/bun.js/bindings/SQLClient.cpp | 11 +++ src/bun.js/bindings/bindings.cpp | 5 +- src/bun.js/bindings/bindings.zig | 73 ++++++++++--------- src/bun.js/bindings/headers-handwritten.h | 6 +- src/bun.js/bindings/helpers.h | 10 +-- .../webcore/JSDOMConvertBufferSource.h | 26 +++++++ .../bindings/webcore/JSDOMConvertWebGL.cpp | 3 + .../webcore/SerializedScriptValue.cpp | 15 +++- src/bun.js/javascript.zig | 5 +- src/bun.js/modules/NodeBufferModule.h | 10 ++- src/bun.js/modules/NodeUtilTypesModule.h | 10 ++- src/bun.js/node/types.zig | 1 + src/bun.js/test/pretty_format.zig | 65 ++++++++++------- src/bun.js/webcore/blob.zig | 61 ++++++++-------- src/defines-table.zig | 1 + src/io/io.zig | 21 ++++-- src/js/internal/primordials.js | 1 + src/string.zig | 2 +- test/harness.ts | 1 + test/js/bun/util/fuzzy-wuzzy.test.ts | 1 + test/js/bun/util/password.test.ts | 1 + test/js/node/buffer.test.js | 6 +- .../parallel/util-inspect.test.js | 7 +- test/js/web/encoding/text-decoder.test.js | 1 + test/js/web/fetch/body-stream.test.ts | 4 + test/js/web/fetch/body.test.ts | 1 + 35 files changed, 265 insertions(+), 133 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1701cb55df22e3..476f38ee4c672b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -135,6 +135,7 @@ }, "files.associations": { "*.idl": "cpp", + "array": "cpp", }, "C_Cpp.files.exclude": { "**/.vscode": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index edad1f71832088..c2dbd958fa6b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_policy(SET CMP0067 NEW) set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) set(Bun_VERSION "1.1.23") -set(WEBKIT_TAG a060f087c2232fb20d82c321d21e074e735d3261) +set(WEBKIT_TAG 1cdc5e606ad7d451853f75a068a320148385f397) set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}") message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}") @@ -1030,7 +1030,6 @@ add_compile_definitions( "LIBUS_USE_BORINGSSL=1" "WITH_BORINGSSL=1" "STATICALLY_LINKED_WITH_JavaScriptCore=1" - "STATICALLY_LINKED_WITH_WTF=1" "STATICALLY_LINKED_WITH_BMALLOC=1" "BUILDING_WITH_CMAKE=1" "JSC_OBJC_API_ENABLED=0" diff --git a/docs/api/binary-data.md b/docs/api/binary-data.md index 7c0be246fc8e0d..a6c752410bd98d 100644 --- a/docs/api/binary-data.md +++ b/docs/api/binary-data.md @@ -219,6 +219,11 @@ The following classes are typed arrays, along with a description of how they int --- +- [`Float16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array) +- Every two (2) bytes are interpreted as a 16-bit floating point number. Range -6.104e5 to 6.55e4. + +--- + - [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) - Every four (4) bytes are interpreted as a 32-bit floating point number. Range -3.4e38 to 3.4e38. diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index bc0af025212349..926dfb7f93a880 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/ConsoleObject.zig @@ -1175,6 +1175,7 @@ pub const Formatter = struct { .Uint16Array, .Int32Array, .Uint32Array, + .Float16Array, .Float32Array, .Float64Array, .BigInt64Array, @@ -2122,7 +2123,7 @@ pub const Formatter = struct { } }, .Array => { - const len = @as(u32, @truncate(value.getLength(this.globalThis))); + const len = value.getLength(this.globalThis); // TODO: DerivedArray does not get passed along in JSType, and it's not clear why. // if (jsType == .DerivedArray) { @@ -3087,6 +3088,13 @@ pub const Formatter = struct { @as([]align(std.meta.alignment([]u32)) u32, @alignCast(std.mem.bytesAsSlice(u32, slice))), enable_ansi_colors, ), + .Float16Array => this.writeTypedArray( + *@TypeOf(writer), + &writer, + f16, + @as([]align(std.meta.alignment([]f16)) f16, @alignCast(std.mem.bytesAsSlice(f16, slice))), + enable_ansi_colors, + ), .Float32Array => this.writeTypedArray( *@TypeOf(writer), &writer, diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index d83bb196e0bcd2..ad30c58074cf73 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -3720,6 +3720,7 @@ const HashObject = struct { .Uint16Array, .Int32Array, .Uint32Array, + .Float16Array, .Float32Array, .Float64Array, .BigInt64Array, diff --git a/src/bun.js/api/bun/udp_socket.zig b/src/bun.js/api/bun/udp_socket.zig index 3e88e568d2ce40..a443346490cd57 100644 --- a/src/bun.js/api/bun/udp_socket.zig +++ b/src/bun.js/api/bun/udp_socket.zig @@ -496,20 +496,19 @@ pub const UDPSocket = struct { }; const payload_arg = arguments.ptr[0]; - var payload = brk: { + var payload_str = JSC.ZigString.Slice.empty; + defer payload_str.deinit(); + const payload = brk: { if (payload_arg.asArrayBuffer(globalThis)) |array_buffer| { - break :brk bun.JSC.ZigString.Slice{ - .ptr = array_buffer.ptr, - .len = array_buffer.len, - }; + break :brk array_buffer.slice(); } else if (payload_arg.isString()) { - break :brk payload_arg.asString().toSlice(globalThis, bun.default_allocator); + payload_str = payload_arg.asString().toSlice(globalThis, bun.default_allocator); + break :brk payload_str.slice(); } else { globalThis.throwInvalidArguments("Expected ArrayBufferView or string as first argument", .{}); return .zero; } }; - defer payload.deinit(); var addr: std.posix.sockaddr.storage = std.mem.zeroes(std.posix.sockaddr.storage); const addr_ptr = brk: { diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index b3e89c575cfc1f..504fe02cc1636d 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -251,9 +251,9 @@ pub const JSStringList = std.ArrayList(js.JSStringRef); pub const ArrayBuffer = extern struct { ptr: [*]u8 = undefined, - offset: u32 = 0, - len: u32 = 0, - byte_len: u32 = 0, + offset: usize = 0, + len: usize = 0, + byte_len: usize = 0, typed_array_type: JSC.JSValue.JSType = .Cell, value: JSC.JSValue = JSC.JSValue.zero, shared: bool = false, @@ -1353,6 +1353,7 @@ pub const BinaryType = enum(u4) { Int8Array, Int16Array, Int32Array, + Float16Array, Float32Array, Float64Array, // DataView, @@ -1363,6 +1364,7 @@ pub const BinaryType = enum(u4) { .Buffer => .Uint8Array, // .DataView => .DataView, .Float32Array => .Float32Array, + .Float16Array => .Float16Array, .Float64Array => .Float64Array, .Int16Array => .Int16Array, .Int32Array => .Int32Array, @@ -1384,6 +1386,7 @@ pub const BinaryType = enum(u4) { .{ "Buffer", .Buffer }, // .{ "DataView", .DataView }, .{ "Float32Array", .Float32Array }, + .{ "Float16Array", .Float16Array }, .{ "Float64Array", .Float64Array }, .{ "Int16Array", .Int16Array }, .{ "Int32Array", .Int32Array }, @@ -1394,6 +1397,7 @@ pub const BinaryType = enum(u4) { .{ "arraybuffer", .ArrayBuffer }, .{ "buffer", .Buffer }, // .{ "dataview", .DataView }, + .{ "float16array", .Float16Array }, .{ "float32array", .Float32Array }, .{ "float64array", .Float64Array }, .{ "int16array", .Int16Array }, @@ -1426,7 +1430,7 @@ pub const BinaryType = enum(u4) { .Uint8Array => return JSC.ArrayBuffer.create(globalThis, bytes, .Uint8Array), // These aren't documented, but they are supported - .Uint16Array, .Uint32Array, .Int8Array, .Int16Array, .Int32Array, .Float32Array, .Float64Array => { + .Uint16Array, .Uint32Array, .Int8Array, .Int16Array, .Int32Array, .Float16Array, .Float32Array, .Float64Array => { const buffer = JSC.ArrayBuffer.create(globalThis, bytes, .ArrayBuffer); return JSC.JSValue.c(JSC.C.JSObjectMakeTypedArrayWithArrayBuffer(globalThis, this.toTypedArrayType(), buffer.asObjectRef(), null)); }, diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 8297fbd1a3ca3c..f7a68583de710f 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -2299,6 +2299,7 @@ JSC_DEFINE_HOST_FUNCTION(constructJSBuffer, (JSC::JSGlobalObject * lexicalGlobal case Int8ArrayType: case Int16ArrayType: case Int32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: diff --git a/src/bun.js/bindings/KeyObject.cpp b/src/bun.js/bindings/KeyObject.cpp index 071e627bd1765b..97b1e395a696ff 100644 --- a/src/bun.js/bindings/KeyObject.cpp +++ b/src/bun.js/bindings/KeyObject.cpp @@ -377,6 +377,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo case Int8ArrayType: case Int16ArrayType: case Int32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: @@ -939,6 +940,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob case Int8ArrayType: case Int16ArrayType: case Int32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: @@ -1272,6 +1274,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createSecretKey, (JSC::JSGlobalObject * lexi case Int8ArrayType: case Int16ArrayType: case Int32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: @@ -1328,6 +1331,7 @@ static ExceptionOr> KeyObject__GetBuffer(JSValue bufferArg) case Int8ArrayType: case Int16ArrayType: case Int32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: diff --git a/src/bun.js/bindings/SQLClient.cpp b/src/bun.js/bindings/SQLClient.cpp index c334be56f3af0e..807fffffa32085 100644 --- a/src/bun.js/bindings/SQLClient.cpp +++ b/src/bun.js/bindings/SQLClient.cpp @@ -182,6 +182,17 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } return array; } + case JSC::JSType::Float16ArrayType: { + JSC::JSFloat16Array* array = JSC::JSFloat16Array::createUninitialized(globalObject, globalObject->typedArrayStructure(TypedArrayType::TypeFloat16, false), length); + if (UNLIKELY(array == nullptr)) { + return {}; + } + + if (length > 0) { + memcpy(array->vector(), reinterpret_cast(cell.value.typed_array.data), length * 2); // sizeof(float16_t) + } + return array; + } case JSC::JSType::Float32ArrayType: { JSC::JSFloat32Array* array = JSC::JSFloat32Array::createUninitialized(globalObject, globalObject->typedArrayStructure(TypedArrayType::TypeFloat32, false), length); if (UNLIKELY(array == nullptr)) { diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 00ab1b34b6a1ba..b199d55edcc203 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -1049,6 +1049,7 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2, case Uint16ArrayType: case Int32ArrayType: case Uint32ArrayType: + case Float16ArrayType: case Float32ArrayType: case Float64ArrayType: case BigInt64ArrayType: @@ -1872,7 +1873,7 @@ extern "C" JSC__JSValue ZigString__toJSONObject(const ZigString* strPtr, JSC::JS if (str.isNull()) { // isNull() will be true for empty strings and for strings which are too long. // So we need to check the length is plausibly due to a long string. - if (strPtr->len > Bun__syntheticAllocationLimit) { + if (strPtr->len > Bun__stringSyntheticAllocationLimit) { scope.throwException(globalObject, Bun::createError(globalObject, Bun::ErrorCode::ERR_STRING_TOO_LONG, "Cannot parse a JSON string longer than 2^32-1 characters"_s)); return {}; } @@ -2026,6 +2027,7 @@ double JSC__JSValue__getLengthIfPropertyExistsInternal(JSC__JSValue value, JSC__ case JSC::JSType::Uint16ArrayType: case JSC::JSType::Int32ArrayType: case JSC::JSType::Uint32ArrayType: + case JSC::JSType::Float16ArrayType: case JSC::JSType::Float32ArrayType: case JSC::JSType::Float64ArrayType: case JSC::JSType::BigInt64ArrayType: @@ -2768,6 +2770,7 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar case JSC::JSType::Uint16ArrayType: case JSC::JSType::Int32ArrayType: case JSC::JSType::Uint32ArrayType: + case JSC::JSType::Float16ArrayType: case JSC::JSType::Float32ArrayType: case JSC::JSType::Float64ArrayType: case JSC::JSType::BigInt64ArrayType: diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index f2f74930277ee7..c9a5037bf9d8db 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3430,40 +3430,41 @@ pub const JSValue = enum(JSValueReprInt) { Uint16Array = 43, Int32Array = 44, Uint32Array = 45, - Float32Array = 46, - Float64Array = 47, - BigInt64Array = 48, - BigUint64Array = 49, - DataView = 50, - GlobalObject = 51, - GlobalLexicalEnvironment = 52, - LexicalEnvironment = 53, - ModuleEnvironment = 54, - StrictEvalActivation = 55, - WithScope = 56, - ModuleNamespaceObject = 57, - ShadowRealm = 58, - RegExpObject = 59, - JSDate = 60, - ProxyObject = 61, - JSGenerator = 62, - JSAsyncGenerator = 63, - JSArrayIterator = 64, - JSMapIterator = 65, - JSSetIterator = 66, - JSStringIterator = 67, - JSPromise = 68, - JSMap = 69, - JSSet = 70, - JSWeakMap = 71, - JSWeakSet = 72, - WebAssemblyModule = 73, - WebAssemblyInstance = 74, - WebAssemblyGCObject = 75, - StringObject = 76, - DerivedStringObject = 77, - - InternalFieldTuple, + Float16Array = 46, + Float32Array = 47, + Float64Array = 48, + BigInt64Array = 49, + BigUint64Array = 50, + DataView = 51, + GlobalObject = 52, + GlobalLexicalEnvironment = 53, + LexicalEnvironment = 54, + ModuleEnvironment = 55, + StrictEvalActivation = 56, + WithScope = 57, + ModuleNamespaceObject = 58, + ShadowRealm = 59, + RegExpObject = 60, + JSDate = 61, + ProxyObject = 62, + JSGenerator = 63, + JSAsyncGenerator = 64, + JSArrayIterator = 65, + JSMapIterator = 66, + JSSetIterator = 67, + JSStringIterator = 68, + JSPromise = 69, + JSMap = 70, + JSSet = 71, + JSWeakMap = 72, + JSWeakSet = 73, + WebAssemblyModule = 74, + WebAssemblyInstance = 75, + WebAssemblyGCObject = 76, + StringObject = 77, + DerivedStringObject = 78, + + InternalFieldTuple = 79, MaxJS = 0b11111111, Event = 0b11101111, @@ -3490,6 +3491,7 @@ pub const JSValue = enum(JSValueReprInt) { .Event, .FinalObject, .Float32Array, + .Float16Array, .Float64Array, .GlobalObject, .Int16Array, @@ -3546,6 +3548,7 @@ pub const JSValue = enum(JSValueReprInt) { .BigInt64Array, .BigUint64Array, .Float32Array, + .Float16Array, .Float64Array, .Int16Array, .Int32Array, @@ -3641,6 +3644,7 @@ pub const JSValue = enum(JSValueReprInt) { .BigInt64Array, .BigUint64Array, .Float32Array, + .Float16Array, .Float64Array, .Int16Array, .Int32Array, @@ -3682,6 +3686,7 @@ pub const JSValue = enum(JSValueReprInt) { .BigInt64Array, .BigUint64Array, .Float32Array, + .Float16Array, .Float64Array, .Int16Array, .Int32Array, diff --git a/src/bun.js/bindings/headers-handwritten.h b/src/bun.js/bindings/headers-handwritten.h index 615780ea6b781e..54efa66cfcdebc 100644 --- a/src/bun.js/bindings/headers-handwritten.h +++ b/src/bun.js/bindings/headers-handwritten.h @@ -298,9 +298,9 @@ using Uint8Array_alias = JSC::JSUint8Array; typedef struct { char* ptr; - uint32_t offset; - uint32_t len; - uint32_t byte_len; + size_t offset; + size_t len; + size_t byte_len; uint8_t cell_type; int64_t _value; bool shared; diff --git a/src/bun.js/bindings/helpers.h b/src/bun.js/bindings/helpers.h index f00e80e66da41e..ee00db842f23c2 100644 --- a/src/bun.js/bindings/helpers.h +++ b/src/bun.js/bindings/helpers.h @@ -25,7 +25,7 @@ class GlobalObject; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" -extern "C" size_t Bun__syntheticAllocationLimit; +extern "C" size_t Bun__stringSyntheticAllocationLimit; namespace Zig { @@ -86,7 +86,7 @@ static const WTF::String toString(ZigString str) if (UNLIKELY(isTaggedExternalPtr(str.ptr))) { // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__syntheticAllocationLimit)) { + if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { free_global_string(nullptr, reinterpret_cast(const_cast(untag(str.ptr))), static_cast(str.len)); return {}; } @@ -98,7 +98,7 @@ static const WTF::String toString(ZigString str) } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__syntheticAllocationLimit)) { + if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { return {}; } @@ -128,7 +128,7 @@ static const WTF::String toString(ZigString str, StringPointer ptr) } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__syntheticAllocationLimit)) { + if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { return {}; } @@ -148,7 +148,7 @@ static const WTF::String toStringCopy(ZigString str, StringPointer ptr) } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__syntheticAllocationLimit)) { + if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { return {}; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h b/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h index 211ba841158aad..0a451c5a09c412 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h @@ -47,6 +47,8 @@ struct IDLUint32Array : IDLTypedArray { }; struct IDLUint8ClampedArray : IDLTypedArray { }; +struct IDLFloat16Array : IDLTypedArray { +}; struct IDLFloat32Array : IDLTypedArray { }; struct IDLFloat64Array : IDLTypedArray { @@ -63,6 +65,7 @@ inline RefPtr toPossiblySharedUint8Array(JSC::VM& vm, JSC::JSVa inline RefPtr toPossiblySharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } inline RefPtr toPossiblySharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } inline RefPtr toPossiblySharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } +inline RefPtr toPossiblySharedFloat16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } inline RefPtr toPossiblySharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } inline RefPtr toPossiblySharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } inline RefPtr toPossiblySharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView(vm, value); } @@ -75,6 +78,7 @@ inline RefPtr toUnsharedUint8Array(JSC::VM& vm, JSC::JSValue va inline RefPtr toUnsharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } inline RefPtr toUnsharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } inline RefPtr toUnsharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } +inline RefPtr toUnsharedFloat16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } inline RefPtr toUnsharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } inline RefPtr toUnsharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } inline RefPtr toUnsharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView(vm, value); } @@ -355,6 +359,28 @@ template<> struct JSConverter { } }; +template<> struct Converter : DefaultConverter { + using WrapperType = JSC::JSFloat16Array; + using ReturnType = RefPtr; + + template + static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) + { + return Detail::BufferSourceConverter::convert(lexicalGlobalObject, value, std::forward(exceptionThrower)); + } +}; + +template<> struct JSConverter { + static constexpr bool needsState = true; + static constexpr bool needsGlobalObject = true; + + template + static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) + { + return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value)); + } +}; + template<> struct Converter : DefaultConverter { using WrapperType = JSC::JSFloat32Array; using ReturnType = RefPtr; diff --git a/src/bun.js/bindings/webcore/JSDOMConvertWebGL.cpp b/src/bun.js/bindings/webcore/JSDOMConvertWebGL.cpp index 7d45766614706b..bfcf892fe69699 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertWebGL.cpp +++ b/src/bun.js/bindings/webcore/JSDOMConvertWebGL.cpp @@ -122,6 +122,9 @@ JSValue convertToJSValue(JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& RELEASE_ASSERT(!list.hasOverflowed()); return constructArray(&globalObject, static_cast(nullptr), list); }, + [&](const RefPtr& array) { + return toJS(&lexicalGlobalObject, &globalObject, array.get()); + }, [&](const RefPtr& array) { return toJS(&lexicalGlobalObject, &globalObject, array.get()); }, diff --git a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp index c264ab8c6092e1..56aea5cfff37bf 100644 --- a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp +++ b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp @@ -250,6 +250,7 @@ enum ArrayBufferViewSubtag { Float64ArrayTag = 9, BigInt64ArrayTag = 10, BigUint64ArrayTag = 11, + Float16ArrayTag = 12, }; // static bool isTypeExposedToGlobalObject(JSC::JSGlobalObject& globalObject, SerializationTag tag) @@ -351,6 +352,7 @@ static unsigned typedArrayElementSize(ArrayBufferViewSubtag tag) return 1; case Int16ArrayTag: case Uint16ArrayTag: + case Float16ArrayTag: return 2; case Int32ArrayTag: case Uint32ArrayTag: @@ -1289,6 +1291,8 @@ class CloneSerializer : CloneBase { write(Int32ArrayTag); else if (obj->inherits()) write(Uint32ArrayTag); + else if (obj->inherits()) + write(Float16ArrayTag); else if (obj->inherits()) write(Float32ArrayTag); else if (obj->inherits()) @@ -2566,7 +2570,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) indexStack.last()++; goto objectStartVisitMember; } - mapStartState : { + mapStartState: { ASSERT(inValue.isObject()); if (inputObjectStack.size() > maximumFilterRecursion) return SerializationReturnCode::StackOverflowError; @@ -2614,7 +2618,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) goto mapDataStartVisitEntry; } - setStartState : { + setStartState: { ASSERT(inValue.isObject()); if (inputObjectStack.size() > maximumFilterRecursion) return SerializationReturnCode::StackOverflowError; @@ -3506,6 +3510,9 @@ class CloneDeserializer : CloneBase { case Uint32ArrayTag: arrayBufferView = toJS(m_lexicalGlobalObject, m_globalObject, Uint32Array::wrappedAs(arrayBuffer.releaseNonNull(), byteOffset, length).get()); return true; + case Float16ArrayTag: + arrayBufferView = toJS(m_lexicalGlobalObject, m_globalObject, Float16Array::wrappedAs(arrayBuffer.releaseNonNull(), byteOffset, length).get()); + return true; case Float32ArrayTag: arrayBufferView = toJS(m_lexicalGlobalObject, m_globalObject, Float32Array::wrappedAs(arrayBuffer.releaseNonNull(), byteOffset, length).get()); return true; @@ -5073,7 +5080,7 @@ DeserializationResult CloneDeserializer::deserialize() propertyNameStack.removeLast(); goto objectStartVisitMember; } - mapObjectStartState : { + mapObjectStartState: { if (outputObjectStack.size() > maximumFilterRecursion) return std::make_pair(JSValue(), SerializationReturnCode::StackOverflowError); JSMap* map = JSMap::create(m_lexicalGlobalObject->vm(), m_globalObject->mapStructure()); @@ -5102,7 +5109,7 @@ DeserializationResult CloneDeserializer::deserialize() goto mapDataStartVisitEntry; } - setObjectStartState : { + setObjectStartState: { if (outputObjectStack.size() > maximumFilterRecursion) return std::make_pair(JSValue(), SerializationReturnCode::StackOverflowError); JSSet* set = JSSet::create(m_lexicalGlobalObject->vm(), m_globalObject->setStructure()); diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index f1d00c0443a20d..0449756c3674f8 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1041,6 +1041,7 @@ pub const VirtualMachine = struct { if (map.get("BUN_FEATURE_FLAG_SYNTHETIC_MEMORY_LIMIT")) |value| { if (std.fmt.parseInt(usize, value, 10)) |limit| { synthetic_allocation_limit = limit; + string_allocation_limit = limit; } else |_| { Output.panic("BUN_FEATURE_FLAG_SYNTHETIC_MEMORY_LIMIT must be a positive integer", .{}); } @@ -4267,11 +4268,12 @@ export fn Bun__removeSourceProviderSourceMap(vm: *VirtualMachine, opaque_source_ pub export var isBunTest: bool = false; // TODO: evaluate if this has any measurable performance impact. -/// Defaults to 4.7 GB, which is the limit for typed arrays pub var synthetic_allocation_limit: usize = std.math.maxInt(u32); +pub var string_allocation_limit: usize = std.math.maxInt(u32); comptime { @export(synthetic_allocation_limit, .{ .name = "Bun__syntheticAllocationLimit" }); + @export(string_allocation_limit, .{ .name = "Bun__stringSyntheticAllocationLimit" }); } pub export fn Bun__setSyntheticAllocationLimitForTesting(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(JSC.conv) JSValue { @@ -4289,5 +4291,6 @@ pub export fn Bun__setSyntheticAllocationLimitForTesting(globalObject: *JSC.JSGl const limit: usize = @intCast(@max(args[0].coerceToInt64(globalObject), 1024 * 1024)); const prev = synthetic_allocation_limit; synthetic_allocation_limit = limit; + string_allocation_limit = limit; return JSValue.jsNumber(prev); } diff --git a/src/bun.js/modules/NodeBufferModule.h b/src/bun.js/modules/NodeBufferModule.h index d7f768e83884a8..d44b981967fd52 100644 --- a/src/bun.js/modules/NodeBufferModule.h +++ b/src/bun.js/modules/NodeBufferModule.h @@ -3,8 +3,10 @@ #include "root.h" #include "../bindings/JSBuffer.h" +#include "JavaScriptCore/PageCount.h" #include "_NativeModule.h" #include "wtf/SIMDUTF.h" +#include namespace Zig { using namespace WebCore; @@ -165,18 +167,18 @@ DEFINE_NATIVE_MODULE(NodeBuffer) { JSC::jsNumber(50)); put(JSC::Identifier::fromString(vm, "kMaxLength"_s), - JSC::jsNumber(4294967296LL)); + JSC::jsNumber(MAX_ARRAY_BUFFER_SIZE)); put(JSC::Identifier::fromString(vm, "kStringMaxLength"_s), - JSC::jsNumber(536870888)); + JSC::jsNumber(std::numeric_limits().max())); JSC::JSObject *constants = JSC::constructEmptyObject( lexicalGlobalObject, globalObject->objectPrototype(), 2); constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_LENGTH"_s), - JSC::jsNumber(4294967296LL)); + JSC::jsNumber(MAX_ARRAY_BUFFER_SIZE)); constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_STRING_LENGTH"_s), - JSC::jsNumber(536870888)); + JSC::jsNumber(std::numeric_limits().max())); put(JSC::Identifier::fromString(vm, "constants"_s), constants); diff --git a/src/bun.js/modules/NodeUtilTypesModule.h b/src/bun.js/modules/NodeUtilTypesModule.h index 854ee30e0c0ce7..a90fd7e6815f76 100644 --- a/src/bun.js/modules/NodeUtilTypesModule.h +++ b/src/bun.js/modules/NodeUtilTypesModule.h @@ -357,6 +357,12 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsInt32Array, GET_FIRST_CELL return JSValue::encode(jsBoolean(cell->type() == Int32ArrayType)); } +JSC_DEFINE_HOST_FUNCTION(jsFunctionIsFloat16Array, + (JSC::JSGlobalObject * globalObject, + JSC::CallFrame *callframe)) { + GET_FIRST_CELL + return JSValue::encode(jsBoolean(cell->type() == Float16ArrayType)); +} JSC_DEFINE_HOST_FUNCTION(jsFunctionIsFloat32Array, (JSC::JSGlobalObject * globalObject, JSC::CallFrame *callframe)) { @@ -418,7 +424,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsCryptoKey, namespace Zig { DEFINE_NATIVE_MODULE(NodeUtilTypes) { - INIT_NATIVE_MODULE(42); + INIT_NATIVE_MODULE(43); putNativeFn(Identifier::fromString(vm, "isExternal"_s), jsFunctionIsExternal); putNativeFn(Identifier::fromString(vm, "isDate"_s), jsFunctionIsDate); @@ -482,6 +488,8 @@ DEFINE_NATIVE_MODULE(NodeUtilTypes) { jsFunctionIsInt16Array); putNativeFn(Identifier::fromString(vm, "isInt32Array"_s), jsFunctionIsInt32Array); + putNativeFn(Identifier::fromString(vm, "isFloat16Array"_s), + jsFunctionIsFloat16Array); putNativeFn(Identifier::fromString(vm, "isFloat32Array"_s), jsFunctionIsFloat32Array); putNativeFn(Identifier::fromString(vm, "isFloat64Array"_s), diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index ba78ea8722e213..cb9b9d411b396d 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -452,6 +452,7 @@ pub const StringOrBuffer = union(enum) { .Int32Array, .Uint32Array, .Float32Array, + .Float16Array, .Float64Array, .BigInt64Array, .BigUint64Array, diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig index 4f66dc796e3086..bb690e6c144ad2 100644 --- a/src/bun.js/test/pretty_format.zig +++ b/src/bun.js/test/pretty_format.zig @@ -359,7 +359,7 @@ pub const JestPrettyFormat = struct { const Result = struct { tag: Tag, - cell: JSValue.JSType = JSValue.JSType.Cell, + cell: JSValue.JSType = .Cell, }; pub fn get(value: JSValue, globalThis: *JSGlobalObject) Result { @@ -455,36 +455,37 @@ pub const JestPrettyFormat = struct { return .{ .tag = switch (js_type) { - JSValue.JSType.ErrorInstance => .Error, - JSValue.JSType.NumberObject => .Double, - JSValue.JSType.DerivedArray, JSValue.JSType.Array => .Array, - JSValue.JSType.DerivedStringObject, JSValue.JSType.String, JSValue.JSType.StringObject => .String, - JSValue.JSType.RegExpObject => .String, - JSValue.JSType.Symbol => .Symbol, - JSValue.JSType.BooleanObject => .Boolean, - JSValue.JSType.JSFunction => .Function, - JSValue.JSType.JSWeakMap, JSValue.JSType.JSMap => .Map, - JSValue.JSType.JSWeakSet, JSValue.JSType.JSSet => .Set, - JSValue.JSType.JSDate => .JSON, - JSValue.JSType.JSPromise => .Promise, - JSValue.JSType.Object, - JSValue.JSType.FinalObject, + .ErrorInstance => .Error, + .NumberObject => .Double, + .DerivedArray, .Array => .Array, + .DerivedStringObject, .String, .StringObject => .String, + .RegExpObject => .String, + .Symbol => .Symbol, + .BooleanObject => .Boolean, + .JSFunction => .Function, + .JSWeakMap, .JSMap => .Map, + .JSWeakSet, .JSSet => .Set, + .JSDate => .JSON, + .JSPromise => .Promise, + .Object, + .FinalObject, .ModuleNamespaceObject, .GlobalObject, => .Object, .ArrayBuffer, - JSValue.JSType.Int8Array, - JSValue.JSType.Uint8Array, - JSValue.JSType.Uint8ClampedArray, - JSValue.JSType.Int16Array, - JSValue.JSType.Uint16Array, - JSValue.JSType.Int32Array, - JSValue.JSType.Uint32Array, - JSValue.JSType.Float32Array, - JSValue.JSType.Float64Array, - JSValue.JSType.BigInt64Array, - JSValue.JSType.BigUint64Array, + .Int8Array, + .Uint8Array, + .Uint8ClampedArray, + .Int16Array, + .Uint16Array, + .Int32Array, + .Uint32Array, + .Float16Array, + .Float32Array, + .Float64Array, + .BigInt64Array, + .BigUint64Array, .DataView, => .TypedArray, @@ -1371,7 +1372,7 @@ pub const JestPrettyFormat = struct { value.jsonStringify(this.globalThis, this.indent, &str); this.addForNewLine(str.length()); - if (jsType == JSValue.JSType.JSDate) { + if (jsType == .JSDate) { // in the code for printing dates, it never exceeds this amount var iso_string_buf: [36]u8 = undefined; var out_buf: []const u8 = std.fmt.bufPrint(&iso_string_buf, "{}", .{str}) catch ""; @@ -1868,6 +1869,16 @@ pub const JestPrettyFormat = struct { writer.print("{d},", .{el}); } }, + .Float16Array => { + const slice_with_type: []align(std.meta.alignment([]f16)) f16 = @alignCast(std.mem.bytesAsSlice(f16, slice)); + this.indent += 1; + defer this.indent -|= 1; + for (slice_with_type) |el| { + writer.writeAll("\n"); + this.writeIndent(Writer, writer_) catch {}; + writer.print("{d},", .{el}); + } + }, .Float32Array => { const slice_with_type: []align(std.meta.alignment([]f32)) f32 = @alignCast(std.mem.bytesAsSlice(f32, slice)); this.indent += 1; diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 4ae9cede089ccf..7185f8084916bb 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -4502,6 +4502,7 @@ pub const Blob = struct { JSC.JSValue.JSType.Uint16Array, JSC.JSValue.JSType.Int32Array, JSC.JSValue.JSType.Uint32Array, + JSC.JSValue.JSType.Float16Array, JSC.JSValue.JSType.Float32Array, JSC.JSValue.JSType.Float64Array, JSC.JSValue.JSType.BigInt64Array, @@ -4586,9 +4587,9 @@ pub const Blob = struct { switch (item.jsTypeLoose()) { .NumberObject, .Cell, - JSC.JSValue.JSType.String, - JSC.JSValue.JSType.StringObject, - JSC.JSValue.JSType.DerivedStringObject, + .String, + .StringObject, + .DerivedStringObject, => { var sliced = item.toSlice(global, bun.default_allocator); const allocator = sliced.allocator.get(); @@ -4596,19 +4597,20 @@ pub const Blob = struct { joiner.push(sliced.slice(), allocator); continue; }, - JSC.JSValue.JSType.ArrayBuffer, - JSC.JSValue.JSType.Int8Array, - JSC.JSValue.JSType.Uint8Array, - JSC.JSValue.JSType.Uint8ClampedArray, - JSC.JSValue.JSType.Int16Array, - JSC.JSValue.JSType.Uint16Array, - JSC.JSValue.JSType.Int32Array, - JSC.JSValue.JSType.Uint32Array, - JSC.JSValue.JSType.Float32Array, - JSC.JSValue.JSType.Float64Array, - JSC.JSValue.JSType.BigInt64Array, - JSC.JSValue.JSType.BigUint64Array, - JSC.JSValue.JSType.DataView, + .ArrayBuffer, + .Int8Array, + .Uint8Array, + .Uint8ClampedArray, + .Int16Array, + .Uint16Array, + .Int32Array, + .Uint32Array, + .Float16Array, + .Float32Array, + .Float64Array, + .BigInt64Array, + .BigUint64Array, + .DataView, => { could_have_non_ascii = true; var buf = item.asArrayBuffer(global).?; @@ -4651,19 +4653,20 @@ pub const Blob = struct { } }, - JSC.JSValue.JSType.ArrayBuffer, - JSC.JSValue.JSType.Int8Array, - JSC.JSValue.JSType.Uint8Array, - JSC.JSValue.JSType.Uint8ClampedArray, - JSC.JSValue.JSType.Int16Array, - JSC.JSValue.JSType.Uint16Array, - JSC.JSValue.JSType.Int32Array, - JSC.JSValue.JSType.Uint32Array, - JSC.JSValue.JSType.Float32Array, - JSC.JSValue.JSType.Float64Array, - JSC.JSValue.JSType.BigInt64Array, - JSC.JSValue.JSType.BigUint64Array, - JSC.JSValue.JSType.DataView, + .ArrayBuffer, + .Int8Array, + .Uint8Array, + .Uint8ClampedArray, + .Int16Array, + .Uint16Array, + .Int32Array, + .Uint32Array, + .Float16Array, + .Float32Array, + .Float64Array, + .BigInt64Array, + .BigUint64Array, + .DataView, => { var buf = current.asArrayBuffer(global).?; joiner.pushStatic(buf.slice()); diff --git a/src/defines-table.zig b/src/defines-table.zig index 645d7ef91382fe..8fdfeda58e52f2 100644 --- a/src/defines-table.zig +++ b/src/defines-table.zig @@ -234,6 +234,7 @@ pub const pure_global_identifiers = .{ .{ "EvalError", pure_global_identifier_define }, .{ "Event", pure_global_identifier_define }, .{ "EventTarget", pure_global_identifier_define }, + .{ "Float16Array", pure_global_identifier_define }, .{ "Float32Array", pure_global_identifier_define }, .{ "Float64Array", pure_global_identifier_define }, .{ "Int16Array", pure_global_identifier_define }, diff --git a/src/io/io.zig b/src/io/io.zig index db39594351d194..7a4f36d3c2505b 100644 --- a/src/io/io.zig +++ b/src/io/io.zig @@ -126,8 +126,14 @@ pub const Loop = struct { } }, .close => |close| { - close.poll.unregisterWithFd(this.pollfd(), close.fd); - this.active -= 1; + log("close({}, registered={any})", .{ close.fd, close.poll.flags.contains(.registered) }); + // Only remove from the interest list if it was previously registered. + // Otherwise, epoll gets confused. + // This state can happen if polling for readable/writable previously failed. + if (close.poll.flags.contains(.was_ever_registered)) { + close.poll.unregisterWithFd(this.pollfd(), close.fd); + this.active -= 1; + } close.onDone(close.ctx); }, } @@ -566,7 +572,6 @@ pub const Poll = struct { fd.cast(), null, ); - this.flags.remove(.was_ever_registered); this.flags.remove(.registered); } @@ -644,7 +649,7 @@ pub const Poll = struct { var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @intFromPtr(Pollable.init(tag, this).ptr()) } }; - const op: u32 = if (this.flags.contains(.registered) or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD; + const op: u32 = if (this.flags.contains(.was_ever_registered) or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD; const ctl = linux.epoll_ctl( watcher_fd.cast(), @@ -652,11 +657,15 @@ pub const Poll = struct { fd.cast(), &event, ); - this.flags.insert(.registered); - this.flags.insert(.was_ever_registered); + if (JSC.Maybe(void).errnoSys(ctl, .epoll_ctl)) |errno| { return errno; } + // Only mark if it successfully registered. + // If it failed to register, we don't want to unregister it later if + // it never had done so in the first place. + this.flags.insert(.registered); + this.flags.insert(.was_ever_registered); } else { @compileError("epoll not supported on this platform"); } diff --git a/src/js/internal/primordials.js b/src/js/internal/primordials.js index 8293100b841b8f..59baa9e058277e 100644 --- a/src/js/internal/primordials.js +++ b/src/js/internal/primordials.js @@ -208,6 +208,7 @@ export default { Int8Array, Int16Array, Int32Array, + Float16Array, Float32Array, Float64Array, BigUint64Array, diff --git a/src/string.zig b/src/string.zig index e7cfbc505b52ef..f5f84a699116e0 100644 --- a/src/string.zig +++ b/src/string.zig @@ -645,7 +645,7 @@ pub const String = extern struct { /// Max WTFStringImpl length. /// **Not** in bytes. In characters. pub inline fn max_length() usize { - return JSC.synthetic_allocation_limit; + return JSC.string_allocation_limit; } /// If the allocation fails, this will free the bytes and return a dead string. diff --git a/test/harness.ts b/test/harness.ts index 638248f6c0d03c..df1d547def8fee 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -296,6 +296,7 @@ const binaryTypes = { "int8array": Int8Array, "int16array": Int16Array, "int32array": Int32Array, + "float16array": Float16Array, "float32array": Float32Array, "float64array": Float64Array, } as const; diff --git a/test/js/bun/util/fuzzy-wuzzy.test.ts b/test/js/bun/util/fuzzy-wuzzy.test.ts index 34e4859a401171..1af4e30697ac7f 100644 --- a/test/js/bun/util/fuzzy-wuzzy.test.ts +++ b/test/js/bun/util/fuzzy-wuzzy.test.ts @@ -136,6 +136,7 @@ const ignoreList = [ Int8Array.prototype, Int16Array.prototype, Int32Array.prototype, + Float16Array.prototype, Float32Array.prototype, Float64Array.prototype, BigInt64Array.prototype, diff --git a/test/js/bun/util/password.test.ts b/test/js/bun/util/password.test.ts index b84a10e45473e0..632fa334e8f2f5 100644 --- a/test/js/bun/util/password.test.ts +++ b/test/js/bun/util/password.test.ts @@ -87,6 +87,7 @@ describe("hash", () => { Int8Array, Int16Array, Int32Array, + Float16Array, Float32Array, Float64Array, ArrayBuffer, diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index 00602e0a2df1f7..860a3f76c55e57 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -1862,9 +1862,9 @@ it("Buffer can be mocked", () => { it("constants", () => { expect(BufferModule.constants.MAX_LENGTH).toBe(4294967296); - expect(BufferModule.constants.MAX_STRING_LENGTH).toBe(536870888); + expect(BufferModule.constants.MAX_STRING_LENGTH).toBe(4294967295); expect(BufferModule.default.constants.MAX_LENGTH).toBe(4294967296); - expect(BufferModule.default.constants.MAX_STRING_LENGTH).toBe(536870888); + expect(BufferModule.default.constants.MAX_STRING_LENGTH).toBe(4294967295); }); it("File", () => { @@ -2438,6 +2438,8 @@ it("Buffer.byteLength()", () => { expect(Buffer.byteLength(int32)).toBe(32); const uint32 = new Uint32Array(8); expect(Buffer.byteLength(uint32)).toBe(32); + const float16 = new Float16Array(8); + expect(Buffer.byteLength(float16)).toBe(16); const float32 = new Float32Array(8); expect(Buffer.byteLength(float32)).toBe(32); const float64 = new Float64Array(8); diff --git a/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js b/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js index 93d032ea407f4f..be3f2123b842be 100644 --- a/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js +++ b/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js @@ -239,6 +239,7 @@ test("inspect from a different context", () => { test("no assertion failures 2", () => { [ + Float16Array, Float32Array, Float64Array, Int16Array, @@ -270,6 +271,7 @@ test("no assertion failures 2", () => { // Now check that declaring a TypedArray in a different context works the same. [ + Float16Array, Float32Array, Float64Array, Int16Array, @@ -2065,6 +2067,7 @@ test("no assertion failures 3", () => { [new Int8Array(2), "[Int8Array(2): null prototype] [ 0, 0 ]"], [new Int16Array(2), "[Int16Array(2): null prototype] [ 0, 0 ]"], [new Int32Array(2), "[Int32Array(2): null prototype] [ 0, 0 ]"], + [new Float16Array(2), "[Float16Array(2): null prototype] [ 0, 0 ]"], [new Float32Array(2), "[Float32Array(2): null prototype] [ 0, 0 ]"], [new Float64Array(2), "[Float64Array(2): null prototype] [ 0, 0 ]"], [new BigInt64Array(2), "[BigInt64Array(2): null prototype] [ 0n, 0n ]"], @@ -2658,6 +2661,7 @@ test("no assertion failures 3", () => { "_", "_error", "util", + "Float16Array", ]; out = util.inspect(obj, { compact: 3, breakLength: 80, maxArrayLength: 250 }); @@ -2699,7 +2703,8 @@ test("no assertion failures 3", () => { " 'string_decoder', 'tls', 'trace_events',", " 'tty', 'url', 'v8',", " 'vm', 'worker_threads', 'zlib',", - " '_', '_error', 'util'", + " '_', '_error', 'util',", + " 'Float16Array'", "]", ].join("\n"); diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js index 91bba95b7e691c..a392f52d9d78db 100644 --- a/test/js/web/encoding/text-decoder.test.js +++ b/test/js/web/encoding/text-decoder.test.js @@ -185,6 +185,7 @@ describe("TextDecoder", () => { Int8Array, Int16Array, Int32Array, + Float16Array, Float32Array, Float64Array, DataView, diff --git a/test/js/web/fetch/body-stream.test.ts b/test/js/web/fetch/body-stream.test.ts index 57ce950be8be00..5d06ba4eb28d35 100644 --- a/test/js/web/fetch/body-stream.test.ts +++ b/test/js/web/fetch/body-stream.test.ts @@ -257,6 +257,7 @@ describe("reader", function () { new Int16Array(bytes), new Int32Array(bytes), + new Float16Array(bytes), new Float32Array(bytes), // make sure we handle subarray() as expected when reading @@ -265,10 +266,13 @@ describe("reader", function () { new Int16Array(bytes).subarray(0, new Int16Array(bytes).byteLength - 1), new Int32Array(bytes).subarray(1), new Int32Array(bytes).subarray(0, new Int32Array(bytes).byteLength - 1), + new Float16Array(bytes).subarray(1), + new Float16Array(bytes).subarray(0, new Float16Array(bytes).byteLength - 1), new Float32Array(bytes).subarray(1), new Float32Array(bytes).subarray(0, new Float32Array(bytes).byteLength - 1), new Int16Array(bytes).subarray(0, 1), new Int32Array(bytes).subarray(0, 1), + new Float16Array(bytes).subarray(0, 1), new Float32Array(bytes).subarray(0, 1), ]) { gc(); diff --git a/test/js/web/fetch/body.test.ts b/test/js/web/fetch/body.test.ts index a26b0784501fd6..41c1b27a67d9e6 100644 --- a/test/js/web/fetch/body.test.ts +++ b/test/js/web/fetch/body.test.ts @@ -28,6 +28,7 @@ const bufferTypes = [ Int8Array, Int16Array, Int32Array, + Float16Array, Float32Array, Float64Array, ];