| 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 "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 11 #include "bindings/core/v8/V8PerIsolateData.h" | 12 #include "bindings/core/v8/V8PerIsolateData.h" |
| 12 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/events/EventTarget.h" | 14 #include "core/events/EventTarget.h" |
| 14 #include "core/events/PromiseRejectionEvent.h" | 15 #include "core/events/PromiseRejectionEvent.h" |
| 15 #include "core/inspector/ThreadDebugger.h" | 16 #include "core/inspector/ThreadDebugger.h" |
| 16 #include "platform/WebTaskRunner.h" | 17 #include "platform/WebTaskRunner.h" |
| 17 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
| 18 #include "public/platform/WebScheduler.h" | 19 #include "public/platform/WebScheduler.h" |
| 19 #include "public/platform/WebThread.h" | 20 #include "public/platform/WebThread.h" |
| 20 #include "wtf/Functional.h" | 21 #include "wtf/Functional.h" |
| 21 #include "wtf/PtrUtil.h" | 22 #include "wtf/PtrUtil.h" |
| 22 #include <memory> | |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 | 25 |
| 26 static const unsigned maxReportedHandlersPendingResolution = 1000; | 26 static const unsigned maxReportedHandlersPendingResolution = 1000; |
| 27 | 27 |
| 28 class RejectedPromises::Message final { | 28 class RejectedPromises::Message final { |
| 29 public: | 29 public: |
| 30 static std::unique_ptr<Message> create( | 30 static std::unique_ptr<Message> create( |
| 31 ScriptState* scriptState, | 31 ScriptState* scriptState, |
| 32 v8::Local<v8::Promise> promise, | 32 v8::Local<v8::Promise> promise, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 init.setReason(ScriptValue(m_scriptState, reason)); | 74 init.setReason(ScriptValue(m_scriptState, reason)); |
| 75 init.setCancelable(true); | 75 init.setCancelable(true); |
| 76 PromiseRejectionEvent* event = PromiseRejectionEvent::create( | 76 PromiseRejectionEvent* event = PromiseRejectionEvent::create( |
| 77 m_scriptState, EventTypeNames::unhandledrejection, init); | 77 m_scriptState, EventTypeNames::unhandledrejection, init); |
| 78 // Log to console if event was not canceled. | 78 // Log to console if event was not canceled. |
| 79 m_shouldLogToConsole = | 79 m_shouldLogToConsole = |
| 80 target->dispatchEvent(event) == DispatchEventResult::NotCanceled; | 80 target->dispatchEvent(event) == DispatchEventResult::NotCanceled; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (m_shouldLogToConsole) { | 83 if (m_shouldLogToConsole) { |
| 84 V8PerIsolateData* data = V8PerIsolateData::from(m_scriptState->isolate()); | 84 ThreadDebugger* debugger = ThreadDebugger::from(m_scriptState->isolate()); |
| 85 if (data->threadDebugger()) | 85 if (debugger) { |
| 86 m_promiseRejectionId = data->threadDebugger()->promiseRejected( | 86 m_promiseRejectionId = |
| 87 m_scriptState->context(), m_errorMessage, reason, | 87 debugger->promiseRejected(m_scriptState->context(), m_errorMessage, |
| 88 std::move(m_location)); | 88 reason, std::move(m_location)); |
| 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 m_location.reset(); | 92 m_location.reset(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void revoke() { | 95 void revoke() { |
| 95 ExecutionContext* executionContext = m_scriptState->getExecutionContext(); | 96 ExecutionContext* executionContext = m_scriptState->getExecutionContext(); |
| 96 if (!executionContext) | 97 if (!executionContext) |
| 97 return; | 98 return; |
| 98 | 99 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 m_corsStatus)) { | 111 m_corsStatus)) { |
| 111 PromiseRejectionEventInit init; | 112 PromiseRejectionEventInit init; |
| 112 init.setPromise(ScriptPromise(m_scriptState, value)); | 113 init.setPromise(ScriptPromise(m_scriptState, value)); |
| 113 init.setReason(ScriptValue(m_scriptState, reason)); | 114 init.setReason(ScriptValue(m_scriptState, reason)); |
| 114 PromiseRejectionEvent* event = PromiseRejectionEvent::create( | 115 PromiseRejectionEvent* event = PromiseRejectionEvent::create( |
| 115 m_scriptState, EventTypeNames::rejectionhandled, init); | 116 m_scriptState, EventTypeNames::rejectionhandled, init); |
| 116 target->dispatchEvent(event); | 117 target->dispatchEvent(event); |
| 117 } | 118 } |
| 118 | 119 |
| 119 if (m_shouldLogToConsole && m_promiseRejectionId) { | 120 if (m_shouldLogToConsole && m_promiseRejectionId) { |
| 120 V8PerIsolateData* data = V8PerIsolateData::from(m_scriptState->isolate()); | 121 ThreadDebugger* debugger = ThreadDebugger::from(m_scriptState->isolate()); |
| 121 if (data->threadDebugger()) | 122 if (debugger) { |
| 122 data->threadDebugger()->promiseRejectionRevoked( | 123 debugger->promiseRejectionRevoked(m_scriptState->context(), |
| 123 m_scriptState->context(), m_promiseRejectionId); | 124 m_promiseRejectionId); |
| 125 } |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 void makePromiseWeak() { | 129 void makePromiseWeak() { |
| 128 ASSERT(!m_promise.isEmpty() && !m_promise.isWeak()); | 130 ASSERT(!m_promise.isEmpty() && !m_promise.isWeak()); |
| 129 m_promise.setWeak(this, &Message::didCollectPromise); | 131 m_promise.setWeak(this, &Message::didCollectPromise); |
| 130 m_exception.setWeak(this, &Message::didCollectException); | 132 m_exception.setWeak(this, &Message::didCollectException); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void makePromiseStrong() { | 135 void makePromiseStrong() { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 m_reportedAsErrors.remove(0, maxReportedHandlersPendingResolution / 10); | 278 m_reportedAsErrors.remove(0, maxReportedHandlersPendingResolution / 10); |
| 277 } | 279 } |
| 278 } | 280 } |
| 279 } | 281 } |
| 280 | 282 |
| 281 void RejectedPromises::revokeNow(std::unique_ptr<Message> message) { | 283 void RejectedPromises::revokeNow(std::unique_ptr<Message> message) { |
| 282 message->revoke(); | 284 message->revoke(); |
| 283 } | 285 } |
| 284 | 286 |
| 285 } // namespace blink | 287 } // namespace blink |
| OLD | NEW |