Jacek Caban : jscript: Added String. match implementation for non-regexp arguments.

Alexandre Julliard julliard at winehq.org
Thu Sep 25 07:13:28 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Sep 25 00:53:53 2008 +0200

jscript: Added String.match implementation for non-regexp arguments.

---

 dlls/jscript/string.c     |   44 +++++++++++++++++++++++++-------------------
 dlls/jscript/tests/api.js |    5 +++++
 2 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index 12b6d1a..eb50624 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -354,6 +354,7 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
 {
     StringInstance *This = (StringInstance*)dispex;
     match_result_t *match_result;
+    DispatchEx *regexp;
     DispatchEx *array;
     VARIANT var, *arg_var;
     DWORD match_cnt, i;
@@ -361,33 +362,39 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
 
     TRACE("\n");
 
-    if(dp->cArgs - dp->cNamedArgs != 1) {
+    if(arg_cnt(dp) != 1) {
         FIXME("unsupported args\n");
         return E_NOTIMPL;
     }
 
     arg_var = get_arg(dp, 0);
     switch(V_VT(arg_var)) {
-    case VT_DISPATCH: {
-        DispatchEx *regexp;
-
+    case VT_DISPATCH:
         regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg_var));
         if(regexp) {
-            if(regexp->builtin_info->class == JSCLASS_REGEXP) {
-                hres = regexp_match(regexp, This->str, This->length, FALSE, &match_result, &match_cnt);
-                jsdisp_release(regexp);
-                if(FAILED(hres))
-                    return hres;
+            if(regexp->builtin_info->class == JSCLASS_REGEXP)
                 break;
-            }
             jsdisp_release(regexp);
         }
+    default: {
+        BSTR match_str;
+
+        hres = to_string(dispex->ctx, arg_var, ei, &match_str);
+        if(FAILED(hres))
+            return hres;
+
+        hres = create_regexp_str(dispex->ctx, match_str, SysStringLen(match_str), NULL, 0, &regexp);
+        SysFreeString(match_str);
+        if(FAILED(hres))
+            return hres;
     }
-    default:
-        FIXME("implemented only for regexp args\n");
-        return E_NOTIMPL;
     }
 
+    hres = regexp_match(regexp, This->str, This->length, FALSE, &match_result, &match_cnt);
+    jsdisp_release(regexp);
+    if(FAILED(hres))
+        return hres;
+
     if(!match_cnt) {
         TRACE("no match\n");
 
@@ -415,14 +422,13 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
             break;
     }
 
-    if(FAILED(hres)) {
+    if(SUCCEEDED(hres) && retv) {
+        V_VT(retv) = VT_DISPATCH;
+        V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
+    }else {
         jsdisp_release(array);
-        return hres;
     }
-
-    V_VT(retv) = VT_DISPATCH;
-    V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
-    return S_OK;
+    return hres;
 }
 
 typedef struct {
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 1281b25..aef7c2b 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -151,6 +151,11 @@ arr.concat = String.prototype.concat;
 tmp = arr.concat("d");
 ok(tmp === "2,ad", "arr.concat = " + tmp);
 
+m = "a+bcabc".match("a+");
+ok(typeof(m) === "object", "typeof m is not object");
+ok(m.length === 1, "m.length is not 1");
+ok(m["0"] === "a", "m[0] is not \"ab\"");
+
 r = "- [test] -".replace("[test]", "success");
 ok(r === "- success -", "r = " + r + " expected '- success -'");
 




More information about the wine-cvs mailing list