Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,65 @@
// 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.
var Debug = debug.Debug;
var listenerComplete = false;
var exception = null;
var count = 0;
var log = [];
var done = false;
function LogX(x) {
var stored_count = count;
return function() {
log.push(`[${stored_count}] ${x}`);
};
}
function DebuggerStatement() {
log.push(`[${count}] debugger`);
if (count++ < 3) {
debugger;
}
}
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var p = Promise.resolve();
var q = p.then(LogX("then 1"));
p.then(LogX("then 2"));
q.then(LogX("then 3"));
q.then(DebuggerStatement);
var r = q.then(() => { throw 1; });
r.catch(LogX("catch"));
listenerComplete = true;
} catch (e) {
exception = e;
print(e, e.stack);
quit(1);
};
};
// Add the debug event listener.
Debug.setListener(listener);
DebuggerStatement();
LogX("start")();
// Make sure that the debug event listener was invoked.
assertTrue(listenerComplete);
%PerformMicrotaskCheckpoint();
var expectation =
[ "[0] debugger", "[1] start", "[1] then 1",
"[1] then 2", "[1] then 3", "[1] debugger",
"[2] then 1", "[2] then 2", "[1] catch",
"[2] then 3", "[2] debugger", "[3] then 1",
"[3] then 2", "[2] catch", "[3] then 3",
"[3] debugger", "[3] catch",
];
assertEquals(expectation, log);

View File

@ -0,0 +1,39 @@
// Copyright 2015 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 we only listen to uncaught exceptions and a
// Promise p3 created by Promise.all has a catch handler, and is rejected
// because one of the Promises p2 passed to Promise.all is rejected. We
// expect no Exception debug event to be triggered, since p3 and by
// extension p2 have a catch handler.
var Debug = debug.Debug;
var expected_events = 2;
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
throw new Error("caught");
});
p2.name = "p2";
var p3 = Promise.all([p2]);
p3.name = "p3";
p3.catch(function(e) {});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception)
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,68 @@
// Copyright 2015 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 debug events when we only listen to uncaught exceptions and a
// Promise p3 created by Promise.all has no catch handler, and is rejected
// because one of the Promises p2 passed to Promise.all is rejected.
// We expect one event for p2; the system recognizes the rejection of p3
// to be redundant and based on the rejection of p2 and does not trigger
// an additional rejection.
var Debug = debug.Debug;
var expected_events = 1;
var log = [];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught", event_data.exception().message);
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
assertTrue(event_data.uncaught());
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.all([p2]);
p3.name = "p3";
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["end main", "throw"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,37 @@
// Copyright 2020 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 we only listen to uncaught exceptions and a
// Promise p3 created by Promise.any has a catch handler, and is rejected
// because the Promise p2 passed to Promise.any is rejected. We
// expect no Exception debug event to be triggered, since p3 and by
// extension p2 have a catch handler.
let Debug = debug.Debug;
let expected_events = 2;
let p1 = Promise.resolve();
p1.name = "p1";
let p2 = p1.then(function() {
throw new Error("caught");
});
p2.name = "p2";
let p3 = Promise.any([p2]);
p3.name = "p3";
p3.catch(function(e) {});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception)
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,67 @@
// Copyright 2015 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 debug events when we only listen to uncaught exceptions and a
// Promise p3 created by Promise.any has no catch handler, and is rejected
// because the Promise p2 passed to Promise.any is rejected.
// We expect one event for p2; the system recognizes the rejection of p3
// to be redundant and based on the rejection of p2 and does not trigger
// an additional rejection.
let Debug = debug.Debug;
let expected_events = 1;
let log = [];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught", event_data.exception().message);
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
assertTrue(event_data.uncaught());
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
let p1 = Promise.resolve();
p1.name = "p1";
let p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
let p3 = Promise.any([p2]);
p3.name = "p3";
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["end main", "throw"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,39 @@
// Copyright 2015 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 we only listen to uncaught exceptions and a
// Promise p3 created by Promise.race has a catch handler, and is rejected
// because one of the Promises p2 passed to Promise.all is rejected. We
// expect no Exception debug event to be triggered, since p3 and by
// extension p2 have a catch handler.
var Debug = debug.Debug;
var expected_events = 2;
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
throw new Error("caught");
});
p2.name = "p2";
var p3 = Promise.all([p2]);
p3.name = "p3";
p3.catch(function(e) {});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception)
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,68 @@
// Copyright 2015 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 debug events when we only listen to uncaught exceptions and a
// Promise p3 created by Promise.race has no catch handler, and is rejected
// because one of the Promises p2 passed to Promise.race is rejected.
// We expect one event for p2; the system recognizes the rejection of p3
// to be redundant and based on the rejection of p2 and does not trigger
// an additional rejection.
var Debug = debug.Debug;
var expected_events = 1;
var log = [];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught", event_data.exception().message);
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
assertTrue(event_data.uncaught());
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p1 = Promise.resolve();
p1.name = "p1";
var p2 = p1.then(function() {
log.push("throw");
throw new Error("uncaught"); // event
});
p2.name = "p2";
var p3 = Promise.race([p2]);
p3.name = "p3";
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["end main", "throw"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,43 @@
// 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 debug events when we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
class P extends Promise {
constructor(...args) {
super(...args);
return new Proxy(this, {
get(target, property, receiver) {
if (property in target) {
return Reflect.get(target, property, receiver);
} else {
return (...args) =>
new Promise((resolve, reject) =>
target.then(v => resolve(v[property](...args)))
.catch(reject)
);
}
}
});
}
}
P.resolve({doStuff(){log.push(1)}}).doStuff()
function listener(event, exec_state, event_data, data) {}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
%PerformMicrotaskCheckpoint();

View File

@ -0,0 +1,16 @@
// 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 reentry of special try catch for Promises.
Debug = debug.Debug;
Debug.setBreakOnUncaughtException();
Debug.setListener(function(event, exec_state, event_data, data) { });
var p = new Promise(function(resolve, reject) { resolve(); });
var q = p.then(function() {
new Promise(function(resolve, reject) { resolve(); });
});

View File

@ -0,0 +1,36 @@
// 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 we listen to uncaught exceptions and
// the Promise is rejected in a chained closure after it has been resolved.
// We expect no Exception debug event to be triggered.
Debug = debug.Debug;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve(reject);
});
var q = p.then(
function(value) {
assertEquals(["resolve", "end main"], log);
value(new Error("reject"));
});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
Debug.setListener(listener);
log.push("end main");

