diff options
author | 2023-06-25 20:16:25 -0300 | |
---|---|---|
committer | 2023-06-25 16:16:25 -0700 | |
commit | 3ed28f2828a29129a1791b7a4f6935d842d6493c (patch) | |
tree | c23b6e76e32bf9c2f30070af72593aa16289dc86 /src/bun.js/bindings/ZigGeneratedClasses.h | |
parent | fcf9f0a7eeb3d462d5c6c2110ecdf5a4460c1736 (diff) | |
download | bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.gz bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.zst bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.zip |
[fs.watch] fix reference/deinit (#3396)
* fix js reference
* fix close oops
* refactor + hasPendingActivity
* fmt
* fix race conditions
* fixup
* add test calling close on error event
* fix close inside close + test
* cleanup
Diffstat (limited to 'src/bun.js/bindings/ZigGeneratedClasses.h')
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 3fa0e26d2..1631f960e 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -623,10 +623,37 @@ public: : Base(vm, structure) { m_ctx = sinkPtr; + m_weakThis = JSC::Weak<JSFSWatcher>(this, getOwner()); } void finishCreation(JSC::VM&); + JSC::Weak<JSFSWatcher> m_weakThis; + + static bool hasPendingActivity(void* ctx); + + class Owner final : public JSC::WeakHandleOwner { + public: + bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void* context, JSC::AbstractSlotVisitor& visitor, const char** reason) final + { + auto* controller = JSC::jsCast<JSFSWatcher*>(handle.slot()->asCell()); + if (JSFSWatcher::hasPendingActivity(controller->wrapped())) { + if (UNLIKELY(reason)) + *reason = "has pending activity"; + return true; + } + + return visitor.containsOpaqueRoot(context); + } + void finalize(JSC::Handle<JSC::Unknown>, void* context) final {} + }; + + static JSC::WeakHandleOwner* getOwner() + { + static NeverDestroyed<Owner> m_owner; + return &m_owner.get(); + } + DECLARE_VISIT_CHILDREN; template<typename Visitor> void visitAdditionalChildren(Visitor&); DECLARE_VISIT_OUTPUT_CONSTRAINTS; |