Closed boneskull closed 10 months ago
cc @naugtur
I wanted to rebase this and add cleanup to one of mine functions but noticed this is from a fork. @boneskull want me to fold this into a branch on the endo repo?
patch I wish to apply after rebase on master:
diff --git a/packages/compartment-mapper/src/policy.js b/packages/compartment-mapper/src/policy.js
index 8604bcb2a..c646c37c3 100644
--- a/packages/compartment-mapper/src/policy.js
+++ b/packages/compartment-mapper/src/policy.js
@@ -339,26 +339,28 @@ const diagnoseModulePolicy = errorHint => {
*
* @param {string} specifier
* @param {import('./types.js').CompartmentDescriptor} compartmentDescriptor
- * @param {object} [info]
+ * @param {object} [options]
+ * @param {boolean} [options.exit] - Whether it is an exit module
+ * @param {string} [options.errorHint] - Error hint message
*/
export const enforceModulePolicy = (
specifier,
compartmentDescriptor,
- info = {},
+ { exit, errorHint } = {},
) => {
const { policy, modules, label } = compartmentDescriptor;
if (!policy) {
return;
}
- if (!info.exit) {
+ if (!exit) {
if (!modules[specifier]) {
throw Error(
`Importing ${q(specifier)} in ${q(
label,
)} was not allowed by packages policy ${q(
policy.packages,
- )}${diagnoseModulePolicy(info.errorHint)}`,
+ )}${diagnoseModulePolicy(errorHint)}`,
);
}
return;
@@ -368,7 +370,7 @@ export const enforceModulePolicy = (
throw Error(
`Importing ${q(specifier)} was not allowed by policy builtins:${q(
policy.builtins,
- )}${diagnoseModulePolicy(info.errorHint)}`,
+ )}${diagnoseModulePolicy(errorHint)}`,
);
}
};
@naugtur Resolved
@naugtur OK, so, it's slightly different than the diff you gave me, since the diff you gave me did not match the snapshots; I retained the use of the label
prop from the compartment descriptor
Please take another look at the changes I made based on your comments.
Description
This adds/narrows types for policies and exports them from the
compartment-mapper
entry point. It also updates some usages of existing and new types (e.g., removing "@typedef
references", squashing some null-reference bugs, etc.).Reviewers: please scrutinize the types added to
src/types.js
closely. The generics allow an attenuator implementation to define the types of custom params which it expects. For example:And in the attenuator:
Documentation Considerations
Does Endo consider type changes to be breaking? These types will likely change in the future, and am curious about whether that should be a major bump.
Testing Considerations
I could use
tsd
to test some of these to avoid regressions, if desired.Upgrade Considerations
none