Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): group removal cleanup diagnostics #1942

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions packages/ses/src/permits-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ export default function whitelistIntrinsics(
intrinsics,
markVirtualizedNativeFunction,
) {
// These primitives are allowed allowed for permits.
let groupStarted = false;
const inConsoleGroup = (level, ...args) => {
if (!groupStarted) {
// eslint-disable-next-line @endo/no-polymorphic-call
console.groupCollapsed('Removing unpermitted intrinsics');
groupStarted = true;
}
// eslint-disable-next-line @endo/no-polymorphic-call
return console[level](...args);
};

// These primitives are allowed for permits.
const primitives = ['undefined', 'boolean', 'number', 'string', 'symbol'];

// These symbols are allowed as well-known symbols
Expand Down Expand Up @@ -279,11 +290,7 @@ export default function whitelistIntrinsics(
// that we are removing it so we know to look into it, as happens when
// the language evolves new features to existing intrinsics.
if (subPermit !== false) {
// This call to `console.warn` is intentional. It is not a vestige of
// a debugging attempt. See the comment at top of file for an
// explanation.
// eslint-disable-next-line @endo/no-polymorphic-call
console.warn(`Removing ${subPath}`);
inConsoleGroup('warn', `Removing ${subPath}`);
}
try {
delete obj[prop];
Expand All @@ -292,25 +299,32 @@ export default function whitelistIntrinsics(
if (typeof obj === 'function' && prop === 'prototype') {
obj.prototype = undefined;
if (obj.prototype === undefined) {
// eslint-disable-next-line @endo/no-polymorphic-call
console.warn(`Tolerating undeletable ${subPath} === undefined`);
inConsoleGroup(
'warn',
`Tolerating undeletable ${subPath} === undefined`,
);
// eslint-disable-next-line no-continue
continue;
}
}
// eslint-disable-next-line @endo/no-polymorphic-call
console.error(`failed to delete ${subPath}`, err);
inConsoleGroup('error', `failed to delete ${subPath}`, err);
} else {
// eslint-disable-next-line @endo/no-polymorphic-call
console.error(`deleting ${subPath} threw`, err);
inConsoleGroup('error', `deleting ${subPath} threw`, err);
}
throw err;
}
}
}
}

// Start path with 'intrinsics' to clarify that properties are not
// removed from the global object by the whitelisting operation.
visitProperties('intrinsics', intrinsics, permitted);
try {
// Start path with 'intrinsics' to clarify that properties are not
// removed from the global object by the whitelisting operation.
visitProperties('intrinsics', intrinsics, permitted);
} finally {
if (groupStarted) {
// eslint-disable-next-line @endo/no-polymorphic-call
console.groupEnd();
}
}
}
2 changes: 2 additions & 0 deletions packages/ses/test/error/test-permit-removal-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ test('permit removal warnings', t => {
t,
() => lockdown(),
[
['groupCollapsed', 'Removing unpermitted intrinsics'],
['warn', 'Removing intrinsics.Array.isArray.prototype'],
[
'warn',
'Tolerating undeletable intrinsics.Array.isArray.prototype === undefined',
],
['warn', 'Removing intrinsics.Array.extraRemovableDataProperty'],
['groupEnd'],
],
{},
);
Expand Down