Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
6f17fa52
Commit
6f17fa52
authored
Apr 15, 2010
by
Jacek Caban
Committed by
Alexandre Julliard
Apr 15, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jscript: Fixed String.match implementation for non-global regexps.
parent
e3ae0243
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
49 deletions
+119
-49
jscript.h
dlls/jscript/jscript.h
+1
-0
regexp.c
dlls/jscript/regexp.c
+81
-0
string.c
dlls/jscript/string.c
+10
-49
regexp.js
dlls/jscript/tests/regexp.js
+27
-0
No files found.
dlls/jscript/jscript.h
View file @
6f17fa52
...
...
@@ -324,6 +324,7 @@ HRESULT regexp_match_next(script_ctx_t*,DispatchEx*,DWORD,const WCHAR*,DWORD,con
DWORD
*
,
DWORD
*
,
match_result_t
*
);
HRESULT
regexp_match
(
script_ctx_t
*
,
DispatchEx
*
,
const
WCHAR
*
,
DWORD
,
BOOL
,
match_result_t
**
,
DWORD
*
);
HRESULT
parse_regexp_flags
(
const
WCHAR
*
,
DWORD
,
DWORD
*
);
HRESULT
regexp_string_match
(
script_ctx_t
*
,
DispatchEx
*
,
BSTR
,
VARIANT
*
,
jsexcept_t
*
);
static
inline
VARIANT
*
get_arg
(
DISPPARAMS
*
dp
,
DWORD
i
)
{
...
...
dlls/jscript/regexp.c
View file @
6f17fa52
...
...
@@ -3878,6 +3878,87 @@ HRESULT create_regexp_var(script_ctx_t *ctx, VARIANT *src_arg, VARIANT *flags_ar
return
create_regexp
(
ctx
,
src
,
-
1
,
flags
,
ret
);
}
HRESULT
regexp_string_match
(
script_ctx_t
*
ctx
,
DispatchEx
*
re
,
BSTR
str
,
VARIANT
*
retv
,
jsexcept_t
*
ei
)
{
RegExpInstance
*
regexp
=
(
RegExpInstance
*
)
re
;
match_result_t
*
match_result
;
DWORD
match_cnt
,
i
,
length
;
DispatchEx
*
array
;
VARIANT
var
;
HRESULT
hres
;
length
=
SysStringLen
(
str
);
if
(
!
(
regexp
->
jsregexp
->
flags
&
JSREG_GLOB
))
{
match_result_t
match
,
*
parens
=
NULL
;
DWORD
parens_cnt
,
parens_size
=
0
;
const
WCHAR
*
cp
=
str
;
hres
=
regexp_match_next
(
ctx
,
&
regexp
->
dispex
,
0
,
str
,
length
,
&
cp
,
&
parens
,
&
parens_size
,
&
parens_cnt
,
&
match
);
if
(
FAILED
(
hres
))
return
hres
;
if
(
retv
)
{
if
(
hres
==
S_OK
)
{
IDispatch
*
ret
;
hres
=
create_match_array
(
ctx
,
str
,
&
match
,
parens
,
parens_cnt
,
ei
,
&
ret
);
if
(
SUCCEEDED
(
hres
))
{
V_VT
(
retv
)
=
VT_DISPATCH
;
V_DISPATCH
(
retv
)
=
ret
;
}
}
else
{
V_VT
(
retv
)
=
VT_NULL
;
}
}
heap_free
(
parens
);
return
S_OK
;
}
hres
=
regexp_match
(
ctx
,
&
regexp
->
dispex
,
str
,
length
,
FALSE
,
&
match_result
,
&
match_cnt
);
if
(
FAILED
(
hres
))
return
hres
;
if
(
!
match_cnt
)
{
TRACE
(
"no match
\n
"
);
if
(
retv
)
V_VT
(
retv
)
=
VT_NULL
;
return
S_OK
;
}
hres
=
create_array
(
ctx
,
match_cnt
,
&
array
);
if
(
FAILED
(
hres
))
return
hres
;
V_VT
(
&
var
)
=
VT_BSTR
;
for
(
i
=
0
;
i
<
match_cnt
;
i
++
)
{
V_BSTR
(
&
var
)
=
SysAllocStringLen
(
match_result
[
i
].
str
,
match_result
[
i
].
len
);
if
(
!
V_BSTR
(
&
var
))
{
hres
=
E_OUTOFMEMORY
;
break
;
}
hres
=
jsdisp_propput_idx
(
array
,
i
,
&
var
,
ei
,
NULL
/*FIXME*/
);
SysFreeString
(
V_BSTR
(
&
var
));
if
(
FAILED
(
hres
))
break
;
}
heap_free
(
match_result
);
if
(
SUCCEEDED
(
hres
)
&&
retv
)
{
V_VT
(
retv
)
=
VT_DISPATCH
;
V_DISPATCH
(
retv
)
=
(
IDispatch
*
)
_IDispatchEx_
(
array
);
}
else
{
jsdisp_release
(
array
);
}
return
hres
;
}
static
HRESULT
RegExpConstr_value
(
script_ctx_t
*
ctx
,
vdisp_t
*
jsthis
,
WORD
flags
,
DISPPARAMS
*
dp
,
VARIANT
*
retv
,
jsexcept_t
*
ei
,
IServiceProvider
*
sp
)
{
...
...
dlls/jscript/string.c
View file @
6f17fa52
...
...
@@ -622,11 +622,9 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
VARIANT
*
retv
,
jsexcept_t
*
ei
,
IServiceProvider
*
sp
)
{
const
WCHAR
*
str
;
match_result_t
*
match_result
;
DispatchEx
*
regexp
;
DispatchEx
*
array
;
VARIANT
var
,
*
arg_var
;
DWORD
length
,
match_cnt
,
i
;
VARIANT
*
arg_var
;
DWORD
length
;
BSTR
val_str
=
NULL
;
HRESULT
hres
=
S_OK
;
...
...
@@ -645,7 +643,7 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
case
VT_DISPATCH
:
regexp
=
iface_to_jsdisp
((
IUnknown
*
)
V_DISPATCH
(
arg_var
));
if
(
regexp
)
{
if
(
regexp
->
builtin_info
->
class
==
JSCLASS_REGEXP
)
if
(
is_class
(
regexp
,
JSCLASS_REGEXP
)
)
break
;
jsdisp_release
(
regexp
);
}
...
...
@@ -664,54 +662,17 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
}
hres
=
get_string_val
(
ctx
,
jsthis
,
ei
,
&
str
,
&
length
,
&
val_str
);
if
(
SUCCEEDED
(
hres
))
hres
=
regexp_match
(
ctx
,
regexp
,
str
,
length
,
FALSE
,
&
match_result
,
&
match_cnt
);
jsdisp_release
(
regexp
);
if
(
FAILED
(
hres
))
{
SysFreeString
(
val_str
);
return
hres
;
}
if
(
!
match_cnt
)
{
TRACE
(
"no match
\n
"
);
if
(
retv
)
V_VT
(
retv
)
=
VT_NULL
;
SysFreeString
(
val_str
);
return
S_OK
;
}
hres
=
create_array
(
ctx
,
match_cnt
,
&
array
);
if
(
FAILED
(
hres
))
{
SysFreeString
(
val_str
);
return
hres
;
}
V_VT
(
&
var
)
=
VT_BSTR
;
for
(
i
=
0
;
i
<
match_cnt
;
i
++
)
{
V_BSTR
(
&
var
)
=
SysAllocStringLen
(
match_result
[
i
].
str
,
match_result
[
i
].
len
);
if
(
!
V_BSTR
(
&
var
))
{
if
(
SUCCEEDED
(
hres
))
{
if
(
!
val_str
)
val_str
=
SysAllocStringLen
(
str
,
length
);
if
(
val_str
)
hres
=
regexp_string_match
(
ctx
,
regexp
,
val_str
,
retv
,
ei
);
else
hres
=
E_OUTOFMEMORY
;
break
;
}
hres
=
jsdisp_propput_idx
(
array
,
i
,
&
var
,
ei
,
NULL
/*FIXME*/
);
SysFreeString
(
V_BSTR
(
&
var
));
if
(
FAILED
(
hres
))
break
;
}
heap_free
(
match_result
);
jsdisp_release
(
regexp
);
SysFreeString
(
val_str
);
if
(
SUCCEEDED
(
hres
)
&&
retv
)
{
V_VT
(
retv
)
=
VT_DISPATCH
;
V_DISPATCH
(
retv
)
=
(
IDispatch
*
)
_IDispatchEx_
(
array
);
}
else
{
jsdisp_release
(
array
);
}
return
hres
;
}
...
...
dlls/jscript/tests/regexp.js
View file @
6f17fa52
...
...
@@ -113,6 +113,7 @@ ok(typeof(m) === "object", "typeof m is not object");
ok
(
m
.
length
===
2
,
"m.length is not 2"
);
ok
(
m
[
"0"
]
===
"ab"
,
"m[0] is not
\"
ab
\"
"
);
ok
(
m
[
"1"
]
===
"ab"
,
"m[1] is not
\"
ab
\"
"
);
/* ok(m.input === "abcabc", "m.input = " + m.input); */
m
=
"abcabc"
.
match
(
/Ab/g
);
ok
(
typeof
(
m
)
===
"object"
,
"typeof m is not object"
);
...
...
@@ -167,6 +168,32 @@ ok(m["0"] === "ab", "m[0] is not \"ab\"");
m
=
"abcabc"
.
match
();
ok
(
m
===
null
,
"m is not null"
);
m
=
"abcabc"
.
match
(
/
(
a
)(
b
)
cabc/
);
ok
(
typeof
(
m
)
===
"object"
,
"typeof m is not object"
);
ok
(
m
.
length
===
3
,
"m.length is not 3"
);
ok
(
m
[
0
]
===
"abcabc"
,
"m[0] is not
\"
abc
\"
"
);
ok
(
m
[
1
]
===
"a"
,
"m[1] is not
\"
a
\"
"
);
ok
(
m
[
2
]
===
"b"
,
"m[2] is not
\"
b
\"
"
);
re
=
/
(
a
)
bcabc/
;
re
.
lastIndex
=
-
3
;
m
=
"abcabc"
.
match
(
re
);
ok
(
typeof
(
m
)
===
"object"
,
"typeof m is not object"
);
ok
(
m
.
length
===
2
,
"m.length = "
+
m
.
length
+
"expected 3"
);
ok
(
m
[
0
]
===
"abcabc"
,
"m[0] is not
\"
abc
\"
"
);
ok
(
m
[
1
]
===
"a"
,
"m[1] is not
\"
a
\"
"
);
ok
(
re
.
lastIndex
===
6
,
"re.lastIndex = "
+
re
.
lastIndex
);
re
=
/
(
a
)
bcabc/
;
re
.
lastIndex
=
2
;
m
=
"abcabcxxx"
.
match
(
re
);
ok
(
typeof
(
m
)
===
"object"
,
"typeof m is not object"
);
ok
(
m
.
length
===
2
,
"m.length = "
+
m
.
length
+
"expected 3"
);
ok
(
m
[
0
]
===
"abcabc"
,
"m[0] is not
\"
abc
\"
"
);
ok
(
m
[
1
]
===
"a"
,
"m[1] is not
\"
a
\"
"
);
ok
(
m
.
input
===
"abcabcxxx"
,
"m.input = "
+
m
.
input
);
ok
(
re
.
lastIndex
===
6
,
"re.lastIndex = "
+
re
.
lastIndex
);
r
=
"- [test] -"
.
replace
(
re
=
/
\[([^\[]
+
)\]
/g
,
"success"
);
ok
(
r
===
"- success -"
,
"r = "
+
r
+
" expected '- success -'"
);
ok
(
re
.
lastIndex
===
8
,
"re.lastIndex = "
+
re
.
lastIndex
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment