1335b1ec36
With this CL d8 exits with an error code if there is an unhandled promise rejection, e.g. due tue a failed assertion in a promise. Up until now these assertions were just ignored. Bug: v8:10556 Change-Id: I25f20e4be45a2de130562deb15f6a144f0ac976f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2238569 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#68503}
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --ignore-unhandled-promises
|
|
|
|
// Test exercises code paths for catching exceptions in the promise constructor
|
|
// in conjunction with deoptimization.
|
|
|
|
Debug = debug.Debug;
|
|
|
|
var expected_events = 4;
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
try {
|
|
if (event == Debug.DebugEvent.Exception) {
|
|
expected_events--;
|
|
assertTrue(expected_events >= 0);
|
|
assertEquals("uncaught", event_data.exception().message);
|
|
assertTrue(event_data.uncaught());
|
|
// The frame comes from the Promise.reject call
|
|
assertNotNull(/\/\/ EXCEPTION/.exec(event_data.sourceLineText()));
|
|
assertTrue(event_data.uncaught());
|
|
}
|
|
} catch (e) {
|
|
%AbortJS(e + "\n" + e.stack);
|
|
}
|
|
}
|
|
|
|
Debug.setBreakOnException();
|
|
Debug.setListener(listener);
|
|
|
|
function foo(a,b) {
|
|
let P = new Promise((resolve, reject) => { bar(a,b); resolve()})
|
|
return P;
|
|
}
|
|
|
|
function bar(a,b) {
|
|
%DeoptimizeFunction(foo);
|
|
throw new Error("uncaught"); // EXCEPTION
|
|
}
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
foo();
|
|
%PerformMicrotaskCheckpoint();
|
|
|
|
foo();
|
|
%PerformMicrotaskCheckpoint();
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
// bar likely gets inlined into foo.
|
|
foo();
|
|
%PerformMicrotaskCheckpoint();
|
|
|
|
%NeverOptimizeFunction(bar);
|
|
%PrepareFunctionForOptimization(foo);
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
// bar does not get inlined into foo.
|
|
foo();
|
|
%PerformMicrotaskCheckpoint();
|
|
|
|
assertEquals(0, expected_events);
|