diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp index 92ec3716ce..ae11f9c407 100644 --- a/src/dawn/node/binding/GPUDevice.cpp +++ b/src/dawn/node/binding/GPUDevice.cpp @@ -174,7 +174,9 @@ GPUDevice::~GPUDevice() { // lost_promise_ is left hanging. We'll also not clean up any GPU objects before terminating the // process, which is not a good idea. if (!destroyed_) { - destroy(env_); + lost_promise_.Discard(); + device_.Destroy(); + destroyed_ = true; } } diff --git a/src/dawn/node/interop/Core.h b/src/dawn/node/interop/Core.h index be1b4ac495..a193f34458 100644 --- a/src/dawn/node/interop/Core.h +++ b/src/dawn/node/interop/Core.h @@ -185,6 +185,7 @@ enum class PromiseState { Pending, Resolved, Rejected, + Discarded, }; namespace detail { @@ -206,6 +207,12 @@ class PromiseBase { PromiseState GetState() const { return state_->state; } + // Place the promise into the Discarded state. + // This state will not throw a fatal error if this promise has not been rejected or resolved by + // the time it is finalized. This is useful for Node tear-down where the attempting to create + // new objects will result in a fatal error. + void Discard() { state_->state = PromiseState::Discarded; } + protected: void Resolve(Napi::Value value) const { state_->deferred.Resolve(value);