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

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

Issue 2577053002: ActiveScriptWrappable: GC wrappers in detached ExecutionContexts. (Closed)
Patch Set: component build fix(msvc) Created 4 years 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/ActiveScriptWrappable.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ActiveScriptWrappable.cpp b/third_party/WebKit/Source/bindings/core/v8/ActiveScriptWrappable.cpp
index 2c44e04451016528612e51009012b2c17b843847..0803547b11071f28a0ff26f402ce12ffb468b718 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ActiveScriptWrappable.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ActiveScriptWrappable.cpp
@@ -4,13 +4,16 @@
#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/V8Binding.h"
#include "bindings/core/v8/V8PerIsolateData.h"
+#include "core/dom/ExecutionContext.h"
namespace blink {
-ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self)
+ActiveScriptWrappableBase::ActiveScriptWrappableBase(ScriptWrappable* self)
: m_scriptWrappable(self) {
ASSERT(ThreadState::current());
v8::Isolate* isolate = ThreadState::current()->isolate();
@@ -18,7 +21,7 @@ ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self)
isolateData->addActiveScriptWrappable(this);
}
-void ActiveScriptWrappable::traceActiveScriptWrappables(
+void ActiveScriptWrappableBase::traceActiveScriptWrappables(
v8::Isolate* isolate,
ScriptWrappableVisitor* visitor) {
V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
@@ -33,6 +36,22 @@ void ActiveScriptWrappable::traceActiveScriptWrappables(
continue;
}
+ // A wrapper isn't kept alive after its ExecutionContext becomes
+ // detached, even if hasPendingActivity() returns |true|. This measure
+ // avoids memory leaks and has proven not to be too eager wrt
+ // garbage collection of objects belonging to discarded browser contexts
+ // ( https://html.spec.whatwg.org/#a-browsing-context-is-discarded )
+ //
+ // Consequently, an implementation of hasPendingActivity() is
+ // not required to take the detached state of the associated
+ // ExecutionContext into account (i.e., return |false|.) We probe
+ // the detached state of the ExecutionContext via
+ // |isContextDestroyed()|.
+ //
+ // TODO(haraken): Implement correct lifetime using traceWrapper.
+ if (activeWrappable->isContextDestroyed(activeWrappable)) {
+ continue;
+ }
auto wrapperTypeInfo =
const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo());
visitor->RegisterV8Reference(

Powered by Google App Engine
This is Rietveld 408576698