Skip to content

Commit

Permalink
feat(eventual-send): also breakpoint on eventual-sends
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 3, 2024
1 parent 5d92dd6 commit 55e5ced
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
35 changes: 35 additions & 0 deletions packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { trackTurns } from './track-turns.js';
import { makeMessageBreakpointTester } from './message-breakpoints.js';

const { details: X, quote: q, Fail } = assert;
const { assign, create } = Object;

const shouldBreakpointSend = makeMessageBreakpointTester(
'ENDO_SEND_BREAKPOINTS',
);

/** @type {ProxyHandler<any>} */
const baseFreezableProxyHandler = {
set(_target, _prop, _value) {
Expand Down Expand Up @@ -55,13 +60,28 @@ const makeEProxyHandler = (x, HandledPromise) =>
);
}

if (shouldBreakpointSend(x, p)) {
// eslint-disable-next-line no-debugger
debugger; // LOOK UP THE STACK
// Stopped at a breakpoint on eventual-send of a method-call
// message,
// so that you can walk back on the stack to see how we came to
// make this eventual-send
}
return HandledPromise.applyMethod(x, p, args);
},
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/50319
}[p],
);
},
apply: (_target, _thisArg, argArray = []) => {
if (shouldBreakpointSend(x, undefined)) {
// eslint-disable-next-line no-debugger
debugger; // LOOK UP THE STACK
// Stopped at a breakpoint on eventual-send of a function-call message,
// so that you can walk back on the stack to see how we came to
// make this eventual-send
}
return HandledPromise.applyFunction(x, argArray);
},
has: (_target, _p) => {
Expand Down Expand Up @@ -94,6 +114,14 @@ const makeESendOnlyProxyHandler = (x, HandledPromise) =>
Fail`Unexpected receiver for "${q(p)}" method of E.sendOnly(${q(
x,
)})`;
if (shouldBreakpointSend(x, p)) {
// eslint-disable-next-line no-debugger
debugger; // LOOK UP THE STACK
// Stopped at a breakpoint on eventual-send of a method-call
// message,
// so that you can walk back on the stack to see how we came to
// make this eventual-send
}
HandledPromise.applyMethodSendOnly(x, p, args);
return undefined;
},
Expand All @@ -103,6 +131,13 @@ const makeESendOnlyProxyHandler = (x, HandledPromise) =>
},
apply: (_target, _thisArg, argsArray = []) => {
HandledPromise.applyFunctionSendOnly(x, argsArray);
if (shouldBreakpointSend(x, undefined)) {
// eslint-disable-next-line no-debugger
debugger; // LOOK UP THE STACK
// Stopped at a breakpoint on eventual-send of a function-call message,
// so that you can walk back on the stack to see how we came to
// make this eventual-send
}
return undefined;
},
has: (_target, _p) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/eventual-send/src/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { apply, ownKeys } = Reflect;

const ntypeof = specimen => (specimen === null ? 'null' : typeof specimen);

const shouldDeliveryBreakpoint = makeMessageBreakpointTester(
const shouldBreakpointDelivery = makeMessageBreakpointTester(
'ENDO_DELIVERY_BREAKPOINTS',
);

Expand Down Expand Up @@ -76,9 +76,9 @@ export const localApplyFunction = (t, args) => {
X`Cannot invoke target as a function; typeof target is ${q(ntypeof(t))}`,
TypeError,
);
if (shouldDeliveryBreakpoint(t, undefined, args)) {
if (shouldBreakpointDelivery(t, undefined)) {
// eslint-disable-next-line no-debugger
debugger;
debugger; // STEP INTO APPLY
// Stopped at a breakpoint on this delivery of an eventual function call
// so that you can step *into* the following `apply` in order to see the
// function call as it happens. Or step *over* to see what happens
Expand Down Expand Up @@ -111,9 +111,9 @@ export const localApplyMethod = (t, method, args) => {
const ftype = ntypeof(fn);
typeof fn === 'function' ||
Fail`invoked method ${q(method)} is not a function; it is a ${q(ftype)}`;
if (shouldDeliveryBreakpoint(t, method, args)) {
if (shouldBreakpointDelivery(t, method)) {
// eslint-disable-next-line no-debugger
debugger;
debugger; // STEP INTO APPLY
// Stopped at a breakpoint on this delivery of an eventual method call
// so that you can step *into* the following `apply` in order to see the
// method call as it happens. Or step *over* to see what happens
Expand Down
6 changes: 2 additions & 4 deletions packages/eventual-send/src/message-breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const tagMatches = (tag, objTag) =>
tag === '*' ||
tag === objTag ||
(objTag.endsWith(tag) &&
`Alleged: ${tag}` === objTag ||
`DebugName: ${tag}` === objTag
);
(`Alleged: ${tag}` === objTag || `DebugName: ${tag}` === objTag));

export const makeMessageBreakpointTester = optionName => {
const breakpointsList = getEnvironmentOption(optionName, '');
Expand Down Expand Up @@ -43,7 +41,7 @@ export const makeMessageBreakpointTester = optionName => {
const shouldBreakpoint =
breakpointsList === ''
? () => false
: (obj, verb, args) => {
: (obj, verb) => {
if (verb === undefined) {
// TODO enable function breakpointing
return false;
Expand Down
6 changes: 6 additions & 0 deletions packages/pass-style/test/prepare-breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ process.env.ENDO_DELIVERY_BREAKPOINTS = [
'Bob.foo=*',
'*.bar=0',
].join(',');

process.env.ENDO_SEND_BREAKPOINTS = [
// One line per breakpoint directive.
'Bob.foo=*',
'*.bar=0',
].join(',');

0 comments on commit 55e5ced

Please sign in to comment.