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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
34 jsval_t last_index_val
;
37 static inline RegExpInstance
*regexp_from_jsdisp(jsdisp_t
*jsdisp
)
39 return CONTAINING_RECORD(jsdisp
, RegExpInstance
, dispex
);
42 static inline RegExpInstance
*regexp_this(jsval_t vthis
)
44 jsdisp_t
*jsdisp
= is_object_instance(vthis
) ? to_jsdisp(get_object(vthis
)) : NULL
;
45 return (jsdisp
&& is_class(jsdisp
, JSCLASS_REGEXP
)) ? regexp_from_jsdisp(jsdisp
) : NULL
;
48 static void set_last_index(RegExpInstance
*This
, DWORD last_index
)
50 This
->last_index
= last_index
;
51 jsval_release(This
->last_index_val
);
52 This
->last_index_val
= jsval_number(last_index
);
55 static HRESULT
do_regexp_match_next(script_ctx_t
*ctx
, RegExpInstance
*regexp
,
56 DWORD rem_flags
, jsstr_t
*jsstr
, const WCHAR
*str
, match_state_t
*ret
)
60 hres
= regexp_execute(regexp
->jsregexp
, ctx
, &ctx
->tmp_heap
,
61 str
, jsstr_length(jsstr
), ret
);
65 if(rem_flags
& REM_RESET_INDEX
)
66 set_last_index(regexp
, 0);
70 if(!(rem_flags
& REM_NO_CTX_UPDATE
) && ctx
->last_match
!= jsstr
) {
71 jsstr_release(ctx
->last_match
);
72 ctx
->last_match
= jsstr_addref(jsstr
);
75 if(!(rem_flags
& REM_NO_CTX_UPDATE
)) {
76 DWORD i
, n
= min(ARRAY_SIZE(ctx
->match_parens
), ret
->paren_count
);
78 for(i
=0; i
< n
; i
++) {
79 if(ret
->parens
[i
].index
== -1) {
80 ctx
->match_parens
[i
].index
= 0;
81 ctx
->match_parens
[i
].length
= 0;
83 ctx
->match_parens
[i
].index
= ret
->parens
[i
].index
;
84 ctx
->match_parens
[i
].length
= ret
->parens
[i
].length
;
88 if(n
< ARRAY_SIZE(ctx
->match_parens
))
89 memset(ctx
->match_parens
+n
, 0, sizeof(ctx
->match_parens
) - n
*sizeof(ctx
->match_parens
[0]));
92 set_last_index(regexp
, ret
->cp
-str
);
94 if(!(rem_flags
& REM_NO_CTX_UPDATE
)) {
95 ctx
->last_match_index
= ret
->cp
-str
-ret
->match_len
;
96 ctx
->last_match_length
= ret
->match_len
;
102 HRESULT
regexp_match_next(script_ctx_t
*ctx
, jsdisp_t
*dispex
,
103 DWORD rem_flags
, jsstr_t
*jsstr
, match_state_t
**ret
)
105 RegExpInstance
*regexp
= regexp_from_jsdisp(dispex
);
106 match_state_t
*match
;
111 if((rem_flags
& REM_CHECK_GLOBAL
) && !(regexp
->jsregexp
->flags
& REG_GLOB
)) {
112 if(rem_flags
& REM_ALLOC_RESULT
)
117 str
= jsstr_flatten(jsstr
);
119 return E_OUTOFMEMORY
;
121 if(rem_flags
& REM_ALLOC_RESULT
) {
122 match
= alloc_match_state(regexp
->jsregexp
, NULL
, str
);
124 return E_OUTOFMEMORY
;
128 mark
= heap_pool_mark(&ctx
->tmp_heap
);
130 if(rem_flags
& REM_NO_PARENS
) {
131 match
= alloc_match_state(regexp
->jsregexp
, &ctx
->tmp_heap
, NULL
);
133 heap_pool_clear(mark
);
134 return E_OUTOFMEMORY
;
136 match
->cp
= (*ret
)->cp
;
137 match
->match_len
= (*ret
)->match_len
;
142 hres
= do_regexp_match_next(ctx
, regexp
, rem_flags
, jsstr
, str
, match
);
144 if(rem_flags
& REM_NO_PARENS
) {
145 (*ret
)->cp
= match
->cp
;
146 (*ret
)->match_len
= match
->match_len
;
149 heap_pool_clear(mark
);
151 if(hres
!= S_OK
&& (rem_flags
& REM_ALLOC_RESULT
)) {
159 static HRESULT
regexp_match(script_ctx_t
*ctx
, jsdisp_t
*dispex
, jsstr_t
*jsstr
, BOOL gflag
,
160 match_result_t
**match_result
, DWORD
*result_cnt
)
162 RegExpInstance
*This
= regexp_from_jsdisp(dispex
);
163 match_result_t
*ret
= NULL
;
164 match_state_t
*result
;
165 DWORD i
=0, ret_size
= 0;
170 mark
= heap_pool_mark(&ctx
->tmp_heap
);
172 str
= jsstr_flatten(jsstr
);
174 return E_OUTOFMEMORY
;
176 result
= alloc_match_state(This
->jsregexp
, &ctx
->tmp_heap
, str
);
178 heap_pool_clear(mark
);
179 return E_OUTOFMEMORY
;
183 hres
= do_regexp_match_next(ctx
, This
, 0, jsstr
, str
, result
);
184 if(hres
== S_FALSE
) {
194 match_result_t
*old_ret
= ret
;
196 ret
= realloc(old_ret
, (ret_size
<<= 1) * sizeof(match_result_t
));
200 ret
= malloc((ret_size
=4) * sizeof(match_result_t
));
203 hres
= E_OUTOFMEMORY
;
208 ret
[i
].index
= result
->cp
- str
- result
->match_len
;
209 ret
[i
++].length
= result
->match_len
;
211 if(!gflag
&& !(This
->jsregexp
->flags
& REG_GLOB
)) {
217 heap_pool_clear(mark
);
228 static HRESULT
RegExp_get_source(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
232 *r
= jsval_string(jsstr_addref(regexp_from_jsdisp(jsthis
)->str
));
236 static HRESULT
RegExp_get_global(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
240 *r
= jsval_bool(!!(regexp_from_jsdisp(jsthis
)->jsregexp
->flags
& REG_GLOB
));
244 static HRESULT
RegExp_get_ignoreCase(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
248 *r
= jsval_bool(!!(regexp_from_jsdisp(jsthis
)->jsregexp
->flags
& REG_FOLD
));
252 static HRESULT
RegExp_get_multiline(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
256 *r
= jsval_bool(!!(regexp_from_jsdisp(jsthis
)->jsregexp
->flags
& REG_MULTILINE
));
260 static INT
index_from_val(script_ctx_t
*ctx
, jsval_t v
)
265 hres
= to_number(ctx
, v
, &n
);
270 return is_int32(n
) ? n
: 0;
273 static HRESULT
RegExp_get_lastIndex(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
275 RegExpInstance
*regexp
= regexp_from_jsdisp(jsthis
);
279 return jsval_copy(regexp
->last_index_val
, r
);
282 static HRESULT
RegExp_set_lastIndex(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t value
)
284 RegExpInstance
*regexp
= regexp_from_jsdisp(jsthis
);
289 jsval_release(regexp
->last_index_val
);
290 hres
= jsval_copy(value
, ®exp
->last_index_val
);
294 regexp
->last_index
= index_from_val(ctx
, value
);
298 static HRESULT
RegExp_toString(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
301 RegExpInstance
*regexp
;
308 if(!(regexp
= regexp_this(vthis
))) {
309 WARN("Not a RegExp\n");
310 return JS_E_REGEXP_EXPECTED
;
317 len
= jsstr_length(regexp
->str
) + 2;
319 f
= regexp
->jsregexp
->flags
;
324 if(f
& REG_MULTILINE
)
327 ret
= jsstr_alloc_buf(len
, &ptr
);
329 return E_OUTOFMEMORY
;
332 ptr
+= jsstr_flush(regexp
->str
, ptr
);
339 if(f
& REG_MULTILINE
)
342 *r
= jsval_string(ret
);
346 static HRESULT
create_match_array(script_ctx_t
*ctx
, jsstr_t
*input_str
,
347 const match_state_t
*result
, IDispatch
**ret
)
355 input
= jsstr_flatten(input_str
);
357 return E_OUTOFMEMORY
;
359 hres
= create_array(ctx
, result
->paren_count
+1, &array
);
363 for(i
=0; i
< result
->paren_count
; i
++) {
366 if(result
->parens
[i
].index
!= -1) {
367 if(!(str
= jsstr_substr(input_str
, result
->parens
[i
].index
, result
->parens
[i
].length
))) {
368 hres
= E_OUTOFMEMORY
;
371 val
= jsval_string(str
);
372 }else if(ctx
->version
< SCRIPTLANGUAGEVERSION_ES5
) {
373 val
= jsval_string(jsstr_empty());
375 val
= jsval_undefined();
378 hres
= jsdisp_propput_idx(array
, i
+1, val
);
384 while(SUCCEEDED(hres
)) {
385 hres
= jsdisp_propput_name(array
, L
"index", jsval_number(result
->cp
-input
-result
->match_len
));
389 hres
= jsdisp_propput_name(array
, L
"lastIndex", jsval_number(result
->cp
-input
));
393 hres
= jsdisp_propput_name(array
, L
"input", jsval_string(input_str
));
397 str
= jsstr_alloc_len(result
->cp
-result
->match_len
, result
->match_len
);
399 hres
= E_OUTOFMEMORY
;
402 hres
= jsdisp_propput_name(array
, L
"0", jsval_string(str
));
408 jsdisp_release(array
);
412 *ret
= to_disp(array
);
416 static HRESULT
run_exec(script_ctx_t
*ctx
, jsval_t vthis
, jsval_t arg
,
417 jsstr_t
**input
, match_state_t
**result
, BOOL
*ret
)
419 RegExpInstance
*regexp
;
420 match_state_t
*match
;
421 DWORD last_index
= 0;
426 if(!(regexp
= regexp_this(vthis
))) {
427 WARN("Not a RegExp\n");
428 return JS_E_REGEXP_EXPECTED
;
431 hres
= to_flat_string(ctx
, arg
, &jsstr
, &string
);
435 if(regexp
->jsregexp
->flags
& REG_GLOB
) {
436 if(regexp
->last_index
< 0) {
437 jsstr_release(jsstr
);
438 set_last_index(regexp
, 0);
441 *input
= jsstr_empty();
445 last_index
= regexp
->last_index
;
448 match
= alloc_match_state(regexp
->jsregexp
, &ctx
->tmp_heap
, string
+last_index
);
450 jsstr_release(jsstr
);
451 return E_OUTOFMEMORY
;
454 hres
= regexp_match_next(ctx
, ®exp
->dispex
, REM_RESET_INDEX
, jsstr
, &match
);
456 jsstr_release(jsstr
);
465 jsstr_release(jsstr
);
469 static HRESULT
RegExp_exec(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
472 match_state_t
*match
;
480 mark
= heap_pool_mark(&ctx
->tmp_heap
);
482 hres
= run_exec(ctx
, vthis
, argc
? argv
[0] : jsval_string(jsstr_empty()), &string
, &match
, &b
);
484 heap_pool_clear(mark
);
492 hres
= create_match_array(ctx
, string
, match
, &ret
);
494 *r
= jsval_disp(ret
);
500 heap_pool_clear(mark
);
501 jsstr_release(string
);
505 static HRESULT
RegExp_test(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
508 match_state_t
*match
;
516 mark
= heap_pool_mark(&ctx
->tmp_heap
);
517 hres
= run_exec(ctx
, vthis
, argc
? argv
[0] : jsval_string(undef_str
= jsstr_undefined()), NULL
, &match
, &b
);
518 heap_pool_clear(mark
);
520 jsstr_release(undef_str
);
529 static HRESULT
RegExp_value(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
536 return JS_E_FUNCTION_EXPECTED
;
538 FIXME("unimplemented flags %x\n", flags
);
545 static void RegExp_destructor(jsdisp_t
*dispex
)
547 RegExpInstance
*This
= regexp_from_jsdisp(dispex
);
550 regexp_destroy(This
->jsregexp
);
551 jsval_release(This
->last_index_val
);
552 jsstr_release(This
->str
);
556 static HRESULT
RegExp_gc_traverse(struct gc_ctx
*gc_ctx
, enum gc_traverse_op op
, jsdisp_t
*dispex
)
558 return gc_process_linked_val(gc_ctx
, op
, dispex
, ®exp_from_jsdisp(dispex
)->last_index_val
);
561 static const builtin_prop_t RegExp_props
[] = {
562 {L
"exec", RegExp_exec
, PROPF_METHOD
|1},
563 {L
"global", NULL
,0, RegExp_get_global
},
564 {L
"ignoreCase", NULL
,0, RegExp_get_ignoreCase
},
565 {L
"lastIndex", NULL
,0, RegExp_get_lastIndex
, RegExp_set_lastIndex
},
566 {L
"multiline", NULL
,0, RegExp_get_multiline
},
567 {L
"source", NULL
,0, RegExp_get_source
},
568 {L
"test", RegExp_test
, PROPF_METHOD
|1},
569 {L
"toString", RegExp_toString
, PROPF_METHOD
}
572 static const builtin_info_t RegExp_info
= {
575 ARRAY_SIZE(RegExp_props
),
585 static const builtin_prop_t RegExpInst_props
[] = {
586 {L
"global", NULL
,0, RegExp_get_global
},
587 {L
"ignoreCase", NULL
,0, RegExp_get_ignoreCase
},
588 {L
"lastIndex", NULL
,0, RegExp_get_lastIndex
, RegExp_set_lastIndex
},
589 {L
"multiline", NULL
,0, RegExp_get_multiline
},
590 {L
"source", NULL
,0, RegExp_get_source
}
593 static const builtin_info_t RegExpInst_info
= {
596 ARRAY_SIZE(RegExpInst_props
),
606 static HRESULT
alloc_regexp(script_ctx_t
*ctx
, jsstr_t
*str
, jsdisp_t
*object_prototype
, RegExpInstance
**ret
)
608 RegExpInstance
*regexp
;
611 regexp
= calloc(1, sizeof(RegExpInstance
));
613 return E_OUTOFMEMORY
;
616 hres
= init_dispex(®exp
->dispex
, ctx
, &RegExp_info
, object_prototype
);
618 hres
= init_dispex_from_constr(®exp
->dispex
, ctx
, &RegExpInst_info
, ctx
->regexp_constr
);
625 regexp
->str
= jsstr_addref(str
);
626 regexp
->last_index_val
= jsval_number(0);
632 HRESULT
create_regexp(script_ctx_t
*ctx
, jsstr_t
*src
, DWORD flags
, jsdisp_t
**ret
)
634 RegExpInstance
*regexp
;
638 str
= jsstr_flatten(src
);
640 return E_OUTOFMEMORY
;
642 TRACE("%s %lx\n", debugstr_wn(str
, jsstr_length(src
)), flags
);
644 hres
= alloc_regexp(ctx
, src
, NULL
, ®exp
);
648 regexp
->jsregexp
= regexp_new(ctx
, &ctx
->tmp_heap
, str
, jsstr_length(regexp
->str
), flags
, FALSE
);
649 if(!regexp
->jsregexp
) {
650 WARN("regexp_new failed\n");
651 jsdisp_release(®exp
->dispex
);
652 return DISP_E_EXCEPTION
;
655 *ret
= ®exp
->dispex
;
659 HRESULT
create_regexp_var(script_ctx_t
*ctx
, jsval_t src_arg
, jsval_t
*flags_arg
, jsdisp_t
**ret
)
662 const WCHAR
*opt
= NULL
;
666 if(is_object_instance(src_arg
)) {
669 obj
= to_jsdisp(get_object(src_arg
));
671 if(is_class(obj
, JSCLASS_REGEXP
)) {
672 RegExpInstance
*regexp
= regexp_from_jsdisp(obj
);
674 hres
= create_regexp(ctx
, regexp
->str
, regexp
->jsregexp
->flags
, ret
);
680 if(is_undefined(src_arg
))
683 hres
= to_string(ctx
, src_arg
, &src
);
687 if(flags_arg
&& !is_undefined(*flags_arg
)) {
690 hres
= to_string(ctx
, *flags_arg
, &opt_str
);
691 if(SUCCEEDED(hres
)) {
692 opt
= jsstr_flatten(opt_str
);
694 hres
= parse_regexp_flags(opt
, jsstr_length(opt_str
), &flags
);
696 hres
= E_OUTOFMEMORY
;
697 jsstr_release(opt_str
);
702 hres
= create_regexp(ctx
, src
, flags
, ret
);
707 HRESULT
regexp_string_match(script_ctx_t
*ctx
, jsdisp_t
*re
, jsstr_t
*jsstr
, jsval_t
*r
)
709 RegExpInstance
*regexp
= regexp_from_jsdisp(re
);
710 match_result_t
*match_result
;
716 str
= jsstr_flatten(jsstr
);
718 return E_OUTOFMEMORY
;
720 if(!(regexp
->jsregexp
->flags
& REG_GLOB
)) {
721 match_state_t
*match
;
724 mark
= heap_pool_mark(&ctx
->tmp_heap
);
725 match
= alloc_match_state(regexp
->jsregexp
, &ctx
->tmp_heap
, str
);
727 heap_pool_clear(mark
);
728 return E_OUTOFMEMORY
;
731 hres
= regexp_match_next(ctx
, ®exp
->dispex
, 0, jsstr
, &match
);
733 heap_pool_clear(mark
);
741 hres
= create_match_array(ctx
, jsstr
, match
, &ret
);
743 *r
= jsval_disp(ret
);
749 heap_pool_clear(mark
);
753 hres
= regexp_match(ctx
, ®exp
->dispex
, jsstr
, FALSE
, &match_result
, &match_cnt
);
765 hres
= create_array(ctx
, match_cnt
, &array
);
771 for(i
=0; i
< match_cnt
; i
++) {
774 tmp_str
= jsstr_substr(jsstr
, match_result
[i
].index
, match_result
[i
].length
);
776 hres
= E_OUTOFMEMORY
;
780 hres
= jsdisp_propput_idx(array
, i
, jsval_string(tmp_str
));
781 jsstr_release(tmp_str
);
786 while(SUCCEEDED(hres
)) {
787 hres
= jsdisp_propput_name(array
, L
"index", jsval_number(match_result
[match_cnt
-1].index
));
791 hres
= jsdisp_propput_name(array
, L
"lastIndex",
792 jsval_number(match_result
[match_cnt
-1].index
+ match_result
[match_cnt
-1].length
));
796 hres
= jsdisp_propput_name(array
, L
"input", jsval_string(jsstr
));
802 if(SUCCEEDED(hres
) && r
)
803 *r
= jsval_obj(array
);
805 jsdisp_release(array
);
809 static HRESULT
global_idx(script_ctx_t
*ctx
, DWORD idx
, jsval_t
*r
)
813 ret
= jsstr_substr(ctx
->last_match
, ctx
->match_parens
[idx
].index
, ctx
->match_parens
[idx
].length
);
815 return E_OUTOFMEMORY
;
817 *r
= jsval_string(ret
);
821 static HRESULT
RegExpConstr_get_idx1(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
824 return global_idx(ctx
, 0, r
);
827 static HRESULT
RegExpConstr_get_idx2(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
830 return global_idx(ctx
, 1, r
);
833 static HRESULT
RegExpConstr_get_idx3(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
836 return global_idx(ctx
, 2, r
);
839 static HRESULT
RegExpConstr_get_idx4(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
842 return global_idx(ctx
, 3, r
);
845 static HRESULT
RegExpConstr_get_idx5(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
848 return global_idx(ctx
, 4, r
);
851 static HRESULT
RegExpConstr_get_idx6(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
854 return global_idx(ctx
, 5, r
);
857 static HRESULT
RegExpConstr_get_idx7(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
860 return global_idx(ctx
, 6, r
);
863 static HRESULT
RegExpConstr_get_idx8(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
866 return global_idx(ctx
, 7, r
);
869 static HRESULT
RegExpConstr_get_idx9(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
872 return global_idx(ctx
, 8, r
);
875 static HRESULT
RegExpConstr_get_leftContext(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
881 ret
= jsstr_substr(ctx
->last_match
, 0, ctx
->last_match_index
);
883 return E_OUTOFMEMORY
;
885 *r
= jsval_string(ret
);
889 static HRESULT
RegExpConstr_get_rightContext(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
895 ret
= jsstr_substr(ctx
->last_match
, ctx
->last_match_index
+ctx
->last_match_length
,
896 jsstr_length(ctx
->last_match
) - ctx
->last_match_index
- ctx
->last_match_length
);
898 return E_OUTOFMEMORY
;
900 *r
= jsval_string(ret
);
904 static HRESULT
RegExpConstr_value(script_ctx_t
*ctx
, jsval_t vthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
910 case DISPATCH_METHOD
:
912 if(is_object_instance(argv
[0])) {
913 jsdisp_t
*jsdisp
= to_jsdisp(get_object(argv
[0]));
915 if(is_class(jsdisp
, JSCLASS_REGEXP
)) {
916 if(argc
> 1 && !is_undefined(argv
[1]))
917 return JS_E_REGEXP_SYNTAX
;
920 *r
= jsval_obj(jsdisp_addref(jsdisp
));
927 case DISPATCH_CONSTRUCT
: {
931 hres
= create_regexp_var(ctx
, argc
? argv
[0] : jsval_undefined(), argc
> 1 ? argv
+1 : NULL
, &ret
);
942 FIXME("unimplemented flags: %x\n", flags
);
949 static const builtin_prop_t RegExpConstr_props
[] = {
950 {L
"$1", NULL
,0, RegExpConstr_get_idx1
, builtin_set_const
},
951 {L
"$2", NULL
,0, RegExpConstr_get_idx2
, builtin_set_const
},
952 {L
"$3", NULL
,0, RegExpConstr_get_idx3
, builtin_set_const
},
953 {L
"$4", NULL
,0, RegExpConstr_get_idx4
, builtin_set_const
},
954 {L
"$5", NULL
,0, RegExpConstr_get_idx5
, builtin_set_const
},
955 {L
"$6", NULL
,0, RegExpConstr_get_idx6
, builtin_set_const
},
956 {L
"$7", NULL
,0, RegExpConstr_get_idx7
, builtin_set_const
},
957 {L
"$8", NULL
,0, RegExpConstr_get_idx8
, builtin_set_const
},
958 {L
"$9", NULL
,0, RegExpConstr_get_idx9
, builtin_set_const
},
959 {L
"leftContext", NULL
,0, RegExpConstr_get_leftContext
, builtin_set_const
},
960 {L
"rightContext", NULL
,0, RegExpConstr_get_rightContext
, builtin_set_const
}
963 static const builtin_info_t RegExpConstr_info
= {
966 ARRAY_SIZE(RegExpConstr_props
),
972 HRESULT
create_regexp_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, jsdisp_t
**ret
)
974 jsstr_t
*str
= jsstr_empty();
975 RegExpInstance
*regexp
;
978 hres
= alloc_regexp(ctx
, str
, object_prototype
, ®exp
);
983 hres
= create_builtin_constructor(ctx
, RegExpConstr_value
, L
"RegExp", &RegExpConstr_info
,
984 PROPF_CONSTR
|2, ®exp
->dispex
, ret
);
986 jsdisp_release(®exp
->dispex
);
990 HRESULT
parse_regexp_flags(const WCHAR
*str
, DWORD str_len
, DWORD
*ret
)
995 for (p
= str
; p
< str
+str_len
; p
++) {
1004 flags
|= REG_MULTILINE
;
1007 flags
|= REG_STICKY
;
1010 WARN("wrong flag %c\n", *p
);