Jacek Caban : jscript: Use special case for lastIndex< 0 only for global regexps in run_exec.

Alexandre Julliard julliard at winehq.org
Thu Apr 15 11:37:36 CDT 2010


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Apr 15 12:38:05 2010 +0200

jscript: Use special case for lastIndex<0 only for global regexps in run_exec.

---

 dlls/jscript/regexp.c        |   26 +++++++++++++-------------
 dlls/jscript/tests/regexp.js |   13 +++++++++++++
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c
index e895603..a5d607e 100644
--- a/dlls/jscript/regexp.c
+++ b/dlls/jscript/regexp.c
@@ -3637,25 +3637,25 @@ static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexce
         hres = to_string(ctx, arg, ei, &string);
         if(FAILED(hres))
             return hres;
+        length = SysStringLen(string);
     }else {
-        string = SysAllocStringLen(NULL, 0);
-        if(!string)
-            return E_OUTOFMEMORY;
+        string = NULL;
+        length = 0;
     }
 
-    if(regexp->last_index < 0) {
-        SysFreeString(string);
-        set_last_index(regexp, 0);
-        *ret = VARIANT_FALSE;
-        if(input) {
-            *input = NULL;
+    if(regexp->jsregexp->flags & JSREG_GLOB) {
+        if(regexp->last_index < 0) {
+            SysFreeString(string);
+            set_last_index(regexp, 0);
+            *ret = VARIANT_FALSE;
+            if(input) {
+                *input = NULL;
+            }
+            return S_OK;
         }
-        return S_OK;
-    }
 
-    length = SysStringLen(string);
-    if(regexp->jsregexp->flags & JSREG_GLOB)
         last_index = regexp->last_index;
+    }
 
     cp = string + last_index;
     hres = regexp_match_next(ctx, &regexp->dispex, REM_RESET_INDEX, string, length, &cp, parens,
diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js
index fac1112..513e56e 100644
--- a/dlls/jscript/tests/regexp.js
+++ b/dlls/jscript/tests/regexp.js
@@ -410,6 +410,19 @@ m = re.exec("  ");
 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
 ok(m === null, "m = " + m + " expected null");
 
+re = /a/;
+re.lastIndex = -3;
+ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
+m = re.exec(" a a ");
+ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 0");
+ok(m.index === 1, "m = " + m + " expected 1");
+
+re.lastIndex = -1;
+ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
+m = re.exec("  ");
+ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
+ok(m === null, "m = " + m + " expected null");
+
 re = /aa/g;
 i = 'baacd'.search(re);
 ok(i === 1, "'baacd'.search(re) = " + i);




More information about the wine-cvs mailing list