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
34a9c343
Commit
34a9c343
authored
Apr 20, 2021
by
Jacek Caban
Committed by
Alexandre Julliard
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jscript: Support replacer argument in JSON.stringify.
Signed-off-by:
Jacek Caban
<
jacek@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
6a58d990
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
8 deletions
+51
-8
json.c
dlls/jscript/json.c
+31
-7
api.js
dlls/jscript/tests/api.js
+20
-1
No files found.
dlls/jscript/json.c
View file @
34a9c343
...
...
@@ -320,6 +320,8 @@ typedef struct {
size_t
stack_size
;
WCHAR
gap
[
11
];
/* according to the spec, it's no longer than 10 chars */
jsdisp_t
*
replacer
;
}
stringify_ctx_t
;
static
BOOL
stringify_push_obj
(
stringify_ctx_t
*
ctx
,
jsdisp_t
*
obj
)
...
...
@@ -656,7 +658,22 @@ static HRESULT stringify(stringify_ctx_t *ctx, jsdisp_t *object, const WCHAR *na
FIXME
(
"Use toJSON.
\n
"
);
}
/* FIXME: Support replacer replacer. */
if
(
ctx
->
replacer
)
{
jsstr_t
*
name_str
;
jsval_t
args
[
2
];
if
(
!
(
name_str
=
jsstr_alloc
(
name
)))
{
jsval_release
(
value
);
return
E_OUTOFMEMORY
;
}
args
[
0
]
=
jsval_string
(
name_str
);
args
[
1
]
=
value
;
hres
=
jsdisp_call_value
(
ctx
->
replacer
,
to_disp
(
object
),
DISPATCH_METHOD
,
ARRAY_SIZE
(
args
),
args
,
&
v
);
jsstr_release
(
name_str
);
jsval_release
(
value
);
if
(
FAILED
(
hres
))
return
hres
;
value
=
v
;
}
v
=
value
;
hres
=
maybe_to_primitive
(
ctx
->
ctx
,
v
,
&
value
);
...
...
@@ -736,8 +753,8 @@ static HRESULT stringify(stringify_ctx_t *ctx, jsdisp_t *object, const WCHAR *na
/* ECMA-262 5.1 Edition 15.12.3 */
static
HRESULT
JSON_stringify
(
script_ctx_t
*
ctx
,
vdisp_t
*
jsthis
,
WORD
flags
,
unsigned
argc
,
jsval_t
*
argv
,
jsval_t
*
r
)
{
stringify_ctx_t
stringify_ctx
=
{
ctx
,
NULL
,
0
,
0
,
NULL
,
0
,
0
,
{
0
}
};
jsdisp_t
*
obj
;
stringify_ctx_t
stringify_ctx
=
{
ctx
};
jsdisp_t
*
obj
=
NULL
,
*
replacer
;
HRESULT
hres
;
TRACE
(
"
\n
"
);
...
...
@@ -748,9 +765,14 @@ static HRESULT JSON_stringify(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return
S_OK
;
}
if
(
argc
>=
2
&&
is_object_instance
(
argv
[
1
]))
{
FIXME
(
"Replacer %s not yet supported
\n
"
,
debugstr_jsval
(
argv
[
1
]));
return
E_NOTIMPL
;
if
(
argc
>=
2
&&
is_object_instance
(
argv
[
1
])
&&
get_object
(
argv
[
1
])
&&
(
replacer
=
to_jsdisp
(
get_object
(
argv
[
1
]))))
{
if
(
is_callable
(
replacer
))
{
stringify_ctx
.
replacer
=
jsdisp_addref
(
replacer
);
}
else
if
(
is_class
(
replacer
,
JSCLASS_ARRAY
))
{
FIXME
(
"Array replacer not yet supported
\n
"
);
return
E_NOTIMPL
;
}
}
if
(
argc
>=
3
)
{
...
...
@@ -758,7 +780,7 @@ static HRESULT JSON_stringify(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
hres
=
maybe_to_primitive
(
ctx
,
argv
[
2
],
&
space_val
);
if
(
FAILED
(
hres
))
return
hres
;
goto
fail
;
if
(
is_number
(
space_val
))
{
double
n
=
get_number
(
space_val
);
...
...
@@ -805,6 +827,8 @@ static HRESULT JSON_stringify(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
fail:
if
(
obj
)
jsdisp_release
(
obj
);
if
(
stringify_ctx
.
replacer
)
jsdisp_release
(
stringify_ctx
.
replacer
);
heap_free
(
stringify_ctx
.
buf
);
heap_free
(
stringify_ctx
.
stack
);
return
hres
;
...
...
dlls/jscript/tests/api.js
View file @
34a9c343
...
...
@@ -1923,7 +1923,7 @@ ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
[[
NaN
],
"null"
],
[[
Infinity
],
"null"
],
[[
-
Infinity
],
"null"
],
[[{
prop1
:
true
,
prop2
:
"string"
}],
"{
\"
prop1
\"
:true,
\"
prop2
\"
:
\"
string
\"
}"
],
[[{
prop1
:
true
,
prop2
:
"string"
,
func1
:
function
()
{}
}],
"{
\"
prop1
\"
:true,
\"
prop2
\"
:
\"
string
\"
}"
],
[[{
prop1
:
true
,
prop2
:
testObj
,
prop3
:
undefined
}],
"{
\"
prop1
\"
:true}"
],
[[{
prop1
:
true
,
prop2
:
{
prop
:
"string"
}},
undefined
,
" "
],
"{
\
n
\"
prop1
\"
: true,
\
n
\"
prop2
\"
: {
\
n
\"
prop
\"
:
\"
string
\"
\
n }
\
n}"
],
...
...
@@ -1951,6 +1951,25 @@ ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
ok
(
s
===
undefined
||
s
===
"undefined"
/* broken on some old versions */
,
"stringify(undefined) returned "
+
s
+
" expected undefined"
);
s
=
JSON
.
stringify
(
1
,
function
(
name
,
value
)
{
ok
(
name
===
""
,
"name = "
+
name
);
ok
(
value
===
1
,
"value = "
+
value
);
ok
(
this
[
name
]
===
value
,
"this["
+
name
+
"] = "
+
this
[
name
]
+
" expected "
+
value
);
return
2
;
});
ok
(
s
==
"2"
,
"s = "
+
s
);
var
o
=
{
prop
:
1
};
s
=
JSON
.
stringify
(
1
,
function
(
name
,
value
)
{
ok
(
name
===
""
||
name
===
"prop"
,
"name = "
+
name
);
ok
(
value
===
1
||
value
===
true
,
"value = "
+
value
);
ok
(
this
[
name
]
===
value
,
"this["
+
name
+
"] = "
+
this
[
name
]
+
" expected "
+
value
);
if
(
name
===
""
)
return
o
;
ok
(
this
===
o
,
"this != o"
);
return
value
;
});
ok
(
s
==
"{
\"
prop
\"
:1}"
,
"s = "
+
s
);
var
parse_tests
=
[
[
"true"
,
true
],
[
"
\
nnull "
,
null
],
...
...
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