View File

@ -0,0 +1,67 @@
// 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 we listen to all exceptions and
// there is a catch handler for the to-be-rejected Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var log = [];
var expected_events = 1;
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function(value) {
log.push("reject");
return Promise.reject(new Error("reject"));
});
q.catch(
function(e) {
assertEquals("reject", e.message);
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("reject", event_data.exception().message);
assertFalse(event_data.uncaught());
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
Debug.setListener(listener);
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["resolve", "end main", "reject"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,75 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// there is only a default reject handler for the to-be-rejected Promise.
// We expect only one debug event: when the first Promise is rejected
// and only has default reject handlers. No event is triggered when
// simply forwarding the rejection with .then's default handler.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var resolve, reject;
var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; });
var p1 = p0.then(function() {
log.push("p0.then");
return Promise.reject(new Error("123"));
});
var p2 = p1.then(function() {
log.push("p1.then");
});
var q = new Promise(function(res, rej) {
log.push("resolve q");
res();
});
q.then(function() {
log.push("resolve p");
resolve();
})
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertTrue(event_data.uncaught());
// p1 is rejected, uncaught, with the error from the Promise.reject line
assertNotNull(event_data.sourceLineText().match("Promise.reject"));
}
} 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 q", "end main", "resolve p", "p0.then"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,33 @@
// 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 we only listen to uncaught exceptions, the Promise
// is rejected, and a catch handler is installed right before the rejection.
// We expect no debug event to be triggered.
Debug = debug.Debug;
var p = new Promise(function(resolve, reject) {
resolve();
});
var q = p.then(
function() {
q.catch(function(e) {
assertEquals("caught", e.message);
});
return Promise.reject(Error("caught"));
});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,35 @@
// 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 we only listen to uncaught exceptions and
// there is a catch handler for the to-be-rejected Promise.
// We expect no debug event to be triggered.
Debug = debug.Debug;
var p = new Promise(function(resolve, reject) {
resolve();
});
var q = p.then(
function() {
return Promise.reject(Error("caught reject"));
});
q.catch(
function(e) {
assertEquals("caught reject", e.message);
});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,65 @@
// 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);

