diff options
author | 2022-04-30 23:58:27 -0700 | |
---|---|---|
committer | 2022-04-30 23:58:27 -0700 | |
commit | 92b27b338d459473fea8d8ca3b3802d02961d530 (patch) | |
tree | 11eb931c07f57d7f59e30adf1c1c4f98aa4e18ed /src/javascript/jsc | |
parent | eb129d9f9090a3a38437067d71332c91960799c1 (diff) | |
download | bun-92b27b338d459473fea8d8ca3b3802d02961d530.tar.gz bun-92b27b338d459473fea8d8ca3b3802d02961d530.tar.zst bun-92b27b338d459473fea8d8ca3b3802d02961d530.zip |
[bun.js] Implement `Buffer.from` and `Buffer.copy`
Diffstat (limited to 'src/javascript/jsc')
-rw-r--r-- | src/javascript/jsc/bindings/BunBuiltins.h | 100 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/JSBuffer.cpp | 800 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/JSBufferConstructorBuiltins.cpp | 107 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h | 122 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp | 177 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h | 27 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/WebCoreJSBuiltins.h | 4 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/builtins/js/JSBufferConstructor.js | 72 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js | 58 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers-cpp.h | 2 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers.h | 2 | ||||
-rw-r--r-- | src/javascript/jsc/ffi.exports.js | 1 |
12 files changed, 952 insertions, 520 deletions
diff --git a/src/javascript/jsc/bindings/BunBuiltins.h b/src/javascript/jsc/bindings/BunBuiltins.h index c5e22599b..63ce51bc0 100644 --- a/src/javascript/jsc/bindings/BunBuiltins.h +++ b/src/javascript/jsc/bindings/BunBuiltins.h @@ -1,99 +1 @@ -#pragma once - -namespace WebCore { - -class ExtendedDOMClientIsoSubspaces; -class ExtendedDOMIsoSubspaces; - -class DOMWrapperWorld; -} - -#include "root.h" -#include "JSBufferPrototypeBuiltins.h" - -namespace WebCore { - -class JSBuiltinFunctions { -public: - explicit JSBuiltinFunctions(JSC::VM& vm) - : m_vm(vm) - , m_jsBufferPrototypeBuiltins(m_vm) - // , m_byteLengthQueuingStrategyBuiltins(m_vm) - // , m_countQueuingStrategyBuiltins(m_vm) - // , m_readableByteStreamControllerBuiltins(m_vm) - // , m_readableByteStreamInternalsBuiltins(m_vm) - // , m_readableStreamBuiltins(m_vm) - // , m_readableStreamBYOBReaderBuiltins(m_vm) - // , m_readableStreamBYOBRequestBuiltins(m_vm) - // , m_readableStreamDefaultControllerBuiltins(m_vm) - // , m_readableStreamDefaultReaderBuiltins(m_vm) - // , m_readableStreamInternalsBuiltins(m_vm) - // , m_streamInternalsBuiltins(m_vm) - // , m_transformStreamBuiltins(m_vm) - // , m_transformStreamDefaultControllerBuiltins(m_vm) - // , m_transformStreamInternalsBuiltins(m_vm) - // , m_writableStreamDefaultControllerBuiltins(m_vm) - // , m_writableStreamDefaultWriterBuiltins(m_vm) - // , m_writableStreamInternalsBuiltins(m_vm) - // , m_jsDOMBindingInternalsBuiltins(m_vm) - // , m_textDecoderStreamBuiltins(m_vm) - // , m_textEncoderStreamBuiltins(m_vm) - { - // m_jsBufferPrototypeBuiltins.exportNames(); - - // m_readableByteStreamInternalsBuiltins.exportNames(); - // m_readableStreamInternalsBuiltins.exportNames(); - // m_streamInternalsBuiltins.exportNames(); - // m_transformStreamInternalsBuiltins.exportNames(); - // m_writableStreamInternalsBuiltins.exportNames(); - // m_jsDOMBindingInternalsBuiltins.exportNames(); - } - - // ByteLengthQueuingStrategyBuiltinsWrapper& byteLengthQueuingStrategyBuiltins() { return m_byteLengthQueuingStrategyBuiltins; } - // CountQueuingStrategyBuiltinsWrapper& countQueuingStrategyBuiltins() { return m_countQueuingStrategyBuiltins; } - // ReadableByteStreamControllerBuiltinsWrapper& readableByteStreamControllerBuiltins() { return m_readableByteStreamControllerBuiltins; } - // ReadableByteStreamInternalsBuiltinsWrapper& readableByteStreamInternalsBuiltins() { return m_readableByteStreamInternalsBuiltins; } - // ReadableStreamBuiltinsWrapper& readableStreamBuiltins() { return m_readableStreamBuiltins; } - // ReadableStreamBYOBReaderBuiltinsWrapper& readableStreamBYOBReaderBuiltins() { return m_readableStreamBYOBReaderBuiltins; } - // ReadableStreamBYOBRequestBuiltinsWrapper& readableStreamBYOBRequestBuiltins() { return m_readableStreamBYOBRequestBuiltins; } - // ReadableStreamDefaultControllerBuiltinsWrapper& readableStreamDefaultControllerBuiltins() { return m_readableStreamDefaultControllerBuiltins; } - // ReadableStreamDefaultReaderBuiltinsWrapper& readableStreamDefaultReaderBuiltins() { return m_readableStreamDefaultReaderBuiltins; } - // ReadableStreamInternalsBuiltinsWrapper& readableStreamInternalsBuiltins() { return m_readableStreamInternalsBuiltins; } - // StreamInternalsBuiltinsWrapper& streamInternalsBuiltins() { return m_streamInternalsBuiltins; } - // TransformStreamBuiltinsWrapper& transformStreamBuiltins() { return m_transformStreamBuiltins; } - // TransformStreamDefaultControllerBuiltinsWrapper& transformStreamDefaultControllerBuiltins() { return m_transformStreamDefaultControllerBuiltins; } - // TransformStreamInternalsBuiltinsWrapper& transformStreamInternalsBuiltins() { return m_transformStreamInternalsBuiltins; } - // WritableStreamDefaultControllerBuiltinsWrapper& writableStreamDefaultControllerBuiltins() { return m_writableStreamDefaultControllerBuiltins; } - // WritableStreamDefaultWriterBuiltinsWrapper& writableStreamDefaultWriterBuiltins() { return m_writableStreamDefaultWriterBuiltins; } - // WritableStreamInternalsBuiltinsWrapper& writableStreamInternalsBuiltins() { return m_writableStreamInternalsBuiltins; } - // JSDOMBindingInternalsBuiltinsWrapper& jsDOMBindingInternalsBuiltins() { return m_jsDOMBindingInternalsBuiltins; } - // TextDecoderStreamBuiltinsWrapper& textDecoderStreamBuiltins() { return m_textDecoderStreamBuiltins; } - // TextEncoderStreamBuiltinsWrapper& textEncoderStreamBuiltins() { return m_textEncoderStreamBuiltins; } - JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } - -private: - JSC::VM& m_vm; - JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; - // ByteLengthQueuingStrategyBuiltinsWrapper m_byteLengthQueuingStrategyBuiltins; - // CountQueuingStrategyBuiltinsWrapper m_countQueuingStrategyBuiltins; - // ReadableByteStreamControllerBuiltinsWrapper m_readableByteStreamControllerBuiltins; - // ReadableByteStreamInternalsBuiltinsWrapper m_readableByteStreamInternalsBuiltins; - // ReadableStreamBuiltinsWrapper m_readableStreamBuiltins; - // ReadableStreamBYOBReaderBuiltinsWrapper m_readableStreamBYOBReaderBuiltins; - // ReadableStreamBYOBRequestBuiltinsWrapper m_readableStreamBYOBRequestBuiltins; - // ReadableStreamDefaultControllerBuiltinsWrapper m_readableStreamDefaultControllerBuiltins; - // ReadableStreamDefaultReaderBuiltinsWrapper m_readableStreamDefaultReaderBuiltins; - // ReadableStreamInternalsBuiltinsWrapper m_readableStreamInternalsBuiltins; - // StreamInternalsBuiltinsWrapper m_streamInternalsBuiltins; - // TransformStreamBuiltinsWrapper m_transformStreamBuiltins; - // TransformStreamDefaultControllerBuiltinsWrapper m_transformStreamDefaultControllerBuiltins; - // TransformStreamInternalsBuiltinsWrapper m_transformStreamInternalsBuiltins; - // WritableStreamDefaultControllerBuiltinsWrapper m_writableStreamDefaultControllerBuiltins; - // WritableStreamDefaultWriterBuiltinsWrapper m_writableStreamDefaultWriterBuiltins; - // WritableStreamInternalsBuiltinsWrapper m_writableStreamInternalsBuiltins; - // JSDOMBindingInternalsBuiltinsWrapper m_jsDOMBindingInternalsBuiltins; - // TextDecoderStreamBuiltinsWrapper m_textDecoderStreamBuiltins; - // TextEncoderStreamBuiltinsWrapper m_textEncoderStreamBuiltins; -}; - -}
\ No newline at end of file +#include "WebCoreJSBuiltins.h"
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSBuffer.cpp b/src/javascript/jsc/bindings/JSBuffer.cpp index afb4eebcd..930a6de68 100644 --- a/src/javascript/jsc/bindings/JSBuffer.cpp +++ b/src/javascript/jsc/bindings/JSBuffer.cpp @@ -28,11 +28,12 @@ #include "wtf/GetPtr.h" #include "wtf/PointerPreparations.h" #include "wtf/URL.h" -#include "JSBufferPrototypeBuiltins.h" - -#include "JSBufferEncodingType.h" #include "JavaScriptCore/BuiltinNames.h" +#include "JSBufferEncodingType.h" +#include "JSBufferPrototypeBuiltins.h" +#include "JSBufferConstructorBuiltins.h" +#include "JavaScriptCore/JSBase.h" #if ENABLE(MEDIA_SOURCE) #include "BufferMediaSource.h" #include "JSMediaSource.h" @@ -67,30 +68,22 @@ static JSC_DECLARE_HOST_FUNCTION(jsBufferPrototypeFunction_write); static void toBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSUint8Array* uint8Array); -JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, unsigned int length, void* ctx, JSTypedArrayBytesDeallocator bytesDeallocator) +bool JSBuffer__isBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::EncodedJSValue value) { - JSC::JSUint8Array* uint8Array = nullptr; - - if (LIKELY(length > 0)) { - auto buffer = ArrayBuffer::createFromBytes(ptr, length, createSharedTask<void(void*)>([=](void* p) { - if (bytesDeallocator) - bytesDeallocator(p, ctx); - })); - - uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(buffer), 0, length); - } else { - uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), 0); - } + JSC::VM& vm = lexicalGlobalObject->vm(); + auto clientData = WebCore::clientData(vm); - toBuffer(lexicalGlobalObject, uint8Array); + auto* jsBuffer = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, JSC::JSValue::decode(value)); + if (!jsBuffer) + return false; - return JSC::JSValue::encode(uint8Array); + return !!jsBuffer->getIfPropertyExists(lexicalGlobalObject, clientData->builtinNames().dataViewPrivateName()); } namespace WebCore { using namespace JSC; -template<> class IDLOperation<WebCore::JSBuffer> { +template<> class IDLOperation<JSBuffer> { public: using ClassParameter = JSC::JSUint8Array*; using Operation = JSC::EncodedJSValue(JSC::JSGlobalObject*, JSC::CallFrame*, ClassParameter); @@ -115,76 +108,67 @@ public: } }; -class JSBufferPrototype : public JSC::JSNonFinalObject { -public: - using Base = JSC::JSNonFinalObject; - static constexpr JSC::TypedArrayType TypedArrayStorageType = JSC::JSUint8Array::Adaptor::typeValue; - static JSBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) - { - JSBufferPrototype* ptr = new (NotNull, JSC::allocateCell<JSBufferPrototype>(vm)) JSBufferPrototype(vm, globalObject, structure); - ptr->finishCreation(vm, globalObject); - return ptr; - } +} - DECLARE_INFO; - template<typename CellType, JSC::SubspaceAccess> - static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - return &vm.plainObjectSpace(); - } - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSC::JSType::Uint8ArrayType), StructureFlags), info(), JSC::MayHaveIndexedAccessors); - } +JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, unsigned int length, void* ctx, JSTypedArrayBytesDeallocator bytesDeallocator) +{ -private: - JSBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) - : Base(vm, structure) - { - } + JSC::JSUint8Array* uint8Array = nullptr; - void finishCreation(JSC::VM&, JSC::JSGlobalObject*); -}; -STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBufferPrototype, JSBufferPrototype::Base); + if (LIKELY(length > 0)) { + auto buffer = ArrayBuffer::createFromBytes(ptr, length, createSharedTask<void(void*)>([=](void* p) { + if (bytesDeallocator) + bytesDeallocator(p, ctx); + })); -bool JSBuffer__isBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::EncodedJSValue value) -{ - VM& vm = lexicalGlobalObject->vm(); - auto clientData = WebCore::clientData(vm); + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(buffer), 0, length); + } else { + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), 0); + } - auto* jsBuffer = JSC::jsDynamicCast<JSUint8Array*>(vm, JSC::JSValue::decode(value)); - if (!jsBuffer) - return false; + toBuffer(lexicalGlobalObject, uint8Array); - return !!jsBuffer->getIfPropertyExists(lexicalGlobalObject, clientData->builtinNames().dataViewPrivateName()); + return JSC::JSValue::encode(uint8Array); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) +namespace WebCore { +using namespace JSC; + +static inline JSC::JSUint8Array* JSBuffer__bufferFromLengthAsArray(JSC::JSGlobalObject* lexicalGlobalObject, int length) { - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto length = callFrame->uncheckedArgument(0).toInt32(lexicalGlobalObject); - if (length < 0) { + auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm()); + + if (UNLIKELY(length < 0)) { throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"); - return JSValue::encode(jsUndefined()); + return nullptr; } - auto arrayBuffer = JSC::ArrayBuffer::tryCreate(length, 1); - if (!arrayBuffer) { - throwOutOfMemoryError(lexicalGlobalObject, throwScope); - return JSValue::encode(jsUndefined()); + JSC::JSUint8Array* uint8Array = nullptr; + + if (LIKELY(length > 0)) { + + auto arrayBuffer = JSC::ArrayBuffer::tryCreateUninitialized(length, 1); + if (UNLIKELY(!arrayBuffer)) { + throwOutOfMemoryError(lexicalGlobalObject, throwScope); + return nullptr; + } + + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(arrayBuffer), 0, length); + } else { + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), 0); } - auto uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(arrayBuffer), 0, length); toBuffer(lexicalGlobalObject, uint8Array); - RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(uint8Array)); + RELEASE_AND_RETURN(throwScope, uint8Array); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_alloc, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) + +EncodedJSValue JSBuffer__bufferFromLength(JSC::JSGlobalObject* lexicalGlobalObject, int length) { - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_allocBody>(*lexicalGlobalObject, *callFrame, "alloc"); + return JSC::JSValue::encode(JSBuffer__bufferFromLengthAsArray(lexicalGlobalObject, length)); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { VM& vm = lexicalGlobalObject->vm(); @@ -197,74 +181,194 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeBody(JS auto length = callFrame->uncheckedArgument(0).toInt32(lexicalGlobalObject); RELEASE_AND_RETURN(throwScope, JSBuffer__bufferFromLength(lexicalGlobalObject, length)); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafe, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) + +EncodedJSValue JSBuffer__bufferFromPointerAndLength(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, unsigned int length) { - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_allocUnsafeBody>(*lexicalGlobalObject, *callFrame, "allocUnsafe"); + + JSC::JSUint8Array* uint8Array; + + if (LIKELY(length > 0)) { + auto buffer = ArrayBuffer::createFromBytes(ptr, length, nullptr); + + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(buffer), 0, length); + } else { + uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), 0); + } + + toBuffer(lexicalGlobalObject, uint8Array); + + return JSC::JSValue::encode(uint8Array); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeSlowBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +// new Buffer() +static inline EncodedJSValue constructBufferEmpty(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) { - return jsBufferConstructorFunction_allocUnsafeBody(lexicalGlobalObject, callFrame, castedThis); + return JSBuffer__bufferFromLength(lexicalGlobalObject, 0); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafeSlow, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) + +// new Buffer(size) +static inline EncodedJSValue constructBufferFromLength(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) { - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_allocUnsafeSlowBody>(*lexicalGlobalObject, *callFrame, "allocUnsafeSlow"); + return jsBufferConstructorFunction_allocUnsafeBody(lexicalGlobalObject, callFrame, nullptr); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_byteLengthBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue constructBufferFromStringAndEncoding(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); - return JSValue::encode(jsUndefined()); -} -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_byteLength, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_byteLengthBody>(*lexicalGlobalObject, *callFrame, "byteLength"); + uint32_t offset = 0; + uint32_t length = castedThis->length(); + WebCore::BufferEncodingType encoding = WebCore::BufferEncodingType::utf8; + + auto scope = DECLARE_THROW_SCOPE(vm); + + EnsureStillAliveScope arg0 = callFrame->argument(0); + auto* str = arg0.value().toString(lexicalGlobalObject); + + EnsureStillAliveScope arg1 = callFrame->argument(1); + + if (str->length() == 0) + return constructBufferEmpty(lexicalGlobalObject, callFrame); + + if (callFrame->argumentCount() > 1) { + std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, callFrame->argument(1)); + if (!encoded) { + throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"); + return JSC::JSValue::encode(jsUndefined()); + } + + encoding = encoded.value(); + } + + auto view = str->tryGetValue(lexicalGlobalObject); + JSC::EncodedJSValue result; + + switch (encoding) { + case WebCore::BufferEncodingType::utf8: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsUTF8(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsUTF8(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + + case WebCore::BufferEncodingType::latin1: + case WebCore::BufferEncodingType::ascii: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsASCII(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsASCII(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + case WebCore::BufferEncodingType::ucs2: + case WebCore::BufferEncodingType::utf16le: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsUTF16(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsUTF16(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + + case WebCore::BufferEncodingType::base64: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsBase64(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsBase64(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + + case WebCore::BufferEncodingType::base64url: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsURLSafeBase64(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsURLSafeBase64(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + + case WebCore::BufferEncodingType::hex: { + if (view.is8Bit()) { + result = Bun__encoding__constructFromLatin1AsHex(lexicalGlobalObject, view.characters8(), view.length()); + } else { + result = Bun__encoding__constructFromUTF16AsHex(lexicalGlobalObject, view.characters16(), view.length()); + } + break; + } + } + JSC::JSValue decoded = JSC::JSValue::decode(result); + if (UNLIKELY(!result)) { + throwTypeError(lexicalGlobalObject, scope, "An error occurred while decoding the string"_s); + return JSC::JSValue::encode(jsUndefined()); + } + + if (decoded.isCell() && decoded.getObject()->isErrorInstance()) { + scope.throwException(lexicalGlobalObject, decoded); + return JSC::JSValue::encode(jsUndefined()); + } + + RELEASE_AND_RETURN(scope, result); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { - auto& vm = JSC::getVM(lexicalGlobalObject); - return JSValue::encode(jsUndefined()); + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto length = callFrame->uncheckedArgument(0).toInt32(lexicalGlobalObject); + if (length < 0) { + throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"); + return JSValue::encode(jsUndefined()); + } + + auto arrayBuffer = JSC::ArrayBuffer::tryCreate(length, 1); + if (!arrayBuffer) { + throwOutOfMemoryError(lexicalGlobalObject, throwScope); + return JSValue::encode(jsUndefined()); + } + + auto uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeUint8), WTFMove(arrayBuffer), 0, length); + toBuffer(lexicalGlobalObject, uint8Array); + + RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(uint8Array)); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_compare, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocUnsafeSlowBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_compareBody>(*lexicalGlobalObject, *callFrame, "compare"); + return jsBufferConstructorFunction_allocUnsafeBody(lexicalGlobalObject, callFrame, castedThis); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_byteLengthBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSValue::encode(jsUndefined()); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_concat, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_concatBody>(*lexicalGlobalObject, *callFrame, "concat"); -} -static inline JSC::EncodedJSValue jsBufferConstructorFunction_fromBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSValue::encode(jsUndefined()); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_from, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_fromBody>(*lexicalGlobalObject, *callFrame, "from"); + auto& vm = JSC::getVM(lexicalGlobalObject); + + return JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferConstructorFunction_isBufferBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferConstructorFunction_isBufferBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { if (callFrame->argumentCount() < 1) return JSC::JSValue::encode(JSC::jsBoolean(false)); return JSC::JSValue::encode(JSC::jsBoolean(JSBuffer__isBuffer(lexicalGlobalObject, JSC::JSValue::encode(callFrame->uncheckedArgument(0))))); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isBuffer, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_isBufferBody>(*lexicalGlobalObject, *callFrame, "isBuffer"); -} -static inline JSC::EncodedJSValue jsBufferConstructorFunction_isEncodingBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) + +static inline JSC::EncodedJSValue jsBufferConstructorFunction_isEncodingBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSValue::encode(jsUndefined()); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isEncoding, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation<WebCore::JSBuffer>::call<jsBufferConstructorFunction_isEncodingBody>(*lexicalGlobalObject, *callFrame, "isEncoding"); -} static inline JSC::EncodedJSValue jsBufferConstructorFunction_toBufferBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { @@ -278,6 +382,7 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_toBufferBody(JSC:: auto buffer = callFrame->uncheckedArgument(0); if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo(vm)->typedArrayStorageType)) { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); + return JSValue::encode(jsUndefined()); } JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); @@ -289,186 +394,144 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_toBufferBody(JSC:: toBuffer(lexicalGlobalObject, view); RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(view)); } -JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_toBuffer, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_toBufferBody>(*lexicalGlobalObject, *callFrame, "toBuffer"); -} -using JSBufferConstructor = JSDOMConstructor<JSBuffer>; +class JSBufferPrototype : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static constexpr JSC::TypedArrayType TypedArrayStorageType = JSC::JSUint8Array::Adaptor::typeValue; + static JSBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) + { + JSBufferPrototype* ptr = new (NotNull, JSC::allocateCell<JSBufferPrototype>(vm)) JSBufferPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } -/* Hash table for constructor */ -static const HashTableValue JSBufferConstructorTableValues[] = { - { "construct", static_cast<unsigned>(JSC::PropertyAttribute::Builtin, JSC::PropertyAttribute::DontEnum, JSC::PropertyAttribute::DontDelete), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeBufferConstructorCodeGenerator), (intptr_t)(3) } }, - { "alloc", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_alloc), (intptr_t)(3) } }, - { "allocUnsafe", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_allocUnsafe), (intptr_t)(1) } }, - { "allocUnsafeSlow", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_allocUnsafe), (intptr_t)(1) } }, - { "byteLength", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_byteLength), (intptr_t)(2) } }, - { "compare", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_compare), (intptr_t)(2) } }, - { "concat", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_concat), (intptr_t)(2) } }, - { "from", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_from), (intptr_t)(3) } }, -}; + DECLARE_INFO; + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } -// new Buffer() -static inline EncodedJSValue constructBufferEmpty(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - return JSBuffer__bufferFromLength(lexicalGlobalObject, 0); -} +private: + JSBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } -// new Buffer(size) -static inline EncodedJSValue constructBufferFromLength(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBufferPrototype, JSBufferPrototype::Base); + +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { - return jsBufferConstructorFunction_allocUnsafeBody(lexicalGlobalObject, callFrame, nullptr); + auto& vm = JSC::getVM(lexicalGlobalObject); + return JSC::JSValue::encode(jsUndefined()); } - -static inline JSC::EncodedJSValue constructBufferFromStringAndEncoding(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); - uint32_t offset = 0; - uint32_t length = castedThis->length(); - WebCore::BufferEncodingType encoding = WebCore::BufferEncodingType::utf8; - - auto scope = DECLARE_THROW_SCOPE(vm); - - EnsureStillAliveScope arg0 = callFrame->argument(0); - auto* str = arg0.value().toString(lexicalGlobalObject); - - auto globalObject = reinterpret_cast<WebCore::JSDOMGlobalObject*>(lexicalGlobalObject); - - JSC::MarkedArgumentBuffer args; - - auto* baseStructure = globalObject->m_typedArrayUint8.get(globalObject); - auto arrayBufferView = JSC::JSUint8Array::createUninitialized(globalObject, baseStructure, length); + auto throwScope = DECLARE_THROW_SCOPE(vm); - if (!arrayBufferView) { - throwOutOfMemoryError(lexicalGlobalObject, throwScope); + if (callFrame->argumentCount() < 1) { + throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); return JSValue::encode(jsUndefined()); } - auto* subclassStructure = JSC::InternalFunction::createSubclassStructure(lexicalGlobalObject, arrayBufferView, WebCore::getDOMStructure<JSBuffer>(vm, *globalObject)); - - auto buffer = JSBuffer::create(subclassStructure, globalObject, Buffer::create(globalObject, WTFMove(arrayBufferView))); - - return JSC::JSValue::encode(buffer); -} + auto buffer = callFrame->uncheckedArgument(0); -case WebCore::BufferEncodingType::base64url: { - if (view.is8Bit()) { - result = Bun__encoding__constructFromLatin1AsURLSafeBase64(lexicalGlobalObject, view.characters8(), view.length()); - } else { - result = Bun__encoding__constructFromUTF16AsURLSafeBase64(lexicalGlobalObject, view.characters16(), view.length()); + if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo(vm)->typedArrayStorageType)) { + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); + return JSValue::encode(jsUndefined()); } - break; -} -case WebCore::BufferEncodingType::hex: { - if (view.is8Bit()) { - result = Bun__encoding__constructFromLatin1AsHex(lexicalGlobalObject, view.characters8(), view.length()); - } else { - result = Bun__encoding__constructFromUTF16AsHex(lexicalGlobalObject, view.characters16(), view.length()); + JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); + if (UNLIKELY(!view || view->isDetached())) { + throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array is detached"_s); + return JSValue::encode(jsUndefined()); } - break; -} -} -JSC::JSValue decoded = JSC::JSValue::decode(result); -if (UNLIKELY(!result)) { - throwTypeError(lexicalGlobalObject, scope, "An error occurred while decoding the string"_s); - return JSC::JSValue::encode(jsUndefined()); -} -if (decoded.isCell() && decoded.getObject()->isErrorInstance()) { - scope.throwException(lexicalGlobalObject, decoded); - return JSC::JSValue::encode(jsUndefined()); -} + size_t targetStart = 0; + size_t targetEndInit = view->byteLength(); + size_t targetEnd = targetEndInit; -RELEASE_AND_RETURN(scope, result); -} + size_t sourceStart = 0; + size_t sourceEndInit = castedThis->byteLength(); + size_t sourceEnd = sourceEndInit; -template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBufferConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - UNUSED_PARAM(throwScope); - size_t argsCount = std::min<size_t>(3, callFrame->argumentCount()); - if (argsCount == 0) { - RELEASE_AND_RETURN(throwScope, (constructBufferEmpty(lexicalGlobalObject, callFrame))); - } - JSValue distinguishingArg = callFrame->uncheckedArgument(0); - if (distinguishingArg.isNumber()) { - RELEASE_AND_RETURN(throwScope, (constructBufferFromLength(lexicalGlobalObject, callFrame))); - } else if (distinguishingArg.isString()) { - RELEASE_AND_RETURN(throwScope, (constructBufferFromStringAndEncoding(lexicalGlobalObject, callFrame, nullptr))); - } + if (callFrame->argumentCount() > 1) { + if (auto targetEnd_ = callFrame->uncheckedArgument(1).tryGetAsUint32Index()) { + targetStart = targetEnd_.value(); + } else { + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s); + return JSValue::encode(jsUndefined()); + } - JSC::JSObject* constructor = lexicalGlobalObject->m_typedArrayUint8.constructor(lexicalGlobalObject); + if (callFrame->argumentCount() > 2) { + auto targetEndArgument = callFrame->uncheckedArgument(2); + if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) { + targetEnd = targetEnd_.value(); + } else { + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s); + return JSValue::encode(jsUndefined()); + } + } - // TODO: avoid this copy - MarkedArgumentBuffer args; - for (size_t i = 0; i < argsCount; ++i) - args.append(callFrame->uncheckedArgument(i)); + if (callFrame->argumentCount() > 3) { + auto targetEndArgument = callFrame->uncheckedArgument(2); + if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) { + sourceStart = targetEnd_.value(); + } else { + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s); + return JSValue::encode(jsUndefined()); + } + } - JSC::JSObject* object = JSC::construct(lexicalGlobalObject, constructor, callFrame->newTarget(), args, "Failed to construct 'Buffer' object"_s); - if (!object) { - return JSC::JSValue::encode(JSC::jsUndefined()); + if (callFrame->argumentCount() > 4) { + auto targetEndArgument = callFrame->uncheckedArgument(2); + if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) { + sourceEnd = targetEnd_.value(); + } else { + throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s); + return JSValue::encode(jsUndefined()); + } + } } - auto value = JSC::JSValue(object); - - toBuffer(lexicalGlobalObject, JSC::jsCast<JSC::JSUint8Array*>(value)); - - RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(value)); -} -JSC_ANNOTATE_HOST_FUNCTION(JSBufferConstructorConstruct, JSBufferConstructor::construct); - -template<> const ClassInfo JSBufferConstructor::s_info = { "Buffer"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferConstructor) }; - -template<> JSValue JSBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) -{ - UNUSED_PARAM(vm); - return globalObject.functionPrototype(); -} + if (targetStart > std::min(targetEnd, targetEndInit) || targetEnd > targetEndInit) { + return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "targetStart and targetEnd out of range"_s)); + } -template<> void JSBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) -{ - putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); - JSString* nameString = jsNontrivialString(vm, "Buffer"_s); - m_originalName.set(vm, this, nameString); - putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + if (sourceStart > std::min(sourceEnd, sourceEndInit) || sourceEnd > sourceEndInit) { + return throwVMError(lexicalGlobalObject, throwScope, createRangeError(lexicalGlobalObject, "sourceStart and sourceEnd out of range"_s)); + } - putDirect(vm, vm.propertyNames->prototype, JSBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); - reifyStaticProperties(vm, JSBuffer::info(), JSBufferConstructorTableValues, *this); -} + auto sourceLength = sourceEnd - sourceStart; + auto targetLength = targetEnd - targetStart; + auto actualLength = std::min(sourceLength, targetLength); -bool JSBuffer__isBuffer(JSC::JSGlobalObject* global, JSC::EncodedJSValue value) -{ - VM& vm = global->vm(); - auto* jsBuffer = jsDynamicCast<JSBuffer*>(vm, JSValue::decode(value)); - return !!jsBuffer; -} + auto sourceStartPtr = castedThis->typedVector() + sourceStart; + auto targetStartPtr = view->typedVector() + targetStart; -const ClassInfo JSBuffer::s_info - = { "Buffer"_s, JSC::getUint8ArrayClassInfo(), nullptr, nullptr, CREATE_METHOD_TABLE(JSBuffer) }; + memmove(targetStartPtr, sourceStartPtr, actualLength); -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) -{ - auto& vm = JSC::getVM(lexicalGlobalObject); - return JSC::JSValue::encode(jsUndefined()); -} -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) -{ - auto& vm = JSC::getVM(lexicalGlobalObject); - return JSC::JSValue::encode(jsUndefined()); + return JSValue::encode(jsNumber(actualLength)); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_includesBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_includesBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); @@ -477,33 +540,32 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_includesBody(JSC::JS return JSC::JSValue::encode(JSC::JSValue(reinterpret_cast<uint8_t*>(castedThis->vector())[0])); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_indexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_indexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_lastIndexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_lastIndexOfBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap16Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap16Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap32Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap32Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap64Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_swap64Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); return JSC::JSValue::encode(jsUndefined()); } - -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); uint32_t offset = 0; @@ -608,7 +670,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS RELEASE_AND_RETURN(scope, JSC::JSValue::encode(retValue)); } -static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<WebCore::JSBuffer>::ClassParameter castedThis) +static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSBuffer>::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); uint32_t offset = 0; @@ -736,6 +798,120 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlo RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsNumber(written))); } +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_alloc, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_allocBody>(*lexicalGlobalObject, *callFrame, "alloc"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafe, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_allocUnsafeBody>(*lexicalGlobalObject, *callFrame, "allocUnsafe"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_allocUnsafeSlow, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_allocUnsafeSlowBody>(*lexicalGlobalObject, *callFrame, "allocUnsafeSlow"); +} +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_byteLength, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_byteLengthBody>(*lexicalGlobalObject, *callFrame, "byteLength"); +} + +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_toBuffer, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_toBufferBody>(*lexicalGlobalObject, *callFrame, "toBuffer"); +} + +using JSBufferConstructor = JSDOMConstructor<JSBuffer>; + +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isEncoding, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_isEncodingBody>(*lexicalGlobalObject, *callFrame, "isEncoding"); +} + +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_compare, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_compareBody>(*lexicalGlobalObject, *callFrame, "compare"); +} + +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isBuffer, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_isBufferBody>(*lexicalGlobalObject, *callFrame, "isBuffer"); +} + +JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_concat, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation<JSBuffer>::call<jsBufferConstructorFunction_concatBody>(*lexicalGlobalObject, *callFrame, "concat"); +} + +/* Hash table for constructor */ +static const HashTableValue JSBufferConstructorTableValues[] = { + { "alloc", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_alloc), (intptr_t)(3) } }, + { "allocUnsafe", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_allocUnsafe), (intptr_t)(1) } }, + { "allocUnsafeSlow", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_allocUnsafe), (intptr_t)(1) } }, + { "byteLength", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_byteLength), (intptr_t)(2) } }, + { "compare", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_compare), (intptr_t)(2) } }, + { "concat", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_concat), (intptr_t)(2) } }, + { "from", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferConstructorFromCodeGenerator), (intptr_t)(1) } }, + { "isBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_isBuffer), (intptr_t)(1) } }, + { "toBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_toBuffer), (intptr_t)(1) } }, + { "isEncoding", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferConstructorFunction_isEncoding), (intptr_t)(1) } }, +}; + +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBufferConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +{ + VM& vm = lexicalGlobalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + size_t argsCount = std::min<size_t>(3, callFrame->argumentCount()); + if (argsCount == 0) { + RELEASE_AND_RETURN(throwScope, (constructBufferEmpty(lexicalGlobalObject, callFrame))); + } + JSValue distinguishingArg = callFrame->uncheckedArgument(0); + if (distinguishingArg.isNumber()) { + RELEASE_AND_RETURN(throwScope, (constructBufferFromLength(lexicalGlobalObject, callFrame))); + } else if (distinguishingArg.isString()) { + RELEASE_AND_RETURN(throwScope, (constructBufferFromStringAndEncoding(lexicalGlobalObject, callFrame, nullptr))); + } + + JSC::JSObject* constructor = lexicalGlobalObject->m_typedArrayUint8.constructor(lexicalGlobalObject); + + // TODO: avoid this copy + MarkedArgumentBuffer args; + for (size_t i = 0; i < argsCount; ++i) + args.append(callFrame->uncheckedArgument(i)); + + JSC::JSObject* object = JSC::construct(lexicalGlobalObject, constructor, callFrame->newTarget(), args, "Failed to construct 'Buffer' object"_s); + if (!object) { + return JSC::JSValue::encode(JSC::jsUndefined()); + } + + auto value = JSC::JSValue(object); + + toBuffer(lexicalGlobalObject, JSC::jsCast<JSC::JSUint8Array*>(value)); + + RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(value)); +} +JSC_ANNOTATE_HOST_FUNCTION(JSBufferConstructorConstruct, JSBufferConstructor::construct); + +template<> const ClassInfo JSBufferConstructor::s_info = { "Buffer"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferConstructor) }; + +template<> JSValue JSBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) +{ + UNUSED_PARAM(vm); + return globalObject.functionPrototype(); +} + +template<> void JSBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) +{ + putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + JSString* nameString = jsNontrivialString(vm, "Buffer"_s); + m_originalName.set(vm, this, nameString); + putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); + putDirect(vm, vm.propertyNames->prototype, JSBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); + reifyStaticProperties(vm, JSBuffer::info(), JSBufferConstructorTableValues, *this); +} + +const ClassInfo JSBuffer::s_info = { "Buffer"_s, JSC::getUint8ArrayClassInfo(), nullptr, nullptr, CREATE_METHOD_TABLE(JSBuffer) }; + JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_compare, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) { return IDLOperation<JSBuffer>::call<jsBufferPrototypeFunction_compareBody>(*lexicalGlobalObject, *callFrame, "compare"); @@ -785,6 +961,8 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_write, (JSGlobalObject * lexi return IDLOperation<JSBuffer>::call<jsBufferPrototypeFunction_writeBody>(*lexicalGlobalObject, *callFrame, "write"); } +/* */ + /* Hash table for prototype */ static const HashTableValue JSBufferPrototypeTableValues[] @@ -804,6 +982,39 @@ static const HashTableValue JSBufferPrototypeTableValues[] { "includes", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_includes), (intptr_t)(3) } }, { "indexOf", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_indexOf), (intptr_t)(3) } }, { "lastIndexOf", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_lastIndexOf), (intptr_t)(3) } }, + { "latin1Slice", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeLatin1SliceCodeGenerator), (intptr_t)(2) } }, + { "latin1Write", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeLatin1WriteCodeGenerator), (intptr_t)(1) } }, + { "readBigInt64", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigInt64LECodeGenerator), (intptr_t)(1) } }, + { "readBigInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigInt64BECodeGenerator), (intptr_t)(1) } }, + { "readBigInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigInt64LECodeGenerator), (intptr_t)(1) } }, + { "readBigUInt64", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigUInt64LECodeGenerator), (intptr_t)(1) } }, + { "readBigUInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigUInt64BECodeGenerator), (intptr_t)(1) } }, + { "readBigUInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigUInt64LECodeGenerator), (intptr_t)(1) } }, + { "readDouble", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadDoubleLECodeGenerator), (intptr_t)(1) } }, + { "readDoubleBE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadDoubleBECodeGenerator), (intptr_t)(1) } }, + { "readDoubleLE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadDoubleLECodeGenerator), (intptr_t)(1) } }, + { "readFloat", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadFloatLECodeGenerator), (intptr_t)(1) } }, + { "readFloatBE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadFloatBECodeGenerator), (intptr_t)(1) } }, + { "readFloatLE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadFloatLECodeGenerator), (intptr_t)(1) } }, + { "readInt16", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt16LECodeGenerator), (intptr_t)(1) } }, + { "readInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt16BECodeGenerator), (intptr_t)(1) } }, + { "readInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt16LECodeGenerator), (intptr_t)(1) } }, + { "readInt32", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt32LECodeGenerator), (intptr_t)(1) } }, + { "readInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt32BECodeGenerator), (intptr_t)(1) } }, + { "readInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt32LECodeGenerator), (intptr_t)(1) } }, + { "readInt8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt8CodeGenerator), (intptr_t)(2) } }, + { "readUint16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16BECodeGenerator), (intptr_t)(1) } }, + { "readUInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16BECodeGenerator), (intptr_t)(1) } }, + { "readUint16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16LECodeGenerator), (intptr_t)(1) } }, + { "readUInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16LECodeGenerator), (intptr_t)(1) } }, + { "readUint32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32BECodeGenerator), (intptr_t)(1) } }, + { "readUInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32BECodeGenerator), (intptr_t)(1) } }, + { "readUint32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32LECodeGenerator), (intptr_t)(1) } }, + { "readUInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32LECodeGenerator), (intptr_t)(1) } }, + { "readUint8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt8CodeGenerator), (intptr_t)(1) } }, + { "readUInt8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt8CodeGenerator), (intptr_t)(1) } }, + { "slice", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeSliceCodeGenerator), (intptr_t)(2) } }, + { "subarray", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeSliceCodeGenerator), (intptr_t)(2) } }, { "swap16", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_swap16), (intptr_t)(0) } }, { "swap32", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_swap32), (intptr_t)(0) } }, { "swap64", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_swap64), (intptr_t)(0) } }, @@ -815,45 +1026,37 @@ static const HashTableValue JSBufferPrototypeTableValues[] { "utf8Slice", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeUtf8SliceCodeGenerator), (intptr_t)(2) } }, { "utf8Write", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeUtf8WriteCodeGenerator), (intptr_t)(1) } }, { "write", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsBufferPrototypeFunction_write), (intptr_t)(4) } }, - { "readBigInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigInt64BECodeGenerator), (intptr_t)(2) } }, - { "readBigInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigInt64LECodeGenerator), (intptr_t)(2) } }, - { "readBigUInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigUInt64BECodeGenerator), (intptr_t)(3) } }, - { "readBigUInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadBigUInt64LECodeGenerator), (intptr_t)(3) } }, - { "readDoubleBE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadDoubleBECodeGenerator), (intptr_t)(3) } }, - { "readDoubleLE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadDoubleLECodeGenerator), (intptr_t)(3) } }, - { "readFloatBE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadFloatBECodeGenerator), (intptr_t)(3) } }, - { "readFloatLE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadFloatLECodeGenerator), (intptr_t)(3) } }, - { "readInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt16BECodeGenerator), (intptr_t)(3) } }, - { "readInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt16LECodeGenerator), (intptr_t)(3) } }, - { "readInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt32BECodeGenerator), (intptr_t)(1) } }, - { "readInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt32LECodeGenerator), (intptr_t)(1) } }, - { "readInt8", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadInt8CodeGenerator), (intptr_t)(1) } }, - { "readUInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16BECodeGenerator), (intptr_t)(1) } }, - { "readUInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt16LECodeGenerator), (intptr_t)(1) } }, - { "readUInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32BECodeGenerator), (intptr_t)(1) } }, - { "readUInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt32LECodeGenerator), (intptr_t)(1) } }, - { "readUInt8", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeReadUInt8CodeGenerator), (intptr_t)(1) } }, - { "slice", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeSliceCodeGenerator), (intptr_t)(2) } }, - { "subarray", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeSubarrayCodeGenerator), (intptr_t)(2) } }, - { "toJSON", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeToJSONCodeGenerator), (intptr_t)(2) } }, - { "writeBigInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigInt64BECodeGenerator), (intptr_t)(2) } }, - { "writeBigInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigInt64LECodeGenerator), (intptr_t)(2) } }, - { "writeBigUInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64BECodeGenerator), (intptr_t)(2) } }, - { "writeBigUInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64LECodeGenerator), (intptr_t)(2) } }, - { "writeDoubleBE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteDoubleBECodeGenerator), (intptr_t)(2) } }, - { "writeDoubleLE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteDoubleLECodeGenerator), (intptr_t)(2) } }, - { "writeFloatBE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteFloatBECodeGenerator), (intptr_t)(2) } }, - { "writeFloatLE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteFloatLECodeGenerator), (intptr_t)(2) } }, - { "writeInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt16BECodeGenerator), (intptr_t)(2) } }, - { "writeInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt16LECodeGenerator), (intptr_t)(2) } }, - { "writeInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt32BECodeGenerator), (intptr_t)(2) } }, - { "writeInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt32LECodeGenerator), (intptr_t)(2) } }, - { "writeInt8", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt8CodeGenerator), (intptr_t)(2) } }, - { "writeUInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16BECodeGenerator), (intptr_t)(2) } }, - { "writeUInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16LECodeGenerator), (intptr_t)(2) } }, - { "writeUInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32BECodeGenerator), (intptr_t)(2) } }, - { "writeUInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32LECodeGenerator), (intptr_t)(2) } }, - { "writeUInt8", static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt8CodeGenerator), (intptr_t)(0) } }, + { "writeBigInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigInt64BECodeGenerator), (intptr_t)(1) } }, + { "writeBigInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigInt64LECodeGenerator), (intptr_t)(1) } }, + { "writeBigUint64BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64BECodeGenerator), (intptr_t)(1) } }, + { "writeBigUInt64BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64BECodeGenerator), (intptr_t)(1) } }, + { "writeBigUint64LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64LECodeGenerator), (intptr_t)(1) } }, + { "writeBigUInt64LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteBigUInt64LECodeGenerator), (intptr_t)(1) } }, + { "writeDouble", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteDoubleLECodeGenerator), (intptr_t)(1) } }, + { "writeDoubleBE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteDoubleBECodeGenerator), (intptr_t)(1) } }, + { "writeDoubleLE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteDoubleLECodeGenerator), (intptr_t)(1) } }, + { "writeFloat", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteFloatLECodeGenerator), (intptr_t)(1) } }, + { "writeFloatBE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteFloatBECodeGenerator), (intptr_t)(1) } }, + { "writeFloatLE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteFloatLECodeGenerator), (intptr_t)(1) } }, + { "writeInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt16BECodeGenerator), (intptr_t)(1) } }, + { "writeInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt16LECodeGenerator), (intptr_t)(1) } }, + { "writeInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt32BECodeGenerator), (intptr_t)(1) } }, + { "writeInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt32LECodeGenerator), (intptr_t)(1) } }, + { "writeInt8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteInt8CodeGenerator), (intptr_t)(1) } }, + { "writeUint16", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16LECodeGenerator), (intptr_t)(1) } }, + { "writeUInt16", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16LECodeGenerator), (intptr_t)(1) } }, + { "writeUint16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16BECodeGenerator), (intptr_t)(1) } }, + { "writeUInt16BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16BECodeGenerator), (intptr_t)(1) } }, + { "writeUint16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16LECodeGenerator), (intptr_t)(1) } }, + { "writeUInt16LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt16LECodeGenerator), (intptr_t)(1) } }, + { "writeUint32", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32LECodeGenerator), (intptr_t)(1) } }, + { "writeUInt32", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32LECodeGenerator), (intptr_t)(1) } }, + { "writeUint32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32BECodeGenerator), (intptr_t)(1) } }, + { "writeUInt32BE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32BECodeGenerator), (intptr_t)(1) } }, + { "writeUint32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32LECodeGenerator), (intptr_t)(1) } }, + { "writeUInt32LE", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt32LECodeGenerator), (intptr_t)(1) } }, + { "writeUint8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt8CodeGenerator), (intptr_t)(1) } }, + { "writeUInt8", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t) static_cast<BuiltinGenerator>(jsBufferPrototypeWriteUInt8CodeGenerator), (intptr_t)(1) } }, }; void JSBufferPrototype::finishCreation(VM& vm, JSC::JSGlobalObject* globalThis) @@ -861,13 +1064,14 @@ void JSBufferPrototype::finishCreation(VM& vm, JSC::JSGlobalObject* globalThis) Base::finishCreation(vm); reifyStaticProperties(vm, JSBuffer::info(), JSBufferPrototypeTableValues, *this); JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); + this->setPrototypeDirect(vm, globalThis->m_typedArrayUint8.prototype(globalThis)); } const ClassInfo JSBufferPrototype::s_info = { "Buffer"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferPrototype) }; JSObject* JSBuffer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) { - return JSBufferPrototype::create(vm, &globalObject, JSBufferPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); + return JSBufferPrototype::create(vm, &globalObject, JSBufferPrototype::createStructure(vm, &globalObject, globalObject.m_typedArrayUint8.prototype(&globalObject))); } JSObject* JSBuffer::prototype(VM& vm, JSDOMGlobalObject& globalObject) @@ -986,7 +1190,7 @@ static void toBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSUint8Array object->setPrototypeDirect(vm, WebCore::JSBuffer::prototype(vm, *JSC::jsCast<WebCore::JSDOMGlobalObject*>(lexicalGlobalObject))); auto* dataView = JSC::JSDataView::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructure(JSC::TypeDataView), uint8Array->possiblySharedBuffer(), uint8Array->byteOffset(), uint8Array->length()); - object->putDirectWithoutTransition(vm, clientData->builtinNames().dataViewPublicName(), dataView, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - // Mark it - object->putDirectWithoutTransition(vm, clientData->builtinNames().dataViewPrivateName(), JSC::JSValue(true), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + // putDirectWithTransition doesn't work here + object->putDirect(vm, clientData->builtinNames().dataViewPublicName(), dataView, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + object->putDirect(vm, clientData->builtinNames().dataViewPrivateName(), JSC::JSValue(true), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); }
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.cpp b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.cpp new file mode 100644 index 000000000..6acff3ce0 --- /dev/null +++ b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#include "config.h" +#include "JSBufferConstructorBuiltins.h" + +#include "WebCoreJSClientData.h" +#include <JavaScriptCore/HeapInlines.h> +#include <JavaScriptCore/IdentifierInlines.h> +#include <JavaScriptCore/Intrinsic.h> +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <JavaScriptCore/JSCellInlines.h> +#include <JavaScriptCore/StructureInlines.h> +#include <JavaScriptCore/VM.h> + +namespace WebCore { + +const JSC::ConstructAbility s_jsBufferConstructorFromCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_jsBufferConstructorFromCodeConstructorKind = JSC::ConstructorKind::None; +const int s_jsBufferConstructorFromCodeLength = 1250; +static const JSC::Intrinsic s_jsBufferConstructorFromCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_jsBufferConstructorFromCode = + "(function (items) {\n" \ + " \"use strict\";\n" \ + "\n" \ + " if (!@isConstructor(this))\n" \ + " @throwTypeError(\"Buffer.from requires |this| to be a constructor\");\n" \ + "\n" \ + "\n" \ + " if (typeof items === 'string') {\n" \ + " switch (@argumentCount()) {\n" \ + " case 1: {\n" \ + " return new this(items);\n" \ + " }\n" \ + " case 2: {\n" \ + " return new this(items, @argument(1));\n" \ + " }\n" \ + " default: {\n" \ + " return new this(items, @argument(1), @argument(2));\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + "\n" \ + " var arrayLike = @toObject(items, \"Buffer.from requires an array-like object - not null or undefined\");\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " //\n" \ + " if (@isTypedArrayView(arrayLike)) {\n" \ + " var length = @typedArrayLength(arrayLike);\n" \ + " var result = this.allocUnsafe(length);\n" \ + " result.set(arrayLike);\n" \ + " return result;\n" \ + " } else if (arrayLike instanceof ArrayBuffer || arrayLike instanceof SharedArrayBuffer) {\n" \ + " var byteOffset = @argument(1);\n" \ + " var byteLength = @argument(2);\n" \ + " //\n" \ + " var out = new @Uint8Array(arrayLike, byteOffset, byteLength);\n" \ + " var result = this.allocUnsafe(out.length);\n" \ + " result.set(out);\n" \ + " return result;\n" \ + " }\n" \ + "\n" \ + " return @tailCallForwardArguments(@Uint8Array.from, this);\n" \ + "})\n" \ +; + + +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ +{\ + JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ + return clientData->builtinFunctions().jsBufferConstructorBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().jsBufferConstructorBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ +} +WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR + + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h new file mode 100644 index 000000000..328e597eb --- /dev/null +++ b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2016 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#pragma once + +#include <JavaScriptCore/BuiltinUtils.h> +#include <JavaScriptCore/Identifier.h> +#include <JavaScriptCore/JSFunction.h> +#include <JavaScriptCore/UnlinkedFunctionExecutable.h> + +namespace JSC { +class FunctionExecutable; +} + +namespace WebCore { + +/* JSBufferConstructor */ +extern const char* const s_jsBufferConstructorFromCode; +extern const int s_jsBufferConstructorFromCodeLength; +extern const JSC::ConstructAbility s_jsBufferConstructorFromCodeConstructAbility; +extern const JSC::ConstructorKind s_jsBufferConstructorFromCodeConstructorKind; + +#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_DATA(macro) \ + macro(from, jsBufferConstructorFrom, 1) \ + +#define WEBCORE_BUILTIN_JSBUFFERCONSTRUCTOR_FROM 1 + +#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(macro) \ + macro(jsBufferConstructorFromCode, from, static_cast<const char*>(nullptr), s_jsBufferConstructorFromCodeLength) \ + +#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(macro) \ + macro(from) \ + +#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR + +class JSBufferConstructorBuiltinsWrapper : private JSC::WeakHandleOwner { +public: + explicit JSBufferConstructorBuiltinsWrapper(JSC::VM& vm) + : m_vm(vm) + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), { })) + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS + { + } + +#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ + JSC::UnlinkedFunctionExecutable* name##Executable(); \ + const JSC::SourceCode& name##Source() const { return m_##name##Source; } + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +#undef EXPOSE_BUILTIN_EXECUTABLES + + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + + void exportNames(); + +private: + JSC::VM& m_vm; + + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ + JSC::SourceCode m_##name##Source;\ + JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable; + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS + +}; + +#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +inline JSC::UnlinkedFunctionExecutable* JSBufferConstructorBuiltinsWrapper::name##Executable() \ +{\ + if (!m_##name##Executable) {\ + JSC::Identifier executableName = functionName##PublicName();\ + if (overriddenName)\ + executableName = JSC::Identifier::fromString(m_vm, overriddenName);\ + m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\ + }\ + return m_##name##Executable.get();\ +} +WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +#undef DEFINE_BUILTIN_EXECUTABLES + +inline void JSBufferConstructorBuiltinsWrapper::exportNames() +{ +#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); + WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +#undef EXPORT_FUNCTION_NAME +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp index 83c790a17..2c3969f98 100644 --- a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp +++ b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.cpp @@ -42,445 +42,434 @@ namespace WebCore { -const JSC::ConstructAbility s_jsBufferPrototypeBufferConstructorCodeConstructAbility = JSC::ConstructAbility::CanConstruct; -const JSC::ConstructorKind s_jsBufferPrototypeBufferConstructorCodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeBufferConstructorCodeLength = 181; -static const JSC::Intrinsic s_jsBufferPrototypeBufferConstructorCodeIntrinsic = JSC::NoIntrinsic; -const char* const s_jsBufferPrototypeBufferConstructorCode = - "(function (arrayBuffer, byteOffset, byteLength) {\n" \ - " console.log(\"hi\")\n" \ - " return Reflect.construct(this, [arrayBuffer, byteOffset, byteLength], @Uint8Array.prototype.constructor);\n" \ - "})\n" \ -; - const JSC::ConstructAbility s_jsBufferPrototypeSetBigUint64CodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeSetBigUint64CodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeSetBigUint64CodeLength = 170; +const int s_jsBufferPrototypeSetBigUint64CodeLength = 107; static const JSC::Intrinsic s_jsBufferPrototypeSetBigUint64CodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeSetBigUint64Code = "(function (offset, value, le) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value, le);\n" \ + " return this.dataView.setBigUint64(offset, value, le);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadInt8CodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadInt8CodeLength = 143; +const int s_jsBufferPrototypeReadInt8CodeLength = 80; static const JSC::Intrinsic s_jsBufferPrototypeReadInt8CodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadInt8Code = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt8(offset);\n" \ + " return this.dataView.getInt8(offset);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadUInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadUInt8CodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadUInt8CodeLength = 144; +const int s_jsBufferPrototypeReadUInt8CodeLength = 81; static const JSC::Intrinsic s_jsBufferPrototypeReadUInt8CodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadUInt8Code = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint8(offset);\n" \ + " return this.dataView.getUint8(offset);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadInt16LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadInt16LECodeLength = 150; +const int s_jsBufferPrototypeReadInt16LECodeLength = 87; static const JSC::Intrinsic s_jsBufferPrototypeReadInt16LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadInt16LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt16(offset, true);\n" \ + " return this.dataView.getInt16(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadInt16BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadInt16BECodeLength = 144; +const int s_jsBufferPrototypeReadInt16BECodeLength = 88; static const JSC::Intrinsic s_jsBufferPrototypeReadInt16BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadInt16BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt16(offset);\n" \ + " return this.dataView.getInt16(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadUInt16LECodeLength = 151; +const int s_jsBufferPrototypeReadUInt16LECodeLength = 88; static const JSC::Intrinsic s_jsBufferPrototypeReadUInt16LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadUInt16LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint16(offset, true);\n" \ + " return this.dataView.getUint16(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadUInt16BECodeLength = 145; +const int s_jsBufferPrototypeReadUInt16BECodeLength = 89; static const JSC::Intrinsic s_jsBufferPrototypeReadUInt16BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadUInt16BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint16(offset);\n" \ + " return this.dataView.getUint16(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadInt32LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadInt32LECodeLength = 150; +const int s_jsBufferPrototypeReadInt32LECodeLength = 87; static const JSC::Intrinsic s_jsBufferPrototypeReadInt32LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadInt32LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt32(offset, true);\n" \ + " return this.dataView.getInt32(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadInt32BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadInt32BECodeLength = 144; +const int s_jsBufferPrototypeReadInt32BECodeLength = 88; static const JSC::Intrinsic s_jsBufferPrototypeReadInt32BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadInt32BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getInt32(offset);\n" \ + " return this.dataView.getInt32(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadUInt32LECodeLength = 151; +const int s_jsBufferPrototypeReadUInt32LECodeLength = 88; static const JSC::Intrinsic s_jsBufferPrototypeReadUInt32LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadUInt32LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint32(offset, true);\n" \ + " return this.dataView.getUint32(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadUInt32BECodeLength = 145; +const int s_jsBufferPrototypeReadUInt32BECodeLength = 89; static const JSC::Intrinsic s_jsBufferPrototypeReadUInt32BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadUInt32BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getUint32(offset);\n" \ + " return this.dataView.getUint32(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadFloatLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadFloatLECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadFloatLECodeLength = 152; +const int s_jsBufferPrototypeReadFloatLECodeLength = 89; static const JSC::Intrinsic s_jsBufferPrototypeReadFloatLECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadFloatLECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat32(offset, true);\n" \ + " return this.dataView.getFloat32(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadFloatBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadFloatBECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadFloatBECodeLength = 146; +const int s_jsBufferPrototypeReadFloatBECodeLength = 90; static const JSC::Intrinsic s_jsBufferPrototypeReadFloatBECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadFloatBECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat32(offset);\n" \ + " return this.dataView.getFloat32(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleLECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadDoubleLECodeLength = 152; +const int s_jsBufferPrototypeReadDoubleLECodeLength = 89; static const JSC::Intrinsic s_jsBufferPrototypeReadDoubleLECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadDoubleLECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat64(offset, true);\n" \ + " return this.dataView.getFloat64(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleBECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadDoubleBECodeLength = 146; +const int s_jsBufferPrototypeReadDoubleBECodeLength = 90; static const JSC::Intrinsic s_jsBufferPrototypeReadDoubleBECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadDoubleBECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getFloat64(offset);\n" \ + " return this.dataView.getFloat64(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadBigInt64LECodeLength = 153; +const int s_jsBufferPrototypeReadBigInt64LECodeLength = 90; static const JSC::Intrinsic s_jsBufferPrototypeReadBigInt64LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadBigInt64LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigInt64(offset, true);\n" \ + " return this.dataView.getBigInt64(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadBigInt64BECodeLength = 147; +const int s_jsBufferPrototypeReadBigInt64BECodeLength = 91; static const JSC::Intrinsic s_jsBufferPrototypeReadBigInt64BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadBigInt64BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigInt64(offset);\n" \ + " return this.dataView.getBigInt64(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadBigUInt64LECodeLength = 154; +const int s_jsBufferPrototypeReadBigUInt64LECodeLength = 91; static const JSC::Intrinsic s_jsBufferPrototypeReadBigUInt64LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadBigUInt64LECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigUint64(offset, true);\n" \ + " return this.dataView.getBigUint64(offset, true);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeReadBigUInt64BECodeLength = 148; +const int s_jsBufferPrototypeReadBigUInt64BECodeLength = 92; static const JSC::Intrinsic s_jsBufferPrototypeReadBigUInt64BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeReadBigUInt64BECode = "(function (offset) {\n" \ " \"use strict\";\n" \ - " return (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).getBigUint64(offset);\n" \ + " return this.dataView.getBigUint64(offset, false);\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteInt8CodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteInt8CodeLength = 171; +const int s_jsBufferPrototypeWriteInt8CodeLength = 108; static const JSC::Intrinsic s_jsBufferPrototypeWriteInt8CodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteInt8Code = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt8(offset, value);\n" \ + " this.dataView.setInt8(offset, value);\n" \ " return offset + 1;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt8CodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteUInt8CodeLength = 172; +const int s_jsBufferPrototypeWriteUInt8CodeLength = 109; static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt8CodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteUInt8Code = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint8(offset, value);\n" \ + " this.dataView.setUint8(offset, value);\n" \ " return offset + 1;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteInt16LECodeLength = 178; +const int s_jsBufferPrototypeWriteInt16LECodeLength = 115; static const JSC::Intrinsic s_jsBufferPrototypeWriteInt16LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteInt16LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt16(offset, value, true);\n" \ + " this.dataView.setInt16(offset, value, true);\n" \ " return offset + 2;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteInt16BECodeLength = 172; +const int s_jsBufferPrototypeWriteInt16BECodeLength = 116; static const JSC::Intrinsic s_jsBufferPrototypeWriteInt16BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteInt16BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt16(offset, value);\n" \ + " this.dataView.setInt16(offset, value, false);\n" \ " return offset + 2;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteUInt16LECodeLength = 179; +const int s_jsBufferPrototypeWriteUInt16LECodeLength = 116; static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt16LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteUInt16LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint16(offset, value, true);\n" \ + " this.dataView.setUint16(offset, value, true);\n" \ " return offset + 2;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteUInt16BECodeLength = 173; +const int s_jsBufferPrototypeWriteUInt16BECodeLength = 117; static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt16BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteUInt16BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint16(offset, value);\n" \ + " this.dataView.setUint16(offset, value, false);\n" \ " return offset + 2;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteInt32LECodeLength = 178; +const int s_jsBufferPrototypeWriteInt32LECodeLength = 115; static const JSC::Intrinsic s_jsBufferPrototypeWriteInt32LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteInt32LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt32(offset, value, true);\n" \ + " this.dataView.setInt32(offset, value, true);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteInt32BECodeLength = 172; +const int s_jsBufferPrototypeWriteInt32BECodeLength = 116; static const JSC::Intrinsic s_jsBufferPrototypeWriteInt32BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteInt32BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setInt32(offset, value);\n" \ + " this.dataView.setInt32(offset, value, false);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteUInt32LECodeLength = 179; +const int s_jsBufferPrototypeWriteUInt32LECodeLength = 116; static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt32LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteUInt32LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint32(offset, value, true);\n" \ + " this.dataView.setUint32(offset, value, true);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteUInt32BECodeLength = 173; +const int s_jsBufferPrototypeWriteUInt32BECodeLength = 117; static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt32BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteUInt32BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setUint32(offset, value);\n" \ + " this.dataView.setUint32(offset, value, false);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatLECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteFloatLECodeLength = 180; +const int s_jsBufferPrototypeWriteFloatLECodeLength = 117; static const JSC::Intrinsic s_jsBufferPrototypeWriteFloatLECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteFloatLECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat32(offset, value, true);\n" \ + " this.dataView.setFloat32(offset, value, true);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatBECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteFloatBECodeLength = 174; +const int s_jsBufferPrototypeWriteFloatBECodeLength = 118; static const JSC::Intrinsic s_jsBufferPrototypeWriteFloatBECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteFloatBECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat32(offset, value);\n" \ + " this.dataView.setFloat32(offset, value, false);\n" \ " return offset + 4;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleLECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteDoubleLECodeLength = 180; +const int s_jsBufferPrototypeWriteDoubleLECodeLength = 117; static const JSC::Intrinsic s_jsBufferPrototypeWriteDoubleLECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteDoubleLECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat64(offset, value, true);\n" \ + " this.dataView.setFloat64(offset, value, true);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleBECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteDoubleBECodeLength = 174; +const int s_jsBufferPrototypeWriteDoubleBECodeLength = 118; static const JSC::Intrinsic s_jsBufferPrototypeWriteDoubleBECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteDoubleBECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setFloat64(offset, value);\n" \ + " this.dataView.setFloat64(offset, value, false);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteBigInt64LECodeLength = 181; +const int s_jsBufferPrototypeWriteBigInt64LECodeLength = 118; static const JSC::Intrinsic s_jsBufferPrototypeWriteBigInt64LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteBigInt64LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigInt64(offset, value, true);\n" \ + " this.dataView.setBigInt64(offset, value, true);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteBigInt64BECodeLength = 175; +const int s_jsBufferPrototypeWriteBigInt64BECodeLength = 119; static const JSC::Intrinsic s_jsBufferPrototypeWriteBigInt64BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteBigInt64BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigInt64(offset, value);\n" \ + " this.dataView.setBigInt64(offset, value, false);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64LECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteBigUInt64LECodeLength = 182; +const int s_jsBufferPrototypeWriteBigUInt64LECodeLength = 119; static const JSC::Intrinsic s_jsBufferPrototypeWriteBigUInt64LECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteBigUInt64LECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value, true);\n" \ + " this.dataView.setBigUint64(offset, value, true);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64BECodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeWriteBigUInt64BECodeLength = 176; +const int s_jsBufferPrototypeWriteBigUInt64BECodeLength = 120; static const JSC::Intrinsic s_jsBufferPrototypeWriteBigUInt64BECodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeWriteBigUInt64BECode = "(function (value, offset) {\n" \ " \"use strict\";\n" \ - " (this._view ||= new DataView(this.buffer, this.byteOffset, this.byteLength)).setBigUint64(offset, value);\n" \ + " this.dataView.setBigUint64(offset, value, false);\n" \ " return offset + 8;\n" \ "})\n" \ ; const JSC::ConstructAbility s_jsBufferPrototypeSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_jsBufferPrototypeSliceCodeConstructorKind = JSC::ConstructorKind::None; -const int s_jsBufferPrototypeSliceCodeLength = 309; +const int s_jsBufferPrototypeSliceCodeLength = 262; static const JSC::Intrinsic s_jsBufferPrototypeSliceCodeIntrinsic = JSC::NoIntrinsic; const char* const s_jsBufferPrototypeSliceCode = "(function (start, end) {\n" \ @@ -489,9 +478,7 @@ const char* const s_jsBufferPrototypeSliceCode = " return this;\n" \ " }\n" \ "\n" \ - " if (Buffer[Symbol.species] !== Buffer) {\n" \ - " Buffer[Symbol.species] = Buffer;\n" \ - " }\n" \ + " Buffer[Symbol.species] ||= Buffer;\n" \ "\n" \ " return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));\n" \ "})\n" \ @@ -686,6 +673,18 @@ const char* const s_jsBufferPrototypeToJSONCode = "})\n" \ ; +const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeConstructorKind = JSC::ConstructorKind::None; +const int s_jsBufferPrototypeInitializeBunBufferCodeLength = 45; +static const JSC::Intrinsic s_jsBufferPrototypeInitializeBunBufferCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_jsBufferPrototypeInitializeBunBufferCode = + "(function (parameters)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + "})\n" \ +; + #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ diff --git a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h index d25ad9b76..3bd387ff3 100644 --- a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h +++ b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h @@ -1,4 +1,3 @@ -// clang-format off /* * Copyright (c) 2016 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. @@ -43,10 +42,6 @@ class FunctionExecutable; namespace WebCore { /* JSBufferPrototype */ -extern const char* const s_jsBufferPrototypeBufferConstructorCode; -extern const int s_jsBufferPrototypeBufferConstructorCodeLength; -extern const JSC::ConstructAbility s_jsBufferPrototypeBufferConstructorCodeConstructAbility; -extern const JSC::ConstructorKind s_jsBufferPrototypeBufferConstructorCodeConstructorKind; extern const char* const s_jsBufferPrototypeSetBigUint64Code; extern const int s_jsBufferPrototypeSetBigUint64CodeLength; extern const JSC::ConstructAbility s_jsBufferPrototypeSetBigUint64CodeConstructAbility; @@ -267,9 +262,12 @@ extern const char* const s_jsBufferPrototypeToJSONCode; extern const int s_jsBufferPrototypeToJSONCodeLength; extern const JSC::ConstructAbility s_jsBufferPrototypeToJSONCodeConstructAbility; extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind; +extern const char* const s_jsBufferPrototypeInitializeBunBufferCode; +extern const int s_jsBufferPrototypeInitializeBunBufferCodeLength; +extern const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility; +extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeConstructorKind; #define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_DATA(macro) \ - macro(Buffer, jsBufferPrototypeBufferConstructor, 3) \ macro(setBigUint64, jsBufferPrototypeSetBigUint64, 3) \ macro(readInt8, jsBufferPrototypeReadInt8, 1) \ macro(readUInt8, jsBufferPrototypeReadUInt8, 1) \ @@ -325,8 +323,8 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind; macro(base64urlSlice, jsBufferPrototypeBase64urlSlice, 2) \ macro(hexSlice, jsBufferPrototypeHexSlice, 2) \ macro(toJSON, jsBufferPrototypeToJSON, 0) \ + macro(initializeBunBuffer, jsBufferPrototypeInitializeBunBuffer, 1) \ -#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BUFFER 1 #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SETBIGUINT64 1 #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT8 1 #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT8 1 @@ -382,9 +380,9 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind; #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64URLSLICE 1 #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_HEXSLICE 1 #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_TOJSON 1 +#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_INITIALIZEBUNBUFFER 1 #define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(macro) \ - macro(jsBufferPrototypeBufferConstructorCode, Buffer, static_cast<const char*>(nullptr), s_jsBufferPrototypeBufferConstructorCodeLength) \ macro(jsBufferPrototypeSetBigUint64Code, setBigUint64, static_cast<const char*>(nullptr), s_jsBufferPrototypeSetBigUint64CodeLength) \ macro(jsBufferPrototypeReadInt8Code, readInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt8CodeLength) \ macro(jsBufferPrototypeReadUInt8Code, readUInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt8CodeLength) \ @@ -440,9 +438,20 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind; macro(jsBufferPrototypeBase64urlSliceCode, base64urlSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64urlSliceCodeLength) \ macro(jsBufferPrototypeHexSliceCode, hexSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeHexSliceCodeLength) \ macro(jsBufferPrototypeToJSONCode, toJSON, static_cast<const char*>(nullptr), s_jsBufferPrototypeToJSONCodeLength) \ + macro(jsBufferPrototypeInitializeBunBufferCode, initializeBunBuffer, static_cast<const char*>(nullptr), s_jsBufferPrototypeInitializeBunBufferCodeLength) \ #define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(macro) \ - macro(Buffer) \ + macro(asciiSlice) \ + macro(asciiWrite) \ + macro(base64Slice) \ + macro(base64Write) \ + macro(base64urlSlice) \ + macro(base64urlWrite) \ + macro(hexSlice) \ + macro(hexWrite) \ + macro(initializeBunBuffer) \ + macro(latin1Slice) \ + macro(latin1Write) \ macro(readBigInt64BE) \ macro(readBigInt64LE) \ macro(readBigUInt64BE) \ diff --git a/src/javascript/jsc/bindings/WebCoreJSBuiltins.h b/src/javascript/jsc/bindings/WebCoreJSBuiltins.h index a06c8bfcf..515775d32 100644 --- a/src/javascript/jsc/bindings/WebCoreJSBuiltins.h +++ b/src/javascript/jsc/bindings/WebCoreJSBuiltins.h @@ -30,6 +30,7 @@ #pragma once +#include "JSBufferConstructorBuiltins.h" #include "JSBufferPrototypeBuiltins.h" #include <JavaScriptCore/VM.h> @@ -39,14 +40,17 @@ class JSBuiltinFunctions { public: explicit JSBuiltinFunctions(JSC::VM& vm) : m_vm(vm) + , m_jsBufferConstructorBuiltins(m_vm) , m_jsBufferPrototypeBuiltins(m_vm) { } + JSBufferConstructorBuiltinsWrapper& jsBufferConstructorBuiltins() { return m_jsBufferConstructorBuiltins; } JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } private: JSC::VM& m_vm; + JSBufferConstructorBuiltinsWrapper m_jsBufferConstructorBuiltins; JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; }; diff --git a/src/javascript/jsc/bindings/builtins/js/JSBufferConstructor.js b/src/javascript/jsc/bindings/builtins/js/JSBufferConstructor.js new file mode 100644 index 000000000..464dd9c90 --- /dev/null +++ b/src/javascript/jsc/bindings/builtins/js/JSBufferConstructor.js @@ -0,0 +1,72 @@ +/* + * Copyright 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// ^ that comment is required or the builtins generator will have a fit. + + +function from(items) { + "use strict"; + + if (!@isConstructor(this)) + @throwTypeError("Buffer.from requires |this| to be a constructor"); + + + if (typeof items === 'string') { + switch (@argumentCount()) { + case 1: { + return new this(items); + } + case 2: { + return new this(items, @argument(1)); + } + default: { + return new this(items, @argument(1), @argument(2)); + } + } + } + + + var arrayLike = @toObject(items, "Buffer.from requires an array-like object - not null or undefined"); + + // Buffer-specific fast path: + // - uninitialized memory + // - use .set + if (@isTypedArrayView(arrayLike)) { + var length = @typedArrayLength(arrayLike); + var result = this.allocUnsafe(length); + result.set(arrayLike); + return result; + } else if (arrayLike instanceof ArrayBuffer || arrayLike instanceof SharedArrayBuffer) { + var byteOffset = @argument(1); + var byteLength = @argument(2); + // this will throw if detached + var out = new @Uint8Array(arrayLike, byteOffset, byteLength); + var result = this.allocUnsafe(out.length); + result.set(out); + return result; + } + + return @tailCallForwardArguments(@Uint8Array.from, this); +} diff --git a/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js b/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js index ea1234b8e..c841bcd6c 100644 --- a/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js +++ b/src/javascript/jsc/bindings/builtins/js/JSBufferPrototype.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Codeblog Corp. All rights reserved. + * Copyright 2022 Codeblog Corp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,9 +23,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + // ^ that comment is required or the builtins generator will have a fit. -// -// + // The fastest way as of April 2022 is to use DataView. // DataView has intrinsics that cause inlining @@ -47,7 +47,7 @@ function readInt16LE(offset) { } function readInt16BE(offset) { "use strict"; - return this.dataView.getInt16(offset); + return this.dataView.getInt16(offset, false); } function readUInt16LE(offset) { "use strict"; @@ -55,7 +55,7 @@ function readUInt16LE(offset) { } function readUInt16BE(offset) { "use strict"; - return this.dataView.getUint16(offset); + return this.dataView.getUint16(offset, false); } function readInt32LE(offset) { "use strict"; @@ -63,7 +63,7 @@ function readInt32LE(offset) { } function readInt32BE(offset) { "use strict"; - return this.dataView.getInt32(offset); + return this.dataView.getInt32(offset, false); } function readUInt32LE(offset) { "use strict"; @@ -71,7 +71,7 @@ function readUInt32LE(offset) { } function readUInt32BE(offset) { "use strict"; - return this.dataView.getUint32(offset); + return this.dataView.getUint32(offset, false); } function readFloatLE(offset) { "use strict"; @@ -79,7 +79,7 @@ function readFloatLE(offset) { } function readFloatBE(offset) { "use strict"; - return this.dataView.getFloat32(offset); + return this.dataView.getFloat32(offset, false); } function readDoubleLE(offset) { "use strict"; @@ -87,7 +87,7 @@ function readDoubleLE(offset) { } function readDoubleBE(offset) { "use strict"; - return this.dataView.getFloat64(offset); + return this.dataView.getFloat64(offset, false); } function readBigInt64LE(offset) { "use strict"; @@ -95,7 +95,7 @@ function readBigInt64LE(offset) { } function readBigInt64BE(offset) { "use strict"; - return this.dataView.getBigInt64(offset); + return this.dataView.getBigInt64(offset, false); } function readBigUInt64LE(offset) { "use strict"; @@ -103,7 +103,7 @@ function readBigUInt64LE(offset) { } function readBigUInt64BE(offset) { "use strict"; - return this.dataView.getBigUint64(offset); + return this.dataView.getBigUint64(offset, false); } function writeInt8(value, offset) { "use strict"; @@ -122,7 +122,7 @@ function writeInt16LE(value, offset) { } function writeInt16BE(value, offset) { "use strict"; - this.dataView.setInt16(offset, value); + this.dataView.setInt16(offset, value, false); return offset + 2; } function writeUInt16LE(value, offset) { @@ -132,7 +132,7 @@ function writeUInt16LE(value, offset) { } function writeUInt16BE(value, offset) { "use strict"; - this.dataView.setUint16(offset, value); + this.dataView.setUint16(offset, value, false); return offset + 2; } function writeInt32LE(value, offset) { @@ -142,7 +142,7 @@ function writeInt32LE(value, offset) { } function writeInt32BE(value, offset) { "use strict"; - this.dataView.setInt32(offset, value); + this.dataView.setInt32(offset, value, false); return offset + 4; } function writeUInt32LE(value, offset) { @@ -152,7 +152,7 @@ function writeUInt32LE(value, offset) { } function writeUInt32BE(value, offset) { "use strict"; - this.dataView.setUint32(offset, value); + this.dataView.setUint32(offset, value, false); return offset + 4; } @@ -164,7 +164,7 @@ function writeFloatLE(value, offset) { function writeFloatBE(value, offset) { "use strict"; - this.dataView.setFloat32(offset, value); + this.dataView.setFloat32(offset, value, false); return offset + 4; } @@ -176,7 +176,7 @@ function writeDoubleLE(value, offset) { function writeDoubleBE(value, offset) { "use strict"; - this.dataView.setFloat64(offset, value); + this.dataView.setFloat64(offset, value, false); return offset + 8; } @@ -188,7 +188,7 @@ function writeBigInt64LE(value, offset) { function writeBigInt64BE(value, offset) { "use strict"; - this.dataView.setBigInt64(offset, value); + this.dataView.setBigInt64(offset, value, false); return offset + 8; } @@ -200,7 +200,7 @@ function writeBigUInt64LE(value, offset) { function writeBigUInt64BE(value, offset) { "use strict"; - this.dataView.setBigUint64(offset, value); + this.dataView.setBigUint64(offset, value, false); return offset + 8; } @@ -276,11 +276,9 @@ function base64urlSlice(offset, length) { "use strict"; return this.toString(offset, length, "base64url"); } - -function subarray(start, end) { +function hexSlice(offset, length) { "use strict"; - - return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0)); + return this.toString(offset, length, "hex"); } function toJSON() { @@ -289,3 +287,17 @@ function toJSON() { const data = @Array.from(this); return { type, data }; } + +function subarray(start, end) { + "use strict"; + + Buffer[Symbol.species] ??= Buffer; + return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0)); +} + + +function initializeBunBuffer(parameters) +{ + "use strict"; + +} diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h index 87e7e3afe..67ae00e83 100644 --- a/src/javascript/jsc/bindings/headers-cpp.h +++ b/src/javascript/jsc/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1651208705 +//-- AUTOGENERATED FILE -- 1651379222 // clang-format off #pragma once diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index b6158690c..2e8b427b1 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format: off -//-- AUTOGENERATED FILE -- 1651208705 +//-- AUTOGENERATED FILE -- 1651379222 #pragma once #include <stddef.h> diff --git a/src/javascript/jsc/ffi.exports.js b/src/javascript/jsc/ffi.exports.js index ce72297ff..570476888 100644 --- a/src/javascript/jsc/ffi.exports.js +++ b/src/javascript/jsc/ffi.exports.js @@ -5,4 +5,5 @@ export const CString = globalThis.Bun.FFI.CString; export const dlopen = globalThis.Bun.FFI.dlopen; export const callback = globalThis.Bun.FFI.callback; export const viewSource = globalThis.Bun.FFI.viewSource; + // --- FFIType --- |