mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
@@ -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..];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user