diff --git a/shared/src/interfaces/IAltResource.h b/shared/src/interfaces/IAltResource.h index 9cc255bcf..e5e049fc3 100644 --- a/shared/src/interfaces/IAltResource.h +++ b/shared/src/interfaces/IAltResource.h @@ -2,8 +2,6 @@ #include "IResource.h" -#include - namespace js { class IAltResource : public alt::IResource::Impl, public IResource @@ -22,21 +20,16 @@ namespace js static void ExternalFunctionCallback(const v8::FunctionCallbackInfo& info); }; - using NextTickCallback = std::function; - protected: alt::IResource* resource = nullptr; std::unordered_map> resourceObjects; - std::queue nextTickCallbacks; - void Reset() override { IResource::Reset(); resource = nullptr; resourceObjects.clear(); - nextTickCallbacks = {}; } public: @@ -84,13 +77,7 @@ namespace js void OnTick() override { - while(!nextTickCallbacks.empty()) - { - NextTickCallback& callback = nextTickCallbacks.front(); - callback(); - nextTickCallbacks.pop(); - } - + IResource::ProcessNextTickCallbacks(); js::Function onTick = GetBindingExport("timers:tick"); if(onTick.IsValid()) onTick.Call(); } @@ -102,10 +89,5 @@ namespace js resourceObjects.at(resource).Get(isolate)->SetAlignedPointerInInternalField(1, nullptr); resourceObjects.erase(resource); } - - void PushNextTickCallback(NextTickCallback&& callback) - { - nextTickCallbacks.push(std::move(callback)); - } }; } // namespace js diff --git a/shared/src/interfaces/IResource.h b/shared/src/interfaces/IResource.h index 0f5c0fbff..6da63c266 100644 --- a/shared/src/interfaces/IResource.h +++ b/shared/src/interfaces/IResource.h @@ -2,6 +2,7 @@ #include #include +#include #include "v8.h" #include "cpp-sdk/SDK.h" @@ -20,6 +21,9 @@ namespace js { class IResource : public IScriptObjectHandler, public ICompatibilityHandler { + public: + using NextTickCallback = std::function; + protected: static constexpr int ContextInternalFieldIdx = 1; @@ -27,12 +31,10 @@ namespace js v8::Isolate* isolate; Persistent context; - std::unordered_map> bindingExports; - std::unordered_map> ownedBuffers; - bool rawEmitEnabled = false; + std::queue nextTickCallbacks; void Initialize() { @@ -53,10 +55,22 @@ namespace js context.Reset(); bindingExports.clear(); ownedBuffers.clear(); + rawEmitEnabled = false; + nextTickCallbacks = {}; } void InitializeBinding(Binding* binding); + void ProcessNextTickCallbacks() + { + while(!nextTickCallbacks.empty()) + { + NextTickCallback& callback = nextTickCallbacks.front(); + callback(); + nextTickCallbacks.pop(); + } + } + public: class Scope { @@ -197,6 +211,11 @@ namespace js rawEmitEnabled = toggle; } + void PushNextTickCallback(NextTickCallback&& callback) + { + nextTickCallbacks.push(std::move(callback)); + } + template static ResourceType* GetFromContext(v8::Local context) {