Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "bindings/core/v8/RejectedPromises.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ScriptState.h" | |
| 9 #include "bindings/core/v8/ScriptValue.h" | |
| 10 #include "bindings/core/v8/V8Binding.h" | |
| 11 #include "core/dom/ExecutionContext.h" | |
| 12 #include "core/inspector/ConsoleMessage.h" | |
| 13 #include "core/inspector/ScriptArguments.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 class RejectedPromises::Message final : public NoBaseWillBeGarbageCollectedFinal ized<RejectedPromises::Message> { | |
| 18 public: | |
| 19 static PassOwnPtrWillBeRawPtr<Message> create(const ScriptValue& promise, co nst ScriptValue& exception, const String& errorMessage, const String& resourceNa me, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<Scrip tCallStack> callStack) | |
| 20 { | |
| 21 return adoptPtrWillBeNoop(new Message(promise, exception, errorMessage, resourceName, scriptId, lineNumber, columnNumber, callStack)); | |
| 22 } | |
| 23 | |
| 24 void trace(Visitor* visitor) | |
| 25 { | |
| 26 visitor->trace(m_callStack); | |
| 27 } | |
| 28 | |
| 29 private: | |
| 30 Message(const ScriptValue& promise, const ScriptValue& exception, const Stri ng& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) | |
| 31 : m_promise(promise) | |
| 32 , m_exception(exception) | |
| 33 , m_errorMessage(errorMessage) | |
| 34 , m_resourceName(resourceName) | |
| 35 , m_scriptId(scriptId) | |
| 36 , m_lineNumber(lineNumber) | |
| 37 , m_columnNumber(columnNumber) | |
| 38 , m_callStack(callStack) | |
| 39 { | |
| 40 } | |
| 41 | |
| 42 friend class RejectedPromises; | |
| 43 | |
| 44 const ScriptValue m_promise; | |
| 45 const ScriptValue m_exception; | |
| 46 const String m_errorMessage; | |
| 47 const String m_resourceName; | |
| 48 const int m_scriptId; | |
| 49 const int m_lineNumber; | |
| 50 const int m_columnNumber; | |
| 51 const RefPtrWillBeMember<ScriptCallStack> m_callStack; | |
| 52 }; | |
| 53 | |
| 54 RejectedPromises::RejectedPromises() | |
| 55 { | |
| 56 } | |
| 57 | |
| 58 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RejectedPromises); | |
| 59 | |
| 60 void RejectedPromises::trace(Visitor* visitor) | |
| 61 { | |
| 62 visitor->trace(m_queue); | |
| 63 } | |
| 64 | |
| 65 void RejectedPromises::add(ScriptState* scriptState, v8::PromiseRejectMessage da ta, const String& errorMessage, const String& resourceName, int scriptId, int li neNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) | |
| 66 { | |
| 67 v8::Handle<v8::Promise> promise = data.GetPromise(); | |
| 68 OwnPtrWillBeRawPtr<Message> message = Message::create(ScriptValue(scriptStat e, promise), ScriptValue(scriptState, data.GetValue()), errorMessage, resourceNa me, scriptId, lineNumber, columnNumber, callStack); | |
| 69 | |
| 70 m_queue.append(message.release()); | |
| 71 } | |
| 72 | |
| 73 void RejectedPromises::dispose() | |
|
haraken
2015/02/08 01:53:54
Who calls dispose() when the main thread shuts dow
sof
2015/02/08 06:57:39
Like on trunk, no one drains it should there be an
| |
| 74 { | |
| 75 processQueue(); | |
| 76 } | |
| 77 | |
| 78 void RejectedPromises::processQueue() | |
| 79 { | |
| 80 while (!m_queue.isEmpty()) { | |
| 81 OwnPtrWillBeRawPtr<Message> message = m_queue.takeFirst(); | |
| 82 ScriptState* scriptState = message->m_promise.scriptState(); | |
| 83 if (!scriptState->contextIsValid()) | |
| 84 continue; | |
| 85 // If execution termination has been triggered, quietly bail out. | |
| 86 if (v8::V8::IsExecutionTerminating(scriptState->isolate())) | |
| 87 continue; | |
| 88 ExecutionContext* executionContext = scriptState->executionContext(); | |
| 89 if (!executionContext) | |
| 90 continue; | |
| 91 | |
| 92 ScriptState::Scope scope(scriptState); | |
| 93 | |
| 94 ASSERT(!message->m_promise.isEmpty()); | |
| 95 v8::Handle<v8::Value> value = message->m_promise.v8Value(); | |
| 96 ASSERT(!value.IsEmpty() && value->IsPromise()); | |
| 97 if (v8::Handle<v8::Promise>::Cast(value)->HasHandler()) | |
| 98 continue; | |
| 99 | |
| 100 const String errorMessage = "Uncaught (in promise)"; | |
| 101 Vector<ScriptValue> args; | |
| 102 args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), er rorMessage))); | |
| 103 args.append(message->m_exception); | |
| 104 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create( scriptState, args); | |
| 105 | |
| 106 String embedderErrorMessage = message->m_errorMessage; | |
| 107 if (embedderErrorMessage.isEmpty()) | |
| 108 embedderErrorMessage = errorMessage; | |
| 109 else if (embedderErrorMessage.startsWith("Uncaught ")) | |
| 110 embedderErrorMessage.insert(" (in promise)", 8); | |
| 111 | |
| 112 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(JSMessageSource, ErrorMessageLevel, embedderErrorMessage, message->m_resource Name, message->m_lineNumber, message->m_columnNumber); | |
| 113 consoleMessage->setScriptArguments(arguments); | |
| 114 consoleMessage->setCallStack(message->m_callStack); | |
| 115 consoleMessage->setScriptId(message->m_scriptId); | |
| 116 executionContext->addConsoleMessage(consoleMessage.release()); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 } // namespace blink | |
| OLD | NEW |