Skip to content

Commit

Permalink
Bump WebKit (#16068)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Dec 31, 2024
1 parent 5058bd3 commit 1ae8552
Show file tree
Hide file tree
Showing 26 changed files with 345 additions and 645 deletions.
1 change: 0 additions & 1 deletion cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}
)

if(WIN32)
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
list(APPEND BUN_CXX_SOURCES ${CWD}/src/bun.js/bindings/windows/rescle.cpp)
list(APPEND BUN_CXX_SOURCES ${CWD}/src/bun.js/bindings/windows/rescle-binding.cpp)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")

if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION 00e2b186fd25e79cea4cb4d63d9fd388192327f6)
set(WEBKIT_VERSION ba17b88ba9a5c1140bf74cf3a1637fbc89a3b9e7)
endif()

if(WEBKIT_LOCAL)
Expand Down
4 changes: 4 additions & 0 deletions packages/bun-usockets/src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ void us_internal_dispatch_ready_poll(struct us_poll_t *p, int error, int eof, in
}

if(eof && s) {
if (UNLIKELY(us_socket_is_closed(0, s))) {
// Do not call on_end after the socket has been closed
return;
}
if (us_socket_is_shut_down(0, s)) {
/* We got FIN back after sending it */
s = us_socket_close(0, s, LIBUS_SOCKET_CLOSE_CODE_CLEAN_SHUTDOWN, NULL);
Expand Down
9 changes: 4 additions & 5 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1154,11 +1154,11 @@ pub const Crypto = struct {
};
}

pub const names: std.EnumArray(Algorithm, ZigString) = brk: {
var all = std.EnumArray(Algorithm, ZigString).initUndefined();
pub const names: std.EnumArray(Algorithm, bun.String) = brk: {
var all = std.EnumArray(Algorithm, bun.String).initUndefined();
var iter = all.iterator();
while (iter.next()) |entry| {
entry.value.* = ZigString.init(@tagName(entry.key));
entry.value.* = bun.String.init(@tagName(entry.key));
}
break :brk all;
};
Expand Down Expand Up @@ -2329,8 +2329,7 @@ pub const Crypto = struct {
_: JSValue,
_: JSValue,
) JSC.JSValue {
var values = EVP.Algorithm.names.values;
return JSC.JSValue.createStringArray(globalThis_, &values, values.len, true);
return bun.String.toJSArray(globalThis_, &EVP.Algorithm.names.values);
}

fn hashToEncoding(globalThis: *JSGlobalObject, evp: *EVP, input: JSC.Node.BlobOrStringOrBuffer, encoding: JSC.Node.Encoding) bun.JSError!JSC.JSValue {
Expand Down
20 changes: 10 additions & 10 deletions src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -983,36 +983,36 @@ pub const FFI = struct {
return val;
}
JSC.markBinding(@src());
var zig_strings = allocator.alloc(ZigString, symbols.count()) catch unreachable;
for (symbols.values(), 0..) |*function, i| {
var strs = std.ArrayList(bun.String).initCapacity(allocator, symbols.count()) catch bun.outOfMemory();
defer {
for (strs.items) |str| {
str.deref();
}
strs.deinit();
}
for (symbols.values()) |*function| {
var arraylist = std.ArrayList(u8).init(allocator);
var writer = arraylist.writer();
function.printSourceCode(&writer) catch {
// an error while generating source code
for (symbols.keys()) |key| {
allocator.free(@constCast(key));
}
for (zig_strings) |zig_string| {
allocator.free(@constCast(zig_string.slice()));
}
for (symbols.values()) |*function_| {
function_.arg_types.deinit(allocator);
}

symbols.clearAndFree(allocator);
return ZigString.init("Error while printing code").toErrorInstance(global);
};
zig_strings[i] = ZigString.init(arraylist.items);
strs.appendAssumeCapacity(bun.String.createUTF8(arraylist.items));
}

const ret = JSC.JSValue.createStringArray(global, zig_strings.ptr, zig_strings.len, true);
const ret = bun.String.toJSArray(global, strs.items);

for (symbols.keys()) |key| {
allocator.free(@constCast(key));
}
for (zig_strings) |zig_string| {
allocator.free(@constCast(zig_string.slice()));
}
for (symbols.values()) |*function_| {
function_.arg_types.deinit(allocator);
if (function_.step == .compiled) {
Expand Down
56 changes: 28 additions & 28 deletions src/bun.js/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,56 +167,56 @@ static JSValue constructVersions(VM& vm, JSObject* processObject)
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(ASCIILiteral::fromLiteralUnsafe(REPORTED_NODEJS_VERSION)))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__version)).substring(1))));
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(Bun__version)).substring(1))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_boringssl)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(Bun__versions_boringssl)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "openssl"_s),
// https://github.com/oven-sh/bun/issues/7921
// BoringSSL is a fork of OpenSSL 1.1.0, so we can report OpenSSL 1.1.0
JSC::JSValue(JSC::jsString(vm, String("1.1.0"_s), 0)));
JSC::JSValue(JSC::jsOwnedString(vm, String("1.1.0"_s))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_libarchive)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_libarchive))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_mimalloc)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_mimalloc))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_picohttpparser)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_picohttpparser))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "uwebsockets"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_uws)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_uws))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(BUN_WEBKIT_VERSION)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(BUN_WEBKIT_VERSION))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_zig)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zig))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_zlib)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zlib))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "tinycc"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_tinycc)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_tinycc))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "lolhtml"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_lolhtml)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_lolhtml))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "ares"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_c_ares)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_c_ares))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "libdeflate"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_libdeflate)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_libdeflate))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "usockets"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_usockets)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_usockets))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "lshpack"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_lshpack)))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_lshpack))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zstd"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__versions_zstd)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "v8"_s), JSValue(JSC::jsString(vm, makeString("12.4.254.14-node.12"_s))), 0);
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zstd))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "v8"_s), JSValue(JSC::jsOwnedString(vm, String("12.4.254.14-node.12"_s))), 0);
#if OS(WINDOWS)
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsString(vm, String::fromLatin1(uv_version_string()))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String::fromLatin1(uv_version_string()))), 0);
#else
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsString(vm, makeString("1.48.0"_s))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String("1.48.0"_s))), 0);
#endif
object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsString(vm, makeString("9"_s))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsOwnedString(vm, String("9"_s))), 0);

