Jacek Caban : jscript: Added RegExp contruction implementation.

Alexandre Julliard julliard at winehq.org
Wed Sep 24 08:48:43 CDT 2008


Module: wine
Branch: master
Commit: 98f2dfee9cabde7fd62d11cd2850d608ec055aca
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=98f2dfee9cabde7fd62d11cd2850d608ec055aca

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 24 01:48:37 2008 +0200

jscript: Added RegExp contruction implementation.

---

 dlls/jscript/global.c        |    2 +-
 dlls/jscript/regexp.c        |   74 ++++++++++++++++++++++++++++++++++++++++-
 dlls/jscript/tests/regexp.js |   24 +++++++++++++
 3 files changed, 97 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index adee371..30e2bd5 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -426,7 +426,7 @@ static HRESULT init_constructors(script_ctx_t *ctx)
     if(FAILED(hres))
         return hres;
 
-    hres = create_object_constr(ctx, &ctx->regexp_constr);
+    hres = create_regexp_constr(ctx, &ctx->regexp_constr);
     if(FAILED(hres))
         return hres;
 
diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c
index 863b52e..e811e48 100644
--- a/dlls/jscript/regexp.c
+++ b/dlls/jscript/regexp.c
@@ -3546,11 +3546,81 @@ static HRESULT create_regexp(script_ctx_t *ctx, const WCHAR *exp, int len, DWORD
     return S_OK;
 }
 
+static HRESULT regexp_constructor(script_ctx_t *ctx, DISPPARAMS *dp, VARIANT *retv)
+{
+    const WCHAR *opt = emptyW, *src;
+    DispatchEx *ret;
+    VARIANT *arg;
+    HRESULT hres;
+
+    if(!arg_cnt(dp)) {
+        FIXME("no args\n");
+        return E_NOTIMPL;
+    }
+
+    arg = get_arg(dp,0);
+    if(V_VT(arg) == VT_DISPATCH) {
+        DispatchEx *obj;
+
+        obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
+        if(obj) {
+            if(is_class(obj, JSCLASS_REGEXP)) {
+                RegExpInstance *regexp = (RegExpInstance*)obj;
+
+                hres = create_regexp(ctx, regexp->str, -1, regexp->jsregexp->flags, &ret);
+                jsdisp_release(obj);
+                if(FAILED(hres))
+                    return hres;
+
+                V_VT(retv) = VT_DISPATCH;
+                V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
+                return S_OK;
+            }
+
+            jsdisp_release(obj);
+        }
+    }
+
+    if(V_VT(arg) != VT_BSTR) {
+        FIXME("vt arg0 = %d\n", V_VT(arg));
+        return E_NOTIMPL;
+    }
+
+    src = V_BSTR(arg);
+
+    if(arg_cnt(dp) >= 2) {
+        arg = get_arg(dp,1);
+        if(V_VT(arg) != VT_BSTR) {
+            FIXME("unimplemented for vt %d\n", V_VT(arg));
+            return E_NOTIMPL;
+        }
+
+        opt = V_BSTR(arg);
+    }
+
+    hres = create_regexp_str(ctx, src, -1, opt, strlenW(opt), &ret);
+    if(FAILED(hres))
+        return hres;
+
+    V_VT(retv) = VT_DISPATCH;
+    V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
+    return S_OK;
+}
+
 static HRESULT RegExpConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    TRACE("\n");
+
+    switch(flags) {
+    case DISPATCH_CONSTRUCT:
+        return regexp_constructor(dispex->ctx, dp, retv);
+    default:
+        FIXME("unimplemented flags: %x\n", flags);
+        return E_NOTIMPL;
+    }
+
+    return S_OK;
 }
 
 HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx **ret)
diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js
index 209ee22..13ce8a2 100644
--- a/dlls/jscript/tests/regexp.js
+++ b/dlls/jscript/tests/regexp.js
@@ -51,4 +51,28 @@ ok(m.length === 2, "m.length is not 1");
 ok(m["0"] === "aaab", "m[0] is not \"ab\"");
 ok(m["1"] === "ab", "m[1] is not \"ab\"");
 
+m = "abcabc".match(new RegExp("ab"));
+ok(typeof(m) === "object", "typeof m is not object");
+ok(m.length === 1, "m.length is not 1");
+ok(m["0"] === "ab", "m[0] is not \"ab\"");
+
+/*
+m = "abcabc".match(new RegExp("ab","g"));
+ok(typeof(m) === "object", "typeof m is not object");
+ok(m.length === 2, "m.length is not 1");
+ok(m["0"] === "ab", "m[0] is not \"ab\"");
+ok(m["1"] === "ab", "m[1] is not \"ab\"");
+
+m = "abcabc".match(new RegExp(/ab/g));
+ok(typeof(m) === "object", "typeof m is not object");
+ok(m.length === 2, "m.length is not 1");
+ok(m["0"] === "ab", "m[0] is not \"ab\"");
+ok(m["1"] === "ab", "m[1] is not \"ab\"");
+
+m = "abcabc".match(new RegExp("ab","g", "test"));
+ok(typeof(m) === "object", "typeof m is not object");
+ok(m.length === 2, "m.length is not 1");
+ok(m["0"] === "ab", "m[0] is not \"ab\"");
+ok(m["1"] === "ab", "m[1] is not \"ab\"");
+*/
 reportSuccess();




More information about the wine-cvs mailing list