OLD | NEW |
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 <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 case kResolved: | 58 case kResolved: |
59 case kRejected: | 59 case kRejected: |
60 ResolveOrRejectInternal(resolver); | 60 ResolveOrRejectInternal(resolver); |
61 break; | 61 break; |
62 } | 62 } |
63 | 63 |
64 return ScriptPromise(script_state, promise); | 64 return ScriptPromise(script_state, promise); |
65 } | 65 } |
66 | 66 |
67 void ScriptPromisePropertyBase::ResolveOrReject(State target_state) { | 67 void ScriptPromisePropertyBase::ResolveOrReject(State target_state) { |
68 ASSERT(GetExecutionContext()); | 68 DCHECK(GetExecutionContext()); |
69 ASSERT(state_ == kPending); | 69 DCHECK_EQ(state_, kPending); |
70 ASSERT(target_state == kResolved || target_state == kRejected); | 70 DCHECK(target_state == kResolved || target_state == kRejected); |
71 | 71 |
72 state_ = target_state; | 72 state_ = target_state; |
73 | 73 |
74 v8::HandleScope handle_scope(isolate_); | 74 v8::HandleScope handle_scope(isolate_); |
75 size_t i = 0; | 75 size_t i = 0; |
76 while (i < wrappers_.size()) { | 76 while (i < wrappers_.size()) { |
77 const std::unique_ptr<ScopedPersistent<v8::Object>>& persistent = | 77 const std::unique_ptr<ScopedPersistent<v8::Object>>& persistent = |
78 wrappers_[i]; | 78 wrappers_[i]; |
79 if (persistent->IsEmpty()) { | 79 if (persistent->IsEmpty()) { |
80 // wrapper has died. | 80 // wrapper has died. |
(...skipping 21 matching lines...) Expand all Loading... |
102 CheckThis(); | 102 CheckThis(); |
103 ClearWrappers(); | 103 ClearWrappers(); |
104 state_ = kPending; | 104 state_ = kPending; |
105 } | 105 } |
106 | 106 |
107 void ScriptPromisePropertyBase::ResolveOrRejectInternal( | 107 void ScriptPromisePropertyBase::ResolveOrRejectInternal( |
108 v8::Local<v8::Promise::Resolver> resolver) { | 108 v8::Local<v8::Promise::Resolver> resolver) { |
109 v8::Local<v8::Context> context = resolver->CreationContext(); | 109 v8::Local<v8::Context> context = resolver->CreationContext(); |
110 switch (state_) { | 110 switch (state_) { |
111 case kPending: | 111 case kPending: |
112 ASSERT_NOT_REACHED(); | 112 NOTREACHED(); |
113 break; | 113 break; |
114 case kResolved: | 114 case kResolved: |
115 resolver->Resolve(context, ResolvedValue(isolate_, context->Global())) | 115 resolver->Resolve(context, ResolvedValue(isolate_, context->Global())) |
116 .ToChecked(); | 116 .ToChecked(); |
117 break; | 117 break; |
118 case kRejected: | 118 case kRejected: |
119 resolver->Reject(context, RejectedValue(isolate_, context->Global())) | 119 resolver->Reject(context, RejectedValue(isolate_, context->Global())) |
120 .ToChecked(); | 120 .ToChecked(); |
121 break; | 121 break; |
122 } | 122 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (!wrapper.IsEmpty()) { | 162 if (!wrapper.IsEmpty()) { |
163 // TODO(peria): Use deleteProperty() if http://crbug.com/v8/6227 is fixed. | 163 // TODO(peria): Use deleteProperty() if http://crbug.com/v8/6227 is fixed. |
164 ResolverSymbol().Set(wrapper, v8::Undefined(isolate_)); | 164 ResolverSymbol().Set(wrapper, v8::Undefined(isolate_)); |
165 PromiseSymbol().Set(wrapper, v8::Undefined(isolate_)); | 165 PromiseSymbol().Set(wrapper, v8::Undefined(isolate_)); |
166 } | 166 } |
167 } | 167 } |
168 wrappers_.Clear(); | 168 wrappers_.Clear(); |
169 } | 169 } |
170 | 170 |
171 void ScriptPromisePropertyBase::CheckThis() { | 171 void ScriptPromisePropertyBase::CheckThis() { |
172 RELEASE_ASSERT(this); | 172 CHECK(this); |
173 } | 173 } |
174 | 174 |
175 void ScriptPromisePropertyBase::CheckWrappers() { | 175 void ScriptPromisePropertyBase::CheckWrappers() { |
176 for (WeakPersistentSet::iterator i = wrappers_.begin(); i != wrappers_.end(); | 176 for (WeakPersistentSet::iterator i = wrappers_.begin(); i != wrappers_.end(); |
177 ++i) { | 177 ++i) { |
178 RELEASE_ASSERT(*i); | 178 CHECK(*i); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 V8PrivateProperty::Symbol ScriptPromisePropertyBase::PromiseSymbol() { | 182 V8PrivateProperty::Symbol ScriptPromisePropertyBase::PromiseSymbol() { |
183 switch (name_) { | 183 switch (name_) { |
184 #define P(Interface, Name) \ | 184 #define P(Interface, Name) \ |
185 case Name: \ | 185 case Name: \ |
186 return V8PrivateProperty::V8_PRIVATE_PROPERTY_GETTER_NAME( \ | 186 return V8PrivateProperty::V8_PRIVATE_PROPERTY_GETTER_NAME( \ |
187 Interface, Name##Promise)(isolate_); | 187 Interface, Name##Promise)(isolate_); |
188 | 188 |
(...skipping 18 matching lines...) Expand all Loading... |
207 } | 207 } |
208 NOTREACHED(); | 208 NOTREACHED(); |
209 return V8PrivateProperty::GetSymbol(isolate_, "noResolver"); | 209 return V8PrivateProperty::GetSymbol(isolate_, "noResolver"); |
210 } | 210 } |
211 | 211 |
212 DEFINE_TRACE(ScriptPromisePropertyBase) { | 212 DEFINE_TRACE(ScriptPromisePropertyBase) { |
213 ContextClient::Trace(visitor); | 213 ContextClient::Trace(visitor); |
214 } | 214 } |
215 | 215 |
216 } // namespace blink | 216 } // namespace blink |
OLD | NEW |