View File

@ -0,0 +1,38 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// the Promise is rejected in the Promise constructor.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var steps = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
steps++;
assertEquals("uncaught", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} catch (e) {
exception = e;
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
reject(new Error("uncaught")); // event
});
assertEquals(1, steps);
assertNull(exception);

View File

@ -0,0 +1,64 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we listen to all exceptions and
// there is a catch handler for the to-be-rejected Promise.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("reject");
return Promise.reject(new Error("uncaught reject"));
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught reject", event_data.exception().message);
assertTrue(event_data.uncaught());
// The frame comes from the Promise.reject call
assertNotNull(/Promise\.reject/.exec(event_data.sourceLineText()));
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
Debug.setListener(listener);
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["resolve", "end main", "reject"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,71 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// there is a catch handler for the to-be-rejected Promise.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var reject_closure;
var p = new Promise(function(resolve, reject) {
log.push("postpone p");
reject_closure = reject;
});
var q = new Promise(function(resolve, reject) {
log.push("resolve q");
resolve();
});
q.then(function() {
log.push("reject p");
reject_closure(new Error("uncaught reject p")); // event
})
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught reject p", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} 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(["postpone p", "resolve q", "end main", "reject p"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,64 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// there is no catch handler for the to-be-rejected Promise.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("reject");
return Promise.reject(Error("uncaught reject")); // event
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught reject", event_data.exception().message);
assertTrue(event_data.uncaught());
// The JavaScript frame is from the Promise rejection
assertTrue(/Promise\.reject/.test(event_data.sourceLineText()));
}
} 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", "reject"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,73 @@
// 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 a Promise is rejected, which is caught by a custom
// promise, which has a number for reject closure. We expect an Exception debug
// events trying to call the invalid reject closure.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
function MyPromise(resolver) {
var reject = 1;
var resolve = function() { };
log.push("construct");
resolver(resolve, reject);
};
MyPromise.prototype = new Promise(function() {});
p.constructor = MyPromise;
var q = p.then(
function() {
log.push("reject caught");
return Promise.reject(new Error("caught"));
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("number is not a function", event_data.exception().message);
// All of the frames on the stack are from native Javascript.
assertEquals(0, exec_state.frameCount());
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["resolve", "construct", "end main", "reject caught"],
log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);
log.push("end main");

View File

@ -0,0 +1,83 @@
// 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 a Promise is rejected, which is caught by a
// custom promise, which throws a new exception in its reject handler.
// We expect two Exception debug events:
// 1) when promise q is rejected.
// 2) when the custom reject closure in MyPromise throws an exception.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
function MyPromise(resolver) {
var reject = function() {
log.push("throw in reject");
throw new Error("reject"); // event
};
var resolve = function() { };
log.push("construct");
resolver(resolve, reject);
};
MyPromise.prototype = new Promise(function() {});
p.constructor = MyPromise;
var q = p.then(
function() {
log.push("reject caught");
return Promise.reject(new Error("caught"));
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("reject", event_data.exception().message);
// Assert that the debug event is triggered at the throw site.
assertTrue(
exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} catch (e) {
// Signal a failure with exit code 1. This is necessary since the
// debugger swallows exceptions and we expect the chained function
// and this listener to be executed after the main script is finished.
print("Unexpected exception: " + e + "\n" + e.stack);
quit(1);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
log.push("end main");
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["resolve", "construct", "end main",
"reject caught", "throw in reject"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,73 @@
// 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 a Promise is rejected, which is caught by a custom
// promise, which has undefined for reject closure. We expect an Exception
// debug even calling the (undefined) custom rejected closure.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
function MyPromise(resolver) {
var reject = undefined;
var resolve = function() { };
log.push("construct");
resolver(resolve, reject);
};
MyPromise.prototype = new Promise(function() {});
p.constructor = MyPromise;
var q = p.then(
function() {
log.push("reject caught");
return Promise.reject(new Error("caught"));
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("caught", event_data.exception().message);
// All of the frames on the stack are from native Javascript.
assertEquals(0, exec_state.frameCount());
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
function testDone(iteration) {
function checkResult() {
try {
assertTrue(iteration < 10);
if (expected_events === 0) {
assertEquals(["resolve", "construct", "end main", "reject caught"],
log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);
log.push("end main");

View File

@ -0,0 +1,46 @@
// Copyright 2015 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.
var Debug = debug.Debug;
var exception = null;
var breaks = [];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
breaks.push(exec_state.frame(0).sourceLineText().trimLeft());
exec_state.prepareStep(Debug.StepAction.StepInto);
} catch (e) {
exception = e;
}
}
Debug.setListener(listener);
function resolver(resolve, reject) {
print(1);
print(2);
print(3);
resolve();
}
debugger;
var p = new Promise(resolver);
Debug.setListener(null);
var expected_breaks = [
"debugger;",
"var p = new Promise(resolver);",
"print(1);",
"print(2);",
"print(3);",
"resolve();",
"}",
"Debug.setListener(null);"
];
assertEquals(expected_breaks, breaks);
assertNull(exception);

View File

@ -0,0 +1,60 @@
// Copyright 2015 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: --noalways-turbofan
// Tests stepping into through Promises.
Debug = debug.Debug
var exception = null;
var break_count = 0;
const expected_breaks = 9;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
var source = exec_state.frame(0).sourceLineText();
print("paused at: " + source);
assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
"Unexpected pause at: " + source + "\n" +
"Expected: // Break " + break_count + ".");
++break_count;
if (break_count !== expected_breaks) {
exec_state.prepareStep(Debug.StepAction.StepInto);
}
}
} catch(e) {
exception = e;
print(e, e.stack);
}
};
Debug.setListener(listener);
Promise.resolve(42)
.then(
function f0() {
debugger; // Break 0.
} // Break 1.
)
.then(callback)
.then(callback.bind(null))
.then(Object)
.then(callback.bind(null).bind(null))
.then(finalize)
.catch(function(err) {
%AbortJS("FAIL: " + err);
});
function callback(x) {
return x // Break 2. // Break 4. // Break 6.
; // Break 3. // Break 5. // Break 7.
}
function finalize() {
assertNull(exception); // Break 8.
assertEquals(expected_breaks, break_count);
Debug.setListener(null);
}

View File

@ -0,0 +1,66 @@
// 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 we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("throw");
throw new Error("caught");
});
q.catch(
function(e) {
assertEquals("caught", e.message);
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("caught", event_data.exception().message);
assertFalse(event_data.uncaught());
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
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"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,76 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// there is only a default reject handler for the to-be-rejected Promise.
// We expect only one debug event: when the first Promise is rejected
// and only has default reject handlers. No event is triggered when
// simply forwarding the rejection with .then's default handler.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var resolve, reject;
var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; });
var p1 = p0.then(function() {
log.push("p0.then");
throw new Error("123"); // event
});
var p2 = p1.then(function() {
log.push("p1.then");
});
var q = new Promise(function(res, rej) {
log.push("resolve q");
res();
});
q.then(function() {
log.push("resolve p");
resolve();
})
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertTrue(event_data.uncaught());
// p1 is rejected, uncaught except for its default reject handler.
assertTrue(
exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} 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 q", "end main", "resolve p", "p0.then"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,33 @@
// 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 we only listen to uncaught exceptions, the Promise
// throws, and a catch handler is installed right before throwing.
// We expect no debug event to be triggered.
Debug = debug.Debug;
var p = new Promise(function(resolve, reject) {
resolve();
});
var q = p.then(
function() {
q.catch(function(e) {
assertEquals("caught", e.message);
});
throw new Error("caught");
});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,35 @@
// 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 we only listen to uncaught exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect no debug event to be triggered.
Debug = debug.Debug;
var p = new Promise(function(resolve, reject) {
resolve();
});
var q = p.then(
function() {
throw new Error("caught throw");
});
q.catch(
function(e) {
assertEquals("caught throw", e.message);
});
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,41 @@
// 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 we only listen to uncaught exceptions and
// there is a catch handler for the to-be-rejected Promise.
// We expect no Exception debug events, since the default reject handler passes
// the rejection on to a user-defined reject handler.
Debug = debug.Debug;
var resolve, reject;
var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; });
var p1 = p0.then(function() {
throw new Error();
});
var p2 = p1.then(function() { });
var p3 = p2.catch(function() { });
var q = new Promise(function(res, rej) {
res();
});
q.then(function() {
resolve();
})
function listener(event, exec_state, event_data, data) {
try {
assertTrue(event != Debug.DebugEvent.Exception);
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

View File

@ -0,0 +1,70 @@
// Copyright 2016 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 we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise, first
// caught by a try-finally, and immediately rethrown.
// We expect a normal Exception debug event to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("throw");
try {
throw new Error("caught");
} finally {
}
});
q.catch(
function(e) {
assertEquals("caught", e.message);
});
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("caught", event_data.exception().message);
assertFalse(event_data.uncaught());
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
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"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,39 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// an exception is thrown in the Promise constructor.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var step = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
assertEquals(0, step);
assertEquals("uncaught", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
step++;
}
} catch (e) {
exception = e;
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
throw new Error("uncaught"); // event
});
assertEquals(1, step);
assertNull(exception);

