jscript: Added RegExp contruction implementation.
This commit is contained in:
parent
7a54be05f0
commit
98f2dfee9c
|
@ -426,7 +426,7 @@ static HRESULT init_constructors(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = create_object_constr(ctx, &ctx->regexp_constr);
|
||||
hres = create_regexp_constr(ctx, &ctx->regexp_constr);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
|
|
@ -3546,11 +3546,81 @@ static HRESULT create_regexp(script_ctx_t *ctx, const WCHAR *exp, int len, DWORD
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT regexp_constructor(script_ctx_t *ctx, DISPPARAMS *dp, VARIANT *retv)
|
||||
{
|
||||
const WCHAR *opt = emptyW, *src;
|
||||
DispatchEx *ret;
|
||||
VARIANT *arg;
|
||||
HRESULT hres;
|
||||
|
||||
if(!arg_cnt(dp)) {
|
||||
FIXME("no args\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
arg = get_arg(dp,0);
|
||||
if(V_VT(arg) == VT_DISPATCH) {
|
||||
DispatchEx *obj;
|
||||
|
||||
obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
|
||||
if(obj) {
|
||||
if(is_class(obj, JSCLASS_REGEXP)) {
|
||||
RegExpInstance *regexp = (RegExpInstance*)obj;
|
||||
|
||||
hres = create_regexp(ctx, regexp->str, -1, regexp->jsregexp->flags, &ret);
|
||||
jsdisp_release(obj);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
V_VT(retv) = VT_DISPATCH;
|
||||
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
jsdisp_release(obj);
|
||||
}
|
||||
}
|
||||
|
||||
if(V_VT(arg) != VT_BSTR) {
|
||||
FIXME("vt arg0 = %d\n", V_VT(arg));
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
src = V_BSTR(arg);
|
||||
|
||||
if(arg_cnt(dp) >= 2) {
|
||||
arg = get_arg(dp,1);
|
||||
if(V_VT(arg) != VT_BSTR) {
|
||||
FIXME("unimplemented for vt %d\n", V_VT(arg));
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
opt = V_BSTR(arg);
|
||||
}
|
||||
|
||||
hres = create_regexp_str(ctx, src, -1, opt, strlenW(opt), &ret);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
V_VT(retv) = VT_DISPATCH;
|
||||
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT RegExpConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
TRACE("\n");
|
||||
|
||||
switch(flags) {
|
||||
case DISPATCH_CONSTRUCT:
|
||||
return regexp_constructor(dispex->ctx, dp, retv);
|
||||
default:
|
||||
FIXME("unimplemented flags: %x\n", flags);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx **ret)
|
||||
|
|
|
@ -51,4 +51,28 @@ ok(m.length === 2, "m.length is not 1");
|
|||
ok(m["0"] === "aaab", "m[0] is not \"ab\"");
|
||||
ok(m["1"] === "ab", "m[1] is not \"ab\"");
|
||||
|
||||
m = "abcabc".match(new RegExp("ab"));
|
||||
ok(typeof(m) === "object", "typeof m is not object");
|
||||
ok(m.length === 1, "m.length is not 1");
|
||||
ok(m["0"] === "ab", "m[0] is not \"ab\"");
|
||||
|
||||
/*
|
||||
m = "abcabc".match(new RegExp("ab","g"));
|
||||
ok(typeof(m) === "object", "typeof m is not object");
|
||||
ok(m.length === 2, "m.length is not 1");
|
||||
ok(m["0"] === "ab", "m[0] is not \"ab\"");
|
||||
ok(m["1"] === "ab", "m[1] is not \"ab\"");
|
||||
|
||||
m = "abcabc".match(new RegExp(/ab/g));
|
||||
ok(typeof(m) === "object", "typeof m is not object");
|
||||
ok(m.length === 2, "m.length is not 1");
|
||||
ok(m["0"] === "ab", "m[0] is not \"ab\"");
|
||||
ok(m["1"] === "ab", "m[1] is not \"ab\"");
|
||||
|
||||
m = "abcabc".match(new RegExp("ab","g", "test"));
|
||||
ok(typeof(m) === "object", "typeof m is not object");
|
||||
ok(m.length === 2, "m.length is not 1");
|
||||
ok(m["0"] === "ab", "m[0] is not \"ab\"");
|
||||
ok(m["1"] === "ab", "m[1] is not \"ab\"");
|
||||
*/
|
||||
reportSuccess();
|
||||
|
|
Loading…
Reference in New Issue