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

fix(compartment-mapper): fix #2407 include symbol-named properties #2408

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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
15 changes: 12 additions & 3 deletions packages/compartment-mapper/src/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
policyLookupHelper,
} from './policy-format.js';

const { create, entries, values, assign, keys, freeze } = Object;
const { create, entries, values, assign, freeze, getOwnPropertyDescriptors } =
Object;
const { ownKeys } = Reflect;
const q = JSON.stringify;

/**
Expand All @@ -19,7 +21,9 @@ const q = JSON.stringify;
export const ATTENUATORS_COMPARTMENT = '<ATTENUATORS>';

/**
* Copies properties (optionally limited to a specific list) from one object to another.
* Copies properties (optionally limited to a specific list) from one object
* to another. By default, copies all enumerable, own, string- and
* symbol-named properties.
*
* @param {object} from
* @param {object} to
Expand All @@ -28,7 +32,12 @@ export const ATTENUATORS_COMPARTMENT = '<ATTENUATORS>';
*/
const selectiveCopy = (from, to, list) => {
if (!list) {
list = keys(from);
const descs = getOwnPropertyDescriptors(from);
list = ownKeys(from).filter(
key =>
// @ts-expect-error TypeScript still confused about a symbol as index
descs[key].enumerable,
);
erights marked this conversation as resolved.
Show resolved Hide resolved
}
for (let index = 0; index < list.length; index += 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naugtur Might be worth you time to investigate how a policy would name a symbol to be preserved.

const key = list[index];
Expand Down
Loading