MCPcopy Index your code
hub / github.com/nodejs/node / getCrossRealmRegex

Function getCrossRealmRegex

lib/internal/util.js:739–756  ·  view source on GitHub ↗
(regex)

Source from the content-addressed store, hash-verified

737
738const crossRealmRegexes = new SafeWeakMap();
739function getCrossRealmRegex(regex) {
740 const cached = crossRealmRegexes.get(regex);
741 if (cached) return cached;
742
743 let flagString = '';
744 if (RegExpPrototypeGetHasIndices(regex)) flagString += 'd';
745 if (RegExpPrototypeGetGlobal(regex)) flagString += 'g';
746 if (RegExpPrototypeGetIgnoreCase(regex)) flagString += 'i';
747 if (RegExpPrototypeGetMultiline(regex)) flagString += 'm';
748 if (RegExpPrototypeGetDotAll(regex)) flagString += 's';
749 if (RegExpPrototypeGetUnicode(regex)) flagString += 'u';
750 if (RegExpPrototypeGetSticky(regex)) flagString += 'y';
751
752 const { RegExp: RegExpFromAnotherRealm } = getInternalGlobal();
753 const crossRealmRegex = new RegExpFromAnotherRealm(RegExpPrototypeGetSource(regex), flagString);
754 crossRealmRegexes.set(regex, crossRealmRegex);
755 return crossRealmRegex;
756}
757
758function SideEffectFreeRegExpPrototypeSymbolReplace(regex, string, replacement) {
759 return getCrossRealmRegex(regex)[SymbolReplace](string, replacement);

Calls 3

getInternalGlobalFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…