Repository navigation
a fresh node startup has populated RegExp statics #43740
Description
Activity
cc @aduh95
I would like to work on the fix for this. Looks like it is a side of this.
ah, maybe the statics are populated by the same realm then :-/ that would be great for the repl, but wouldn't address node itself.
Duplicate of #18931?
Reacted by Hemanth HMThe repl part, yes - but not the
node -pepart.it's likely that switching to primordials (since I believe they'd update the statics on the primordial RegExp instead of the global RegExp) would solve this as well.
Before user code is executed,
primordials.RegExp === globalThis.RegExp, so that wouldn't help. Creating an empty RegExp sounds fine though.@hemanth if you want to work on the REPL side, that'd be great, I have a fix ready for the other problem.
Reacted by Jordan Harband and Hemanth HM@aduh95 Trying to understand the intent behind this.
regExMatcher.exec(savedRegExMatches.join(sep))results in:[ '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', '', '', '', '', '', '', '', '', '', index: 0, input: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', groups: undefined ]
My understanding is it's trying to clear up whatever RegEx node internals may have run between two REPL entries if that makes sense.
- The user enters a regex operation, and hit ENTER to eval their entry.
- Node.js internals run other regex operations that overrides
RegExpstatics. - The user expect to find
RegExpstatics in the same state their original operation should have left them.
I think that works for
RegExp.$1toRegExp.$9, but not the other ones. Not sure this could be achieve without re-running the user code.Node.js internals run other regex operations that overrides RegExp statics.
If we use primordial
SafeRegExpwe can avoid this side effect?Using
SafeRegExpis not very practical because that would mean we can no longer use regex literals in core. Trying to migrate all of core toSafeRegExpseems like an unreasonable amount of work.From my point of view #20549 (comment) and #20549 (comment) is a good TL;DR for this thread. I'd say let's try this approach and run benchmark to see how it performs. IMO it would be worth creating a
SafeRegExpclass in primordials rather than thegetInternalGlobalhack.I wonder if ShadowRealms integration gives a new solution to this problem, allowing us to run REPL code on another Realm sounds like something that should also fix the issue. Should we move this discussion to #18931 since only the REPL is at stake now?
Isn't
RegExp.$_a standard web-compatibility legacy feature? Spec wise are we safe to remove and not support it?It's implemented by V8, I'm sure we can easily disable it – but yes, as far as ECMAScript is concerned, it doesn't exist.
6 remaining items
- added a commit that references this issue
on Aug 4, 2022 - added a commit that references this issue
on Aug 5, 2022 - added a commit that references this issue
on Aug 23, 2022 - added 2 commits that reference this issue
on Sep 23, 2022 - added 5 commits that reference this issue
on Oct 3, 2022 - added 2 commits that reference this issue
on Jan 3, 2023
Version
v18.5.0
Platform
n/a
Subsystem
No response
What steps will reproduce the bug?
node -pe 'RegExp.$_'will print outWeakRef.node, and thenRegExp.$_, will print out'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.This also applies to
$&.How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
I expect the empty string for all RegExp statics.
This is a problem for a few reasons:
If there's a point, right before node starts running user code, and right before the repl becomes available, then we could execute a trivial regular expression operation to clear all the statics.
Alternatively, this may be exposing non-primordial regex usage, and it's likely that switching to primordials (since I believe they'd update the statics on the primordial RegExp instead of the global RegExp) would solve this as well.
Additional information
No response