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,40 @@
// 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.
// Flags: --ignore-unhandled-promises
Debug = debug.Debug
let listenerComplete = false;
let breakPointCount = 0;
let exceptionThrown = false;
async function f() {
await (async function() { var a = "a"; await 1; debugger; })();
var b = "b";
assertTrue(listenerDone);
assertFalse(exceptionThrown);
assertEquals(1, breakpointCount);
}
function listener(event, exec_state, event_data, data) {
try {
if (event != Debug.DebugEvent.Break) return;
breakpointCount++;
listenerDone = true;
assertEquals("a", exec_state.frame(0).evaluate("a"));
assertEquals("b", exec_state.frame(1).evaluate("b"));
assertEquals("c", exec_state.frame(2).evaluate("c"));
} catch (e) {
exceptionThrown = true;
};
};
Debug.setListener(listener);
var c = "c";
f();

View File

@ -0,0 +1,66 @@
// Copyright 2017 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
Debug = debug.Debug
var exception = null;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
var line = exec_state.frame(0).sourceLineText();
var match = /Exception/.exec(line);
assertNotNull(match);
} catch (e) {
exception = e;
}
}
// Caught throw, events on any exception.
Debug.setListener(listener);
Debug.setBreakOnException();
var thenable = {
get then() {
throw new Error(); // Exception
}
};
class MyPromise extends Promise {
get then() {
throw new Error();
}
}
MyPromise.resolve(thenable);
var p = Promise.resolve(thenable);
async function foo() {
return thenable;
}
foo();
async function foo() {
await thenable;
}
foo();
async function foo() {
try {
await thenable;
} catch (e) {}
}
foo();
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnException();
assertNull(exception);

View File

@ -0,0 +1,223 @@
// 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.
// Flags: --ignore-unhandled-promises
Debug = debug.Debug
let events = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
events++;
}
async function thrower() {
throw "a"; // Exception a
}
var reject = () => Promise.reject("b"); // Exception b
async function awaitReturn() { await 1; return; }
async function scalar() { return 1; }
function nothing() { return 1; }
function rejectConstructor() {
return new Promise((resolve, reject) => reject("c")); // Exception c
}
async function argThrower(x = (() => { throw "d"; })()) { } // Exception d
async function awaitThrow() {
await undefined;
throw "e"; // Exception e
}
function constructorReject() {
return new Promise((resolve, reject) =>
Promise.resolve().then(() =>
reject("f") // Exception f
)
);
}
function constructorThrow() {
return new Promise((resolve, reject) =>
Promise.resolve().then(() => {
throw "g"; // Exception g
})
);
}
function suppressThrow() {
return thrower();
}
async function caught(producer) {
try {
await producer();
} catch (e) {
}
}
async function uncaught(producer) {
await producer();
}
async function indirectUncaught(producer) {
await uncaught(producer);
}
async function indirectCaught(producer) {
try {
await uncaught(producer);
} catch (e) {
}
}
function dotCatch(producer) {
Promise.resolve(producer()).catch(() => {});
}
function indirectReturnDotCatch(producer) {
(async() => producer())().catch(() => {});
}
function indirectAwaitDotCatch(producer) {
(async() => await producer())().catch(() => {});
}
function nestedDotCatch(producer) {
Promise.resolve(producer()).then().catch(() => {});
}
async function indirectAwaitCatch(producer) {
try {
await (() => producer())();
} catch (e) {
}
}
function switchCatch(producer) {
let resolve;
let promise = new Promise(r => resolve = r);
async function localCaught() {
try {
await promise; // force switching to localUncaught and back
await producer();
} catch (e) { }
}
async function localUncaught() {
await undefined;
resolve();
}
localCaught();
localUncaught();
}
function switchDotCatch(producer) {
let resolve;
let promise = new Promise(r => resolve = r);
async function localCaught() {
await promise; // force switching to localUncaught and back
await producer();
}
async function localUncaught() {
await undefined;
resolve();
}
localCaught().catch(() => {});
localUncaught();
}
let catches = [caught,
indirectCaught,
indirectAwaitCatch,
indirectAwaitDotCatch,
indirectReturnDotCatch,
switchCatch,
switchDotCatch];
let noncatches = [uncaught, indirectUncaught];
let lateCatches = [dotCatch,
nestedDotCatch];
let throws = [rejectConstructor, thrower, reject, argThrower, suppressThrow];
let nonthrows = [awaitReturn, scalar, nothing];
let lateThrows = [awaitThrow, constructorReject];
let uncatchable = [constructorThrow];
let cases = [];
for (let producer of throws.concat(lateThrows)) {
for (let consumer of catches) {
cases.push({ producer, consumer, expectedEvents: 1, caught: true });
cases.push({ producer, consumer, expectedEvents: 0, caught: false });
}
}
for (let producer of throws.concat(lateThrows)) {
for (let consumer of noncatches) {
cases.push({ producer, consumer, expectedEvents: 1, caught: true });
cases.push({ producer, consumer, expectedEvents: 1, caught: false });
}
}
for (let producer of nonthrows) {
for (let consumer of catches.concat(noncatches, lateCatches)) {
cases.push({ producer, consumer, expectedEvents: 0, caught: true });
cases.push({ producer, consumer, expectedEvents: 0, caught: false });
}
}
for (let producer of uncatchable) {
for (let consumer of catches.concat(noncatches, lateCatches)) {
cases.push({ producer, consumer, expectedEvents: 1, caught: true });
cases.push({ producer, consumer, expectedEvents: 1, caught: false });
}
}
for (let producer of lateThrows) {
for (let consumer of lateCatches) {
cases.push({ producer, consumer, expectedEvents: 1, caught: true });
cases.push({ producer, consumer, expectedEvents: 0, caught: false });
}
}
for (let producer of throws) {
for (let consumer of lateCatches) {
cases.push({ producer, consumer, expectedEvents: 1, caught: true });
cases.push({ producer, consumer, expectedEvents: 1, caught: false });
}
}
function runPart(n) {
let subcases = cases.slice(n * cases.length / 4,
((n + 1) * cases.length) / 4);
for (let {producer, consumer, expectedEvents, caught} of subcases) {
Debug.setListener(listener);
if (caught) {
Debug.setBreakOnException();
} else {
Debug.setBreakOnUncaughtException();
}
events = 0;
consumer(producer);
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
if (caught) {
Debug.clearBreakOnException();
} else {
Debug.clearBreakOnUncaughtException();
}
if (expectedEvents != events) {
%AbortJS(`producer ${producer} consumer ${consumer} expectedEvents ` +
`${expectedEvents} caught ${caught} events ${events}`);
}
}
}

