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
b9d7ebd9
Commit
b9d7ebd9
authored
Aug 23, 2009
by
Piotr Caban
Committed by
Alexandre Julliard
Aug 24, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jscript: Added String.substr implementation.
parent
0091b3fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
2 deletions
+99
-2
string.c
dlls/jscript/string.c
+76
-2
api.js
dlls/jscript/tests/api.js
+23
-0
No files found.
dlls/jscript/string.c
View file @
b9d7ebd9
...
...
@@ -1380,11 +1380,85 @@ static HRESULT String_substring(DispatchEx *dispex, LCID lcid, WORD flags, DISPP
return
S_OK
;
}
/* ECMA-262 3rd Edition B.2.3 */
static
HRESULT
String_substr
(
DispatchEx
*
dispex
,
LCID
lcid
,
WORD
flags
,
DISPPARAMS
*
dp
,
VARIANT
*
retv
,
jsexcept_t
*
ei
,
IServiceProvider
*
sp
)
{
FIXME
(
"
\n
"
);
return
E_NOTIMPL
;
BSTR
val_str
=
NULL
;
const
WCHAR
*
str
;
INT
start
=
0
,
len
;
DWORD
length
;
VARIANT
v
;
HRESULT
hres
;
TRACE
(
"
\n
"
);
if
(
is_class
(
dispex
,
JSCLASS_STRING
))
{
StringInstance
*
this
=
(
StringInstance
*
)
dispex
;
str
=
this
->
str
;
length
=
this
->
length
;
}
else
{
VARIANT
this
;
V_VT
(
&
this
)
=
VT_DISPATCH
;
V_DISPATCH
(
&
this
)
=
(
IDispatch
*
)
_IDispatchEx_
(
dispex
);
hres
=
to_string
(
dispex
->
ctx
,
&
this
,
ei
,
&
val_str
);
if
(
FAILED
(
hres
))
return
hres
;
str
=
val_str
;
length
=
SysStringLen
(
val_str
);
}
if
(
arg_cnt
(
dp
)
>=
1
)
{
hres
=
to_integer
(
dispex
->
ctx
,
dp
->
rgvarg
+
dp
->
cArgs
-
1
,
ei
,
&
v
);
if
(
FAILED
(
hres
))
{
SysFreeString
(
val_str
);
return
hres
;
}
if
(
V_VT
(
&
v
)
==
VT_I4
)
{
start
=
V_I4
(
&
v
);
if
(
start
<
0
)
start
=
0
;
else
if
(
start
>=
length
)
start
=
length
;
}
else
{
start
=
V_R8
(
&
v
)
<
0
.
0
?
0
:
length
;
}
}
if
(
arg_cnt
(
dp
)
>=
2
)
{
hres
=
to_integer
(
dispex
->
ctx
,
dp
->
rgvarg
+
dp
->
cArgs
-
2
,
ei
,
&
v
);
if
(
FAILED
(
hres
))
{
SysFreeString
(
val_str
);
return
hres
;
}
if
(
V_VT
(
&
v
)
==
VT_I4
)
{
len
=
V_I4
(
&
v
);
if
(
len
<
0
)
len
=
0
;
else
if
(
len
>
length
-
start
)
len
=
length
-
start
;
}
else
{
len
=
V_R8
(
&
v
)
<
0
.
0
?
0
:
length
-
start
;
}
}
else
{
len
=
length
-
start
;
}
hres
=
S_OK
;
if
(
retv
)
{
V_VT
(
retv
)
=
VT_BSTR
;
V_BSTR
(
retv
)
=
SysAllocStringLen
(
str
+
start
,
len
);
if
(
!
V_BSTR
(
retv
))
hres
=
E_OUTOFMEMORY
;
}
SysFreeString
(
val_str
);
return
hres
;
}
static
HRESULT
String_sup
(
DispatchEx
*
dispex
,
LCID
lcid
,
WORD
flags
,
DISPPARAMS
*
dp
,
...
...
dlls/jscript/tests/api.js
View file @
b9d7ebd9
...
...
@@ -111,6 +111,10 @@ ok(str.toString() === "", "str.toString() = " + str.toString());
var
str
=
new
String
(
"test"
,
"abc"
);
ok
(
str
.
toString
()
===
"test"
,
"str.toString() = "
+
str
.
toString
());
var
strObj
=
new
Object
();
strObj
.
toString
=
function
()
{
return
"abcd"
};
strObj
.
substr
=
String
.
prototype
.
substr
;
tmp
=
"value "
+
str
;
ok
(
tmp
===
"value test"
,
"'value ' + str = "
+
tmp
);
...
...
@@ -172,6 +176,25 @@ ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
tmp
=
"abcd"
.
substring
();
ok
(
tmp
===
"abcd"
,
"'abcd'.substring() = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
1
,
3
);
ok
(
tmp
===
"bcd"
,
"'abcd'.substr(1,3) = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
-
1
,
3
);
ok
(
tmp
===
"abc"
,
"'abcd'.substr(-1,3) = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
1
,
6
);
ok
(
tmp
===
"bcd"
,
"'abcd'.substr(1,6) = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
2
,
-
1
);
ok
(
tmp
===
""
,
"'abcd'.substr(3,1) = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
2
,
0
);
ok
(
tmp
===
""
,
"'abcd'.substr(2,2) = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
true
,
"3"
);
ok
(
tmp
===
"bcd"
,
"'abcd'.substr(true,'3') = "
+
tmp
);
tmp
=
"abcd"
.
substr
(
1
,
3
,
2
);
ok
(
tmp
===
"bcd"
,
"'abcd'.substr(1,3,2) = "
+
tmp
);
tmp
=
"abcd"
.
substr
();
ok
(
tmp
===
"abcd"
,
"'abcd'.substr() = "
+
tmp
);
tmp
=
strObj
.
substr
(
1
,
1
);
ok
(
tmp
===
"b"
,
"'abcd'.substr(1,3) = "
+
tmp
);
tmp
=
"abcd"
.
slice
(
1
,
3
);
ok
(
tmp
===
"bc"
,
"'abcd'.slice(1,3) = "
+
tmp
);
tmp
=
"abcd"
.
slice
(
1
,
-
1
);
...
...
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