Piotr Caban : jscript: Add index, input and lastIndex properties to regexp functions results.

Alexandre Julliard julliard at winehq.org
Tue Oct 19 13:03:48 CDT 2010


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Oct 19 13:54:48 2010 +0200

jscript: Add index, input and lastIndex properties to regexp functions results.

---

 dlls/jscript/regexp.c        |   28 ++++++++++++++++++++++++++++
 dlls/jscript/tests/regexp.js |    4 ++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c
index 5d75144..8edfd97 100644
--- a/dlls/jscript/regexp.c
+++ b/dlls/jscript/regexp.c
@@ -3590,6 +3590,7 @@ static HRESULT create_match_array(script_ctx_t *ctx, BSTR input, const match_res
 
     static const WCHAR indexW[] = {'i','n','d','e','x',0};
     static const WCHAR inputW[] = {'i','n','p','u','t',0};
+    static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
     static const WCHAR zeroW[] = {'0',0};
 
     hres = create_array(ctx, parens_cnt+1, &array);
@@ -3617,6 +3618,11 @@ static HRESULT create_match_array(script_ctx_t *ctx, BSTR input, const match_res
         if(FAILED(hres))
             break;
 
+        V_I4(&var) = result->str-input+result->len;
+        hres = jsdisp_propput_name(array, lastIndexW, &var, ei, NULL/*FIXME*/);
+        if(FAILED(hres))
+            break;
+
         V_VT(&var) = VT_BSTR;
         V_BSTR(&var) = input;
         hres = jsdisp_propput_name(array, inputW, &var, ei, NULL/*FIXME*/);
@@ -3918,6 +3924,10 @@ HRESULT create_regexp_var(script_ctx_t *ctx, VARIANT *src_arg, VARIANT *flags_ar
 HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
         VARIANT *retv, jsexcept_t *ei)
 {
+    static const WCHAR indexW[] = {'i','n','d','e','x',0};
+    static const WCHAR inputW[] = {'i','n','p','u','t',0};
+    static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
+
     RegExpInstance *regexp = (RegExpInstance*)re;
     match_result_t *match_result;
     DWORD match_cnt, i, length;
@@ -3985,6 +3995,24 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, BSTR str,
             break;
     }
 
+    while(SUCCEEDED(hres)) {
+        V_VT(&var) = VT_I4;
+        V_I4(&var) = match_result[match_cnt-1].str-str;
+        hres = jsdisp_propput_name(array, indexW, &var, ei, NULL/*FIXME*/);
+        if(FAILED(hres))
+            break;
+
+        V_I4(&var) = match_result[match_cnt-1].str-str+match_result[match_cnt-1].len;
+        hres = jsdisp_propput_name(array, lastIndexW, &var, ei, NULL/*FIXME*/);
+        if(FAILED(hres))
+            break;
+
+        V_VT(&var) = VT_BSTR;
+        V_BSTR(&var) = str;
+        hres = jsdisp_propput_name(array, inputW, &var, ei, NULL/*FIXME*/);
+        break;
+    }
+
     heap_free(match_result);
 
     if(SUCCEEDED(hres) && retv)
diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js
index 26919f9..4d513e0 100644
--- a/dlls/jscript/tests/regexp.js
+++ b/dlls/jscript/tests/regexp.js
@@ -50,6 +50,7 @@ ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
 m = re.exec(" aabaaa");
 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
 ok(m.index === 1, "m.index = " + m.index);
+ok(m.lastIndex == 3, "m.lastIndex = " + m.lastIndex);
 ok(m.input === " aabaaa", "m.input = " + m.input);
 ok(m.length === 1, "m.length = " + m.length);
 ok(m[0] === "aa", "m[0] = " + m[0]);
@@ -194,6 +195,9 @@ ok(typeof(m) === "object", "typeof m is not object");
 ok(m.length === 2, "m.length is not 2");
 ok(m["0"] === "ab", "m[0] is not \"ab\"");
 ok(m["1"] === "ab", "m[1] is not \"ab\"");
+ok(m.index === 3, "m.index = " + m.index);
+ok(m.input === "abcabc", "m.input = " + m.input);
+ok(m.lastIndex === 5, "m.lastIndex = " + m.lastIndex);
 
 m = "abcabcg".match("ab", "g");
 ok(typeof(m) === "object", "typeof m is not object");




More information about the wine-cvs mailing list