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

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

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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/ScriptPromisePropertyBase.h" 5 #include "bindings/core/v8/ScriptPromisePropertyBase.h"
6 6
7 #include "bindings/core/v8/ScopedPersistent.h" 7 #include "bindings/core/v8/ScopedPersistent.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8HiddenValue.h" 10 #include "bindings/core/v8/V8HiddenValue.h"
11 #include "core/dom/ExecutionContext.h" 11 #include "core/dom/ExecutionContext.h"
12 #include "wtf/PtrUtil.h"
13 #include <memory>
12 14
13 namespace blink { 15 namespace blink {
14 16
15 ScriptPromisePropertyBase::ScriptPromisePropertyBase(ExecutionContext* execution Context, Name name) 17 ScriptPromisePropertyBase::ScriptPromisePropertyBase(ExecutionContext* execution Context, Name name)
16 : ContextLifecycleObserver(executionContext) 18 : ContextLifecycleObserver(executionContext)
17 , m_isolate(toIsolate(executionContext)) 19 , m_isolate(toIsolate(executionContext))
18 , m_name(name) 20 , m_name(name)
19 , m_state(Pending) 21 , m_state(Pending)
20 { 22 {
21 } 23 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 { 76 {
75 ASSERT(getExecutionContext()); 77 ASSERT(getExecutionContext());
76 ASSERT(m_state == Pending); 78 ASSERT(m_state == Pending);
77 ASSERT(targetState == Resolved || targetState == Rejected); 79 ASSERT(targetState == Resolved || targetState == Rejected);
78 80
79 m_state = targetState; 81 m_state = targetState;
80 82
81 v8::HandleScope handleScope(m_isolate); 83 v8::HandleScope handleScope(m_isolate);
82 size_t i = 0; 84 size_t i = 0;
83 while (i < m_wrappers.size()) { 85 while (i < m_wrappers.size()) {
84 const OwnPtr<ScopedPersistent<v8::Object>>& persistent = m_wrappers[i]; 86 const std::unique_ptr<ScopedPersistent<v8::Object>>& persistent = m_wrap pers[i];
85 if (persistent->isEmpty()) { 87 if (persistent->isEmpty()) {
86 // wrapper has died. 88 // wrapper has died.
87 // Since v8 GC can run during the iteration and clear the reference, 89 // Since v8 GC can run during the iteration and clear the reference,
88 // we can't move this check out of the loop. 90 // we can't move this check out of the loop.
89 m_wrappers.remove(i); 91 m_wrappers.remove(i);
90 continue; 92 continue;
91 } 93 }
92 v8::Local<v8::Object> wrapper = persistent->newLocal(m_isolate); 94 v8::Local<v8::Object> wrapper = persistent->newLocal(m_isolate);
93 ScriptState* scriptState = ScriptState::from(wrapper->CreationContext()) ; 95 ScriptState* scriptState = ScriptState::from(wrapper->CreationContext()) ;
94 ScriptState::Scope scope(scriptState); 96 ScriptState::Scope scope(scriptState);
(...skipping 27 matching lines...) Expand all
122 resolver->Reject(context, rejectedValue(m_isolate, context->Global())); 124 resolver->Reject(context, rejectedValue(m_isolate, context->Global()));
123 break; 125 break;
124 } 126 }
125 } 127 }
126 128
127 v8::Local<v8::Object> ScriptPromisePropertyBase::ensureHolderWrapper(ScriptState * scriptState) 129 v8::Local<v8::Object> ScriptPromisePropertyBase::ensureHolderWrapper(ScriptState * scriptState)
128 { 130 {
129 v8::Local<v8::Context> context = scriptState->context(); 131 v8::Local<v8::Context> context = scriptState->context();
130 size_t i = 0; 132 size_t i = 0;
131 while (i < m_wrappers.size()) { 133 while (i < m_wrappers.size()) {
132 const OwnPtr<ScopedPersistent<v8::Object>>& persistent = m_wrappers[i]; 134 const std::unique_ptr<ScopedPersistent<v8::Object>>& persistent = m_wrap pers[i];
133 if (persistent->isEmpty()) { 135 if (persistent->isEmpty()) {
134 // wrapper has died. 136 // wrapper has died.
135 // Since v8 GC can run during the iteration and clear the reference, 137 // Since v8 GC can run during the iteration and clear the reference,
136 // we can't move this check out of the loop. 138 // we can't move this check out of the loop.
137 m_wrappers.remove(i); 139 m_wrappers.remove(i);
138 continue; 140 continue;
139 } 141 }
140 142
141 v8::Local<v8::Object> wrapper = persistent->newLocal(m_isolate); 143 v8::Local<v8::Object> wrapper = persistent->newLocal(m_isolate);
142 if (wrapper->CreationContext() == context) 144 if (wrapper->CreationContext() == context)
143 return wrapper; 145 return wrapper;
144 ++i; 146 ++i;
145 } 147 }
146 v8::Local<v8::Object> wrapper = holder(m_isolate, context->Global()); 148 v8::Local<v8::Object> wrapper = holder(m_isolate, context->Global());
147 OwnPtr<ScopedPersistent<v8::Object>> weakPersistent = adoptPtr(new ScopedPer sistent<v8::Object>); 149 std::unique_ptr<ScopedPersistent<v8::Object>> weakPersistent = wrapUnique(ne w ScopedPersistent<v8::Object>);
148 weakPersistent->set(m_isolate, wrapper); 150 weakPersistent->set(m_isolate, wrapper);
149 weakPersistent->setWeak(weakPersistent.get(), &clearHandle); 151 weakPersistent->setWeak(weakPersistent.get(), &clearHandle);
150 m_wrappers.append(std::move(weakPersistent)); 152 m_wrappers.append(std::move(weakPersistent));
151 return wrapper; 153 return wrapper;
152 } 154 }
153 155
154 void ScriptPromisePropertyBase::clearWrappers() 156 void ScriptPromisePropertyBase::clearWrappers()
155 { 157 {
156 checkThis(); 158 checkThis();
157 checkWrappers(); 159 checkWrappers();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 ASSERT_NOT_REACHED(); 210 ASSERT_NOT_REACHED();
209 return v8::Local<v8::String>(); 211 return v8::Local<v8::String>();
210 } 212 }
211 213
212 DEFINE_TRACE(ScriptPromisePropertyBase) 214 DEFINE_TRACE(ScriptPromisePropertyBase)
213 { 215 {
214 ContextLifecycleObserver::trace(visitor); 216 ContextLifecycleObserver::trace(visitor);
215 } 217 }
216 218
217 } // namespace blink 219 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698