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..684488adb7420bf4ada2f2960cc3cdb4a6848333 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableVisitor.h |
| @@ -0,0 +1,89 @@ |
| +// 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() \ |
| + 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() \ |
| + DECLARE_VIRTUAL_TRACE_WRAPPERS() override; |
|
haraken
2016/04/18 04:35:42
Yeah, what I was suggesting is to remove OVERRIDE_
Marcel Hlopko
2016/04/18 11:45:35
That would mean skipping override keyword. Are you
|
| + |
| +/** |
| + * 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 { |
| + 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; |
| + void traceWrappers(const NodeRareData* rareData) const; |
| +private: |
| + void mark(const ScriptWrappable* scriptWrappable) const; |
| + void mark(const void* garbageCollected) const; |
| + bool isMarked(const void* garbageCollected) const; |
|
haraken
2016/04/18 04:35:42
mark => markWrapper
isMarked => isWrapperMarked
Marcel Hlopko
2016/04/18 11:45:35
To be honest, I don't like the word wrapper here,
|
| + v8::Isolate* m_isolate; |
| + ScriptWrappableHeapTracer* m_tracer; |
| +}; |
| + |
| +} |
| +#endif |