3c0f1ff
From d4fd415694506160bb62eb615100aa8377d6bdeb Mon Sep 17 00:00:00 2001
3c0f1ff
From: Jun Aruga <jaruga@redhat.com>
3c0f1ff
Date: Fri, 22 Jul 2016 10:23:08 +0200
3c0f1ff
Subject: [PATCH] - Revert "Ensure JSON var isn't shadowed in JSC and
3c0f1ff
 Spidermonkey"   This reverts commit f47c02c8536ce7cf0850b6a511fcecad6539eeaf.
3c0f1ff
 - Revert "Add WSH JScript support" with fixing the conflict   This reverts
3c0f1ff
 commit 8b22842cbd3e2cf46d413aa7d352869b19303d31. - Remove JScript definition
3c0f1ff
 from runtimes.rb
3c0f1ff
3c0f1ff
---
3c0f1ff
 lib/execjs/runtimes.rb               |   8 -
3c0f1ff
 lib/execjs/support/jscript_runner.js |  22 --
3c0f1ff
 lib/execjs/support/json2.js          | 481 -----------------------------------
3c0f1ff
 3 files changed, 511 deletions(-)
3c0f1ff
 delete mode 100644 lib/execjs/support/jscript_runner.js
3c0f1ff
 delete mode 100644 lib/execjs/support/json2.js
3c0f1ff
3c0f1ff
diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb
3c0f1ff
index 52dc3c9..97dc7fd 100644
3c0f1ff
--- a/lib/execjs/runtimes.rb
3c0f1ff
+++ b/lib/execjs/runtimes.rb
3c0f1ff
@@ -38,13 +38,6 @@ module Runtimes
3c0f1ff
       deprecated:  true
3c0f1ff
     )
3c0f1ff
 
3c0f1ff
-    JScript = ExternalRuntime.new(
3c0f1ff
-      name:        "JScript",
3c0f1ff
-      command:     "cscript //E:jscript //Nologo //U",
3c0f1ff
-      runner_path: ExecJS.root + "/support/jscript_runner.js",
3c0f1ff
-      encoding:    'UTF-16LE' # CScript with //U returns UTF-16LE
3c0f1ff
-    )
3c0f1ff
-
3c0f1ff
     V8 = ExternalRuntime.new(
3c0f1ff
       name:        "V8",
3c0f1ff
       command:     "d8",
3c0f1ff
@@ -86,7 +79,6 @@ def self.runtimes
3c0f1ff
         Node,
3c0f1ff
         JavaScriptCore,
3c0f1ff
         SpiderMonkey,
3c0f1ff
-        JScript,
3c0f1ff
         V8
3c0f1ff
       ]
3c0f1ff
     end
