OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NotShared_h | |
6 #define NotShared_h | |
7 | |
8 // A wrapper template type that is used to ensure that a TypedArray is not | |
9 // backed by a SharedArrayBuffer. | |
10 // | |
11 // Typically this is used as an annotation on C++ functions that are called by | |
12 // the bindings layer, e.g.: | |
13 // | |
14 // void Foo(NotShared<DOMUint32Array> param) { | |
15 // DOMUint32Array* array = param.view(); | |
16 // ... | |
17 // } | |
18 | |
19 #include "platform/heap/Handle.h" | |
20 | |
21 namespace blink { | |
22 | |
23 template <typename T> | |
24 class CORE_EXPORT NotShared { | |
25 STACK_ALLOCATED(); | |
26 | |
27 public: | |
28 using TypedArrayType = T; | |
29 | |
30 NotShared() {} | |
31 | |
32 explicit NotShared(T* typedArray) : m_typedArray(typedArray) { | |
33 DCHECK(!(typedArray && typedArray->view()->isShared())); | |
34 } | |
35 NotShared(const NotShared& other) = default; | |
36 template <typename U> | |
37 NotShared(const NotShared<U>& other) : m_typedArray(other.view()) {} | |
38 template <typename U> | |
39 NotShared(const Member<U>& other) { | |
40 DCHECK(!other->view()->isShared()); | |
41 m_typedArray = *other; | |
42 } | |
43 | |
44 NotShared& operator=(const NotShared& other) = default; | |
45 template <typename U> | |
46 NotShared& operator=(const NotShared<U>& other) { | |
47 m_typedArray = other.view(); | |
48 return *this; | |
49 } | |
50 | |
51 T* view() const { return m_typedArray.get(); } | |
52 | |
53 bool operator!() const { return !m_typedArray; } | |
54 explicit operator bool() const { return !!m_typedArray; } | |
55 | |
56 private: | |
57 Member<T> m_typedArray; | |
58 }; | |
59 | |
60 } // namespace blink | |
61 | |
62 namespace WTF { | |
63 | |
64 template <typename T> | |
65 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,
| |
66 return p.view(); | |
67 } | |
68 | |
69 } // namespace WTF | |
70 | |
71 #endif // NotShared_h | |
OLD | NEW |