Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions src/base64/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,11 @@ pub use bun_core::base64::encode;

/// [`encode`] appended to `out` (reserving the room itself); returns the number of bytes appended.
pub fn encode_append(out: &mut Vec<u8>, source: &[u8]) -> usize {
encode_append_impl(out, source, false)
}

fn encode_append_impl(out: &mut Vec<u8>, source: &[u8], is_urlsafe: bool) -> usize {
let len = simdutf::base64::encode_len(source.len(), is_urlsafe);
let len = simdutf::base64::encode_len(source.len(), false);
// SAFETY: `encode_raw` writes exactly `len` bytes into the `len` spare bytes reserved here.
unsafe {
bun_core::vec::fill_spare(out, len, |spare| {
let written = simdutf::base64::encode_raw(source, spare.as_mut_ptr(), is_urlsafe);
let written = simdutf::base64::encode_raw(source, spare.as_mut_ptr(), false);
debug_assert_eq!(written, len);
(written, written)
})
Expand All @@ -158,13 +154,6 @@ pub fn encode_url_safe(dest: &mut [u8], source: &[u8]) -> usize {
simdutf::base64::encode(source, dest, true)
}

/// [`encode_url_safe`] into a freshly-allocated `Vec<u8>`.
pub fn simdutf_encode_url_safe_alloc(source: &[u8]) -> Vec<u8> {
let mut destination = Vec::new();
encode_append_impl(&mut destination, source, true);
destination
}

pub fn decode_len(source: &[u8]) -> usize {
match zig_base64::STANDARD.decoder.calc_size_for_slice(source) {
Ok(v) => v,
Expand Down
62 changes: 1 addition & 61 deletions src/http_jsc/websocket_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bun_collections::linear_fifo::DynamicBuffer;
use bun_core::{EncodedSlice, strings};
use bun_http::websocket::{Opcode, WebsocketHeader};
use bun_io::KeepAlive;
use bun_jsc::{self as jsc, GlobalRef, JSGlobalObject, JSValue};
use bun_jsc::{self as jsc, GlobalRef, JSGlobalObject};
use bun_ptr::{BackRef, JsCell, RefPtr, Root, ThisPtr};
use bun_uws::{self as uws, NewSocketHandler, us_bun_verify_error_t};
use bun_uws_sys::us_socket_t;
Expand Down Expand Up @@ -1291,34 +1291,6 @@ impl<const SSL: bool> WebSocket<SSL> {
!tcp.is_closed() && !tcp.is_shutdown()
}

pub(crate) fn write_blob(this: ThisPtr<Self>, blob_value: JSValue, op: u8) {
// See write_binary_data() — tunnel.write() can re-enter fail().
let _guard = this.ref_guard();

if !this.has_tcp() || op > 0xF {
this.dispatch_abrupt_close(ErrorCode::Ended);
return;
}

// Cast the JSValue to a Blob.
// `bun_jsc::webcore::Blob` is an opaque C-ABI shim (real
// layout lives in `bun_runtime::webcore::Blob`, a higher-tier crate).
// `from_js`/`shared_view` trampoline through extern fns to avoid the
// dep cycle — see `bun_jsc::webcore::Blob` impl block.
let Some(blob) = blob_value.as_class_ref::<bun_jsc::webcore::Blob>() else {
this.dispatch_abrupt_close(ErrorCode::Ended);
return;
};
let opcode = Opcode::from_raw(op);
let data = blob.shared_view();
if data.is_empty() {
let _ = this.send_data(Copy::Bytes(&[]), !this.has_backpressure(), opcode);
return;
}

this.send_frame(Copy::Bytes(data), data.len(), opcode);
}

pub(crate) fn write_string(this: ThisPtr<Self>, str: &EncodedSlice, op: u8) {
// See write_binary_data() — tunnel.write() can re-enter fail().
let _guard = this.ref_guard();
Expand Down Expand Up @@ -1724,14 +1696,6 @@ pub fn bun__websocketclient__write_binary_data(
) {
WebSocketClient::write_binary_data(this, bytes, op)
}
// HOST_EXPORT(Bun__WebSocketClient__writeBlob, c)
pub fn bun__websocketclient__write_blob(
this: ThisPtr<crate::websocket_client::WebSocketClient>,
blob_value: JSValue,
op: u8,
) {
WebSocketClient::write_blob(this, blob_value, op)
}
// HOST_EXPORT(Bun__WebSocketClient__writeString, c)
pub fn bun__websocketclient__write_string(
this: ThisPtr<crate::websocket_client::WebSocketClient>,
Expand Down Expand Up @@ -1783,22 +1747,6 @@ pub fn bun__websocketclienttls__init(
secure,
)
}
// HOST_EXPORT(Bun__WebSocketClientTLS__initWithTunnel, c)
pub fn bun__websocketclienttls__init_with_tunnel(
outgoing: &crate::websocket_client::cpp_websocket::CppWebSocket,
tunnel: ThisPtr<crate::websocket_client::websocket_proxy_tunnel::WebSocketProxyTunnel>,
global_this: &JSGlobalObject,
buffered_data: Option<Box<crate::websocket_client::InitialData>>,
deflate_params: Option<&crate::websocket_client::websocket_deflate::Params>,
) -> *mut crate::websocket_client::WebSocketClientTLS {
WebSocketClientTLS::init_with_tunnel(
outgoing,
tunnel,
global_this,
buffered_data,
deflate_params,
)
}
// HOST_EXPORT(Bun__WebSocketClientTLS__memoryCost, c)
pub fn bun__websocketclienttls__memory_cost(
this: &crate::websocket_client::WebSocketClientTLS,
Expand All @@ -1813,14 +1761,6 @@ pub fn bun__websocketclienttls__write_binary_data(
) {
WebSocketClientTLS::write_binary_data(this, bytes, op)
}
// HOST_EXPORT(Bun__WebSocketClientTLS__writeBlob, c)
pub fn bun__websocketclienttls__write_blob(
this: ThisPtr<crate::websocket_client::WebSocketClientTLS>,
blob_value: JSValue,
op: u8,
) {
WebSocketClientTLS::write_blob(this, blob_value, op)
}
// HOST_EXPORT(Bun__WebSocketClientTLS__writeString, c)
pub fn bun__websocketclienttls__write_string(
this: ThisPtr<crate::websocket_client::WebSocketClientTLS>,
Expand Down
15 changes: 0 additions & 15 deletions src/jsc/bindings/ErrorStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ JSC::JSString* JSCStackFrame::functionName()
return jsString(this->m_vm, m_functionName);
}

JSC::JSString* JSCStackFrame::typeName()
{
if (!m_typeName) {
m_typeName = retrieveTypeName();
}

return jsString(this->m_vm, m_typeName);
}

JSCStackFrame::SourcePositions* JSCStackFrame::getSourcePositions()
{
if (SourcePositionsState::NotCalculated == m_sourcePositionsState) {
Expand Down Expand Up @@ -338,12 +329,6 @@ ALWAYS_INLINE String JSCStackFrame::retrieveFunctionName()
return emptyString();
}

ALWAYS_INLINE String JSCStackFrame::retrieveTypeName()
{
JSC::JSObject* calleeObject = uncheckedDowncast<JSC::JSObject>(m_callee);
return calleeObject->className();
}

// General flow here is based on JSC's appendSourceToError (ErrorInstance.cpp)
bool JSCStackFrame::calculateSourcePositions()
{
Expand Down
4 changes: 0 additions & 4 deletions src/jsc/bindings/ErrorStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class JSCStackFrame {
// Lazy-initialized
WTF::String m_sourceURL;
WTF::String m_functionName;
WTF::String m_typeName;

// m_wasmFunctionIndexOrName has meaning only when m_isWasmFrame is set
JSC::Wasm::IndexOrName m_wasmFunctionIndexOrName;
Expand Down Expand Up @@ -84,7 +83,6 @@ class JSCStackFrame {
intptr_t sourceID() const;
JSC::JSString* sourceURL();
JSC::JSString* functionName();
JSC::JSString* typeName();

bool isFunctionOrEval() const { return m_isFunctionOrEval; }
bool isAsync() const { return m_isAsync; }
Expand Down Expand Up @@ -151,8 +149,6 @@ class JSCStackFrame {
*/
ALWAYS_INLINE String retrieveFunctionName();

ALWAYS_INLINE String retrieveTypeName();

bool calculateSourcePositions();
};

Expand Down
11 changes: 0 additions & 11 deletions src/jsc/bindings/JSNodePerformanceHooksHistogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ JSNodePerformanceHooksHistogram* JSNodePerformanceHooksHistogram::create(VM& vm,
return ptr;
}

JSNodePerformanceHooksHistogram* JSNodePerformanceHooksHistogram::create(VM& vm, Structure* structure, JSGlobalObject* globalObject, HistogramData&& existingHistogramData)
{
JSNodePerformanceHooksHistogram* ptr = new (NotNull, allocateCell<JSNodePerformanceHooksHistogram>(vm)) JSNodePerformanceHooksHistogram(vm, structure, std::move(existingHistogramData));
ptr->finishCreation(vm);
if (ptr->m_histogramData.histogram) {
ptr->m_extraMemorySizeForGC = hdr_get_memory_size(ptr->m_histogramData.histogram);
vm.heap.reportExtraMemoryAllocated(ptr, ptr->m_extraMemorySizeForGC);
}
return ptr;
}

void JSNodePerformanceHooksHistogram::destroy(JSCell* cell)
{
static_cast<JSNodePerformanceHooksHistogram*>(cell)->~JSNodePerformanceHooksHistogram();
Expand Down
6 changes: 0 additions & 6 deletions src/jsc/bindings/JSNodePerformanceHooksHistogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ class JSNodePerformanceHooksHistogram final : public JSC::JSDestructibleObject {
int64_t highest,
int figures);

static JSNodePerformanceHooksHistogram* create(
JSC::VM& vm,
JSC::Structure* structure,
JSC::JSGlobalObject* globalObject,
HistogramData&& existingHistogramData);

void finishCreation(JSC::VM& vm);
static void destroy(JSC::JSCell*);

Expand Down
102 changes: 0 additions & 102 deletions src/jsc/bindings/ncrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ void CryptoErrorList::capture()
}
}

void CryptoErrorList::add(WTF::String error)
{
errors_.push_back(error);
}

std::optional<WTF::String> CryptoErrorList::pop_back()
{
if (errors_.empty()) return std::nullopt;
Expand All @@ -100,14 +95,6 @@ std::optional<WTF::String> CryptoErrorList::pop_back()
return error;
}

std::optional<WTF::String> CryptoErrorList::pop_front()
{
if (errors_.empty()) return std::nullopt;
WTF::String error = errors_.front();
errors_.pop_front();
return error;
}

// ============================================================================
DataPointer DataPointer::Alloc(size_t len)
{
Expand Down Expand Up @@ -280,17 +267,6 @@ size_t BignumPointer::byteLength() const
return BN_num_bytes(bn_.get());
}

DataPointer BignumPointer::encode() const
{
return EncodePadded(bn_.get(), byteLength());
}

size_t BignumPointer::encodeInto(unsigned char* out) const
{
if (!bn_) return 0;
return BN_bn2bin(bn_.get(), out);
}

DataPointer BignumPointer::Encode(const BIGNUM* bn)
{
return EncodePadded(bn, bn != nullptr ? BN_num_bytes(bn) : 0);
Expand Down Expand Up @@ -1183,13 +1159,6 @@ std::optional<WTF::String> X509View::getFingerprint(
return std::nullopt;
}

X509Pointer X509View::clone() const
{
ClearErrorOnReturn clear_error_on_return;
if (!cert_) return {};
return X509Pointer(X509_dup(const_cast<X509*>(cert_)));
}

Result<X509Pointer, int> X509Pointer::Parse(
Buffer<const unsigned char> buffer)
{
Expand Down Expand Up @@ -1289,12 +1258,6 @@ BIOPointer BIOPointer::NewMem()
return BIOPointer(BIO_new(BIO_s_mem()));
}

BIOPointer BIOPointer::New(const BIO_METHOD* method)
{
if (method == nullptr) return {};
return BIOPointer(BIO_new(method));
}

BIOPointer BIOPointer::New(const void* data, size_t len)
{
return BIOPointer(BIO_new_mem_buf(data, len));
Expand All @@ -1307,13 +1270,6 @@ BIOPointer BIOPointer::New(const BIGNUM* bn)
return res;
}

int BIOPointer::Write(BIOPointer* bio, WTF::StringView message)
{
if (bio == nullptr || !*bio) return 0;
auto messageUtf8 = message.utf8();
return BIO_write(bio->get(), messageUtf8.data(), messageUtf8.length());
}

// ============================================================================
// DHPointer

Expand Down Expand Up @@ -1877,12 +1833,6 @@ int EVPKeyPointer::base_id() const
return base_id(get());
}

int EVPKeyPointer::bits() const
{
if (get() == nullptr) return 0;
return EVP_PKEY_bits(get());
}

size_t EVPKeyPointer::size() const
{
if (get() == nullptr) return 0;
Expand Down Expand Up @@ -2496,11 +2446,6 @@ const Cipher Cipher::FromCtx(const CipherCtxPointer& ctx)
return Cipher(EVP_CIPHER_CTX_cipher(ctx.get()));
}

const Cipher& Cipher::EMPTY()
{
static const Cipher cipher = Cipher();
return cipher;
}
const Cipher& Cipher::AES_128_CBC()
{
static const Cipher cipher = Cipher::FromNid(NID_aes_128_cbc);
Expand Down Expand Up @@ -3056,14 +3001,6 @@ ECKeyPointer ECKeyPointer::NewByCurveName(int nid)
return ECKeyPointer(EC_KEY_new_by_curve_name(nid));
}

ECKeyPointer ECKeyPointer::New(const EC_GROUP* group)
{
auto ptr = ECKeyPointer(EC_KEY_new());
if (!ptr) return {};
if (!EC_KEY_set_group(ptr.get(), group)) return {};
return ptr;
}

// ============================================================================

EVPKeyCtxPointer::EVPKeyCtxPointer()
Expand Down Expand Up @@ -3259,21 +3196,6 @@ bool EVPKeyCtxPointer::initForDecrypt()
return EVP_PKEY_decrypt_init(ctx_.get()) == 1;
}

DataPointer EVPKeyCtxPointer::derive() const
{
if (!ctx_) return {};
size_t len = 0;
if (EVP_PKEY_derive(ctx_.get(), nullptr, &len) != 1) return {};
auto data = DataPointer::Alloc(len);
if (!data) return {};
if (EVP_PKEY_derive(
ctx_.get(), static_cast<unsigned char*>(data.get()), &len)
!= 1) {
return {};
}
return data;
}

EVPKeyPointer EVPKeyCtxPointer::paramgen() const
{
if (!ctx_) return {};
Expand Down Expand Up @@ -3490,21 +3412,6 @@ DataPointer Cipher::recover(const EVPKeyPointer& key,

// ============================================================================

Ec::Ec()
: ec_(nullptr)
{
}

Ec::Ec(OSSL3_CONST EC_KEY* key)
: ec_(key)
{
}

const EC_GROUP* Ec::getGroup() const
{
return ECKeyPointer::GetGroup(ec_);
}

int Ec::GetCurveIdFromName(const char* name)
{
int nid = EC_curve_nist2nid(name);
Expand Down Expand Up @@ -3766,15 +3673,6 @@ bool HMACCtxPointer::update(const Buffer<const void>& buf)
== 1;
}

DataPointer HMACCtxPointer::digest()
{
auto data = DataPointer::Alloc(EVP_MAX_MD_SIZE);
if (!data) return {};
Buffer<void> buf = data;
if (!digestInto(&buf)) return {};
return data.resize(buf.len);
}

bool HMACCtxPointer::digestInto(Buffer<void>* buf)
{
if (!ctx_) return false;
Expand Down
Loading
Loading