Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/WebKit/Source/core/dom/NotShared.h

Issue 2707243006: [SharedArrayBuffer] Prevent SharedArrayBuffer being used in Web APIs (Closed)
Patch Set: add missing tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 NotShared {
25 STACK_ALLOCATED();
26
27 public:
28 using TypedArrayType = T;
29
30 NotShared() {}
31
32 explicit NotShared(T* typedArray) : typed_array_(typedArray) {
33 DCHECK(!(typedArray && typedArray->View()->IsShared()));
34 }
35 NotShared(const NotShared& other) = default;
36 template <typename U>
37 NotShared(const NotShared<U>& other) : typed_array_(other.View()) {}
38 template <typename U>
39 NotShared(const Member<U>& other) {
40 DCHECK(!other->View()->IsShared());
41 typed_array_ = other.Get();
42 }
43
44 NotShared& operator=(const NotShared& other) = default;
45 template <typename U>
46 NotShared& operator=(const NotShared<U>& other) {
47 typed_array_ = other.View();
48 return *this;
49 }
50
51 T* View() const { return typed_array_.Get(); }
52
53 bool operator!() const { return !typed_array_; }
54 explicit operator bool() const { return !!typed_array_; }
55
56 private:
57 // Must use an untraced member here since this object may be constructed on a
58 // thread without a ThreadState (e.g. an Audio worklet). This is safe because
59 // this object is only stack allocated.
haraken 2017/04/11 01:01:03 Update this comment. This is safe not because the
binji 2017/04/11 01:17:33 Done, and added TODO w/ bug as well.
60 UntracedMember<T> typed_array_;
61 };
62
63 } // namespace blink
64
65 #endif // NotShared_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/DOMArrayPiece.cpp ('k') | third_party/WebKit/Source/core/fileapi/Blob.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698