Bug 636175 - Move dom/src/json/test/unit tests into JS suite tests, because that's where they belong. r=pbiggar
authorJeff Walden <jwalden@mit.edu>
Fri, 25 Feb 2011 19:01:54 -0800
changeset 67931 0756cd76cb066d9f7399612873bd21e3e0c7de26
parent 67930 67596937aa398b3fee032ef90e63eb6541f18749
child 67932 d2f2cac2e9802c29a3628aeebbd77f868d17c0b0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbiggar
bugs636175
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 636175 - Move dom/src/json/test/unit tests into JS suite tests, because that's where they belong. r=pbiggar
dom/src/json/test/unit/decodeFromStream-01.json
dom/src/json/test/unit/fail1.json
dom/src/json/test/unit/fail10.json
dom/src/json/test/unit/fail11.json
dom/src/json/test/unit/fail12.json
dom/src/json/test/unit/fail13.json
dom/src/json/test/unit/fail14.json
dom/src/json/test/unit/fail15.json
dom/src/json/test/unit/fail16.json
dom/src/json/test/unit/fail17.json
dom/src/json/test/unit/fail18.json
dom/src/json/test/unit/fail19.json
dom/src/json/test/unit/fail2.json
dom/src/json/test/unit/fail20.json
dom/src/json/test/unit/fail21.json
dom/src/json/test/unit/fail22.json
dom/src/json/test/unit/fail23.json
dom/src/json/test/unit/fail24.json
dom/src/json/test/unit/fail25.json
dom/src/json/test/unit/fail26.json
dom/src/json/test/unit/fail27.json
dom/src/json/test/unit/fail28.json
dom/src/json/test/unit/fail29.json
dom/src/json/test/unit/fail3.json
dom/src/json/test/unit/fail30.json
dom/src/json/test/unit/fail31.json
dom/src/json/test/unit/fail32.json
dom/src/json/test/unit/fail33.json
dom/src/json/test/unit/fail34.json
dom/src/json/test/unit/fail4.json
dom/src/json/test/unit/fail5.json
dom/src/json/test/unit/fail6.json
dom/src/json/test/unit/fail7.json
dom/src/json/test/unit/fail8.json
dom/src/json/test/unit/fail9.json
dom/src/json/test/unit/head_json.js
dom/src/json/test/unit/json2.js
dom/src/json/test/unit/pass1.json
dom/src/json/test/unit/pass3.json
dom/src/json/test/unit/test_decode.js
dom/src/json/test/unit/test_decodeFromStream.js
dom/src/json/test/unit/test_decode_long_input.js
dom/src/json/test/unit/test_decode_primitives.js
dom/src/json/test/unit/test_dropping_elements_in_stringify.js
dom/src/json/test/unit/test_encode.js
dom/src/json/test/unit/test_encode_primitives.js
dom/src/json/test/unit/test_encoding_errors.js
dom/src/json/test/unit/test_long_input.js
dom/src/json/test/unit/test_replacer.js
dom/src/json/test/unit/test_reviver.js
dom/src/json/test/unit/test_syntax_errors.js
dom/src/json/test/unit/test_wrappers.js
js/src/tests/e4x/extensions/json-stringify-dropping-xml-elements.js
js/src/tests/e4x/extensions/jstests.list
js/src/tests/e4x/extensions/stringify-xml.js
js/src/tests/ecma_5/JSON/cyclic-stringify.js
js/src/tests/ecma_5/JSON/jstests.list
js/src/tests/ecma_5/JSON/parse-crockford-01.js
js/src/tests/ecma_5/JSON/parse-octal-syntax-error.js
js/src/tests/ecma_5/JSON/parse-primitives.js
js/src/tests/ecma_5/JSON/parse-reviver.js
js/src/tests/ecma_5/JSON/parse-syntax-errors-01.js
js/src/tests/ecma_5/JSON/parse-syntax-errors-02.js
js/src/tests/ecma_5/JSON/parse.js
js/src/tests/ecma_5/JSON/stringify-dropping-elements.js
js/src/tests/ecma_5/JSON/stringify-primitives.js
js/src/tests/ecma_5/JSON/stringify-replacer.js
js/src/tests/ecma_5/JSON/stringify.js
rename from dom/src/json/test/unit/pass3.json
rename to dom/src/json/test/unit/decodeFromStream-01.json
deleted file mode 100644
--- a/dom/src/json/test/unit/fail1.json
+++ /dev/null
@@ -1,1 +0,0 @@
-"Unterminated string literal
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail10.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Extra value after close": true} "misplaced quoted value"
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail11.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Illegal expression": 1 + 2}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail12.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Illegal invocation": alert()}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail13.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Numbers cannot have leading zeroes": 013}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail14.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Numbers cannot be hex": 0x14}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail15.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Illegal backslash escape: \x15"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail16.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[\naked]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail17.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Illegal backslash escape: \017"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail18.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail19.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Missing colon" null}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail2.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Unclosed array"
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail20.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Double colon":: null}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail21.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Comma instead of colon", null}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail22.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Colon instead of comma": false]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail23.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Bad value", truth]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail24.json
+++ /dev/null
@@ -1,1 +0,0 @@
-['single quote']
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail25.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["	tab	character	in	string	"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail26.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["tab\   character\   in\  string\  "]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail27.json
+++ /dev/null
@@ -1,2 +0,0 @@
-["line
-break"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail28.json
+++ /dev/null
@@ -1,2 +0,0 @@
-["line\
-break"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail29.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[0e]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail3.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{unquoted_key: "keys must be quoted"}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail30.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[0e+]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail31.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[0e+-1]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail32.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Comma instead if closing brace": true,
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail33.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["mismatch"}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail34.json
+++ /dev/null
@@ -1,1 +0,0 @@
-0{
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail4.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["extra comma",]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail5.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["double extra comma",,]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail6.json
+++ /dev/null
@@ -1,1 +0,0 @@
-[   , "<-- missing value"]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail7.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Comma after the close"],
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail8.json
+++ /dev/null
@@ -1,1 +0,0 @@
-["Extra close"]]
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/fail9.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"Extra comma": true,}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/head_json.js
+++ /dev/null
@@ -1,19 +0,0 @@
-var Ci = Components.interfaces;
-var Cc = Components.classes;
-
-var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-var workingDir = dirSvc.get("TmpD", Ci.nsIFile);
-
-var outputName = "json-test-output";
-var outputDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
-outputDir.initWithFile(workingDir);
-outputDir.append(outputName);
-
-if (!outputDir.exists()) {
-  outputDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0777);
-} else if (!outputDir.isDirectory()) {
-  do_throw(outputName + " is not a directory?")
-}
-var crockfordJSON = null;
-load("json2.js");
deleted file mode 100644
--- a/dom/src/json/test/unit/json2.js
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
-    http://www.JSON.org/json2.js
-    2008-11-19
-
-    Public Domain.
-
-    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-
-    See http://www.JSON.org/js.html
-
-    This file creates a global JSON object containing two methods: stringify
-    and parse.
-
-        JSON.stringify(value, replacer, space)
-            value       any JavaScript value, usually an object or array.
-
-            replacer    an optional parameter that determines how object
-                        values are stringified for objects. It can be a
-                        function or an array of strings.
-
-            space       an optional parameter that specifies the indentation
-                        of nested structures. If it is omitted, the text will
-                        be packed without extra whitespace. If it is a number,
-                        it will specify the number of spaces to indent at each
-                        level. If it is a string (such as '\t' or '&nbsp;'),
-                        it contains the characters used to indent at each level.
-
-            This method produces a JSON text from a JavaScript value.
-
-            When an object value is found, if the object contains a toJSON
-            method, its toJSON method will be called and the result will be
-            stringified. A toJSON method does not serialize: it returns the
-            value represented by the name/value pair that should be serialized,
-            or undefined if nothing should be serialized. The toJSON method
-            will be passed the key associated with the value, and this will be
-            bound to the object holding the key.
-
-            For example, this would serialize Dates as ISO strings.
-
-                Date.prototype.toJSON = function (key) {
-                    function f(n) {
-                        // Format integers to have at least two digits.
-                        return n < 10 ? '0' + n : n;
-                    }
-
-                    return this.getUTCFullYear()   + '-' +
-                         f(this.getUTCMonth() + 1) + '-' +
-                         f(this.getUTCDate())      + 'T' +
-                         f(this.getUTCHours())     + ':' +
-                         f(this.getUTCMinutes())   + ':' +
-                         f(this.getUTCSeconds())   + 'Z';
-                };
-
-            You can provide an optional replacer method. It will be passed the
-            key and value of each member, with this bound to the containing
-            object. The value that is returned from your method will be
-            serialized. If your method returns undefined, then the member will
-            be excluded from the serialization.
-
-            If the replacer parameter is an array of strings, then it will be
-            used to select the members to be serialized. It filters the results
-            such that only members with keys listed in the replacer array are
-            stringified.
-
-            Values that do not have JSON representations, such as undefined or
-            functions, will not be serialized. Such values in objects will be
-            dropped; in arrays they will be replaced with null. You can use
-            a replacer function to replace those with JSON values.
-            JSON.stringify(undefined) returns undefined.
-
-            The optional space parameter produces a stringification of the
-            value that is filled with line breaks and indentation to make it
-            easier to read.
-
-            If the space parameter is a non-empty string, then that string will
-            be used for indentation. If the space parameter is a number, then
-            the indentation will be that many spaces.
-
-            Example:
-
-            text = JSON.stringify(['e', {pluribus: 'unum'}]);
-            // text is '["e",{"pluribus":"unum"}]'
-
-
-            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
-            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
-
-            text = JSON.stringify([new Date()], function (key, value) {
-                return this[key] instanceof Date ?
-                    'Date(' + this[key] + ')' : value;
-            });
-            // text is '["Date(---current time---)"]'
-
-
-        JSON.parse(text, reviver)
-            This method parses a JSON text to produce an object or array.
-            It can throw a SyntaxError exception.
-
-            The optional reviver parameter is a function that can filter and
-            transform the results. It receives each of the keys and values,
-            and its return value is used instead of the original value.
-            If it returns what it received, then the structure is not modified.
-            If it returns undefined then the member is deleted.
-
-            Example:
-
-            // Parse the text. Values that look like ISO date strings will
-            // be converted to Date objects.
-
-            myData = JSON.parse(text, function (key, value) {
-                var a;
-                if (typeof value === 'string') {
-                    a =
-/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
-                    if (a) {
-                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
-                            +a[5], +a[6]));
-                    }
-                }
-                return value;
-            });
-
-            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
-                var d;
-                if (typeof value === 'string' &&
-                        value.slice(0, 5) === 'Date(' &&
-                        value.slice(-1) === ')') {
-                    d = new Date(value.slice(5, -1));
-                    if (d) {
-                        return d;
-                    }
-                }
-                return value;
-            });
-
-
-    This is a reference implementation. You are free to copy, modify, or
-    redistribute.
-
-    This code should be minified before deployment.
-    See http://javascript.crockford.com/jsmin.html
-
-    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
-    NOT CONTROL.
-*/
-
-/*jslint evil: true */
-
-/*global JSON */
-
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
-    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
-    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
-    lastIndex, length, parse, prototype, push, replace, slice, stringify,
-    test, toJSON, toString, valueOf
-*/
-
-// Create a JSON object only if one does not already exist. We create the
-// methods in a closure to avoid creating global variables.
-
-if (!this.crockfordJSON) {
-    crockfordJSON = {};
-    crockfordJSON.window = this;
-}
-(function () {
-
-    function f(n) {
-        // Format integers to have at least two digits.
-        return n < 10 ? '0' + n : n;
-    }
-
-    if (typeof Date.prototype.toJSON !== 'function') {
-
-        Date.prototype.toJSON = function (key) {
-
-            return this.getUTCFullYear()   + '-' +
-                 f(this.getUTCMonth() + 1) + '-' +
-                 f(this.getUTCDate())      + 'T' +
-                 f(this.getUTCHours())     + ':' +
-                 f(this.getUTCMinutes())   + ':' +
-                 f(this.getUTCSeconds())   + 'Z';
-        };
-
-        String.prototype.toJSON =
-        Number.prototype.toJSON =
-        Boolean.prototype.toJSON = function (key) {
-            return this.valueOf();
-        };
-    }
-
-    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
-        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
-        gap,
-        indent,
-        meta = {    // table of character substitutions
-            '\b': '\\b',
-            '\t': '\\t',
-            '\n': '\\n',
-            '\f': '\\f',
-            '\r': '\\r',
-            '"' : '\\"',
-            '\\': '\\\\'
-        },
-        rep;
-
-
-    function quote(string) {
-
-// If the string contains no control characters, no quote characters, and no
-// backslash characters, then we can safely slap some quotes around it.
-// Otherwise we must also replace the offending characters with safe escape
-// sequences.
-
-        escapable.lastIndex = 0;
-        return escapable.test(string) ?
-            '"' + string.replace(escapable, function (a) {
-                var c = meta[a];
-                return typeof c === 'string' ? c :
-                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
-            }) + '"' :
-            '"' + string + '"';
-    }
-
-
-    function str(key, holder) {
-
-// Produce a string from holder[key].
-
-        var i,          // The loop counter.
-            k,          // The member key.
-            v,          // The member value.
-            length,
-            mind = gap,
-            partial,
-            value = holder[key];
-
-// If the value has a toJSON method, call it to obtain a replacement value.
-
-        if (value && typeof value === 'object' &&
-                typeof value.toJSON === 'function') {
-            value = value.toJSON(key);
-        }
-
-// If we were called with a replacer function, then call the replacer to
-// obtain a replacement value.
-
-        if (typeof rep === 'function') {
-            value = rep.call(holder, key, value);
-        }
-
-// What happens next depends on the value's type.
-
-        switch (typeof value) {
-        case 'string':
-            return quote(value);
-
-        case 'number':
-
-// JSON numbers must be finite. Encode non-finite numbers as null.
-
-            return isFinite(value) ? String(value) : 'null';
-
-        case 'boolean':
-        case 'null':
-
-// If the value is a boolean or null, convert it to a string. Note:
-// typeof null does not produce 'null'. The case is included here in
-// the remote chance that this gets fixed someday.
-
-            return String(value);
-
-// If the type is 'object', we might be dealing with an object or an array or
-// null.
-
-        case 'object':
-
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
-// so watch out for that case.
-
-            if (!value) {
-                return 'null';
-            }
-
-// Make an array to hold the partial results of stringifying this object value.
-
-            gap += indent;
-            partial = [];
-
-// Is the value an array?
-
-            if (Object.prototype.toString.apply(value) === '[object Array]') {
-
-// The value is an array. Stringify every element. Use null as a placeholder
-// for non-JSON values.
-
-                length = value.length;
-                for (i = 0; i < length; i += 1) {
-                    partial[i] = str(i, value) || 'null';
-                }
-
-// Join all of the elements together, separated with commas, and wrap them in
-// brackets.
-
-                v = partial.length === 0 ? '[]' :
-                    gap ? '[\n' + gap +
-                            partial.join(',\n' + gap) + '\n' +
-                                mind + ']' :
-                          '[' + partial.join(',') + ']';
-                gap = mind;
-                return v;
-            }
-
-// If the replacer is an array, use it to select the members to be stringified.
-
-            if (rep && typeof rep === 'object') {
-                length = rep.length;
-                for (i = 0; i < length; i += 1) {
-                    k = rep[i];
-                    if (typeof k === 'string') {
-                        v = str(k, value);
-                        if (v) {
-                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
-                        }
-                    }
-                }
-            } else {
-
-// Otherwise, iterate through all of the keys in the object.
-
-                for (k in value) {
-                    if (Object.hasOwnProperty.call(value, k)) {
-                        v = str(k, value);
-                        if (v) {
-                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
-                        }
-                    }
-                }
-            }
-
-// Join all of the member texts together, separated with commas,
-// and wrap them in braces.
-
-            v = partial.length === 0 ? '{}' :
-                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
-                        mind + '}' : '{' + partial.join(',') + '}';
-            gap = mind;
-            return v;
-        }
-    }
-
-// If the JSON object does not yet have a stringify method, give it one.
-
-    if (typeof crockfordJSON.stringify !== 'function') {
-        crockfordJSON.stringify = function (value, replacer, space) {
-
-// The stringify method takes a value and an optional replacer, and an optional
-// space parameter, and returns a JSON text. The replacer can be a function
-// that can replace values, or an array of strings that will select the keys.
-// A default replacer method can be provided. Use of the space parameter can
-// produce text that is more easily readable.
-
-            var i;
-            gap = '';
-            indent = '';
-
-// If the space parameter is a number, make an indent string containing that
-// many spaces.
-
-            if (typeof space === 'number') {
-                for (i = 0; i < space; i += 1) {
-                    indent += ' ';
-                }
-
-// If the space parameter is a string, it will be used as the indent string.
-
-            } else if (typeof space === 'string') {
-                indent = space;
-            }
-
-// If there is a replacer, it must be a function or an array.
-// Otherwise, throw an error.
-
-            rep = replacer;
-            if (replacer && typeof replacer !== 'function' &&
-                    (typeof replacer !== 'object' ||
-                     typeof replacer.length !== 'number')) {
-                throw new Error('JSON.stringify');
-            }
-
-// Make a fake root object containing our value under the key of ''.
-// Return the result of stringifying the value.
-
-            return str('', {'': value});
-        };
-    }
-
-
-// If the JSON object does not yet have a parse method, give it one.
-
-    if (typeof crockfordJSON.parse !== 'function') {
-        crockfordJSON.parse = function (text, reviver) {
-
-// The parse method takes a text and an optional reviver function, and returns
-// a JavaScript value if the text is a valid JSON text.
-
-            var j;
-
-            function walk(holder, key) {
-
-// The walk method is used to recursively walk the resulting structure so
-// that modifications can be made.
-
-                var k, v, value = holder[key];
-                if (value && typeof value === 'object') {
-                    for (k in value) {
-                        if (Object.hasOwnProperty.call(value, k)) {
-                            v = walk(value, k);
-                            if (v !== undefined) {
-                                value[k] = v;
-                            } else {
-                                delete value[k];
-                            }
-                        }
-                    }
-                }
-                return reviver.call(holder, key, value);
-            }
-
-
-// Parsing happens in four stages. In the first stage, we replace certain
-// Unicode characters with escape sequences. JavaScript handles many characters
-// incorrectly, either silently deleting them, or treating them as line endings.
-
-            cx.lastIndex = 0;
-            if (cx.test(text)) {
-                text = text.replace(cx, function (a) {
-                    return '\\u' +
-                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
-                });
-            }
-
-// In the second stage, we run the text against regular expressions that look
-// for non-JSON patterns. We are especially concerned with '()' and 'new'
-// because they can cause invocation, and '=' because it can cause mutation.
-// But just to be safe, we want to reject all unexpected forms.
-
-// We split the second stage into 4 regexp operations in order to work around
-// crippling inefficiencies in IE's and Safari's regexp engines. First we
-// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
-// replace all simple value tokens with ']' characters. Third, we delete all
-// open brackets that follow a colon or comma or that begin the text. Finally,
-// we look to see that the remaining characters are only whitespace or ']' or
-// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
-
-            if (/^[\],:{}\s]*$/.
-test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
-replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
-replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
-
-// In the third stage we use the eval function to compile the text into a
-// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
-// in JavaScript: it can begin a block or an object literal. We wrap the text
-// in parens to eliminate the ambiguity.
-
-                j = eval('(' + text + ')');
-
-// In the optional fourth stage, we recursively walk the new structure, passing
-// each name/value pair to a reviver function for possible transformation.
-
-                return typeof reviver === 'function' ?
-                    walk({'': j}, '') : j;
-            }
-
-// If the text is not JSON parseable, then a SyntaxError is thrown.
-
-            throw new SyntaxError('JSON.parse');
-        };
-    }
-})();
deleted file mode 100644
--- a/dom/src/json/test/unit/pass1.json
+++ /dev/null
@@ -1,58 +0,0 @@
-[
-    "JSON Test Pattern pass1",
-    {"object with 1 member":["array with 1 element"]},
-    {},
-    [],
-    -42,
-    true,
-    false,
-    null,
-    {
-        "integer": 1234567890,
-        "real": -9876.543210,
-        "e": 0.123456789e-12,
-        "E": 1.234567890E+34,
-        "":  23456789012E66,
-        "zero": 0,
-        "one": 1,
-        "space": " ",
-        "quote": "\"",
-        "backslash": "\\",
-        "controls": "\b\f\n\r\t",
-        "slash": "/ & \/",
-        "alpha": "abcdefghijklmnopqrstuvwyz",
-        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
-        "digit": "0123456789",
-        "0123456789": "digit",
-        "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
-        "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
-        "true": true,
-        "false": false,
-        "null": null,
-        "array":[  ],
-        "object":{  },
-        "address": "50 St. James Street",
-        "url": "http://www.JSON.org/",
-        "comment": "// /* <!-- --",
-        "# -- --> */": " ",
-        " s p a c e d " :[1,2 , 3
-
-,
-
-4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],
-        "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
-        "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
-        "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
-: "A key can be any string"
-    },
-    0.5 ,98.6
-,
-99.44
-,
-
-1066,
-1e1,
-0.1e1,
-1e-1,
-1e00,2e+00,2e-00
-,"rosebud"]
rename from dom/src/json/test/unit/test_decode.js
rename to dom/src/json/test/unit/test_decodeFromStream.js
--- a/dom/src/json/test/unit/test_decode.js
+++ b/dom/src/json/test/unit/test_decodeFromStream.js
@@ -1,196 +1,26 @@
-function decode_strings() {
-  // empty object
-  var x = nativeJSON.decode("{}");
-  do_check_eq(typeof x, "object");
-
-  // empty array
-  x = nativeJSON.decode("[]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 0);
-  do_check_eq(x.constructor, Array);
-
-  // one element array
-  x = nativeJSON.decode("[[]]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 1);
-  do_check_eq(x.constructor, Array);
-  do_check_eq(x[0].constructor, Array);
+var Ci = Components.interfaces;
+var Cc = Components.classes;
 
-  // multiple arrays
-  x = nativeJSON.decode("[[],[],[]]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 3);
-  do_check_eq(x.constructor, Array);
-  do_check_eq(x[0].constructor, Array);
-  do_check_eq(x[1].constructor, Array);
-  do_check_eq(x[2].constructor, Array);
-
-  // array key/value
-  x = nativeJSON.decode('{"foo":[]}');
-  do_check_eq(typeof x, "object");
-  do_check_eq(typeof x.foo, "object");
-  do_check_eq(x.foo.constructor, Array);
-  x = nativeJSON.decode('{"foo":[], "bar":[]}');
-  do_check_eq(typeof x, "object");
-  do_check_eq(typeof x.foo, "object");
-  do_check_eq(x.foo.constructor, Array);
-  do_check_eq(typeof x.bar, "object");
-  do_check_eq(x.bar.constructor, Array);
+var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
 
-  // nesting
-  x = nativeJSON.decode('{"foo":[{}]}');
-  do_check_eq(x.foo.constructor, Array);
-  do_check_eq(x.foo.length, 1);
-  do_check_eq(typeof x.foo[0], "object");
-  x = nativeJSON.decode('{"foo":[{"foo":[{"foo":{}}]}]}');
-  do_check_eq(x.foo[0].foo[0].foo.constructor, Object);
-  x = nativeJSON.decode('{"foo":[{"foo":[{"foo":[]}]}]}');
-  do_check_eq(x.foo[0].foo[0].foo.constructor, Array);
-
-  // strings
-  x = nativeJSON.decode('{"foo":"bar"}');
-  do_check_eq(x.foo, "bar");
-  x = nativeJSON.decode('["foo", "bar", "baz"]');
-  do_check_eq(x[0], "foo");
-  do_check_eq(x[1], "bar");
-  do_check_eq(x[2], "baz");
-
-  // numbers
-  x = nativeJSON.decode('{"foo":5.5, "bar":5}');
-  do_check_eq(x.foo, 5.5);
-  do_check_eq(x.bar, 5);
-  
-  // keywords
-  x = nativeJSON.decode('{"foo": true, "bar":false, "baz":null}');
-  do_check_eq(x.foo, true);
-  do_check_eq(x.bar, false);
-  do_check_eq(x.baz, null);
-  
-  // short escapes
-  x = nativeJSON.decode('{"foo": "\\"", "bar":"\\\\", "baz":"\\b","qux":"\\f", "quux":"\\n", "quuux":"\\r","quuuux":"\\t"}');
-  do_check_eq(x.foo, '"');
-  do_check_eq(x.bar, '\\');
-  do_check_eq(x.baz, '\b');
-  do_check_eq(x.qux, '\f');
-  do_check_eq(x.quux, "\n");
-  do_check_eq(x.quuux, "\r");
-  do_check_eq(x.quuuux, "\t");
-
-  // unicode escape
-  x = nativeJSON.decode('{"foo":"hmm\\u006dmm"}');
-  do_check_eq("hmm\u006dmm", x.foo);
-
-  x = nativeJSON.decode('{"JSON Test Pattern pass3": {"The outermost value": "must be an object or array.","In this test": "It is an object." }}');
-}
-
-function test_files() {
-  function read_file(path) {
-    try {
+function run_test()
+{
+  function read_file(path)
+  {
+    try
+    {
       var f = do_get_file(path);
       var istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
       istream.init(f, -1, -1, false);
-      var x = nativeJSON.decodeFromStream(istream, istream.available());
-    } finally {
+      return nativeJSON.decodeFromStream(istream, istream.available());
+    }
+    finally
+    {
       istream.close();
     }
-    return x;
   }
 
-  var x = read_file("pass3.json");
+  var x = read_file("decodeFromStream-01.json");
   do_check_eq(x["JSON Test Pattern pass3"]["The outermost value"], "must be an object or array.");
   do_check_eq(x["JSON Test Pattern pass3"]["In this test"], "It is an object.");
-
-  x = read_file("pass1.json");
-  do_check_eq(x[0], "JSON Test Pattern pass1");
-  do_check_eq(x[1]["object with 1 member"][0], "array with 1 element");
-  do_check_eq(x[2].constructor, Object);
-  do_check_eq(x[3].constructor, Array);
-  do_check_eq(x[4], -42);
-  do_check_eq(x[5], true);
-  do_check_eq(x[6], false);
-  do_check_eq(x[7], null);
-  do_check_eq(x[8].constructor, Object);
-  do_check_eq(x[8]["integer"], 1234567890);
-  do_check_eq(x[8]["real"], -9876.543210);
-  do_check_eq(x[8]["e"], 0.123456789e-12);
-  do_check_eq(x[8]["E"], 1.234567890E+34);
-  do_check_eq(x[8][""], 23456789012E66);
-  do_check_eq(x[8]["zero"], 0);
-  do_check_eq(x[8]["one"], 1);
-  do_check_eq(x[8]["space"], " ");
-  do_check_eq(x[8]["quote"], "\"");
-  do_check_eq(x[8]["backslash"], "\\");
-  do_check_eq(x[8]["controls"], "\b\f\n\r\t");
-  do_check_eq(x[8]["slash"], "/ & /");
-  do_check_eq(x[8]["alpha"], "abcdefghijklmnopqrstuvwyz");
-  do_check_eq(x[8]["ALPHA"], "ABCDEFGHIJKLMNOPQRSTUVWYZ");
-  do_check_eq(x[8]["digit"], "0123456789");
-  do_check_eq(x[8]["0123456789"], "digit");
-  do_check_eq(x[8]["special"], "`1~!@#$%^&*()_+-={':[,]}|;.</>?");
-  do_check_eq(x[8]["hex"], "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A");
-  do_check_eq(x[8]["true"], true);
-  do_check_eq(x[8]["false"], false);
-  do_check_eq(x[8]["null"], null);
-  do_check_eq(x[8]["array"].length, 0);
-  do_check_eq(x[8]["object"].constructor, Object);
-  do_check_eq(x[8]["address"], "50 St. James Street");
-  do_check_eq(x[8]["url"], "http://www.JSON.org/");
-  do_check_eq(x[8]["comment"], "// /* <!-- --");
-  do_check_eq(x[8]["# -- --> */"], " ");
-  do_check_eq(x[8][" s p a c e d "].length, 7);
-  do_check_eq(x[8]["compact"].length, 7);
-  do_check_eq(x[8]["jsontext"], "{\"object with 1 member\":[\"array with 1 element\"]}");
-  do_check_eq(x[8]["quotes"], "&#34; \u0022 %22 0x22 034 &#x22;");
-  do_check_eq(x[8]["\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"], "A key can be any string");
-  do_check_eq(x[9], 0.5);
-  do_check_eq(x[10], 98.6);
-  do_check_eq(x[11], 99.44);
-  do_check_eq(x[12], 1066);
-  do_check_eq(x[13], 1e1);
-  do_check_eq(x[14], 0.1e1);
-  do_check_eq(x[15], 1e-1);
-  do_check_eq(x[16], 1e00);
-  do_check_eq(x[17], 2e+00);
-  do_check_eq(x[18], 2e-00);
-  do_check_eq(x[19], "rosebud");
-  
-  // test invalid input
-  //
-  // We allow some minor JSON infractions, like trailing commas
-  // Those are special-cased below, leaving the original sequence
-  // of failure's from Crockford intact.
-  //
-  // Section 4 of RFC 4627 allows this tolerance.
-  //
-  for (var i = 1; i <= 34; ++i) {
-    var path = "fail" + i + ".json";
-    try {
-      dump(path +"\n");
-      x = read_file(path);
-      if (i == 13) {
-        // {"Numbers cannot have leading zeroes": 013}
-        do_check_eq(x["Numbers cannot have leading zeroes"], 13);
-      } else if (i == 18) {
-        // [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
-        var t = x[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0];
-        do_check_eq(t, "Too deep");
-      } else {
-
-        do_throw("UNREACHED");
-
-      }
-
-    } catch (ex) {
-      // expected from parsing invalid JSON
-      if (i == 13 || i == 18) {
-        do_throw("Unexpected pass in " + path);
-      }
-    }
-  }
-  
 }
-
-function run_test() {
-  decode_strings();
-  test_files();
-}
rename from dom/src/json/test/unit/test_long_input.js
rename to dom/src/json/test/unit/test_decode_long_input.js
--- a/dom/src/json/test/unit/test_long_input.js
+++ b/dom/src/json/test/unit/test_decode_long_input.js
@@ -1,9 +1,13 @@
 // This tests breaking long input across parser buffers
+var Ci = Components.interfaces;
+var Cc = Components.classes;
+
+var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
 
 var x = {"Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "2Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "3Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "6Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "7Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "8Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "9Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
@@ -16,13 +20,13 @@ var x = {"Lorem ipsum his ponderum delic
 "16Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "17Lorem ipsum his ponderum delicatissimi ne, at noster dolores urbanitas pro, cibo elaboraret no his. Ea dicunt maiorum usu. Ad appareat facilisis mediocritatem eos. Tale graeci mentitum in eos, hinc insolens at nam. Graecis nominavi aliquyam eu vix.":"Id solet assentior sadipscing pro. Et per atqui graecis, usu quot viris repudiandae ei, mollis evertitur an nam. At nam dolor ignota, liber labore omnesque ea mei, has movet voluptaria in. Vel an impetus omittantur. Vim movet option salutandi ex, ne mei ignota corrumpit. Mucius comprehensam id per. Est ea putant maiestatis.",
 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz":"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
 }
 
 var y = nativeJSON.encode(x);
 var z = nativeJSON.decode(y);
 
-function run_test() {
-  for (var i in x) {
-   do_check_eq(x[i], z[i]);
-  }
+function run_test()
+{
+  for (var i in x)
+    do_check_eq(x[i], z[i]);
 }
deleted file mode 100644
--- a/dom/src/json/test/unit/test_decode_primitives.js
+++ /dev/null
@@ -1,88 +0,0 @@
-function parse_primitives() {
-
-  print("parse object");
-  // check an empty object, just for sanity
-  var emptyObject = "{}";
-  var x = nativeJSON.decode(emptyObject);
-  do_check_eq(typeof x, "object");
-  print("parse object 2");
-  
-  x = JSON.parse(emptyObject);
-  do_check_eq(typeof x, "object");
-  
-  print("parse object 3");
-  x = crockfordJSON.parse(emptyObject);
-  do_check_eq(typeof x, "object");
-
-  // booleans and null
-  print("parse bool");
-  x = JSON.parse("true");
-  do_check_eq(typeof x, "boolean");
-  do_check_eq(x, true);
-  
-  print("parse bool with space")
-  x = JSON.parse("true          ");
-  do_check_eq(typeof x, "boolean");
-  do_check_eq(x, true);
-  
-  print("parse false");
-  x = JSON.parse("false");
-  do_check_eq(typeof x, "boolean");
-  do_check_eq(x, false);
-  
-  print("parse null");
-  x = JSON.parse("           null           ");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x, null);
-  
-  // numbers
-  print("parse numbers")
-  x = JSON.parse("1234567890");
-  do_check_eq(typeof x, "number");
-  do_check_eq(x, 1234567890);
-  
-  x = JSON.parse("-9876.543210");
-  do_check_eq(typeof x, "number");
-  do_check_eq(x, -9876.543210);
-  
-  x = JSON.parse("0.123456789e-12");
-  do_check_eq(typeof x, "number");
-  do_check_eq(x, 0.123456789e-12);
-  
-  x = JSON.parse("1.234567890E+34");
-  do_check_eq(typeof x, "number");
-  do_check_eq(x, 1.234567890E+34);
-
-  x = JSON.parse("      23456789012E66          \r\r\r\r      \n\n\n\n ");
-  do_check_eq(typeof x, "number");
-  do_check_eq(x, 23456789012E66);
- 
-  // strings
-  x = crockfordJSON.parse('"foo"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "foo");
-  x = JSON.parse('"foo"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "foo");
-  
-  x = JSON.parse('"\\r\\n"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "\r\n");
-  
-  x = JSON.parse('"\\uabcd\uef4A"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "\uabcd\uef4A");
-
-  x = JSON.parse('"\\uabcd"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "\uabcd");
-
-  x = JSON.parse('"\\f"');
-  do_check_eq(typeof x, "string");
-  do_check_eq(x, "\f");
-
-}
-
-function run_test() {
-  parse_primitives();
-}
deleted file mode 100644
--- a/dom/src/json/test/unit/test_dropping_elements_in_stringify.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var w = {foo: 123};
-var x = {foo: 123, bar: function () {}};
-var y = {foo: 123, bar: function () {}, baz: 123};
-var z = {foo: 123, bar: <x><y></y></x>, baz: 123};
-
-function run_test() {
-  do_check_eq('{"foo":123}', JSON.stringify(w));
-  do_check_eq('{"foo":123}', JSON.stringify(x));
-  do_check_eq('{"foo":123,"baz":123}', JSON.stringify(y));
-  do_check_eq('{"foo":123,"baz":123}', JSON.stringify(z));
-}
--- a/dom/src/json/test/unit/test_encode.js
+++ b/dom/src/json/test/unit/test_encode.js
@@ -1,116 +1,41 @@
+var Ci = Components.interfaces;
+var Cc = Components.classes;
 
-// returns a list of [string, object] pairs to test encoding
-function getTestPairs() {
-  var testPairs = [
-    ["{}", {}],
-    ["[]", []],
-    ['{"foo":"bar"}', {"foo":"bar"}],
-    ['{"null":null}', {"null":null}],
-    ['{"five":5}', {"five":5}],
-    ['{"five":5,"six":6}', {"five":5, "six":6}],
-    ['{"x":{"y":"z"}}', {"x":{"y":"z"}}],
-    ['{"w":{"x":{"y":"z"}}}', {"w":{"x":{"y":"z"}}}],
-    ['[1,2,3]', [1,2,3]],
-    ['{"w":{"x":{"y":[1,2,3]}}}', {"w":{"x":{"y":[1,2,3]}}}],
-    ['{"false":false}', {"false":false}],
-    ['{"true":true}', {"true":true}],
-    ['{"child has two members":{"this":"one","2":"and this one"}}',
-     {"child has two members": {"this":"one", 2:"and this one"}}],
-    ['{"x":{"a":"b","c":{"y":"z"},"f":"g"}}',
-     {"x":{"a":"b","c":{"y":"z"},"f":"g"}}],
-    ['{"x":[1,{"y":"z"},3]}', {"x":[1,{"y":"z"},3]}],
-    ['["hmm"]', [new String("hmm")]],
-    ['[true]', [new Boolean(true)]],
-    ['[42]', [new Number(42)]],
-    ['["1978-09-13T12:24:34.023Z"]', [new Date(Date.UTC(1978, 8, 13, 12, 24, 34, 23))]],
-    ['[1,null,3]',[1,,3]],
-    [null, function test(){}],
-    [null, dump],
-    ['{"mm\\\"mm":"hmm"}',{"mm\"mm":"hmm"}],
-    ['{"mm\\\"mm\\\"mm":"hmm"}',{"mm\"mm\"mm":"hmm"}],
-    ['{"\\\"":"hmm"}',{'"':"hmm"}],
-    ['{"\\\\":"hmm"}',{'\\':"hmm"}],
-    ['{"mmm\\\\mmm":"hmm"}',{'mmm\\mmm':"hmm"}],
-    ['{"mmm\\\\mmm\\\\mmm":"hmm"}',{'mmm\\mmm\\mmm':"hmm"}],
-    ['{"mm\\u000bmm":"hmm"}',{"mm\u000bmm":"hmm"}],
-    ['{"mm\\u0000mm":"hmm"}',{"mm\u0000mm":"hmm"}]
-  ];
+var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
 
-  var x = {"free":"variable"}
-  testPairs.push(['{"free":"variable"}', x]);
-  testPairs.push(['{"y":{"free":"variable"}}', {"y":x}]);
-
-  // array prop
-  var x = {
-    a: [1,2,3]
-  }
-  testPairs.push(['{"a":[1,2,3]}', x])
+var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
+var workingDir = dirSvc.get("TmpD", Ci.nsIFile);
 
-  var y = {
-    foo: function(hmm) { return hmm; }
-  }
-  testPairs.push(['{"y":{}}',{"y":y}]);
-
-  // test toJSON
-  var hmm = {
-    toJSON: function() { return {"foo":"bar"}}
-  }
-  testPairs.push(['{"hmm":{"foo":"bar"}}', {"hmm":hmm}]);
-  testPairs.push(['{"foo":"bar"}', hmm]); // on the root
-
-  // toJSON on prototype
-  var Y = function() {
-    this.d = "e";
-  }
-  Y.prototype = {
-    not:"there?",
-    toJSON: function() { return {"foo":"bar"}}
-  };
-  var y = new Y();
-  testPairs.push(['{"foo":"bar"}', y.toJSON()]);
-  testPairs.push(['{"foo":"bar"}', y]);
+var outputName = "json-test-output";
+var outputDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
+outputDir.initWithFile(workingDir);
+outputDir.append(outputName);
 
-  // return undefined from toJSON
-  var hmm = {
-    toJSON: function() { return; }
-  }
-  testPairs.push(['{}', {"hmm":hmm}]);
-
-  // array with named prop
-  var x= new Array();
-  x[0] = 1;
-  x.foo = "bar";
-  //testPairs.push(['[1]', x]);
-
-  // prototype
-  var X = function() { this.foo = "b" }
-  X.prototype = {c:"d"}
-  var y = new X();
-  testPairs.push(['{"foo":"b"}', y]);
-
-  // useless roots will be dropped
-  testPairs.push([null, null]);
-  testPairs.push([null, ""]);
-  testPairs.push([null, undefined]);
-  testPairs.push([null, 5]);
-
-  return testPairs;
+if (!outputDir.exists()) {
+  outputDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0777);
+} else if (!outputDir.isDirectory()) {
+  do_throw(outputName + " is not a directory?")
 }
 
-function testStringEncode() {
-  // test empty arg
-  do_check_eq(null, nativeJSON.encode());
+function testStringEncode()
+{
+  do_check_eq(nativeJSON.encode(), null);
 
-  var pairs = getTestPairs();
-  for each(pair in pairs) {
-    var nativeResult = nativeJSON.encode(pair[1]);
-    do_check_eq(pair[0], nativeResult);
-  }
+  // useless roots are dropped
+  do_check_eq(nativeJSON.encode(null), null);
+  do_check_eq(nativeJSON.encode(""), null);
+  do_check_eq(nativeJSON.encode(undefined), null);
+  do_check_eq(nativeJSON.encode(5), null);
+  do_check_eq(nativeJSON.encode(function(){}), null);
+  do_check_eq(nativeJSON.encode(dump), null);
+
+  // All other testing should occur in js/src/tests/ecma_5/JSON/ using
+  // the otherwise-exactly-identical JSON.stringify.
 }
 
 function testOutputStreams() {
   function writeToFile(obj, charset, writeBOM) {
     var jsonFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
     jsonFile.initWithFile(outputDir);
     jsonFile.append("test.json");
     jsonFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
@@ -119,18 +44,31 @@ function testOutputStreams() {
       stream.init(jsonFile, 0x04 | 0x08 | 0x20, 0600, 0); // write, create, truncate
       nativeJSON.encodeToStream(stream, charset, writeBOM, obj);
     } finally {
       stream.close();
     }
     return jsonFile;
   }
 
-  var pairs = getTestPairs();
-  for each(pair in pairs) {
+  var pairs = [
+    ["{}", {}],
+    ['{"foo":"bar"}', {"foo":"bar"}],
+    ['{"null":null}', {"null":null}],
+    ['{"five":5}', {"five":5}],
+    ['{"true":true}', {"true":true}],
+    ['{"x":{"y":"z"}}', {"x":{"y":"z"}}],
+    ['{"w":{"x":{"y":"z"}}}', {"w":{"x":{"y":"z"}}}],
+    ["[]", []],
+    ['[1,2,3]', [1,2,3]],
+    ['[1,null,3]',[1,,3]],
+  ];
+  for (var i = 0; i < pairs.length; i++)
+  {
+    var pair = pairs[i];
     if (pair[1] && (typeof pair[1] == "object")) {
       var utf8File = writeToFile(pair[1], "UTF-8", false);
       var utf16LEFile = writeToFile(pair[1], "UTF-16LE", false);
       var utf16BEFile = writeToFile(pair[1], "UTF-16BE", false);
 
       // all ascii with no BOMs, so this will work
       do_check_eq(utf16LEFile.fileSize / 2, utf8File.fileSize);
       do_check_eq(utf16LEFile.fileSize, utf16BEFile.fileSize);
@@ -151,19 +89,23 @@ function testOutputStreams() {
 function throwingToJSON() {
   var a = {
     "b": 1,
     "c": 2,
     toJSON: function() { throw("uh oh"); }
   }
   try {
     var y = nativeJSON.encode(a);
-  } catch (ex) {}
+    throw "didn't throw";
+  } catch (ex) {
+    do_check_eq(ex, "uh oh");
+  }
 }
 
-function run_test() {
+function run_test()
+{
   testStringEncode();
   throwingToJSON();
   
   // failing on windows -- bug 410005
   // testOutputStreams();
   
 }
deleted file mode 100644
--- a/dom/src/json/test/unit/test_encode_primitives.js
+++ /dev/null
@@ -1,34 +0,0 @@
-function stringify_primitives() {
-  // sanity
-  var x = JSON.stringify({});
-  do_check_eq(x, "{}");
-
-  // booleans and null
-  x = JSON.stringify(true);
-  do_check_eq(x, "true");
-
-  x = JSON.stringify(false);
-  do_check_eq(x, "false");
-
-  x = JSON.stringify(new Boolean(false));
-  do_check_eq(x, "false");
-
-  x = JSON.stringify(null);
-  do_check_eq(x, "null");
-
-  x = JSON.stringify(1234);
-  do_check_eq(x, "1234");
-
-  x = JSON.stringify(new Number(1234));
-  do_check_eq(x, "1234");
-
-  x = JSON.stringify("asdf");
-  do_check_eq(x, '"asdf"');
-
-  x = JSON.stringify(new String("asdf"));
-  do_check_eq(x, '"asdf"');
-}
-
-function run_test() {
-  stringify_primitives();
-}
deleted file mode 100644
--- a/dom/src/json/test/unit/test_encoding_errors.js
+++ /dev/null
@@ -1,27 +0,0 @@
-function tooDeep() {
-  var arr = [];
-  var root = [arr];
-  var tail;
-  for (var i = 0; i < 5000; i++) {
-    tail = [];
-    arr.push(tail);
-    arr = tail;
-  }
-  JSON.stringify(root);
-}
-
-function run_test() {
-  do_check_eq(undefined, JSON.stringify(undefined));
-  do_check_eq(undefined, JSON.stringify(function(){}));
-  do_check_eq(undefined, JSON.stringify(<x><y></y></x>));
-
-  var ok = false;
-  try {
-    tooDeep();
-  } catch (e) {
-    do_check_true(e instanceof Error);
-    ok = true;
-  }
-  do_check_true(ok);
-}
-
deleted file mode 100644
--- a/dom/src/json/test/unit/test_replacer.js
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * These return* functions are used by the
- * replacer tests taken from bug 512447
- */
-function returnObjectFor1(k, v) {
-    if (k == "1")
-        return {};
-    return v;
-}
-function returnArrayFor1(k, v) {
-    if (k == "1")
-        return [];
-    return v;
-}
-function returnNullFor1(k, v) {
-    if (k == "1")
-        return null;
-    return v;
-}
-function returnStringForUndefined(k, v) {
-    if (v === undefined)
-        return "undefined value";
-    return v;
-}
-function returnCycleObjectFor1(k, v) {
-    if (k == "1")
-        return object;
-    return v;
-}
-function returnCycleArrayFor1(k, v) {
-    if (k == "1")
-        return array;
-    return v;
-}
-
-function run_test() {
-  var x = JSON.stringify({key:2},function(k,v){return k?undefined:v;})
-  do_check_eq("{}", x);
-  
-  var x = JSON.stringify(["hmm", "hmm"],function(k,v){return k!==""?undefined:v;})
-  do_check_eq("[null,null]", x);
-  
-  var foo = ["hmm"];
-  function censor(k, v) {
-    if (v !== foo)
-      return "XXX";
-    return v;
-  }
-  var x = JSON.stringify(foo, censor);
-  do_check_eq(x, '["XXX"]');
-
-  foo = ["bar", ["baz"], "qux"];
-  var x = JSON.stringify(foo, censor);
-  do_check_eq(x, '["XXX","XXX","XXX"]');
-
-  function censor2(k, v) {
-    if (typeof(v) == "string")
-      return "XXX";
-    return v;
-  }
-
-  foo = ["bar", ["baz"], "qux"];
-  var x = JSON.stringify(foo, censor2);
-  do_check_eq(x, '["XXX",["XXX"],"XXX"]');
-
-  foo = {bar: 42, qux: 42, quux: 42};
-  var x = JSON.stringify(foo, ["bar"]);
-  do_check_eq(x, '{"bar":42}');
-
-  foo = {bar: {bar: 42, schmoo:[]}, qux: 42, quux: 42};
-  var x = JSON.stringify(foo, ["bar", "schmoo"]);
-  do_check_eq(x, '{"bar":{"bar":42,"schmoo":[]}}');
-
-  var x = JSON.stringify(foo, null, "");
-  do_check_eq(x, '{"bar":{"bar":42,"schmoo":[]},"qux":42,"quux":42}');
-
-  var x = JSON.stringify(foo, null, "  ");
-  do_check_eq(x, '{\n  "bar": {\n    "bar": 42,\n    "schmoo": []\n  },\n  "qux": 42,\n  "quux": 42\n}');
-
-  foo = {bar:{bar:{}}}
-  var x = JSON.stringify(foo, null, "  ");
-  do_check_eq(x, '{\n  "bar": {\n    "bar": {}\n  }\n}');
-  
-  var x = JSON.stringify({x:1,arr:[1]}, function (k,v) { return typeof v === 'number' ? 3 : v; });
-  do_check_eq(x, '{"x":3,"arr":[3]}');
-
-  foo = ['e'];
-  var x = JSON.stringify(foo, null, '\t');
-  do_check_eq(x, '[\n\t"e"\n]');
-
-  foo = {0:0, 1:1, 2:2, 3:undefined};
-  var x = JSON.stringify(foo, returnObjectFor1);
-  do_check_eq(x, '{"0":0,"1":{},"2":2}');
-
-  var x = JSON.stringify(foo, returnArrayFor1);
-  do_check_eq(x, '{"0":0,"1":[],"2":2}');
-
-  var x = JSON.stringify(foo, returnNullFor1);
-  do_check_eq(x, '{"0":0,"1":null,"2":2}');
-
-  var x = JSON.stringify(foo, returnStringForUndefined);
-  do_check_eq(x, '{"0":0,"1":1,"2":2,"3":"undefined value"}');
-
-  var thrown = false;
-  try {
-    var x = JSON.stringify(foo, returnCycleObjectFor1);
-  } catch (e) {
-    thrown = true;
-  }
-  do_check_eq(thrown, true);
-
-  var thrown = false;
-  try {
-    var x = JSON.stringify(foo, returnCycleArrayFor1);
-  } catch (e) {
-    thrown = true;
-  }
-  do_check_eq(thrown, true);
-
-  var thrown = false;
-  foo = [0, 1, 2, undefined];
-  try {
-    var x = JSON.stringify(foo, returnCycleObjectFor1);
-  } catch (e) {
-    thrown = true;
-  }
-  do_check_eq(thrown, true);
-}
-
deleted file mode 100644
--- a/dom/src/json/test/unit/test_reviver.js
+++ /dev/null
@@ -1,36 +0,0 @@
-function doubler(k, v) {
-  do_check_true("string" == typeof k);
-
-  if ((typeof v) == "number")
-    return 2 * v;
-
-  return v;
-}
-
-function run_test() {
-  var x = JSON.parse('{"a":5,"b":6}', doubler);
-  do_check_true(x.hasOwnProperty('a'));
-  do_check_true(x.hasOwnProperty('b'));
-  do_check_eq(x.a, 10);
-  do_check_eq(x.b, 12);
-
-  x = JSON.parse('[3, 4, 5]', doubler);
-  do_check_eq(x[0], 6);
-  do_check_eq(x[1], 8);
-  do_check_eq(x[2], 10);
-
-  // make sure reviver isn't called after a failed parse
-  var called = false;
-  function dontCallMe(k, v) {
-    called = true;
-  }
-
-  try {
-    x = JSON.parse('{{{{{{{}}}}', dontCallMe);
-  } catch (e) {
-    if (! (e instanceof SyntaxError))
-      throw("wrong exception");
-  }
-
-  do_check_false(called);
-}
deleted file mode 100644
--- a/dom/src/json/test/unit/test_syntax_errors.js
+++ /dev/null
@@ -1,28 +0,0 @@
-function checkForSyntaxErrors(s) {
-  var crockfordErrored = false;
-  try {
-    crockfordJSON.parse(s)
-  } catch (e) {
-    var crockfordErrored = true;
-    do_check_true(e instanceof crockfordJSON.window.SyntaxError);
-  }
-  do_check_true(crockfordErrored);
-  
-  var JSONErrored = false;
-  try {
-    JSON.parse(s)
-  } catch (e) {
-    var JSONErrored = true;
-    do_check_true(e instanceof SyntaxError);
-  }
-  do_check_true(JSONErrored);
-}
-
-function run_test() {
-  checkForSyntaxErrors("{}...");
-  checkForSyntaxErrors('{"foo": truBBBB}');
-  checkForSyntaxErrors('{foo: truBBBB}');
-  checkForSyntaxErrors('{"foo": undefined}');
-  checkForSyntaxErrors('{"foo": ]');
-  checkForSyntaxErrors('{"foo');
-}
\ No newline at end of file
deleted file mode 100644
--- a/dom/src/json/test/unit/test_wrappers.js
+++ /dev/null
@@ -1,190 +0,0 @@
-
-// returns a list of [string, object] pairs to test encoding
-function getTestPairs() {
-  var testPairs = [
-    ["{}", {}],
-    ["[]", []],
-    ['{"foo":"bar"}', {"foo":"bar"}],
-    ['{"null":null}', {"null":null}],
-    ['{"five":5}', {"five":5}],
-    ['{"five":5,"six":6}', {"five":5, "six":6}],
-    ['{"x":{"y":"z"}}', {"x":{"y":"z"}}],
-    ['{"w":{"x":{"y":"z"}}}', {"w":{"x":{"y":"z"}}}],
-    ['[1,2,3]', [1,2,3]],
-    ['{"w":{"x":{"y":[1,2,3]}}}', {"w":{"x":{"y":[1,2,3]}}}],
-    ['{"false":false}', {"false":false}],
-    ['{"true":true}', {"true":true}],
-    ['{"child has two members":{"this":"one","2":"and this one"}}',
-     {"child has two members": {"this":"one", 2:"and this one"}}],
-    ['{"x":{"a":"b","c":{"y":"z"},"f":"g"}}',
-     {"x":{"a":"b","c":{"y":"z"},"f":"g"}}],
-    ['{"x":[1,{"y":"z"},3]}', {"x":[1,{"y":"z"},3]}],
-    ['["hmm"]', [new String("hmm")]],
-    ['[true]', [new Boolean(true)]],
-    ['[42]', [new Number(42)]],
-    ['["1978-09-13T12:24:34.023Z"]', [new Date(Date.UTC(1978, 8, 13, 12, 24, 34, 23))]],
-    ['[1,null,3]',[1,,3]],
-    ['{"mm\\\"mm":"hmm"}',{"mm\"mm":"hmm"}],
-    ['{"mm\\\"mm\\\"mm":"hmm"}',{"mm\"mm\"mm":"hmm"}],
-    ['{"\\\"":"hmm"}',{'"':"hmm"}],
-    ['{"\\\\":"hmm"}',{'\\':"hmm"}],
-    ['{"mmm\\\\mmm":"hmm"}',{'mmm\\mmm':"hmm"}],
-    ['{"mmm\\\\mmm\\\\mmm":"hmm"}',{'mmm\\mmm\\mmm':"hmm"}],
-    ['{"mm\\u000bmm":"hmm"}',{"mm\u000bmm":"hmm"}],
-    ['{"mm\\u0000mm":"hmm"}',{"mm\u0000mm":"hmm"}]
-  ];
-
-  var x = {"free":"variable"}
-  testPairs.push(['{"free":"variable"}', x]);
-  testPairs.push(['{"y":{"free":"variable"}}', {"y":x}]);
-
-  // array prop
-  var x = {
-    a: [1,2,3]
-  }
-  testPairs.push(['{"a":[1,2,3]}', x])
-
-  var y = {
-    foo: function(hmm) { return hmm; }
-  }
-  testPairs.push(['{"y":{}}',{"y":y}]);
-
-  // test toJSON
-  var hmm = {
-    toJSON: function() { return {"foo":"bar"}}
-  }
-  testPairs.push(['{"hmm":{"foo":"bar"}}', {"hmm":hmm}]);
-  testPairs.push(['{"foo":"bar"}', hmm]); // on the root
-
-  // toJSON on prototype
-  var Y = function() {
-    this.not = "there?";
-    this.d = "e";
-  }
-  Y.prototype = {
-    not:"there?",
-    toJSON: function() { return {"foo":"bar"}}
-  };
-  var y = new Y();
-  testPairs.push(['{"foo":"bar"}', y.toJSON()]);
-  testPairs.push(['{"foo":"bar"}', y]);
-
-  // return undefined from toJSON
-  var hmm = {
-    toJSON: function() { return; }
-  }
-  testPairs.push(['{}', {"hmm":hmm}]);
-
-  // array with named prop
-  var x= new Array();
-  x[0] = 1;
-  x.foo = "bar";
-  testPairs.push(['[1]', x]);
-
-  // prototype
-  var X = function() { this.a = "b" }
-  X.prototype = {c:"d"}
-  var y = new X();
-  testPairs.push(['{"a":"b"}', y]);
-
-  return testPairs;
-}
-
-function testStringEncode() {
-  var pairs = getTestPairs();
-  for each(pair in pairs) {
-    print(pair)
-    var nativeResult = JSON.stringify(pair[1]);
-    do_check_eq(pair[0], nativeResult);
-  }
-}
-
-function decode_strings() {
-  // empty object
-  var x = JSON.parse("{}");
-  do_check_eq(typeof x, "object");
-
-  // empty array
-  x = JSON.parse("[]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 0);
-  do_check_eq(x.constructor, Array);
-
-  // one element array
-  x = JSON.parse("[[]]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 1);
-  do_check_eq(x.constructor, Array);
-  do_check_eq(x[0].constructor, Array);
-
-  // multiple arrays
-  x = JSON.parse("[[],[],[]]");
-  do_check_eq(typeof x, "object");
-  do_check_eq(x.length, 3);
-  do_check_eq(x.constructor, Array);
-  do_check_eq(x[0].constructor, Array);
-  do_check_eq(x[1].constructor, Array);
-  do_check_eq(x[2].constructor, Array);
-
-  // array key/value
-  x = JSON.parse('{"foo":[]}');
-  do_check_eq(typeof x, "object");
-  do_check_eq(typeof x.foo, "object");
-  do_check_eq(x.foo.constructor, Array);
-  x = JSON.parse('{"foo":[], "bar":[]}');
-  do_check_eq(typeof x, "object");
-  do_check_eq(typeof x.foo, "object");
-  do_check_eq(x.foo.constructor, Array);
-  do_check_eq(typeof x.bar, "object");
-  do_check_eq(x.bar.constructor, Array);
-
-  // nesting
-  x = JSON.parse('{"foo":[{}]}');
-  do_check_eq(x.foo.constructor, Array);
-  do_check_eq(x.foo.length, 1);
-  do_check_eq(typeof x.foo[0], "object");
-  x = JSON.parse('{"foo":[{"foo":[{"foo":{}}]}]}');
-  do_check_eq(x.foo[0].foo[0].foo.constructor, Object);
-  x = JSON.parse('{"foo":[{"foo":[{"foo":[]}]}]}');
-  do_check_eq(x.foo[0].foo[0].foo.constructor, Array);
-
-  // strings
-  x = JSON.parse('{"foo":"bar"}');
-  do_check_eq(x.foo, "bar");
-  x = JSON.parse('["foo", "bar", "baz"]');
-  do_check_eq(x[0], "foo");
-  do_check_eq(x[1], "bar");
-  do_check_eq(x[2], "baz");
-
-  // numbers
-  x = JSON.parse('{"foo":5.5, "bar":5}');
-  do_check_eq(x.foo, 5.5);
-  do_check_eq(x.bar, 5);
-  
-  // keywords
-  x = JSON.parse('{"foo": true, "bar":false, "baz":null}');
-  do_check_eq(x.foo, true);
-  do_check_eq(x.bar, false);
-  do_check_eq(x.baz, null);
-  
-  // short escapes
-  x = JSON.parse('{"foo": "\\"", "bar":"\\\\", "baz":"\\b","qux":"\\f", "quux":"\\n", "quuux":"\\r","quuuux":"\\t"}');
-  do_check_eq(x.foo, '"');
-  do_check_eq(x.bar, '\\');
-  do_check_eq(x.baz, '\b');
-  do_check_eq(x.qux, '\f');
-  do_check_eq(x.quux, "\n");
-  do_check_eq(x.quuux, "\r");
-  do_check_eq(x.quuuux, "\t");
-
-  // unicode escape
-  x = JSON.parse('{"foo":"hmm\\u006dmm"}');
-  do_check_eq("hmm\u006dmm", x.foo);
-
-  x = JSON.parse('{"JSON Test Pattern pass3": {"The outermost value": "must be an object or array.","In this test": "It is an object." }}');
-}
-
-function run_test() {
-  testStringEncode();
-  decode_strings();
-}
new file mode 100644
--- /dev/null
+++ b/js/src/tests/e4x/extensions/json-stringify-dropping-xml-elements.js
@@ -0,0 +1,14 @@
+// Ported from dom/src/json/test/unit/test_dropping_elements_in_stringify.js
+
+assertEq(JSON.stringify({foo: 123, bar: <x><y></y></x>, baz: 123}),
+         '{"foo":123,"baz":123}');
+
+assertEq(JSON.stringify([123, <x><y></y></x>, 456]),
+         '[123,null,456]');
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
--- a/js/src/tests/e4x/extensions/jstests.list
+++ b/js/src/tests/e4x/extensions/jstests.list
@@ -17,8 +17,10 @@ script regress-354151-02.js
 script regress-374025.js
 script regress-374163.js
 script regress-410192.js
 script regress-450871-01.js
 script regress-450871-02.js
 script regress-462734-01.js
 script extensibility.js
 script regress-595207.js
+script json-stringify-dropping-xml-elements.js
+script stringify-xml.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/e4x/extensions/stringify-xml.js
@@ -0,0 +1,13 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+assertEq(JSON.stringify(undefined), undefined);
+assertEq(JSON.stringify(function(){}), undefined);
+assertEq(JSON.stringify(<x><y></y></x>), undefined);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
--- a/js/src/tests/ecma_5/JSON/cyclic-stringify.js
+++ b/js/src/tests/ecma_5/JSON/cyclic-stringify.js
@@ -92,9 +92,9 @@ catch (e)
            "cyclic data structures not detected immediately");
 }
 
 /******************************************************************************/
 
 if (typeof reportCompare === "function")
   reportCompare(true, true);
 
-print("All tests passed!");
+print("Tests complete");
--- a/js/src/tests/ecma_5/JSON/jstests.list
+++ b/js/src/tests/ecma_5/JSON/jstests.list
@@ -1,12 +1,22 @@
 url-prefix ../../jsreftest.html?test=ecma_5/JSON/
 script cyclic-stringify.js
 script small-codepoints.js
+script parse.js
+script parse-crockford-01.js
+script parse-primitives.js
+script parse-reviver.js
+fails script parse-octal-syntax-error.js # our JSON.parse wrongly accepts octal numbers
+script parse-syntax-errors-01.js
+script parse-syntax-errors-02.js
+script stringify.js
 script stringify-boxed-primitives.js
 script stringify-call-replacer-once.js
 script stringify-call-toJSON-once.js
+script stringify-dropping-elements.js
 script stringify-gap.js
 script stringify-ignore-noncallable-toJSON.js
+script stringify-primitives.js
+script stringify-replacer.js
 script stringify-replacer-with-array-indexes.js
 script stringify-toJSON-arguments.js
 script trailing-comma.js
-
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-crockford-01.js
@@ -0,0 +1,123 @@
+// Ported from dom/src/json/test/unit/test_decode.js
+
+var str =
+  '[\n' +
+  '    "JSON Test Pattern pass1",\n' +
+  '    {"object with 1 member":["array with 1 element"]},\n' +
+  '    {},\n' +
+  '    [],\n' +
+  '    -42,\n' +
+  '    true,\n' +
+  '    false,\n' +
+  '    null,\n' +
+  '    {\n' +
+  '        "integer": 1234567890,\n' +
+  '        "real": -9876.543210,\n' +
+  '        "e": 0.123456789e-12,\n' +
+  '        "E": 1.234567890E+34,\n' +
+  '        "":  23456789012E66,\n' +
+  '        "zero": 0,\n' +
+  '        "one": 1,\n' +
+  '        "space": " ",\n' +
+  '        "quote": "\\"",\n' +
+  '        "backslash": "\\\\",\n' +
+  '        "controls": "\\b\\f\\n\\r\\t",\n' +
+  '        "slash": "/ & \\/",\n' +
+  '        "alpha": "abcdefghijklmnopqrstuvwyz",\n' +
+  '        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",\n' +
+  '        "digit": "0123456789",\n' +
+  '        "0123456789": "digit",\n' +
+  '        "special": "`1~!@#$%^&*()_+-={\':[,]}|;.</>?",\n' +
+  '        "hex": "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",\n' +
+  '        "true": true,\n' +
+  '        "false": false,\n' +
+  '        "null": null,\n' +
+  '        "array":[  ],\n' +
+  '        "object":{  },\n' +
+  '        "address": "50 St. James Street",\n' +
+  '        "url": "http://www.JSON.org/",\n' +
+  '        "comment": "// /* <!-- --",\n' +
+  '        "# -- --> */": " ",\n' +
+  '        " s p a c e d " :[1,2 , 3\n' +
+  '\n' +
+  ',\n' +
+  '\n' +
+  '4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],\n' +
+  '        "jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",\n' +
+  '        "quotes": "&#34; \\u0022 %22 0x22 034 &#x22;",\n' +
+  '        "\\/\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"\n' +
+  ': "A key can be any string"\n' +
+  '    },\n' +
+  '    0.5 ,98.6\n' +
+  ',\n' +
+  '99.44\n' +
+  ',\n' +
+  '\n' +
+  '1066,\n' +
+  '1e1,\n' +
+  '0.1e1,\n' +
+  '1e-1,\n' +
+  '1e00,2e+00,2e-00\n' +
+  ',"rosebud"]\n';
+
+var x = JSON.parse(str);
+
+assertEq(x[0], "JSON Test Pattern pass1");
+assertEq(x[1]["object with 1 member"][0], "array with 1 element");
+assertEq(x[2].constructor, Object);
+assertEq(x[3].constructor, Array);
+assertEq(x[4], -42);
+assertEq(x[5], true);
+assertEq(x[6], false);
+assertEq(x[7], null);
+assertEq(x[8].constructor, Object);
+assertEq(x[8]["integer"], 1234567890);
+assertEq(x[8]["real"], -9876.543210);
+assertEq(x[8]["e"], 0.123456789e-12);
+assertEq(x[8]["E"], 1.234567890E+34);
+assertEq(x[8][""], 23456789012E66);
+assertEq(x[8]["zero"], 0);
+assertEq(x[8]["one"], 1);
+assertEq(x[8]["space"], " ");
+assertEq(x[8]["quote"], "\"");
+assertEq(x[8]["backslash"], "\\");
+assertEq(x[8]["controls"], "\b\f\n\r\t");
+assertEq(x[8]["slash"], "/ & /");
+assertEq(x[8]["alpha"], "abcdefghijklmnopqrstuvwyz");
+assertEq(x[8]["ALPHA"], "ABCDEFGHIJKLMNOPQRSTUVWYZ");
+assertEq(x[8]["digit"], "0123456789");
+assertEq(x[8]["0123456789"], "digit");
+assertEq(x[8]["special"], "`1~!@#$%^&*()_+-={':[,]}|;.</>?");
+assertEq(x[8]["hex"], "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A");
+assertEq(x[8]["true"], true);
+assertEq(x[8]["false"], false);
+assertEq(x[8]["null"], null);
+assertEq(x[8]["array"].length, 0);
+assertEq(x[8]["object"].constructor, Object);
+assertEq(x[8]["address"], "50 St. James Street");
+assertEq(x[8]["url"], "http://www.JSON.org/");
+assertEq(x[8]["comment"], "// /* <!-- --");
+assertEq(x[8]["# -- --> */"], " ");
+assertEq(x[8][" s p a c e d "].length, 7);
+assertEq(x[8]["compact"].length, 7);
+assertEq(x[8]["jsontext"], "{\"object with 1 member\":[\"array with 1 element\"]}");
+assertEq(x[8]["quotes"], "&#34; \u0022 %22 0x22 034 &#x22;");
+assertEq(x[8]["\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"], "A key can be any string");
+assertEq(x[9], 0.5);
+assertEq(x[10], 98.6);
+assertEq(x[11], 99.44);
+assertEq(x[12], 1066);
+assertEq(x[13], 1e1);
+assertEq(x[14], 0.1e1);
+assertEq(x[15], 1e-1);
+assertEq(x[16], 1e00);
+assertEq(x[17], 2e+00);
+assertEq(x[18], 2e-00);
+assertEq(x[19], "rosebud");
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-octal-syntax-error.js
@@ -0,0 +1,11 @@
+// Ported from dom/src/json/test/unit/test_decode.js and
+// dom/src/json/test/unit/fail13.json
+
+testJSON('{"Numbers cannot have leading zeroes": 013}', true);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-primitives.js
@@ -0,0 +1,64 @@
+// Ported from dom/src/json/test/unit/test_decode_primitives.js
+
+var x;
+
+// check an empty object, just for sanity
+var emptyObject = "{}";
+x = JSON.parse(emptyObject);
+assertEq(typeof x, "object");
+assertEq(x instanceof Object, true);
+
+x = JSON.parse(emptyObject);
+assertEq(typeof x, "object");
+
+// booleans and null
+x = JSON.parse("true");
+assertEq(x, true);
+
+x = JSON.parse("true          ");
+assertEq(x, true);
+
+x = JSON.parse("false");
+assertEq(x, false);
+
+x = JSON.parse("           null           ");
+assertEq(x, null);
+
+// numbers
+x = JSON.parse("1234567890");
+assertEq(x, 1234567890);
+
+x = JSON.parse("-9876.543210");
+assertEq(x, -9876.543210);
+
+x = JSON.parse("0.123456789e-12");
+assertEq(x, 0.123456789e-12);
+
+x = JSON.parse("1.234567890E+34");
+assertEq(x, 1.234567890E+34);
+
+x = JSON.parse("      23456789012E66          \r\r\r\r      \n\n\n\n ");
+assertEq(x, 23456789012E66);
+
+// strings
+x = JSON.parse('"foo"');
+assertEq(x, "foo");
+
+x = JSON.parse('"\\r\\n"');
+assertEq(x, "\r\n");
+
+x = JSON.parse('  "\\uabcd\uef4A"');
+assertEq(x, "\uabcd\uef4A");
+
+x = JSON.parse('"\\uabcd"  ');
+assertEq(x, "\uabcd");
+
+x = JSON.parse('"\\f"');
+assertEq(x, "\f");
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-reviver.js
@@ -0,0 +1,47 @@
+// Ported from dom/src/json/test/unit/test_reviver.js
+
+function doubler(k, v)
+{
+  assertEq(typeof k, "string");
+
+  if (typeof v == "number")
+    return 2 * v;
+
+  return v;
+}
+
+var x = JSON.parse('{"a":5,"b":6}', doubler);
+assertEq(x.hasOwnProperty('a'), true);
+assertEq(x.hasOwnProperty('b'), true);
+assertEq(x.a, 10);
+assertEq(x.b, 12);
+
+x = JSON.parse('[3, 4, 5]', doubler);
+assertEq(x[0], 6);
+assertEq(x[1], 8);
+assertEq(x[2], 10);
+
+// make sure reviver isn't called after a failed parse
+var called = false;
+function dontCallMe(k, v)
+{
+  called = true;
+}
+
+try
+{
+  JSON.parse('{{{{{{{}}}}', dontCallMe);
+  throw new Error("didn't throw?");
+}
+catch (e)
+{
+  assertEq(e instanceof SyntaxError, true, "wrong exception: " + e);
+}
+assertEq(called, false);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-syntax-errors-01.js
@@ -0,0 +1,15 @@
+// Ported from dom/src/json/test/unit/test_syntax_errors.js
+
+testJSON("{}...", true);
+testJSON('{"foo": truBBBB}', true);
+testJSON('{foo: truBBBB}', true);
+testJSON('{"foo": undefined}', true);
+testJSON('{"foo": ]', true);
+testJSON('{"foo', true);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-syntax-errors-02.js
@@ -0,0 +1,46 @@
+// Ported from dom/src/json/test/unit/test_decode.js and
+// dom/src/json/test/unit/fail[1 to 34, minus 13].json
+
+testJSON('"Unterminated string literal', true);
+testJSON('["Unclosed array"', true);
+testJSON('{unquoted_key: "keys must be quoted"}', true);
+testJSON('["extra comma",]', true);
+testJSON('["double extra comma",,]', true);
+testJSON('[   , "<-- missing value"]', true);
+testJSON('["Comma after the close"],', true);
+testJSON('["Extra close"]]', true);
+testJSON('{"Extra comma": true,}', true);
+testJSON('{"Extra value after close": true} "misplaced quoted value"', true);
+testJSON('{"Illegal expression": 1 + 2}', true);
+testJSON('{"Illegal invocation": alert()}', true);
+testJSON('{"Numbers cannot be hex": 0x14}', true);
+testJSON('["Illegal backslash escape: \\x15"]', true);
+testJSON('[\\naked]', true);
+testJSON('["Illegal backslash escape: \\017"]', true);
+testJSON('{"Missing colon" null}', true);
+testJSON('{"Double colon":: null}', true);
+testJSON('{"Comma instead of colon", null}', true);
+testJSON('["Colon instead of comma": false]', true);
+testJSON('["Bad value", truth]', true);
+testJSON("['single quote']", true);
+testJSON('["	tab	character	in	string	"]', true);
+testJSON('["tab\\   character\\   in\\  string\\  "]', true);
+testJSON('["line\rbreak"]', true);
+testJSON('["line\nbreak"]', true);
+testJSON('["line\r\nbreak"]', true);
+testJSON('["line\\\rbreak"]', true);
+testJSON('["line\\\nbreak"]', true);
+testJSON('["line\\\r\nbreak"]', true);
+testJSON('[0e]', true);
+testJSON('[0e+]', true);
+testJSON('[0e+-1]', true);
+testJSON('{"Comma instead of closing brace": true,', true);
+testJSON('["mismatch"}', true);
+testJSON('0{', true);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse.js
@@ -0,0 +1,178 @@
+// Ported from dom/src/json/test/unit/test_wrappers.js and
+// dom/src/json/test/unit/test_decode.js
+
+function assertIsObject(x)
+{
+  assertEq(typeof x, "object");
+  assertEq(x instanceof Object, true);
+}
+
+function assertIsArray(x)
+{
+  assertIsObject(x);
+  assertEq(Array.isArray(x), true);
+  assertEq(Object.getPrototypeOf(x), Array.prototype);
+  assertEq(x instanceof Array, true);
+  assertEq(x.constructor, Array);
+}
+
+var x;
+var props;
+
+// empty object
+x = JSON.parse("{}");
+assertIsObject(x);
+assertEq(Object.getOwnPropertyNames(x).length, 0);
+
+// empty array
+x = JSON.parse("[]");
+assertIsArray(x);
+assertEq(x.length, 0);
+
+// one element array
+x = JSON.parse("[[]]");
+assertIsArray(x);
+assertEq(x.length, 1);
+assertIsArray(x[0]);
+assertEq(x[0].length, 0);
+
+// multiple arrays
+x = JSON.parse("[[],[],[]]");
+assertIsArray(x);
+assertEq(x.length, 3);
+assertIsArray(x[0]);
+assertEq(x[0].length, 0);
+assertIsArray(x[1]);
+assertEq(x[1].length, 0);
+assertIsArray(x[2]);
+assertEq(x[2].length, 0);
+
+// array key/value
+x = JSON.parse('{"foo":[]}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "foo");
+assertIsArray(x.foo);
+assertEq(x.foo.length, 0);
+
+x = JSON.parse('{"foo":[], "bar":[]}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x).sort();
+assertEq(props.length, 2);
+assertEq(props[0], "bar");
+assertEq(props[1], "foo");
+assertIsArray(x.foo);
+assertEq(x.foo.length, 0);
+assertIsArray(x.bar);
+assertEq(x.bar.length, 0);
+
+// nesting
+x = JSON.parse('{"foo":[{}]}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "foo");
+assertIsArray(x.foo);
+assertEq(x.foo.length, 1);
+assertIsObject(x.foo[0]);
+assertEq(Object.getOwnPropertyNames(x.foo[0]).length, 0);
+
+x = JSON.parse('{"foo":[{"foo":[{"foo":{}}]}]}');
+assertIsObject(x.foo[0].foo[0].foo);
+
+x = JSON.parse('{"foo":[{"foo":[{"foo":[]}]}]}');
+assertIsArray(x.foo[0].foo[0].foo);
+
+// strings
+x = JSON.parse('{"foo":"bar"}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "foo");
+assertEq(x.foo, "bar");
+
+x = JSON.parse('["foo", "bar", "baz"]');
+assertIsArray(x);
+assertEq(x.length, 3);
+assertEq(x[0], "foo");
+assertEq(x[1], "bar");
+assertEq(x[2], "baz");
+
+// numbers
+x = JSON.parse('{"foo":5.5, "bar":5}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x).sort();
+assertEq(props.length, 2);
+assertEq(props[0], "bar");
+assertEq(props[1], "foo");
+assertEq(x.foo, 5.5);
+assertEq(x.bar, 5);
+
+// keywords
+x = JSON.parse('{"foo": true, "bar":false, "baz":null}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x).sort();
+assertEq(props.length, 3);
+assertEq(props[0], "bar");
+assertEq(props[1], "baz");
+assertEq(props[2], "foo");
+assertEq(x.foo, true);
+assertEq(x.bar, false);
+assertEq(x.baz, null);
+
+// short escapes
+x = JSON.parse('{"foo": "\\"", "bar":"\\\\", "baz":"\\b","qux":"\\f", "quux":"\\n", "quuux":"\\r","quuuux":"\\t"}');
+props = Object.getOwnPropertyNames(x).sort();
+assertEq(props.length, 7);
+assertEq(props[0], "bar");
+assertEq(props[1], "baz");
+assertEq(props[2], "foo");
+assertEq(props[3], "quuuux");
+assertEq(props[4], "quuux");
+assertEq(props[5], "quux");
+assertEq(props[6], "qux");
+assertEq(x.foo, '"');
+assertEq(x.bar, '\\');
+assertEq(x.baz, '\b');
+assertEq(x.qux, '\f');
+assertEq(x.quux, "\n");
+assertEq(x.quuux, "\r");
+assertEq(x.quuuux, "\t");
+
+// unicode escape
+x = JSON.parse('{"foo":"hmm\\u006dmm"}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "foo");
+assertEq("hmm\u006dmm", x.foo);
+
+x = JSON.parse('{"hmm\\u006dmm":"foo"}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "hmmmmm");
+assertEq(x.hmm\u006dmm, "foo");
+
+// miscellaneous
+x = JSON.parse('{"JSON Test Pattern pass3": {"The outermost value": "must be an object or array.","In this test": "It is an object." }}');
+assertIsObject(x);
+props = Object.getOwnPropertyNames(x);
+assertEq(props.length, 1);
+assertEq(props[0], "JSON Test Pattern pass3");
+assertIsObject(x["JSON Test Pattern pass3"]);
+props = Object.getOwnPropertyNames(x["JSON Test Pattern pass3"]).sort();
+assertEq(props.length, 2);
+assertEq(props[0], "In this test");
+assertEq(props[1], "The outermost value");
+assertEq(x["JSON Test Pattern pass3"]["The outermost value"],
+         "must be an object or array.");
+assertEq(x["JSON Test Pattern pass3"]["In this test"], "It is an object.");
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/stringify-dropping-elements.js
@@ -0,0 +1,22 @@
+// Ported from dom/src/json/test/unit/test_dropping_elements_in_stringify.js
+
+assertEq(JSON.stringify({foo: 123}),
+         '{"foo":123}');
+assertEq(JSON.stringify({foo: 123, bar: function () {}}),
+         '{"foo":123}');
+assertEq(JSON.stringify({foo: 123, bar: function () {}, baz: 123}),
+         '{"foo":123,"baz":123}');
+
+assertEq(JSON.stringify([123]),
+         '[123]');
+assertEq(JSON.stringify([123, function () {}]),
+         '[123,null]');
+assertEq(JSON.stringify([123, function () {}, 456]),
+         '[123,null,456]');
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/stringify-primitives.js
@@ -0,0 +1,41 @@
+// Ported from dom/src/json/test/unit/test_encode_primitives.js
+
+// sanity
+var x = JSON.stringify({});
+assertEq(x, "{}");
+
+// booleans and null
+x = JSON.stringify(true);
+assertEq(x, "true");
+
+x = JSON.stringify(false);
+assertEq(x, "false");
+
+x = JSON.stringify(new Boolean(false));
+assertEq(x, "false");
+
+x = JSON.stringify(null);
+assertEq(x, "null");
+
+x = JSON.stringify(1234);
+assertEq(x, "1234");
+
+x = JSON.stringify(new Number(1234));
+assertEq(x, "1234");
+
+x = JSON.stringify("asdf");
+assertEq(x, '"asdf"');
+
+x = JSON.stringify(new String("asdf"));
+assertEq(x, '"asdf"');
+
+assertEq(JSON.stringify(undefined), undefined);
+assertEq(JSON.stringify(function(){}), undefined);
+assertEq(JSON.stringify(JSON.stringify), undefined);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/stringify-replacer.js
@@ -0,0 +1,157 @@
+// Ported from dom/src/json/test/unit/test_replacer.js
+
+/**
+ * These return* functions are used by the
+ * replacer tests taken from bug 512447
+ */
+function returnObjectFor1(k, v)
+{
+  if (k == "1")
+    return {};
+  return v;
+}
+function returnArrayFor1(k, v)
+{
+  if (k == "1")
+    return [];
+  return v;
+}
+function returnNullFor1(k, v)
+{
+  if (k == "1")
+    return null;
+  return v;
+}
+function returnStringForUndefined(k, v)
+{
+  if (v === undefined)
+    return "undefined value";
+  return v;
+}
+var cycleObject = {}; cycleObject.cycle = cycleObject;
+function returnCycleObjectFor1(k, v)
+{
+  if (k == "1")
+    return cycleObject;
+  return v;
+}
+var array = [0, 1, 2]; array[3] = array;
+function returnCycleArrayFor1(k, v)
+{
+  if (k == "1")
+    return array;
+  return v;
+}
+
+// BEGIN TEST
+var x;
+
+x = JSON.stringify({ key: 2 },
+                   function(k,v) { return k ? undefined : v; });
+assertEq(x, "{}");
+
+x = JSON.stringify(["hmm", "hmm"],
+                   function(k,v) { return k !== "" ? undefined : v; });
+assertEq(x, "[null,null]");
+
+var foo = ["hmm"];
+function censor(k, v)
+{
+  if (v !== foo)
+    return "XXX";
+  return v;
+}
+x = JSON.stringify(foo, censor);
+assertEq(x, '["XXX"]');
+
+foo = ["bar", ["baz"], "qux"];
+x = JSON.stringify(foo, censor);
+assertEq(x, '["XXX","XXX","XXX"]');
+
+function censor2(k, v)
+{
+  if (typeof(v) == "string")
+    return "XXX";
+  return v;
+}
+
+foo = ["bar", ["baz"], "qux"];
+x = JSON.stringify(foo, censor2);
+assertEq(x, '["XXX",["XXX"],"XXX"]');
+
+foo = { bar: 42, qux: 42, quux: 42 };
+x = JSON.stringify(foo, ["bar"]);
+assertEq(x, '{"bar":42}');
+
+foo = {bar: {bar: 42, schmoo:[]}, qux: 42, quux: 42};
+x = JSON.stringify(foo, ["bar", "schmoo"]);
+assertEq(x, '{"bar":{"bar":42,"schmoo":[]}}');
+
+x = JSON.stringify(foo, null, "");
+assertEq(x, '{"bar":{"bar":42,"schmoo":[]},"qux":42,"quux":42}');
+
+x = JSON.stringify(foo, null, "  ");
+assertEq(x, '{\n  "bar": {\n    "bar": 42,\n    "schmoo": []\n  },\n  "qux": 42,\n  "quux": 42\n}');
+
+foo = {bar:{bar:{}}}
+x = JSON.stringify(foo, null, "  ");
+assertEq(x, '{\n  "bar": {\n    "bar": {}\n  }\n}');
+
+x = JSON.stringify({ x: 1, arr: [1] },
+                   function (k,v) { return typeof v === 'number' ? 3 : v; });
+assertEq(x, '{"x":3,"arr":[3]}');
+
+foo = ['e'];
+x = JSON.stringify(foo, null, '\t');
+assertEq(x, '[\n\t"e"\n]');
+
+foo = {0:0, 1:1, 2:2, 3:undefined};
+x = JSON.stringify(foo, returnObjectFor1);
+assertEq(x, '{"0":0,"1":{},"2":2}');
+
+x = JSON.stringify(foo, returnArrayFor1);
+assertEq(x, '{"0":0,"1":[],"2":2}');
+
+x = JSON.stringify(foo, returnNullFor1);
+assertEq(x, '{"0":0,"1":null,"2":2}');
+
+x = JSON.stringify(foo, returnStringForUndefined);
+assertEq(x, '{"0":0,"1":1,"2":2,"3":"undefined value"}');
+
+try
+{
+  JSON.stringify(foo, returnCycleObjectFor1);
+  throw new Error("no error thrown");
+}
+catch (e)
+{
+  assertEq(e instanceof TypeError, true, "no TypeError thrown: " + e);
+}
+
+try
+{
+  JSON.stringify(foo, returnCycleArrayFor1);
+  throw new Error("no error thrown");
+}
+catch (e)
+{
+  assertEq(e instanceof TypeError, true, "no TypeError thrown: " + e);
+}
+
+foo = [0, 1, 2, undefined];
+try
+{
+  JSON.stringify(foo, returnCycleObjectFor1);
+  throw new Error("no error thrown");
+}
+catch (e)
+{
+  assertEq(e instanceof TypeError, true, "no TypeError thrown: " + e);
+}
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/stringify.js
@@ -0,0 +1,86 @@
+// Ported from dom/src/json/test/unit/test_wrappers.js
+
+function assertStringify(v, expect)
+{
+  assertEq(JSON.stringify(v), expect);
+}
+
+assertStringify({}, "{}");
+assertStringify([], "[]");
+assertStringify({"foo":"bar"}, '{"foo":"bar"}');
+assertStringify({"null":null}, '{"null":null}');
+assertStringify({"five":5}, '{"five":5}');
+assertStringify({"five":5, "six":6}, '{"five":5,"six":6}');
+assertStringify({"x":{"y":"z"}}, '{"x":{"y":"z"}}');
+assertStringify({"w":{"x":{"y":"z"}}}, '{"w":{"x":{"y":"z"}}}');
+assertStringify([1,2,3], '[1,2,3]');
+assertStringify({"w":{"x":{"y":[1,2,3]}}}, '{"w":{"x":{"y":[1,2,3]}}}');
+assertStringify({"false":false}, '{"false":false}');
+assertStringify({"true":true}, '{"true":true}');
+assertStringify({"child has two members": {"this":"one", 2:"and this one"}},
+                '{"child has two members":{"this":"one","2":"and this one"}}');
+assertStringify({"x":{"a":"b","c":{"y":"z"},"f":"g"}},
+                '{"x":{"a":"b","c":{"y":"z"},"f":"g"}}');
+assertStringify({"x":[1,{"y":"z"},3]}, '{"x":[1,{"y":"z"},3]}');
+assertStringify([new String("hmm")], '["hmm"]');
+assertStringify([new Boolean(true)], '[true]');
+assertStringify([new Number(42)], '[42]');
+assertStringify([new Date(Date.UTC(1978, 8, 13, 12, 24, 34, 23))],
+                '["1978-09-13T12:24:34.023Z"]');
+assertStringify([1,,3], '[1,null,3]');
+assertStringify({"mm\"mm":"hmm"}, '{"mm\\\"mm":"hmm"}');
+assertStringify({"mm\"mm\"mm":"hmm"}, '{"mm\\\"mm\\\"mm":"hmm"}');
+assertStringify({'"':"hmm"}, '{"\\\"":"hmm"}');
+assertStringify({'\\':"hmm"}, '{"\\\\":"hmm"}');
+assertStringify({'mmm\\mmm':"hmm"}, '{"mmm\\\\mmm":"hmm"}');
+assertStringify({'mmm\\mmm\\mmm':"hmm"}, '{"mmm\\\\mmm\\\\mmm":"hmm"}');
+assertStringify({"mm\u000bmm":"hmm"}, '{"mm\\u000bmm":"hmm"}');
+assertStringify({"mm\u0000mm":"hmm"}, '{"mm\\u0000mm":"hmm"}');
+
+var x = {"free":"variable"};
+assertStringify(x, '{"free":"variable"}');
+assertStringify({"y":x}, '{"y":{"free":"variable"}}');
+
+// array prop
+assertStringify({ a: [1,2,3] }, '{"a":[1,2,3]}');
+
+assertStringify({"y": { foo: function(hmm) { return hmm; } } }, '{"y":{}}');
+
+// test toJSON
+var hmm = { toJSON: function() { return {"foo":"bar"} } };
+assertStringify({"hmm":hmm}, '{"hmm":{"foo":"bar"}}');
+assertStringify(hmm, '{"foo":"bar"}'); // on the root
+
+// toJSON on prototype
+var Y = function() {
+  this.not = "there?";
+  this.d = "e";
+};
+Y.prototype = {
+  not: "there?",
+  toJSON: function() { return {"foo":"bar"}}
+};
+var y = new Y();
+assertStringify(y.toJSON(), '{"foo":"bar"}');
+assertStringify(y, '{"foo":"bar"}');
+
+// return undefined from toJSON
+assertStringify({"hmm": { toJSON: function() { return; } } }, '{}');
+
+// array with named prop
+var x = new Array();
+x[0] = 1;
+x.foo = "bar";
+assertStringify(x, '[1]');
+
+// prototype
+var X = function() { this.a = "b" };
+X.prototype = { c: "d" };
+assertStringify(new X(), '{"a":"b"}');
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");