diff options
author | 2023-08-18 19:59:03 -0700 | |
---|---|---|
committer | 2023-08-18 19:59:03 -0700 | |
commit | 26036a390b71e079e31694d2dcf64572e30db74f (patch) | |
tree | 615d509d8253c2bc3418b93b61531cfee83ca71e | |
parent | 943a6642243cbc8a180ab7108279dd7110ab1eaf (diff) | |
download | bun-26036a390b71e079e31694d2dcf64572e30db74f.tar.gz bun-26036a390b71e079e31694d2dcf64572e30db74f.tar.zst bun-26036a390b71e079e31694d2dcf64572e30db74f.zip |
Implement BigIntStats (#4208)
* Implement BigIntStats
* changes
* rename test
* comment
* test changes?
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h | 6 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h | 7 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.cpp | 1052 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.h | 59 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/generated_classes.zig | 308 | ||||
-rw-r--r-- | src/bun.js/bindings/generated_classes_list.zig | 3 | ||||
-rw-r--r-- | src/bun.js/node/node.classes.ts | 149 | ||||
-rw-r--r-- | src/bun.js/node/node_fs.zig | 5 | ||||
-rw-r--r-- | src/bun.js/node/node_fs_binding.zig | 2 | ||||
-rw-r--r-- | src/bun.js/node/types.zig | 460 | ||||
-rw-r--r-- | test/js/node/fs/fs.test.ts | 35 |
14 files changed, 1874 insertions, 221 deletions
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h index 3d878ab22..3c3aa5669 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h @@ -1,5 +1,6 @@ std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForAttributeIterator; -std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlob; +std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBigIntStats; +std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBigIntStatsConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlob; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildArtifact; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildMessage; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildMessageConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForComment; diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h index 47fac3029..a521090c0 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h @@ -1,5 +1,6 @@ std::unique_ptr<IsoSubspace> m_subspaceForAttributeIterator; -std::unique_ptr<IsoSubspace> m_subspaceForBlob; +std::unique_ptr<IsoSubspace> m_subspaceForBigIntStats; +std::unique_ptr<IsoSubspace> m_subspaceForBigIntStatsConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBlob; std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBuildArtifact; std::unique_ptr<IsoSubspace> m_subspaceForBuildMessage; std::unique_ptr<IsoSubspace> m_subspaceForBuildMessageConstructor;std::unique_ptr<IsoSubspace> m_subspaceForComment; diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index 731ecd81d..0596372b4 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -4,6 +4,12 @@ JSC::Structure* JSAttributeIteratorStructure() { return m_JSAttributeIterator.ge JSC::LazyClassStructure m_JSAttributeIterator; bool hasJSAttributeIteratorSetterValue { false }; mutable JSC::WriteBarrier<JSC::Unknown> m_JSAttributeIteratorSetterValue; +JSC::Structure* JSBigIntStatsStructure() { return m_JSBigIntStats.getInitializedOnMainThread(this); } + JSC::JSObject* JSBigIntStatsConstructor() { return m_JSBigIntStats.constructorInitializedOnMainThread(this); } + JSC::JSValue JSBigIntStatsPrototype() { return m_JSBigIntStats.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSBigIntStats; + bool hasJSBigIntStatsSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSBigIntStatsSetterValue; JSC::Structure* JSBlobStructure() { return m_JSBlob.getInitializedOnMainThread(this); } JSC::JSObject* JSBlobConstructor() { return m_JSBlob.constructorInitializedOnMainThread(this); } JSC::JSValue JSBlobPrototype() { return m_JSBlob.prototypeInitializedOnMainThread(this); } diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index 9c31c6708..40a473727 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -5,6 +5,12 @@ void GlobalObject::initGeneratedLazyClasses() { init.setStructure(WebCore::JSAttributeIterator::createStructure(init.vm, init.global, init.prototype)); }); + m_JSBigIntStats.initLater( + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSBigIntStats::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSBigIntStats::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSBigIntStats::createConstructor(init.vm, init.global, init.prototype)); + }); m_JSBlob.initLater( [](LazyClassStructure::Initializer& init) { init.setPrototype(WebCore::JSBlob::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); @@ -292,6 +298,7 @@ template<typename Visitor> void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) { thisObject->m_JSAttributeIterator.visit(visitor); visitor.append(thisObject->m_JSAttributeIteratorSetterValue); + thisObject->m_JSBigIntStats.visit(visitor); visitor.append(thisObject->m_JSBigIntStatsSetterValue); thisObject->m_JSBlob.visit(visitor); visitor.append(thisObject->m_JSBlobSetterValue); thisObject->m_JSBuildArtifact.visit(visitor); visitor.append(thisObject->m_JSBuildArtifactSetterValue); thisObject->m_JSBuildMessage.visit(visitor); visitor.append(thisObject->m_JSBuildMessageSetterValue); diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 1609480e9..066732db9 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -230,6 +230,1058 @@ extern "C" EncodedJSValue AttributeIterator__create(Zig::GlobalObject* globalObj return JSValue::encode(instance); } +class JSBigIntStatsPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + + static JSBigIntStatsPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + JSBigIntStatsPrototype* ptr = new (NotNull, JSC::allocateCell<JSBigIntStatsPrototype>(vm)) JSBigIntStatsPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSBigIntStatsPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +class JSBigIntStatsConstructor final : public JSC::InternalFunction { +public: + using Base = JSC::InternalFunction; + static JSBigIntStatsConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSBigIntStatsPrototype* prototype); + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); + } + + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSBigIntStatsConstructor, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForBigIntStatsConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBigIntStatsConstructor = std::forward<decltype(space)>(space); }, + [](auto& spaces) { return spaces.m_subspaceForBigIntStatsConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForBigIntStatsConstructor = std::forward<decltype(space)>(space); }); + } + + void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSBigIntStatsPrototype* prototype); + + // Must be defined for each specialization class. + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); + + DECLARE_EXPORT_INFO; + +private: + JSBigIntStatsConstructor(JSC::VM& vm, JSC::Structure* structure); + void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSBigIntStatsPrototype* prototype); +}; + +extern "C" void* BigIntStatsClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*); +JSC_DECLARE_CUSTOM_GETTER(jsBigIntStatsConstructor); + +extern "C" void BigIntStatsClass__finalize(void*); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__atime(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__atimeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__atimeMs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__atimeMsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__atimeNs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__atimeNsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__birthtime(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__birthtimeMs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeMsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__birthtimeNs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeNsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__blksize(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__blksizeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__blocks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__blocksGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__ctime(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__ctimeMs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeMsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__ctimeNs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeNsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__dev(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__devGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__gid(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__gidGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__ino(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__inoGetterWrap); + +extern "C" EncodedJSValue BigIntStatsPrototype__isBlockDevice_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isBlockDeviceCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isBlockDeviceWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isBlockDevice_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isBlockDevice(BigIntStatsPrototype__isBlockDeviceWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isBlockDeviceWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isBlockDevice_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isCharacterDevice_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isCharacterDeviceCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isCharacterDeviceWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isCharacterDevice_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isCharacterDevice(BigIntStatsPrototype__isCharacterDeviceWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isCharacterDeviceWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isCharacterDevice_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isDirectory_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isDirectoryCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isDirectoryWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isDirectory_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isDirectory(BigIntStatsPrototype__isDirectoryWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isDirectoryWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isDirectory_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isFIFO_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isFIFOCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isFIFOWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isFIFO_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isFIFO(BigIntStatsPrototype__isFIFOWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isFIFOWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isFIFO_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isFile_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isFileCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isFileWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isFile_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isFile(BigIntStatsPrototype__isFileWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isFileWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isFile_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isSocket_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isSocketCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isSocketWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isSocket_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isSocket(BigIntStatsPrototype__isSocketWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isSocketWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isSocket_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__isSymbolicLink_(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(BigIntStatsPrototype__isSymbolicLinkCallback); + +extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(BigIntStatsPrototype__isSymbolicLinkWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)); +extern "C" EncodedJSValue BigIntStatsPrototype__isSymbolicLink_WithoutTypeChecks(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); + +static const JSC::DOMJIT::Signature DOMJITSignatureForBigIntStatsPrototype__isSymbolicLink(BigIntStatsPrototype__isSymbolicLinkWithoutTypeChecksWrapper, + JSBigIntStats::info(), + JSC::DOMJIT::Effect::forPure(), + JSC::SpecHeapTop); + +JSC_DEFINE_JIT_OPERATION(BigIntStatsPrototype__isSymbolicLinkWithoutTypeChecksWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + IGNORE_WARNINGS_BEGIN("frame-address") + CallFrame* callFrame = DECLARE_CALL_FRAME(vm); + IGNORE_WARNINGS_END + JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame); + return BigIntStatsPrototype__isSymbolicLink_WithoutTypeChecks(reinterpret_cast<JSBigIntStats*>(thisValue)->wrapped(), lexicalGlobalObject); +} + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__mode(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__modeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__mtime(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__mtimeMs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeMsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__mtimeNs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeNsGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__nlink(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__nlinkGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__rdev(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__rdevGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__size(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__sizeGetterWrap); + +extern "C" JSC::EncodedJSValue BigIntStatsPrototype__uid(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(BigIntStatsPrototype__uidGetterWrap); + +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBigIntStatsPrototype, JSBigIntStatsPrototype::Base); + +static const HashTableValue JSBigIntStatsPrototypeTableValues[] = { + { "atime"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__atimeGetterWrap, 0 } }, + { "atimeMs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__atimeMsGetterWrap, 0 } }, + { "atimeNs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__atimeNsGetterWrap, 0 } }, + { "birthtime"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__birthtimeGetterWrap, 0 } }, + { "birthtimeMs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__birthtimeMsGetterWrap, 0 } }, + { "birthtimeNs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__birthtimeNsGetterWrap, 0 } }, + { "blksize"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__blksizeGetterWrap, 0 } }, + { "blocks"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__blocksGetterWrap, 0 } }, + { "ctime"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__ctimeGetterWrap, 0 } }, + { "ctimeMs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__ctimeMsGetterWrap, 0 } }, + { "ctimeNs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__ctimeNsGetterWrap, 0 } }, + { "dev"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__devGetterWrap, 0 } }, + { "gid"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__gidGetterWrap, 0 } }, + { "ino"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__inoGetterWrap, 0 } }, + { "isBlockDevice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isBlockDeviceCallback, &DOMJITSignatureForBigIntStatsPrototype__isBlockDevice } }, + { "isCharacterDevice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isCharacterDeviceCallback, &DOMJITSignatureForBigIntStatsPrototype__isCharacterDevice } }, + { "isDirectory"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isDirectoryCallback, &DOMJITSignatureForBigIntStatsPrototype__isDirectory } }, + { "isFIFO"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isFIFOCallback, &DOMJITSignatureForBigIntStatsPrototype__isFIFO } }, + { "isFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isFileCallback, &DOMJITSignatureForBigIntStatsPrototype__isFile } }, + { "isSocket"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isSocketCallback, &DOMJITSignatureForBigIntStatsPrototype__isSocket } }, + { "isSymbolicLink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::DOMJITFunctionType, BigIntStatsPrototype__isSymbolicLinkCallback, &DOMJITSignatureForBigIntStatsPrototype__isSymbolicLink } }, + { "mode"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__modeGetterWrap, 0 } }, + { "mtime"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__mtimeGetterWrap, 0 } }, + { "mtimeMs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__mtimeMsGetterWrap, 0 } }, + { "mtimeNs"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__mtimeNsGetterWrap, 0 } }, + { "nlink"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__nlinkGetterWrap, 0 } }, + { "rdev"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__rdevGetterWrap, 0 } }, + { "size"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__sizeGetterWrap, 0 } }, + { "uid"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BigIntStatsPrototype__uidGetterWrap, 0 } } +}; + +const ClassInfo JSBigIntStatsPrototype::s_info = { "BigIntStats"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBigIntStatsPrototype) }; + +JSC_DEFINE_CUSTOM_GETTER(jsBigIntStatsConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto* prototype = jsDynamicCast<JSBigIntStatsPrototype*>(JSValue::decode(thisValue)); + + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(globalObject->JSBigIntStatsConstructor()); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__atimeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_atime.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + BigIntStatsPrototype__atime(thisObject->wrapped(), globalObject)); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_atime.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +extern "C" void BigIntStatsPrototype__atimeSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + thisObject->m_atime.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__atimeGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_atime.get()); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__atimeMsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__atimeMs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__atimeNsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__atimeNs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_birthtime.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + BigIntStatsPrototype__birthtime(thisObject->wrapped(), globalObject)); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_birthtime.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +extern "C" void BigIntStatsPrototype__birthtimeSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + thisObject->m_birthtime.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__birthtimeGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_birthtime.get()); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeMsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__birthtimeMs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__birthtimeNsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__birthtimeNs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__blksizeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__blksize(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__blocksGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__blocks(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_ctime.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + BigIntStatsPrototype__ctime(thisObject->wrapped(), globalObject)); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_ctime.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +extern "C" void BigIntStatsPrototype__ctimeSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + thisObject->m_ctime.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__ctimeGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_ctime.get()); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeMsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__ctimeMs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__ctimeNsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__ctimeNs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__devGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__dev(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__gidGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__gid(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__inoGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__ino(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isBlockDeviceCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isBlockDevice_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isCharacterDeviceCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isCharacterDevice_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isDirectoryCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isDirectory_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isFIFOCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isFIFO_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isFile_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isSocketCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isSocket_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(BigIntStatsPrototype__isSymbolicLinkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSBigIntStats* thisObject = jsDynamicCast<JSBigIntStats*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + +#ifdef BUN_DEBUG + /** View the file name of the JS file that called this function + * from a debugger */ + SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm); + const char* fileName = sourceOrigin.string().utf8().data(); + static const char* lastFileName = nullptr; + if (lastFileName != fileName) { + lastFileName = fileName; + } +#endif + + return BigIntStatsPrototype__isSymbolicLink_(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__modeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__mode(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_mtime.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + BigIntStatsPrototype__mtime(thisObject->wrapped(), globalObject)); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_mtime.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +extern "C" void BigIntStatsPrototype__mtimeSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + thisObject->m_mtime.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue BigIntStatsPrototype__mtimeGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_mtime.get()); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeMsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__mtimeMs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__mtimeNsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__mtimeNs(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__nlinkGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__nlink(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__rdevGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__rdev(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__sizeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__size(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_CUSTOM_GETTER(BigIntStatsPrototype__uidGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = BigIntStatsPrototype__uid(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +void JSBigIntStatsPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSBigIntStats::info(), JSBigIntStatsPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +void JSBigIntStatsConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSBigIntStatsPrototype* prototype) +{ + Base::finishCreation(vm, 0, "BigIntStats"_s, PropertyAdditionMode::WithoutStructureTransition); + + putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + ASSERT(inherits(info())); +} + +JSBigIntStatsConstructor::JSBigIntStatsConstructor(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, construct, construct) +{ +} + +JSBigIntStatsConstructor* JSBigIntStatsConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSBigIntStatsPrototype* prototype) +{ + JSBigIntStatsConstructor* ptr = new (NotNull, JSC::allocateCell<JSBigIntStatsConstructor>(vm)) JSBigIntStatsConstructor(vm, structure); + ptr->finishCreation(vm, globalObject, prototype); + return ptr; +} + +JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBigIntStatsConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + JSC::VM& vm = globalObject->vm(); + JSObject* newTarget = asObject(callFrame->newTarget()); + auto* constructor = globalObject->JSBigIntStatsConstructor(); + Structure* structure = globalObject->JSBigIntStatsStructure(); + if (constructor != newTarget) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>( + // ShadowRealm functions belong to a different global object. + getFunctionRealm(globalObject, newTarget)); + RETURN_IF_EXCEPTION(scope, {}); + structure = InternalFunction::createSubclassStructure( + globalObject, + newTarget, + functionGlobalObject->JSBigIntStatsStructure()); + } + + void* ptr = BigIntStatsClass__construct(globalObject, callFrame); + + if (UNLIKELY(!ptr)) { + return JSValue::encode(JSC::jsUndefined()); + } + + JSBigIntStats* instance = JSBigIntStats::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +void JSBigIntStatsConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSBigIntStatsPrototype* prototype) +{ +} + +const ClassInfo JSBigIntStatsConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBigIntStatsConstructor) }; + +extern "C" EncodedJSValue BigIntStats__getConstructor(Zig::GlobalObject* globalObject) +{ + return JSValue::encode(globalObject->JSBigIntStatsConstructor()); +} + +JSBigIntStats::~JSBigIntStats() +{ + if (m_ctx) { + BigIntStatsClass__finalize(m_ctx); + } +} +void JSBigIntStats::destroy(JSCell* cell) +{ + static_cast<JSBigIntStats*>(cell)->JSBigIntStats::~JSBigIntStats(); +} + +const ClassInfo JSBigIntStats::s_info = { "BigIntStats"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBigIntStats) }; + +void JSBigIntStats::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(info())); +} + +JSBigIntStats* JSBigIntStats::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) +{ + JSBigIntStats* ptr = new (NotNull, JSC::allocateCell<JSBigIntStats>(vm)) JSBigIntStats(vm, structure, ctx); + ptr->finishCreation(vm); + return ptr; +} + +extern "C" void* BigIntStats__fromJS(JSC::EncodedJSValue value) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(value); + if (decodedValue.isEmpty() || !decodedValue.isCell()) + return nullptr; + + JSC::JSCell* cell = decodedValue.asCell(); + JSBigIntStats* object = JSC::jsDynamicCast<JSBigIntStats*>(cell); + + if (!object) + return nullptr; + + return object->wrapped(); +} + +extern "C" bool BigIntStats__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) +{ + JSBigIntStats* object = JSC::jsDynamicCast<JSBigIntStats*>(JSValue::decode(value)); + if (!object) + return false; + + object->m_ctx = ptr; + return true; +} + +extern "C" const size_t BigIntStats__ptrOffset = JSBigIntStats::offsetOfWrapped(); + +void JSBigIntStats::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast<JSBigIntStats*>(cell); + if (void* wrapped = thisObject->wrapped()) { + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + } + Base::analyzeHeap(cell, analyzer); +} + +JSObject* JSBigIntStats::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype) +{ + return WebCore::JSBigIntStatsConstructor::create(vm, globalObject, WebCore::JSBigIntStatsConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<WebCore::JSBigIntStatsPrototype*>(prototype)); +} + +JSObject* JSBigIntStats::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) +{ + return JSBigIntStatsPrototype::create(vm, globalObject, JSBigIntStatsPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); +} + +extern "C" EncodedJSValue BigIntStats__create(Zig::GlobalObject* globalObject, void* ptr) +{ + auto& vm = globalObject->vm(); + JSC::Structure* structure = globalObject->JSBigIntStatsStructure(); + JSBigIntStats* instance = JSBigIntStats::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +template<typename Visitor> +void JSBigIntStats::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + + visitor.append(thisObject->m_atime); + visitor.append(thisObject->m_birthtime); + visitor.append(thisObject->m_ctime); + visitor.append(thisObject->m_mtime); +} + +DEFINE_VISIT_CHILDREN(JSBigIntStats); + +template<typename Visitor> +void JSBigIntStats::visitAdditionalChildren(Visitor& visitor) +{ + JSBigIntStats* thisObject = this; + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + + visitor.append(thisObject->m_atime); + visitor.append(thisObject->m_birthtime); + visitor.append(thisObject->m_ctime); + visitor.append(thisObject->m_mtime); +} + +DEFINE_VISIT_ADDITIONAL_CHILDREN(JSBigIntStats); + +template<typename Visitor> +void JSBigIntStats::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor) +{ + JSBigIntStats* thisObject = jsCast<JSBigIntStats*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + thisObject->visitAdditionalChildren<Visitor>(visitor); +} + +DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSBigIntStats); class JSBlobPrototype final : public JSC::JSNonFinalObject { public: using Base = JSC::JSNonFinalObject; diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index bd7750ebf..6ed7eb5de 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -66,6 +66,65 @@ public: void finishCreation(JSC::VM&); }; +class JSBigIntStats final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSBigIntStats* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSBigIntStats, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForBigIntStats.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBigIntStats = std::forward<decltype(space)>(space); }, + [](auto& spaces) { return spaces.m_subspaceForBigIntStats.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForBigIntStats = std::forward<decltype(space)>(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(0b11101110), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSBigIntStats(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSBigIntStats, m_ctx); } + + void* m_ctx { nullptr }; + + JSBigIntStats(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); + + DECLARE_VISIT_CHILDREN; + template<typename Visitor> void visitAdditionalChildren(Visitor&); + DECLARE_VISIT_OUTPUT_CONSTRAINTS; + + mutable JSC::WriteBarrier<JSC::Unknown> m_atime; + mutable JSC::WriteBarrier<JSC::Unknown> m_birthtime; + mutable JSC::WriteBarrier<JSC::Unknown> m_ctime; + mutable JSC::WriteBarrier<JSC::Unknown> m_mtime; +}; + class JSBlob final : public JSC::JSDestructibleObject { public: using Base = JSC::JSDestructibleObject; diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 124f71d86..2c6f634a9 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3762,6 +3762,7 @@ pub const JSValue = enum(JSValueReprInt) { 0...std.math.maxInt(i32) => jsNumberFromInt32(@as(i32, @intCast(number))), else => jsNumberFromInt64(@as(i64, @intCast(number))), }, + // u0 => jsNumberFromInt32(0), else => @compileError("Type transformation missing for number of type: " ++ @typeName(Number)), }; } @@ -4140,9 +4141,11 @@ pub const JSValue = enum(JSValueReprInt) { return null; } + /// This always returns a JS BigInt pub fn fromInt64NoTruncate(globalObject: *JSGlobalObject, i: i64) JSValue { return cppFn("fromInt64NoTruncate", .{ globalObject, i }); } + /// This always returns a JS BigInt pub fn fromUInt64NoTruncate(globalObject: *JSGlobalObject, i: u64) JSValue { return cppFn("fromUInt64NoTruncate", .{ globalObject, i }); } diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 130c47277..70cf4728d 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -84,6 +84,313 @@ pub const JSAttributeIterator = struct { } } }; +pub const JSBigIntStats = struct { + const BigIntStats = Classes.BigIntStats; + const GetterType = fn (*BigIntStats, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const GetterTypeWithThisValue = fn (*BigIntStats, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const SetterType = fn (*BigIntStats, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const SetterTypeWithThisValue = fn (*BigIntStats, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const CallbackType = fn (*BigIntStats, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; + + /// Return the pointer to the wrapped object. + /// If the object does not match the type, return null. + pub fn fromJS(value: JSC.JSValue) ?*BigIntStats { + JSC.markBinding(@src()); + return BigIntStats__fromJS(value); + } + + extern fn BigIntStatsPrototype__atimeSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn BigIntStatsPrototype__atimeGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `BigIntStats.atime` setter + /// This value will be visited by the garbage collector. + pub fn atimeSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + BigIntStatsPrototype__atimeSetCachedValue(thisValue, globalObject, value); + } + + /// `BigIntStats.atime` getter + /// This value will be visited by the garbage collector. + pub fn atimeGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = BigIntStatsPrototype__atimeGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + extern fn BigIntStatsPrototype__birthtimeSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn BigIntStatsPrototype__birthtimeGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `BigIntStats.birthtime` setter + /// This value will be visited by the garbage collector. + pub fn birthtimeSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + BigIntStatsPrototype__birthtimeSetCachedValue(thisValue, globalObject, value); + } + + /// `BigIntStats.birthtime` getter + /// This value will be visited by the garbage collector. + pub fn birthtimeGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = BigIntStatsPrototype__birthtimeGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + extern fn BigIntStatsPrototype__ctimeSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn BigIntStatsPrototype__ctimeGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `BigIntStats.ctime` setter + /// This value will be visited by the garbage collector. + pub fn ctimeSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + BigIntStatsPrototype__ctimeSetCachedValue(thisValue, globalObject, value); + } + + /// `BigIntStats.ctime` getter + /// This value will be visited by the garbage collector. + pub fn ctimeGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = BigIntStatsPrototype__ctimeGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + extern fn BigIntStatsPrototype__mtimeSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn BigIntStatsPrototype__mtimeGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `BigIntStats.mtime` setter + /// This value will be visited by the garbage collector. + pub fn mtimeSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + BigIntStatsPrototype__mtimeSetCachedValue(thisValue, globalObject, value); + } + + /// `BigIntStats.mtime` getter + /// This value will be visited by the garbage collector. + pub fn mtimeGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = BigIntStatsPrototype__mtimeGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + /// Get the BigIntStats constructor value. + /// This loads lazily from the global object. + pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + return BigIntStats__getConstructor(globalObject); + } + + /// Create a new instance of BigIntStats + pub fn toJS(this: *BigIntStats, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + if (comptime Environment.allow_assert) { + const value__ = BigIntStats__create(globalObject, this); + std.debug.assert(value__.as(BigIntStats).? == this); // If this fails, likely a C ABI issue. + return value__; + } else { + return BigIntStats__create(globalObject, this); + } + } + + /// Modify the internal ptr to point to a new instance of BigIntStats. + pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*BigIntStats) bool { + JSC.markBinding(@src()); + return BigIntStats__dangerouslySetPtr(value, ptr); + } + + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *BigIntStats, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(BigIntStats__dangerouslySetPtr(value, null)); + } + + extern fn BigIntStats__fromJS(JSC.JSValue) ?*BigIntStats; + extern fn BigIntStats__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; + + extern fn BigIntStats__create(globalObject: *JSC.JSGlobalObject, ptr: ?*BigIntStats) JSC.JSValue; + + extern fn BigIntStats__dangerouslySetPtr(JSC.JSValue, ?*BigIntStats) bool; + + comptime { + if (@TypeOf(BigIntStats.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*BigIntStats)) { + @compileLog("BigIntStats.constructor is not a constructor"); + } + + if (@TypeOf(BigIntStats.finalize) != (fn (*BigIntStats) callconv(.C) void)) { + @compileLog("BigIntStats.finalize is not a finalizer"); + } + + if (@TypeOf(BigIntStats.atime) != GetterType) + @compileLog("Expected BigIntStats.atime to be a getter"); + + if (@TypeOf(BigIntStats.atimeMs) != GetterType) + @compileLog("Expected BigIntStats.atimeMs to be a getter"); + + if (@TypeOf(BigIntStats.atimeNs) != GetterType) + @compileLog("Expected BigIntStats.atimeNs to be a getter"); + + if (@TypeOf(BigIntStats.birthtime) != GetterType) + @compileLog("Expected BigIntStats.birthtime to be a getter"); + + if (@TypeOf(BigIntStats.birthtimeMs) != GetterType) + @compileLog("Expected BigIntStats.birthtimeMs to be a getter"); + + if (@TypeOf(BigIntStats.birthtimeNs) != GetterType) + @compileLog("Expected BigIntStats.birthtimeNs to be a getter"); + + if (@TypeOf(BigIntStats.blksize) != GetterType) + @compileLog("Expected BigIntStats.blksize to be a getter"); + + if (@TypeOf(BigIntStats.blocks) != GetterType) + @compileLog("Expected BigIntStats.blocks to be a getter"); + + if (@TypeOf(BigIntStats.ctime) != GetterType) + @compileLog("Expected BigIntStats.ctime to be a getter"); + + if (@TypeOf(BigIntStats.ctimeMs) != GetterType) + @compileLog("Expected BigIntStats.ctimeMs to be a getter"); + + if (@TypeOf(BigIntStats.ctimeNs) != GetterType) + @compileLog("Expected BigIntStats.ctimeNs to be a getter"); + + if (@TypeOf(BigIntStats.dev) != GetterType) + @compileLog("Expected BigIntStats.dev to be a getter"); + + if (@TypeOf(BigIntStats.gid) != GetterType) + @compileLog("Expected BigIntStats.gid to be a getter"); + + if (@TypeOf(BigIntStats.ino) != GetterType) + @compileLog("Expected BigIntStats.ino to be a getter"); + + if (@TypeOf(BigIntStats.isBlockDevice_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isBlockDevice_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isBlockDevice_) != CallbackType) + @compileLog("Expected BigIntStats.isBlockDevice_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isBlockDevice_))); + if (@TypeOf(BigIntStats.isCharacterDevice_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isCharacterDevice_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isCharacterDevice_) != CallbackType) + @compileLog("Expected BigIntStats.isCharacterDevice_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isCharacterDevice_))); + if (@TypeOf(BigIntStats.isDirectory_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isDirectory_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isDirectory_) != CallbackType) + @compileLog("Expected BigIntStats.isDirectory_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isDirectory_))); + if (@TypeOf(BigIntStats.isFIFO_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isFIFO_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isFIFO_) != CallbackType) + @compileLog("Expected BigIntStats.isFIFO_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isFIFO_))); + if (@TypeOf(BigIntStats.isFile_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isFile_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isFile_) != CallbackType) + @compileLog("Expected BigIntStats.isFile_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isFile_))); + if (@TypeOf(BigIntStats.isSocket_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isSocket_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isSocket_) != CallbackType) + @compileLog("Expected BigIntStats.isSocket_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isSocket_))); + if (@TypeOf(BigIntStats.isSymbolicLink_WithoutTypeChecks) != fn ( + *BigIntStats, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue) + @compileLog("Expected BigIntStats.isSymbolicLink_WithoutTypeChecks to be a DOMJIT function"); + if (@TypeOf(BigIntStats.isSymbolicLink_) != CallbackType) + @compileLog("Expected BigIntStats.isSymbolicLink_ to be a callback but received " ++ @typeName(@TypeOf(BigIntStats.isSymbolicLink_))); + if (@TypeOf(BigIntStats.mode) != GetterType) + @compileLog("Expected BigIntStats.mode to be a getter"); + + if (@TypeOf(BigIntStats.mtime) != GetterType) + @compileLog("Expected BigIntStats.mtime to be a getter"); + + if (@TypeOf(BigIntStats.mtimeMs) != GetterType) + @compileLog("Expected BigIntStats.mtimeMs to be a getter"); + + if (@TypeOf(BigIntStats.mtimeNs) != GetterType) + @compileLog("Expected BigIntStats.mtimeNs to be a getter"); + + if (@TypeOf(BigIntStats.nlink) != GetterType) + @compileLog("Expected BigIntStats.nlink to be a getter"); + + if (@TypeOf(BigIntStats.rdev) != GetterType) + @compileLog("Expected BigIntStats.rdev to be a getter"); + + if (@TypeOf(BigIntStats.size) != GetterType) + @compileLog("Expected BigIntStats.size to be a getter"); + + if (@TypeOf(BigIntStats.uid) != GetterType) + @compileLog("Expected BigIntStats.uid to be a getter"); + + if (!JSC.is_bindgen) { + @export(BigIntStats.atime, .{ .name = "BigIntStatsPrototype__atime" }); + @export(BigIntStats.atimeMs, .{ .name = "BigIntStatsPrototype__atimeMs" }); + @export(BigIntStats.atimeNs, .{ .name = "BigIntStatsPrototype__atimeNs" }); + @export(BigIntStats.birthtime, .{ .name = "BigIntStatsPrototype__birthtime" }); + @export(BigIntStats.birthtimeMs, .{ .name = "BigIntStatsPrototype__birthtimeMs" }); + @export(BigIntStats.birthtimeNs, .{ .name = "BigIntStatsPrototype__birthtimeNs" }); + @export(BigIntStats.blksize, .{ .name = "BigIntStatsPrototype__blksize" }); + @export(BigIntStats.blocks, .{ .name = "BigIntStatsPrototype__blocks" }); + @export(BigIntStats.constructor, .{ .name = "BigIntStatsClass__construct" }); + @export(BigIntStats.ctime, .{ .name = "BigIntStatsPrototype__ctime" }); + @export(BigIntStats.ctimeMs, .{ .name = "BigIntStatsPrototype__ctimeMs" }); + @export(BigIntStats.ctimeNs, .{ .name = "BigIntStatsPrototype__ctimeNs" }); + @export(BigIntStats.dev, .{ .name = "BigIntStatsPrototype__dev" }); + @export(BigIntStats.finalize, .{ .name = "BigIntStatsClass__finalize" }); + @export(BigIntStats.gid, .{ .name = "BigIntStatsPrototype__gid" }); + @export(BigIntStats.ino, .{ .name = "BigIntStatsPrototype__ino" }); + @export(BigIntStats.isBlockDevice_, .{ .name = "BigIntStatsPrototype__isBlockDevice_" }); + @export(BigIntStats.isBlockDevice_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isBlockDevice_WithoutTypeChecks" }); + @export(BigIntStats.isCharacterDevice_, .{ .name = "BigIntStatsPrototype__isCharacterDevice_" }); + @export(BigIntStats.isCharacterDevice_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isCharacterDevice_WithoutTypeChecks" }); + @export(BigIntStats.isDirectory_, .{ .name = "BigIntStatsPrototype__isDirectory_" }); + @export(BigIntStats.isDirectory_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isDirectory_WithoutTypeChecks" }); + @export(BigIntStats.isFIFO_, .{ .name = "BigIntStatsPrototype__isFIFO_" }); + @export(BigIntStats.isFIFO_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isFIFO_WithoutTypeChecks" }); + @export(BigIntStats.isFile_, .{ .name = "BigIntStatsPrototype__isFile_" }); + @export(BigIntStats.isFile_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isFile_WithoutTypeChecks" }); + @export(BigIntStats.isSocket_, .{ .name = "BigIntStatsPrototype__isSocket_" }); + @export(BigIntStats.isSocket_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isSocket_WithoutTypeChecks" }); + @export(BigIntStats.isSymbolicLink_, .{ .name = "BigIntStatsPrototype__isSymbolicLink_" }); + @export(BigIntStats.isSymbolicLink_WithoutTypeChecks, .{ .name = "BigIntStatsPrototype__isSymbolicLink_WithoutTypeChecks" }); + @export(BigIntStats.mode, .{ .name = "BigIntStatsPrototype__mode" }); + @export(BigIntStats.mtime, .{ .name = "BigIntStatsPrototype__mtime" }); + @export(BigIntStats.mtimeMs, .{ .name = "BigIntStatsPrototype__mtimeMs" }); + @export(BigIntStats.mtimeNs, .{ .name = "BigIntStatsPrototype__mtimeNs" }); + @export(BigIntStats.nlink, .{ .name = "BigIntStatsPrototype__nlink" }); + @export(BigIntStats.rdev, .{ .name = "BigIntStatsPrototype__rdev" }); + @export(BigIntStats.size, .{ .name = "BigIntStatsPrototype__size" }); + @export(BigIntStats.uid, .{ .name = "BigIntStatsPrototype__uid" }); + } + } +}; pub const JSBlob = struct { const Blob = Classes.Blob; const GetterType = fn (*Blob, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; @@ -6436,6 +6743,7 @@ pub const JSTranspiler = struct { comptime { _ = JSAttributeIterator; + _ = JSBigIntStats; _ = JSBlob; _ = JSBuildArtifact; _ = JSBuildMessage; diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index 6033fc7ff..20f36a458 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -36,7 +36,8 @@ 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.Stats; + pub const Stats = JSC.Node.StatsSmall; + pub const BigIntStats = JSC.Node.StatsBig; pub const Subprocess = JSC.Subprocess; pub const TCPSocket = JSC.API.TCPSocket; pub const TLSSocket = JSC.API.TLSSocket; diff --git a/src/bun.js/node/node.classes.ts b/src/bun.js/node/node.classes.ts index 2efad5245..bf9a4bcde 100644 --- a/src/bun.js/node/node.classes.ts +++ b/src/bun.js/node/node.classes.ts @@ -199,6 +199,155 @@ export default [ }, }), define({ + name: "BigIntStats", + construct: false, + finalize: true, + klass: {}, + JSType: "0b11101110", + 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, + }, + }, + dev: { + getter: "dev", + }, + ino: { + getter: "ino", + }, + mode: { + getter: "mode", + }, + nlink: { + getter: "nlink", + }, + uid: { + getter: "uid", + }, + gid: { + getter: "gid", + }, + rdev: { + getter: "rdev", + }, + size: { + getter: "size", + }, + blksize: { + getter: "blksize", + }, + blocks: { + getter: "blocks", + }, + atime: { + getter: "atime", + cache: true, + }, + mtime: { + getter: "mtime", + cache: true, + }, + ctime: { + getter: "ctime", + cache: true, + }, + birthtime: { + getter: "birthtime", + cache: true, + }, + atimeMs: { + getter: "atimeMs", + }, + mtimeMs: { + getter: "mtimeMs", + }, + ctimeMs: { + getter: "ctimeMs", + }, + birthtimeMs: { + getter: "birthtimeMs", + }, + atimeNs: { + getter: "atimeNs", + }, + mtimeNs: { + getter: "mtimeNs", + }, + ctimeNs: { + getter: "ctimeNs", + }, + birthtimeNs: { + getter: "birthtimeNs", + }, + }, + }), + define({ name: "Dirent", construct: true, finalize: true, diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 274bc54a7..b7ae0418d 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -3426,8 +3426,6 @@ pub const NodeFS = struct { return Maybe(Return.Fdatasync).todo; } pub fn fstat(_: *NodeFS, args: Arguments.Fstat, comptime flavor: Flavor) Maybe(Return.Fstat) { - if (args.big_int) return Maybe(Return.Fstat).todo; - switch (comptime flavor) { .sync => { return switch (Syscall.fstat(args.fd)) { @@ -3531,8 +3529,6 @@ pub const NodeFS = struct { } pub fn lstat(this: *NodeFS, args: Arguments.Lstat, comptime flavor: Flavor) Maybe(Return.Lstat) { _ = flavor; - if (args.big_int) return Maybe(Return.Lstat).todo; - return switch (Syscall.lstat( args.path.sliceZ( &this.sync_error_buf, @@ -4713,7 +4709,6 @@ pub const NodeFS = struct { } pub fn stat(this: *NodeFS, args: Arguments.Stat, comptime flavor: Flavor) Maybe(Return.Stat) { _ = flavor; - if (args.big_int) return Maybe(Return.Stat).todo; return @as(Maybe(Return.Stat), switch (Syscall.stat( args.path.sliceZ( diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index 3a02442b3..dfc47b2ce 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -282,7 +282,7 @@ pub const NodeJSFS = struct { } pub fn getStats(_: *NodeJSFS, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { - return JSC.Node.Stats.getConstructor(globalThis); + return JSC.Node.StatsSmall.getConstructor(globalThis); } pub const watch = callSync(.watch); diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 38d6baeb3..6f5f412c3 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1272,223 +1272,239 @@ pub const FileSystemFlags = enum(Mode) { } }; -/// Milliseconds precision -pub const Date = enum(u64) { - _, - - pub fn toJS(this: Date, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { - const seconds = @as(f64, @floatCast(@as(f64, @floatFromInt(@intFromEnum(this))))); - const unix_timestamp = JSC.JSValue.jsNumber(seconds); - const array: [1]JSC.C.JSValueRef = .{unix_timestamp.asObjectRef()}; - const obj = JSC.C.JSObjectMakeDate(ctx, 1, &array, exception); - return obj; - } -}; +/// Stats and BigIntStats classes from node:fs +pub fn StatType(comptime Big: bool) type { + const Int = if (Big) i64 else i32; + const Float = if (Big) i64 else f64; + const Timestamp = if (Big) u64 else u0; + + const Date = packed struct { + value: Float, + pub inline fn toJS(this: @This(), ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { + const milliseconds = JSC.JSValue.jsNumber(this.value); + const array: [1]JSC.C.JSValueRef = .{milliseconds.asObjectRef()}; + const obj = JSC.C.JSObjectMakeDate(ctx, 1, &array, exception); + return obj; + } + }; -fn StatsDataType(comptime T: type) type { return struct { - dev: T, - ino: T, - mode: T, - nlink: T, - uid: T, - gid: T, - rdev: T, + pub usingnamespace if (Big) JSC.Codegen.JSBigIntStats else JSC.Codegen.JSStats; + + // Stats stores these as i32, but BigIntStats stores all of these as i64 + dev: Int, + ino: Int, + mode: Int, + nlink: Int, + uid: Int, + gid: Int, + rdev: Int, // Always store size as a 64-bit integer size: i64, - blksize: T, - blocks: T, - atime_ms: f64, - mtime_ms: f64, - ctime_ms: f64, - birthtime_ms: T, - - // TODO: don't store these 4 fields - atime: Date, - mtime: Date, - ctime: Date, - birthtime: Date, - - pub fn init(stat_: os.Stat) @This() { - const atime = stat_.atime(); - const mtime = stat_.mtime(); - const ctime = stat_.ctime(); - - return @This(){ - .dev = @as(T, @truncate(@as(i64, @intCast(stat_.dev)))), - .ino = @as(T, @truncate(@as(i64, @intCast(stat_.ino)))), - .mode = @as(T, @truncate(@as(i64, @intCast(stat_.mode)))), - .nlink = @as(T, @truncate(@as(i64, @intCast(stat_.nlink)))), - .uid = @as(T, @truncate(@as(i64, @intCast(stat_.uid)))), - .gid = @as(T, @truncate(@as(i64, @intCast(stat_.gid)))), - .rdev = @as(T, @truncate(@as(i64, @intCast(stat_.rdev)))), - .size = @truncate(@as(i64, @intCast(stat_.size))), - .blksize = @as(T, @truncate(@as(i64, @intCast(stat_.blksize)))), - .blocks = @as(T, @truncate(@as(i64, @intCast(stat_.blocks)))), - .atime_ms = (@as(f64, @floatFromInt(@max(atime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(atime.tv_nsec, 0))))) / std.time.ns_per_ms), - .mtime_ms = (@as(f64, @floatFromInt(@max(mtime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(mtime.tv_nsec, 0))))) / std.time.ns_per_ms), - .ctime_ms = (@as(f64, @floatFromInt(@max(ctime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(ctime.tv_nsec, 0))))) / std.time.ns_per_ms), - .atime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(atime.tv_sec * std.time.ms_per_s, 0))))), - .mtime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(mtime.tv_sec * std.time.ms_per_s, 0))))), - .ctime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(ctime.tv_sec * std.time.ms_per_s, 0))))), + blksize: Int, + blocks: Int, - // Linux doesn't include this info in stat - // maybe it does in statx, but do you really need birthtime? If you do please file an issue. - .birthtime_ms = if (Environment.isLinux) - 0 - else - @as(T, @truncate(@as(i64, @intCast(if (stat_.birthtime().tv_nsec > 0) (@as(usize, @intCast(stat_.birthtime().tv_nsec)) / std.time.ns_per_ms) else 0)))), - - .birthtime = if (Environment.isLinux) - @as(Date, @enumFromInt(0)) - else - @as(Date, @enumFromInt(@as(u64, @intCast(@max(stat_.birthtime().tv_sec, 0))))), - }; - } - }; -} + // _ms is either a float if Small, or a 64-bit integer if Big + atime_ms: Float, + mtime_ms: Float, + ctime_ms: Float, + birthtime_ms: Float, -pub const Stats = union(enum) { - big: StatsDataType(i64), - small: StatsDataType(i32), + // _ns is a u64 storing nanosecond precision. it is a u0 when not BigIntStats + atime_ns: Timestamp = 0, + mtime_ns: Timestamp = 0, + ctime_ns: Timestamp = 0, + birthtime_ns: Timestamp = 0, - const This = Stats; - pub usingnamespace JSC.Codegen.JSStats; + const This = @This(); - fn unionGetter(comptime field: std.meta.FieldEnum(StatsDataType(i64))) JSC.To.Cpp.PropertyGetter(This) { - return struct { - pub fn callback(this: *This, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { - return switch (this.*) { - .big => JSC.toJS(globalThis, @field(this.big, @tagName(field)), null), - .small => JSC.toJS(globalThis, @field(this.small, @tagName(field)), null), - }; - } - }.callback; - } - - pub const isBlockDevice_ = JSC.wrapInstanceMethod(Stats, "isBlockDevice", false); - pub const isCharacterDevice_ = JSC.wrapInstanceMethod(Stats, "isCharacterDevice", false); - pub const isDirectory_ = JSC.wrapInstanceMethod(Stats, "isDirectory", false); - pub const isFIFO_ = JSC.wrapInstanceMethod(Stats, "isFIFO", false); - pub const isFile_ = JSC.wrapInstanceMethod(Stats, "isFile", false); - pub const isSocket_ = JSC.wrapInstanceMethod(Stats, "isSocket", false); - pub const isSymbolicLink_ = JSC.wrapInstanceMethod(Stats, "isSymbolicLink", false); - - pub const isBlockDevice_WithoutTypeChecks = domCall(.isBlockDevice); - pub const isCharacterDevice_WithoutTypeChecks = domCall(.isCharacterDevice); - pub const isDirectory_WithoutTypeChecks = domCall(.isDirectory); - pub const isFIFO_WithoutTypeChecks = domCall(.isFIFO); - pub const isFile_WithoutTypeChecks = domCall(.isFile); - pub const isSocket_WithoutTypeChecks = domCall(.isSocket); - pub const isSymbolicLink_WithoutTypeChecks = domCall(.isSymbolicLink); - - const DOMCallFn = fn ( - *Stats, - *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue; - fn domCall(comptime decl: std.meta.DeclEnum(Stats)) DOMCallFn { - return struct { - pub fn run( - this: *Stats, - _: *JSC.JSGlobalObject, - ) callconv(.C) JSC.JSValue { - return @call(.auto, @field(Stats, @tagName(decl)), .{this}); + inline fn toNanoseconds(ts: std.os.timespec) Timestamp { + return @as(Timestamp, @intCast(ts.tv_sec * 1_000_000_000)) + @as(Timestamp, @intCast(ts.tv_nsec)); + } + + inline fn toTimeMS(ts: std.os.timespec) Float { + if (Big) { + return @as(i64, @intCast(ts.tv_sec * std.time.ms_per_s)) + @as(i64, @intCast(@divTrunc(ts.tv_nsec, std.time.ns_per_ms))); + } else { + return (@as(f64, @floatFromInt(@max(ts.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(ts.tv_nsec, 0))))) / std.time.ns_per_ms); } - }.run; - } - - pub const dev = unionGetter(.dev); - pub const ino = unionGetter(.ino); - pub const mode = unionGetter(.mode); - pub const nlink = unionGetter(.nlink); - pub const uid = unionGetter(.uid); - pub const gid = unionGetter(.gid); - pub const rdev = unionGetter(.rdev); - pub const size = unionGetter(.size); - pub const blksize = unionGetter(.blksize); - pub const blocks = unionGetter(.blocks); - pub const atime = unionGetter(.atime); - pub const mtime = unionGetter(.mtime); - pub const ctime = unionGetter(.ctime); - pub const birthtime = unionGetter(.birthtime); - pub const atimeMs = unionGetter(.atime_ms); - pub const mtimeMs = unionGetter(.mtime_ms); - pub const ctimeMs = unionGetter(.ctime_ms); - pub const birthtimeMs = unionGetter(.birthtime_ms); - - fn modeInternal(this: *This) i32 { - return switch (this.*) { - .big => @as(i32, @truncate(this.big.mode)), - .small => this.small.mode, - }; - } + } - pub fn isBlockDevice(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISBLK(@as(Mode, @intCast(this.modeInternal())))); - } + fn getter(comptime field: std.meta.FieldEnum(This)) JSC.To.Cpp.PropertyGetter(This) { + return struct { + pub fn callback(this: *This, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { + const value = @field(this, @tagName(field)); + if (comptime (Big and @typeInfo(@TypeOf(value)) == .Int)) { + return JSC.JSValue.fromInt64NoTruncate(globalThis, @intCast(value)); + } + return JSC.toJS(globalThis, value, null); + } + }.callback; + } - pub fn isCharacterDevice(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISCHR(@as(Mode, @intCast(this.modeInternal())))); - } + fn dateGetter(comptime field: std.meta.FieldEnum(This)) JSC.To.Cpp.PropertyGetter(This) { + return struct { + pub fn callback(this: *This, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { + const value = @field(this, @tagName(field)); + // Doing `Date{ ... }` here shouldn't actually change the memory layout of `value` + // but it will tell comptime code how to convert the i64/f64 to a JS Date. + return JSC.toJS(globalThis, Date{ .value = value }, null); + } + }.callback; + } + + pub const isBlockDevice_ = JSC.wrapInstanceMethod(This, "isBlockDevice", false); + pub const isCharacterDevice_ = JSC.wrapInstanceMethod(This, "isCharacterDevice", false); + pub const isDirectory_ = JSC.wrapInstanceMethod(This, "isDirectory", false); + pub const isFIFO_ = JSC.wrapInstanceMethod(This, "isFIFO", false); + pub const isFile_ = JSC.wrapInstanceMethod(This, "isFile", false); + pub const isSocket_ = JSC.wrapInstanceMethod(This, "isSocket", false); + pub const isSymbolicLink_ = JSC.wrapInstanceMethod(This, "isSymbolicLink", false); + + pub const isBlockDevice_WithoutTypeChecks = domCall(.isBlockDevice); + pub const isCharacterDevice_WithoutTypeChecks = domCall(.isCharacterDevice); + pub const isDirectory_WithoutTypeChecks = domCall(.isDirectory); + pub const isFIFO_WithoutTypeChecks = domCall(.isFIFO); + pub const isFile_WithoutTypeChecks = domCall(.isFile); + pub const isSocket_WithoutTypeChecks = domCall(.isSocket); + pub const isSymbolicLink_WithoutTypeChecks = domCall(.isSymbolicLink); + + const DOMCallFn = fn ( + *This, + *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue; + fn domCall(comptime decl: std.meta.DeclEnum(This)) DOMCallFn { + return struct { + pub fn run( + this: *This, + _: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + return @call(.auto, @field(This, @tagName(decl)), .{this}); + } + }.run; + } - pub fn isDirectory(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISDIR(@as(Mode, @intCast(this.modeInternal())))); - } + pub const dev = getter(.dev); + pub const ino = getter(.ino); + pub const mode = getter(.mode); + pub const nlink = getter(.nlink); + pub const uid = getter(.uid); + pub const gid = getter(.gid); + pub const rdev = getter(.rdev); + pub const size = getter(.size); + pub const blksize = getter(.blksize); + pub const blocks = getter(.blocks); + pub const atime = dateGetter(.atime_ms); + pub const mtime = dateGetter(.mtime_ms); + pub const ctime = dateGetter(.ctime_ms); + pub const birthtime = dateGetter(.birthtime_ms); + pub const atimeMs = getter(.atime_ms); + pub const mtimeMs = getter(.mtime_ms); + pub const ctimeMs = getter(.ctime_ms); + pub const birthtimeMs = getter(.birthtime_ms); + pub const atimeNs = getter(.atime_ns); + pub const mtimeNs = getter(.mtime_ns); + pub const ctimeNs = getter(.ctime_ns); + pub const birthtimeNs = getter(.birthtime_ns); - pub fn isFIFO(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISFIFO(@as(Mode, @intCast(this.modeInternal())))); - } + inline fn modeInternal(this: *This) i32 { + return @truncate(this.mode); + } - pub fn isFile(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISREG(@as(Mode, @intCast(this.modeInternal())))); - } + pub fn isBlockDevice(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISBLK(@as(Mode, @intCast(this.modeInternal())))); + } - pub fn isSocket(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISSOCK(@as(Mode, @intCast(this.modeInternal())))); - } + pub fn isCharacterDevice(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISCHR(@as(Mode, @intCast(this.modeInternal())))); + } - // Node.js says this method is only valid on the result of lstat() - // so it's fine if we just include it on stat() because it would - // still just return false. - // - // See https://nodejs.org/api/fs.html#statsissymboliclink - pub fn isSymbolicLink(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISLNK(@as(Mode, @intCast(this.modeInternal())))); - } + pub fn isDirectory(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISDIR(@as(Mode, @intCast(this.modeInternal())))); + } - pub fn finalize(this: *This) callconv(.C) void { - bun.default_allocator.destroy(this); - } + pub fn isFIFO(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISFIFO(@as(Mode, @intCast(this.modeInternal())))); + } - pub fn init(stat: std.os.Stat, big: bool) This { - if (big) { - return .{ .big = StatsDataType(i64).init(stat) }; - } else { - return .{ .small = StatsDataType(i32).init(stat) }; + pub fn isFile(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISREG(@as(Mode, @intCast(this.modeInternal())))); } - } - pub fn initWithAllocator(allocator: std.mem.Allocator, stat: std.os.Stat, big: bool) *This { - var this = allocator.create(Stats) catch unreachable; - this.* = init(stat, big); - return this; - } + pub fn isSocket(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISSOCK(@as(Mode, @intCast(this.modeInternal())))); + } - pub fn constructor(globalThis: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) ?*Stats { - // dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs - var args = callFrame.argumentsPtr()[0..@min(callFrame.argumentsCount(), 14)]; + /// Node.js says this method is only valid on the result of lstat() + /// so it's fine if we just include it on stat() because it would + /// still just return false. + /// + /// See https://nodejs.org/api/fs.html#statsissymboliclink + pub fn isSymbolicLink(this: *This) JSC.JSValue { + return JSC.JSValue.jsBoolean(os.S.ISLNK(@as(Mode, @intCast(this.modeInternal())))); + } - var this = globalThis.allocator().create(Stats) catch { - globalThis.throwOutOfMemory(); - return null; - }; + // TODO: BigIntStats includes a `_checkModeProperty` but I dont think anyone actually uses it. - var atime_ms = if (args.len > 10 and args[10].isNumber()) args[10].asNumber() else 0; - var mtime_ms = if (args.len > 11 and args[11].isNumber()) args[11].asNumber() else 0; - var ctime_ms = if (args.len > 12 and args[12].isNumber()) args[12].asNumber() else 0; - var birthtime_ms = if (args.len > 13 and args[13].isNumber()) args[13].toInt32() else 0; - this.* = .{ - .small = StatsDataType(i32){ + pub fn finalize(this: *This) callconv(.C) void { + bun.default_allocator.destroy(this); + } + + pub fn init(stat_: os.Stat) This { + const aTime = stat_.atime(); + const mTime = stat_.mtime(); + const cTime = stat_.ctime(); + + return .{ + .dev = @truncate(@as(i64, @intCast(stat_.dev))), + .ino = @truncate(@as(i64, @intCast(stat_.ino))), + .mode = @truncate(@as(i64, @intCast(stat_.mode))), + .nlink = @truncate(@as(i64, @intCast(stat_.nlink))), + .uid = @truncate(@as(i64, @intCast(stat_.uid))), + .gid = @truncate(@as(i64, @intCast(stat_.gid))), + .rdev = @truncate(@as(i64, @intCast(stat_.rdev))), + .size = @truncate(@as(i64, @intCast(stat_.size))), + .blksize = @truncate(@as(i64, @intCast(stat_.blksize))), + .blocks = @truncate(@as(i64, @intCast(stat_.blocks))), + .atime_ms = toTimeMS(aTime), + .mtime_ms = toTimeMS(mTime), + .ctime_ms = toTimeMS(cTime), + .atime_ns = if (Big) toNanoseconds(aTime) else 0, + .mtime_ns = if (Big) toNanoseconds(mTime) else 0, + .ctime_ns = if (Big) toNanoseconds(cTime) else 0, + + // Linux doesn't include this info in stat + // maybe it does in statx, but do you really need birthtime? If you do please file an issue. + .birthtime_ms = if (Environment.isLinux) 0 else toTimeMS(stat_.birthtime()), + .birthtime_ns = if (Big and !Environment.isLinux) toNanoseconds(stat_.birthtime()) else 0, + }; + } + + pub fn initWithAllocator(allocator: std.mem.Allocator, stat: std.os.Stat) *This { + var this = allocator.create(This) catch unreachable; + this.* = init(stat); + return this; + } + + pub fn constructor(globalThis: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) ?*This { + if (Big) { + globalThis.throwInvalidArguments("BigIntStats is not a constructor", .{}); + return null; + } + + // dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs + var args = callFrame.argumentsPtr()[0..@min(callFrame.argumentsCount(), 14)]; + + var this = globalThis.allocator().create(This) catch { + globalThis.throwOutOfMemory(); + return null; + }; + + var atime_ms: f64 = if (args.len > 10 and args[10].isNumber()) args[10].asNumber() else 0; + var mtime_ms: f64 = if (args.len > 11 and args[11].isNumber()) args[11].asNumber() else 0; + var ctime_ms: f64 = if (args.len > 12 and args[12].isNumber()) args[12].asNumber() else 0; + var birthtime_ms: f64 = if (args.len > 13 and args[13].isNumber()) args[13].asNumber() else 0; + this.* = .{ .dev = if (args.len > 0 and args[0].isNumber()) args[0].toInt32() else 0, .mode = if (args.len > 1 and args[1].isNumber()) args[1].toInt32() else 0, .nlink = if (args.len > 2 and args[2].isNumber()) args[2].toInt32() else 0, @@ -1499,27 +1515,47 @@ pub const Stats = union(enum) { .ino = if (args.len > 7 and args[7].isNumber()) args[7].toInt32() else 0, .size = if (args.len > 8 and args[8].isNumber()) args[8].toInt32() else 0, .blocks = if (args.len > 9 and args[9].isNumber()) args[9].toInt32() else 0, - .atime_ms = (atime_ms), - .mtime_ms = (mtime_ms), - .ctime_ms = (ctime_ms), + .atime_ms = atime_ms, + .mtime_ms = mtime_ms, + .ctime_ms = ctime_ms, .birthtime_ms = birthtime_ms, - .atime = @enumFromInt(@as(u64, @intFromFloat(atime_ms))), - .mtime = @enumFromInt(@as(u64, @intFromFloat(mtime_ms))), - .ctime = @enumFromInt(@as(u64, @intFromFloat(ctime_ms))), - .birthtime = @enumFromInt(@as(u64, @intCast(birthtime_ms))), - }, - }; - return this; + }; + return this; + } + + comptime { + _ = isBlockDevice_WithoutTypeChecks; + _ = isCharacterDevice_WithoutTypeChecks; + _ = isDirectory_WithoutTypeChecks; + _ = isFIFO_WithoutTypeChecks; + _ = isFile_WithoutTypeChecks; + _ = isSocket_WithoutTypeChecks; + _ = isSymbolicLink_WithoutTypeChecks; + } + }; +} + +pub const StatsSmall = StatType(false); +pub const StatsBig = StatType(true); + +/// Union between `Stats` and `BigIntStats` where the type can be decided at runtime +pub const Stats = union(enum) { + big: StatsBig, + small: StatsSmall, + + pub inline fn init(stat_: os.Stat, big: bool) Stats { + if (big) { + return .{ .big = StatsBig.init(stat_) }; + } else { + return .{ .small = StatsSmall.init(stat_) }; + } } - comptime { - _ = isBlockDevice_WithoutTypeChecks; - _ = isCharacterDevice_WithoutTypeChecks; - _ = isDirectory_WithoutTypeChecks; - _ = isFIFO_WithoutTypeChecks; - _ = isFile_WithoutTypeChecks; - _ = isSocket_WithoutTypeChecks; - _ = isSymbolicLink_WithoutTypeChecks; + pub inline fn toJS(this: *Stats, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + return switch (this.*) { + .big => this.big.toJS(globalObject), + .small => this.small.toJS(globalObject), + }; } }; diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 064336865..58fb455fc 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -1833,3 +1833,38 @@ it("new Stats", () => { expect(stats.ctime).toEqual(new Date(13)); expect(stats.birthtime).toEqual(new Date(14)); }); + +it("BigIntStats", () => { + const withoutBigInt = statSync(__filename, { bigint: false }); + const withBigInt = statSync(__filename, { bigint: true }); + + expect(withoutBigInt.isFile() === withBigInt.isFile()).toBe(true); + expect(withoutBigInt.isDirectory() === withBigInt.isDirectory()).toBe(true); + expect(withoutBigInt.isBlockDevice() === withBigInt.isBlockDevice()).toBe(true); + expect(withoutBigInt.isCharacterDevice() === withBigInt.isCharacterDevice()).toBe(true); + expect(withoutBigInt.isSymbolicLink() === withBigInt.isSymbolicLink()).toBe(true); + expect(withoutBigInt.isFIFO() === withBigInt.isFIFO()).toBe(true); + expect(withoutBigInt.isSocket() === withBigInt.isSocket()).toBe(true); + + const expectclose = (a: bigint, b: bigint) => expect(Math.abs(Number(a - b))).toBeLessThan(1000); + + expectclose(BigInt(withoutBigInt.dev), withBigInt.dev); + expectclose(BigInt(withoutBigInt.ino), withBigInt.ino); + expectclose(BigInt(withoutBigInt.mode), withBigInt.mode); + expectclose(BigInt(withoutBigInt.nlink), withBigInt.nlink); + expectclose(BigInt(withoutBigInt.uid), withBigInt.uid); + expectclose(BigInt(withoutBigInt.gid), withBigInt.gid); + expectclose(BigInt(withoutBigInt.rdev), withBigInt.rdev); + expectclose(BigInt(withoutBigInt.size), withBigInt.size); + expectclose(BigInt(withoutBigInt.blksize), withBigInt.blksize); + expectclose(BigInt(withoutBigInt.blocks), withBigInt.blocks); + expectclose(BigInt(Math.floor(withoutBigInt.atimeMs)), withBigInt.atimeMs); + expectclose(BigInt(Math.floor(withoutBigInt.mtimeMs)), withBigInt.mtimeMs); + expectclose(BigInt(Math.floor(withoutBigInt.ctimeMs)), withBigInt.ctimeMs); + expectclose(BigInt(Math.floor(withoutBigInt.birthtimeMs)), withBigInt.birthtimeMs); + + expect(withBigInt.atime.getTime()).toEqual(withoutBigInt.atime.getTime()); + expect(withBigInt.mtime.getTime()).toEqual(withoutBigInt.mtime.getTime()); + expect(withBigInt.ctime.getTime()).toEqual(withoutBigInt.ctime.getTime()); + expect(withBigInt.birthtime.getTime()).toEqual(withoutBigInt.birthtime.getTime()); +}); |