OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/RejectedPromises.h" | 5 #include "bindings/core/v8/RejectedPromises.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/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (!execution_context) | 56 if (!execution_context) |
57 return; | 57 return; |
58 | 58 |
59 ScriptState::Scope scope(script_state_); | 59 ScriptState::Scope scope(script_state_); |
60 v8::Local<v8::Value> value = promise_.NewLocal(script_state_->GetIsolate()); | 60 v8::Local<v8::Value> value = promise_.NewLocal(script_state_->GetIsolate()); |
61 v8::Local<v8::Value> reason = | 61 v8::Local<v8::Value> reason = |
62 exception_.NewLocal(script_state_->GetIsolate()); | 62 exception_.NewLocal(script_state_->GetIsolate()); |
63 // Either collected or https://crbug.com/450330 | 63 // Either collected or https://crbug.com/450330 |
64 if (value.IsEmpty() || !value->IsPromise()) | 64 if (value.IsEmpty() || !value->IsPromise()) |
65 return; | 65 return; |
66 ASSERT(!HasHandler()); | 66 DCHECK(!HasHandler()); |
67 | 67 |
68 EventTarget* target = execution_context->ErrorEventTarget(); | 68 EventTarget* target = execution_context->ErrorEventTarget(); |
69 if (target && !execution_context->ShouldSanitizeScriptError(resource_name_, | 69 if (target && !execution_context->ShouldSanitizeScriptError(resource_name_, |
70 cors_status_)) { | 70 cors_status_)) { |
71 PromiseRejectionEventInit init; | 71 PromiseRejectionEventInit init; |
72 init.setPromise(ScriptPromise(script_state_, value)); | 72 init.setPromise(ScriptPromise(script_state_, value)); |
73 init.setReason(ScriptValue(script_state_, reason)); | 73 init.setReason(ScriptValue(script_state_, reason)); |
74 init.setCancelable(true); | 74 init.setCancelable(true); |
75 PromiseRejectionEvent* event = PromiseRejectionEvent::Create( | 75 PromiseRejectionEvent* event = PromiseRejectionEvent::Create( |
76 script_state_, EventTypeNames::unhandledrejection, init); | 76 script_state_, EventTypeNames::unhandledrejection, init); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 ThreadDebugger* debugger = | 120 ThreadDebugger* debugger = |
121 ThreadDebugger::From(script_state_->GetIsolate()); | 121 ThreadDebugger::From(script_state_->GetIsolate()); |
122 if (debugger) { | 122 if (debugger) { |
123 debugger->PromiseRejectionRevoked(script_state_->GetContext(), | 123 debugger->PromiseRejectionRevoked(script_state_->GetContext(), |
124 promise_rejection_id_); | 124 promise_rejection_id_); |
125 } | 125 } |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 void MakePromiseWeak() { | 129 void MakePromiseWeak() { |
130 ASSERT(!promise_.IsEmpty() && !promise_.IsWeak()); | 130 DCHECK(!promise_.IsEmpty()); |
| 131 DCHECK(!promise_.IsWeak()); |
131 promise_.SetWeak(this, &Message::DidCollectPromise); | 132 promise_.SetWeak(this, &Message::DidCollectPromise); |
132 exception_.SetWeak(this, &Message::DidCollectException); | 133 exception_.SetWeak(this, &Message::DidCollectException); |
133 } | 134 } |
134 | 135 |
135 void MakePromiseStrong() { | 136 void MakePromiseStrong() { |
136 ASSERT(!promise_.IsEmpty() && promise_.IsWeak()); | 137 DCHECK(!promise_.IsEmpty()); |
| 138 DCHECK(promise_.IsWeak()); |
137 promise_.ClearWeak(); | 139 promise_.ClearWeak(); |
138 exception_.ClearWeak(); | 140 exception_.ClearWeak(); |
139 } | 141 } |
140 | 142 |
141 bool HasHandler() { | 143 bool HasHandler() { |
142 ASSERT(!IsCollected()); | 144 DCHECK(!IsCollected()); |
143 ScriptState::Scope scope(script_state_); | 145 ScriptState::Scope scope(script_state_); |
144 v8::Local<v8::Value> value = promise_.NewLocal(script_state_->GetIsolate()); | 146 v8::Local<v8::Value> value = promise_.NewLocal(script_state_->GetIsolate()); |
145 return v8::Local<v8::Promise>::Cast(value)->HasHandler(); | 147 return v8::Local<v8::Promise>::Cast(value)->HasHandler(); |
146 } | 148 } |
147 | 149 |
148 private: | 150 private: |
149 Message(ScriptState* script_state, | 151 Message(ScriptState* script_state, |
150 v8::Local<v8::Promise> promise, | 152 v8::Local<v8::Promise> promise, |
151 v8::Local<v8::Value> exception, | 153 v8::Local<v8::Value> exception, |
152 const String& error_message, | 154 const String& error_message, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 kMaxReportedHandlersPendingResolution / 10); | 281 kMaxReportedHandlersPendingResolution / 10); |
280 } | 282 } |
281 } | 283 } |
282 } | 284 } |
283 | 285 |
284 void RejectedPromises::RevokeNow(std::unique_ptr<Message> message) { | 286 void RejectedPromises::RevokeNow(std::unique_ptr<Message> message) { |
285 message->Revoke(); | 287 message->Revoke(); |
286 } | 288 } |
287 | 289 |
288 } // namespace blink | 290 } // namespace blink |
OLD | NEW |