Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Unified Diff: third_party/WebKit/Source/core/dom/MaybeShared.h

Issue 2707243006: [SharedArrayBuffer] Prevent SharedArrayBuffer being used in Web APIs (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/MaybeShared.h
diff --git a/third_party/WebKit/Source/core/dom/MaybeShared.h b/third_party/WebKit/Source/core/dom/MaybeShared.h
new file mode 100644
index 0000000000000000000000000000000000000000..5e376765ca5cb6b3ddc7e39a923e9ac012721a2b
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/MaybeShared.h
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MaybeShared_h
+#define MaybeShared_h
+
+#include "platform/heap/Handle.h"
+
+namespace blink {
+
+template <typename T>
+class CORE_EXPORT MaybeShared {
+ STACK_ALLOCATED();
+
+ public:
+ MaybeShared() {}
+
+ MaybeShared(T* typedArray) : m_typedArray(typedArray) {}
+ MaybeShared(const MaybeShared& other) = default;
+ template <typename U>
+ MaybeShared(const MaybeShared<U>& other)
+ : m_typedArray(other.viewMaybeShared()) {}
+
+ MaybeShared& operator=(T* typedArray) {
+ m_typedArray = typedArray;
+ return *this;
+ }
+ MaybeShared& operator=(const MaybeShared& other) = default;
+ template <typename U>
+ MaybeShared& operator=(const MaybeShared<U>& other) {
+ m_typedArray = other.viewMaybeShared();
+ return *this;
+ }
+
+ bool isShared() const { return m_typedArray->view()->isShared(); }
+
+ T* viewNotShared() const {
+ DCHECK(!isShared());
+ return m_typedArray.get();
+ }
+ T* viewMaybeShared() const { return m_typedArray.get(); }
+
+ bool operator!() const { return !m_typedArray; }
+ explicit operator bool() const { return !!m_typedArray; }
+ operator ScriptWrappable*() const { return m_typedArray.get(); }
+
+ private:
+ Member<T> m_typedArray;
+};
+
+} // namespace blink
+
+#endif // MaybeShared_h

Powered by Google App Engine
This is Rietveld 408576698