From cd9a1d904d0bdca927a9263e0ee274b8890e72ba Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Wed, 28 Feb 2024 11:16:16 -0800 Subject: [PATCH] feat(ses): tolerate omitted species --- packages/ses/src/tame-regexp-constructor.js | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/ses/src/tame-regexp-constructor.js b/packages/ses/src/tame-regexp-constructor.js index bb7574417c..0a5e263e40 100644 --- a/packages/ses/src/tame-regexp-constructor.js +++ b/packages/ses/src/tame-regexp-constructor.js @@ -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; };