jscript: Added postfix decrement expression implementation.
[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 toStringW[] = {'t','o','S','t','r','i','n','g',0};
30 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
31 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
32 static const WCHAR propertyIsEnumerableW[] =
33     {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
34 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
35
36 static HRESULT RegExp_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
37         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
38 {
39     FIXME("\n");
40     return E_NOTIMPL;
41 }
42
43 static HRESULT RegExp_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
44         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
45 {
46     FIXME("\n");
47     return E_NOTIMPL;
48 }
49
50 static HRESULT RegExp_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
51         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
52 {
53     FIXME("\n");
54     return E_NOTIMPL;
55 }
56
57 static HRESULT RegExp_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
58         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
59 {
60     FIXME("\n");
61     return E_NOTIMPL;
62 }
63
64 static HRESULT RegExp_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
65         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
66 {
67     FIXME("\n");
68     return E_NOTIMPL;
69 }
70
71 static HRESULT RegExp_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
72         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
73 {
74     FIXME("\n");
75     return E_NOTIMPL;
76 }
77
78 static void RegExp_destructor(DispatchEx *dispex)
79 {
80     heap_free(dispex);
81 }
82
83 static const builtin_prop_t RegExp_props[] = {
84     {hasOwnPropertyW,        RegExp_hasOwnProperty,        PROPF_METHOD},
85     {isPrototypeOfW,         RegExp_isPrototypeOf,         PROPF_METHOD},
86     {propertyIsEnumerableW,  RegExp_propertyIsEnumerable,  PROPF_METHOD},
87     {toLocaleStringW,        RegExp_toLocaleString,        PROPF_METHOD},
88     {toStringW,              RegExp_toString,              PROPF_METHOD}
89 };
90
91 static const builtin_info_t RegExp_info = {
92     JSCLASS_REGEXP,
93     {NULL, RegExp_value, 0},
94     sizeof(RegExp_props)/sizeof(*RegExp_props),
95     RegExp_props,
96     RegExp_destructor,
97     NULL
98 };
99
100 static HRESULT alloc_regexp(script_ctx_t *ctx, BOOL use_constr, RegExpInstance **ret)
101 {
102     RegExpInstance *regexp;
103     HRESULT hres;
104
105     regexp = heap_alloc_zero(sizeof(RegExpInstance));
106     if(!regexp)
107         return E_OUTOFMEMORY;
108
109     if(use_constr)
110         hres = init_dispex_from_constr(&regexp->dispex, ctx, &RegExp_info, ctx->regexp_constr);
111     else
112         hres = init_dispex(&regexp->dispex, ctx, &RegExp_info, NULL);
113
114     if(FAILED(hres)) {
115         heap_free(regexp);
116         return hres;
117     }
118
119     *ret = regexp;
120     return S_OK;
121 }
122
123 static HRESULT RegExpConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
124         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
125 {
126     FIXME("\n");
127     return E_NOTIMPL;
128 }
129
130 HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx **ret)
131 {
132     RegExpInstance *regexp;
133     HRESULT hres;
134
135     hres = alloc_regexp(ctx, FALSE, &regexp);
136     if(FAILED(hres))
137         return hres;
138
139     hres = create_builtin_function(ctx, RegExpConstr_value, PROPF_CONSTR, &regexp->dispex, ret);
140
141     jsdisp_release(&regexp->dispex);
142     return hres;
143 }