Skip to content

Commit

Permalink
node:fs: mode+flags message cleanup (#13332)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Aug 16, 2024
1 parent 766a9cf commit d4237b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ pub fn timeLikeFromJS(globalObject: *JSC.JSGlobalObject, value: JSC.JSValue, _:
pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode {
const mode_int = if (value.isNumber()) brk: {
if (!value.isUInt32AsAnyInt()) {
exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"mode\" is out of range. It must be an integer. Received {d}", .{value.toUInt64NoTruncate()}).toJS().asObjectRef();
exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"mode\" is out of range. It must be an integer. Received {d}", .{value.asNumber()}).toJS().asObjectRef();
return null;
}
break :brk @as(Mode, @truncate(value.to(Mode)));
Expand Down Expand Up @@ -1340,7 +1340,7 @@ pub const FileSystemFlags = enum(Mode) {
pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue, exception: JSC.C.ExceptionRef) ?FileSystemFlags {
if (val.isNumber()) {
if (!val.isInt32()) {
exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.toInt64()}).toJS().asObjectRef();
exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.asNumber()}).toJS().asObjectRef();
return null;
}
const number = val.coerce(i32, ctx);
Expand Down
8 changes: 8 additions & 0 deletions test/js/node/fs/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3296,11 +3296,19 @@ it("open flags verification", async () => {
expect(() => fs.open(__filename, invalid, () => {})).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE");
expect(() => fs.openSync(__filename, invalid)).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE");
expect(async () => await fs.promises.open(__filename, invalid)).toThrow(RangeError);

expect(() => fs.open(__filename, 4294967298.5, () => {})).toThrow(
RangeError(`The value of "flags" is out of range. It must be an integer. Received 4294967298.5`),
);
});

it("open mode verification", async () => {
const invalid = 4_294_967_296;
expect(() => fs.open(__filename, 0, invalid, () => {})).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE");
expect(() => fs.openSync(__filename, 0, invalid)).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE");
expect(async () => await fs.promises.open(__filename, 0, invalid)).toThrow(RangeError);

expect(() => fs.open(__filename, 0, 4294967298.5, () => {})).toThrow(
RangeError(`The value of "mode" is out of range. It must be an integer. Received 4294967298.5`),
);
});

0 comments on commit d4237b0

Please sign in to comment.