forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringify-replacer.js
More file actions
39 lines (30 loc) · 1.38 KB
/
stringify-replacer.js
File metadata and controls
39 lines (30 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var o = new Array();
var a = new Object();
// Generate getter that will return a constructed string
function propString(i)
{
return function() { var ret = "a" + i; return ret; };
}
function init(o, a)
{
for (var i = 0; i < 21; i++)
{
// Create a replacer array that doesn't hold the string reference by using a getter to create
// the string.
Object.defineProperty(o, i, { get: propString(i) } );
// Initialize the object to be stringify
a["a" + i] = i;
}
}
init(o,a);
WScript.Echo(JSON.stringify(a,o));
// Bug 30349 - invalid replacer array element after valid element causes crash regardless of input
WScript.Echo(JSON.stringify(true, [new Number(1.5), true])); // Original repro
WScript.Echo(JSON.stringify(false, [new Number(1.5), true]));
WScript.Echo(JSON.stringify(null, [new Number(1.5), true]));
// Valid input should just ignore any bad replacer array elements
WScript.Echo(JSON.stringify(a, [false, "a0", true, "a10", false]));