| Index: third_party/WebKit/Source/core/dom/ArrayBufferViewHelpers.h
|
| diff --git a/third_party/WebKit/Source/core/dom/NotShared.h b/third_party/WebKit/Source/core/dom/ArrayBufferViewHelpers.h
|
| similarity index 50%
|
| rename from third_party/WebKit/Source/core/dom/NotShared.h
|
| rename to third_party/WebKit/Source/core/dom/ArrayBufferViewHelpers.h
|
| index 69173aaea4610677a9fcc4a8d9ea73971f742986..0f3c71f1475f9f20bd72aff88081b59fce0ea61e 100644
|
| --- a/third_party/WebKit/Source/core/dom/NotShared.h
|
| +++ b/third_party/WebKit/Source/core/dom/ArrayBufferViewHelpers.h
|
| @@ -2,8 +2,15 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef NotShared_h
|
| -#define NotShared_h
|
| +#ifndef ArrayBufferViewHelpers_h
|
| +#define ArrayBufferViewHelpers_h
|
| +
|
| +#include <type_traits>
|
| +#include "core/dom/DOMArrayBufferView.h"
|
| +#include "platform/heap/Handle.h"
|
| +#include "platform/wtf/TypeTraits.h"
|
| +
|
| +namespace blink {
|
|
|
| // A wrapper template type that is used to ensure that a TypedArray is not
|
| // backed by a SharedArrayBuffer.
|
| @@ -15,13 +22,11 @@
|
| // DOMUint32Array* array = param.View();
|
| // ...
|
| // }
|
| -
|
| -#include "platform/heap/Handle.h"
|
| -
|
| -namespace blink {
|
| -
|
| template <typename T>
|
| class NotShared {
|
| + static_assert(WTF::IsSubclass<typename std::remove_const<T>::type,
|
| + DOMArrayBufferView>::value,
|
| + "NotShared<T> must have T as subclass of DOMArrayBufferView");
|
| STACK_ALLOCATED();
|
|
|
| public:
|
| @@ -63,6 +68,53 @@ class NotShared {
|
| UntracedMember<T> typed_array_;
|
| };
|
|
|
| +// 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();
|
| +// ...
|
| +// }
|
| +template <typename T>
|
| +class MaybeShared {
|
| + static_assert(WTF::IsSubclass<typename std::remove_const<T>::type,
|
| + DOMArrayBufferView>::value,
|
| + "MaybeShared<T> must have T as subclass of DOMArrayBufferView");
|
| + STACK_ALLOCATED();
|
| +
|
| + public:
|
| + using TypedArrayType = T;
|
| +
|
| + MaybeShared() {}
|
| +
|
| + explicit MaybeShared(T* typedArray) : typed_array_(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 // NotShared_h
|
| +#endif // ArrayBufferViewHelpers_h
|
|
|