jscript: Add index, input and lastIndex properties to regexp functions results.
This commit is contained in:
parent
dcdc6c7013
commit
b9b11c6c67
|
@ -3590,6 +3590,7 @@ static HRESULT create_match_array(script_ctx_t *ctx, BSTR input, const match_res
|
|||
|
||||
static const WCHAR indexW[] = {'i','n','d','e','x',0};
|
||||
static const WCHAR inputW[] = {'i','n','p','u','t',0};
|
||||
static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
|
||||
static const WCHAR zeroW[] = {'0',0};
|
||||
|
||||
hres = create_array(ctx, parens_cnt+1, &array);
|
||||
|
@ -3617,6 +3618,11 @@ static HRESULT create_match_array(script_ctx_t *ctx, BSTR input, const match_res
|
|||
if(FAILED(hres))
|
||||
break;
|
||||
|
||||
V_I4(&var) = result->str-input+result->len;
|
||||
hres = jsdisp_propput_name(array, lastIndexW, &var, ei, NULL/*FIXME*/);
|
||||
if(FAILED(hres))
|
||||
break;
|
||||
|
||||
V_VT(&var) = VT_BSTR;
|
||||
V_BSTR(&var) = input;
|
||||
hres = jsdisp_propput_name(array, inputW, &var, ei, NULL/*FIXME*/);
|
||||
|
@ -3918,6 +3924,10 @@ HRESULT create_regexp_var(script_ctx_t *ctx, VARIANT *src_arg, VARIANT *flags_ar
|
|||
HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
|
||||
VARIANT *retv, jsexcept_t *ei)
|
||||
{
|
||||
static const WCHAR indexW[] = {'i','n','d','e','x',0};
|
||||
static const WCHAR inputW[] = {'i','n','p','u','t',0};
|
||||
static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
|
||||
|
||||
RegExpInstance *regexp = (RegExpInstance*)re;
|
||||
match_result_t *match_result;
|
||||
DWORD match_cnt, i, length;
|
||||
|
@ -3985,6 +3995,24 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
|
|||
break;
|
||||
}
|
||||
|
||||
while(SUCCEEDED(hres)) {
|
||||
V_VT(&var) = VT_I4;
|
||||
V_I4(&var) = match_result[match_cnt-1].str-str;
|
||||
hres = jsdisp_propput_name(array, indexW, &var, ei, NULL/*FIXME*/);
|
||||
if(FAILED(hres))
|
||||
break;
|
||||
|
||||
V_I4(&var) = match_result[match_cnt-1].str-str+match_result[match_cnt-1].len;
|
||||
hres = jsdisp_propput_name(array, lastIndexW, &var, ei, NULL/*FIXME*/);
|
||||
if(FAILED(hres))
|
||||
break;
|
||||
|
||||
V_VT(&var) = VT_BSTR;
|
||||
V_BSTR(&var) = str;
|
||||
hres = jsdisp_propput_name(array, inputW, &var, ei, NULL/*FIXME*/);
|
||||
break;
|
||||
}
|
||||
|
||||
heap_free(match_result);
|
||||
|
||||
if(SUCCEEDED(hres) && retv)
|
||||
|
|
|
@ -50,6 +50,7 @@ ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
|
|||
m = re.exec(" aabaaa");
|
||||
ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
|
||||
ok(m.index === 1, "m.index = " + m.index);
|
||||
ok(m.lastIndex == 3, "m.lastIndex = " + m.lastIndex);
|
||||
ok(m.input === " aabaaa", "m.input = " + m.input);
|
||||
ok(m.length === 1, "m.length = " + m.length);
|
||||
ok(m[0] === "aa", "m[0] = " + m[0]);
|
||||
|
@ -194,6 +195,9 @@ ok(typeof(m) === "object", "typeof m is not object");
|
|||
ok(m.length === 2, "m.length is not 2");
|
||||
ok(m["0"] === "ab", "m[0] is not \"ab\"");
|
||||
ok(m["1"] === "ab", "m[1] is not \"ab\"");
|
||||
ok(m.index === 3, "m.index = " + m.index);
|
||||
ok(m.input === "abcabc", "m.input = " + m.input);
|
||||
ok(m.lastIndex === 5, "m.lastIndex = " + m.lastIndex);
|
||||
|
||||
m = "abcabcg".match("ab", "g");
|
||||
ok(typeof(m) === "object", "typeof m is not object");
|
||||
|
|
Loading…
Reference in New Issue