object->putDirect(vm, JSC::Identifier::fromString(vm, "icu"_s), JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(U_ICU_VERSION)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "unicode"_s), JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(U_UNICODE_VERSION)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "icu"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(U_ICU_VERSION)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "unicode"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(U_UNICODE_VERSION)))), 0);

#define STRINGIFY_IMPL(x) #x
#define STRINGIFY(x) STRINGIFY_IMPL(x)
object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"_s),
JSC::JSValue(JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(STRINGIFY(REPORTED_NODEJS_ABI_VERSION))))));
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(STRINGIFY(REPORTED_NODEJS_ABI_VERSION))))));
#undef STRINGIFY
#undef STRINGIFY_IMPL

Expand All @@ -229,10 +229,10 @@ static JSValue constructProcessReleaseObject(VM& vm, JSObject* processObject)
auto* release = JSC::constructEmptyObject(globalObject);

// SvelteKit compatibility hack
release->putDirect(vm, vm.propertyNames->name, jsString(vm, WTF::String("node"_s)), 0);
release->putDirect(vm, vm.propertyNames->name, jsOwnedString(vm, WTF::String("node"_s)), 0);

release->putDirect(vm, Identifier::fromString(vm, "lts"_s), jsBoolean(false), 0);
release->putDirect(vm, Identifier::fromString(vm, "sourceUrl"_s), jsString(vm, WTF::String(std::span { Bun__githubURL, strlen(Bun__githubURL) })), 0);
release->putDirect(vm, Identifier::fromString(vm, "sourceUrl"_s), jsOwnedString(vm, WTF::String(std::span { Bun__githubURL, strlen(Bun__githubURL) })), 0);
release->putDirect(vm, Identifier::fromString(vm, "headersUrl"_s), jsEmptyString(vm), 0);
release->putDirect(vm, Identifier::fromString(vm, "libUrl"_s), jsEmptyString(vm), 0);

Expand Down Expand Up @@ -1583,7 +1583,7 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
auto timeStamp = WTF::String::fromLatin1(timeBuf);

header->putDirect(vm, JSC::Identifier::fromString(vm, "dumpEventTime"_s), JSC::numberToString(vm, time, 10), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "dumpEventTimeStamp"_s), JSC::jsString(vm, timeStamp, 0));
header->putDirect(vm, JSC::Identifier::fromString(vm, "dumpEventTimeStamp"_s), JSC::jsString(vm, timeStamp));
header->putDirect(vm, JSC::Identifier::fromString(vm, "processId"_s), JSC::jsNumber(getpid()), 0);
// TODO:
header->putDirect(vm, JSC::Identifier::fromString(vm, "threadId"_s), JSC::jsNumber(0), 0);
Expand Down Expand Up @@ -1634,7 +1634,7 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
#if OS(LINUX)
#ifdef __GNU_LIBRARY__
header->putDirect(vm, JSC::Identifier::fromString(vm, "glibcVersionCompiler"_s), JSC::jsString(vm, makeString(__GLIBC__, '.', __GLIBC_MINOR__)), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "glibcVersionRuntime"_s), JSC::jsString(vm, String::fromUTF8(gnu_get_libc_version()), 0));
header->putDirect(vm, JSC::Identifier::fromString(vm, "glibcVersionRuntime"_s), JSC::jsString(vm, String::fromUTF8(gnu_get_libc_version())), 0);
#else
#endif
#endif
Expand Down
11 changes: 9 additions & 2 deletions src/bun.js/bindings/JSBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#endif

#if OS(WINDOWS)
#include "musl-memmem.h"
#include <windows.h>
#endif

Expand Down Expand Up @@ -1288,12 +1287,20 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
RELEASE_AND_RETURN(scope, JSValue::encode(castedThis));
}

#if OS(WINDOWS)
extern "C" void* zig_memmem(const void* haystack, size_t haystack_len, const void* needle, size_t needle_len);
#define MEMMEM_IMPL zig_memmem
#else
#define MEMMEM_IMPL memmem
#endif

static int64_t indexOf(const uint8_t* thisPtr, int64_t thisLength, const uint8_t* valuePtr, int64_t valueLength, int64_t byteOffset)
{
if (thisLength < valueLength + byteOffset)
return -1;
auto start = thisPtr + byteOffset;
auto it = static_cast<uint8_t*>(memmem(start, static_cast<size_t>(thisLength - byteOffset), valuePtr, static_cast<size_t>(valueLength)));

auto it = static_cast<uint8_t*>(MEMMEM_IMPL(start, static_cast<size_t>(thisLength - byteOffset), valuePtr, static_cast<size_t>(valueLength)));
if (it != NULL) {
return it - thisPtr;
}
Expand Down
7 changes: 6 additions & 1 deletion src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,12 @@ void Zig::GlobalObject::resetOnEachMicrotaskTick()
extern "C" JSC__JSGlobalObject* Zig__GlobalObject__create(void* console_client, int32_t executionContextId, bool miniMode, bool evalMode, void* worker_ptr)
{
auto heapSize = miniMode ? JSC::HeapType::Small : JSC::HeapType::Large;
JSC::VM& vm = JSC::VM::create(heapSize).leakRef();
RefPtr<JSC::VM> vmPtr = JSC::VM::tryCreate(heapSize);
if (UNLIKELY(!vmPtr)) {
BUN_PANIC("Failed to allocate JavaScriptCore Virtual Machine. Did your computer run out of memory? Or maybe you compiled Bun with a mismatching libc++ version or compiler?");
}
vmPtr->refSuppressingSaferCPPChecking();
JSC::VM& vm = *vmPtr;
// This must happen before JSVMClientData::create
vm.heap.acquireAccess();
JSC::JSLockHolder locker(vm);
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/bindings/ZigSourceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ static JSC::VM& getVMForBytecodeCache()
static thread_local JSC::VM* vmForBytecodeCache = nullptr;
if (!vmForBytecodeCache) {
const auto heapSize = JSC::HeapType::Small;
auto& vm = JSC::VM::create(heapSize).leakRef();
vm.ref();
vmForBytecodeCache = &vm;
vm.heap.acquireAccess();
auto vmPtr = JSC::VM::tryCreate(heapSize);
vmPtr->refSuppressingSaferCPPChecking();
vmForBytecodeCache = vmPtr.get();
vmPtr->heap.acquireAccess();
}
return *vmForBytecodeCache;
}
Expand Down
39 changes: 0 additions & 39 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2933,44 +2933,6 @@ CPP_DECL void JSC__JSValue__push(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg
array->push(arg1, value2);
}

JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* globalObject, const ZigString* arg1,
size_t arg2, bool clone)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (arg2 == 0) {
return JSC::JSValue::encode(JSC::constructEmptyArray(globalObject, nullptr));
}

JSC::JSArray* array = nullptr;
{
JSC::GCDeferralContext deferralContext(vm);
JSC::ObjectInitializationScope initializationScope(vm);
if ((array = JSC::JSArray::tryCreateUninitializedRestricted(
initializationScope, &deferralContext,
globalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous),
arg2))) {

if (!clone) {
for (size_t i = 0; i < arg2; ++i) {
array->putDirectIndex(globalObject, i, JSC::jsString(vm, Zig::toString(arg1[i]), &deferralContext));
}
} else {
for (size_t i = 0; i < arg2; ++i) {
array->putDirectIndex(globalObject, i, JSC::jsString(vm, Zig::toStringCopy(arg1[i]), &deferralContext));
}
}
}

if (!array) {
JSC::throwOutOfMemoryError(globalObject, scope);
return {};
}

RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::JSValue(array)));
}
}

JSC__JSValue JSC__JSGlobalObject__createAggregateError(JSC__JSGlobalObject* globalObject,
const JSValue* errors, size_t errors_count,
const ZigString* arg3)
Expand Down Expand Up @@ -5056,7 +5018,6 @@ size_t JSC__VM__runGC(JSC__VM* vm, bool sync)
#endif

vm->finalizeSynchronousJSExecution();
WTF::releaseFastMallocFreeMemory();

if (sync) {
vm->clearSourceProviderCaches();
Expand Down
9 changes: 0 additions & 9 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4618,15 +4618,6 @@ pub const JSValue = enum(i64) {
return str;
}

pub fn createStringArray(globalThis: *JSGlobalObject, str: [*c]const ZigString, strings_count: usize, clone: bool) JSValue {
return cppFn("createStringArray", .{
globalThis,
str,
strings_count,
clone,
});
}

pub fn print(
this: JSValue,
globalObject: *JSGlobalObject,
Expand Down
1 change: 0 additions & 1 deletion src/bun.js/bindings/headers.zig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ae8552

Please sign in to comment.