Skip to content

Commit

Permalink
feat(ses): tolerate omitted species (#2108)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Feb 28, 2024
1 parent 7639f0c commit 70c85ef
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/ses/src/tame-regexp-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
return construct(FERAL_REG_EXP, rest, new.target);
};

const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
if (!speciesDesc) {
throw TypeError('no RegExp[Symbol.species] descriptor');
}

defineProperties(ResultRegExp, {
length: { value: 2 },
prototype: {
Expand All @@ -38,8 +33,20 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
enumerable: false,
configurable: false,
},
[speciesSymbol]: speciesDesc,
});
// Hermes does not have `Symbol.species`. We should support such platforms.
if (speciesSymbol) {
const speciesDesc = getOwnPropertyDescriptor(
FERAL_REG_EXP,
speciesSymbol,
);
if (!speciesDesc) {
throw TypeError('no RegExp[Symbol.species] descriptor');
}
defineProperties(ResultRegExp, {
[speciesSymbol]: speciesDesc,
});
}
return ResultRegExp;
};

Expand Down

0 comments on commit 70c85ef

Please sign in to comment.