3c0f1ff
diff --git a/lib/execjs/support/jscript_runner.js b/lib/execjs/support/jscript_runner.js
3c0f1ff
deleted file mode 100644
3c0f1ff
index fc92b4a..0000000
3c0f1ff
--- a/lib/execjs/support/jscript_runner.js
3c0f1ff
+++ /dev/null
3c0f1ff
@@ -1,22 +0,0 @@
3c0f1ff
-(function(program, execJS) { execJS(program) })(function() {
3c0f1ff
-  return eval(#{encode_source(source)});
3c0f1ff
-}, function(program) {
3c0f1ff
-  #{json2_source}
3c0f1ff
-  var output, print = function(string) {
3c0f1ff
-    WScript.Echo(string);
3c0f1ff
-  };
3c0f1ff
-  try {
3c0f1ff
-    result = program();
3c0f1ff
-    if (typeof result == 'undefined' && result !== null) {
3c0f1ff
-      print('["ok"]');
3c0f1ff
-    } else {
3c0f1ff
-      try {
3c0f1ff
-        print(JSON.stringify(['ok', result]));
3c0f1ff
-      } catch (err) {
3c0f1ff
-        print(JSON.stringify(['err', err.name + ': ' + err.message, err.stack]));
3c0f1ff
-      }
3c0f1ff
-    }
3c0f1ff
-  } catch (err) {
3c0f1ff
-    print(JSON.stringify(['err', err.name + ': ' + err.message, err.stack]));
3c0f1ff
-  }
3c0f1ff
-});
3c0f1ff
diff --git a/lib/execjs/support/json2.js b/lib/execjs/support/json2.js
3c0f1ff
deleted file mode 100644
3c0f1ff
index fb8fe0a..0000000
3c0f1ff
--- a/lib/execjs/support/json2.js
3c0f1ff
+++ /dev/null
3c0f1ff
@@ -1,481 +0,0 @@
3c0f1ff
-/*
3c0f1ff
-    http://www.JSON.org/json2.js
3c0f1ff
-    2011-01-18
3c0f1ff
-
3c0f1ff
-    Public Domain.
3c0f1ff
-
3c0f1ff
-    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
3c0f1ff
-
3c0f1ff
-    See http://www.JSON.org/js.html
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-    This code should be minified before deployment.
3c0f1ff
-    See http://javascript.crockford.com/jsmin.html
3c0f1ff
-
3c0f1ff
-    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
3c0f1ff
-    NOT CONTROL.
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-    This file creates a global JSON object containing two methods: stringify
3c0f1ff
-    and parse.
3c0f1ff
-
3c0f1ff
-        JSON.stringify(value, replacer, space)
3c0f1ff
-            value       any JavaScript value, usually an object or array.
3c0f1ff
-
3c0f1ff
-            replacer    an optional parameter that determines how object
3c0f1ff
-                        values are stringified for objects. It can be a
3c0f1ff
-                        function or an array of strings.
3c0f1ff
-
3c0f1ff
-            space       an optional parameter that specifies the indentation
3c0f1ff
-                        of nested structures. If it is omitted, the text will
3c0f1ff
-                        be packed without extra whitespace. If it is a number,
3c0f1ff
-                        it will specify the number of spaces to indent at each
3c0f1ff
-                        level. If it is a string (such as '\t' or ' '),
3c0f1ff
-                        it contains the characters used to indent at each level.
3c0f1ff
-
3c0f1ff
-            This method produces a JSON text from a JavaScript value.
3c0f1ff
-
3c0f1ff
-            When an object value is found, if the object contains a toJSON
3c0f1ff
-            method, its toJSON method will be called and the result will be
3c0f1ff
-            stringified. A toJSON method does not serialize: it returns the
3c0f1ff
-            value represented by the name/value pair that should be serialized,
3c0f1ff
-            or undefined if nothing should be serialized. The toJSON method
3c0f1ff
-            will be passed the key associated with the value, and this will be
3c0f1ff
-            bound to the value
3c0f1ff
-
3c0f1ff
-            For example, this would serialize Dates as ISO strings.
3c0f1ff
-
3c0f1ff
-                Date.prototype.toJSON = function (key) {
3c0f1ff
-                    function f(n) {
3c0f1ff
-                        // Format integers to have at least two digits.
3c0f1ff
-                        return n < 10 ? '0' + n : n;
3c0f1ff
-                    }
3c0f1ff
-
3c0f1ff
-                    return this.getUTCFullYear()   + '-' +
3c0f1ff
-                         f(this.getUTCMonth() + 1) + '-' +
3c0f1ff
-                         f(this.getUTCDate())      + 'T' +
3c0f1ff
-                         f(this.getUTCHours())     + ':' +
3c0f1ff
-                         f(this.getUTCMinutes())   + ':' +
3c0f1ff
-                         f(this.getUTCSeconds())   + 'Z';
3c0f1ff
-                };
3c0f1ff
-
3c0f1ff
-            You can provide an optional replacer method. It will be passed the
3c0f1ff
-            key and value of each member, with this bound to the containing
3c0f1ff
-            object. The value that is returned from your method will be
3c0f1ff
-            serialized. If your method returns undefined, then the member will
3c0f1ff
-            be excluded from the serialization.
3c0f1ff
-
3c0f1ff
-            If the replacer parameter is an array of strings, then it will be
3c0f1ff
-            used to select the members to be serialized. It filters the results
3c0f1ff
-            such that only members with keys listed in the replacer array are
3c0f1ff
-            stringified.
3c0f1ff
-
3c0f1ff
-            Values that do not have JSON representations, such as undefined or
3c0f1ff
-            functions, will not be serialized. Such values in objects will be
3c0f1ff
-            dropped; in arrays they will be replaced with null. You can use
3c0f1ff
-            a replacer function to replace those with JSON values.
3c0f1ff
-            JSON.stringify(undefined) returns undefined.
3c0f1ff
-
3c0f1ff
-            The optional space parameter produces a stringification of the
3c0f1ff
-            value that is filled with line breaks and indentation to make it
3c0f1ff
-            easier to read.
3c0f1ff
-
3c0f1ff
-            If the space parameter is a non-empty string, then that string will
3c0f1ff
-            be used for indentation. If the space parameter is a number, then
3c0f1ff
-            the indentation will be that many spaces.
3c0f1ff
-
3c0f1ff
-            Example:
3c0f1ff
-
3c0f1ff
-            text = JSON.stringify(['e', {pluribus: 'unum'}]);
3c0f1ff
-            // text is '["e",{"pluribus":"unum"}]'
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
3c0f1ff
-            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
3c0f1ff
-
3c0f1ff
-            text = JSON.stringify([new Date()], function (key, value) {
3c0f1ff
-                return this[key] instanceof Date ?
3c0f1ff
-                    'Date(' + this[key] + ')' : value;
3c0f1ff
-            });
3c0f1ff
-            // text is '["Date(---current time---)"]'
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-        JSON.parse(text, reviver)
3c0f1ff
-            This method parses a JSON text to produce an object or array.
3c0f1ff
-            It can throw a SyntaxError exception.
3c0f1ff
-
3c0f1ff
-            The optional reviver parameter is a function that can filter and
3c0f1ff
-            transform the results. It receives each of the keys and values,
3c0f1ff
-            and its return value is used instead of the original value.
3c0f1ff
-            If it returns what it received, then the structure is not modified.
3c0f1ff
-            If it returns undefined then the member is deleted.
3c0f1ff
-
3c0f1ff
-            Example:
3c0f1ff
-
3c0f1ff
-            // Parse the text. Values that look like ISO date strings will
3c0f1ff
-            // be converted to Date objects.
3c0f1ff
-
3c0f1ff
-            myData = JSON.parse(text, function (key, value) {
3c0f1ff
-                var a;
3c0f1ff
-                if (typeof value === 'string') {
3c0f1ff
-                    a =
3c0f1ff
-/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
3c0f1ff
-                    if (a) {
3c0f1ff
-                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
3c0f1ff
-                            +a[5], +a[6]));
3c0f1ff
-                    }
3c0f1ff
-                }
3c0f1ff
-                return value;
3c0f1ff
-            });
3c0f1ff
-
3c0f1ff
-            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
3c0f1ff
-                var d;
3c0f1ff
-                if (typeof value === 'string' &&
3c0f1ff
-                        value.slice(0, 5) === 'Date(' &&
3c0f1ff
-                        value.slice(-1) === ')') {
3c0f1ff
-                    d = new Date(value.slice(5, -1));
3c0f1ff
-                    if (d) {
3c0f1ff
-                        return d;
3c0f1ff
-                    }
3c0f1ff
-                }
3c0f1ff
-                return value;
3c0f1ff
-            });
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-    This is a reference implementation. You are free to copy, modify, or
3c0f1ff
-    redistribute.
3c0f1ff
-*/
3c0f1ff
-
3c0f1ff
-/*jslint evil: true, strict: false, regexp: false */
3c0f1ff
-
3c0f1ff
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
3c0f1ff
-    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
3c0f1ff
-    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
3c0f1ff
-    lastIndex, length, parse, prototype, push, replace, slice, stringify,
3c0f1ff
-    test, toJSON, toString, valueOf
3c0f1ff
-*/
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-// Create a JSON object only if one does not already exist. We create the
3c0f1ff
-// methods in a closure to avoid creating global variables.
3c0f1ff
-
3c0f1ff
-(function (global) {
3c0f1ff
-    if (!global.JSON) {
3c0f1ff
-        global.JSON = {};
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-    var JSON = global.JSON;
3c0f1ff
-
3c0f1ff
-    "use strict";
3c0f1ff
-
3c0f1ff
-    function f(n) {
3c0f1ff
-        // Format integers to have at least two digits.
3c0f1ff
-        return n < 10 ? '0' + n : n;
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-    if (typeof Date.prototype.toJSON !== 'function') {
3c0f1ff
-
3c0f1ff
-        Date.prototype.toJSON = function (key) {
3c0f1ff
-
3c0f1ff
-            return isFinite(this.valueOf()) ?
3c0f1ff
-                this.getUTCFullYear()     + '-' +
3c0f1ff
-                f(this.getUTCMonth() + 1) + '-' +
3c0f1ff
-                f(this.getUTCDate())      + 'T' +
3c0f1ff
-                f(this.getUTCHours())     + ':' +
3c0f1ff
-                f(this.getUTCMinutes())   + ':' +
3c0f1ff
-                f(this.getUTCSeconds())   + 'Z' : null;
3c0f1ff
-        };
3c0f1ff
-
3c0f1ff
-        String.prototype.toJSON      =
3c0f1ff
-            Number.prototype.toJSON  =
3c0f1ff
-            Boolean.prototype.toJSON = function (key) {
3c0f1ff
-                return this.valueOf();
3c0f1ff
-            };
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
3c0f1ff
-        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
3c0f1ff
-        gap,
3c0f1ff
-        indent,
3c0f1ff
-        meta = {    // table of character substitutions
3c0f1ff
-            '\b': '\\b',
3c0f1ff
-            '\t': '\\t',
3c0f1ff
-            '\n': '\\n',
3c0f1ff
-            '\f': '\\f',
3c0f1ff
-            '\r': '\\r',
3c0f1ff
-            '"' : '\\"',
3c0f1ff
-            '\\': '\\\\'
3c0f1ff
-        },
3c0f1ff
-        rep;
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-    function quote(string) {
3c0f1ff
-
3c0f1ff
-// If the string contains no control characters, no quote characters, and no
3c0f1ff
-// backslash characters, then we can safely slap some quotes around it.
3c0f1ff
-// Otherwise we must also replace the offending characters with safe escape
3c0f1ff
-// sequences.
3c0f1ff
-
3c0f1ff
-        escapable.lastIndex = 0;
3c0f1ff
-        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
3c0f1ff
-            var c = meta[a];
3c0f1ff
-            return typeof c === 'string' ? c :
3c0f1ff
-                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
3c0f1ff
-        }) + '"' : '"' + string + '"';
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-    function str(key, holder) {
3c0f1ff
-
3c0f1ff
-// Produce a string from holder[key].
3c0f1ff
-
3c0f1ff
-        var i,          // The loop counter.
3c0f1ff
-            k,          // The member key.
3c0f1ff
-            v,          // The member value.
3c0f1ff
-            length,
3c0f1ff
-            mind = gap,
3c0f1ff
-            partial,
3c0f1ff
-            value = holder[key];
3c0f1ff
-
3c0f1ff
-// If the value has a toJSON method, call it to obtain a replacement value.
3c0f1ff
-
3c0f1ff
-        if (value && typeof value === 'object' &&
3c0f1ff
-                typeof value.toJSON === 'function') {
3c0f1ff
-            value = value.toJSON(key);
3c0f1ff
-        }
3c0f1ff
-
3c0f1ff
-// If we were called with a replacer function, then call the replacer to
3c0f1ff
-// obtain a replacement value.
3c0f1ff
-
3c0f1ff
-        if (typeof rep === 'function') {
3c0f1ff
-            value = rep.call(holder, key, value);
3c0f1ff
-        }
3c0f1ff
-
3c0f1ff
-// What happens next depends on the value's type.
3c0f1ff
-
3c0f1ff
-        switch (typeof value) {
3c0f1ff
-        case 'string':
3c0f1ff
-            return quote(value);
3c0f1ff
-
3c0f1ff
-        case 'number':
3c0f1ff
-
3c0f1ff
-// JSON numbers must be finite. Encode non-finite numbers as null.
3c0f1ff
-
3c0f1ff
-            return isFinite(value) ? String(value) : 'null';
3c0f1ff
-
3c0f1ff
-        case 'boolean':
3c0f1ff
-        case 'null':
3c0f1ff
-
3c0f1ff
-// If the value is a boolean or null, convert it to a string. Note:
3c0f1ff
-// typeof null does not produce 'null'. The case is included here in
3c0f1ff
-// the remote chance that this gets fixed someday.
3c0f1ff
-
3c0f1ff
-            return String(value);
3c0f1ff
-
3c0f1ff
-// If the type is 'object', we might be dealing with an object or an array or
3c0f1ff
-// null.
3c0f1ff
-
3c0f1ff
-        case 'object':
3c0f1ff
-
3c0f1ff
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
3c0f1ff
-// so watch out for that case.
3c0f1ff
-
3c0f1ff
-            if (!value) {
3c0f1ff
-                return 'null';
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// Make an array to hold the partial results of stringifying this object value.
3c0f1ff
-
3c0f1ff
-            gap += indent;
3c0f1ff
-            partial = [];
3c0f1ff
-
3c0f1ff
-// Is the value an array?
3c0f1ff
-
3c0f1ff
-            if (Object.prototype.toString.apply(value) === '[object Array]') {
3c0f1ff
-
3c0f1ff
-// The value is an array. Stringify every element. Use null as a placeholder
3c0f1ff
-// for non-JSON values.
3c0f1ff
-
3c0f1ff
-                length = value.length;
3c0f1ff
-                for (i = 0; i < length; i += 1) {
3c0f1ff
-                    partial[i] = str(i, value) || 'null';
3c0f1ff
-                }
3c0f1ff
-
3c0f1ff
-// Join all of the elements together, separated with commas, and wrap them in
3c0f1ff
-// brackets.
3c0f1ff
-
3c0f1ff
-                v = partial.length === 0 ? '[]' : gap ?
3c0f1ff
-                    '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
3c0f1ff
-                    '[' + partial.join(',') + ']';
3c0f1ff
-                gap = mind;
3c0f1ff
-                return v;
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// If the replacer is an array, use it to select the members to be stringified.
3c0f1ff
-
3c0f1ff
-            if (rep && typeof rep === 'object') {
3c0f1ff
-                length = rep.length;
3c0f1ff
-                for (i = 0; i < length; i += 1) {
3c0f1ff
-                    k = rep[i];
3c0f1ff
-                    if (typeof k === 'string') {
3c0f1ff
-                        v = str(k, value);
3c0f1ff
-                        if (v) {
3c0f1ff
-                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
3c0f1ff
-                        }
3c0f1ff
-                    }
3c0f1ff
-                }
3c0f1ff
-            } else {
3c0f1ff
-
3c0f1ff
-// Otherwise, iterate through all of the keys in the object.
3c0f1ff
-
3c0f1ff
-                for (k in value) {
3c0f1ff
-                    if (Object.hasOwnProperty.call(value, k)) {
3c0f1ff
-                        v = str(k, value);
3c0f1ff
-                        if (v) {
3c0f1ff
-                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
3c0f1ff
-                        }
3c0f1ff
-                    }
3c0f1ff
-                }
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// Join all of the member texts together, separated with commas,
3c0f1ff
-// and wrap them in braces.
3c0f1ff
-
3c0f1ff
-            v = partial.length === 0 ? '{}' : gap ?
3c0f1ff
-                '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
3c0f1ff
-                '{' + partial.join(',') + '}';
3c0f1ff
-            gap = mind;
3c0f1ff
-            return v;
3c0f1ff
-        }
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-// If the JSON object does not yet have a stringify method, give it one.
3c0f1ff
-
3c0f1ff
-    if (typeof JSON.stringify !== 'function') {
3c0f1ff
-        JSON.stringify = function (value, replacer, space) {
3c0f1ff
-
3c0f1ff
-// The stringify method takes a value and an optional replacer, and an optional
3c0f1ff
-// space parameter, and returns a JSON text. The replacer can be a function
3c0f1ff
-// that can replace values, or an array of strings that will select the keys.
3c0f1ff
-// A default replacer method can be provided. Use of the space parameter can
3c0f1ff
-// produce text that is more easily readable.
3c0f1ff
-
3c0f1ff
-            var i;
3c0f1ff
-            gap = '';
3c0f1ff
-            indent = '';
3c0f1ff
-
3c0f1ff
-// If the space parameter is a number, make an indent string containing that
3c0f1ff
-// many spaces.
3c0f1ff
-
3c0f1ff
-            if (typeof space === 'number') {
3c0f1ff
-                for (i = 0; i < space; i += 1) {
3c0f1ff
-                    indent += ' ';
3c0f1ff
-                }
3c0f1ff
-
3c0f1ff
-// If the space parameter is a string, it will be used as the indent string.
3c0f1ff
-
3c0f1ff
-            } else if (typeof space === 'string') {
3c0f1ff
-                indent = space;
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// If there is a replacer, it must be a function or an array.
3c0f1ff
-// Otherwise, throw an error.
3c0f1ff
-
3c0f1ff
-            rep = replacer;
3c0f1ff
-            if (replacer && typeof replacer !== 'function' &&
3c0f1ff
-                    (typeof replacer !== 'object' ||
3c0f1ff
-                    typeof replacer.length !== 'number')) {
3c0f1ff
-                throw new Error('JSON.stringify');
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// Make a fake root object containing our value under the key of ''.
3c0f1ff
-// Return the result of stringifying the value.
3c0f1ff
-
3c0f1ff
-            return str('', {'': value});
3c0f1ff
-        };
3c0f1ff
-    }
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-// If the JSON object does not yet have a parse method, give it one.
3c0f1ff
-
3c0f1ff
-    if (typeof JSON.parse !== 'function') {
3c0f1ff
-        JSON.parse = function (text, reviver) {
3c0f1ff
-
3c0f1ff
-// The parse method takes a text and an optional reviver function, and returns
3c0f1ff
-// a JavaScript value if the text is a valid JSON text.
3c0f1ff
-
3c0f1ff
-            var j;
3c0f1ff
-
3c0f1ff
-            function walk(holder, key) {
3c0f1ff
-
3c0f1ff
-// The walk method is used to recursively walk the resulting structure so
3c0f1ff
-// that modifications can be made.
3c0f1ff
-
3c0f1ff
-                var k, v, value = holder[key];
3c0f1ff
-                if (value && typeof value === 'object') {
3c0f1ff
-                    for (k in value) {
3c0f1ff
-                        if (Object.hasOwnProperty.call(value, k)) {
3c0f1ff
-                            v = walk(value, k);
3c0f1ff
-                            if (v !== undefined) {
3c0f1ff
-                                value[k] = v;
3c0f1ff
-                            } else {
3c0f1ff
-                                delete value[k];
3c0f1ff
-                            }
3c0f1ff
-                        }
3c0f1ff
-                    }
3c0f1ff
-                }
3c0f1ff
-                return reviver.call(holder, key, value);
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-
3c0f1ff
-// Parsing happens in four stages. In the first stage, we replace certain
3c0f1ff
-// Unicode characters with escape sequences. JavaScript handles many characters
3c0f1ff
-// incorrectly, either silently deleting them, or treating them as line endings.
3c0f1ff
-
3c0f1ff
-            text = String(text);
3c0f1ff
-            cx.lastIndex = 0;
3c0f1ff
-            if (cx.test(text)) {
3c0f1ff
-                text = text.replace(cx, function (a) {
3c0f1ff
-                    return '\\u' +
3c0f1ff
-                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
3c0f1ff
-                });
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// In the second stage, we run the text against regular expressions that look
3c0f1ff
-// for non-JSON patterns. We are especially concerned with '()' and 'new'
3c0f1ff
-// because they can cause invocation, and '=' because it can cause mutation.
3c0f1ff
-// But just to be safe, we want to reject all unexpected forms.
3c0f1ff
-
3c0f1ff
-// We split the second stage into 4 regexp operations in order to work around
3c0f1ff
-// crippling inefficiencies in IE's and Safari's regexp engines. First we
3c0f1ff
-// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
3c0f1ff
-// replace all simple value tokens with ']' characters. Third, we delete all
3c0f1ff
-// open brackets that follow a colon or comma or that begin the text. Finally,
3c0f1ff
-// we look to see that the remaining characters are only whitespace or ']' or
3c0f1ff
-// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
3c0f1ff
-
3c0f1ff
-            if (/^[\],:{}\s]*$/
3c0f1ff
-                    .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
3c0f1ff
-                        .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
3c0f1ff
-                        .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
3c0f1ff
-
3c0f1ff
-// In the third stage we use the eval function to compile the text into a
3c0f1ff
-// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
3c0f1ff
-// in JavaScript: it can begin a block or an object literal. We wrap the text
3c0f1ff
-// in parens to eliminate the ambiguity.
3c0f1ff
-
3c0f1ff
-                j = eval('(' + text + ')');
3c0f1ff
-
3c0f1ff
-// In the optional fourth stage, we recursively walk the new structure, passing
3c0f1ff
-// each name/value pair to a reviver function for possible transformation.
3c0f1ff
-
3c0f1ff
-                return typeof reviver === 'function' ?
3c0f1ff
-                    walk({'': j}, '') : j;
3c0f1ff
-            }
3c0f1ff
-
3c0f1ff
-// If the text is not JSON parseable, then a SyntaxError is thrown.
3c0f1ff
-
3c0f1ff
-            throw new SyntaxError('JSON.parse');
3c0f1ff
-        };
3c0f1ff
-    }
3c0f1ff
-}(this));