Skip to content

Commit

Permalink
[fs] Add missing isFile and isDirectory functions to stat()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Apr 10, 2022
1 parent 764fb63 commit 7cd3d13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/javascript/jsc/base.zig
Expand Up @@ -2788,9 +2788,9 @@ pub fn wrap(
return null;
}

JavaScript.VirtualMachine.vm.tick();
if (comptime maybe_async) {
JavaScript.VirtualMachine.vm.tick();

if (maybe_async) {
var promise = JSC.JSInternalPromise.resolvedPromise(ctx.ptr(), result);

switch (promise.status(ctx.ptr().vm())) {
Expand Down
17 changes: 16 additions & 1 deletion src/javascript/jsc/node/types.zig
Expand Up @@ -755,7 +755,15 @@ fn StatsLike(comptime name: [:0]const u8, comptime T: type) type {
pub const Class = JSC.NewClass(
This,
.{ .name = name },
.{},
.{
.isFile = .{
.rfn = JSC.wrap(This, "isFile", false),
},
.isDirectory = .{
.rfn = JSC.wrap(This, "isDirectory", false),
},
.finalize = finalize,
},
.{
.dev = .{
.get = JSC.To.JS.Getter(This, .dev),
Expand Down Expand Up @@ -887,6 +895,13 @@ fn StatsLike(comptime name: [:0]const u8, comptime T: type) type {
};
}

pub fn isFile(this: *Stats) JSC.JSValue {
return JSC.JSValue.jsBoolean(os.S.ISREG(@intCast(os.mode_t, this.mode)));
}
pub fn isDirectory(this: *Stats) JSC.JSValue {
return JSC.JSValue.jsBoolean(os.S.ISDIR(@intCast(os.mode_t, this.mode)));
}

pub fn toJS(this: Stats, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef {
var _this = bun.default_allocator.create(Stats) catch unreachable;
_this.* = this;
Expand Down

0 comments on commit 7cd3d13

Please sign in to comment.