diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index d74f8cf1e87..62cc6f0cda9 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -538,7 +538,7 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags VARIANT *retv, jsexcept_t *ei) { BSTR search_str, val_str; - DWORD length, pos, search_len; + DWORD length, pos = 0, search_len; const WCHAR *str; INT ret = -1; HRESULT hres; @@ -568,15 +568,13 @@ static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags if(arg_cnt(dp) >= 2) { VARIANT ival; + double d; hres = to_integer(ctx, get_arg(dp,1), ei, &ival); if(SUCCEEDED(hres)) { - if(V_VT(&ival) == VT_I4) - pos = V_VT(&ival) > 0 ? V_I4(&ival) : 0; - else - pos = V_R8(&ival) > 0.0 ? length : 0; - if(pos > length) - pos = length; + d = num_val(&ival); + if(d > 0) + pos = is_int32(d) ? min((int)d, length) : length; } }else { pos = length; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 8d8e819853f..b25f0ae92bb 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -496,6 +496,8 @@ tmp = "aaaa".lastIndexOf("a",2); ok(tmp == 2, "lastIndexOf = " + tmp); tmp = strObj.lastIndexOf("b"); ok(tmp === 1, "lastIndexOf = " + tmp); +tmp = "bbb".lastIndexOf("b", bigInt); +ok(tmp === 2, "lastIndexOf = " + tmp); tmp = "".toLowerCase(); ok(tmp === "", "''.toLowerCase() = " + tmp);