View File

@ -0,0 +1,8 @@
// 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.
// Flags: --ignore-unhandled-promises
// Files: test/debugger/debug/es8/async-debug-caught-exception-cases.js
runPart(0);

View File

@ -0,0 +1,8 @@
// 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.
// Flags: --ignore-unhandled-promises
// Files: test/debugger/debug/es8/async-debug-caught-exception-cases.js
runPart(1);

View File

@ -0,0 +1,8 @@
// 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.
// Flags: --ignore-unhandled-promises
// Files: test/debugger/debug/es8/async-debug-caught-exception-cases.js
runPart(2);

View File

@ -0,0 +1,8 @@
// 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.
// Flags: --ignore-unhandled-promises
// Files: test/debugger/debug/es8/async-debug-caught-exception-cases.js
runPart(3);

View File

@ -0,0 +1,144 @@
// 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.
// Flags: --ignore-unhandled-promises
Debug = debug.Debug
var exception = null;
var log;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
var line = exec_state.frame(0).sourceLineText();
var match = /Exception (\w)/.exec(line);
assertNotNull(match);
log.push(match[1]);
} catch (e) {
exception = e;
}
}
async function thrower() {
throw "a"; // Exception a
}
async function caught_throw() {
try {
await thrower();
} catch (e) {
assertEquals("a", e);
}
}
// Caught throw, events on any exception.
log = [];
Debug.setListener(listener);
Debug.setBreakOnException();
caught_throw();
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnException();
assertEquals(["a"], log);
assertNull(exception);
// Caught throw, events on uncaught exception.
log = [];
Debug.setListener(listener);
Debug.setBreakOnUncaughtException();
caught_throw();
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnUncaughtException();
assertEquals([], log);
assertNull(exception);
var reject = Promise.reject("b");
async function caught_reject() {
try {
await reject;
} catch (e) {
assertEquals("b", e);
}
}
// Caught reject, events on any exception.
log = [];
Debug.setListener(listener);
Debug.setBreakOnException();
caught_reject();
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnException();
assertEquals([], log);
assertNull(exception);
// Caught reject, events on uncaught exception.
log = [];
Debug.setListener(listener);
Debug.setBreakOnUncaughtException();
caught_reject();
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnUncaughtException();
assertEquals([], log);
assertNull(exception);
log = [];
Debug.setListener(listener);
Debug.setBreakOnException();
// "rethrown" uncaught exceptions in return don't cause another event
async function propagate_inner() { return thrower(); }
async function propagate_outer() { return propagate_inner(); }
propagate_outer();
%PerformMicrotaskCheckpoint();
assertEquals(["a"], log);
assertNull(exception);
// Also don't propagate if an await interceded
log = [];
async function propagate_await() { await 1; return thrower(); }
async function propagate_await_outer() { return propagate_await(); }
propagate_await_outer();
%PerformMicrotaskCheckpoint();
assertEquals(["a"], log);
assertNull(exception);
Debug.clearBreakOnException();
Debug.setBreakOnUncaughtException();
log = [];
Promise.resolve().then(() => Promise.reject()).catch(() => log.push("d")); // Exception c
%PerformMicrotaskCheckpoint();
assertEquals(["d"], log);
assertNull(exception);
Debug.clearBreakOnUncaughtException();
Debug.setListener(null);
// If devtools is turned on in the middle, then catch prediction
// could be wrong (here, it mispredicts the exception as caught),
// but shouldn't crash.
log = [];
var resolve;
var turnOnListenerPromise = new Promise(r => resolve = r);
async function confused() {
await turnOnListenerPromise;
throw foo
}
confused();
Promise.resolve().then(() => {
Debug.setListener(listener);
Debug.setBreakOnUncaughtException();
resolve();
});
assertEquals([], log);

View File

@ -0,0 +1,53 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B2 StepOut
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
g(); // B2 StepInto
return a;
}
f();
// Starting a new step action at an intermediate break point
// means that we will abort the current async step.
debugger; // B3 StepOver
late_resolve(3); // B4 Continue
%PerformMicrotaskCheckpoint();
assertEquals(5, step_count);

View File

@ -0,0 +1,53 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B2 StepOut
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
g(); // B2 StepInto
return a; // B4 Continue
}
f();
// Continuing at an intermediate break point means that we will
// carry on with the current async step.
debugger; // B3 Continue
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(5, step_count);

View File

@ -0,0 +1,49 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B2 StepOut
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
g();
return a; // B3 Continue
}
f();
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(4, step_count);

View File

@ -0,0 +1,49 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B2 StepOut
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
g();
return a; // B3 Continue
}
f();
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(4, step_count);

View File

@ -0,0 +1,49 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B2 StepInto
function(res, rej) {
late_resolve = res; // B3 StepInto
} // B4 StepInto
); // B5 StepInto
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
g();
return a; // B6 Continue
}
f().then(value => assertEquals(4, value));
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(7, step_count);

View File

@ -0,0 +1,56 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise( // B3 StepOut
function(res, rej) {
late_resolve = res;
}
);
}
async function f1() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepInto
f2(); // B2 StepInto
return a; // B5 Continue
}
async function f2() {
var b = 0 + // B2 StepInto
await
g();
return b; // B4 StepOut
}
f1();
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(6, step_count);

View File

@ -0,0 +1,37 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
async function f() {
var a = 1;
debugger; // B0 StepOver
a += // B1 StepOver
await
5;
return a; // B2 Continue
}
f();
%PerformMicrotaskCheckpoint();
assertEquals(3, step_count);

View File

@ -0,0 +1,49 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise(
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a +=
await // B1 StepOver
g();
return a; // B2 Continue
}
f();
late_resolve(3);
%PerformMicrotaskCheckpoint();
assertEquals(3, step_count);

View File

@ -0,0 +1,47 @@
// 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.
var Debug = debug.Debug;
var step_count = 0;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
var line = execState.frame(0).sourceLineText();
print(line);
var [match, expected_count, step] = /\/\/ B(\d) (\w+)$/.exec(line);
assertEquals(step_count++, parseInt(expected_count));
if (step != "Continue") execState.prepareStep(Debug.StepAction[step]);
} catch (e) {
print(e, e.stack);
quit(1);
}
}
Debug.setListener(listener);
var late_resolve;
function g() {
return new Promise(
function(res, rej) {
late_resolve = res;
}
);
}
async function f() {
var a = 1;
debugger; // B0 StepOver
a += await g(); // B1 StepOut
return a;
}
f();
late_resolve(3); // B2 Continue
%PerformMicrotaskCheckpoint();
assertEquals(3, step_count);

View File

@ -0,0 +1,137 @@
// 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.
// Flags: --noalways-turbofan
var Debug = debug.Debug;
var breakPointCount = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
++breakPointCount;
try {
if (breakPointCount === 1) {
assertEquals(
"inner", exec_state.frame(0).evaluate("inner").value());
// Variables in TDZ should throw an 'unavailable in debugger' error.
assertThrows(() => exec_state.frame(0).evaluate("letInner"));
assertThrows(() => exec_state.frame(0).evaluate("constInner"));
assertEquals("outer", exec_state.frame(0).evaluate("outer").value());
assertEquals(
"const outer", exec_state.frame(0).evaluate("constOuter").value());
assertEquals(
"let outer", exec_state.frame(0).evaluate("letOuter").value());
assertEquals("outer", exec_state.frame(1).evaluate("outer").value());
assertEquals(
"const outer", exec_state.frame(1).evaluate("constOuter").value());
assertEquals(
"let outer", exec_state.frame(1).evaluate("letOuter").value());
// Variables in TDZ should throw an 'unavailable in debugger' error.
assertThrows(() => exec_state.frame(0).evaluate("withVar"));
} else if (breakPointCount === 2) {
assertEquals(
"inner", exec_state.frame(0).evaluate("inner").value());
// Variables in TDZ should throw an 'unavailable in debugger' error.
assertThrows(() => exec_state.frame(0).evaluate("letInner"));
assertThrows(() => exec_state.frame(0).evaluate("constInner"));
assertEquals(57, exec_state.frame(0).evaluate("x").value());
assertEquals(100, exec_state.frame(0).evaluate("y").value());
// From breakPointCount === 1 and later, it's not possible to access
// earlier framestates.
assertEquals("outer", exec_state.frame(0).evaluate("outer").value());
assertEquals(
"const outer", exec_state.frame(0).evaluate("constOuter").value());
assertEquals(
"let outer", exec_state.frame(0).evaluate("letOuter").value());
exec_state.frame(0).evaluate("x = `x later(${x})`");
exec_state.frame(0).evaluate("y = `y later(${y})`");
exec_state.frame(0).evaluate("z = `ZEE`");
} else if (breakPointCount === 3) {
assertEquals(
"inner", exec_state.frame(0).evaluate("inner").value());
assertEquals(
"let inner", exec_state.frame(0).evaluate("letInner").value());
assertEquals(
"const inner", exec_state.frame(0).evaluate("constInner").value());
} else if (breakPointCount === 4) {
assertEquals(
"oop", exec_state.frame(0).evaluate("error.message").value());
assertEquals(
"Error",
exec_state.frame(0).evaluate("error.constructor.name").value());
assertEquals("floof", exec_state.frame(0).evaluate("bun").value());
// Variables in TDZ should throw an 'unavailable in debugger' error.
assertThrows(() => exec_state.frame(0).evaluate("cow"));
assertEquals("outer", exec_state.frame(0).evaluate("outer").value());
assertEquals(
"const outer", exec_state.frame(0).evaluate("constOuter").value());
assertEquals(
"let outer", exec_state.frame(0).evaluate("letOuter").value());
}
} catch (e) {
print(e.stack);
quit(1);
}
}
Debug.setListener(listener);
var outer = "outer";
const constOuter = "const outer";
let letOuter = "let outer"
async function thrower() {
return Promise.reject(new Error("oop"));
}
async function testLater() {
return { x: 57, y: 100 };
}
async function test() {
var inner = "inner";
debugger;
let withVar = await testLater();
with (withVar) {
debugger;
}
assertEquals("x later(57)", withVar.x);
assertEquals("y later(100)", withVar.y);
assertEquals(undefined, withVar.z);
assertEquals("ZEE", z);
let letInner = "let inner";
const constInner = "const inner";
debugger;
try {
await thrower();
} catch (error) {
const bun = "floof";
debugger;
let cow = "moo";
}
}
test().
then(x => {
Debug.setListener(null);
}).
catch(error => {
print(error.stack);
quit(1);
Debug.setListener(null);
});

View File

