jscript: Moved set_last_index call to do_regexp_match_next.

This commit is contained in:
Jacek Caban 2009-12-08 01:13:11 +01:00 committed by Alexandre Julliard
parent 91d62162da
commit c665b86cd0
2 changed files with 34 additions and 10 deletions

View File

@ -3301,6 +3301,13 @@ static inline RegExpInstance *regexp_from_vdisp(vdisp_t *vdisp)
return (RegExpInstance*)vdisp->u.jsdisp;
}
static void set_last_index(RegExpInstance *This, DWORD last_index)
{
This->last_index = last_index;
VariantClear(&This->last_index_var);
num_set_val(&This->last_index_var, last_index);
}
static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, const WCHAR *str, DWORD len,
const WCHAR **cp, match_result_t **parens, DWORD *parens_size, DWORD *parens_cnt, match_result_t *ret)
{
@ -3363,6 +3370,7 @@ static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, c
*cp = result->cp;
ret->str = result->cp-matchlen;
ret->len = matchlen;
set_last_index(regexp, result->cp-str);
return S_OK;
}
@ -3437,13 +3445,6 @@ HRESULT regexp_match(script_ctx_t *ctx, DispatchEx *dispex, const WCHAR *str, DW
return S_OK;
}
static void set_last_index(RegExpInstance *This, DWORD last_index)
{
This->last_index = last_index;
VariantClear(&This->last_index_var);
num_set_val(&This->last_index_var, last_index);
}
static HRESULT RegExp_source(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
@ -3657,7 +3658,6 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
}
if(hres == S_OK) {
set_last_index(regexp, cp-string);
*ret = VARIANT_TRUE;
}else {
set_last_index(regexp, 0);

View File

@ -96,10 +96,11 @@ ok(m[1] === "test", "m[1] = " + m[1]);
b = /a*/.test();
ok(b === true, "/a*/.test() returned " + b);
m = "abcabc".match(/ca/);
m = "abcabc".match(re = /ca/);
ok(typeof(m) === "object", "typeof m is not object");
ok(m.length === 1, "m.length is not 1");
ok(m["0"] === "ca", "m[0] is not \"ca\"");
ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex);
m = "abcabc".match(/ab/);
ok(typeof(m) === "object", "typeof m is not object");
@ -165,8 +166,9 @@ ok(m["0"] === "ab", "m[0] is not \"ab\"");
m = "abcabc".match();
ok(m === null, "m is not null");
r = "- [test] -".replace(/\[([^\[]+)\]/g, "success");
r = "- [test] -".replace(re = /\[([^\[]+)\]/g, "success");
ok(r === "- success -", "r = " + r + " expected '- success -'");
ok(re.lastIndex === 8, "re.lastIndex = " + re.lastIndex);
r = "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
ok(r === "aa aa", "r = " + r + "aa aa");
@ -285,6 +287,28 @@ ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
re = /,+/;
r = "1,,2,".split(re);
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
re = /,+/g;
r = "1,,2,".split(re);
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
re = /,+/;
re.lastIndex = 4;
r = "1,,2,".split(re);
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
re = /abc[^d]/g;
ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");