enforceModulePolicy = (
  specifier,
  compartmentDescriptor,
  { exit, errorHint } = {},
) => {
  const { policy, modules, label } = compartmentDescriptor;
  if (!policy) {
    return;
  }

  if (!exit) {
    if (!modules[specifier]) {
      throw Error(
        `Importing ${q(specifier)} in ${q(
          label,
        )} was not allowed by packages policy ${q(
          policy.packages,
        )}${diagnoseModulePolicy(errorHint)}`,
      );
    }
    return;
  }

  if (!policyLookupHelper(policy, 'builtins', specifier)) {
    throw Error(
      `Importing ${q(specifier)} was not allowed by policy builtins:${q(
        policy.builtins,
      )}${diagnoseModulePolicy(errorHint)}`,
    );
  }
}
Throws if importing of the specifier is not allowed by the policy

@param {string} specifier
@param {CompartmentDescriptor} compartmentDescriptor
@param {EnforceModulePolicyOptions} [options]