@ -0,0 +1,550 @@
// 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.
// Flags: --noalways-turbofan
var Debug = debug.Debug;
var global_marker = 7;
async function thrower() { throw 'Exception'; }
async function test(name, func, args, handler, continuation) {
var handler_called = false;
var exception = null;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
handler_called = true;
handler(exec_state);
}
} catch (e) {
exception = e;
}
}
Debug.setListener(listener);
var result;
if (typeof func === "object")
result = await func.method.apply(func, args);
else
result = await func.apply(null, args);
if (typeof continuation === "function") {
await continuation(result);
}
assertTrue(handler_called, `Expected ${name} handler to be called`);
if (exception) {
exception.message = `${name} / ${exception.message}`;
print(exception.stack);
quit(1);
}
Debug.setListener(null);
}
async function runTests() {
// Simple
await test(
"(AsyncFunctionExpression) Local 1",
async function() { debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 1 --- resume normal",
async function() { let z = await 2; debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({z: 2}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 1 --- resume throw",
async function() { let q = await 1;
try { let z = await thrower(); }
catch (e) { debugger; } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e: 'Exception'}, 0, exec_state);
CheckScopeContent({q: 1}, 1, exec_state);
});
// Simple With Parameter
await test(
"(AsyncFunctionExpression) Local 2",
async function(a) { debugger; }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ a: 1 }, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 2 --- resume normal",
async function(a) { let z = await 2; debugger; }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ a: 1, z: 2 }, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 2 --- resume throw",
async function(a) { let z = await 2;
try { await thrower(); } catch (e) { debugger; } }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ e: 'Exception' }, 0, exec_state);
CheckScopeContent({ a: 1, z: 2 }, 1, exec_state);
});
// Simple With Parameter and Variable
await test(
"(AsyncFunctionExpression) Local 3",
async function(a) { var b = 2; debugger; }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ a: 1, b: 2 }, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 3 --- resume normal",
async function(a) { let y = await 3; var b = 2; let z = await 4;
debugger; }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ a: 1, b: 2, y: 3, z: 4 }, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 3 --- resume throw",
async function(a) { let y = await 3;
try { var b = 2; let z = await thrower(); }
catch (e) { debugger; } }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ e: 'Exception' }, 0, exec_state);
CheckScopeContent({ a: 1, b: 2, y: 3 }, 1, exec_state);
});
// Local scope with parameters and local variables.
await test(
"(AsyncFunctionExpression) Local 4",
async function(a, b) { var x = 3; var y = 4; debugger; }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 4 --- resume normal",
async function(a, b) { let q = await 5; var x = 3; var y = 4;
let r = await 6; debugger; }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4, q: 5, r: 6}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 4 --- resume throw",
async function(a, b) { let q = await 5; var x = 3; var y = 4;
try { let r = await thrower(); }
catch (e) { debugger; } }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e: 'Exception'}, 0, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4, q: 5}, 1, exec_state);
});
// Empty local scope with use of eval.
await test(
"(AsyncFunctionExpression) Local 5",
async function() { eval(""); debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 5 --- resume normal",
async function() { let x = await 1; eval(""); let y = await 2;
debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ x: 1, y: 2 }, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 5 --- resume throw",
async function() { let x = await 1; eval("");
try { let y = await thrower(); }
catch (e) { debugger; } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ e: 'Exception' }, 0, exec_state);
CheckScopeContent({ x: 1 }, 1, exec_state);
});
// Local introducing local variable using eval.
await test(
"(AsyncFunctionExpression) Local 6",
async function() { eval("var i = 5"); debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({i:5}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 6 --- resume normal",
async function() { let x = await 1; eval("var i = 5"); let y = await 2;
debugger; }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({i:5, x: 1, y: 2}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 6 --- resume throw",
async function() { let x = await 1; eval("var i = 5");
try { let y = await thrower(); }
catch (e) { debugger; } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e: 'Exception' }, 0, exec_state);
CheckScopeContent({i:5, x: 1}, 1, exec_state);
});
// Local scope with parameters, local variables and local variable introduced
// using eval.
await test(
"(AsyncFunctionExpression) Local 7",
async function(a, b) { var x = 3; var y = 4;
eval("var i = 5;"); eval("var j = 6");
debugger; }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 7 --- resume normal",
async function(a, b) { let z = await 7; var x = 3; var y = 4;
eval("var i = 5;"); eval("var j = 6");
let q = await 8;
debugger; }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6, z:7, q:8}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Local 7 --- resume throw",
async function(a, b) { let z = await 7; var x = 3; var y = 4;
eval("var i = 5;"); eval("var j = 6");
try { let q = await thrower(); }
catch (e) { debugger; } }, [1, 2],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e: 'Exception'}, 0, exec_state);
//CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6, z:7}, 1, exec_state);
});
// Nested empty with blocks.
await test(
"(AsyncFunctionExpression) With",
async function() { with ({}) { with ({}) { debugger; } } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.With,
debug.ScopeType.With,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
CheckScopeContent({}, 1, exec_state);
});
await test(
"(AsyncFunctionExpression) With --- resume normal",
async function() { let x = await 1; with ({}) { with ({}) {
let y = await 2; debugger; } } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Block,
debug.ScopeType.With,
debug.ScopeType.With,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({y:2}, 0, exec_state);
CheckScopeContent({}, 1, exec_state);
CheckScopeContent({}, 2, exec_state);
CheckScopeContent({x:1}, 3, exec_state);
});
await test(
"(AsyncFunctionExpression) With --- resume throw",
async function() { let x = await 1; with ({}) { with ({}) {
try { let y = await thrower(); }
catch (e) { debugger; } } } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.With,
debug.ScopeType.With,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({ e: 'Exception'}, 0, exec_state);
CheckScopeContent({}, 1, exec_state);
CheckScopeContent({}, 2, exec_state);
CheckScopeContent({x:1}, 3, exec_state);
});
// Simple closure formed by returning an inner function referering the outer
// functions arguments.
await test(
"(AsyncFunctionExpression) Closure 1",
async function(a) { return function() { debugger; return a; } }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 1, exec_state);
},
result => result());
await test(
"(AsyncFunctionExpression) Closure 1 --- resume normal",
async function(a) { let x = await 2;
return function() { debugger; return a; } }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 1, exec_state);
},
result => result());
await test(
"(AsyncFunctionExpression) Closure 1 --- resume throw",
async function(a) { let x = await 2;
return async function() {
try { await thrower(); }
catch (e) { debugger; } return a; }; }, [1],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e: 'Exception'}, 0, exec_state);
CheckScopeContent({a:1}, 2, exec_state);
},
result => result());
await test(
"(AsyncFunctionExpression) Catch block 1",
async function() { try { throw 'Exception'; } catch (e) { debugger; } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e:'Exception'}, 0, exec_state);
});
await test(
"(AsyncFunctionExpression) Catch block 1 --- resume normal",
async function() {
let x = await 1;
try { throw 'Exception'; } catch (e) { let y = await 2; debugger; } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Block,
debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({y: 2}, 0, exec_state);
CheckScopeContent({e:'Exception'}, 1, exec_state);
CheckScopeContent({x: 1}, 2, exec_state);
});
await test(
"(AsyncFunctionExpression) Catch block 1 --- resume throw",
async function() {
let x = await 1;
try { throw 'Exception!'; } catch (e) {
try { let y = await thrower(); } catch (e) { debugger; } } }, [],
exec_state => {
CheckScopeChain([debug.ScopeType.Catch,
debug.ScopeType.Catch,
debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e:'Exception'}, 0, exec_state);
CheckScopeContent({e:'Exception!'}, 1, exec_state);
CheckScopeContent({x: 1}, 2, exec_state);
});
}
runTests().catch(error => {
print(error.stack);
quit(1);
})
// Check that two scope are the same.
function assertScopeMirrorEquals(scope1, scope2) {
assertEquals(scope1.scopeType(), scope2.scopeType());
assertEquals(scope1.frameIndex(), scope2.frameIndex());
assertEquals(scope1.scopeIndex(), scope2.scopeIndex());
assertPropertiesEqual(
scope1.scopeObject().value(), scope2.scopeObject().value());
}
function CheckFastAllScopes(scopes, exec_state) {
var fast_all_scopes = exec_state.frame().allScopes(true);
var length = fast_all_scopes.length;
assertTrue(scopes.length >= length);
for (var i = 0; i < scopes.length && i < length; i++) {
var scope = fast_all_scopes[length - i - 1];
assertEquals(scopes[scopes.length - i - 1], scope.scopeType());
}
}
// Check that the scope chain contains the expected types of scopes.
function CheckScopeChain(scopes, exec_state) {
var all_scopes = exec_state.frame().allScopes();
assertEquals(
scopes.length, all_scopes.length, "FrameMirror.allScopes length");
for (var i = 0; i < scopes.length; i++) {
var scope = exec_state.frame().scope(i);
assertEquals(scopes[i], scope.scopeType());
assertScopeMirrorEquals(all_scopes[i], scope);
// Check the global object when hitting the global scope.
if (scopes[i] == debug.ScopeType.Global) {
assertEquals(global_marker, scope.scopeObject().value().global_marker);
}
}
CheckFastAllScopes(scopes, exec_state);
}
// Check that the content of the scope is as expected. For functions just check
// that there is a function.
function CheckScopeContent(content, number, exec_state) {
var scope = exec_state.frame().scope(number);
var count = 0;
for (var p in content) {
var property_mirror = scope.scopeObject().property(p);
assertFalse(property_mirror.isUndefined(),
`property ${p} not found in scope`);
assertEquals(content[p], property_mirror.value().value(),
`property ${p} has unexpected value`);
count++;
}
// 'arguments' and might be exposed in the local and closure scope. Just
// ignore this.
var scope_size = scope.scopeObject().properties().length;
if (!scope.scopeObject().property('arguments').isUndefined()) {
scope_size--;
}
// Skip property with empty name.
if (!scope.scopeObject().property('').isUndefined()) {
scope_size--;
}
if (scope_size < count) {
print('Names found in scope:');
var names = scope.scopeObject().propertyNames();
for (var i = 0; i < names.length; i++) {
print(names[i]);
}
}
assertTrue(scope_size >= count);
}

