Closed
Bug 887676
Opened 11 years ago
Closed 11 years ago
RegExp lastIndex not set to 0 after exec() doesn't match
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
mozilla25
People
(Reporter: tashmore, Assigned: sstangl)
References
(Depends on 1 open bug)
Details
Attachments
(1 file)
1.61 KB,
patch
|
Waldo
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0 (Beta/Release) Build ID: 20130511120803 Steps to reproduce: In SpiderMonkey v1.8.5, I had the following session: js> r = /a/ /a/ js> r.lastIndex = 999 999 js> r.exec('bc') null js> r.lastIndex 999 js> Actual results: Even though the "exec" call returns null, the "r.lastIndex" property is unchanged (999). This behavior contradicts the ECMA standards on regular expressions. Expected results: According to ECMA-262 section 15.10.6.2, the "r.lastIndex" property should be 0.
Comment 1•11 years ago
|
||
Duplicate of bug 501739?
Comment 2•11 years ago
|
||
No, this is not about the _global_ RegExp.lastIndex.
Comment 3•11 years ago
|
||
Yeah, my initial skim of the algorithm says the bug report's totally valid. Which is crazy, because haven't we touched this and looked at it more than a few times recently? :-) But it's what I'm seeing at a quick glance. I'm happy to take this if we're fine waiting til the Intl API is enabled in desktop builds -- otherwise someone else should grab.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee | ||
Comment 4•11 years ago
|
||
I'll grab, since I looked at regexp code recently. Thanks for reporting.
Assignee: general → sstangl
Comment 5•11 years ago
|
||
Isn't that exactly what this message is about? https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine.internals/T0B9VBa8byI It seems to have been a deliberate change in bug 646490.
Assignee | ||
Comment 6•11 years ago
|
||
As Till pointed out, this does appear to be deliberate behavior. On the other hand, my reading of 15.10.6.2 does suggest that the deliberate behavior is wrong. This patch implements the change -- I'll leave it to Waldo to make a decision on how to interpret the specification.
Attachment #768667 -
Flags: review?(jwalden+bmo)
Any update on whether this deviation from the spec is intentional?
Comment 8•11 years ago
|
||
Comment on attachment 768667 [details] [diff] [review] Always zero lastIndex upon failure to match. Review of attachment 768667 [details] [diff] [review]: ----------------------------------------------------------------- I *think* this change was just an oversight in that bug, given there's no discussion of this at all there. So this is a fine change. Dunno about the sticky-change here, but given we have no spec to follow there, whatever. :-\ ::: js/src/builtin/RegExp.cpp @@ +586,5 @@ > return RegExpRunStatus_Error; > > + /* Steps 9a and 11 (with sticky extension). */ > + if (status == RegExpRunStatus_Success_NotFound) > + reobj->zeroLastIndex(); It's unclear to me that the lastIndex should be zeroed if this is a sticky RegExp, when no more matches are found. Our own documentation trolls us here, providing a demo that stops *just short* of saying what should happen: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky Good times with non-standard, underspecified features as usual. (ES6 says nothing about the semantics of sticky RegExps yet, at least not in the draft I have.) Be on the lookout for this change, as concerns sticky RegExps specifically, breaking some extension or another.
Attachment #768667 -
Flags: review?(jwalden+bmo) → review+
Assignee | ||
Comment 9•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/3b678c591bb5
Comment 10•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/3b678c591bb5
Status: NEW → RESOLVED
Closed: 11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
You need to log in
before you can comment on or make changes to this bug.
Description
•