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

feat(ses): tolerate omitted species #2108

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Changes from 2 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
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 suppory such platforms.
erights marked this conversation as resolved.
Show resolved Hide resolved
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
Loading