Chromium Code Reviews| 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 |