diff --git a/features.txt b/features.txt index 1cf8f2ac43d..c254f1c6c50 100644 --- a/features.txt +++ b/features.txt @@ -99,6 +99,10 @@ Symbol.prototype.description # https://github.com/tc39/proposal-json-superset json-superset +# Well-formed JSON.stringify +# https://github.com/tc39/proposal-well-formed-stringify +well-formed-json-stringify + # Intl.ListFormat # https://github.com/tc39/proposal-intl-list-format Intl.ListFormat diff --git a/test/built-ins/JSON/stringify/15.12.3-0-1.js b/test/built-ins/JSON/stringify/15.12.3-0-1.js index 5cc4240c7de..7fa21c051c1 100644 --- a/test/built-ins/JSON/stringify/15.12.3-0-1.js +++ b/test/built-ins/JSON/stringify/15.12.3-0-1.js @@ -4,19 +4,13 @@ /*--- info: | This test should be run without any built-ins being added/augmented. - The name JSON must be bound to an object. - Section 15 says that every built-in Function object described in this - section � whether as a constructor, an ordinary function, or both � has - a length property whose value is an integer. Unless otherwise specified, - this value is equal to the largest number of named arguments shown in - the section headings for the function description, including optional - parameters. - This default applies to JSON.stringify, and it must exist as a function - taking 3 parameters. + The initial value of [[Configurable]] on JSON is true. This means we + should be able to delete (8.6.2.5) the stringify and parse properties. es5id: 15.12.3-0-1 -description: JSON.stringify must exist as be a function +description: JSON.stringify must be deletable (configurable) ---*/ -var f = JSON.stringify; +var o = JSON; +var desc = Object.getOwnPropertyDescriptor(o, "stringify"); -assert.sameValue(typeof(f), "function", 'typeof(f)'); +assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/built-ins/JSON/stringify/15.12.3-0-2.js b/test/built-ins/JSON/stringify/15.12.3-0-2.js index 08e864d0c88..4c33fa73b8a 100644 --- a/test/built-ins/JSON/stringify/15.12.3-0-2.js +++ b/test/built-ins/JSON/stringify/15.12.3-0-2.js @@ -14,7 +14,7 @@ info: | This default applies to JSON.stringify, and it must exist as a function taking 3 parameters. es5id: 15.12.3-0-2 -description: JSON.stringify must exist as be a function taking 3 parameters +description: JSON.stringify must exist as a function taking 3 parameters ---*/ var f = JSON.stringify; diff --git a/test/built-ins/JSON/stringify/15.12.3-0-3.js b/test/built-ins/JSON/stringify/15.12.3-0-3.js deleted file mode 100644 index 76e41ffb8a4..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-0-3.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - This test should be run without any built-ins being added/augmented. - The initial value of [[Configurable]] on JSON is true. This means we - should be able to delete (8.6.2.5) the stringify and parse properties. -es5id: 15.12.3-0-3 -description: JSON.stringify must be deletable (configurable) ----*/ - -var o = JSON; -var desc = Object.getOwnPropertyDescriptor(o, "stringify"); - -assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-16.js b/test/built-ins/JSON/stringify/15.12.3-11-16.js deleted file mode 100644 index 23f89c2f9ca..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-16.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-16 -description: > - JSON.stringify - stringifying an object where property name is the - union of all null character (The abstract operation Quote(value) - step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-17.js b/test/built-ins/JSON/stringify/15.12.3-11-17.js deleted file mode 100644 index 97232362941..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-17.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-17 -description: > - JSON.stringify - stringifying an object where property name starts - with the union of all null character (The abstract operation - Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fname": "John" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-18.js b/test/built-ins/JSON/stringify/15.12.3-11-18.js deleted file mode 100644 index 6766a4e1995..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-18.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-18 -description: > - JSON.stringify - stringifying an object where property name ends - with the union of all null character (The abstract operation - Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-19.js b/test/built-ins/JSON/stringify/15.12.3-11-19.js deleted file mode 100644 index 052e394f27c..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-19.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-19 -description: > - JSON.stringify - stringifying an object where property name starts - and ends with the union of all null character (The abstract - operation Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fname\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-2.js b/test/built-ins/JSON/stringify/15.12.3-11-2.js index adc1c36c883..721a2fb8ec3 100644 --- a/test/built-ins/JSON/stringify/15.12.3-11-2.js +++ b/test/built-ins/JSON/stringify/15.12.3-11-2.js @@ -4,7 +4,7 @@ /*--- es5id: 15.12.3-11-2 description: > - A JSON.stringify replacer function works is applied to a top level + A JSON.stringify replacer function is applied to a top level undefined value. ---*/ diff --git a/test/built-ins/JSON/stringify/15.12.3-11-20.js b/test/built-ins/JSON/stringify/15.12.3-11-20.js deleted file mode 100644 index 8c9bc27838e..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-20.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-20 -description: > - JSON.stringify - stringifying an object where property name - middles with the union of all null character (The abstract - operation Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "na\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fme": "John" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-21.js b/test/built-ins/JSON/stringify/15.12.3-11-21.js deleted file mode 100644 index ca7e598d61c..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-21.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-21 -description: > - JSON.stringify - stringifying an object where property value is - the union of all null character (The abstract operation - Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-22.js b/test/built-ins/JSON/stringify/15.12.3-11-22.js deleted file mode 100644 index eec1325004d..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-22.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-22 -description: > - JSON.stringify - stringifying an object where property value - starts with the union of all null character (The abstract - operation Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001FJohn" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-23.js b/test/built-ins/JSON/stringify/15.12.3-11-23.js deleted file mode 100644 index 982968f34db..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-23.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-23 -description: > - JSON.stringify - stringifying an object where property value ends - with the union of all null character (The abstract operation - Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name": "John\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-24.js b/test/built-ins/JSON/stringify/15.12.3-11-24.js deleted file mode 100644 index 3fc4140a2c9..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-24.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-24 -description: > - JSON.stringify - stringifying an object where property value - starts and ends with the union of all null character (The abstract - operation Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001FJohn\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-25.js b/test/built-ins/JSON/stringify/15.12.3-11-25.js deleted file mode 100644 index 9a26fa41813..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-25.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-25 -description: > - JSON.stringify - stringifying an object where property value - middles with the union of all null character (The abstract - operation Quote(value) step 2.c) ----*/ - -var result = true; - -var expectedNullChars = new Array(); -expectedNullChars[0] = "\\u0000"; -expectedNullChars[1] = "\\u0001"; -expectedNullChars[2] = "\\u0002"; -expectedNullChars[3] = "\\u0003"; -expectedNullChars[4] = "\\u0004"; -expectedNullChars[5] = "\\u0005"; -expectedNullChars[6] = "\\u0006"; -expectedNullChars[7] = "\\u0007"; -expectedNullChars[8] = "\\b"; -expectedNullChars[9] = "\\t"; -expectedNullChars[10] = "\\n"; -expectedNullChars[11] = "\\u000b"; -expectedNullChars[12] = "\\f"; -expectedNullChars[13] = "\\r"; -expectedNullChars[14] = "\\u000e"; -expectedNullChars[15] = "\\u000f"; -expectedNullChars[16] = "\\u0010"; -expectedNullChars[17] = "\\u0011"; -expectedNullChars[18] = "\\u0012"; -expectedNullChars[19] = "\\u0013"; -expectedNullChars[20] = "\\u0014"; -expectedNullChars[21] = "\\u0015"; -expectedNullChars[22] = "\\u0016"; -expectedNullChars[23] = "\\u0017"; -expectedNullChars[24] = "\\u0018"; -expectedNullChars[25] = "\\u0019"; -expectedNullChars[26] = "\\u001a"; -expectedNullChars[27] = "\\u001b"; -expectedNullChars[28] = "\\u001c"; -expectedNullChars[29] = "\\u001d"; -expectedNullChars[30] = "\\u001e"; -expectedNullChars[31] = "\\u001f"; - -for (var index in expectedNullChars) { - - var str = JSON.stringify({ - "name": "Jo\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fhn" - }); - result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1); -} - -assert(result, 'result !== true'); diff --git a/test/built-ins/JSON/stringify/15.12.3-11-26.js b/test/built-ins/JSON/stringify/15.12.3-11-26.js deleted file mode 100644 index 142160ce5d3..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3-11-26.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3-11-26 -description: > - JSON.stringify - the last element of the concatenation is ']' (The - abstract operation JA(value) step 10.b.iii) ----*/ - -var arrObj = []; -arrObj[0] = "a"; -arrObj[1] = "b"; -arrObj[2] = "c"; - -var jsonText = JSON.stringify(arrObj, undefined, "").toString(); - -assert.sameValue(jsonText.charAt(jsonText.length - 1), "]", 'jsonText.charAt(jsonText.length - 1)'); diff --git a/test/built-ins/JSON/stringify/15.12.3_4-1-1.js b/test/built-ins/JSON/stringify/15.12.3_4-1-1.js index 40b42f57424..636b52e5638 100644 --- a/test/built-ins/JSON/stringify/15.12.3_4-1-1.js +++ b/test/built-ins/JSON/stringify/15.12.3_4-1-1.js @@ -3,7 +3,7 @@ /*--- es5id: 15.12.3_4-1-1 -description: JSON.stringify a circular object throws a error +description: JSON.stringify of a circular object throws a TypeError ---*/ var obj = {}; diff --git a/test/built-ins/JSON/stringify/15.12.3_4-1-2.js b/test/built-ins/JSON/stringify/15.12.3_4-1-2.js index 299853c9164..dfd81c7d2a2 100644 --- a/test/built-ins/JSON/stringify/15.12.3_4-1-2.js +++ b/test/built-ins/JSON/stringify/15.12.3_4-1-2.js @@ -3,11 +3,15 @@ /*--- es5id: 15.12.3_4-1-2 -description: JSON.stringify a circular object throws a TypeError +description: JSON.stringify of an indirectly circular object throws a TypeError ---*/ -var obj = {}; -obj.prop = obj; +var obj = { + p1: { + p2: {} + } +}; +obj.p1.p2.prop = obj; assert.throws(TypeError, function() { JSON.stringify(obj); diff --git a/test/built-ins/JSON/stringify/15.12.3_4-1-3.js b/test/built-ins/JSON/stringify/15.12.3_4-1-3.js deleted file mode 100644 index feb1a6c9c30..00000000000 --- a/test/built-ins/JSON/stringify/15.12.3_4-1-3.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 15.12.3_4-1-3 -description: JSON.stringify a indirectly circular object throws a error ----*/ - -var obj = { - p1: { - p2: {} - } -}; -obj.p1.p2.prop = obj; - -assert.throws(TypeError, function() { - JSON.stringify(obj); -}); diff --git a/test/built-ins/JSON/stringify/string-escape-ascii.js b/test/built-ins/JSON/stringify/string-escape-ascii.js new file mode 100644 index 00000000000..5751c43fdb8 --- /dev/null +++ b/test/built-ins/JSON/stringify/string-escape-ascii.js @@ -0,0 +1,66 @@ +// Copyright (c) 2018 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-quotejsonstring +description: > + JSON.stringify property names and values containing ASCII + characters that require escaping +---*/ + +var char_to_json = { + '"': '\\"', + "\\": "\\\\", + "\x00": "\\u0000", + "\x01": "\\u0001", + "\x02": "\\u0002", + "\x03": "\\u0003", + "\x04": "\\u0004", + "\x05": "\\u0005", + "\x06": "\\u0006", + "\x07": "\\u0007", + "\x08": "\\b", + "\x09": "\\t", + "\x0A": "\\n", + "\x0B": "\\u000b", + "\x0C": "\\f", + "\x0D": "\\r", + "\x0E": "\\u000e", + "\x0F": "\\u000f", + "\x10": "\\u0010", + "\x11": "\\u0011", + "\x12": "\\u0012", + "\x13": "\\u0013", + "\x14": "\\u0014", + "\x15": "\\u0015", + "\x16": "\\u0016", + "\x17": "\\u0017", + "\x18": "\\u0018", + "\x19": "\\u0019", + "\x1A": "\\u001a", + "\x1B": "\\u001b", + "\x1C": "\\u001c", + "\x1D": "\\u001d", + "\x1E": "\\u001e", + "\x1F": "\\u001f" +} + +var chars = Object.keys(char_to_json).join(""); +var chars_reversed = Object.keys(char_to_json).reverse().join(""); +var jsonChars = Object.values(char_to_json).join(""); +var jsonChars_reversed = Object.values(char_to_json).reverse().join(""); +var json = JSON.stringify({ + ["name" + chars + chars_reversed]: chars_reversed + chars + "value" +}); + +for (var char in char_to_json) { + var count = json.split(char_to_json[char]).length - 1; + assert.sameValue(count, 4, + "Every ASCII 0x" + char.charCodeAt(0).toString(16) + " serializes to " + char_to_json[char]); +} + +assert.sameValue( + json, + `{"${"name" + jsonChars + jsonChars_reversed}":"${jsonChars_reversed + jsonChars + "value"}"}`, + "JSON.stringify(objectUsingControlCharacters)" +); diff --git a/test/built-ins/JSON/stringify/string-escape-unicode.js b/test/built-ins/JSON/stringify/string-escape-unicode.js new file mode 100644 index 00000000000..6f35ba16a1d --- /dev/null +++ b/test/built-ins/JSON/stringify/string-escape-unicode.js @@ -0,0 +1,36 @@ +// Copyright (c) 2018 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-quotejsonstring +description: > + JSON.stringify strings containing surrogate code units +features: [well-formed-json-stringify] +---*/ + +assert.sameValue(JSON.stringify("\uD834"), '"\\ud834"', + 'JSON.stringify("\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06"), '"\\udf06"', + 'JSON.stringify("\\uDF06")'); + +assert.sameValue(JSON.stringify("\uD834\uDF06"), '"𝌆"', + 'JSON.stringify("\\uD834\\uDF06")'); +assert.sameValue(JSON.stringify("\uD834\uD834\uDF06\uD834"), '"\\ud834𝌆\\ud834"', + 'JSON.stringify("\\uD834\\uD834\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uD834\uDF06\uDF06"), '"\\ud834𝌆\\udf06"', + 'JSON.stringify("\\uD834\\uD834\\uDF06\\uDF06")'); +assert.sameValue(JSON.stringify("\uDF06\uD834\uDF06\uD834"), '"\\udf06𝌆\\ud834"', + 'JSON.stringify("\\uDF06\\uD834\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06\uD834\uDF06\uDF06"), '"\\udf06𝌆\\udf06"', + 'JSON.stringify("\\uDF06\\uD834\\uDF06\\uDF06")'); + +assert.sameValue(JSON.stringify("\uDF06\uD834"), '"\\udf06\\ud834"', + 'JSON.stringify("\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uDF06\uD834\uD834"), '"𝌆\\ud834\\ud834"', + 'JSON.stringify("\\uD834\\uDF06\\uD834\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uDF06\uD834\uDF06"), '"𝌆𝌆"', + 'JSON.stringify("\\uD834\\uDF06\\uD834\\uDF06")'); +assert.sameValue(JSON.stringify("\uDF06\uDF06\uD834\uD834"), '"\\udf06\\udf06\\ud834\\ud834"', + 'JSON.stringify("\\uDF06\\uDF06\\uD834\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06\uDF06\uD834\uDF06"), '"\\udf06\\udf06𝌆"', + 'JSON.stringify("\\uDF06\\uDF06\\uD834\\uDF06")');