Commit e3ae0243 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

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

parent a924e54c
......@@ -3637,12 +3637,13 @@ 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->jsregexp->flags & JSREG_GLOB) {
if(regexp->last_index < 0) {
SysFreeString(string);
set_last_index(regexp, 0);
......@@ -3653,9 +3654,8 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
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,
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment