From 6019665d4b4166f31956f3fc8ed16cd0af5f4e26 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 21 Jan 2024 20:25:00 -0800 Subject: [PATCH] Fixes #8276 (#8346) * Fixes #8276 * [autofix.ci] apply automated fixes --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/bun.js/bindings/bindings.cpp | 6 +++--- src/string_types.zig | 21 --------------------- test/js/bun/util/filesystem_router.test.ts | 8 ++++++++ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 3f3160462a..80a3ba61f4 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -1516,7 +1516,7 @@ WebCore::FetchHeaders* WebCore__FetchHeaders__createFromUWS(JSC__JSGlobalObject* size_t name_len = nameView.length(); LChar* data = nullptr; - auto value = String::createUninitialized(header.second.length(), data); + auto value = String::createUninitialized(header.second.length(), data); memcpy(data, header.second.data(), header.second.length()); HTTPHeaderName name; @@ -1718,7 +1718,7 @@ JSC__JSValue JSC__JSObject__create(JSC__JSGlobalObject* globalObject, size_t initialCapacity, void* arg2, void (*ArgFn3)(void* arg0, JSC__JSObject* arg1, JSC__JSGlobalObject* arg2)) { - JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), initialCapacity); + JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), std::min(static_cast(initialCapacity), JSFinalObject::maxInlineCapacity)); ArgFn3(arg2, object, globalObject); @@ -2446,7 +2446,7 @@ JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* globalObject, ZigStr JSC::JSObject* object = nullptr; { JSC::ObjectInitializationScope initializationScope(vm); - object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), initialCapacity); + object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), std::min(static_cast(initialCapacity), JSFinalObject::maxInlineCapacity)); if (!clone) { for (size_t i = 0; i < initialCapacity; ++i) { diff --git a/src/string_types.zig b/src/string_types.zig index 2b6b558b04..c9bc56abde 100644 --- a/src/string_types.zig +++ b/src/string_types.zig @@ -17,32 +17,11 @@ pub const PathString = packed struct { len: PathInt = 0, const JSC = @import("root").bun.JSC; - pub fn fromJS(value: JSC.JSValue, global: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) PathString { - if (!value.jsType().isStringLike()) { - JSC.JSError(JSC.getAllocator(global), "Only path strings are supported for now", .{}, global, exception); - return PathString{}; - } - var zig_str = JSC.ZigString.init(""); - value.toZigString(&zig_str, global); - - return PathString.init(zig_str.slice()); - } - - pub inline fn asRef(this: PathString) JSC.JSValueRef { - return this.toValue().asObjectRef(); - } pub fn estimatedSize(this: *const PathString) usize { return @as(usize, this.len); } - pub fn toJS(this: PathString, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef { - var zig_str = JSC.ZigString.init(this.slice()); - zig_str.detectEncoding(); - - return zig_str.toValueAuto(ctx.ptr()).asObjectRef(); - } - pub inline fn slice(this: anytype) string { @setRuntimeSafety(false); // "cast causes pointer to be null" is fine here. if it is null, the len will be 0. return @as([*]u8, @ptrFromInt(@as(usize, @intCast(this.ptr))))[0..this.len]; diff --git a/test/js/bun/util/filesystem_router.test.ts b/test/js/bun/util/filesystem_router.test.ts index c29e91a6c8..2942fab439 100644 --- a/test/js/bun/util/filesystem_router.test.ts +++ b/test/js/bun/util/filesystem_router.test.ts @@ -47,6 +47,10 @@ it("should find files", () => { `b.tsx`, `foo/[id].tsx`, `catch-all/[[...id]].tsx`, + + // https://github.com/oven-sh/bun/issues/8276 + // https://github.com/oven-sh/bun/issues/8278 + ...Array.from({ length: 65 }, (_, i) => `files/a${i}.tsx`), ]); const router = new FileSystemRouter({ @@ -71,6 +75,10 @@ it("should find files", () => { "/b": `${dir}/b.tsx`, "/foo/[id]": `${dir}/foo/[id].tsx`, "/catch-all/[[...id]]": `${dir}/catch-all/[[...id]].tsx`, + + // https://github.com/oven-sh/bun/issues/8276 + // https://github.com/oven-sh/bun/issues/8278 + ...Object.fromEntries(Array.from({ length: 65 }, (_, i) => [`/files/a${i}`, `${dir}/files/a${i}.tsx`])), }; for (const route in fixture) {