View File

@ -0,0 +1,65 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we listen to all exceptions and
// there is no catch handler for the exception thrown in a Promise.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("throw");
throw new Error("uncaught"); // event
});
function listener(event, exec_state, event_data, data) {
try {
// Ignore exceptions during startup in stress runs.
if (event == Debug.DebugEvent.Exception) {
expected_events--;
assertTrue(expected_events >= 0);
assertEquals("uncaught", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
Debug.setBreakOnException();
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"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,64 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var expected_events = 1;
var log = [];
var p = new Promise(function(resolve, reject) {
log.push("resolve");
resolve();
});
var q = p.then(
function() {
log.push("throw");
throw new Error("uncaught"); // event
});
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());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
}
} 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"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,76 @@
// 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 = 2;
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) {
if (expected_events === 0) {
assertUnreachable();
} else {
expected_events--;
log.push("uncaught exception");
}
}
} 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", "uncaught exception", "uncaught exception"], log);
} else {
testDone(iteration + 1);
}
} catch (e) {
%AbortJS(e + "\n" + e.stack);
}
}
%EnqueueMicrotask(checkResult);
}
testDone(0);

View File

@ -0,0 +1,41 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// the Promise is rejected within a try-catch in the Promise constructor.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var step = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
assertEquals(0, step);
assertEquals("uncaught", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
step++;
}
} catch (e) {
exception = e;
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
try { // This try-catch must not prevent this uncaught reject event.
reject(new Error("uncaught")); // event
} catch (e) { }
});
assertEquals(1, step);
assertNull(exception);

View File

@ -0,0 +1,43 @@
// 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.
// Flags: --ignore-unhandled-promises
// Test debug events when we only listen to uncaught exceptions and
// an exception is thrown in the Promise constructor, but caught in an
// inner try-catch. The Promise is rejected afterwards.
// We expect an Exception debug event with a promise to be triggered.
Debug = debug.Debug;
var step = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception) {
assertEquals(0, step);
assertEquals("uncaught", event_data.exception().message);
assertTrue(event_data.uncaught());
// Assert that the debug event is triggered at the throw site.
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
step++;
}
} catch (e) {
exception = e;
}
}
Debug.setBreakOnUncaughtException();
Debug.setListener(listener);
var p = new Promise(function(resolve, reject) {
try { // This try-catch must not prevent this uncaught reject event.
throw new Error("caught");
} catch (e) { }
reject(new Error("uncaught")); // event
});
assertEquals(1, step);
assertNull(exception);