diff options
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.cpp | 16 | ||||
-rw-r--r-- | src/bun.js/bindings/generated_classes.zig | 4 | ||||
-rw-r--r-- | src/bun.js/fs.exports.js | 4 | ||||
-rw-r--r-- | src/bun.js/node/node.classes.ts | 2 | ||||
-rw-r--r-- | src/bun.js/node/node_fs_binding.zig | 4 | ||||
-rw-r--r-- | test/bun.js/fs.test.js | 11 |
6 files changed, 40 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index c5112a4ad..85dfb7b3b 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -4458,6 +4458,9 @@ JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__rmSyncCallback); extern "C" EncodedJSValue NodeJSFSPrototype__stat(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__statCallback); +extern "C" JSC::EncodedJSValue NodeJSFSPrototype__getStats(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(NodeJSFSPrototype__StatsGetterWrap); + extern "C" EncodedJSValue NodeJSFSPrototype__statSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__statSyncCallback); @@ -4572,6 +4575,7 @@ static const HashTableValue JSNodeJSFSPrototypeTableValues[] = { { "rmdirSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmdirSyncCallback, 2 } }, { "rmSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmSyncCallback, 2 } }, { "stat"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__statCallback, 1 } }, + { "Stats"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, NodeJSFSPrototype__StatsGetterWrap, 0 } }, { "statSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__statSyncCallback, 1 } }, { "symlink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__symlinkCallback, 4 } }, { "symlinkSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__symlinkSyncCallback, 3 } }, @@ -5655,6 +5659,18 @@ JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__statCallback, (JSGlobalObject * lexi return NodeJSFSPrototype__stat(thisObject->wrapped(), lexicalGlobalObject, callFrame); } +JSC_DEFINE_CUSTOM_GETTER(NodeJSFSPrototype__StatsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSNodeJSFS* thisObject = jsCast<JSNodeJSFS*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = NodeJSFSPrototype__getStats(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__statSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) { auto& vm = lexicalGlobalObject->vm(); diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 18bf91b99..1687557e4 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -1498,6 +1498,9 @@ pub const JSNodeJSFS = struct { @compileLog("Expected NodeJSFS.rmSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rmSync))); if (@TypeOf(NodeJSFS.stat) != CallbackType) @compileLog("Expected NodeJSFS.stat to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.stat))); + if (@TypeOf(NodeJSFS.getStats) != GetterType) + @compileLog("Expected NodeJSFS.getStats to be a getter"); + if (@TypeOf(NodeJSFS.statSync) != CallbackType) @compileLog("Expected NodeJSFS.statSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.statSync))); if (@TypeOf(NodeJSFS.symlink) != CallbackType) @@ -1559,6 +1562,7 @@ pub const JSNodeJSFS = struct { @export(NodeJSFS.futimes, .{ .name = "NodeJSFSPrototype__futimes" }); @export(NodeJSFS.futimesSync, .{ .name = "NodeJSFSPrototype__futimesSync" }); @export(NodeJSFS.getDirent, .{ .name = "NodeJSFSPrototype__getDirent" }); + @export(NodeJSFS.getStats, .{ .name = "NodeJSFSPrototype__getStats" }); @export(NodeJSFS.lchmod, .{ .name = "NodeJSFSPrototype__lchmod" }); @export(NodeJSFS.lchmodSync, .{ .name = "NodeJSFSPrototype__lchmodSync" }); @export(NodeJSFS.lchown, .{ .name = "NodeJSFSPrototype__lchown" }); diff --git a/src/bun.js/fs.exports.js b/src/bun.js/fs.exports.js index 86a0ef469..00b0054e8 100644 --- a/src/bun.js/fs.exports.js +++ b/src/bun.js/fs.exports.js @@ -146,6 +146,8 @@ export var access = function access(...args) { lutimesSync = fs.lutimesSync.bind(fs), rmSync = fs.rmSync.bind(fs), rmdirSync = fs.rmdirSync.bind(fs), + Dirent = fs.Dirent, + Stats = fs.Stats, promises = import.meta.require("node:fs/promises"); function callbackify(fsFunction, args) { @@ -871,6 +873,7 @@ export default { copyFileSync, createReadStream, createWriteStream, + Dirent, exists, existsSync, fchmod, @@ -920,6 +923,7 @@ export default { rmdirSync, stat, statSync, + Stats, symlink, symlinkSync, truncate, diff --git a/src/bun.js/node/node.classes.ts b/src/bun.js/node/node.classes.ts index 355b5847e..615c3017f 100644 --- a/src/bun.js/node/node.classes.ts +++ b/src/bun.js/node/node.classes.ts @@ -143,7 +143,7 @@ export default [ // TODO: // Dir: { fn: 'Dir', length: 3 }, Dirent: { getter: "getDirent" }, - // Stats: { fn: 'Stats', length: 14 }, + Stats: { getter: 'getStats' }, // ReadStream: { fn: 'ReadStream', length: 2 }, // WriteStream: { fn: 'WriteStream', length: 2 }, // FileReadStream: { fn: 'FileReadStream', length: 2 }, diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index 219f85cd8..61fd0f82b 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -233,6 +233,10 @@ pub const NodeJSFS = struct { return JSC.Node.Dirent.getConstructor(globalThis); } + pub fn getStats(_: *NodeJSFS, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { + return JSC.Node.Stats.getConstructor(globalThis); + } + // Not implemented yet: const notimpl = fdatasync; pub const opendir = notimpl; diff --git a/test/bun.js/fs.test.js b/test/bun.js/fs.test.js index 56f98b32c..f78ce13da 100644 --- a/test/bun.js/fs.test.js +++ b/test/bun.js/fs.test.js @@ -23,6 +23,8 @@ import { unlinkSync, mkdtempSync, constants, + Dirent, + Stats, } from "node:fs"; import { join } from "node:path"; @@ -767,3 +769,12 @@ it("fs.constants", () => { expect(constants.S_IROTH).toBeDefined(); expect(constants.S_IWOTH).toBeDefined(); }); + + +it("fs.Dirent", () => { + expect(Dirent).toBeDefined(); +}); + +it("fs.Stats", () => { + expect(Stats).toBeDefined(); +}); |