jscript: Added RegExp.toString() implementation.

This commit is contained in:
Jacek Caban 2013-05-27 13:57:07 +02:00 committed by Alexandre Julliard
parent 41fe35583d
commit f34722e772
2 changed files with 56 additions and 2 deletions

View File

@ -333,8 +333,50 @@ static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
RegExpInstance *regexp;
unsigned len, f;
jsstr_t *ret;
WCHAR *ptr;
TRACE("\n");
if(!is_vclass(jsthis, JSCLASS_REGEXP)) {
FIXME("Not a RegExp\n");
return E_NOTIMPL;
}
regexp = regexp_from_vdisp(jsthis);
if(!r)
return S_OK;
len = jsstr_length(regexp->str) + 2;
f = regexp->jsregexp->flags;
if(f & REG_FOLD)
len++;
if(f & REG_GLOB)
len++;
if(f & REG_MULTILINE)
len++;
ptr = jsstr_alloc_buf(len, &ret);
if(!ptr)
return E_OUTOFMEMORY;
*ptr++ = '/';
ptr += jsstr_flush(regexp->str, ptr);
*ptr++ = '/';
if(f & REG_FOLD)
*ptr++ = 'i';
if(f & REG_GLOB)
*ptr++ = 'g';
if(f & REG_MULTILINE)
*ptr++ = 'm';
*r = jsval_string(ret);
return S_OK;
}
static HRESULT create_match_array(script_ctx_t *ctx, jsstr_t *input_str,

View File

@ -648,4 +648,16 @@ ok(!("$10" in RegExp), "RegExp.$10 exists");
RegExp.$1 = "a";
ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);
ok(/abc/.toString() === "/abc/", "/abc/.toString() = " + /abc/.toString());
ok(/\//.toString() === "/\\//", "/\//.toString() = " + /\//.toString());
tmp = new RegExp("abc/");
ok(tmp.toString() === "/abc//", "(new RegExp(\"abc/\")).toString() = " + tmp.toString());
ok(/abc/g.toString() === "/abc/g", "/abc/g.toString() = " + /abc/g.toString());
ok(/abc/i.toString() === "/abc/i", "/abc/i.toString() = " + /abc/i.toString());
ok(/abc/ig.toString() === "/abc/ig", "/abc/ig.toString() = " + /abc/ig.toString());
ok(/abc/mgi.toString() === "/abc/igm", "/abc/mgi.toString() = " + /abc/mgi.toString());
tmp = new RegExp("abc/", "mgi");
ok(tmp.toString() === "/abc//igm", "(new RegExp(\"abc/\")).toString() = " + tmp.toString());
ok(/abc/.toString(1, false, "3") === "/abc/", "/abc/.toString(1, false, \"3\") = " + /abc/.toString());
reportSuccess();