Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up#627 broke RegExpBuiltinExec? #777
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Jan 23, 2017
Contributor
In PR #627, I had incorrectly removed a “useless” read access to the lastIndex property for non-global-and-non-sticky regexps, not noticing that the apparently innocuous ToLength() operation may in fact produce a regexp recompilation!
The proper fix is probably to revert that part of the PR, i.e.:
1. Assert: _R_ is an initialized RegExp instance.
1. Assert: Type(_S_) is String.
1. Let _length_ be the number of code units in _S_.
+ 1. Let _lastIndex_ be ? ToLength(? Get(_R_, `"lastIndex"`)).
1. Let _flags_ be _R_.[[OriginalFlags]].
1. If _flags_ contains `"g"`, let _global_ be *true*, else let _global_ be *false*.
1. If _flags_ contains `"y"`, let _sticky_ be *true*, else let _sticky_ be *false*.
1. If _global_ is *false* and _sticky_ is *false*, let _lastIndex_ be 0.
- 1. Else, let _lastIndex_ be ? ToLength(? Get(_R_, `"lastIndex"`)).
1. Let _matcher_ be _R_.[[RegExpMatcher]].
1. If _flags_ contains `"u"`, let _fullUnicode_ be *true*, else let _fullUnicode_ be *false*.
1. Let _matchSucceeded_ be *false*.|
In PR #627, I had incorrectly removed a “useless” read access to the The proper fix is probably to revert that part of the PR, i.e.: 1. Assert: _R_ is an initialized RegExp instance.
1. Assert: Type(_S_) is String.
1. Let _length_ be the number of code units in _S_.
+ 1. Let _lastIndex_ be ? ToLength(? Get(_R_, `"lastIndex"`)).
1. Let _flags_ be _R_.[[OriginalFlags]].
1. If _flags_ contains `"g"`, let _global_ be *true*, else let _global_ be *false*.
1. If _flags_ contains `"y"`, let _sticky_ be *true*, else let _sticky_ be *false*.
1. If _global_ is *false* and _sticky_ is *false*, let _lastIndex_ be 0.
- 1. Else, let _lastIndex_ be ? ToLength(? Get(_R_, `"lastIndex"`)).
1. Let _matcher_ be _R_.[[RegExpMatcher]].
1. If _flags_ contains `"u"`, let _fullUnicode_ be *true*, else let _fullUnicode_ be *false*.
1. Let _matchSucceeded_ be *false*. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Jan 23, 2017
Contributor
In PR #627, I had incorrectly removed a “useless” read access to the lastIndex property for non-global-and-non-sticky regexps, not noticing that the apparently innocuous ToLength() operation may in fact produce a regexp recompilation!
I thought that part was required for #627, but if that's not the case, your fix is certainly the way to go!
I thought that part was required for #627, but if that's not the case, your fix is certainly the way to go! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Jan 23, 2017
Contributor
I thought that part was required for #627
It was not. The motivation was Issue #625, and the required part is avoiding unnecessary writing to the lastIndex property.
In ”reasonable” situations, uselessly reading the lastIndex property has zero side-effect. I was just guilty of premature optimisation.
It was not. The motivation was Issue #625, and the required part is avoiding unnecessary writing to the In ”reasonable” situations, uselessly reading the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
cc @schuay |
anba commentedJan 23, 2017
From https://bugzilla.mozilla.org/show_bug.cgi?id=1317397#c1:
The obvious band-aid fix is:
But I'm not sure that's the correct way to fix this bug.
(If anyone wonders why global and sticky are also reset, that's to avoid regressing #494, #489.)