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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptWrappable.cpp

Issue 1873323002: Have bindings layer assume and insist that all interface types are GCed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/ScriptWrappable.h" 5 #include "bindings/core/v8/ScriptWrappable.h"
6 6
7 #include "bindings/core/v8/DOMDataStore.h" 7 #include "bindings/core/v8/DOMDataStore.h"
8 #include "bindings/core/v8/V8DOMWrapper.h" 8 #include "bindings/core/v8/V8DOMWrapper.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 struct SameSizeAsScriptWrappable { 12 struct SameSizeAsScriptWrappable {
13 virtual ~SameSizeAsScriptWrappable() { } 13 virtual ~SameSizeAsScriptWrappable() { }
14 v8::Persistent<v8::Object> m_wrapper; 14 v8::Persistent<v8::Object> m_wrapper;
15 }; 15 };
16 16
17 static_assert(sizeof(ScriptWrappable) <= sizeof(SameSizeAsScriptWrappable), "Scr iptWrappable should stay small"); 17 static_assert(sizeof(ScriptWrappable) <= sizeof(SameSizeAsScriptWrappable), "Scr iptWrappable should stay small");
18 18
19 namespace {
20
21 class ScriptWrappableProtector final {
22 WTF_MAKE_NONCOPYABLE(ScriptWrappableProtector);
23 public:
24 ScriptWrappableProtector(ScriptWrappable* scriptWrappable, const WrapperType Info* wrapperTypeInfo)
25 : m_scriptWrappable(scriptWrappable), m_wrapperTypeInfo(wrapperTypeInfo)
26 {
27 m_wrapperTypeInfo->refObject(m_scriptWrappable);
28 }
29 ~ScriptWrappableProtector()
30 {
31 m_wrapperTypeInfo->derefObject(m_scriptWrappable);
32 }
33
34 private:
35 ScriptWrappable* m_scriptWrappable;
36 const WrapperTypeInfo* m_wrapperTypeInfo;
37 };
38
39 } // namespace
40
41 v8::Local<v8::Object> ScriptWrappable::wrap(v8::Isolate* isolate, v8::Local<v8:: Object> creationContext) 19 v8::Local<v8::Object> ScriptWrappable::wrap(v8::Isolate* isolate, v8::Local<v8:: Object> creationContext)
42 { 20 {
43 const WrapperTypeInfo* wrapperTypeInfo = this->wrapperTypeInfo(); 21 const WrapperTypeInfo* wrapperTypeInfo = this->wrapperTypeInfo();
44 22
45 // It's possible that no one except for the new wrapper owns this object at
46 // this moment, so we have to prevent GC to collect this object until the
47 // object gets associated with the wrapper.
48 ScriptWrappableProtector protect(this, wrapperTypeInfo);
49
50 ASSERT(!DOMDataStore::containsWrapper(this, isolate)); 23 ASSERT(!DOMDataStore::containsWrapper(this, isolate));
51 24
52 v8::Local<v8::Object> wrapper = V8DOMWrapper::createWrapper(isolate, creatio nContext, wrapperTypeInfo, this); 25 v8::Local<v8::Object> wrapper = V8DOMWrapper::createWrapper(isolate, creatio nContext, wrapperTypeInfo, this);
53 if (UNLIKELY(wrapper.IsEmpty())) 26 if (UNLIKELY(wrapper.IsEmpty()))
54 return wrapper; 27 return wrapper;
55 28
56 wrapperTypeInfo->installConditionallyEnabledProperties(wrapper, isolate); 29 wrapperTypeInfo->installConditionallyEnabledProperties(wrapper, isolate);
57 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper); 30 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper);
58 } 31 }
59 32
60 v8::Local<v8::Object> ScriptWrappable::associateWithWrapper(v8::Isolate* isolate , const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Object> wrapper) 33 v8::Local<v8::Object> ScriptWrappable::associateWithWrapper(v8::Isolate* isolate , const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Object> wrapper)
61 { 34 {
62 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperTypeIn fo, wrapper); 35 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperTypeIn fo, wrapper);
63 } 36 }
64 37
65 } // namespace blink 38 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptWrappable.h ('k') | third_party/WebKit/Source/bindings/core/v8/ToV8Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698