This is kinda ignoring what I've previously mentioned: it is an imposed standard for Web extensions by Google + it is already popular on the backend because it's faster at parsing and executing + people ported it to WASM to make it available no matter what ... can we please stop asking if it's really better? It is ... let's move on, shall we?
If you have the ability to detect if the regular expression might explode with a function, then the "safe" part is already handled.
sure ... we can all also write try { new RegExp(str) } catch (o_O) { console.error('you bad person') }
everywhere in every code to see if a RgExp is even working at all, but that's why I've porposed a flag, so that literal regexp won't need any method.
Is x as explode a good flag to use? /(['"]).*?\1/x
would throw right away, other non looking around patterns won't, how cool in terms of DX is that?
I presume by "small", you're talking about the size of the code that evaluates the regular expression
actually the compiled library size, which is smaller because the RegExp that accepts is simpler
a new willExplode() function will allow you to be sure that the current regular expression engine is just as fast.
nothing is stopping the current regular expressions from internally using explosion detection today, then invisibly switching to the RE2 engine if it won't explode - we wouldn't even need a proposal to allow JavaScript runtimes to gain this performance improvement.
Now we talk ... and whatever, really, as long as the willExplode()
is strictly a RE2 not exploding checking procedure, otherwise anything slightly different will make this whole conversation pointless, because like I've said, RE2 is paving its path behid the developers scene and in awkward and unreachable ways ... if there are more standard APIs imposing its constraints and limits the developer experience with JS and its ecosystem will suffer for no reason whatsoever.
A flag to switch or ensure no exploding RegExp are used is cool both as literal RegEpx, constructors, and at JIT time, so that the engine behind the scene can be the fastest possible if the developer meant to use a non expliding RegExp and the engine can "magically" check that's the case, or throw right away.
A flag is the best way to do this, and a try catch around new RegExp(str, 'x')
a no-brainer when it's needed, replacing the need for a method all together, so that would be cool.
Thank you.