外国某JS高手Asen Bozhilov 做的统计表,趁没被墙前立即抱回来!
var JSONTest = (function (global) { var JSON = global.JSON, NATIVE_JSON_PARSE_SUPPORTED = JSON != null && typeof JSON.parse == 'function', ASSERT_ERROR, parse; ASSERT_ERROR = [ /** * Empty string is not a valid JSONValue */ "", /** * Evaluating ECMAScript expression is not allowed in JSONText */ "eval('6 * 6') == 36", /** * ECMAScript list is not allowed as JSONValue */ '"str", "str"', /** * ECMA-262-5 * JSONString : * JSONStringCharacter :: See 15.12.1.1 * JSONSourceCharacter but not double-quote " or backslash \ or U+0000 thru U+001F */ '"""', '"\\"', '"\x00"', '"\x01"', '"\x02"', '"\x03"', '"\x04"', '"\x05"', '"\x06"', '"\x07"', '"\x08"', '"\x09"', '"\x0a"', '"\x0b"', '"\x0c"', '"\x0d"', '"\x0e"', '"\x0f"', '"\x10"', '"\x11"', '"\x12"', '"\x13"', '"\x14"', '"\x15"', '"\x16"', '"\x17"', '"\x18"', '"\x19"', '"\x1a"', '"\x1b"', '"\x1c"', '"\x1d"', '"\x1e"', '"\x1f"', /** * ECMA-262-5 * JSONEscapeSequence :: See 15.12.1.1 * Cannot contain HexEscapeSequence */ '"\\xF1"', /** * ECMA-262-5 * JSONEscapeSequence :: See 15.12.1.1 * Cannot contain OctalEscapeSequence */ '"\\101"', /** * ECMA-262-5 * JSONNumber :: See 15.12.1.1 * - opt DecimalIntegerLiteral JSONFraction opt ExponentPart opt */ '+2', '2.', '.2', /** * ECMA-262-5 * JSONNumber :: See 15.12.1.1 * Cannot contain OctalIntegerLiteral */ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', /** * ECMA-262-5 * JSONNumber :: See 15.12.1.1 * Cannot contain HexIntegerLiteral */ '0xFF', /** * ECMA-262-5 * JSONMember : See 15.12.1.2 * JSONString : JSONValue */ '{property : false}', "{'property' : false}", /** * JSONNumber is not allowed as property name */ '{2 : false}', /** * true, false and null are not allowed as property name */ '{true : false}', '{false : false}', '{null : false}', /** * ECMA-262-5 * JSONMemberList : See 15.12.1.2 * Trailing coma is not allowed in JSONMemberList: */ '{"property": "value",}', /** * ECMA-262-5 * JSONElementList : See 15.12.1.2 * Trailing coma is not allowed in JSONElementList : */ '["value", "value",]', /** * ECMA-262-5 * JSONWhiteSpace :: See 15.12.1.1 * <TAB> * <CR> * <LF> * <SP> */ /** * Vertical Tab <VT> is not allowed in JSONWhiteSpace */ '[\u000B]', /** * Form Feed <FF> is not allowed in JSONWhiteSpace */ '[\u000C]', /** * No-break space <NBSP> is not allowed in JSONWhiteSpace */ '[\u00A0]', /** * Byte Order Mark <BOM> is not allowed in JSONWhiteSpace */ '[\uFEFF]', /** * Other category 鈥淶s鈥� * Any other Unicode 鈥渟pace separator鈥� <USP> are not allowed in JSONWhiteSpace */ '[\u1680]', '[\u180E]', '[\u2000]', '[\u2001]', '[\u2002]', '[\u2003]', '[\u2004]', '[\u2005]', '[\u2006]', '[\u2007]', '[\u2008]', '[\u2009]', '[\u200A]', '[\u202F]', '[\u205F]', '[\u3000]' ]; return { parse : function () { for (var i = 0, j = 2, len = ASSERT_ERROR.length; i < len; i++, j++) { try { JSON.parse(ASSERT_ERROR[i]); this.print(j, false, "Allowed syntax"); }catch (e) { if (e instanceof SyntaxError) { this.print(j, true, "SyntaxError"); } else { this.print(j, false, "Undefined behavior"); } } } }, print : function (idx, pass, msg) { var row = this.table.rows[idx], cell = row.cells[1]; cell.className = pass ? 'yes' : 'no'; cell.innerHTML = msg; }, run : function () { this.table = document.getElementById('json-table'); this.print(1, NATIVE_JSON_PARSE_SUPPORTED, 'Yes'); if (NATIVE_JSON_PARSE_SUPPORTED) { this.parse(); } } }; })(this);
JSON text | This implementation | FF 3.6.6 | FF 4.0 beta | IE8 | IE9 Beta | Opera 11 (build 1055) | Chrome 6.0.472 | Safari 5 (6533.16) | json2 in FF 3.6.6 | |
---|---|---|---|---|---|---|---|---|---|---|
JSON.parse | - | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
JSON.parse(''); | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
eval('6 * 6') == 36; | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"str", "str" | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
""" | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"\" | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"\u0000" | - | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0001" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0002" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0003" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0004" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0005" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0006" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0007" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0008" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0009" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | Allowed syntax | Allowed syntax | |
"\u000a" | - | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"\u000b" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u000c" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u000d" | - | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"\u000e" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u000f" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0010" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0011" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0012" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0013" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0014" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0015" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0016" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0017" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0018" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u0019" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001a" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001b" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001c" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001d" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001e" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\u001f" | - | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
"\xF1" | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
"\101" | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
+2 | - | Allowed syntax | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
2. | - | Allowed syntax | Allowed syntax | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
.2 | - | Allowed syntax | Allowed syntax | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
00 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
01 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
02 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
03 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
04 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
05 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
06 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
07 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
08 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
09 | - | Allowed syntax | Allowed syntax | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
0xFF | - | SyntaxError | - | SyntaxError | SyntaxError | - | SyntaxError | - | SyntaxError | |
{property : false} | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
{'property' : false} | - | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
{2 : false} | - | SyntaxError | - | - | - | - | SyntaxError | - | Allowed syntax | |
{true : false} | - | SyntaxError | - | - | - | - | SyntaxError | - | Allowed syntax | |
{false : false} | - | SyntaxError | - | - | - | - | SyntaxError | - | Allowed syntax | |
{null : false} | - | SyntaxError | - | - | - | - | SyntaxError | - | Allowed syntax | |
{"property" : "value",} | - | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
["value", "value",] | - | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u000B] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | Allowed syntax | |
[\u000C] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | Allowed syntax | |
[\u00A0] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\uFEFF] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
[\u1680] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
[\u180E] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
[\u2000] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2001] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2002] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2003] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2004] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2005] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2006] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2007] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2008] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u2009] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u200A] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax | |
[\u202F] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
[\u205F] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | SyntaxError | |
[\u3000] | - | SyntaxError | SyntaxError | Allowed syntax | SyntaxError | SyntaxError | SyntaxError | SyntaxError | Allowed syntax |