Skip to content

Commit

Permalink
fixup! fix(ses): Do not get confused by well-known look-alikes
Browse files Browse the repository at this point in the history
Add support for registered symbols
Document Unique and Registered Symbols property shape in whitelist
  • Loading branch information
mhofman committed Mar 16, 2022
1 parent 8fc6c2b commit 6f6fffb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/ses/src/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const {
toStringTag: toStringTagSymbol,
iterator: iteratorSymbol,
matchAll: matchAllSymbol,
keyFor: SymbolKeyFor,
for: SymbolFor,
} = Symbol;

export const { isInteger } = Number;
Expand Down
8 changes: 7 additions & 1 deletion packages/ses/src/whitelist-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
mapGet,
objectHasOwnProperty,
ownKeys,
SymbolKeyFor,
} from './commons.js';

/**
Expand Down Expand Up @@ -107,7 +108,12 @@ export default function whitelistIntrinsics(
if (wellKnownSymbol) {
return wellKnownSymbol;
} else {
return `Unique${String(prop)}`;
const registeredKey = SymbolKeyFor(prop);
if (registeredKey !== undefined) {
return `RegisteredSymbol(${registeredKey})`;
} else {
return `Unique${String(prop)}`;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/ses/src/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ export const NativeErrors = [
* property definition.
* <li>"ObjectPrototype" is the default "[[Proto]]" (when not specified).
* <li>Constants "fn" and "getter" are used to keep the structure DRY.
* <li>Symbol properties are listed using the "@@name" form.
* <li>Symbol properties are listed as follow:
* <li>Well-known symbols use the "@@name" form.
* <li>Registered symbols use the "RegisteredSymbol(key)" form.
* <li>Unique symbols use the "UniqueSymbol(description)" form.
*/

// Function Instances
Expand Down

0 comments on commit 6f6fffb

Please sign in to comment.