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/RejectedPromises.cpp

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 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 "bindings/core/v8/ScopedPersistent.h" 7 #include "bindings/core/v8/ScopedPersistent.h"
8 #include "bindings/core/v8/ScriptCallStack.h" 8 #include "bindings/core/v8/ScriptCallStack.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (value.IsEmpty() || !value->IsPromise()) 62 if (value.IsEmpty() || !value->IsPromise())
63 return; 63 return;
64 ASSERT(!hasHandler()); 64 ASSERT(!hasHandler());
65 65
66 EventTarget* target = executionContext->errorEventTarget(); 66 EventTarget* target = executionContext->errorEventTarget();
67 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) { 67 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) {
68 PromiseRejectionEventInit init; 68 PromiseRejectionEventInit init;
69 init.setPromise(ScriptPromise(m_scriptState, value)); 69 init.setPromise(ScriptPromise(m_scriptState, value));
70 init.setReason(ScriptValue(m_scriptState, reason)); 70 init.setReason(ScriptValue(m_scriptState, reason));
71 init.setCancelable(true); 71 init.setCancelable(true);
72 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(m_scriptState, EventTypeNames::unhandledrejection, init); 72 RawPtr<PromiseRejectionEvent> event = PromiseRejectionEvent::create( m_scriptState, EventTypeNames::unhandledrejection, init);
73 // Log to console if event was not preventDefault()'ed. 73 // Log to console if event was not preventDefault()'ed.
74 m_shouldLogToConsole = target->dispatchEvent(event); 74 m_shouldLogToConsole = target->dispatchEvent(event);
75 } 75 }
76 76
77 if (m_shouldLogToConsole) { 77 if (m_shouldLogToConsole) {
78 const String errorMessage = "Uncaught (in promise)"; 78 const String errorMessage = "Uncaught (in promise)";
79 Vector<ScriptValue> args; 79 Vector<ScriptValue> args;
80 args.append(ScriptValue(m_scriptState, v8String(m_scriptState->isola te(), errorMessage))); 80 args.append(ScriptValue(m_scriptState, v8String(m_scriptState->isola te(), errorMessage)));
81 args.append(ScriptValue(m_scriptState, reason)); 81 args.append(ScriptValue(m_scriptState, reason));
82 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::cre ate(m_scriptState, args); 82 RawPtr<ScriptArguments> arguments = ScriptArguments::create(m_script State, args);
83 83
84 String embedderErrorMessage = m_errorMessage; 84 String embedderErrorMessage = m_errorMessage;
85 if (embedderErrorMessage.isEmpty()) 85 if (embedderErrorMessage.isEmpty())
86 embedderErrorMessage = errorMessage; 86 embedderErrorMessage = errorMessage;
87 else if (embedderErrorMessage.startsWith("Uncaught ")) 87 else if (embedderErrorMessage.startsWith("Uncaught "))
88 embedderErrorMessage.insert(" (in promise)", 8); 88 embedderErrorMessage.insert(" (in promise)", 8);
89 89
90 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, ErrorMessageLevel, embedderErrorMessage, m_resourceName, m_lineNumber, m_columnNumber); 90 RawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMes sageSource, ErrorMessageLevel, embedderErrorMessage, m_resourceName, m_lineNumbe r, m_columnNumber);
91 consoleMessage->setScriptArguments(arguments); 91 consoleMessage->setScriptArguments(arguments);
92 consoleMessage->setCallStack(m_callStack); 92 consoleMessage->setCallStack(m_callStack);
93 consoleMessage->setScriptId(m_scriptId); 93 consoleMessage->setScriptId(m_scriptId);
94 m_consoleMessageId = consoleMessage->assignMessageId(); 94 m_consoleMessageId = consoleMessage->assignMessageId();
95 executionContext->addConsoleMessage(consoleMessage.release()); 95 executionContext->addConsoleMessage(consoleMessage.release());
96 } 96 }
97 97
98 m_callStack.clear(); 98 m_callStack.clear();
99 } 99 }
100 100
101 void revoke() 101 void revoke()
102 { 102 {
103 ExecutionContext* executionContext = m_scriptState->executionContext(); 103 ExecutionContext* executionContext = m_scriptState->executionContext();
104 if (!executionContext) 104 if (!executionContext)
105 return; 105 return;
106 106
107 ScriptState::Scope scope(m_scriptState); 107 ScriptState::Scope scope(m_scriptState);
108 v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate() ); 108 v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate() );
109 v8::Local<v8::Value> reason = m_exception.newLocal(m_scriptState->isolat e()); 109 v8::Local<v8::Value> reason = m_exception.newLocal(m_scriptState->isolat e());
110 // Either collected or https://crbug.com/450330 110 // Either collected or https://crbug.com/450330
111 if (value.IsEmpty() || !value->IsPromise()) 111 if (value.IsEmpty() || !value->IsPromise())
112 return; 112 return;
113 113
114 EventTarget* target = executionContext->errorEventTarget(); 114 EventTarget* target = executionContext->errorEventTarget();
115 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) { 115 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) {
116 PromiseRejectionEventInit init; 116 PromiseRejectionEventInit init;
117 init.setPromise(ScriptPromise(m_scriptState, value)); 117 init.setPromise(ScriptPromise(m_scriptState, value));
118 init.setReason(ScriptValue(m_scriptState, reason)); 118 init.setReason(ScriptValue(m_scriptState, reason));
119 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(m_scriptState, EventTypeNames::rejectionhandled, init); 119 RawPtr<PromiseRejectionEvent> event = PromiseRejectionEvent::create( m_scriptState, EventTypeNames::rejectionhandled, init);
120 target->dispatchEvent(event); 120 target->dispatchEvent(event);
121 } 121 }
122 122
123 if (m_shouldLogToConsole) { 123 if (m_shouldLogToConsole) {
124 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected pro mise"); 124 RawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMes sageSource, RevokedErrorMessageLevel, "Handler added to rejected promise");
125 consoleMessage->setRelatedMessageId(m_consoleMessageId); 125 consoleMessage->setRelatedMessageId(m_consoleMessageId);
126 executionContext->addConsoleMessage(consoleMessage.release()); 126 executionContext->addConsoleMessage(consoleMessage.release());
127 } 127 }
128 } 128 }
129 129
130 void makePromiseWeak() 130 void makePromiseWeak()
131 { 131 {
132 ASSERT(!m_promise.isEmpty() && !m_promise.isWeak()); 132 ASSERT(!m_promise.isEmpty() && !m_promise.isWeak());
133 m_promise.setWeak(this, &Message::didCollectPromise); 133 m_promise.setWeak(this, &Message::didCollectPromise);
134 m_exception.setWeak(this, &Message::didCollectException); 134 m_exception.setWeak(this, &Message::didCollectException);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 m_queue.remove(it); 214 m_queue.remove(it);
215 return; 215 return;
216 } 216 }
217 } 217 }
218 218
219 // Then look it up in the reported errors. 219 // Then look it up in the reported errors.
220 for (size_t i = 0; i < m_reportedAsErrors.size(); ++i) { 220 for (size_t i = 0; i < m_reportedAsErrors.size(); ++i) {
221 auto& message = m_reportedAsErrors.at(i); 221 auto& message = m_reportedAsErrors.at(i);
222 if (!message->isCollected() && message->hasPromise(data.GetPromise())) { 222 if (!message->isCollected() && message->hasPromise(data.GetPromise())) {
223 message->makePromiseStrong(); 223 message->makePromiseStrong();
224 Platform::current()->currentThread()->scheduler()->timerTaskRunner() ->postTask(BLINK_FROM_HERE, new Task(bind(&RejectedPromises::revokeNow, PassRefP trWillBeRawPtr<RejectedPromises>(this), message.release()))); 224 Platform::current()->currentThread()->scheduler()->timerTaskRunner() ->postTask(BLINK_FROM_HERE, new Task(bind(&RejectedPromises::revokeNow, RawPtr<R ejectedPromises>(this), message.release())));
225 m_reportedAsErrors.remove(i); 225 m_reportedAsErrors.remove(i);
226 return; 226 return;
227 } 227 }
228 } 228 }
229 } 229 }
230 230
231 PassOwnPtr<RejectedPromises::MessageQueue> RejectedPromises::createMessageQueue( ) 231 PassOwnPtr<RejectedPromises::MessageQueue> RejectedPromises::createMessageQueue( )
232 { 232 {
233 return adoptPtr(new MessageQueue()); 233 return adoptPtr(new MessageQueue());
234 } 234 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 } 277 }
278 } 278 }
279 279
280 void RejectedPromises::revokeNow(PassOwnPtr<Message> message) 280 void RejectedPromises::revokeNow(PassOwnPtr<Message> message)
281 { 281 {
282 message->revoke(); 282 message->revoke();
283 } 283 }
284 284
285 } // namespace blink 285 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698