From f34722e772303c30c3ce0eac1d3ee2e445762809 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 27 May 2013 13:57:07 +0200 Subject: [PATCH] jscript: Added RegExp.toString() implementation. --- dlls/jscript/jsregexp.c | 46 ++++++++++++++++++++++++++++++++++-- dlls/jscript/tests/regexp.js | 12 ++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/jsregexp.c b/dlls/jscript/jsregexp.c index 0104f3ea5ff..d6602f4b7ed 100644 --- a/dlls/jscript/jsregexp.c +++ b/dlls/jscript/jsregexp.c @@ -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, diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js index 69aa6b77afe..25ec91e075c 100644 --- a/dlls/jscript/tests/regexp.js +++ b/dlls/jscript/tests/regexp.js @@ -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();