2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
29 static const WCHAR lengthW
[] = {'l','e','n','g','t','h',0};
30 static const WCHAR concatW
[] = {'c','o','n','c','a','t',0};
31 static const WCHAR joinW
[] = {'j','o','i','n',0};
32 static const WCHAR popW
[] = {'p','o','p',0};
33 static const WCHAR pushW
[] = {'p','u','s','h',0};
34 static const WCHAR reverseW
[] = {'r','e','v','e','r','s','e',0};
35 static const WCHAR shiftW
[] = {'s','h','i','f','t',0};
36 static const WCHAR sliceW
[] = {'s','l','i','c','e',0};
37 static const WCHAR sortW
[] = {'s','o','r','t',0};
38 static const WCHAR spliceW
[] = {'s','p','l','i','c','e',0};
39 static const WCHAR toStringW
[] = {'t','o','S','t','r','i','n','g',0};
40 static const WCHAR toLocaleStringW
[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
41 static const WCHAR valueOfW
[] = {'v','a','l','u','e','O','f',0};
42 static const WCHAR unshiftW
[] = {'u','n','s','h','i','f','t',0};
43 static const WCHAR hasOwnPropertyW
[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
44 static const WCHAR propertyIsEnumerableW
[] =
45 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
46 static const WCHAR isPrototypeOfW
[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
49 static HRESULT
Array_length(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
50 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
56 static HRESULT
Array_concat(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
57 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
63 static HRESULT
Array_join(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
64 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
70 static HRESULT
Array_pop(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
71 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
77 static HRESULT
Array_push(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
78 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
84 static HRESULT
Array_reverse(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
85 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
91 static HRESULT
Array_shift(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
92 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
98 static HRESULT
Array_slice(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
99 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
105 static HRESULT
Array_sort(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
106 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
112 static HRESULT
Array_splice(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
113 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
119 static HRESULT
Array_toString(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
120 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
126 static HRESULT
Array_toLocaleString(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
127 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
133 static HRESULT
Array_valueOf(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
134 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
140 static HRESULT
Array_unshift(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
141 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
147 static HRESULT
Array_hasOwnProperty(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
148 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
154 static HRESULT
Array_propertyIsEnumerable(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
155 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
161 static HRESULT
Array_isPrototypeOf(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
162 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
168 static HRESULT
Array_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
169 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
175 static void Array_destructor(DispatchEx
*dispex
)
180 static void Array_on_put(DispatchEx
*dispex
, const WCHAR
*name
)
185 static const builtin_prop_t Array_props
[] = {
186 {concatW
, Array_concat
, PROPF_METHOD
},
187 {hasOwnPropertyW
, Array_hasOwnProperty
, PROPF_METHOD
},
188 {isPrototypeOfW
, Array_isPrototypeOf
, PROPF_METHOD
},
189 {joinW
, Array_join
, PROPF_METHOD
},
190 {lengthW
, Array_length
, 0},
191 {popW
, Array_pop
, PROPF_METHOD
},
192 {propertyIsEnumerableW
, Array_propertyIsEnumerable
, PROPF_METHOD
},
193 {pushW
, Array_push
, PROPF_METHOD
},
194 {reverseW
, Array_reverse
, PROPF_METHOD
},
195 {shiftW
, Array_shift
, PROPF_METHOD
},
196 {sliceW
, Array_slice
, PROPF_METHOD
},
197 {sortW
, Array_sort
, PROPF_METHOD
},
198 {spliceW
, Array_splice
, PROPF_METHOD
},
199 {toLocaleStringW
, Array_toLocaleString
, PROPF_METHOD
},
200 {toStringW
, Array_toString
, PROPF_METHOD
},
201 {unshiftW
, Array_unshift
, PROPF_METHOD
},
202 {valueOfW
, Array_valueOf
, PROPF_METHOD
}
205 static const builtin_info_t Array_info
= {
207 {NULL
, Array_value
, 0},
208 sizeof(Array_props
)/sizeof(*Array_props
),
214 static HRESULT
ArrayConstr_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
215 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*sp
)
221 static HRESULT
alloc_array(script_ctx_t
*ctx
, BOOL use_constr
, ArrayInstance
**ret
)
223 ArrayInstance
*array
= heap_alloc_zero(sizeof(ArrayInstance
));
227 hres
= init_dispex_from_constr(&array
->dispex
, ctx
, &Array_info
, ctx
->array_constr
);
229 hres
= init_dispex(&array
->dispex
, ctx
, &Array_info
, NULL
);
240 HRESULT
create_array_constr(script_ctx_t
*ctx
, DispatchEx
**ret
)
242 ArrayInstance
*array
;
245 hres
= alloc_array(ctx
, FALSE
, &array
);
249 hres
= create_builtin_function(ctx
, ArrayConstr_value
, PROPF_CONSTR
, &array
->dispex
, ret
);
251 IDispatchEx_Release(_IDispatchEx_(&array
->dispex
));