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);
32 static const WCHAR lengthW[] = {'l','e','n','g','t','h',0};
33 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
34 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
35 static const WCHAR anchorW[] = {'a','n','c','h','o','r',0};
36 static const WCHAR bigW[] = {'b','i','g',0};
37 static const WCHAR blinkW[] = {'b','l','i','n','k',0};
38 static const WCHAR boldW[] = {'b','o','l','d',0};
39 static const WCHAR charAtW[] = {'c','h','a','r','A','t',0};
40 static const WCHAR charCodeAtW[] = {'c','h','a','r','C','o','d','e','A','t',0};
41 static const WCHAR concatW[] = {'c','o','n','c','a','t',0};
42 static const WCHAR fixedW[] = {'f','i','x','e','d',0};
43 static const WCHAR fontcolorW[] = {'f','o','n','t','c','o','l','o','r',0};
44 static const WCHAR fontsizeW[] = {'f','o','n','t','s','i','z','e',0};
45 static const WCHAR indexOfW[] = {'i','n','d','e','x','O','f',0};
46 static const WCHAR italicsW[] = {'i','t','a','l','i','c','s',0};
47 static const WCHAR lastIndexOfW[] = {'l','a','s','t','I','n','d','e','x','O','f',0};
48 static const WCHAR linkW[] = {'l','i','n','k',0};
49 static const WCHAR matchW[] = {'m','a','t','c','h',0};
50 static const WCHAR replaceW[] = {'r','e','p','l','a','c','e',0};
51 static const WCHAR searchW[] = {'s','e','a','r','c','h',0};
52 static const WCHAR sliceW[] = {'s','l','i','c','e',0};
53 static const WCHAR smallW[] = {'s','m','a','l','l',0};
54 static const WCHAR splitW[] = {'s','p','l','i','t',0};
55 static const WCHAR strikeW[] = {'s','t','r','i','k','e',0};
56 static const WCHAR subW[] = {'s','u','b',0};
57 static const WCHAR substringW[] = {'s','u','b','s','t','r','i','n','g',0};
58 static const WCHAR substrW[] = {'s','u','b','s','t','r',0};
59 static const WCHAR supW[] = {'s','u','p',0};
60 static const WCHAR toLowerCaseW[] = {'t','o','L','o','w','e','r','C','a','s','e',0};
61 static const WCHAR toUpperCaseW[] = {'t','o','U','p','p','e','r','C','a','s','e',0};
62 static const WCHAR toLocaleLowerCaseW[] = {'t','o','L','o','c','a','l','e','L','o','w','e','r','C','a','s','e',0};
63 static const WCHAR toLocaleUpperCaseW[] = {'t','o','L','o','c','a','l','e','U','p','p','e','r','C','a','s','e',0};
64 static const WCHAR localeCompareW[] = {'l','o','c','a','l','e','C','o','m','p','a','r','e',0};
65 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
66 static const WCHAR propertyIsEnumerableW[] =
67 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
68 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
70 static HRESULT String_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
71 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
73 TRACE("%p\n", dispex);
76 case DISPATCH_PROPERTYGET: {
77 StringInstance *jsthis = (StringInstance*)dispex;
80 V_I4(retv) = jsthis->length;
84 FIXME("unimplemented flags %x\n", flags);
91 /* ECMA-262 3rd Edition 15.5.4.2 */
92 static HRESULT String_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
93 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
95 StringInstance *string;
99 if(!is_class(dispex, JSCLASS_STRING)) {
100 WARN("this is not a string object\n");
104 string = (StringInstance*)dispex;
107 BSTR str = SysAllocString(string->str);
109 return E_OUTOFMEMORY;
111 V_VT(retv) = VT_BSTR;
117 /* ECMA-262 3rd Edition 15.5.4.2 */
118 static HRESULT String_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
119 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
123 return String_toString(dispex, lcid, flags, dp, retv, ei, sp);
126 static HRESULT String_anchor(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
127 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
133 static HRESULT String_big(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
134 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
140 static HRESULT String_blink(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
141 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
147 static HRESULT String_bold(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
148 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
154 /* ECMA-262 3rd Edition 15.5.4.5 */
155 static HRESULT String_charAt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
156 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
158 StringInstance *strobj;
165 if(dispex->builtin_info->class != JSCLASS_STRING) {
166 FIXME("not string this not supported\n");
170 strobj = (StringInstance*)dispex;
175 hres = to_integer(dispex->ctx, get_arg(dp, 0), ei, &num);
179 if(V_VT(&num) == VT_I4) {
182 WARN("pos = %lf\n", V_R8(&num));
190 if(0 <= pos && pos < strobj->length)
191 str = SysAllocStringLen(strobj->str+pos, 1);
193 str = SysAllocStringLen(NULL, 0);
195 return E_OUTOFMEMORY;
197 V_VT(retv) = VT_BSTR;
202 /* ECMA-262 3rd Edition 15.5.4.5 */
203 static HRESULT String_charCodeAt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
204 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
207 DWORD length, idx = 0;
212 if(dispex->builtin_info->class == JSCLASS_STRING) {
213 StringInstance *string = (StringInstance*)dispex;
216 length = string->length;
218 FIXME("not string this not supported\n");
222 if(arg_cnt(dp) > 0) {
225 hres = to_integer(dispex->ctx, get_arg(dp, 0), ei, &v);
229 if(V_VT(&v) != VT_I4 || V_I4(&v) < 0 || V_I4(&v) >= length) {
239 V_I4(retv) = str[idx];
244 /* ECMA-262 3rd Edition 15.5.4.6 */
245 static HRESULT String_concat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
246 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
248 BSTR *strs = NULL, ret = NULL;
249 DWORD len = 0, i, l, str_cnt;
256 str_cnt = arg_cnt(dp)+1;
257 strs = heap_alloc_zero(str_cnt * sizeof(BSTR));
259 return E_OUTOFMEMORY;
261 V_VT(&var) = VT_DISPATCH;
262 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
264 hres = to_string(dispex->ctx, &var, ei, strs);
265 if(SUCCEEDED(hres)) {
266 for(i=0; i < arg_cnt(dp); i++) {
267 hres = to_string(dispex->ctx, get_arg(dp, i), ei, strs+i+1);
273 if(SUCCEEDED(hres)) {
274 for(i=0; i < str_cnt; i++)
275 len += SysStringLen(strs[i]);
277 ptr = ret = SysAllocStringLen(NULL, len);
279 for(i=0; i < str_cnt; i++) {
280 l = SysStringLen(strs[i]);
281 memcpy(ptr, strs[i], l*sizeof(WCHAR));
286 for(i=0; i < str_cnt; i++)
287 SysFreeString(strs[i]);
294 V_VT(retv) = VT_BSTR;
302 static HRESULT String_fixed(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
303 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
309 static HRESULT String_fontcolor(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
310 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
316 static HRESULT String_fontsize(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
317 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
323 static HRESULT String_indexOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
324 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
330 static HRESULT String_italics(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
331 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
337 static HRESULT String_lastIndexOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
338 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
344 static HRESULT String_link(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
345 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
351 /* ECMA-262 3rd Edition 15.5.4.10 */
352 static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
353 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
355 StringInstance *This = (StringInstance*)dispex;
356 match_result_t *match_result;
359 VARIANT var, *arg_var;
365 if(arg_cnt(dp) != 1) {
366 FIXME("unsupported args\n");
370 arg_var = get_arg(dp, 0);
371 switch(V_VT(arg_var)) {
373 regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg_var));
375 if(regexp->builtin_info->class == JSCLASS_REGEXP)
377 jsdisp_release(regexp);
382 hres = to_string(dispex->ctx, arg_var, ei, &match_str);
386 hres = create_regexp_str(dispex->ctx, match_str, SysStringLen(match_str), NULL, 0, ®exp);
387 SysFreeString(match_str);
393 hres = regexp_match(regexp, This->str, This->length, FALSE, &match_result, &match_cnt);
394 jsdisp_release(regexp);
402 V_VT(retv) = VT_NULL;
406 hres = create_array(dispex->ctx, match_cnt, &array);
410 V_VT(&var) = VT_BSTR;
412 for(i=0; i < match_cnt; i++) {
413 V_BSTR(&var) = SysAllocStringLen(match_result[i].str, match_result[i].len);
415 hres = E_OUTOFMEMORY;
419 hres = jsdisp_propput_idx(array, i, lcid, &var, ei, NULL/*FIXME*/);
420 SysFreeString(V_BSTR(&var));
425 if(SUCCEEDED(hres) && retv) {
426 V_VT(retv) = VT_DISPATCH;
427 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
429 jsdisp_release(array);
440 static HRESULT strbuf_append(strbuf_t *buf, const WCHAR *str, DWORD len)
445 if(len + buf->len > buf->size) {
449 new_size = buf->size ? buf->size<<1 : 16;
450 if(new_size < buf->len+len)
451 new_size = buf->len+len;
453 new_buf = heap_realloc(buf->buf, new_size*sizeof(WCHAR));
455 new_buf = heap_alloc(new_size*sizeof(WCHAR));
457 return E_OUTOFMEMORY;
460 buf->size = new_size;
463 memcpy(buf->buf+buf->len, str, len*sizeof(WCHAR));
468 static HRESULT rep_call(DispatchEx *func, const WCHAR *str, match_result_t *match, match_result_t *parens,
469 DWORD parens_cnt, LCID lcid, BSTR *ret, jsexcept_t *ei, IServiceProvider *caller)
471 DISPPARAMS dp = {NULL, NULL, 0, 0};
472 VARIANTARG *args, *arg;
477 dp.cArgs = parens_cnt+3;
478 dp.rgvarg = args = heap_alloc_zero(sizeof(VARIANT)*dp.cArgs);
480 return E_OUTOFMEMORY;
482 arg = get_arg(&dp,0);
484 V_BSTR(arg) = SysAllocStringLen(match->str, match->len);
486 hres = E_OUTOFMEMORY;
488 if(SUCCEEDED(hres)) {
489 for(i=0; i < parens_cnt; i++) {
490 arg = get_arg(&dp,i+1);
492 V_BSTR(arg) = SysAllocStringLen(parens[i].str, parens[i].len);
494 hres = E_OUTOFMEMORY;
500 if(SUCCEEDED(hres)) {
501 arg = get_arg(&dp,parens_cnt+1);
503 V_I4(arg) = match->str - str;
505 arg = get_arg(&dp,parens_cnt+2);
507 V_BSTR(arg) = SysAllocString(str);
509 hres = E_OUTOFMEMORY;
513 hres = jsdisp_call_value(func, lcid, DISPATCH_METHOD, &dp, &var, ei, caller);
515 for(i=0; i < parens_cnt+1; i++) {
516 if(i != parens_cnt+1)
517 SysFreeString(V_BSTR(get_arg(&dp,i)));
524 hres = to_string(func->ctx, &var, ei, ret);
529 /* ECMA-262 3rd Edition 15.5.4.11 */
530 static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
531 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
533 DWORD parens_cnt = 0, parens_size=0, rep_len=0, length;
534 BSTR rep_str = NULL, match_str = NULL, ret_str;
535 DispatchEx *rep_func = NULL, *regexp = NULL;
536 match_result_t *parens = NULL, match;
538 strbuf_t ret = {NULL,0,0};
545 if(is_class(dispex, JSCLASS_STRING)) {
546 StringInstance *string = (StringInstance*)dispex;
548 length = string->length;
550 FIXME("not String this\n");
556 ret_str = SysAllocString(str);
558 return E_OUTOFMEMORY;
560 V_VT(retv) = VT_BSTR;
561 V_BSTR(retv) = ret_str;
566 arg_var = get_arg(dp, 0);
567 switch(V_VT(arg_var)) {
569 regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg_var));
571 if(is_class(regexp, JSCLASS_REGEXP)) {
574 jsdisp_release(regexp);
580 hres = to_string(dispex->ctx, arg_var, ei, &match_str);
585 if(arg_cnt(dp) >= 2) {
586 arg_var = get_arg(dp,1);
587 switch(V_VT(arg_var)) {
589 rep_func = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg_var));
591 if(is_class(rep_func, JSCLASS_FUNCTION)) {
594 jsdisp_release(rep_func);
600 hres = to_string(dispex->ctx, arg_var, ei, &rep_str);
604 if(strchrW(rep_str, '$')) {
605 FIXME("unsupported $ in replace string\n");
609 rep_len = SysStringLen(rep_str);
613 if(SUCCEEDED(hres)) {
614 const WCHAR *cp, *ecp;
620 hres = regexp_match_next(regexp, gcheck, str, length, &cp, rep_func ? &parens : NULL,
621 &parens_size, &parens_cnt, &match);
624 if(hres == S_FALSE) {
631 match.str = strstrW(cp, match_str);
634 match.len = SysStringLen(match_str);
635 cp = match.str+match.len;
638 hres = strbuf_append(&ret, ecp, match.str-ecp);
639 ecp = match.str+match.len;
646 hres = rep_call(rep_func, str, &match, parens, parens_cnt, lcid, &cstr, ei, caller);
650 hres = strbuf_append(&ret, cstr, SysStringLen(cstr));
655 hres = strbuf_append(&ret, rep_str, rep_len);
659 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d'};
661 hres = strbuf_append(&ret, undefinedW, sizeof(undefinedW)/sizeof(WCHAR));
668 hres = strbuf_append(&ret, ecp, (str+length)-ecp);
672 jsdisp_release(rep_func);
674 jsdisp_release(regexp);
675 SysFreeString(rep_str);
676 SysFreeString(match_str);
679 if(SUCCEEDED(hres) && retv) {
680 ret_str = SysAllocStringLen(ret.buf, ret.len);
682 return E_OUTOFMEMORY;
684 V_VT(retv) = VT_BSTR;
685 V_BSTR(retv) = ret_str;
686 TRACE("= %s\n", debugstr_w(ret_str));
693 static HRESULT String_search(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
694 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
700 /* ECMA-262 3rd Edition 15.5.4.13 */
701 static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
702 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
712 if(is_class(dispex, JSCLASS_STRING)) {
713 StringInstance *string = (StringInstance*)dispex;
716 length = string->length;
718 FIXME("this is not a string class\n");
723 hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-1, ei, &v);
727 if(V_VT(&v) == VT_I4) {
730 start = length + start;
733 }else if(start > length) {
737 start = V_R8(&v) < 0.0 ? 0 : length;
743 if(arg_cnt(dp) >= 2) {
744 hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-2, ei, &v);
748 if(V_VT(&v) == VT_I4) {
754 }else if(end > length) {
758 end = V_R8(&v) < 0.0 ? 0 : length;
768 BSTR retstr = SysAllocStringLen(str+start, end-start);
770 return E_OUTOFMEMORY;
772 V_VT(retv) = VT_BSTR;
773 V_BSTR(retv) = retstr;
778 static HRESULT String_small(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
779 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
785 static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
786 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
788 StringInstance *string;
789 match_result_t *match_result;
790 DWORD match_cnt, i, len;
798 if(!is_class(dispex, JSCLASS_STRING)) {
799 FIXME("not String this\n");
803 string = (StringInstance*)dispex;
805 if(arg_cnt(dp) != 1) {
806 FIXME("unsupported args\n");
810 arg = get_arg(dp, 0);
815 regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
817 if(is_class(regexp, JSCLASS_REGEXP)) {
818 hres = regexp_match(regexp, string->str, string->length, TRUE, &match_result, &match_cnt);
819 jsdisp_release(regexp);
824 jsdisp_release(regexp);
828 FIXME("unsupported vt %d\n", V_VT(arg));
832 hres = create_array(dispex->ctx, match_cnt+1, &array);
834 if(SUCCEEDED(hres)) {
836 for(i=0; i < match_cnt; i++) {
837 len = match_result[i].str-ptr;
838 V_VT(&var) = VT_BSTR;
839 V_BSTR(&var) = SysAllocStringLen(ptr, len);
841 hres = E_OUTOFMEMORY;
845 hres = jsdisp_propput_idx(array, i, lcid, &var, ei, sp);
846 SysFreeString(V_BSTR(&var));
850 ptr = match_result[i].str + match_result[i].len;
854 if(SUCCEEDED(hres)) {
855 len = (string->str+string->length) - ptr;
857 V_VT(&var) = VT_BSTR;
858 V_BSTR(&var) = SysAllocStringLen(ptr, len);
860 hres = jsdisp_propput_idx(array, i, lcid, &var, ei, sp);
861 SysFreeString(V_BSTR(&var));
864 heap_free(match_result);
866 if(SUCCEEDED(hres) && retv) {
867 V_VT(retv) = VT_DISPATCH;
868 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
870 jsdisp_release(array);
876 static HRESULT String_strike(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
877 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
883 static HRESULT String_sub(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
884 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
890 /* ECMA-262 3rd Edition 15.5.4.15 */
891 static HRESULT String_substring(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
892 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
902 if(is_class(dispex, JSCLASS_STRING)) {
903 StringInstance *string = (StringInstance*)dispex;
905 length = string->length;
908 FIXME("not string this not supported\n");
912 if(arg_cnt(dp) >= 1) {
913 hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-1, ei, &v);
917 if(V_VT(&v) == VT_I4) {
921 else if(start >= length)
924 start = V_R8(&v) < 0.0 ? 0 : length;
928 if(arg_cnt(dp) >= 2) {
929 hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-2, ei, &v);
933 if(V_VT(&v) == VT_I4) {
937 else if(end > length)
940 end = V_R8(&v) < 0.0 ? 0 : length;
953 V_VT(retv) = VT_BSTR;
954 V_BSTR(retv) = SysAllocStringLen(str+start, end-start);
956 return E_OUTOFMEMORY;
961 static HRESULT String_substr(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
962 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
968 static HRESULT String_sup(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
969 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
975 static HRESULT String_toLowerCase(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
976 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
982 static HRESULT String_toUpperCase(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
983 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
989 static HRESULT String_toLocaleLowerCase(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
990 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
996 static HRESULT String_toLocaleUpperCase(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
997 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1003 static HRESULT String_localeCompare(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1004 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1010 static HRESULT String_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1011 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1017 static HRESULT String_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1018 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1024 static HRESULT String_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1025 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1031 static HRESULT String_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1032 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1034 StringInstance *This = (StringInstance*)dispex;
1039 case DISPATCH_PROPERTYGET: {
1040 BSTR str = SysAllocString(This->str);
1042 return E_OUTOFMEMORY;
1044 V_VT(retv) = VT_BSTR;
1049 FIXME("flags %x\n", flags);
1056 static void String_destructor(DispatchEx *dispex)
1058 StringInstance *This = (StringInstance*)dispex;
1060 heap_free(This->str);
1064 static const builtin_prop_t String_props[] = {
1065 {anchorW, String_anchor, PROPF_METHOD},
1066 {bigW, String_big, PROPF_METHOD},
1067 {blinkW, String_blink, PROPF_METHOD},
1068 {boldW, String_bold, PROPF_METHOD},
1069 {charAtW, String_charAt, PROPF_METHOD},
1070 {charCodeAtW, String_charCodeAt, PROPF_METHOD},
1071 {concatW, String_concat, PROPF_METHOD},
1072 {fixedW, String_fixed, PROPF_METHOD},
1073 {fontcolorW, String_fontcolor, PROPF_METHOD},
1074 {fontsizeW, String_fontsize, PROPF_METHOD},
1075 {hasOwnPropertyW, String_hasOwnProperty, PROPF_METHOD},
1076 {indexOfW, String_indexOf, PROPF_METHOD},
1077 {isPrototypeOfW, String_isPrototypeOf, PROPF_METHOD},
1078 {italicsW, String_italics, PROPF_METHOD},
1079 {lastIndexOfW, String_lastIndexOf, PROPF_METHOD},
1080 {lengthW, String_length, 0},
1081 {linkW, String_link, PROPF_METHOD},
1082 {localeCompareW, String_localeCompare, PROPF_METHOD},
1083 {matchW, String_match, PROPF_METHOD},
1084 {propertyIsEnumerableW, String_propertyIsEnumerable, PROPF_METHOD},
1085 {replaceW, String_replace, PROPF_METHOD},
1086 {searchW, String_search, PROPF_METHOD},
1087 {sliceW, String_slice, PROPF_METHOD},
1088 {smallW, String_small, PROPF_METHOD},
1089 {splitW, String_split, PROPF_METHOD},
1090 {strikeW, String_strike, PROPF_METHOD},
1091 {substringW, String_substring, PROPF_METHOD},
1092 {substrW, String_substr, PROPF_METHOD},
1093 {subW, String_sub, PROPF_METHOD},
1094 {supW, String_sup, PROPF_METHOD},
1095 {toLocaleLowerCaseW, String_toLocaleLowerCase, PROPF_METHOD},
1096 {toLocaleUpperCaseW, String_toLocaleUpperCase, PROPF_METHOD},
1097 {toLowerCaseW, String_toLowerCase, PROPF_METHOD},
1098 {toStringW, String_toString, PROPF_METHOD},
1099 {toUpperCaseW, String_toUpperCase, PROPF_METHOD},
1100 {valueOfW, String_valueOf, PROPF_METHOD}
1103 static const builtin_info_t String_info = {
1105 {NULL, String_value, 0},
1106 sizeof(String_props)/sizeof(*String_props),
1112 static HRESULT StringConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
1113 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
1124 hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &str);
1128 str = SysAllocStringLen(NULL, 0);
1130 return E_OUTOFMEMORY;
1133 V_VT(retv) = VT_BSTR;
1137 case DISPATCH_CONSTRUCT: {
1143 hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &str);
1147 hres = create_string(dispex->ctx, str, SysStringLen(str), &ret);
1150 hres = create_string(dispex->ctx, NULL, 0, &ret);
1156 V_VT(retv) = VT_DISPATCH;
1157 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(ret);
1162 FIXME("unimplemented flags: %x\n", flags);
1169 static HRESULT string_alloc(script_ctx_t *ctx, BOOL use_constr, StringInstance **ret)
1171 StringInstance *string;
1174 string = heap_alloc_zero(sizeof(StringInstance));
1176 return E_OUTOFMEMORY;
1179 hres = init_dispex_from_constr(&string->dispex, ctx, &String_info, ctx->string_constr);
1181 hres = init_dispex(&string->dispex, ctx, &String_info, NULL);
1191 HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx **ret)
1193 StringInstance *string;
1196 hres = string_alloc(ctx, FALSE, &string);
1200 hres = create_builtin_function(ctx, StringConstr_value, PROPF_CONSTR, &string->dispex, ret);
1202 jsdisp_release(&string->dispex);
1206 HRESULT create_string(script_ctx_t *ctx, const WCHAR *str, DWORD len, DispatchEx **ret)
1208 StringInstance *string;
1211 hres = string_alloc(ctx, TRUE, &string);
1218 string->length = len;
1219 string->str = heap_alloc((len+1)*sizeof(WCHAR));
1221 jsdisp_release(&string->dispex);
1222 return E_OUTOFMEMORY;
1225 memcpy(string->str, str, len*sizeof(WCHAR));
1226 string->str[len] = 0;
1228 *ret = &string->dispex;