diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:20:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:28:57 +0000 |
commit | d17ea114e5ef69ad5d5d7413280a13e6428098aa (patch) | |
tree | 2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h | |
parent | 8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff) | |
download | qtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz |
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h')
-rw-r--r-- | chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h b/chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h new file mode 100644 index 00000000000..28063c81d3e --- /dev/null +++ b/chromium/third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h @@ -0,0 +1,153 @@ +// Copyright 2016 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_WRAPPABLE_VISITOR_H_ +#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_WRAPPABLE_VISITOR_H_ + +#include "third_party/blink/renderer/platform/bindings/trace_wrapper_base.h" +#include "third_party/blink/renderer/platform/heap/heap_page.h" +#include "third_party/blink/renderer/platform/heap/threading_traits.h" +#include "third_party/blink/renderer/platform/platform_export.h" +#include "third_party/blink/renderer/platform/wtf/deque.h" +#include "third_party/blink/renderer/platform/wtf/vector.h" +#include "v8/include/v8.h" + +namespace blink { + +template <typename T> +class DOMWrapperMap; +class ScriptWrappable; +class ScriptWrappableVisitor; +template <typename T> +class Supplement; +class TraceWrapperBase; +class TraceWrapperBaseForSupplement; +template <typename T> +class TraceWrapperV8Reference; + +#define DEFINE_TRAIT_FOR_TRACE_WRAPPERS(ClassName) \ + template <> \ + inline void TraceTrait<ClassName>::TraceWrappers( \ + ScriptWrappableVisitor* visitor, void* t) { \ + static_assert(sizeof(ClassName), "type needs to be defined"); \ + static_assert(IsGarbageCollectedType<ClassName>::value, \ + "only objects deriving from GarbageCollected can be used"); \ + static_cast<ClassName*>(t)->TraceWrappers(visitor); \ + } + +// Abstract visitor for wrapper references in a ScriptWrappable. +// Usage: +// - Define a derived class that overrides Visit(..) methods. +// - Create an instance of the derived class: visitor. +// - Call visitor.DispatchTraceWrappers(traceable). +// DispatchTraceWrappers will invoke Visit() method for all +// wrapper references in traceable. +class PLATFORM_EXPORT ScriptWrappableVisitor { + public: + template <typename T> + static NOINLINE void MissedWriteBarrier() { + NOTREACHED(); + } + + template <typename T> + static const char* NameCallback(const void* traceable) { + // Mixns never inherit from TraceWrapperBase. + return NameInHeapSnapshot(static_cast<const T*>(traceable)); + } + + // Trace all wrappers of |tracable|. + // + // If you cannot use TraceWrapperMember & the corresponding TraceWrappers() + // for some reason (e.g., unions using raw pointers), see + // |TraceWrappersWithManualWriteBarrier()| below. + template <typename T> + void TraceWrappers(const TraceWrapperMember<T>& traceable) const { + static_assert(sizeof(T), "T must be fully defined"); + Visit(traceable.Get()); + } + + // Enable partial tracing of objects. This is used when tracing interior + // objects without their own header. + template <typename T> + void TraceWrappers(const T& traceable) const { + static_assert(sizeof(T), "T must be fully defined"); + traceable.TraceWrappers(this); + } + + // Only called from automatically generated bindings code. + template <typename T> + void TraceWrappersFromGeneratedCode(const T* traceable) const { + Visit(traceable); + } + + // Require all users of manual write barriers to make this explicit in their + // |TraceWrappers| definition. Be sure to add + // |ScriptWrappableMarkingVisitor::WriteBarrier(new_value)| after all + // assignments to the field. Otherwise, the objects may be collected + // prematurely. + template <typename T> + void TraceWrappersWithManualWriteBarrier(const T* traceable) const { + Visit(traceable); + } + + template <typename V8Type> + void TraceWrappers(const TraceWrapperV8Reference<V8Type>& v8reference) const { + Visit(v8reference.template Cast<v8::Value>()); + } + + // Trace wrappers in non-main worlds. + void TraceWrappers(DOMWrapperMap<ScriptWrappable>*, + const ScriptWrappable* key) const; + + virtual void DispatchTraceWrappers(const TraceWrapperBase*) const; + template <typename T> + void DispatchTraceWrappers(const Supplement<T>* traceable) const { + const TraceWrapperBaseForSupplement* base = traceable; + DispatchTraceWrappersForSupplement(base); + } + // Catch all handlers needed because of mixins except for Supplement<T>. + void DispatchTraceWrappers(const void*) const { CHECK(false); } + + protected: + // The visitor interface. Derived visitors should override this + // function to visit V8 references and ScriptWrappables. + virtual void Visit(const TraceWrapperV8Reference<v8::Value>&) const = 0; + virtual void Visit(const TraceWrapperDescriptor&) const = 0; + virtual void Visit(DOMWrapperMap<ScriptWrappable>*, + const ScriptWrappable* key) const = 0; + + template <typename T> + static TraceWrapperDescriptor WrapperDescriptorFor(const T* traceable) { + return TraceTrait<T>::GetTraceWrapperDescriptor(const_cast<T*>(traceable)); + } + + private: + static const char* NameInHeapSnapshot(const TraceWrapperBase* traceable) { + return traceable->NameInHeapSnapshot(); + } + + static const char* NameInHeapSnapshot(...) { + // Default case for all non-TraceWrapperBase classes. + return "InternalNode"; + } + + // Helper method to invoke the virtual Visit method with wrapper descriptor. + template <typename T> + void Visit(const T* traceable) const { + static_assert(sizeof(T), "T must be fully defined"); + if (!traceable) + return; + Visit(WrapperDescriptorFor(traceable)); + } + + // Supplement-specific implementation of DispatchTraceWrappers. The suffix of + // "ForSupplement" is necessary not to make this member function a candidate + // of overload resolutions. + void DispatchTraceWrappersForSupplement( + const TraceWrapperBaseForSupplement*) const; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_WRAPPABLE_VISITOR_H_ |