Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/NotShared.h |
| diff --git a/third_party/WebKit/Source/core/dom/NotShared.h b/third_party/WebKit/Source/core/dom/NotShared.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b46cb8b66bdbdad73f551fbd1bb9fb9519236ee6 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/NotShared.h |
| @@ -0,0 +1,71 @@ |
| +// 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 NotShared_h |
| +#define NotShared_h |
| + |
| +// A wrapper template type that is used to ensure that a TypedArray is not |
| +// 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(NotShared<DOMUint32Array> param) { |
| +// DOMUint32Array* array = param.view(); |
| +// ... |
| +// } |
| + |
| +#include "platform/heap/Handle.h" |
| + |
| +namespace blink { |
| + |
| +template <typename T> |
| +class CORE_EXPORT NotShared { |
| + STACK_ALLOCATED(); |
| + |
| + public: |
| + using TypedArrayType = T; |
| + |
| + NotShared() {} |
| + |
| + explicit NotShared(T* typedArray) : m_typedArray(typedArray) { |
| + DCHECK(!(typedArray && typedArray->view()->isShared())); |
| + } |
| + NotShared(const NotShared& other) = default; |
| + template <typename U> |
| + NotShared(const NotShared<U>& other) : m_typedArray(other.view()) {} |
| + template <typename U> |
| + NotShared(const Member<U>& other) { |
| + DCHECK(!other->view()->isShared()); |
| + m_typedArray = *other; |
| + } |
| + |
| + NotShared& operator=(const NotShared& other) = default; |
| + template <typename U> |
| + NotShared& operator=(const NotShared<U>& other) { |
| + m_typedArray = other.view(); |
| + return *this; |
| + } |
| + |
| + T* view() const { return m_typedArray.get(); } |
| + |
| + bool operator!() const { return !m_typedArray; } |
| + explicit operator bool() const { return !!m_typedArray; } |
| + |
| + private: |
| + Member<T> m_typedArray; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +namespace WTF { |
| + |
| +template <typename T> |
| +inline T* getPtr(const ::blink::NotShared<T>& p) { |
|
haraken
2017/04/09 14:11:45
Is this needed?
binji
2017/04/09 23:42:27
It was used by a WaveShaperNode attribute getter,
|
| + return p.view(); |
| +} |
| + |
| +} // namespace WTF |
| + |
| +#endif // NotShared_h |