Commit 4e887493 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

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

parent ccd6b205
......@@ -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;
const WCHAR *opt = NULL;
jsstr_t *src;
HRESULT hres;
HRESULT hres = S_OK;
if(is_object_instance(src_arg)) {
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)) {
FIXME("src_arg = %s\n", debugstr_jsval(src_arg));
return E_NOTIMPL;
}
src = get_string(src_arg);
if(is_undefined(src_arg))
src = jsstr_empty();
else
hres = to_string(ctx, src_arg, &src);
if(FAILED(hres))
return hres;
if(flags_arg) {
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 = jsstr_flatten(opt_str);
if(!opt)
if(!opt) {
jsstr_release(src);
return E_OUTOFMEMORY;
}
opt_len = jsstr_length(opt_str);
}
hres = parse_regexp_flags(opt, opt_len, &flags);
if(FAILED(hres))
return hres;
return create_regexp(ctx, src, flags, ret);
if(SUCCEEDED(hres))
hres = create_regexp(ctx, src, flags, ret);
jsstr_release(src);
return hres;
}
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;
HRESULT hres;
if(!argc) {
FIXME("no args\n");
return E_NOTIMPL;
}
hres = create_regexp_var(ctx, argv[0], argc > 1 ? argv+1 : NULL, &ret);
hres = create_regexp_var(ctx, argc ? argv[0] : jsval_undefined(), argc > 1 ? argv+1 : NULL, &ret);
if(FAILED(hres))
return hres;
......
......@@ -677,4 +677,28 @@ ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
ok(re.multiline === true, "re.multiline = " + re.multiline);
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();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment