From db2545b1d9b436baad597eea79154d9052e391f7 Mon Sep 17 00:00:00 2001 From: naugtur Date: Tue, 12 Dec 2023 09:11:07 +0100 Subject: [PATCH] fix(compartment-mapper): Turn empty policy into a null-prototype object --- packages/compartment-mapper/src/node-modules.js | 2 +- packages/compartment-mapper/src/policy-format.js | 2 +- packages/compartment-mapper/src/policy.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/compartment-mapper/src/node-modules.js b/packages/compartment-mapper/src/node-modules.js index 1c5cff649b..056070f12a 100644 --- a/packages/compartment-mapper/src/node-modules.js +++ b/packages/compartment-mapper/src/node-modules.js @@ -566,7 +566,7 @@ const graphPackages = async ( * @param {Graph} graph * @param {Set} tags - build tags about the target environment * for selecting relevant exports, e.g., "browser" or "node". - * @param {object} policy + * @param {object|undefined} policy * @returns {CompartmentMapDescriptor} */ const translateGraph = ( diff --git a/packages/compartment-mapper/src/policy-format.js b/packages/compartment-mapper/src/policy-format.js index 5f2f57e353..958ca2fb1f 100644 --- a/packages/compartment-mapper/src/policy-format.js +++ b/packages/compartment-mapper/src/policy-format.js @@ -122,7 +122,7 @@ export const assertPackagePolicy = (allegedPackagePolicy, path, url) => { const packagePolicy = Object(allegedPackagePolicy); assert( allegedPackagePolicy === packagePolicy && !isArray(allegedPackagePolicy), - `${path} must be an object, got ${allegedPackagePolicy}${inUrl}`, + `${path} must be an object, got ${q(allegedPackagePolicy)}${inUrl}`, ); const { packages, diff --git a/packages/compartment-mapper/src/policy.js b/packages/compartment-mapper/src/policy.js index e0eb1488ae..8604bcb2ac 100644 --- a/packages/compartment-mapper/src/policy.js +++ b/packages/compartment-mapper/src/policy.js @@ -17,7 +17,7 @@ import { isAllowingEverything, } from './policy-format.js'; -const { entries, values, assign, keys, freeze } = Object; +const { create, entries, values, assign, keys, freeze } = Object; const q = JSON.stringify; /** @@ -138,7 +138,7 @@ export const getPolicyForPackage = (namingKit, policy) => { return policy.resources[canonicalName]; } else { // Allow skipping policy entries for packages with no powers. - return {}; + return create(null); } };