Skip to content

Commit

Permalink
Fix Stat constructor, remove native code allocation for stat objects (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 24, 2025
1 parent 40d150b commit f7c5b0d
Show file tree
Hide file tree
Showing 13 changed files with 1,170 additions and 484 deletions.
928 changes: 928 additions & 0 deletions src/bun.js/bindings/NodeFSBinding.cpp

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/bun.js/bindings/NodeFSBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#include "root.h"

namespace Bun {

void initJSStatsClassStructure(JSC::LazyClassStructure::Initializer& init);
void initJSBigIntStatsClassStructure(JSC::LazyClassStructure::Initializer& init);

}
14 changes: 14 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
#include "JavaScriptCore/RemoteInspectorServer.h"
#endif

#include "NodeFSBinding.h"

#if !OS(WINDOWS)
#include <dlfcn.h>
#endif
Expand Down Expand Up @@ -2873,6 +2875,16 @@ void GlobalObject::finishCreation(VM& vm)
jsDynamicCast<Zig::GlobalObject*>(init.owner)));
});

m_JSStatsClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
Bun::initJSStatsClassStructure(init);
});

m_JSStatsBigIntClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
Bun::initJSBigIntStatsClassStructure(init);
});

m_memoryFootprintStructure.initLater(
[](const JSC::LazyProperty<JSC::JSGlobalObject, Structure>::Initializer& init) {
init.set(
Expand Down Expand Up @@ -3826,6 +3838,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_lazyRequireCacheObject.visit(visitor);
thisObject->m_lazyTestModuleObject.visit(visitor);
thisObject->m_memoryFootprintStructure.visit(visitor);
thisObject->m_JSStatsClassStructure.visit(visitor);
thisObject->m_JSStatsBigIntClassStructure.visit(visitor);
thisObject->m_NapiClassStructure.visit(visitor);
thisObject->m_NapiExternalStructure.visit(visitor);
thisObject->m_NAPIFunctionStructure.visit(visitor);
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ class GlobalObject : public Bun::GlobalScope {

LazyProperty<JSGlobalObject, Structure> m_JSS3FileStructure;
LazyProperty<JSGlobalObject, Structure> m_S3ErrorStructure;
LazyClassStructure m_JSStatsClassStructure;
LazyClassStructure m_JSStatsBigIntClassStructure;

JSObject* cryptoObject() const { return m_cryptoObject.getInitializedOnMainThread(this); }
JSObject* JSDOMFileConstructor() const { return m_JSDOMFileConstructor.getInitializedOnMainThread(this); }
Expand Down
2 changes: 0 additions & 2 deletions src/bun.js/bindings/generated_classes_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub const Classes = struct {
pub const SHA512 = JSC.API.Bun.Crypto.SHA512;
pub const SHA512_256 = JSC.API.Bun.Crypto.SHA512_256;
pub const ServerWebSocket = JSC.API.ServerWebSocket;
pub const Stats = JSC.Node.StatsSmall;
pub const BigIntStats = JSC.Node.StatsBig;
pub const Subprocess = JSC.Subprocess;
pub const ResourceUsage = JSC.ResourceUsage;
pub const TCPSocket = JSC.API.TCPSocket;
Expand Down
233 changes: 6 additions & 227 deletions src/bun.js/node/node.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,220 +161,6 @@ export default [
},
values: ["arguments", "callback"],
}),
define({
name: "Stats",
construct: true,
finalize: true,
klass: {},
JSType: "0b11101110",

// TODO: generate-classes needs to handle Object.create properly when
// functions are used. The functions need a fallback implementation to use
// getters.
supportsObjectCreate: true,

proto: {
isBlockDevice: {
fn: "isBlockDevice_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isCharacterDevice: {
fn: "isCharacterDevice_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isDirectory: {
fn: "isDirectory_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isFIFO: {
fn: "isFIFO_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isFile: {
fn: "isFile_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isSocket: {
fn: "isSocket_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isSymbolicLink: {
fn: "isSymbolicLink_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
},
own: {
dev: "dev",
ino: "ino",
mode: "mode",
nlink: "nlink",
uid: "uid",
gid: "gid",
rdev: "rdev",
size: "size",
blksize: "blksize",
blocks: "blocks",
atimeMs: "atimeMs",
mtimeMs: "mtimeMs",
ctimeMs: "ctimeMs",
birthtimeMs: "birthtimeMs",
atime: "atime",
mtime: "mtime",
ctime: "ctime",
birthtime: "birthtime",
},
}),
define({
name: "BigIntStats",
construct: true,
finalize: true,
klass: {},
JSType: "0b11101110",

// TODO: generate-classes needs to handle Object.create properly when
// functions are used. The functions need a fallback implementation to use
// getters.
supportsObjectCreate: true,

proto: {
isBlockDevice: {
fn: "isBlockDevice_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isCharacterDevice: {
fn: "isCharacterDevice_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isDirectory: {
fn: "isDirectory_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isFIFO: {
fn: "isFIFO_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isFile: {
fn: "isFile_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isSocket: {
fn: "isSocket_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
isSymbolicLink: {
fn: "isSymbolicLink_",
length: 0,
enumerable: false,
DOMJIT: {
returns: "bool",
args: [],
pure: true,
},
},
},
own: {
atime: "atime",
atimeMs: "atimeMs",
atimeNs: "atimeNs",
birthtime: "birthtime",
birthtimeMs: "birthtimeMs",
birthtimeNs: "birthtimeNs",
blksize: "blksize",
blocks: "blocks",
ctime: "ctime",
ctimeMs: "ctimeMs",
ctimeNs: "ctimeNs",
dev: "dev",
gid: "gid",
ino: "ino",
mode: "mode",
mtime: "mtime",
mtimeMs: "mtimeMs",
mtimeNs: "mtimeNs",
nlink: "nlink",
rdev: "rdev",
size: "size",
uid: "uid",
},
}),
define({
name: "Dirent",
construct: true,
Expand Down Expand Up @@ -416,19 +202,12 @@ export default [
fn: "isSymbolicLink",
length: 0,
},
name: {
getter: "getName",
cache: true,
},
path: {
getter: "getPath",
cache: true,
},
parentPath: {
// @since node v20.12.x
getter: "getPath",
cache: true,
},
},

own: {
name: "getName",
path: "getPath",
parentPath: "getPath",
},
}),
define({
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/node/node_fs_stat_watcher.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const log = bun.Output.scoped(.StatWatcher, false);

fn statToJSStats(globalThis: *JSC.JSGlobalObject, stats: bun.Stat, bigint: bool) JSC.JSValue {
if (bigint) {
return StatsBig.new(StatsBig.init(stats)).toJS(globalThis);
return StatsBig.init(stats).toJS(globalThis);
} else {
return StatsSmall.new(StatsSmall.init(stats)).toJS(globalThis);
return StatsSmall.init(stats).toJS(globalThis);
}
}

Expand Down
Loading

0 comments on commit f7c5b0d

Please sign in to comment.