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

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

Issue 2815793002: [SharedArrayBuffer] Add "AllowShared" extended attribute, used for WebGL (Closed)
Patch Set: Created 3 years, 8 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..3e5fe87e7417173c1e26c73ee665af44490ca275
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/MaybeShared.h
@@ -0,0 +1,61 @@
+// 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
+
+// A wrapper template type that specifies that a TypedArray may be backed by a
+// SharedArrayBuffer.
+//
+// Typically this is used as an annotation on C++ functions that are called by
+// the bindings layer, e.g.:
+//
+// void Foo(MaybeShared<DOMUint32Array> param) {
+// DOMUint32Array* array = param.View();
+// ...
+// }
+
+#include "platform/heap/Handle.h"
+
+namespace blink {
+
+template <typename T>
+class MaybeShared {
haraken 2017/04/12 04:37:13 A couple of suggestions (which you can address in
+ STACK_ALLOCATED();
+
+ public:
+ using TypedArrayType = T;
+
+ MaybeShared() {}
+
+ explicit MaybeShared(T* typedArray) : typed_array_(typedArray) {
+ DCHECK(!typedArray);
+ }
+ MaybeShared(const MaybeShared& other) = default;
+ template <typename U>
+ MaybeShared(const MaybeShared<U>& other) : typed_array_(other.View()) {}
+ template <typename U>
+ MaybeShared(const Member<U>& other) {
+ typed_array_ = other.Get();
+ }
+
+ MaybeShared& operator=(const MaybeShared& other) = default;
+ template <typename U>
+ MaybeShared& operator=(const MaybeShared<U>& other) {
+ typed_array_ = other.View();
+ return *this;
+ }
+
+ T* View() const { return typed_array_.Get(); }
+
+ bool operator!() const { return !typed_array_; }
+ explicit operator bool() const { return !!typed_array_; }
+
+ private:
+ Member<T> typed_array_;
+};
+
+} // namespace blink
+
+#endif // MaybeShared_h

Powered by Google App Engine
This is Rietveld 408576698