diff options
author | 2022-07-11 04:34:38 -0700 | |
---|---|---|
committer | 2022-07-11 04:34:38 -0700 | |
commit | d6d8c0b80dc689de05d8dfe4306e6966f6ffb07e (patch) | |
tree | b78189b9d900c1c73b1f4effab8bc6774cd4c5e2 /src | |
parent | d9491fe022779de98ccc39a2de6c1196280fac39 (diff) | |
download | bun-d6d8c0b80dc689de05d8dfe4306e6966f6ffb07e.tar.gz bun-d6d8c0b80dc689de05d8dfe4306e6966f6ffb07e.tar.zst bun-d6d8c0b80dc689de05d8dfe4306e6966f6ffb07e.zip |
Fixes https://github.com/oven-sh/bun/issues/561
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 46 | ||||
-rw-r--r-- | src/bun.js/bindings/exports.zig | 4 |
2 files changed, 36 insertions, 14 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 8c495a066..1d4c2b171 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -965,7 +965,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSUint8Array* typedArray = JSC::jsCast<JSC::JSUint8Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Uint8ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -983,7 +985,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSInt8Array* typedArray = JSC::jsCast<JSC::JSInt8Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Int8ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -993,7 +997,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSUint8ClampedArray* typedArray = JSC::jsCast<JSC::JSUint8ClampedArray*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Uint8ClampedArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1002,7 +1008,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSInt16Array* typedArray = JSC::jsCast<JSC::JSInt16Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Int16ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1011,7 +1019,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSUint16Array* typedArray = JSC::jsCast<JSC::JSUint16Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Uint16ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1020,7 +1030,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSInt32Array* typedArray = JSC::jsCast<JSC::JSInt32Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Int32ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1029,7 +1041,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSUint32Array* typedArray = JSC::jsCast<JSC::JSUint32Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Uint32ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1038,7 +1052,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSFloat32Array* typedArray = JSC::jsCast<JSC::JSFloat32Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Float32ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1047,7 +1063,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSFloat64Array* typedArray = JSC::jsCast<JSC::JSFloat64Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::Float64ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1056,7 +1074,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSBigInt64Array* typedArray = JSC::jsCast<JSC::JSBigInt64Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::BigInt64ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1065,7 +1085,9 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar JSC::JSBigUint64Array* typedArray = JSC::jsCast<JSC::JSBigUint64Array*>(value); arg2->len = typedArray->length(); arg2->byte_len = typedArray->byteLength(); - arg2->offset = typedArray->byteOffset(); + // the offset is already set by vector() + // https://github.com/oven-sh/bun/issues/561 + arg2->offset = 0; arg2->cell_type = JSC::JSType::BigUint64ArrayType; arg2->ptr = (char*)typedArray->vector(); return true; @@ -1075,7 +1097,7 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar if (JSC::JSArrayBufferView* view = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(value)) { arg2->len = view->length(); arg2->byte_len = view->byteLength(); - arg2->offset = view->byteOffset(); + arg2->offset = 0; arg2->cell_type = view->type(); arg2->ptr = (char*)view->vector(); return true; diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index d9891f394..3a00ea210 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -2141,10 +2141,10 @@ pub const ZigConsoleClient = struct { const arrayBuffer = value.asArrayBuffer(this.globalThis).?; writer.writeAll(std.mem.span(@tagName(arrayBuffer.typed_array_type))); - writer.print("({d}) [ ", .{arrayBuffer.len}); - const slice = arrayBuffer.slice(); + writer.print("({d}) [ ", .{slice.len}); + if (slice.len > 0) { writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{slice[0]}); var leftover = slice[1..]; |