diff options
author | 2023-02-02 18:42:11 -0800 | |
---|---|---|
committer | 2023-02-03 14:39:07 -0800 | |
commit | 50f1dd61a6c7da5ffdaaed31472a71e8b1bd6605 (patch) | |
tree | 93572b8ddfcab11e3a8c76117d41fbe565c9f34c | |
parent | c64d7933a18b41e76fa23f50e79f19f0b2816382 (diff) | |
download | bun-50f1dd61a6c7da5ffdaaed31472a71e8b1bd6605.tar.gz bun-50f1dd61a6c7da5ffdaaed31472a71e8b1bd6605.tar.zst bun-50f1dd61a6c7da5ffdaaed31472a71e8b1bd6605.zip |
allow other ArrayBufferView in Buffer functions
-rw-r--r-- | src/bun.js/bindings/JSBuffer.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 10002b664..c985a7505 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -580,14 +580,14 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::J } auto castedThisValue = callFrame->uncheckedArgument(0); - JSC::JSUint8Array* castedThis = JSC::jsDynamicCast<JSC::JSUint8Array*>(castedThisValue); + JSC::JSArrayBufferView* castedThis = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(castedThisValue); if (UNLIKELY(!castedThis)) { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Buffer (first argument)"_s); return JSValue::encode(jsUndefined()); } auto buffer = callFrame->uncheckedArgument(1); - JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer); + JSC::JSArrayBufferView* view = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(buffer); if (UNLIKELY(!view)) { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Buffer (2nd argument)"_s); return JSValue::encode(jsUndefined()); @@ -657,8 +657,8 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::J auto targetLength = targetEnd - targetStart; auto actualLength = std::min(sourceLength, targetLength); - auto sourceStartPtr = castedThis->typedVector() + sourceStart; - auto targetStartPtr = view->typedVector() + targetStart; + auto sourceStartPtr = reinterpret_cast<unsigned char*>(castedThis->vector()) + sourceStart; + auto targetStartPtr = reinterpret_cast<unsigned char*>(view->vector()) + targetStart; auto result = actualLength > 0 ? memcmp(sourceStartPtr, targetStartPtr, actualLength) : 0; @@ -955,7 +955,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGl } auto buffer = callFrame->uncheckedArgument(0); - JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer); + JSC::JSArrayBufferView* view = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(buffer); if (UNLIKELY(!view)) { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Buffer"_s); return JSValue::encode(jsUndefined()); @@ -969,7 +969,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGl size_t a_length = castedThis->byteLength(); size_t b_length = view->byteLength(); auto sourceStartPtr = castedThis->typedVector(); - auto targetStartPtr = view->typedVector(); + auto targetStartPtr = reinterpret_cast<unsigned char*>(view->vector()); // same pointer, same length, same contents if (sourceStartPtr == targetStartPtr && a_length == b_length) |