Chromium Code Reviews| 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 MaybeShared_h | |
| 6 #define MaybeShared_h | |
| 7 | |
| 8 // A wrapper template type that specifies that a TypedArray may be backed by a | |
| 9 // 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(MaybeShared<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 MaybeShared { | |
|
haraken
2017/04/12 04:37:13
A couple of suggestions (which you can address in
| |
| 25 STACK_ALLOCATED(); | |
| 26 | |
| 27 public: | |
| 28 using TypedArrayType = T; | |
| 29 | |
| 30 MaybeShared() {} | |
| 31 | |
| 32 explicit MaybeShared(T* typedArray) : typed_array_(typedArray) { | |
| 33 DCHECK(!typedArray); | |
| 34 } | |
| 35 MaybeShared(const MaybeShared& other) = default; | |
| 36 template <typename U> | |
| 37 MaybeShared(const MaybeShared<U>& other) : typed_array_(other.View()) {} | |
| 38 template <typename U> | |
| 39 MaybeShared(const Member<U>& other) { | |
| 40 typed_array_ = other.Get(); | |
| 41 } | |
| 42 | |
| 43 MaybeShared& operator=(const MaybeShared& other) = default; | |
| 44 template <typename U> | |
| 45 MaybeShared& operator=(const MaybeShared<U>& other) { | |
| 46 typed_array_ = other.View(); | |
| 47 return *this; | |
| 48 } | |
| 49 | |
| 50 T* View() const { return typed_array_.Get(); } | |
| 51 | |
| 52 bool operator!() const { return !typed_array_; } | |
| 53 explicit operator bool() const { return !!typed_array_; } | |
| 54 | |
| 55 private: | |
| 56 Member<T> typed_array_; | |
| 57 }; | |
| 58 | |
| 59 } // namespace blink | |
| 60 | |
| 61 #endif // MaybeShared_h | |
| OLD | NEW |