Revert of Catch uncaught promise rejections from V8 and log to console....

Revert of Catch uncaught promise rejections from V8 and log to console. (patchset #13 id:520001 of https://codereview.chromium.org/625943002/)

Reason for revert:
This is likely the cause of breakage for these browser_tests:
ManageProfileUITest.Create_NameUpdateOnAvatarSelected
ManageProfileUITest.Create_NoNameUpdateOnAvatarSelectedAfterRevert
ManageProfileUITest.Create_NoNameUpdateOnAvatarSelectedAfterEdit


https://build.chromium.org/p/chromium.mac/builders/Mac10.6%20Tests%20%281%29/builds/56670

Original issue's description:
> Catch uncaught promise rejections from V8 and log to console.
> 
> Print error messages to DevTools console for rejected Promises that are unhandled by the platform end-of-turn.
> 
> BUG=393913
> R=pfeldman, yurys
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=183464
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=183598

TBR=pfeldman@chromium.org,yurys@chromium.org,jl@opera.com,aandrey@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=393913

Review URL: https://codereview.chromium.org/650203003

git-svn-id: svn://svn.chromium.org/blink/trunk@183611 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e3b5ee7d
...@@ -24,7 +24,7 @@ function runTests() { ...@@ -24,7 +24,7 @@ function runTests() {
document.fonts.addEventListener('loadingerror', onLoadingError); document.fonts.addEventListener('loadingerror', onLoadingError);
document.fonts.ready().then(finish); document.fonts.ready().then(finish);
document.fonts.load('10px TestFont', 'abc').catch(function() {}); document.fonts.load('10px TestFont', 'abc');
} }
var event; var event;
......
...@@ -34,7 +34,7 @@ function runTests() { ...@@ -34,7 +34,7 @@ function runTests() {
document.fonts.addEventListener('loadingerror', onLoadingError); document.fonts.addEventListener('loadingerror', onLoadingError);
document.fonts.ready().then(finish); document.fonts.ready().then(finish);
document.fonts.load('10px TestFont1, TestFont2, TestFont3, TestFont4', 'abc').catch(function() {}); document.fonts.load('10px TestFont1, TestFont2, TestFont3, TestFont4', 'abc');
} }
var event; var event;
......
...@@ -73,11 +73,6 @@ InspectorTest.fixConsoleViewportDimensions = function(width, height) ...@@ -73,11 +73,6 @@ InspectorTest.fixConsoleViewportDimensions = function(width, height)
} }
InspectorTest.dumpConsoleMessages = function(printOriginatingCommand, dumpClassNames, formatter) InspectorTest.dumpConsoleMessages = function(printOriginatingCommand, dumpClassNames, formatter)
{
InspectorTest.addResults(InspectorTest.dumpConsoleMessagesIntoArray(printOriginatingCommand, dumpClassNames, formatter));
}
InspectorTest.dumpConsoleMessagesIntoArray = function(printOriginatingCommand, dumpClassNames, formatter)
{ {
formatter = formatter || InspectorTest.prepareConsoleMessageText; formatter = formatter || InspectorTest.prepareConsoleMessageText;
var result = []; var result = [];
...@@ -99,21 +94,21 @@ InspectorTest.dumpConsoleMessagesIntoArray = function(printOriginatingCommand, d ...@@ -99,21 +94,21 @@ InspectorTest.dumpConsoleMessagesIntoArray = function(printOriginatingCommand, d
} }
} }
if (InspectorTest.dumpConsoleTableMessage(uiMessage, false, result)) { if (InspectorTest.dumpConsoleTableMessage(uiMessage, false)) {
if (dumpClassNames) if (dumpClassNames)
result.push(classNames.join(" > ")); InspectorTest.addResult(classNames.join(" > "));
} else { } else {
var messageText = formatter(element, message); var messageText = formatter(element, message);
result.push(messageText + (dumpClassNames ? " " + classNames.join(" > ") : "")); InspectorTest.addResult(messageText + (dumpClassNames ? " " + classNames.join(" > ") : ""));
} }
if (printOriginatingCommand && uiMessage.consoleMessage().originatingMessage()) if (printOriginatingCommand && uiMessage.consoleMessage().originatingMessage())
result.push("Originating from: " + uiMessage.consoleMessage().originatingMessage().messageText); InspectorTest.addResult("Originating from: " + uiMessage.consoleMessage().originatingMessage().messageText);
} }
return result; return result;
} }
InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate, results) InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate)
{ {
if (forceInvalidate) if (forceInvalidate)
WebInspector.ConsolePanel._view()._viewport.invalidate(); WebInspector.ConsolePanel._view()._viewport.invalidate();
...@@ -126,7 +121,7 @@ InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate, r ...@@ -126,7 +121,7 @@ InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate, r
for (var i = 0; i < headers.length; i++) for (var i = 0; i < headers.length; i++)
headerLine += headers[i].textContent + " | "; headerLine += headers[i].textContent + " | ";
addResult("HEADER " + headerLine); InspectorTest.addResult("HEADER " + headerLine);
var rows = table.querySelectorAll(".data-container tr"); var rows = table.querySelectorAll(".data-container tr");
...@@ -138,17 +133,8 @@ InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate, r ...@@ -138,17 +133,8 @@ InspectorTest.dumpConsoleTableMessage = function(viewMessage, forceInvalidate, r
rowLine += items[j].textContent + " | "; rowLine += items[j].textContent + " | ";
if (rowLine.trim()) if (rowLine.trim())
addResult("ROW " + rowLine); InspectorTest.addResult("ROW " + rowLine);
}
function addResult(x)
{
if (results)
results.push(x);
else
InspectorTest.addResult(x);
} }
return true; return true;
} }
......
...@@ -255,7 +255,7 @@ function test_login(test, origin, username, password) { ...@@ -255,7 +255,7 @@ function test_login(test, origin, username, password) {
.then(test.step_func(function(frame) { .then(test.step_func(function(frame) {
var channel = new MessageChannel(); var channel = new MessageChannel();
channel.port1.onmessage = test.step_func(function() { channel.port1.onmessage = test.step_func(function() {
unload_iframe(frame).catch(function() {}); unload_iframe(frame);
resolve(); resolve();
}); });
frame.contentWindow.postMessage( frame.contentWindow.postMessage(
......
...@@ -50,11 +50,8 @@ function onload() ...@@ -50,11 +50,8 @@ function onload()
bigmap.set(42, 42); bigmap.set(42, 42);
bigmap.set({foo:"from"}, {foo:"to"}); bigmap.set({foo:"from"}, {foo:"to"});
var p = Promise.reject(-0);
p.catch(function() {});
globals = [ globals = [
p, smb1, smb2, obj, map, weakMap, set, weakSet, Promise.reject(-0), smb1, smb2, obj, map, weakMap, set, weakSet,
mapMap0, mapMap, setSet0, setSet, bigmap mapMap0, mapMap, setSet0, setSet, bigmap
]; ];
......
CONSOLE ERROR: Unhandled promise rejection
CONSOLE ERROR: Unhandled promise rejection
CONSOLE ERROR: Unhandled promise rejection
CONSOLE ERROR: Unhandled promise rejection
Tests that uncaught promise rejections are logged into console.
Unhandled promise rejection Promise
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: onload.err1
Unhandled promise rejection Promise
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: onload.err2
Unhandled promise rejection Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: Error: inspector.err1}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: inspector.err1
Unhandled promise rejection Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: Error: inspector.err2}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: inspector.err2
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function runPromises(source)
{
Promise.reject(new Error(source + ".err1"))
.then()
.then()
.then(); // Last is unhandled.
var reject
var m0 = new Promise(function(res, rej) { reject = rej; });
var m1 = m0.then(function() {});
var m2 = m0.then(function() {});
var m3 = m0.then(function() {});
var m4 = 0;
m0.catch(function() {
m2.catch(function() {
m1.catch(function() {
m4 = m3.then(function() {}); // Unhandled.
});
});
});
reject(new Error(source + ".err2"));
}
function onload()
{
runPromises("onload");
runTest();
}
function test()
{
InspectorTest.addConsoleViewSniffer(addMessage, true);
WebInspector.console.showPromise().then(function() {
InspectorTest.evaluateInPage("runPromises('inspector')");
});
var count = 0;
function addMessage(uiMessage)
{
if (uiMessage.toString().indexOf("inspector.err") !== -1)
++count;
if (count === 2)
InspectorTest.expandConsoleMessages(dump);
}
function dump()
{
// Sort console messages from async Promises to avoid flakiness.
var results = InspectorTest.dumpConsoleMessagesIntoArray(false, false, InspectorTest.textContentWithLineBreaks);
results.sort();
InspectorTest.addResults(results);
InspectorTest.completeTest();
}
}
</script>
</head>
<body onload="onload()">
<p>
Tests that uncaught promise rejections are logged into console.
</p>
</body>
</html>
CONSOLE ERROR: Unhandled promise rejection
CONSOLE ERROR: Unhandled promise rejection
Tests uncaught promise rejections fired during pause.
Set timer for test function.
debugger-uncaught-promise-on-pause.html:10 Console was cleared
Unhandled promise rejection Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: Error: inspector.err1}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: inspector.err1
Unhandled promise rejection Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: Error: inspector.err2}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: Error: inspector.err2
<html>
<head>
<script src="../../../http/tests/inspector/inspector-test.js"></script>
<script src="../../../http/tests/inspector/console-test.js"></script>
<script src="../../../http/tests/inspector/debugger-test.js"></script>
<script>
function testFunction()
{
console.clear();
debugger;
}
function runPromises(source)
{
Promise.reject(new Error(source + ".err1"))
.then()
.then()
.then(); // Last is unhandled.
var reject
var m0 = new Promise(function(res, rej) { reject = rej; });
var m1 = m0.then(function() {});
var m2 = m0.then(function() {});
var m3 = m0.then(function() {});
var m4 = 0;
m0.catch(function() {
m2.catch(function() {
m1.catch(function() {
m4 = m3.then(function() {}); // Unhandled.
});
});
});
reject(new Error(source + ".err2"));
}
function test()
{
InspectorTest.setQuiet(true);
InspectorTest.startDebuggerTest(step1);
function step1()
{
InspectorTest.addConsoleViewSniffer(addMessage, true);
InspectorTest.runTestFunctionAndWaitUntilPaused(didPause);
}
function didPause(callFrames, reason, breakpointIds, asyncStackTrace)
{
InspectorTest.evaluateInPage("runPromises('inspector')", resumeExecution);
}
function resumeExecution()
{
InspectorTest.resumeExecution();
}
var count = 0;
function addMessage(uiMessage)
{
if (uiMessage.toString().indexOf("inspector.err") !== -1)
++count;
if (count === 2)
InspectorTest.expandConsoleMessages(dump);
}
function dump()
{
InspectorTest.dumpConsoleMessages(false, false, InspectorTest.textContentWithLineBreaks);
InspectorTest.completeTest();
}
}
</script>
</head>
<body onload="runTest()">
<p>
Tests uncaught promise rejections fired during pause.
</p>
</body>
</html>
...@@ -18,7 +18,7 @@ function testFunction() ...@@ -18,7 +18,7 @@ function testFunction()
var q = new Promise(function(res, rej) { var q = new Promise(function(res, rej) {
reject = rej; reject = rej;
}); });
q.catch(function() { q.then(function() {
}); });
resolve(42); resolve(42);
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "bindings/core/v8/ScriptCallStackFactory.h" #include "bindings/core/v8/ScriptCallStackFactory.h"
#include "bindings/core/v8/ScriptController.h" #include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/ScriptProfiler.h" #include "bindings/core/v8/ScriptProfiler.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h" #include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMException.h" #include "bindings/core/v8/V8DOMException.h"
#include "bindings/core/v8/V8ErrorEvent.h" #include "bindings/core/v8/V8ErrorEvent.h"
...@@ -46,8 +45,6 @@ ...@@ -46,8 +45,6 @@
#include "core/frame/LocalDOMWindow.h" #include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/frame/csp/ContentSecurityPolicy.h" #include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/inspector/ConsoleMessage.h"
#include "core/inspector/ScriptArguments.h"
#include "core/inspector/ScriptCallStack.h" #include "core/inspector/ScriptCallStack.h"
#include "platform/EventDispatchForbiddenScope.h" #include "platform/EventDispatchForbiddenScope.h"
#include "platform/TraceEvent.h" #include "platform/TraceEvent.h"
...@@ -158,78 +155,6 @@ static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Hand ...@@ -158,78 +155,6 @@ static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Hand
} }
} }
typedef WillBeHeapDeque<ScriptValue> PromiseRejectMessageQueue;
static PromiseRejectMessageQueue& promiseRejectMessageQueue()
{
DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PromiseRejectMessageQueue>, queue, (adoptPtrWillBeNoop(new PromiseRejectMessageQueue())));
return *queue;
}
void V8Initializer::reportRejectedPromises()
{
ASSERT(isMainThread());
PromiseRejectMessageQueue& queue = promiseRejectMessageQueue();
while (!queue.isEmpty()) {
ScriptValue promise = queue.takeFirst();
ScriptState* scriptState = promise.scriptState();
if (!scriptState->contextIsValid())
continue;
ScriptState::Scope scope(scriptState);
ASSERT(!promise.isEmpty());
v8::Handle<v8::Value> value = promise.v8Value();
ASSERT(!value.IsEmpty() && value->IsPromise());
if (v8::Handle<v8::Promise>::Cast(value)->HasHandler())
continue;
ExecutionContext* executionContext = scriptState->executionContext();
if (!executionContext)
continue;
const String errorMessage = "Unhandled promise rejection";
Vector<ScriptValue> args;
args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), errorMessage)));
args.append(promise);
RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(scriptState, args);
RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage, "", 0);
consoleMessage->setScriptArguments(arguments);
executionContext->addConsoleMessage(consoleMessage.release());
}
}
static void promiseRejectHandlerInMainThread(v8::PromiseRejectMessage message)
{
ASSERT(isMainThread());
if (message.GetEvent() != v8::kPromiseRejectWithNoHandler)
return;
// It's possible that promiseRejectHandlerInMainThread() is invoked while we're initializing a window.
// In that half-baked situation, we don't have a valid context nor a valid world,
// so just return immediately.
if (DOMWrapperWorld::windowIsBeingInitialized())
return;
v8::Handle<v8::Promise> promise = message.GetPromise();
// Bail out if called during context initialization.
v8::Isolate* isolate = promise->GetIsolate();
v8::Handle<v8::Context> context = isolate->GetCurrentContext();
if (context.IsEmpty())
return;
v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(context->Global(), context->GetIsolate());
if (global.IsEmpty())
return;
if (!toFrameIfNotDetached(context))
return;
ScriptState* scriptState = ScriptState::from(context);
promiseRejectMessageQueue().append(ScriptValue(scriptState, promise));
}
static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data) static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data)
{ {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
...@@ -293,7 +218,6 @@ void V8Initializer::initializeMainThreadIfNeeded() ...@@ -293,7 +218,6 @@ void V8Initializer::initializeMainThreadIfNeeded()
v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbackInMainThread); v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbackInMainThread);
isolate->SetEventLogger(timerTraceProfilerInMainThread); isolate->SetEventLogger(timerTraceProfilerInMainThread);
isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread);
ScriptProfiler::initialize(); ScriptProfiler::initialize();
} }
......
...@@ -34,7 +34,6 @@ class V8Initializer { ...@@ -34,7 +34,6 @@ class V8Initializer {
public: public:
static void initializeMainThreadIfNeeded(); static void initializeMainThreadIfNeeded();
static void initializeWorker(v8::Isolate*); static void initializeWorker(v8::Isolate*);
static void reportRejectedPromises();
}; };
} // namespace blink } // namespace blink
......
...@@ -78,7 +78,6 @@ public: ...@@ -78,7 +78,6 @@ public:
{ {
Microtask::performCheckpoint(); Microtask::performCheckpoint();
V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate()); V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
V8Initializer::reportRejectedPromises();
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment