aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-29 22:33:37 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-29 22:33:37 -0800
commit703bee976b9961a3cccc96c371c833546f3505d9 (patch)
treece531762755f626837c593310e4264be1b1f9325 /src/bun.js/bindings/ZigGlobalObject.cpp
parenteb5105aa09767da7d015299f956ed0fdfdffb386 (diff)
downloadbun-703bee976b9961a3cccc96c371c833546f3505d9.tar.gz
bun-703bee976b9961a3cccc96c371c833546f3505d9.tar.zst
bun-703bee976b9961a3cccc96c371c833546f3505d9.zip
[breaking] Add `binaryType` option to Bun.connect & Bun.listen
This is a breaking change because the default is `Buffer`, but previously the default was `Uint8Array`. While `Buffer` is a subclass of `Uint8Array`, it still technically is a breaking change because `slice` in `Uint8Array` is not semantically identical to `slice` in `Buffer` cc @colinhacks, the .d.ts changes I made here aren't great.
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 9f6a13b40..bfd775cde 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -970,10 +970,13 @@ extern "C" JSC__JSValue Bun__createArrayBufferForCopy(JSC::JSGlobalObject* globa
RELEASE_AND_RETURN(scope, JSValue::encode(JSC::JSArrayBuffer::create(globalObject->vm(), globalObject->arrayBufferStructure(JSC::ArrayBufferSharingMode::Default), WTFMove(arrayBuffer))));
}
-extern "C" JSC__JSValue Bun__createUint8ArrayForCopy(JSC::JSGlobalObject* globalObject, const void* ptr, size_t len)
+extern "C" JSC__JSValue Bun__createUint8ArrayForCopy(JSC::JSGlobalObject* globalObject, const void* ptr, size_t len, bool isBuffer)
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
- JSC::JSUint8Array* array = JSC::JSUint8Array::createUninitialized(globalObject, globalObject->m_typedArrayUint8.get(globalObject), len);
+ JSC::JSUint8Array* array = JSC::JSUint8Array::createUninitialized(
+ globalObject,
+ isBuffer ? reinterpret_cast<Zig::GlobalObject*>(globalObject)->JSBufferSubclassStructure() : globalObject->m_typedArrayUint8.get(globalObject),
+ len);
if (UNLIKELY(!array)) {
JSC::throwOutOfMemoryError(globalObject, scope);