Regexp.rightContext was still not quite right. Fixed and
added more tests. Review URL: https://chromiumcodereview.appspot.com/10008104 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11312 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
f0ea13846d
commit
b32ff09a49
@ -204,6 +204,15 @@ macro CAPTURE(index) = (3 + (index));
|
||||
const CAPTURE0 = 3;
|
||||
const CAPTURE1 = 4;
|
||||
|
||||
# For the regexp capture override array. This has the same
|
||||
# format as the arguments to a function called from
|
||||
# String.prototype.replace.
|
||||
macro OVERRIDE_MATCH(override) = ((override)[0]);
|
||||
macro OVERRIDE_POS(override) = ((override)[(override).length - 2]);
|
||||
macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
|
||||
# 1-based so index of 1 returns the first capture
|
||||
macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
|
||||
|
||||
# PropertyDescriptor return value indices - must match
|
||||
# PropertyDescriptorIndices in runtime.cc.
|
||||
const IS_ACCESSOR_INDEX = 0;
|
||||
|
@ -296,7 +296,7 @@ function RegExpToString() {
|
||||
// of the last successful match.
|
||||
function RegExpGetLastMatch() {
|
||||
if (lastMatchInfoOverride !== null) {
|
||||
return lastMatchInfoOverride[0];
|
||||
return OVERRIDE_MATCH(lastMatchInfoOverride);
|
||||
}
|
||||
var regExpSubject = LAST_SUBJECT(lastMatchInfo);
|
||||
return SubString(regExpSubject,
|
||||
@ -334,8 +334,8 @@ function RegExpGetLeftContext() {
|
||||
subject = LAST_SUBJECT(lastMatchInfo);
|
||||
} else {
|
||||
var override = lastMatchInfoOverride;
|
||||
start_index = override[override.length - 2];
|
||||
subject = override[override.length - 1];
|
||||
start_index = OVERRIDE_POS(override);
|
||||
subject = OVERRIDE_SUBJECT(override);
|
||||
}
|
||||
return SubString(subject, 0, start_index);
|
||||
}
|
||||
@ -349,9 +349,9 @@ function RegExpGetRightContext() {
|
||||
subject = LAST_SUBJECT(lastMatchInfo);
|
||||
} else {
|
||||
var override = lastMatchInfoOverride;
|
||||
subject = override[override.length - 1];
|
||||
var pattern = override[override.length - 3];
|
||||
start_index = override[override.length - 2] + pattern.length;
|
||||
subject = OVERRIDE_SUBJECT(override);
|
||||
var match = OVERRIDE_MATCH(override);
|
||||
start_index = OVERRIDE_POS(override) + match.length;
|
||||
}
|
||||
return SubString(subject, start_index, subject.length);
|
||||
}
|
||||
@ -363,7 +363,9 @@ function RegExpGetRightContext() {
|
||||
function RegExpMakeCaptureGetter(n) {
|
||||
return function() {
|
||||
if (lastMatchInfoOverride) {
|
||||
if (n < lastMatchInfoOverride.length - 2) return lastMatchInfoOverride[n];
|
||||
if (n < lastMatchInfoOverride.length - 2) {
|
||||
return OVERRIDE_CAPTURE(lastMatchInfoOverride, n);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
var index = n * 2;
|
||||
|
@ -25,6 +25,64 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"abcd".replace(/b/g, function() { });
|
||||
function oneMatch(re) {
|
||||
"abcd".replace(re, function() { });
|
||||
assertEquals("abcd", RegExp.input);
|
||||
assertEquals("a", RegExp.leftContext);
|
||||
assertEquals("b", RegExp.lastMatch);
|
||||
assertEquals("", RegExp.lastParen);
|
||||
assertEquals(undefined, RegExp.lastIndex);
|
||||
assertEquals(undefined, RegExp.index);
|
||||
assertEquals("cd", RegExp.rightContext);
|
||||
for (var i = 1; i < 10; i++) {
|
||||
assertEquals("", RegExp['$' + i]);
|
||||
}
|
||||
}
|
||||
|
||||
oneMatch(/b/);
|
||||
oneMatch(/b/g);
|
||||
|
||||
"abcdabcd".replace(/b/g, function() { });
|
||||
assertEquals("abcdabcd", RegExp.input);
|
||||
assertEquals("abcda", RegExp.leftContext);
|
||||
assertEquals("b", RegExp.lastMatch);
|
||||
assertEquals("", RegExp.lastParen);
|
||||
assertEquals(undefined, RegExp.lastIndex);
|
||||
assertEquals(undefined, RegExp.index);
|
||||
assertEquals("cd", RegExp.rightContext);
|
||||
for (var i = 1; i < 10; i++) {
|
||||
assertEquals("", RegExp['$' + i]);
|
||||
}
|
||||
|
||||
function captureMatch(re) {
|
||||
"abcd".replace(re, function() { });
|
||||
assertEquals("abcd", RegExp.input);
|
||||
assertEquals("a", RegExp.leftContext);
|
||||
assertEquals("bc", RegExp.lastMatch);
|
||||
assertEquals("c", RegExp.lastParen);
|
||||
assertEquals(undefined, RegExp.lastIndex);
|
||||
assertEquals(undefined, RegExp.index);
|
||||
assertEquals("d", RegExp.rightContext);
|
||||
assertEquals('b', RegExp.$1);
|
||||
assertEquals('c', RegExp.$2);
|
||||
for (var i = 3; i < 10; i++) {
|
||||
assertEquals("", RegExp['$' + i]);
|
||||
}
|
||||
}
|
||||
|
||||
captureMatch(/(b)(c)/);
|
||||
captureMatch(/(b)(c)/g);
|
||||
|
||||
"abcdabcd".replace(/(b)(c)/g, function() { });
|
||||
assertEquals("abcdabcd", RegExp.input);
|
||||
assertEquals("abcda", RegExp.leftContext);
|
||||
assertEquals("bc", RegExp.lastMatch);
|
||||
assertEquals("c", RegExp.lastParen);
|
||||
assertEquals(undefined, RegExp.lastIndex);
|
||||
assertEquals(undefined, RegExp.index);
|
||||
assertEquals("d", RegExp.rightContext);
|
||||
assertEquals('b', RegExp.$1);
|
||||
assertEquals('c', RegExp.$2);
|
||||
for (var i = 3; i < 10; i++) {
|
||||
assertEquals("", RegExp['$' + i]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user