From bf47aebdeeda0ccd16178bf0a52fd0cbd69794fe Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 5 May 2018 14:13:12 -0500 Subject: [PATCH] jscript: Avoid crash when calling stringify() with no arguments. Signed-off-by: Zebediah Figura Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/json.c | 6 ++++++ dlls/jscript/tests/api.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/dlls/jscript/json.c b/dlls/jscript/json.c index fc23b54c0de..0430d415ba2 100644 --- a/dlls/jscript/json.c +++ b/dlls/jscript/json.c @@ -768,6 +768,12 @@ static HRESULT JSON_stringify(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un TRACE("\n"); + if(!argc) { + if(r) + *r = jsval_undefined(); + 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; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 4207f5a7693..f124c4698ac 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -1810,6 +1810,7 @@ ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN"); return; var stringify_tests = [ + [[], undefined], [[true], "true"], [[false], "false"], [[null], "null"], @@ -1836,6 +1837,9 @@ ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN"); "["+i+"] stringify(" + stringify_tests[i][0] + ") returned " + s + " expected " + stringify_tests[i][1]); } + s = JSON.stringify(); + ok(s === undefined, "stringify() returned " + s + " expected undefined"); + s = JSON.stringify(testObj); ok(s === undefined || s === "undefined" /* broken on some old versions */, "stringify(testObj) returned " + s + " expected undfined");