aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-05-16 20:08:00 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-16 17:08:00 -0700
commitad20b13985fd1cc045fe07a4560f8dd7087a43d7 (patch)
tree112226b65d5d833e153c4989fb26c307d7ecb199
parent1ad8c54c90438c156ad068bdee1d70dfb9404db3 (diff)
downloadbun-ad20b13985fd1cc045fe07a4560f8dd7087a43d7.tar.gz
bun-ad20b13985fd1cc045fe07a4560f8dd7087a43d7.tar.zst
bun-ad20b13985fd1cc045fe07a4560f8dd7087a43d7.zip
Fix segfault on passing undefined to bun.build (#2902)
-rw-r--r--src/bun.js/api/JSBundler.zig5
-rw-r--r--test/bundler/build.test.ts10
2 files changed, 15 insertions, 0 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index c95c359f1..741d956bf 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -494,6 +494,11 @@ pub const JSBundler = struct {
globalThis: *JSC.JSGlobalObject,
arguments: []const JSC.JSValue,
) JSC.JSValue {
+ if (arguments.len == 0 or !arguments[0].isObject()) {
+ globalThis.throwInvalidArguments("Expected a config object to be passed to Bun.build", .{});
+ return JSC.JSValue.jsUndefined();
+ }
+
var plugins: ?*Plugin = null;
const config = Config.fromJS(globalThis, arguments[0], &plugins, globalThis.allocator()) catch {
return JSC.JSValue.jsUndefined();
diff --git a/test/bundler/build.test.ts b/test/bundler/build.test.ts
index 054f24bc3..921481a4b 100644
--- a/test/bundler/build.test.ts
+++ b/test/bundler/build.test.ts
@@ -4,6 +4,16 @@ import { bunEnv, bunExe } from "harness";
import { join } from "path";
describe("Bun.build", () => {
+ test("passing undefined doesnt segfault", () => {
+ try {
+ // @ts-ignore
+ Bun.build();
+ } catch (error) {
+ return;
+ }
+ throw new Error("should have thrown");
+ });
+
test("invalid options throws", async () => {
expect(() => Bun.build({} as any)).toThrow();
expect(() =>