mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
* Rename & improve "length" test * Use verifyProperty in "name" test * Rename & improve property descriptor test * Remove duplicated test https://github.com/tc39/test262/blob/master/test/built-ins/Object/prototype/toString/proxy-array.js * Rename proxy value test * Rename & improve String object unwrapping test * Rename & improve Number object unwrapping test * Rename & improve Boolean object unwrapping test * Rename & merge replacer returns undefined tests * Rename & merge replacer function tests * Rename replacer array revoked proxy test * Add cross-realm replacer array revoked proxy test * Add array proxy replacer test * Add replacer array keys order test * Add empty replacer array test * Add non-finite numbers serialization test * Add replacer array abrupt completion test * Add replacer array with duplicates test * Add replacer array ignores undefined test * Add replacer array unwraps strings test * Add replacer array unwraps numbers test * Rename & merge circular object tests * Add circular array test * Rename & merge top-level primitives tests * Rename string escape tests * Rename BigInt tests * Rename & improve function value test * Add replacer function abrupt test * Rename & merge wrong space type tests * Rename float number space test * Rename & improve Number object space test * Rename & improve String object space test * Rename basic numeric space test * Rename string space slice test * Add replacer array numbers test * Add toJSON abrupt completions test * Add not callable toJSON test * Add toJSON call arguments test * Add replacer array wrong types test * Rename & improve string space test * Rename & improve replacer wrong type test * Add built-in object requirements test * Add basic toJSON result test * Add abrupt array value test * Add abrupt object value test * Rename & merge space number clamp tests * Add replacer function wrapper test * Add symbol value test * Add negative zero value test * Add replacer function & toJSON test * Add circular object from toJSON test * Add circular array from toJSON test * Add circular object from replacer test * Add circular array from replacer test * Add replacer function arguments test * Split & improve proxy value test * Split & improve revoked proxy value test
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
// 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)"
|
|
);
|