jscript: Support passing non-string pattern to RegExp constructor.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-06-05 18:26:11 +02:00 committed by Alexandre Julliard
parent ccd6b205fa
commit 4e8874930a
2 changed files with 39 additions and 18 deletions

View File

@ -674,7 +674,7 @@ HRESULT create_regexp_var(script_ctx_t *ctx, jsval_t src_arg, jsval_t *flags_arg
unsigned flags, opt_len = 0; unsigned flags, opt_len = 0;
const WCHAR *opt = NULL; const WCHAR *opt = NULL;
jsstr_t *src; jsstr_t *src;
HRESULT hres; HRESULT hres = S_OK;
if(is_object_instance(src_arg)) { if(is_object_instance(src_arg)) {
jsdisp_t *obj; jsdisp_t *obj;
@ -693,12 +693,12 @@ HRESULT create_regexp_var(script_ctx_t *ctx, jsval_t src_arg, jsval_t *flags_arg
} }
} }
if(!is_string(src_arg)) { if(is_undefined(src_arg))
FIXME("src_arg = %s\n", debugstr_jsval(src_arg)); src = jsstr_empty();
return E_NOTIMPL; else
} hres = to_string(ctx, src_arg, &src);
if(FAILED(hres))
src = get_string(src_arg); return hres;
if(flags_arg) { if(flags_arg) {
jsstr_t *opt_str; jsstr_t *opt_str;
@ -710,16 +710,18 @@ HRESULT create_regexp_var(script_ctx_t *ctx, jsval_t src_arg, jsval_t *flags_arg
opt_str = get_string(*flags_arg); opt_str = get_string(*flags_arg);
opt = jsstr_flatten(opt_str); opt = jsstr_flatten(opt_str);
if(!opt) if(!opt) {
jsstr_release(src);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}
opt_len = jsstr_length(opt_str); opt_len = jsstr_length(opt_str);
} }
hres = parse_regexp_flags(opt, opt_len, &flags); hres = parse_regexp_flags(opt, opt_len, &flags);
if(FAILED(hres)) if(SUCCEEDED(hres))
return hres; hres = create_regexp(ctx, src, flags, ret);
jsstr_release(src);
return create_regexp(ctx, src, flags, ret); return hres;
} }
HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, jsstr_t *jsstr, jsval_t *r) HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, jsstr_t *jsstr, jsval_t *r)
@ -953,12 +955,7 @@ static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsdisp_t *ret; jsdisp_t *ret;
HRESULT hres; HRESULT hres;
if(!argc) { hres = create_regexp_var(ctx, argc ? argv[0] : jsval_undefined(), argc > 1 ? argv+1 : NULL, &ret);
FIXME("no args\n");
return E_NOTIMPL;
}
hres = create_regexp_var(ctx, argv[0], argc > 1 ? argv+1 : NULL, &ret);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;

View File

@ -677,4 +677,28 @@ ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === true, "re.multiline = " + re.multiline); ok(re.multiline === true, "re.multiline = " + re.multiline);
ok(re.global === true, "re.global = " + re.global); ok(re.global === true, "re.global = " + re.global);
re = new RegExp(undefined);
ok(re.source === "", "re.source = " + re.source);
ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === false, "re.multiline = " + re.multiline);
ok(re.global === false, "re.global = " + re.global);
re = new RegExp();
ok(re.source === "", "re.source = " + re.source);
ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === false, "re.multiline = " + re.multiline);
ok(re.global === false, "re.global = " + re.global);
re = new RegExp(true);
ok(re.source === "true", "re.source = " + re.source);
ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === false, "re.multiline = " + re.multiline);
ok(re.global === false, "re.global = " + re.global);
re = new RegExp({ toString: function() { return "test"; } });
ok(re.source === "test", "re.source = " + re.source);
ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === false, "re.multiline = " + re.multiline);
ok(re.global === false, "re.global = " + re.global);
reportSuccess(); reportSuccess();