Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index 6d0d3c84a3845750283340bf2bf611576f460994..7f5cf19fc70608442df9cd5253aac34ad6a2a288 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -1707,6 +1707,25 @@ class ThreadedListZoneEntry final : public ZoneObject { |
DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); |
}; |
+template <typename T> |
+class ScopedAssignment { |
+ public: |
+ V8_INLINE ScopedAssignment(T& previous, T&& value) |
+ : location_(&previous), prev_(previous) { |
+ *location_ = value; |
+ } |
+ V8_INLINE ScopedAssignment(T& previous, const T& value) |
+ : location_(&previous), prev_(previous) { |
+ *location_ = value; |
+ } |
+ |
+ V8_INLINE ~ScopedAssignment() { *location_ = prev_; } |
+ |
+ private: |
+ T* location_; |
+ T prev_; |
+}; |
+ |
} // namespace internal |
} // namespace v8 |