View File

@ -0,0 +1,75 @@
// 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.
var Debug = debug.Debug;
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + promise);
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
}
var break_count = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
break_count++;
var line = exec_state.frame(0).sourceLineText();
print(line);
assertTrue(line.indexOf(`B${break_count}`) > 0);
} catch (e) {
exception = e;
}
}
async function g() {
setbreaks();
throw 1; // B1
}
async function f() {
try {
await g();
} catch (e) {}
return 2; // B2
}
function setbreaks() {
Debug.setListener(listener);
Debug.setBreakPoint(g, 2);
Debug.setBreakPoint(f, 4);
}
f();
%PerformMicrotaskCheckpoint();
assertEqualsAsync(2, async () => break_count);
assertEqualsAsync(null, async () => exception);
Debug.setListener(null);

View File

@ -0,0 +1,73 @@
// 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.
var Debug = debug.Debug;
function assertEqualsAsync(expected, run, msg) {
var actual;
var hadValue = false;
var hadError = false;
var promise = run();
if (typeof promise !== "object" || typeof promise.then !== "function") {
throw new MjsUnitAssertionError(
"Expected " + run.toString() +
" to return a Promise, but it returned " + promise);
}
promise.then(function(value) { hadValue = true; actual = value; },
function(error) { hadError = true; actual = error; });
assertFalse(hadValue || hadError);
%PerformMicrotaskCheckpoint();
if (hadError) throw actual;
assertTrue(
hadValue, "Expected '" + run.toString() + "' to produce a value");
assertEquals(expected, actual, msg);
}
var break_count = 0;
var exception = null;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
break_count++;
var line = exec_state.frame(0).sourceLineText();
assertTrue(line.indexOf(`B${break_count}`) > 0);
} catch (e) {
exception = e;
}
}
Debug.setListener(listener);
async function g() {
throw 1;
}
async function f() {
try {
await g(); // B1
} catch (e) {}
assertEquals(2, break_count); // B2
return 1; // B3
}
Debug.setBreakPoint(f, 2);
Debug.setBreakPoint(f, 4);
Debug.setBreakPoint(f, 5);
f();
%PerformMicrotaskCheckpoint();
assertEqualsAsync(3, async () => break_count);
assertEqualsAsync(null, async () => exception);
Debug.setListener(null);

View File

@ -0,0 +1,44 @@
// Copyright 2017 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.
Debug = debug.Debug
var exception = null;
var step = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Exception) return;
try {
var line = exec_state.frame(0).sourceLineText();
var match = /Exception/.exec(line);
assertNotNull(match);
step++;
} catch (e) {
exception = e;
}
}
// Caught throw, events on any exception.
Debug.setListener(listener);
Debug.setBreakOnException();
var thenable = {
get then() {
throw new Error('err'); // Exception
}
};
var caughtException = null;
Promise.resolve()
.finally(() => thenable)
.catch(e => caughtException = e);
%PerformMicrotaskCheckpoint();
Debug.setListener(null);
Debug.clearBreakOnException();
assertNull(exception);
assertNotNull(caughtException);
assertEquals(1, step);