Jacek Caban : jscript: Moved resetting lastIndex to do_regexp_match_next.

Alexandre Julliard julliard at winehq.org
Mon Jan 25 11:21:04 CST 2010


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sat Jan 23 23:57:55 2010 +0100

jscript: Moved resetting lastIndex to do_regexp_match_next.

---

 dlls/jscript/jscript.h       |    4 +++-
 dlls/jscript/regexp.c        |   33 ++++++++++++++++-----------------
 dlls/jscript/string.c        |    8 ++++----
 dlls/jscript/tests/regexp.js |    1 +
 4 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index a839067..95f5028 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -318,7 +318,9 @@ typedef struct {
     DWORD len;
 } match_result_t;
 
-HRESULT regexp_match_next(script_ctx_t*,DispatchEx*,BOOL,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
+#define REM_CHECK_GLOBAL 0x0001
+#define REM_RESET_INDEX  0x0002
+HRESULT regexp_match_next(script_ctx_t*,DispatchEx*,DWORD,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
         DWORD*,DWORD*,match_result_t*);
 HRESULT regexp_match(script_ctx_t*,DispatchEx*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*);
 HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*);
diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c
index 751fe41..0457545 100644
--- a/dlls/jscript/regexp.c
+++ b/dlls/jscript/regexp.c
@@ -3308,8 +3308,9 @@ static void set_last_index(RegExpInstance *This, DWORD last_index)
     num_set_val(&This->last_index_var, last_index);
 }
 
-static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, const WCHAR *str, DWORD len,
-        const WCHAR **cp, match_result_t **parens, DWORD *parens_size, DWORD *parens_cnt, match_result_t *ret)
+static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, DWORD rem_flags,
+        const WCHAR *str, DWORD len, const WCHAR **cp, match_result_t **parens, DWORD *parens_size,
+        DWORD *parens_cnt, match_result_t *ret)
 {
     REMatchState *x, *result;
     REGlobalData gData;
@@ -3334,8 +3335,11 @@ static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, c
         return E_FAIL;
     }
 
-    if(!result)
+    if(!result) {
+        if(rem_flags & REM_RESET_INDEX)
+            set_last_index(regexp, 0);
         return S_FALSE;
+    }
 
     if(parens) {
         DWORD i;
@@ -3375,19 +3379,20 @@ static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, c
     return S_OK;
 }
 
-HRESULT regexp_match_next(script_ctx_t *ctx, DispatchEx *dispex, BOOL gcheck, const WCHAR *str, DWORD len,
-        const WCHAR **cp, match_result_t **parens, DWORD *parens_size, DWORD *parens_cnt, match_result_t *ret)
+HRESULT regexp_match_next(script_ctx_t *ctx, DispatchEx *dispex, DWORD rem_flags, const WCHAR *str,
+        DWORD len, const WCHAR **cp, match_result_t **parens, DWORD *parens_size, DWORD *parens_cnt,
+        match_result_t *ret)
 {
     RegExpInstance *regexp = (RegExpInstance*)dispex;
     jsheap_t *mark;
     HRESULT hres;
 
-    if(gcheck && !(regexp->jsregexp->flags & JSREG_GLOB))
+    if((rem_flags & REM_CHECK_GLOBAL) && !(regexp->jsregexp->flags & JSREG_GLOB))
         return S_FALSE;
 
     mark = jsheap_mark(&ctx->tmp_heap);
 
-    hres = do_regexp_match_next(ctx, regexp, str, len, cp, parens, parens_size, parens_cnt, ret);
+    hres = do_regexp_match_next(ctx, regexp, rem_flags, str, len, cp, parens, parens_size, parens_cnt, ret);
 
     jsheap_clear(mark);
     return hres;
@@ -3406,7 +3411,7 @@ HRESULT regexp_match(script_ctx_t *ctx, DispatchEx *dispex, const WCHAR *str, DW
     mark = jsheap_mark(&ctx->tmp_heap);
 
     while(1) {
-        hres = do_regexp_match_next(ctx, This, str, len, &cp, NULL, NULL, NULL, &cres);
+        hres = do_regexp_match_next(ctx, This, 0, str, len, &cp, NULL, NULL, NULL, &cres);
         if(hres == S_FALSE) {
             hres = S_OK;
             break;
@@ -3653,20 +3658,14 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
         last_index = regexp->last_index;
 
     cp = string + last_index;
-    hres = regexp_match_next(ctx, &regexp->dispex, FALSE, string, length, &cp, parens, parens ? &parens_size : NULL,
-            parens_cnt, match);
+    hres = regexp_match_next(ctx, &regexp->dispex, REM_RESET_INDEX, string, length, &cp, parens,
+            parens ? &parens_size : NULL, parens_cnt, match);
     if(FAILED(hres)) {
         SysFreeString(string);
         return hres;
     }
 
-    if(hres == S_OK) {
-        *ret = VARIANT_TRUE;
-    }else {
-        set_last_index(regexp, 0);
-        *ret = VARIANT_FALSE;
-    }
-
+    *ret = hres == S_OK ? VARIANT_TRUE : VARIANT_FALSE;
     if(input) {
         *input = string;
     }else {
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index 31e73a0..df43fee 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -820,7 +820,7 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
     DispatchEx *rep_func = NULL, *regexp = NULL;
     match_result_t *parens = NULL, match, **parens_ptr = &parens;
     strbuf_t ret = {NULL,0,0};
-    BOOL gcheck = FALSE;
+    DWORD re_flags = 0;
     VARIANT *arg_var;
     HRESULT hres = S_OK;
 
@@ -897,9 +897,9 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
 
         while(1) {
             if(regexp) {
-                hres = regexp_match_next(ctx, regexp, gcheck, str, length, &cp, parens_ptr,
+                hres = regexp_match_next(ctx, regexp, re_flags, str, length, &cp, parens_ptr,
                         &parens_size, &parens_cnt, &match);
-                gcheck = TRUE;
+                re_flags = REM_CHECK_GLOBAL;
 
                 if(hres == S_FALSE) {
                     hres = S_OK;
@@ -1073,7 +1073,7 @@ static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
     }
 
     cp = str;
-    hres = regexp_match_next(ctx, regexp, FALSE, str, length, &cp, NULL, NULL, NULL, &match);
+    hres = regexp_match_next(ctx, regexp, REM_RESET_INDEX, str, length, &cp, NULL, NULL, NULL, &match);
     SysFreeString(val_str);
     jsdisp_release(regexp);
     if(FAILED(hres))
diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js
index 52a94ad..d09d787 100644
--- a/dlls/jscript/tests/regexp.js
+++ b/dlls/jscript/tests/regexp.js
@@ -433,6 +433,7 @@ re = /d/g;
 re.lastIndex = 1;
 i = 'abc'.search(re);
 ok(i === -1, "'abc'.search(/d/g) = " + i);
+ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
 
 i = 'abcdde'.search(/[df]/);
 ok(i === 3, "'abc'.search(/[df]/) = " + i);




More information about the wine-cvs mailing list