jscript: Use special case for lastIndex<0 only for global regexps in run_exec.

This commit is contained in:
Jacek Caban 2010-04-15 12:38:05 +02:00 committed by Alexandre Julliard
parent a924e54c94
commit e3ae02433a
2 changed files with 26 additions and 13 deletions

View File

@ -3637,25 +3637,25 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
hres = to_string(ctx, arg, ei, &string);
if(FAILED(hres))
return hres;
length = SysStringLen(string);
}else {
string = SysAllocStringLen(NULL, 0);
if(!string)
return E_OUTOFMEMORY;
string = NULL;
length = 0;
}
if(regexp->last_index < 0) {
SysFreeString(string);
set_last_index(regexp, 0);
*ret = VARIANT_FALSE;
if(input) {
*input = NULL;
if(regexp->jsregexp->flags & JSREG_GLOB) {
if(regexp->last_index < 0) {
SysFreeString(string);
set_last_index(regexp, 0);
*ret = VARIANT_FALSE;
if(input) {
*input = NULL;
}
return S_OK;
}
return S_OK;
}
length = SysStringLen(string);
if(regexp->jsregexp->flags & JSREG_GLOB)
last_index = regexp->last_index;
}
cp = string + last_index;
hres = regexp_match_next(ctx, &regexp->dispex, REM_RESET_INDEX, string, length, &cp, parens,

View File

@ -410,6 +410,19 @@ m = re.exec(" ");
ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
ok(m === null, "m = " + m + " expected null");
re = /a/;
re.lastIndex = -3;
ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
m = re.exec(" a a ");
ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 0");
ok(m.index === 1, "m = " + m + " expected 1");
re.lastIndex = -1;
ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
m = re.exec(" ");
ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
ok(m === null, "m = " + m + " expected null");
re = /aa/g;
i = 'baacd'.search(re);
ok(i === 1, "'baacd'.search(re) = " + i);