The Spidermonkey test suite contains the following test (in file
ecma_5/RegExp/exec.js):
r = /abc/;
r.lastIndex = -17;
res = r.exec("cdefg");
assertEq(res, null);
assertEq(r.lastIndex, -17);
In my understanding this test is wrong, lastIndex should be 0 due to step
9.a.(i). Safari and Firefox report -17, Chrome and IE report 0. I guess it is a
tricky part of the spec as most real world implementations will move the
iteration of step 9 into the [[Match]] routine as to enable first character
optimizations and alike. The correct behavior is not covered in test262.
Recommend to add the following test:
/*
* @es5id 15.10.6.2 (step 9.a.i)
* @description If the pattern does not match, lastIndex is always set to 0,
even if the 'global' flag is false.
*/
function testCase()
{
var r = /abc/;
r.lastIndex = -17;
res = r.exec("defg");
return r.lastIndex===0;
}
Note that the original Spidermonkey test is in the public domain, according to
the file header. This post is also placed in the public domain.
Paul
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals