Skip to content

Commit

Permalink
feat(ses): tolerate omitted species
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 28, 2024
1 parent 7639f0c commit cd9a1d9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/ses/src/tame-regexp-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ 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');
}
if (speciesSymbol) {
const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
if (!speciesDesc) {
throw TypeError('no RegExp[Symbol.species] descriptor');
}

defineProperties(ResultRegExp, {
length: { value: 2 },
prototype: {
value: RegExpPrototype,
writable: false,
enumerable: false,
configurable: false,
},
[speciesSymbol]: speciesDesc,
});
defineProperties(ResultRegExp, {
length: { value: 2 },
prototype: {
value: RegExpPrototype,
writable: false,
enumerable: false,
configurable: false,
},
[speciesSymbol]: speciesDesc,
});
}
return ResultRegExp;
};

Expand Down

0 comments on commit cd9a1d9

Please sign in to comment.