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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp

Issue 1876383003: Introduce infrastructure for tracing ScriptWrappables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use newer v8 api Created 4 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/bindings/core/v8/ScriptWrappableHeapTracer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..02d564064cc8c571d32e61230b360ee1689b199a
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp
@@ -0,0 +1,95 @@
+// 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.
+
+#include "bindings/core/v8/ScriptWrappableHeapTracer.h"
+
+#include "bindings/core/v8/ActiveScriptWrappable.h"
+#include "bindings/core/v8/DOMDataStore.h"
+#include "bindings/core/v8/ScriptWrappable.h"
+#include "bindings/core/v8/ScriptWrappableVisitor.h"
+#include "bindings/core/v8/WrapperTypeInfo.h"
+#include "platform/heap/HeapPage.h"
+
+namespace blink {
+
+ScriptWrappableHeapTracer::~ScriptWrappableHeapTracer()
+{
+}
+
+void ScriptWrappableHeapTracer::TracePrologue(v8::Isolate* isolate)
+{
+ m_tracingInProgress = true;
+ ScriptWrappableVisitor visitor(isolate, this);
+ ActiveScriptWrappable::traceActiveScriptWrappables(&visitor);
+}
+
+void ScriptWrappableHeapTracer::AddHeaderToUnmark(HeapObjectHeader* header)
+{
+ m_headersToUnmark.append(header);
+}
+
+void ScriptWrappableHeapTracer::TraceEpilogue(v8::Isolate* isolate)
+{
+ for (auto header : m_headersToUnmark)
+ header->unmarkWrapper();
+
+ m_headersToUnmark.clear();
+ m_tracingInProgress = false;
+}
+
+void ScriptWrappableHeapTracer::TraceWrappersFrom(v8::Isolate* isolate, const std::vector<std::pair<void*, void*>>& internalFieldsOfPotentialWrappers)
+{
+ ASSERT(m_tracingInProgress);
+ for (auto pair : internalFieldsOfPotentialWrappers) {
+ TraceWrappersFrom(isolate, pair);
+ }
+}
+
+
+void ScriptWrappableHeapTracer::TraceWrappersFrom(v8::Isolate* isolate, std::pair<void*, void*> internalFields)
+{
+ if (reinterpret_cast<WrapperTypeInfo*>(internalFields.first)->ginEmbedder
+ != gin::GinEmbedder::kEmbedderBlink)
+ return;
+
+ ScriptWrappable* scriptWrappable = reinterpret_cast<ScriptWrappable*>(
+ internalFields.second);
+ uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId;
+ if (classId != WrapperTypeInfo::NodeClassId
haraken 2016/04/19 04:58:31 ASSERT(classId == WrapperTypeInfo::NodeClassId ||
Marcel Hlopko 2016/04/19 12:40:29 Done.
+ && classId != WrapperTypeInfo::ObjectClassId) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ ScriptWrappableVisitor visitor(isolate, this);
+ visitor.traceWrappers(scriptWrappable);
+}
+
+void ScriptWrappableHeapTracer::TraceWrappersFrom(v8::Isolate* isolate, v8::Persistent<v8::Object>* handle)
haraken 2016/04/19 04:58:31 Where is this method used?
Marcel Hlopko 2016/04/19 12:40:29 Nowhere, removed.
+{
+ ScriptWrappable* scriptWrappable = toScriptWrappable(*handle);
+ uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId;
+ if (classId != WrapperTypeInfo::NodeClassId
+ && classId != WrapperTypeInfo::ObjectClassId) {
haraken 2016/04/19 04:58:31 Ditto.
Marcel Hlopko 2016/04/19 12:40:29 Done.
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ ScriptWrappableVisitor visitor(isolate, this);
+ visitor.traceWrappers(scriptWrappable);
+}
+
+void ScriptWrappableHeapTracer::markWrapper(const v8::Persistent<v8::Object>& handle, v8::Isolate* isolate)
+{
+ handle.RegisterExternalReference(isolate);
+}
+
+void ScriptWrappableHeapTracer::markWrappersInAllWorlds(const ScriptWrappable* scriptWrappable, v8::Isolate* isolate)
+{
+ DOMWrapperWorld::markWrappersInAllWorlds(
+ const_cast<ScriptWrappable*>(scriptWrappable), isolate);
+}
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698