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

Unified 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 side-by-side diff with in-line comments
Download patch
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..d92db00ab986dcddccf2f324616feb8fe007a213
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/NotShared.h
@@ -0,0 +1,65 @@
+// 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 NotShared {
+ STACK_ALLOCATED();
+
+ public:
+ using TypedArrayType = T;
+
+ NotShared() {}
+
+ explicit NotShared(T* typedArray) : typed_array_(typedArray) {
+ DCHECK(!(typedArray && typedArray->View()->IsShared()));
+ }
+ NotShared(const NotShared& other) = default;
+ template <typename U>
+ NotShared(const NotShared<U>& other) : typed_array_(other.View()) {}
+ template <typename U>
+ NotShared(const Member<U>& other) {
+ DCHECK(!other->View()->IsShared());
+ typed_array_ = other.Get();
+ }
+
+ NotShared& operator=(const NotShared& other) = default;
+ template <typename U>
+ NotShared& operator=(const NotShared<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:
+ // Must use an untraced member here since this object may be constructed on a
+ // thread without a ThreadState (e.g. an Audio worklet). This is safe because
+ // 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.
+ UntracedMember<T> typed_array_;
+};
+
+} // namespace blink
+
+#endif // NotShared_h
« 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