46488f71bb
PromiseHooks can be called with a proxy which fails the cast and crashes. This patch changes the runtime functions to explicitly check for a JSPromise. This has the side effect of removing the existing broken support for catch prediction for non native promises. Bug: v8:7398, v8:7190 Change-Id: I66dbe5f9935943a91afb7ee14919bd9248f9f7e4 Reviewed-on: https://chromium-review.googlesource.com/907677 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#51182}
72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
// Copyright 2014 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.
|
|
|
|
|
|
// Test debug events when an exception is thrown inside a Promise,
|
|
// which is caught by a custom promise, which throws a new exception
|
|
// in its reject handler. We expect no Exception debug events.
|
|
|
|
Debug = debug.Debug;
|
|
|
|
var expected_events = 0;
|
|
var log = [];
|
|
|
|
var p = new Promise(function(resolve, reject) {
|
|
log.push("resolve");
|
|
resolve();
|
|
});
|
|
|
|
function MyPromise(resolver) {
|
|
var reject = function() {
|
|
throw new Error("reject"); // event
|
|
};
|
|
var resolve = function() { };
|
|
resolver(resolve, reject);
|
|
};
|
|
|
|
MyPromise.prototype = new Promise(function() {});
|
|
MyPromise.__proto__ = Promise;
|
|
p.constructor = MyPromise;
|
|
|
|
var q = p.then(
|
|
function() {
|
|
log.push("throw caught");
|
|
throw new Error("caught"); // event
|
|
});
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
try {
|
|
if (event == Debug.DebugEvent.Exception) {
|
|
assertUnreachable();
|
|
}
|
|
} catch (e) {
|
|
%AbortJS(e + "\n" + e.stack);
|
|
}
|
|
}
|
|
|
|
Debug.setBreakOnUncaughtException();
|
|
Debug.setListener(listener);
|
|
|
|
log.push("end main");
|
|
|
|
function testDone(iteration) {
|
|
function checkResult() {
|
|
try {
|
|
assertTrue(iteration < 10);
|
|
if (expected_events === 0) {
|
|
assertEquals(["resolve", "end main",
|
|
"throw caught"], log);
|
|
} else {
|
|
testDone(iteration + 1);
|
|
}
|
|
} catch (e) {
|
|
%AbortJS(e + "\n" + e.stack);
|
|
}
|
|
}
|
|
|
|
%EnqueueMicrotask(checkResult);
|
|
}
|
|
|
|
testDone(0);
|