WordPress.org

Make WordPress Core

Changeset 17679


Ignore:
Timestamp:
04/21/2011 10:21:27 PM (7 years ago)
Author:
azaozz
Message:

Update json2.js, props niallkennedy, fixes #16669

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/json2.dev.js

    r11911 r17679  
    11/*
    22    http://www.JSON.org/json2.js
    3     2009-08-17
     3    2011-02-23
    44
    55    Public Domain.
     
    88
    99    See http://www.JSON.org/js.html
     10
     11
     12    This code should be minified before deployment.
     13    See http://javascript.crockford.com/jsmin.html
     14
     15    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
     16    NOT CONTROL.
     17
    1018
    1119    This file creates a global JSON object containing two methods: stringify
     
    137145    This is a reference implementation. You are free to copy, modify, or
    138146    redistribute.
    139 
    140     This code should be minified before deployment.
    141     See http://javascript.crockford.com/jsmin.html
    142 
    143     USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    144     NOT CONTROL.
    145147*/
    146148
    147 /*jslint evil: true */
     149/*jslint evil: true, strict: false, regexp: false */
    148150
    149151/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
     
    154156*/
    155157
    156 "use strict";
    157158
    158159// Create a JSON object only if one does not already exist. We create the
    159160// methods in a closure to avoid creating global variables.
    160161
    161 if (!this.JSON) {
    162     this.JSON = {};
     162var JSON;
     163if (!JSON) {
     164    JSON = {};
    163165}
    164166
    165167(function () {
     168    "use strict";
    166169
    167170    function f(n) {
     
    175178
    176179            return isFinite(this.valueOf()) ?
    177                    this.getUTCFullYear()   + '-' +
    178                  f(this.getUTCMonth() + 1) + '-' +
    179                  f(this.getUTCDate())      + 'T' +
    180                  f(this.getUTCHours())     + ':' +
    181                  f(this.getUTCMinutes())   + ':' +
    182                  f(this.getUTCSeconds())   + 'Z' : null;
     180                this.getUTCFullYear()     + '-' +
     181                f(this.getUTCMonth() + 1) + '-' +
     182                f(this.getUTCDate())      + 'T' +
     183                f(this.getUTCHours())     + ':' +
     184                f(this.getUTCMinutes())   + ':' +
     185                f(this.getUTCSeconds())   + 'Z' : null;
    183186        };
    184187
    185         String.prototype.toJSON =
    186         Number.prototype.toJSON =
    187         Boolean.prototype.toJSON = function (key) {
    188             return this.valueOf();
    189         };
     188        String.prototype.toJSON      =
     189            Number.prototype.toJSON =
     190            Boolean.prototype.toJSON = function (key) {
     191                return this.valueOf();
     192            };
    190193    }
    191194
     
    214217
    215218        escapable.lastIndex = 0;
    216         return escapable.test(string) ?
    217             '"' + string.replace(escapable, function (a) {
    218                 var c = meta[a];
    219                 return typeof c === 'string' ? c :
    220                     '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
    221             }) + '"' :
    222             '"' + string + '"';
     219        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
     220            var c = meta[a];
     221            return typeof c === 'string' ? c :
     222                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
     223        }) + '"' : '"' + string + '"';
    223224    }
    224225
     
    303304// brackets.
    304305
    305                 v = partial.length === 0 ? '[]' :
    306                     gap ? '[\n' + gap +
    307                             partial.join(',\n' + gap) + '\n' +
    308                                 mind + ']' :
    309                           '[' + partial.join(',') + ']';
     306                v = partial.length === 0 ? '[]' : gap ?
     307                    '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
     308                    '[' + partial.join(',') + ']';
    310309                gap = mind;
    311310                return v;
     
    317316                length = rep.length;
    318317                for (i = 0; i < length; i += 1) {
    319                     k = rep[i];
    320                     if (typeof k === 'string') {
     318                    if (typeof rep[i] === 'string') {
     319                        k = rep[i];
    321320                        v = str(k, value);
    322321                        if (v) {
     
    330329
    331330                for (k in value) {
    332                     if (Object.hasOwnProperty.call(value, k)) {
     331                    if (Object.prototype.hasOwnProperty.call(value, k)) {
    333332                        v = str(k, value);
    334333                        if (v) {
     
    342341// and wrap them in braces.
    343342
    344             v = partial.length === 0 ? '{}' :
    345                 gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
    346                         mind + '}' : '{' + partial.join(',') + '}';
     343            v = partial.length === 0 ? '{}' : gap ?
     344                '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
     345                '{' + partial.join(',') + '}';
    347346            gap = mind;
    348347            return v;
     
    385384            if (replacer && typeof replacer !== 'function' &&
    386385                    (typeof replacer !== 'object' ||
    387                      typeof replacer.length !== 'number')) {
     386                    typeof replacer.length !== 'number')) {
    388387                throw new Error('JSON.stringify');
    389388            }
     
    415414                if (value && typeof value === 'object') {
    416415                    for (k in value) {
    417                         if (Object.hasOwnProperty.call(value, k)) {
     416                        if (Object.prototype.hasOwnProperty.call(value, k)) {
    418417                            v = walk(value, k);
    419418                            if (v !== undefined) {
     
    433432// incorrectly, either silently deleting them, or treating them as line endings.
    434433
     434            text = String(text);
    435435            cx.lastIndex = 0;
    436436            if (cx.test(text)) {
     
    454454// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
    455455
    456             if (/^[\],:{}\s]*$/.
    457 test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
    458 replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
    459 replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
     456            if (/^[\],:{}\s]*$/
     457                    .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
     458                        .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
     459                        .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
    460460
    461461// In the third stage we use the eval function to compile the text into a
     
    479479    }
    480480}());
    481 
  • trunk/wp-includes/js/json2.js

    r17286 r17679  
    1 "use strict";if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};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={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){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){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}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{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){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)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}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,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());
     1var JSON;if(!JSON){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};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={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){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){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==="string"){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}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,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());
  • trunk/wp-includes/script-loader.php

    r17662 r17679  
    244244    $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');
    245245
    246     $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", false, '20110113');
     246    $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", false, '2011-02-23');
    247247
    248248    $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.1-20110113' );
Note: See TracChangeset for help on using the changeset viewer.