diff --git a/.buildkite/ci.mjs b/.buildkite/ci.mjs index c0ac6b0673..8aa1460057 100755 --- a/.buildkite/ci.mjs +++ b/.buildkite/ci.mjs @@ -331,16 +331,14 @@ function getZigAgent(platform, options) { return getEc2Agent( { os: "linux", - arch: "x64", + arch: "aarch64", abi: "musl", distro: "alpine", release: "3.21", }, options, { - instanceType: "c7i.2xlarge", - cpuCount: 4, - threadsPerCore: 1, + instanceType: "r8g.large", }, ); } diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d4b774ba36..e7850387a0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,18 +1,18 @@ # Project -.github/CODEOWNERS @Jarred-Sumner +/.github/CODEOWNERS @Jarred-Sumner # Build system -CMakeLists.txt @Electroid -cmake/ @Electroid -scripts/ @Electroid +/CMakeLists.txt @Electroid +/cmake/*.cmake @Electroid +/scripts/ @Electroid # CI -.buildkite/ @Electroid -.github/workflows/ @Electroid +/.buildkite/ @Electroid +/.github/workflows/ @Electroid # Debugger protocol -packages/bun-inspector-protocol/ @Electroid -packages/bun-debug-adapter-protocol/ @Electroid +/packages/bun-inspector-protocol/ @Electroid +/packages/bun-debug-adapter-protocol/ @Electroid # Tests -test/expectations.txt @Jarred-Sumner +/test/expectations.txt @Jarred-Sumner diff --git a/cmake/BakeRuntimeSources.txt b/cmake/sources/BakeRuntimeSources.txt similarity index 100% rename from cmake/BakeRuntimeSources.txt rename to cmake/sources/BakeRuntimeSources.txt diff --git a/cmake/BindgenSources.txt b/cmake/sources/BindgenSources.txt similarity index 100% rename from cmake/BindgenSources.txt rename to cmake/sources/BindgenSources.txt diff --git a/cmake/BunErrorSources.txt b/cmake/sources/BunErrorSources.txt similarity index 100% rename from cmake/BunErrorSources.txt rename to cmake/sources/BunErrorSources.txt diff --git a/cmake/CSources.txt b/cmake/sources/CSources.txt similarity index 87% rename from cmake/CSources.txt rename to cmake/sources/CSources.txt index adbab642c8..67bf951f15 100644 --- a/cmake/CSources.txt +++ b/cmake/sources/CSources.txt @@ -8,5 +8,4 @@ packages/bun-usockets/src/quic.c packages/bun-usockets/src/socket.c packages/bun-usockets/src/udp.c src/bun.js/bindings/uv-posix-polyfills.c -src/bun.js/bindings/uv-posix-stubs.c -src/asan-config.c +src/bun.js/bindings/uv-posix-stubs.c \ No newline at end of file diff --git a/cmake/CxxSources.txt b/cmake/sources/CxxSources.txt similarity index 100% rename from cmake/CxxSources.txt rename to cmake/sources/CxxSources.txt diff --git a/cmake/JavaScriptCodegenSources.txt b/cmake/sources/JavaScriptCodegenSources.txt similarity index 100% rename from cmake/JavaScriptCodegenSources.txt rename to cmake/sources/JavaScriptCodegenSources.txt diff --git a/cmake/JavaScriptSources.txt b/cmake/sources/JavaScriptSources.txt similarity index 100% rename from cmake/JavaScriptSources.txt rename to cmake/sources/JavaScriptSources.txt diff --git a/cmake/NodeFallbacksSources.txt b/cmake/sources/NodeFallbacksSources.txt similarity index 100% rename from cmake/NodeFallbacksSources.txt rename to cmake/sources/NodeFallbacksSources.txt diff --git a/cmake/ZigGeneratedClassesSources.txt b/cmake/sources/ZigGeneratedClassesSources.txt similarity index 100% rename from cmake/ZigGeneratedClassesSources.txt rename to cmake/sources/ZigGeneratedClassesSources.txt diff --git a/cmake/ZigSources.txt b/cmake/sources/ZigSources.txt similarity index 99% rename from cmake/ZigSources.txt rename to cmake/sources/ZigSources.txt index 1dcd73c2a5..0aff5f740f 100644 --- a/cmake/ZigSources.txt +++ b/cmake/sources/ZigSources.txt @@ -222,6 +222,7 @@ src/bun.js/webcore/Response.zig src/bun.js/webcore/S3Client.zig src/bun.js/webcore/S3File.zig src/bun.js/webcore/S3Stat.zig +src/bun.js/webcore/ScriptExecutionContext.zig src/bun.js/webcore/Sink.zig src/bun.js/webcore/streams.zig src/bun.js/webcore/TextDecoder.zig diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index c9600843e7..87c2545010 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -46,7 +46,7 @@ endif() set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error) -absolute_sources(BUN_ERROR_SOURCES ${CWD}/cmake/BunErrorSources.txt) +absolute_sources(BUN_ERROR_SOURCES ${CWD}/cmake/sources/BunErrorSources.txt) set(BUN_ERROR_OUTPUT ${CODEGEN_PATH}/bun-error) set(BUN_ERROR_OUTPUTS @@ -135,7 +135,7 @@ register_command( set(BUN_NODE_FALLBACKS_SOURCE ${CWD}/src/node-fallbacks) -absolute_sources(BUN_NODE_FALLBACKS_SOURCES ${CWD}/cmake/NodeFallbacksSources.txt) +absolute_sources(BUN_NODE_FALLBACKS_SOURCES ${CWD}/cmake/sources/NodeFallbacksSources.txt) set(BUN_NODE_FALLBACKS_OUTPUT ${CODEGEN_PATH}/node-fallbacks) set(BUN_NODE_FALLBACKS_OUTPUTS) @@ -235,7 +235,7 @@ register_command( set(BUN_ZIG_GENERATED_CLASSES_SCRIPT ${CWD}/src/codegen/generate-classes.ts) -absolute_sources(BUN_ZIG_GENERATED_CLASSES_SOURCES ${CWD}/cmake/ZigGeneratedClassesSources.txt) +absolute_sources(BUN_ZIG_GENERATED_CLASSES_SOURCES ${CWD}/cmake/sources/ZigGeneratedClassesSources.txt) set(BUN_ZIG_GENERATED_CLASSES_OUTPUTS ${CODEGEN_PATH}/ZigGeneratedClasses.h @@ -268,8 +268,8 @@ register_command( set(BUN_JAVASCRIPT_CODEGEN_SCRIPT ${CWD}/src/codegen/bundle-modules.ts) -absolute_sources(BUN_JAVASCRIPT_SOURCES ${CWD}/cmake/JavaScriptSources.txt) -absolute_sources(BUN_JAVASCRIPT_CODEGEN_SOURCES ${CWD}/cmake/JavaScriptCodegenSources.txt) +absolute_sources(BUN_JAVASCRIPT_SOURCES ${CWD}/cmake/sources/JavaScriptSources.txt) +absolute_sources(BUN_JAVASCRIPT_CODEGEN_SOURCES ${CWD}/cmake/sources/JavaScriptCodegenSources.txt) list(APPEND BUN_JAVASCRIPT_CODEGEN_SOURCES ${CWD}/src/bun.js/bindings/InternalModuleRegistry.cpp @@ -311,7 +311,7 @@ register_command( set(BUN_BAKE_RUNTIME_CODEGEN_SCRIPT ${CWD}/src/codegen/bake-codegen.ts) -absolute_sources(BUN_BAKE_RUNTIME_SOURCES ${CWD}/cmake/BakeRuntimeSources.txt) +absolute_sources(BUN_BAKE_RUNTIME_SOURCES ${CWD}/cmake/sources/BakeRuntimeSources.txt) list(APPEND BUN_BAKE_RUNTIME_CODEGEN_SOURCES ${CWD}/src/bun.js/bindings/InternalModuleRegistry.cpp @@ -344,7 +344,7 @@ register_command( set(BUN_BINDGEN_SCRIPT ${CWD}/src/codegen/bindgen.ts) -absolute_sources(BUN_BINDGEN_SOURCES ${CWD}/cmake/BindgenSources.txt) +absolute_sources(BUN_BINDGEN_SOURCES ${CWD}/cmake/sources/BindgenSources.txt) set(BUN_BINDGEN_CPP_OUTPUTS ${CODEGEN_PATH}/GeneratedBindings.cpp @@ -501,7 +501,7 @@ WEBKIT_ADD_SOURCE_DEPENDENCIES( # --- Zig --- -absolute_sources(BUN_ZIG_SOURCES ${CWD}/cmake/ZigSources.txt) +absolute_sources(BUN_ZIG_SOURCES ${CWD}/cmake/sources/ZigSources.txt) list(APPEND BUN_ZIG_SOURCES ${CWD}/build.zig @@ -598,8 +598,8 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "build.zig") set(BUN_USOCKETS_SOURCE ${CWD}/packages/bun-usockets) # hand written cpp source files. Full list of "source" code (including codegen) is in BUN_CPP_SOURCES -absolute_sources(BUN_CXX_SOURCES ${CWD}/cmake/CxxSources.txt) -absolute_sources(BUN_C_SOURCES ${CWD}/cmake/CSources.txt) +absolute_sources(BUN_CXX_SOURCES ${CWD}/cmake/sources/CxxSources.txt) +absolute_sources(BUN_C_SOURCES ${CWD}/cmake/sources/CSources.txt) if(WIN32) list(APPEND BUN_CXX_SOURCES ${CWD}/src/bun.js/bindings/windows/rescle.cpp) diff --git a/packages/bun-error/runtime-error.ts b/packages/bun-error/runtime-error.ts index 4a739edf3e..81041129d8 100644 --- a/packages/bun-error/runtime-error.ts +++ b/packages/bun-error/runtime-error.ts @@ -42,11 +42,11 @@ export default class RuntimeError { original: Error; stack: StackFrame[]; - static from(error: Error) { + static from(error: Error): RuntimeError { const runtime = new RuntimeError(); runtime.original = error; runtime.stack = this.parseStack(error); - return RuntimeError; + return runtime; } /** diff --git a/scripts/glob-sources.mjs b/scripts/glob-sources.mjs index fa20fd28ad..da991eac1c 100644 --- a/scripts/glob-sources.mjs +++ b/scripts/glob-sources.mjs @@ -23,7 +23,7 @@ async function globSources(output, patterns, excludes = []) { .sort((a, b) => a.localeCompare(b)) .join("\n"); - await write(join(root, "cmake", output), sources); + await write(join(root, "cmake", "sources", output), sources); } const input = await file(join(root, "cmake", "Sources.json")).json(); diff --git a/src/bun.js/webcore/TextDecoder.zig b/src/bun.js/webcore/TextDecoder.zig index 873800b5c3..ebaee756dd 100644 --- a/src/bun.js/webcore/TextDecoder.zig +++ b/src/bun.js/webcore/TextDecoder.zig @@ -280,46 +280,40 @@ fn decodeSlice(this: *TextDecoder, globalThis: *JSC.JSGlobalObject, buffer_slice } pub fn constructor(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!*TextDecoder { - var args_ = callframe.arguments_old(2); - var arguments: []const JSC.JSValue = args_.ptr[0..args_.len]; + const encoding_value, const options_value = callframe.argumentsAsArray(2); var decoder = TextDecoder{}; - if (arguments.len > 0) { - // encoding - if (arguments[0].isString()) { - var str = try arguments[0].toSlice(globalThis, bun.default_allocator); - defer if (str.isAllocated()) str.deinit(); + if (encoding_value.isString()) { + var str = try encoding_value.toSlice(globalThis, bun.default_allocator); + defer str.deinit(); - if (EncodingLabel.which(str.slice())) |label| { - decoder.encoding = label; - } else { - return globalThis.ERR(.ENCODING_NOT_SUPPORTED, "Unsupported encoding label \"{s}\"", .{str.slice()}).throw(); - } - } else if (arguments[0].isUndefined()) { - // default to utf-8 - decoder.encoding = EncodingLabel.@"UTF-8"; + if (EncodingLabel.which(str.slice())) |label| { + decoder.encoding = label; } else { - return globalThis.throwInvalidArguments("TextDecoder(encoding) label is invalid", .{}); + return globalThis.ERR(.ENCODING_NOT_SUPPORTED, "Unsupported encoding label \"{s}\"", .{str.slice()}).throw(); + } + } else if (encoding_value.isUndefined()) { + // default to utf-8 + decoder.encoding = EncodingLabel.@"UTF-8"; + } else { + return globalThis.throwInvalidArguments("TextDecoder(encoding) label is invalid", .{}); + } + + if (!options_value.isUndefined()) { + if (!options_value.isObject()) { + return globalThis.throwInvalidArguments("TextDecoder(options) is invalid", .{}); } - if (arguments.len >= 2) { - const options = arguments[1]; + if (try options_value.get(globalThis, "fatal")) |fatal| { + decoder.fatal = fatal.toBoolean(); + } - if (!options.isObject()) { - return globalThis.throwInvalidArguments("TextDecoder(options) is invalid", .{}); - } - - if (try options.get(globalThis, "fatal")) |fatal| { - decoder.fatal = fatal.toBoolean(); - } - - if (try options.get(globalThis, "ignoreBOM")) |ignoreBOM| { - if (ignoreBOM.isBoolean()) { - decoder.ignore_bom = ignoreBOM.asBoolean(); - } else { - return globalThis.throwInvalidArguments("TextDecoder(options) ignoreBOM is invalid. Expected boolean value", .{}); - } + if (try options_value.get(globalThis, "ignoreBOM")) |ignoreBOM| { + if (ignoreBOM.isBoolean()) { + decoder.ignore_bom = ignoreBOM.asBoolean(); + } else { + return globalThis.throwInvalidArguments("TextDecoder(options) ignoreBOM is invalid. Expected boolean value", .{}); } } } diff --git a/test/internal/ban-words.test.ts b/test/internal/ban-words.test.ts index 31d7e9a8e7..3ed36e67a9 100644 --- a/test/internal/ban-words.test.ts +++ b/test/internal/ban-words.test.ts @@ -41,7 +41,7 @@ const words: Record "std.fs.File": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 64 }, ".stdFile()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 18 }, ".stdDir()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 48 }, - ".arguments_old(": { reason: "Please migrate to .argumentsAsArray() or another argument API", limit: 286 }, + ".arguments_old(": { reason: "Please migrate to .argumentsAsArray() or another argument API", limit: 285 }, "// autofix": { reason: "Evaluate if this variable should be deleted entirely or explicitly discarded.", limit: 176 }, }; const words_keys = [...Object.keys(words)]; diff --git a/test/js/bun/runtime-error.test.ts b/test/js/bun/runtime-error.test.ts new file mode 100644 index 0000000000..36c01859de --- /dev/null +++ b/test/js/bun/runtime-error.test.ts @@ -0,0 +1,9 @@ +import { expect, test } from "bun:test"; +import RuntimeError from "../../../packages/bun-error/runtime-error"; + +test("RuntimeError.from returns instance", () => { + const err = new Error("boom"); + const runtime = RuntimeError.from(err); + expect(runtime.original).toBe(err); + expect(Array.isArray(runtime.stack)).toBe(true); +}); diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js index ca27e07890..42738c4e88 100644 --- a/test/js/web/encoding/text-decoder.test.js +++ b/test/js/web/encoding/text-decoder.test.js @@ -298,6 +298,12 @@ describe("TextDecoder", () => { const decoder = new TextDecoder(undefined); expect(decoder.encoding).toBe("utf-8"); }); + + it("should support undefined options", () => { + expect(() => { + const decoder = new TextDecoder("utf-8", undefined); + }).not.toThrow(); + }); }); describe("TextDecoder ignoreBOM", () => {