 do_check_eq(toJSONString("Foo-Bar \b\t\n\f\r\"\\ \x01\u20ac"), '"Foo-Bar \\b\\t\\n\\f\\r\\"\\\\ \\u0001\\u20ac"'); 
function run_test() {  // converts an object to a JSON string and tests its integrity  function toJSONString(a) {    var res = JSON.toString(a);    if (!JSON.isMostlyHarmless(res))      throw new SyntaxError("Invalid JSON string: " + res);    return res;  }    // ensures that an object can't be converted to a JSON string  function isInvalidType(a) {    // FIXME: bug 393206    return true;    try {      JSON.toString(a);      return false;    } catch (ex) {      return ex instanceof TypeError;    }  }  // ensures that a string can't be converted back to a JavaScript object  function isInvalidSyntax(a) {    // FIXME: bug 393206    return true;    try {      JSON.fromString(a);      return false;    } catch (ex) {      return ex instanceof SyntaxError;    }  }    Components.utils.import("resource://gre/modules/JSON.jsm");  do_check_eq(typeof(JSON), "object");    // some of the tests are adapted from /testing/mochitest/tests/test_Base.js  do_check_eq(toJSONString(true), "true");  do_check_eq(toJSONString(false), "false");    do_check_eq(toJSONString(1), "1");  do_check_eq(toJSONString(1.23), "1.23");  do_check_eq(toJSONString(1.23e-45), "1.23e-45");    do_check_true(isInvalidType(Infinity));  do_check_true(isInvalidType(NaN));    // FIXME: bug 393206  //do_check_eq(toJSONString("Foo-Bar \b\t\n\f\r\"\\ \x01€"),  //            '"Foo-Bar \\b\\t\\n\\f\\r\\"\\\\ \\u0001\\u20ac"');    do_check_eq(toJSONString(null), "null");  do_check_true(isInvalidType(undefined));    do_check_eq(toJSONString([1, "2", 3.3]), '[1,"2",3.3]');  // duck-typed Array (since we'll never really get something instanceof Array)  do_check_eq(toJSONString({ 0: 0, 1: "1", 2: -2.2, length: 3 }), '[0,"1",-2.2]');    var obj = { a: 1, b: "2", c: [-3e+30] };  do_check_eq(toJSONString(obj), '{"a":1,"b":"2","c":[-3e+30]}');  do_check_eq(JSON.toString(obj, ["b", "c"] /* keys to drop */), '{"a":1}');    do_check_true(isInvalidType(function() { }));    // make sure that toJSONString actually works...  do_check_eq(toJSONString(obj), JSON.toString(obj));    do_check_eq(JSON.fromString("true"), true);  do_check_eq(JSON.fromString("false"), false);  do_check_eq(JSON.fromString("1"), 1);  do_check_eq(JSON.fromString('"2.2"'), "2.2");  do_check_eq(JSON.fromString("1.23e-45"), 1.23e-45);  do_check_true(isInvalidSyntax("NaN"));    // FIXME: bug 393206  //do_check_eq(JSON.fromString('"Foo-Bar \\b\\t\\n\\f\\r\\"\\\\ \\u0001\\u20ac"'),  //                            "Foo-Bar \b\t\n\f\r\"\\ \x01€");  do_check_true(isInvalidSyntax('"multi\nline"'));  do_check_eq(JSON.fromString("null"), null);  do_check_true(isInvalidSyntax("."));    var res = JSON.fromString('[1,"2",3.3]');  do_check_eq(res.length, 3);  do_check_eq(res[2], 3.3);  // res is an instance of the sandbox's array  do_check_false(res instanceof Array);    res = JSON.fromString(toJSONString(obj));  do_check_eq(res.a, obj.a);  do_check_eq(res.b, obj.b);  do_check_eq(res.c.length, obj.c.length);  do_check_eq(res.c[0], obj.c[0]);    // those would throw on JSON.fromString if there's no object |a|  do_check_true(JSON.isMostlyHarmless("a"));  do_check_true(JSON.isMostlyHarmless("a[0]"));  do_check_true(JSON.isMostlyHarmless('a["alert(\\"P0wn3d!\\");"]'));    do_check_false(JSON.isMostlyHarmless('(function() { alert("P0wn3d!"); })()'));  do_check_false(JSON.isMostlyHarmless('{ get a() { return "P0wn3d!"; } }'));}
5459	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/5459/06deeccfe641bc21564cf4382bfa041e711a84ae/test_json.js/buggy/js/src/xpconnect/tests/unit/test_json.js