[fs] Add missing isFile and isDirectory functions to stat()

This commit is contained in:
Jarred Sumner
2022-04-09 21:45:46 -07:00
parent 764fb63617
commit 7cd3d13011
2 changed files with 18 additions and 3 deletions

View File

@@ -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())) {

View File

@@ -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),
@@ -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;