jscript: Treat no argument as "undefined" in RegExp.test.

This commit is contained in:
Jacek Caban 2010-05-26 19:17:58 +02:00 committed by Alexandre Julliard
parent 0acb7fb1e4
commit fe86330d7e
2 changed files with 20 additions and 1 deletions

View File

@ -101,6 +101,7 @@ static const WCHAR leftContextW[] =
static const WCHAR rightContextW[] = static const WCHAR rightContextW[] =
{'r','i','g','h','t','C','o','n','t','e','x','t',0}; {'r','i','g','h','t','C','o','n','t','e','x','t',0};
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
static const WCHAR emptyW[] = {0}; static const WCHAR emptyW[] = {0};
/* FIXME: Better error handling */ /* FIXME: Better error handling */
@ -3717,12 +3718,24 @@ static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPP
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
match_result_t match; match_result_t match;
VARIANT undef_var;
VARIANT_BOOL b; VARIANT_BOOL b;
DWORD argc;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
hres = run_exec(ctx, jsthis, arg_cnt(dp) ? get_arg(dp,0) : NULL, ei, NULL, &match, NULL, NULL, &b); argc = arg_cnt(dp);
if(!argc) {
V_VT(&undef_var) = VT_BSTR;
V_BSTR(&undef_var) = SysAllocString(undefinedW);
if(!V_BSTR(&undef_var))
return E_OUTOFMEMORY;
}
hres = run_exec(ctx, jsthis, argc ? get_arg(dp,0) : &undef_var, ei, NULL, &match, NULL, NULL, &b);
if(!argc)
SysFreeString(V_BSTR(&undef_var));
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;

View File

@ -96,6 +96,12 @@ ok(m[1] === "test", "m[1] = " + m[1]);
b = /a*/.test(); b = /a*/.test();
ok(b === true, "/a*/.test() returned " + b); ok(b === true, "/a*/.test() returned " + b);
b = /f/.test();
ok(b === true, "/f/.test() returned " + b);
b = /abc/.test();
ok(b === false, "/abc/.test() returned " + b);
m = "abcabc".match(re = /ca/); m = "abcabc".match(re = /ca/);
ok(typeof(m) === "object", "typeof m is not object"); ok(typeof(m) === "object", "typeof m is not object");
ok(m.length === 1, "m.length is not 1"); ok(m.length === 1, "m.length is not 1");