This commit is contained in:
Jarred Sumner
2024-10-10 21:50:03 -07:00
committed by GitHub
parent 584a8ceb84
commit 05f53dc70f
3 changed files with 17 additions and 3 deletions

View File

@@ -6510,6 +6510,10 @@ pub const CallFrame = opaque {
pub inline fn slice(self: *const @This()) []const JSValue {
return self.ptr[0..self.len];
}
pub inline fn all(self: *const @This()) []const JSValue {
return self.ptr[0..];
}
};
}

View File

@@ -146,9 +146,9 @@ pub const Ansi256 = struct {
};
pub fn jsFunctionColor(globalThis: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(JSC.conv) JSC.JSValue {
const args = callFrame.arguments(2).slice();
if (args.len < 1 or args[0].isUndefined()) {
globalThis.throwNotEnoughArguments("Bun.color", 2, args.len);
const args = callFrame.argumentsUndef(2).all();
if (args[0].isUndefined()) {
globalThis.throwInvalidArgumentType("color", "input", "string, number, or object");
return JSC.JSValue.jsUndefined();
}

View File

@@ -180,6 +180,7 @@ const bad = [
];
test.each(bad)("color(%s, 'css') === null", input => {
expect(color(input, "css")).toBeNull();
expect(color(input)).toBeNull();
});
const weird = [
@@ -189,9 +190,18 @@ const weird = [
describe("weird", () => {
test.each(weird)("color(%s, 'css') === %s", (input, expected) => {
expect(color(input, "css")).toEqual(expected);
expect(color(input)).toEqual(expected);
});
});
test("0 args", () => {
expect(() => color()).toThrow(
expect.objectContaining({
code: "ERR_INVALID_ARG_TYPE",
}),
);
});
test("fuzz ansi256", () => {
withoutAggressiveGC(() => {
for (let i = 0; i < 256; i++) {