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

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

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

Powered by Google App Engine
This is Rietveld 408576698