Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/ScriptWrappableVisitor.h |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableVisitor.h b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableVisitor.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d547df2a3b987626af26c595066048bf06ef298f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableVisitor.h |
| @@ -0,0 +1,88 @@ |
| +// 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 ScriptWrappableVisitor_h |
| +#define ScriptWrappableVisitor_h |
| + |
| +#include "platform/heap/HeapAllocator.h" |
| +#include <v8.h> |
| +#include <vector> |
| + |
| + |
| +namespace blink { |
| + |
| +class HeapObjectHeader; |
| +class ScriptWrappable; |
| +class ScriptWrappableHeapTracer; |
| +class NodeRareData; |
| + |
| +/** |
| + * Declares non-virtual traceWrappers method. Should be used on |
| + * non-ScriptWrappable classes which should participate in wrapper tracing (e.g. |
| + * NodeRareData): |
| + * |
| + * class NodeRareData { |
| + * public: |
| + * DECLARE_NONVIRTUAL_TRACE_WRAPPERS(); |
| + * } |
| + */ |
| +#define DECLARE_NONVIRTUAL_TRACE_WRAPPERS() \ |
|
haraken
2016/04/19 04:58:31
DECLARE_NONVIRTUAL_TRACE_WRAPPERS => DECLARE_TRACE
Marcel Hlopko
2016/04/19 12:40:30
Done.
|
| + void traceWrappers(const ScriptWrappableVisitor*) const |
| + |
| +/** |
| + * Declares virtual traceWrappers method. It is used in ScriptWrappable, and can |
| + * be used by non-ScriptWrappable classes which expect being inherited. |
| + */ |
| +#define DECLARE_VIRTUAL_TRACE_WRAPPERS() \ |
| + virtual DECLARE_NONVIRTUAL_TRACE_WRAPPERS() |
| + |
| +/** |
| + * Declares overridden traceWrappers method in the subclass of a class with |
| + * DECLARE_VIRTUAL_TRACE_WRAPPERS(), used e.g. in dom/Node: |
| + * |
| + * class Node : public ScriptWrappable { |
| + * OVERRIDE_TRACE_WRAPPERS(); |
| + * } |
| + */ |
| +#define OVERRIDE_TRACE_WRAPPERS() \ |
|
haraken
2016/04/19 04:58:31
Yeah, I'd prefer dropping OVERRIDE in order to mak
Marcel Hlopko
2016/04/19 12:40:30
Done.
|
| + DECLARE_VIRTUAL_TRACE_WRAPPERS() override; |
| + |
| +/** |
| + * Provides definition of traceWrappers method. Custom code will usually call |
| + * visitor->traceWrappers with all objects which could contribute to the set of |
| + * reachable wrappers: |
| + * |
| + * DEFINE_TRACE_WRAPPERS(NodeRareData) |
| + * { |
| + * visitor->traceWrappers(m_nodeLists); |
| + * visitor->traceWrappers(m_mutationObserverData); |
| + * } |
| + */ |
| +#define DEFINE_TRACE_WRAPPERS(T) \ |
| + void T::traceWrappers(const ScriptWrappableVisitor* visitor) const |
| + |
| +/** |
| + * ScriptWrappableVisitor is able to trace through the script wrappable |
| + * references. It is used by the ScriptWrappableHeapTracer during V8 garbage |
| + * collection. |
| + */ |
| +class ScriptWrappableVisitor { |
|
haraken
2016/04/19 04:58:31
I guess you can just remove ScriptWrappableVisitor
Marcel Hlopko
2016/04/19 12:40:30
Done. I cleaned up v8 api once again.
|
| + STACK_ALLOCATED(); |
| +public: |
| + ScriptWrappableVisitor(v8::Isolate* isolate, ScriptWrappableHeapTracer* tracer) |
| + : m_isolate(isolate) |
| + , m_tracer(tracer) |
| + {}; |
| + void traceWrappers(const ScriptWrappable* wrappable) const; |
| + void traceWrappers(const ScriptWrappable& wrappable) const; |
| +private: |
| + void markHeader(const ScriptWrappable* scriptWrappable) const; |
| + void markHeader(const void* garbageCollected) const; |
| + bool isHeaderMarked(const void* garbageCollected) const; |
| + v8::Isolate* m_isolate; |
| + ScriptWrappableHeapTracer* m_tracer; |
| +}; |
| + |
| +} |
| +#endif |