summaryrefslogtreecommitdiff
path: root/chromium/v8/src/execution/local-isolate-wrapper.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/execution/local-isolate-wrapper.h
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/execution/local-isolate-wrapper.h')
-rw-r--r--chromium/v8/src/execution/local-isolate-wrapper.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/chromium/v8/src/execution/local-isolate-wrapper.h b/chromium/v8/src/execution/local-isolate-wrapper.h
new file mode 100644
index 00000000000..8dbf0c23919
--- /dev/null
+++ b/chromium/v8/src/execution/local-isolate-wrapper.h
@@ -0,0 +1,85 @@
+// Copyright 2020 the V8 project 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 V8_EXECUTION_LOCAL_ISOLATE_WRAPPER_H_
+#define V8_EXECUTION_LOCAL_ISOLATE_WRAPPER_H_
+
+#include "src/utils/pointer-with-payload.h"
+
+namespace v8 {
+namespace internal {
+
+// LocalWrapperBase is the base-class for wrapper classes around a main-thread
+// and off-thread type, e.g. Isolate and OffThreadIsolate, and a bit stating
+// which of the two the wrapper wraps.
+//
+// The shared methods are defined on MethodCaller, which will dispatch to the
+// right type depending on the state of the wrapper. The reason for a separate
+// MethodCaller is to
+//
+// a) Move the method definitions into an -inl.h so that this header can have
+// minimal dependencies, and
+// b) To allow the type methods to be called with operator-> (e.g.
+// isolate_wrapper->heap()), while forcing the wrapper methods to be called
+// with a dot (e.g. isolate_wrapper.is_main_thread()).
+template <typename MainThreadType, typename OffThreadType,
+ typename MethodCaller>
+class LocalWrapperBase {
+ public:
+ // Helper for returning a MethodCaller* by value from operator->.
+ class MethodCallerRef {
+ public:
+ MethodCaller* operator->() { return &caller_; }
+
+ private:
+ friend class LocalWrapperBase;
+ explicit MethodCallerRef(LocalWrapperBase* wrapper) : caller_(wrapper) {}
+
+ MethodCaller caller_;
+ };
+
+ explicit LocalWrapperBase(std::nullptr_t) : pointer_and_tag_(nullptr) {}
+ explicit LocalWrapperBase(MainThreadType* pointer)
+ : pointer_and_tag_(pointer, false) {}
+ explicit LocalWrapperBase(OffThreadType* pointer)
+ : pointer_and_tag_(pointer, true) {}
+
+ MainThreadType* main_thread() {
+ DCHECK(is_main_thread());
+ return static_cast<MainThreadType*>(
+ pointer_and_tag_.GetPointerWithKnownPayload(false));
+ }
+ OffThreadType* off_thread() {
+ DCHECK(is_off_thread());
+ return static_cast<OffThreadType*>(
+ pointer_and_tag_.GetPointerWithKnownPayload(true));
+ }
+
+ bool is_main_thread() const {
+ return !is_null() && !pointer_and_tag_.GetPayload();
+ }
+ bool is_off_thread() const {
+ return !is_null() && pointer_and_tag_.GetPayload();
+ }
+ bool is_null() const { return pointer_and_tag_.GetPointer() == nullptr; }
+
+ // Access the methods via wrapper->Method.
+ MethodCallerRef operator->() { return MethodCallerRef(this); }
+
+ private:
+ PointerWithPayload<void, bool, 1> pointer_and_tag_;
+};
+
+using LocalHeapWrapper =
+ LocalWrapperBase<class Heap, class OffThreadHeap, class HeapMethodCaller>;
+using LocalLoggerWrapper = LocalWrapperBase<class Logger, class OffThreadLogger,
+ class LoggerMethodCaller>;
+using LocalIsolateWrapper =
+ LocalWrapperBase<class Isolate, class OffThreadIsolate,
+ class IsolateMethodCaller>;
+
+} // namespace internal
+} // namespace v8
+
+#endif // V8_EXECUTION_LOCAL_ISOLATE_WRAPPER_H_