jscript: Added missing RegExp properties.
[wine] / dlls / jscript / regexp.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "jscript.h"
20
21 #include "wine/debug.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
24
25 typedef struct {
26     DispatchEx dispex;
27 } RegExpInstance;
28
29 static const WCHAR sourceW[] = {'s','o','u','r','c','e',0};
30 static const WCHAR globalW[] = {'g','l','o','b','a','l',0};
31 static const WCHAR ignoreCaseW[] = {'i','g','n','o','r','e','C','a','s','e',0};
32 static const WCHAR multilineW[] = {'m','u','l','t','i','l','i','n','e',0};
33 static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
34 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
35 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
36 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
37 static const WCHAR propertyIsEnumerableW[] =
38     {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
39 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
40 static const WCHAR execW[] = {'e','x','e','c',0};
41
42 static HRESULT RegExp_source(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
43         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
44 {
45     FIXME("\n");
46     return E_NOTIMPL;
47 }
48
49 static HRESULT RegExp_global(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
50         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
51 {
52     FIXME("\n");
53     return E_NOTIMPL;
54 }
55
56 static HRESULT RegExp_ignoreCase(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
57         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
58 {
59     FIXME("\n");
60     return E_NOTIMPL;
61 }
62
63 static HRESULT RegExp_multiline(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
64         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
65 {
66     FIXME("\n");
67     return E_NOTIMPL;
68 }
69
70 static HRESULT RegExp_lastIndex(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
71         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
72 {
73     FIXME("\n");
74     return E_NOTIMPL;
75 }
76
77 static HRESULT RegExp_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
78         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
79 {
80     FIXME("\n");
81     return E_NOTIMPL;
82 }
83
84 static HRESULT RegExp_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
85         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
86 {
87     FIXME("\n");
88     return E_NOTIMPL;
89 }
90
91 static HRESULT RegExp_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
92         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
93 {
94     FIXME("\n");
95     return E_NOTIMPL;
96 }
97
98 static HRESULT RegExp_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
99         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
100 {
101     FIXME("\n");
102     return E_NOTIMPL;
103 }
104
105 static HRESULT RegExp_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
106         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
107 {
108     FIXME("\n");
109     return E_NOTIMPL;
110 }
111
112 static HRESULT RegExp_exec(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
113         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
114 {
115     FIXME("\n");
116     return E_NOTIMPL;
117 }
118
119 static HRESULT RegExp_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
120         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
121 {
122     FIXME("\n");
123     return E_NOTIMPL;
124 }
125
126 static void RegExp_destructor(DispatchEx *dispex)
127 {
128     heap_free(dispex);
129 }
130
131 static const builtin_prop_t RegExp_props[] = {
132     {execW,                  RegExp_exec,                  PROPF_METHOD},
133     {globalW,                RegExp_global,                0},
134     {hasOwnPropertyW,        RegExp_hasOwnProperty,        PROPF_METHOD},
135     {ignoreCaseW,            RegExp_ignoreCase,            0},
136     {isPrototypeOfW,         RegExp_isPrototypeOf,         PROPF_METHOD},
137     {lastIndexW,             RegExp_lastIndex,             0},
138     {multilineW,             RegExp_multiline,             0},
139     {propertyIsEnumerableW,  RegExp_propertyIsEnumerable,  PROPF_METHOD},
140     {sourceW,                RegExp_source,                0},
141     {toLocaleStringW,        RegExp_toLocaleString,        PROPF_METHOD},
142     {toStringW,              RegExp_toString,              PROPF_METHOD}
143 };
144
145 static const builtin_info_t RegExp_info = {
146     JSCLASS_REGEXP,
147     {NULL, RegExp_value, 0},
148     sizeof(RegExp_props)/sizeof(*RegExp_props),
149     RegExp_props,
150     RegExp_destructor,
151     NULL
152 };
153
154 static HRESULT alloc_regexp(script_ctx_t *ctx, BOOL use_constr, RegExpInstance **ret)
155 {
156     RegExpInstance *regexp;
157     HRESULT hres;
158
159     regexp = heap_alloc_zero(sizeof(RegExpInstance));
160     if(!regexp)
161         return E_OUTOFMEMORY;
162
163     if(use_constr)
164         hres = init_dispex_from_constr(&regexp->dispex, ctx, &RegExp_info, ctx->regexp_constr);
165     else
166         hres = init_dispex(&regexp->dispex, ctx, &RegExp_info, NULL);
167
168     if(FAILED(hres)) {
169         heap_free(regexp);
170         return hres;
171     }
172
173     *ret = regexp;
174     return S_OK;
175 }
176
177 static HRESULT RegExpConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
178         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
179 {
180     FIXME("\n");
181     return E_NOTIMPL;
182 }
183
184 HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx **ret)
185 {
186     RegExpInstance *regexp;
187     HRESULT hres;
188
189     hres = alloc_regexp(ctx, FALSE, &regexp);
190     if(FAILED(hres))
191         return hres;
192
193     hres = create_builtin_function(ctx, RegExpConstr_value, PROPF_CONSTR, &regexp->dispex, ret);
194
195     jsdisp_release(&regexp->dispex);
196     return hres;
197 }