Compare commits

...

5 Commits

Author SHA1 Message Date
Dylan Conway
10d683c110 Update CMakeLists.txt 2024-08-09 00:24:06 -07:00
Dylan Conway
cc453f89d7 2 2024-08-07 02:08:45 -07:00
Dylan Conway
91feb36e91 update c api usage 2024-08-07 00:44:20 -07:00
Dylan Conway
4af2b81774 bump webkit 2024-08-07 00:42:44 -07:00
Dylan Conway
cbb68b10ff Float16Array 2024-08-06 20:27:46 -07:00
34 changed files with 185 additions and 47 deletions

View File

@@ -4,7 +4,7 @@ cmake_policy(SET CMP0067 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(Bun_VERSION "1.1.22")
set(WEBKIT_TAG a060f087c2232fb20d82c321d21e074e735d3261)
set(WEBKIT_TAG db0e2ac9fb062cfb681dad67575ecc9b9dbfe6c6)
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")

View File

@@ -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.

View File

@@ -19,10 +19,11 @@ const buffer = new ArrayBuffer(64);
const arr1 = new Uint8Array(buffer);
const arr2 = new Uint16Array(buffer);
const arr3 = new Uint32Array(buffer);
const arr4 = new Float32Array(buffer);
const arr5 = new Float64Array(buffer);
const arr6 = new BigInt64Array(buffer);
const arr7 = new BigUint64Array(buffer);
const arr4 = new Float16Array(buffer);
const arr5 = new Float32Array(buffer);
const arr6 = new Float64Array(buffer);
const arr7 = new BigInt64Array(buffer);
const arr8 = new BigUint64Array(buffer);
```
---

View File

@@ -144,7 +144,7 @@ console.log(buffer.toString()); // Hello World!\n
The following JavaScript objects are supported for redirection to:
- `Buffer`, `Uint8Array`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, `Float64Array`, `ArrayBuffer`, `SharedArrayBuffer` (writes to the underlying buffer)
- `Buffer`, `Uint8Array`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float16Array`, `Float32Array`, `Float64Array`, `ArrayBuffer`, `SharedArrayBuffer` (writes to the underlying buffer)
- `Bun.file(path)`, `Bun.file(fd)` (writes to the file)
### Example: Redirect input from JavaScript objects (`<`)
@@ -163,7 +163,7 @@ console.log(result); // hello i am a response body
The following JavaScript objects are supported for redirection from:
- `Buffer`, `Uint8Array`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, `Float64Array`, `ArrayBuffer`, `SharedArrayBuffer` (reads from the underlying buffer)
- `Buffer`, `Uint8Array`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float16Array`, `Float32Array`, `Float64Array`, `ArrayBuffer`, `SharedArrayBuffer` (reads from the underlying buffer)
- `Bun.file(path)`, `Bun.file(fd)` (reads from the file)
- `Response` (reads from the body)

View File

@@ -1174,6 +1174,7 @@ pub const Formatter = struct {
.Uint16Array,
.Int32Array,
.Uint32Array,
.Float16Array,
.Float32Array,
.Float64Array,
.BigInt64Array,
@@ -3076,6 +3077,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,

View File

@@ -3720,6 +3720,7 @@ const HashObject = struct {
.Uint16Array,
.Int32Array,
.Uint32Array,
.Float16Array,
.Float32Array,
.Float64Array,
.BigInt64Array,

View File

@@ -1337,6 +1337,7 @@ pub const BinaryType = enum(u4) {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
// DataView,
@@ -1346,6 +1347,7 @@ pub const BinaryType = enum(u4) {
.ArrayBuffer => .ArrayBuffer,
.Buffer => .Uint8Array,
// .DataView => .DataView,
.Float16Array => .Float16Array,
.Float32Array => .Float32Array,
.Float64Array => .Float64Array,
.Int16Array => .Int16Array,
@@ -1367,6 +1369,7 @@ pub const BinaryType = enum(u4) {
.{ "ArrayBuffer", .ArrayBuffer },
.{ "Buffer", .Buffer },
// .{ "DataView", .DataView },
.{ "Float16Array", .Float16Array },
.{ "Float32Array", .Float32Array },
.{ "Float64Array", .Float64Array },
.{ "Int16Array", .Int16Array },
@@ -1378,6 +1381,7 @@ pub const BinaryType = enum(u4) {
.{ "arraybuffer", .ArrayBuffer },
.{ "buffer", .Buffer },
// .{ "dataview", .DataView },
.{ "float16array", .Float16Array },
.{ "float32array", .Float32Array },
.{ "float64array", .Float64Array },
.{ "int16array", .Int16Array },
@@ -1410,7 +1414,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));
},

View File

@@ -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:

View File

@@ -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<Vector<uint8_t>> KeyObject__GetBuffer(JSValue bufferArg)
case Int8ArrayType:
case Int16ArrayType:
case Int32ArrayType:
case Float16ArrayType:
case Float32ArrayType:
case Float64ArrayType:
case BigInt64ArrayType:

View File

@@ -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<void*>(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)) {

View File

@@ -1038,6 +1038,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:
@@ -1993,6 +1994,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:
@@ -2732,6 +2734,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:

View File

@@ -3374,40 +3374,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,
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,
InternalFieldTuple = 79,
MaxJS = 0b11111111,
Event = 0b11101111,
@@ -3433,6 +3434,7 @@ pub const JSValue = enum(JSValueReprInt) {
.ErrorInstance,
.Event,
.FinalObject,
.Float16Array,
.Float32Array,
.Float64Array,
.GlobalObject,
@@ -3489,6 +3491,7 @@ pub const JSValue = enum(JSValueReprInt) {
.ArrayBuffer,
.BigInt64Array,
.BigUint64Array,
.Float16Array,
.Float32Array,
.Float64Array,
.Int16Array,
@@ -3504,6 +3507,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub fn toC(this: JSType) C_API.JSTypedArrayType {
bun.debugAssert(this != .Float16Array);
return switch (this) {
.Int8Array => .kJSTypedArrayTypeInt8Array,
.Int16Array => .kJSTypedArrayTypeInt16Array,
@@ -3584,6 +3588,7 @@ pub const JSValue = enum(JSValueReprInt) {
.ArrayBuffer,
.BigInt64Array,
.BigUint64Array,
.Float16Array,
.Float32Array,
.Float64Array,
.Int16Array,
@@ -3625,6 +3630,7 @@ pub const JSValue = enum(JSValueReprInt) {
.ArrayBuffer,
.BigInt64Array,
.BigUint64Array,
.Float16Array,
.Float32Array,
.Float64Array,
.Int16Array,

View File

@@ -47,6 +47,8 @@ struct IDLUint32Array : IDLTypedArray<JSC::Uint32Array> {
};
struct IDLUint8ClampedArray : IDLTypedArray<JSC::Uint8ClampedArray> {
};
struct IDLFloat16Array : IDLTypedArray<JSC::Float16Array> {
};
struct IDLFloat32Array : IDLTypedArray<JSC::Float32Array> {
};
struct IDLFloat64Array : IDLTypedArray<JSC::Float64Array> {
@@ -63,6 +65,7 @@ inline RefPtr<JSC::Uint8Array> toPossiblySharedUint8Array(JSC::VM& vm, JSC::JSVa
inline RefPtr<JSC::Uint8ClampedArray> toPossiblySharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Uint8ClampedAdaptor>(vm, value); }
inline RefPtr<JSC::Uint16Array> toPossiblySharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Uint16Adaptor>(vm, value); }
inline RefPtr<JSC::Uint32Array> toPossiblySharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Uint32Adaptor>(vm, value); }
inline RefPtr<JSC::Float16Array> toPossiblySharedFloat16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Float16Adaptor>(vm, value); }
inline RefPtr<JSC::Float32Array> toPossiblySharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Float32Adaptor>(vm, value); }
inline RefPtr<JSC::Float64Array> toPossiblySharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::Float64Adaptor>(vm, value); }
inline RefPtr<JSC::BigInt64Array> toPossiblySharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toPossiblySharedNativeTypedView<JSC::BigInt64Adaptor>(vm, value); }
@@ -75,6 +78,7 @@ inline RefPtr<JSC::Uint8Array> toUnsharedUint8Array(JSC::VM& vm, JSC::JSValue va
inline RefPtr<JSC::Uint8ClampedArray> toUnsharedUint8ClampedArray(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Uint8ClampedAdaptor>(vm, value); }
inline RefPtr<JSC::Uint16Array> toUnsharedUint16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Uint16Adaptor>(vm, value); }
inline RefPtr<JSC::Uint32Array> toUnsharedUint32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Uint32Adaptor>(vm, value); }
inline RefPtr<JSC::Float16Array> toUnsharedFloat16Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Float16Adaptor>(vm, value); }
inline RefPtr<JSC::Float32Array> toUnsharedFloat32Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Float32Adaptor>(vm, value); }
inline RefPtr<JSC::Float64Array> toUnsharedFloat64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::Float64Adaptor>(vm, value); }
inline RefPtr<JSC::BigInt64Array> toUnsharedBigInt64Array(JSC::VM& vm, JSC::JSValue value) { return JSC::toUnsharedNativeTypedView<JSC::BigInt64Adaptor>(vm, value); }
@@ -355,6 +359,28 @@ template<> struct JSConverter<IDLUint8ClampedArray> {
}
};
template<> struct Converter<IDLFloat16Array> : DefaultConverter<IDLFloat16Array> {
using WrapperType = JSC::JSFloat16Array;
using ReturnType = RefPtr<JSC::Float16Array>;
template<typename ExceptionThrower = DefaultExceptionThrower>
static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
{
return Detail::BufferSourceConverter<IDLFloat16Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
}
};
template<> struct JSConverter<IDLFloat16Array> {
static constexpr bool needsState = true;
static constexpr bool needsGlobalObject = true;
template<typename U>
static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value)
{
return toJS(&lexicalGlobalObject, &globalObject, Detail::getPtrOrRef(value));
}
};
template<> struct Converter<IDLFloat32Array> : DefaultConverter<IDLFloat32Array> {
using WrapperType = JSC::JSFloat32Array;
using ReturnType = RefPtr<JSC::Float32Array>;

View File

@@ -122,6 +122,9 @@ JSValue convertToJSValue(JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject&
RELEASE_ASSERT(!list.hasOverflowed());
return constructArray(&globalObject, static_cast<JSC::ArrayAllocationProfile*>(nullptr), list);
},
[&](const RefPtr<Float16Array>& array) {
return toJS(&lexicalGlobalObject, &globalObject, array.get());
},
[&](const RefPtr<Float32Array>& array) {
return toJS(&lexicalGlobalObject, &globalObject, array.get());
},

View File

@@ -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 @@ private:
write(Int32ArrayTag);
else if (obj->inherits<JSUint32Array>())
write(Uint32ArrayTag);
else if (obj->inherits<JSFloat16Array>())
write(Float16ArrayTag);
else if (obj->inherits<JSFloat32Array>())
write(Float32ArrayTag);
else if (obj->inherits<JSFloat64Array>())
@@ -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 @@ private:
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());

View File

@@ -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),

View File

@@ -451,6 +451,7 @@ pub const StringOrBuffer = union(enum) {
.Uint16Array,
.Int32Array,
.Uint32Array,
.Float16Array,
.Float32Array,
.Float64Array,
.BigInt64Array,

View File

@@ -481,6 +481,7 @@ pub const JestPrettyFormat = struct {
JSValue.JSType.Uint16Array,
JSValue.JSType.Int32Array,
JSValue.JSType.Uint32Array,
JSValue.JSType.Float16Array,
JSValue.JSType.Float32Array,
JSValue.JSType.Float64Array,
JSValue.JSType.BigInt64Array,
@@ -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;

View File

@@ -4467,6 +4467,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,
@@ -4569,6 +4570,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,
@@ -4624,6 +4626,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,

View File

@@ -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 },

View File

@@ -208,6 +208,7 @@ export default {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
BigUint64Array,

View File

@@ -296,6 +296,7 @@ const binaryTypes = {
"int8array": Int8Array,
"int16array": Int16Array,
"int32array": Int32Array,
"float16Array": Float16Array,
"float32array": Float32Array,
"float64array": Float64Array,
} as const;

View File

@@ -136,6 +136,7 @@ const ignoreList = [
Int8Array.prototype,
Int16Array.prototype,
Int32Array.prototype,
Float16Array.prototype,
Float32Array.prototype,
Float64Array.prototype,
BigInt64Array.prototype,

View File

@@ -217,6 +217,7 @@ it("TypedArray prints", () => {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
]) {

View File

@@ -87,6 +87,7 @@ describe("hash", () => {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
ArrayBuffer,
@@ -160,6 +161,7 @@ describe("verify", () => {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
ArrayBuffer,

View File

@@ -19,6 +19,7 @@ const intArrays = [
Uint16Array,
Uint32Array,
Uint8ClampedArray,
Float16Array,
Float32Array,
Float64Array
];

View 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);

View File

@@ -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");

View File

@@ -41,6 +41,7 @@ for (const [value, _method] of [
[new Int8Array()],
[new Int16Array()],
[new Int32Array()],
[new Float16Array()],
[new Float32Array()],
[new Float64Array()],
[new BigInt64Array()],
@@ -92,6 +93,7 @@ test("isBoxedPrimitive", () => {
const int8Array = new Int8Array(arrayBuffer);
const int16Array = new Int16Array(arrayBuffer);
const int32Array = new Int32Array(arrayBuffer);
const float16Array = new Float16Array(arrayBuffer);
const float32Array = new Float32Array(arrayBuffer);
const float64Array = new Float64Array(arrayBuffer);
const bigInt64Array = new BigInt64Array(arrayBuffer);
@@ -106,6 +108,7 @@ test("isBoxedPrimitive", () => {
const fakeInt8Array = Object.create(Int8Array.prototype);
const fakeInt16Array = Object.create(Int16Array.prototype);
const fakeInt32Array = Object.create(Int32Array.prototype);
const fakeFloat16Array = Object.create(Float16Array.prototype);
const fakeFloat32Array = Object.create(Float32Array.prototype);
const fakeFloat64Array = Object.create(Float64Array.prototype);
const fakeBigInt64Array = Object.create(BigInt64Array.prototype);
@@ -119,6 +122,7 @@ test("isBoxedPrimitive", () => {
const stealthyInt8Array = Object.setPrototypeOf(new Int8Array(arrayBuffer), Int8Array.prototype);
const stealthyInt16Array = Object.setPrototypeOf(new Int16Array(arrayBuffer), Int16Array.prototype);
const stealthyInt32Array = Object.setPrototypeOf(new Int32Array(arrayBuffer), Int32Array.prototype);
const stealthyFloat16Array = Object.setPrototypeOf(new Float16Array(arrayBuffer), Float16Array.prototype);
const stealthyFloat32Array = Object.setPrototypeOf(new Float32Array(arrayBuffer), Float32Array.prototype);
const stealthyFloat64Array = Object.setPrototypeOf(new Float64Array(arrayBuffer), Float64Array.prototype);
const stealthyBigInt64Array = Object.setPrototypeOf(new BigInt64Array(arrayBuffer), BigInt64Array.prototype);
@@ -153,6 +157,9 @@ test("isBoxedPrimitive", () => {
int32Array,
fakeInt32Array,
stealthyInt32Array,
float16Array,
fakeFloat16Array,
stealthyFloat16Array,
float32Array,
fakeFloat32Array,
stealthyFloat32Array,
@@ -186,6 +193,8 @@ test("isBoxedPrimitive", () => {
stealthyInt16Array,
int32Array,
stealthyInt32Array,
float16Array,
stealthyFloat16Array,
float32Array,
stealthyFloat32Array,
float64Array,
@@ -211,6 +220,8 @@ test("isBoxedPrimitive", () => {
stealthyInt16Array,
int32Array,
stealthyInt32Array,
float16Array,
stealthyFloat16Array,
float32Array,
stealthyFloat32Array,
float64Array,
@@ -227,6 +238,7 @@ test("isBoxedPrimitive", () => {
isInt8Array: [int8Array, stealthyInt8Array],
isInt16Array: [int16Array, stealthyInt16Array],
isInt32Array: [int32Array, stealthyInt32Array],
isFloat16Array: [float16Array, stealthyFloat16Array],
isFloat32Array: [float32Array, stealthyFloat32Array],
isFloat64Array: [float64Array, stealthyFloat64Array],
isBigInt64Array: [bigInt64Array, stealthyBigInt64Array],

View File

@@ -89,6 +89,7 @@ function testRunInContext(
Int16Array,
Uint32Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
BigInt64Array,

View File

@@ -185,6 +185,7 @@ describe("TextDecoder", () => {
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
DataView,

View File

@@ -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();

View File

@@ -28,6 +28,7 @@ const bufferTypes = [
Int8Array,
Int16Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
];

View File

@@ -1029,6 +1029,7 @@ describe("Blob", () => {
Int16Array,
Uint32Array,
Int32Array,
Float16Array,
Float32Array,
Float64Array,
];