Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed json test after master -> ie10 merge

  • Loading branch information...
commit 05f25fa8ef15f896b4526eff7b49ef52adc0939a 2 parents ae609ab + f968f0f
@davglass authored
View
88 build/json-parse/json-parse-coverage.js
@@ -26,10 +26,10 @@ _yuitest_coverage["build/json-parse/json-parse.js"] = {
path: "build/json-parse/json-parse.js",
code: []
};
-_yuitest_coverage["build/json-parse/json-parse.js"].code=["YUI.add('json-parse', function (Y, NAME) {","","/**"," * <p>The JSON module adds support for serializing JavaScript objects into"," * JSON strings and parsing JavaScript objects from strings in JSON format.</p>"," *"," * <p>The JSON namespace is added to your YUI instance including static methods"," * Y.JSON.parse(..) and Y.JSON.stringify(..).</p>"," *"," * <p>The functionality and method signatures follow the ECMAScript 5"," * specification. In browsers with native JSON support, the native"," * implementation is used.</p>"," *"," * <p>The <code>json</code> module is a rollup of <code>json-parse</code> and"," * <code>json-stringify</code>.</p>"," * "," * <p>As their names suggest, <code>json-parse</code> adds support for parsing"," * JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing"," * JavaScript data into JSON strings (Y.JSON.stringify). You may choose to"," * include either of the submodules individually if you don't need the"," * complementary functionality, or include the rollup for both.</p>"," *"," * @module json"," * @main json"," * @class JSON"," * @static"," */","","/**"," * Provides Y.JSON.parse method to accept JSON strings and return native"," * JavaScript objects."," *"," * @module json"," * @submodule json-parse"," * @for JSON"," * @static"," */","","","// All internals kept private for security reasons","function fromGlobal(ref) {"," return (Y.config.win || this || {})[ref];","}","",""," /**"," * Alias to native browser implementation of the JSON object if available."," *"," * @property Native"," * @type {Object}"," * @private"," */","var _JSON = fromGlobal('JSON'),",""," Native = (Object.prototype.toString.call(_JSON) === '[object JSON]' && _JSON),"," useNative = !!Native,",""," /**"," * Replace certain Unicode characters that JavaScript may handle incorrectly"," * during eval--either by deleting them or treating them as line"," * endings--with escape sequences."," * IMPORTANT NOTE: This regex will be used to modify the input if a match is"," * found."," *"," * @property _UNICODE_EXCEPTIONS"," * @type {RegExp}"," * @private"," */"," _UNICODE_EXCEPTIONS = /[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,","",""," /**"," * First step in the safety evaluation. Regex used to replace all escape"," * sequences (i.e. \"\\\\\", etc) with '@' characters (a non-JSON character)."," *"," * @property _ESCAPES"," * @type {RegExp}"," * @private"," */"," _ESCAPES = /\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,",""," /**"," * Second step in the safety evaluation. Regex used to replace all simple"," * values with ']' characters."," *"," * @property _VALUES"," * @type {RegExp}"," * @private"," */"," _VALUES = /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,",""," /**"," * Third step in the safety evaluation. Regex used to remove all open"," * square brackets following a colon, comma, or at the beginning of the"," * string."," *"," * @property _BRACKETS"," * @type {RegExp}"," * @private"," */"," _BRACKETS = /(?:^|:|,)(?:\\s*\\[)+/g,",""," /**"," * Final step in the safety evaluation. Regex used to test the string left"," * after all previous replacements for invalid characters."," *"," * @property _UNSAFE"," * @type {RegExp}"," * @private"," */"," _UNSAFE = /[^\\],:{}\\s]/,"," "," /**"," * Replaces specific unicode characters with their appropriate \\unnnn"," * format. Some browsers ignore certain characters during eval."," *"," * @method escapeException"," * @param c {String} Unicode character"," * @return {String} the \\unnnn escapement of the character"," * @private"," */"," _escapeException = function (c) {"," return '\\\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);"," },",""," /**"," * Traverses nested objects, applying a reviver function to each (key,value)"," * from the scope if the key:value's containing object. The value returned"," * from the function will replace the original value in the key:value pair."," * If the value returned is undefined, the key will be omitted from the"," * returned object."," *"," * @method _revive"," * @param data {MIXED} Any JavaScript data"," * @param reviver {Function} filter or mutation function"," * @return {MIXED} The results of the filtered data"," * @private"," */"," _revive = function (data, reviver) {"," var walk = function (o,key) {"," var k,v,value = o[key];"," if (value && typeof value === 'object') {"," for (k in value) {"," if (value.hasOwnProperty(k)) {"," v = walk(value, k);"," if (v === undefined) {"," delete value[k];"," } else {"," value[k] = v;"," }"," }"," }"," }"," return reviver.call(o,key,value);"," };",""," return typeof reviver === 'function' ? walk({'':data},'') : data;"," },",""," /**"," * Parse a JSON string, returning the native JavaScript representation."," *"," * @param s {string} JSON string data"," * @param reviver {function} (optional) function(k,v) passed each key value"," * pair of object literals, allowing pruning or altering values"," * @return {MIXED} the native JavaScript representation of the JSON string"," * @throws SyntaxError"," * @method parse"," * @static"," */"," // JavaScript implementation in lieu of native browser support. Based on"," // the json2.js library from http://json.org"," _parse = function (s,reviver) {"," // Replace certain Unicode characters that are otherwise handled"," // incorrectly by some browser implementations."," // NOTE: This modifies the input if such characters are found!"," s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);"," "," // Test for any remaining invalid characters"," if (!_UNSAFE.test(s.replace(_ESCAPES,'@')."," replace(_VALUES,']')."," replace(_BRACKETS,''))) {",""," // Eval the text into a JavaScript data structure, apply any"," // reviver function, and return"," return _revive( eval('(' + s + ')'), reviver );"," }",""," throw new SyntaxError('JSON.parse');"," };"," ","Y.namespace('JSON').parse = function (s,reviver) {"," if (typeof s !== 'string') {"," s += '';"," }",""," return Native && Y.JSON.useNativeParse ?"," Native.parse(s,reviver) : _parse(s,reviver);","};","","function workingNative( k, v ) {"," return k === \"ok\" ? true : v;","}","","// Double check basic functionality. This is mainly to catch early broken","// implementations of the JSON API in Firefox 3.1 beta1 and beta2","if ( Native ) {"," try {"," useNative = ( Native.parse( '{\"ok\":false}', workingNative ) ).ok;"," }"," catch ( e ) {"," useNative = false;"," }","}","","/**"," * Leverage native JSON parse if the browser has a native implementation."," * In general, this is a good idea. See the Known Issues section in the"," * JSON user guide for caveats. The default value is true for browsers with"," * native JSON support."," *"," * @property useNativeParse"," * @type Boolean"," * @default true"," * @static"," */","Y.JSON.useNativeParse = useNative;","","","}, '@VERSION@', {\"requires\": [\"yui-base\"]});"];
-_yuitest_coverage["build/json-parse/json-parse.js"].lines = {"1":0,"41":0,"42":0,"53":0,"123":0,"140":0,"141":0,"142":0,"143":0,"144":0,"145":0,"146":0,"147":0,"149":0,"154":0,"157":0,"177":0,"180":0,"186":0,"189":0,"192":0,"193":0,"194":0,"197":0,"201":0,"202":0,"207":0,"208":0,"209":0,"212":0,"227":0};
-_yuitest_coverage["build/json-parse/json-parse.js"].functions = {"fromGlobal:41":0,"_escapeException:122":0,"walk:140":0,"_revive:139":0,"_parse:173":0,"parse:192":0,"workingNative:201":0,"(anonymous 1):1":0};
-_yuitest_coverage["build/json-parse/json-parse.js"].coveredLines = 31;
+_yuitest_coverage["build/json-parse/json-parse.js"].code=["YUI.add('json-parse', function (Y, NAME) {","","/**"," * <p>The JSON module adds support for serializing JavaScript objects into"," * JSON strings and parsing JavaScript objects from strings in JSON format.</p>"," *"," * <p>The JSON namespace is added to your YUI instance including static methods"," * Y.JSON.parse(..) and Y.JSON.stringify(..).</p>"," *"," * <p>The functionality and method signatures follow the ECMAScript 5"," * specification. In browsers with native JSON support, the native"," * implementation is used.</p>"," *"," * <p>The <code>json</code> module is a rollup of <code>json-parse</code> and"," * <code>json-stringify</code>.</p>"," *"," * <p>As their names suggest, <code>json-parse</code> adds support for parsing"," * JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing"," * JavaScript data into JSON strings (Y.JSON.stringify). You may choose to"," * include either of the submodules individually if you don't need the"," * complementary functionality, or include the rollup for both.</p>"," *"," * @module json"," * @main json"," * @class JSON"," * @static"," */","","/**"," * Provides Y.JSON.parse method to accept JSON strings and return native"," * JavaScript objects."," *"," * @module json"," * @submodule json-parse"," * @for JSON"," * @static"," */","","","// All internals kept private for security reasons","function fromGlobal(ref) {"," var g = ((typeof global === 'object') ? global : undefined);"," return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];","}","",""," /**"," * Alias to native browser implementation of the JSON object if available."," *"," * @property Native"," * @type {Object}"," * @private"," */","var _JSON = fromGlobal('JSON'),",""," Native = (Object.prototype.toString.call(_JSON) === '[object JSON]' && _JSON),"," useNative = !!Native,",""," /**"," * Replace certain Unicode characters that JavaScript may handle incorrectly"," * during eval--either by deleting them or treating them as line"," * endings--with escape sequences."," * IMPORTANT NOTE: This regex will be used to modify the input if a match is"," * found."," *"," * @property _UNICODE_EXCEPTIONS"," * @type {RegExp}"," * @private"," */"," _UNICODE_EXCEPTIONS = /[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,","",""," /**"," * First step in the safety evaluation. Regex used to replace all escape"," * sequences (i.e. \"\\\\\", etc) with '@' characters (a non-JSON character)."," *"," * @property _ESCAPES"," * @type {RegExp}"," * @private"," */"," _ESCAPES = /\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,",""," /**"," * Second step in the safety evaluation. Regex used to replace all simple"," * values with ']' characters."," *"," * @property _VALUES"," * @type {RegExp}"," * @private"," */"," _VALUES = /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,",""," /**"," * Third step in the safety evaluation. Regex used to remove all open"," * square brackets following a colon, comma, or at the beginning of the"," * string."," *"," * @property _BRACKETS"," * @type {RegExp}"," * @private"," */"," _BRACKETS = /(?:^|:|,)(?:\\s*\\[)+/g,",""," /**"," * Final step in the safety evaluation. Regex used to test the string left"," * after all previous replacements for invalid characters."," *"," * @property _UNSAFE"," * @type {RegExp}"," * @private"," */"," _UNSAFE = /[^\\],:{}\\s]/,",""," /**"," * Replaces specific unicode characters with their appropriate \\unnnn"," * format. Some browsers ignore certain characters during eval."," *"," * @method escapeException"," * @param c {String} Unicode character"," * @return {String} the \\unnnn escapement of the character"," * @private"," */"," _escapeException = function (c) {"," return '\\\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);"," },",""," /**"," * Traverses nested objects, applying a reviver function to each (key,value)"," * from the scope if the key:value's containing object. The value returned"," * from the function will replace the original value in the key:value pair."," * If the value returned is undefined, the key will be omitted from the"," * returned object."," *"," * @method _revive"," * @param data {MIXED} Any JavaScript data"," * @param reviver {Function} filter or mutation function"," * @return {MIXED} The results of the filtered data"," * @private"," */"," _revive = function (data, reviver) {"," var walk = function (o,key) {"," var k,v,value = o[key];"," if (value && typeof value === 'object') {"," for (k in value) {"," if (value.hasOwnProperty(k)) {"," v = walk(value, k);"," if (v === undefined) {"," delete value[k];"," } else {"," value[k] = v;"," }"," }"," }"," }"," return reviver.call(o,key,value);"," };",""," return typeof reviver === 'function' ? walk({'':data},'') : data;"," },",""," /**"," * Parse a JSON string, returning the native JavaScript representation."," *"," * @param s {string} JSON string data"," * @param reviver {function} (optional) function(k,v) passed each key value"," * pair of object literals, allowing pruning or altering values"," * @return {MIXED} the native JavaScript representation of the JSON string"," * @throws SyntaxError"," * @method parse"," * @static"," */"," // JavaScript implementation in lieu of native browser support. Based on"," // the json2.js library from http://json.org"," _parse = function (s,reviver) {"," // Replace certain Unicode characters that are otherwise handled"," // incorrectly by some browser implementations."," // NOTE: This modifies the input if such characters are found!"," s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);",""," // Test for any remaining invalid characters"," if (!_UNSAFE.test(s.replace(_ESCAPES,'@')."," replace(_VALUES,']')."," replace(_BRACKETS,''))) {",""," // Eval the text into a JavaScript data structure, apply any"," // reviver function, and return"," return _revive( eval('(' + s + ')'), reviver );"," }",""," throw new SyntaxError('JSON.parse');"," };","","Y.namespace('JSON').parse = function (s,reviver) {"," if (typeof s !== 'string') {"," s += '';"," }",""," return Native && Y.JSON.useNativeParse ?"," Native.parse(s,reviver) : _parse(s,reviver);","};","","function workingNative( k, v ) {"," return k === \"ok\" ? true : v;","}","","// Double check basic functionality. This is mainly to catch early broken","// implementations of the JSON API in Firefox 3.1 beta1 and beta2","if ( Native ) {"," try {"," useNative = ( Native.parse( '{\"ok\":false}', workingNative ) ).ok;"," }"," catch ( e ) {"," useNative = false;"," }","}","","/**"," * Leverage native JSON parse if the browser has a native implementation."," * In general, this is a good idea. See the Known Issues section in the"," * JSON user guide for caveats. The default value is true for browsers with"," * native JSON support."," *"," * @property useNativeParse"," * @type Boolean"," * @default true"," * @static"," */","Y.JSON.useNativeParse = useNative;","","","}, '@VERSION@', {\"requires\": [\"yui-base\"]});"];
+_yuitest_coverage["build/json-parse/json-parse.js"].lines = {"1":0,"41":0,"42":0,"43":0,"54":0,"124":0,"141":0,"142":0,"143":0,"144":0,"145":0,"146":0,"147":0,"148":0,"150":0,"155":0,"158":0,"178":0,"181":0,"187":0,"190":0,"193":0,"194":0,"195":0,"198":0,"202":0,"203":0,"208":0,"209":0,"210":0,"213":0,"228":0};
+_yuitest_coverage["build/json-parse/json-parse.js"].functions = {"fromGlobal:41":0,"_escapeException:123":0,"walk:141":0,"_revive:140":0,"_parse:174":0,"parse:193":0,"workingNative:202":0,"(anonymous 1):1":0};
+_yuitest_coverage["build/json-parse/json-parse.js"].coveredLines = 32;
_yuitest_coverage["build/json-parse/json-parse.js"].coveredFunctions = 8;
_yuitest_coverline("build/json-parse/json-parse.js", 1);
YUI.add('json-parse', function (Y, NAME) {
@@ -47,7 +47,7 @@ YUI.add('json-parse', function (Y, NAME) {
*
* <p>The <code>json</code> module is a rollup of <code>json-parse</code> and
* <code>json-stringify</code>.</p>
- *
+ *
* <p>As their names suggest, <code>json-parse</code> adds support for parsing
* JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing
* JavaScript data into JSON strings (Y.JSON.stringify). You may choose to
@@ -77,7 +77,9 @@ _yuitest_coverline("build/json-parse/json-parse.js", 41);
function fromGlobal(ref) {
_yuitest_coverfunc("build/json-parse/json-parse.js", "fromGlobal", 41);
_yuitest_coverline("build/json-parse/json-parse.js", 42);
-return (Y.config.win || this || {})[ref];
+var g = ((typeof global === 'object') ? global : undefined);
+ _yuitest_coverline("build/json-parse/json-parse.js", 43);
+return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
}
@@ -88,7 +90,7 @@ return (Y.config.win || this || {})[ref];
* @type {Object}
* @private
*/
-_yuitest_coverline("build/json-parse/json-parse.js", 53);
+_yuitest_coverline("build/json-parse/json-parse.js", 54);
var _JSON = fromGlobal('JSON'),
Native = (Object.prototype.toString.call(_JSON) === '[object JSON]' && _JSON),
@@ -148,7 +150,7 @@ var _JSON = fromGlobal('JSON'),
* @private
*/
_UNSAFE = /[^\],:{}\s]/,
-
+
/**
* Replaces specific unicode characters with their appropriate \unnnn
* format. Some browsers ignore certain characters during eval.
@@ -159,8 +161,8 @@ var _JSON = fromGlobal('JSON'),
* @private
*/
_escapeException = function (c) {
- _yuitest_coverfunc("build/json-parse/json-parse.js", "_escapeException", 122);
-_yuitest_coverline("build/json-parse/json-parse.js", 123);
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "_escapeException", 123);
+_yuitest_coverline("build/json-parse/json-parse.js", 124);
return '\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);
},
@@ -178,36 +180,36 @@ return '\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);
* @private
*/
_revive = function (data, reviver) {
- _yuitest_coverfunc("build/json-parse/json-parse.js", "_revive", 139);
-_yuitest_coverline("build/json-parse/json-parse.js", 140);
-var walk = function (o,key) {
- _yuitest_coverfunc("build/json-parse/json-parse.js", "walk", 140);
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "_revive", 140);
_yuitest_coverline("build/json-parse/json-parse.js", 141);
+var walk = function (o,key) {
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "walk", 141);
+_yuitest_coverline("build/json-parse/json-parse.js", 142);
var k,v,value = o[key];
- _yuitest_coverline("build/json-parse/json-parse.js", 142);
+ _yuitest_coverline("build/json-parse/json-parse.js", 143);
if (value && typeof value === 'object') {
- _yuitest_coverline("build/json-parse/json-parse.js", 143);
+ _yuitest_coverline("build/json-parse/json-parse.js", 144);
for (k in value) {
- _yuitest_coverline("build/json-parse/json-parse.js", 144);
+ _yuitest_coverline("build/json-parse/json-parse.js", 145);
if (value.hasOwnProperty(k)) {
- _yuitest_coverline("build/json-parse/json-parse.js", 145);
-v = walk(value, k);
_yuitest_coverline("build/json-parse/json-parse.js", 146);
+v = walk(value, k);
+ _yuitest_coverline("build/json-parse/json-parse.js", 147);
if (v === undefined) {
- _yuitest_coverline("build/json-parse/json-parse.js", 147);
+ _yuitest_coverline("build/json-parse/json-parse.js", 148);
delete value[k];
} else {
- _yuitest_coverline("build/json-parse/json-parse.js", 149);
+ _yuitest_coverline("build/json-parse/json-parse.js", 150);
value[k] = v;
}
}
}
}
- _yuitest_coverline("build/json-parse/json-parse.js", 154);
+ _yuitest_coverline("build/json-parse/json-parse.js", 155);
return reviver.call(o,key,value);
};
- _yuitest_coverline("build/json-parse/json-parse.js", 157);
+ _yuitest_coverline("build/json-parse/json-parse.js", 158);
return typeof reviver === 'function' ? walk({'':data},'') : data;
},
@@ -228,58 +230,58 @@ return typeof reviver === 'function' ? walk({'':data},'') : data;
// Replace certain Unicode characters that are otherwise handled
// incorrectly by some browser implementations.
// NOTE: This modifies the input if such characters are found!
- _yuitest_coverfunc("build/json-parse/json-parse.js", "_parse", 173);
-_yuitest_coverline("build/json-parse/json-parse.js", 177);
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "_parse", 174);
+_yuitest_coverline("build/json-parse/json-parse.js", 178);
s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);
-
+
// Test for any remaining invalid characters
- _yuitest_coverline("build/json-parse/json-parse.js", 180);
+ _yuitest_coverline("build/json-parse/json-parse.js", 181);
if (!_UNSAFE.test(s.replace(_ESCAPES,'@').
replace(_VALUES,']').
replace(_BRACKETS,''))) {
// Eval the text into a JavaScript data structure, apply any
// reviver function, and return
- _yuitest_coverline("build/json-parse/json-parse.js", 186);
+ _yuitest_coverline("build/json-parse/json-parse.js", 187);
return _revive( eval('(' + s + ')'), reviver );
}
- _yuitest_coverline("build/json-parse/json-parse.js", 189);
+ _yuitest_coverline("build/json-parse/json-parse.js", 190);
throw new SyntaxError('JSON.parse');
};
-
-_yuitest_coverline("build/json-parse/json-parse.js", 192);
-Y.namespace('JSON').parse = function (s,reviver) {
- _yuitest_coverfunc("build/json-parse/json-parse.js", "parse", 192);
+
_yuitest_coverline("build/json-parse/json-parse.js", 193);
+Y.namespace('JSON').parse = function (s,reviver) {
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "parse", 193);
+_yuitest_coverline("build/json-parse/json-parse.js", 194);
if (typeof s !== 'string') {
- _yuitest_coverline("build/json-parse/json-parse.js", 194);
+ _yuitest_coverline("build/json-parse/json-parse.js", 195);
s += '';
}
- _yuitest_coverline("build/json-parse/json-parse.js", 197);
+ _yuitest_coverline("build/json-parse/json-parse.js", 198);
return Native && Y.JSON.useNativeParse ?
Native.parse(s,reviver) : _parse(s,reviver);
};
-_yuitest_coverline("build/json-parse/json-parse.js", 201);
-function workingNative( k, v ) {
- _yuitest_coverfunc("build/json-parse/json-parse.js", "workingNative", 201);
_yuitest_coverline("build/json-parse/json-parse.js", 202);
+function workingNative( k, v ) {
+ _yuitest_coverfunc("build/json-parse/json-parse.js", "workingNative", 202);
+_yuitest_coverline("build/json-parse/json-parse.js", 203);
return k === "ok" ? true : v;
}
// Double check basic functionality. This is mainly to catch early broken
// implementations of the JSON API in Firefox 3.1 beta1 and beta2
-_yuitest_coverline("build/json-parse/json-parse.js", 207);
+_yuitest_coverline("build/json-parse/json-parse.js", 208);
if ( Native ) {
- _yuitest_coverline("build/json-parse/json-parse.js", 208);
+ _yuitest_coverline("build/json-parse/json-parse.js", 209);
try {
- _yuitest_coverline("build/json-parse/json-parse.js", 209);
+ _yuitest_coverline("build/json-parse/json-parse.js", 210);
useNative = ( Native.parse( '{"ok":false}', workingNative ) ).ok;
}
catch ( e ) {
- _yuitest_coverline("build/json-parse/json-parse.js", 212);
+ _yuitest_coverline("build/json-parse/json-parse.js", 213);
useNative = false;
}
}
@@ -295,7 +297,7 @@ useNative = false;
* @default true
* @static
*/
-_yuitest_coverline("build/json-parse/json-parse.js", 227);
+_yuitest_coverline("build/json-parse/json-parse.js", 228);
Y.JSON.useNativeParse = useNative;
View
11 build/json-parse/json-parse-debug.js
@@ -13,7 +13,7 @@ YUI.add('json-parse', function (Y, NAME) {
*
* <p>The <code>json</code> module is a rollup of <code>json-parse</code> and
* <code>json-stringify</code>.</p>
- *
+ *
* <p>As their names suggest, <code>json-parse</code> adds support for parsing
* JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing
* JavaScript data into JSON strings (Y.JSON.stringify). You may choose to
@@ -39,7 +39,8 @@ YUI.add('json-parse', function (Y, NAME) {
// All internals kept private for security reasons
function fromGlobal(ref) {
- return (Y.config.win || this || {})[ref];
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
}
@@ -109,7 +110,7 @@ var _JSON = fromGlobal('JSON'),
* @private
*/
_UNSAFE = /[^\],:{}\s]/,
-
+
/**
* Replaces specific unicode characters with their appropriate \unnnn
* format. Some browsers ignore certain characters during eval.
@@ -175,7 +176,7 @@ var _JSON = fromGlobal('JSON'),
// incorrectly by some browser implementations.
// NOTE: This modifies the input if such characters are found!
s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);
-
+
// Test for any remaining invalid characters
if (!_UNSAFE.test(s.replace(_ESCAPES,'@').
replace(_VALUES,']').
@@ -188,7 +189,7 @@ var _JSON = fromGlobal('JSON'),
throw new SyntaxError('JSON.parse');
};
-
+
Y.namespace('JSON').parse = function (s,reviver) {
if (typeof s !== 'string') {
s += '';
View
2  build/json-parse/json-parse-min.js
@@ -1 +1 @@
-YUI.add("json-parse",function(e,t){function n(t){return(e.config.win||this||{})[t]}function d(e,t){return e==="ok"?!0:t}var r=n("JSON"),i=Object.prototype.toString.call(r)==="[object JSON]"&&r,s=!!i,o=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,u=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,a=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,f=/(?:^|:|,)(?:\s*\[)+/g,l=/[^\],:{}\s]/,c=function(e){return"\\u"+("0000"+(+e.charCodeAt(0)).toString(16)).slice(-4)},h=function(e,t){var n=function(e,r){var i,s,o=e[r];if(o&&typeof o=="object")for(i in o)o.hasOwnProperty(i)&&(s=n(o,i),s===undefined?delete o[i]:o[i]=s);return t.call(e,r,o)};return typeof t=="function"?n({"":e},""):e},p=function(e,t){e=e.replace(o,c);if(!l.test(e.replace(u,"@").replace(a,"]").replace(f,"")))return h(eval("("+e+")"),t);throw new SyntaxError("JSON.parse")};e.namespace("JSON").parse=function(t,n){return typeof t!="string"&&(t+=""),i&&e.JSON.useNativeParse?i.parse(t,n):p(t,n)};if(i)try{s=i.parse('{"ok":false}',d).ok}catch(v){s=!1}e.JSON.useNativeParse=s},"@VERSION@",{requires:["yui-base"]});
+YUI.add("json-parse",function(e,t){function n(t){var n=typeof global=="object"?global:undefined;return(e.UA.nodejs&&n?n:e.config.win||{})[t]}function d(e,t){return e==="ok"?!0:t}var r=n("JSON"),i=Object.prototype.toString.call(r)==="[object JSON]"&&r,s=!!i,o=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,u=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,a=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,f=/(?:^|:|,)(?:\s*\[)+/g,l=/[^\],:{}\s]/,c=function(e){return"\\u"+("0000"+(+e.charCodeAt(0)).toString(16)).slice(-4)},h=function(e,t){var n=function(e,r){var i,s,o=e[r];if(o&&typeof o=="object")for(i in o)o.hasOwnProperty(i)&&(s=n(o,i),s===undefined?delete o[i]:o[i]=s);return t.call(e,r,o)};return typeof t=="function"?n({"":e},""):e},p=function(e,t){e=e.replace(o,c);if(!l.test(e.replace(u,"@").replace(a,"]").replace(f,"")))return h(eval("("+e+")"),t);throw new SyntaxError("JSON.parse")};e.namespace("JSON").parse=function(t,n){return typeof t!="string"&&(t+=""),i&&e.JSON.useNativeParse?i.parse(t,n):p(t,n)};if(i)try{s=i.parse('{"ok":false}',d).ok}catch(v){s=!1}e.JSON.useNativeParse=s},"@VERSION@",{requires:["yui-base"]});
View
11 build/json-parse/json-parse.js
@@ -13,7 +13,7 @@ YUI.add('json-parse', function (Y, NAME) {
*
* <p>The <code>json</code> module is a rollup of <code>json-parse</code> and
* <code>json-stringify</code>.</p>
- *
+ *
* <p>As their names suggest, <code>json-parse</code> adds support for parsing
* JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing
* JavaScript data into JSON strings (Y.JSON.stringify). You may choose to
@@ -39,7 +39,8 @@ YUI.add('json-parse', function (Y, NAME) {
// All internals kept private for security reasons
function fromGlobal(ref) {
- return (Y.config.win || this || {})[ref];
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
}
@@ -109,7 +110,7 @@ var _JSON = fromGlobal('JSON'),
* @private
*/
_UNSAFE = /[^\],:{}\s]/,
-
+
/**
* Replaces specific unicode characters with their appropriate \unnnn
* format. Some browsers ignore certain characters during eval.
@@ -175,7 +176,7 @@ var _JSON = fromGlobal('JSON'),
// incorrectly by some browser implementations.
// NOTE: This modifies the input if such characters are found!
s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);
-
+
// Test for any remaining invalid characters
if (!_UNSAFE.test(s.replace(_ESCAPES,'@').
replace(_VALUES,']').
@@ -188,7 +189,7 @@ var _JSON = fromGlobal('JSON'),
throw new SyntaxError('JSON.parse');
};
-
+
Y.namespace('JSON').parse = function (s,reviver) {
if (typeof s !== 'string') {
s += '';
View
199 build/json-stringify/json-stringify-coverage.js
@@ -26,11 +26,11 @@ _yuitest_coverage["build/json-stringify/json-stringify.js"] = {
path: "build/json-stringify/json-stringify.js",
code: []
};
-_yuitest_coverage["build/json-stringify/json-stringify.js"].code=["YUI.add('json-stringify', function (Y, NAME) {","","/**"," * Provides Y.JSON.stringify method for converting objects to JSON strings."," *"," * @module json"," * @submodule json-stringify"," * @for JSON"," * @static"," */","var _JSON = (Y.config.win || {}).JSON,"," Lang = Y.Lang,"," isFunction= Lang.isFunction,"," isObject = Lang.isObject,"," isArray = Lang.isArray,"," _toStr = Object.prototype.toString,"," Native = (_toStr.call(_JSON) === '[object JSON]' && _JSON),"," useNative = !!Native,"," UNDEFINED = 'undefined',"," OBJECT = 'object',"," NULL = 'null',"," STRING = 'string',"," NUMBER = 'number',"," BOOLEAN = 'boolean',"," DATE = 'date',"," _allowable= {"," 'undefined' : UNDEFINED,"," 'string' : STRING,"," '[object String]' : STRING,"," 'number' : NUMBER,"," '[object Number]' : NUMBER,"," 'boolean' : BOOLEAN,"," '[object Boolean]' : BOOLEAN,"," '[object Date]' : DATE,"," '[object RegExp]' : OBJECT"," },"," EMPTY = '',"," OPEN_O = '{',"," CLOSE_O = '}',"," OPEN_A = '[',"," CLOSE_A = ']',"," COMMA = ',',"," COMMA_CR = \",\\n\","," CR = \"\\n\","," COLON = ':',"," COLON_SP = ': ',"," QUOTE = '\"',",""," // Regex used to capture characters that need escaping before enclosing"," // their containing string in quotes."," _SPECIAL = /[\\x00-\\x07\\x0b\\x0e-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,",""," // Character substitution map for common escapes and special characters."," _COMMON = ["," [/\\\\/g, '\\\\\\\\'],"," [/\\\"/g, '\\\\\"'],"," [/\\x08/g, '\\\\b'],"," [/\\x09/g, '\\\\t'],"," [/\\x0a/g, '\\\\n'],"," [/\\x0c/g, '\\\\f'],"," [/\\x0d/g, '\\\\r']"," ],"," _COMMON_LENGTH = _COMMON.length,",""," // In-process optimization for special character escapes that haven't yet"," // been promoted to _COMMON"," _CHAR = {},",""," // Per-char counter to determine if it's worth fast tracking a special"," // character escape sequence."," _CHAR_COUNT, _CACHE_THRESHOLD;","","// Utility function used to determine how to serialize a variable.","function _type(o) {"," var t = typeof o;"," return _allowable[t] || // number, string, boolean, undefined"," _allowable[_toStr.call(o)] || // Number, String, Boolean, Date"," (t === OBJECT ?"," (o ? OBJECT : NULL) : // object, array, null, misc natives"," UNDEFINED); // function, unknown","}","","// Escapes a special character to a safe Unicode representation","function _char(c) {"," if (!_CHAR[c]) {"," _CHAR[c] = '\\\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);"," _CHAR_COUNT[c] = 0;"," }",""," // === to avoid this conditional for the remainder of the current operation"," if (++_CHAR_COUNT[c] === _CACHE_THRESHOLD) {"," _COMMON.push([new RegExp(c, 'g'), _CHAR[c]]);"," _COMMON_LENGTH = _COMMON.length;"," }",""," return _CHAR[c];","}","","// Enclose escaped strings in quotes","function _string(s) {"," var i, chr;",""," // Preprocess the string against common characters to avoid function"," // overhead associated with replacement via function."," for (i = 0; i < _COMMON_LENGTH; i++) {"," chr = _COMMON[i];"," s = s.replace(chr[0], chr[1]);"," }"," "," // original function replace for the not-as-common set of chars"," return QUOTE + s.replace(_SPECIAL, _char) + QUOTE;","}","","// Adds the provided space to the beginning of every line in the input string","function _indent(s,space) {"," return s.replace(/^/gm, space);","}","","// JavaScript implementation of stringify (see API declaration of stringify)","function _stringify(o,w,space) {"," if (o === undefined) {"," return undefined;"," }",""," var replacer = isFunction(w) ? w : null,"," format = _toStr.call(space).match(/String|Number/) || [],"," _date = Y.JSON.dateToString,"," stack = [],"," tmp,i,len;",""," _CHAR_COUNT = {};"," _CACHE_THRESHOLD = Y.JSON.charCacheThreshold;",""," if (replacer || !isArray(w)) {"," w = undefined;"," }",""," // Ensure whitelist keys are unique (bug 2110391)"," if (w) {"," tmp = {};"," for (i = 0, len = w.length; i < len; ++i) {"," tmp[w[i]] = true;"," }"," w = tmp;"," }",""," // Per the spec, strings are truncated to 10 characters and numbers"," // are converted to that number of spaces (max 10)"," space = format[0] === 'Number' ?"," new Array(Math.min(Math.max(0,space),10)+1).join(\" \") :"," (space || EMPTY).slice(0,10);",""," function _serialize(h,key) {"," var value = h[key],"," t = _type(value),"," a = [],"," colon = space ? COLON_SP : COLON,"," arr, i, keys, k, v;",""," // Per the ECMA 5 spec, toJSON is applied before the replacer is"," // called. Also per the spec, Date.prototype.toJSON has been added, so"," // Date instances should be serialized prior to exposure to the"," // replacer. I disagree with this decision, but the spec is the spec."," if (isObject(value) && isFunction(value.toJSON)) {"," value = value.toJSON(key);"," } else if (t === DATE) {"," value = _date(value);"," }",""," if (isFunction(replacer)) {"," value = replacer.call(h,key,value);"," }",""," if (value !== h[key]) {"," t = _type(value);"," }",""," switch (t) {"," case DATE : // intentional fallthrough. Pre-replacer Dates are"," // serialized in the toJSON stage. Dates here would"," // have been produced by the replacer."," case OBJECT : break;"," case STRING : return _string(value);"," case NUMBER : return isFinite(value) ? value+EMPTY : NULL;"," case BOOLEAN : return value+EMPTY;"," case NULL : return NULL;"," default : return undefined;"," }",""," // Check for cyclical references in nested objects"," for (i = stack.length - 1; i >= 0; --i) {"," if (stack[i] === value) {"," throw new Error(\"JSON.stringify. Cyclical reference\");"," }"," }",""," arr = isArray(value);",""," // Add the object to the processing stack"," stack.push(value);",""," if (arr) { // Array"," for (i = value.length - 1; i >= 0; --i) {"," a[i] = _serialize(value, i) || NULL;"," }"," } else { // Object"," // If whitelist provided, take only those keys"," keys = w || value;"," i = 0;",""," for (k in keys) {"," if (keys.hasOwnProperty(k)) {"," v = _serialize(value, k);"," if (v) {"," a[i++] = _string(k) + colon + v;"," }"," }"," }"," }",""," // remove the array from the stack"," stack.pop();",""," if (space && a.length) {"," return arr ?"," OPEN_A + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_A :"," OPEN_O + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_O;"," } else {"," return arr ?"," OPEN_A + a.join(COMMA) + CLOSE_A :"," OPEN_O + a.join(COMMA) + CLOSE_O;"," }"," }",""," // process the input"," return _serialize({'':o},'');","}","","// Double check basic native functionality. This is primarily to catch broken","// early JSON API implementations in Firefox 3.1 beta1 and beta2.","if ( Native ) {"," try {"," useNative = ( '0' === Native.stringify(0) );"," } catch ( e ) {"," useNative = false;"," }","}","","Y.mix(Y.namespace('JSON'),{"," /**"," * Leverage native JSON stringify if the browser has a native"," * implementation. In general, this is a good idea. See the Known Issues"," * section in the JSON user guide for caveats. The default value is true"," * for browsers with native JSON support."," *"," * @property useNativeStringify"," * @type Boolean"," * @default true"," * @static"," */"," useNativeStringify : useNative,",""," /**"," * Serializes a Date instance as a UTC date string. Used internally by"," * stringify. Override this method if you need Dates serialized in a"," * different format."," *"," * @method dateToString"," * @param d {Date} The Date to serialize"," * @return {String} stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ"," * @deprecated Use a replacer function"," * @static"," */"," dateToString : function (d) {"," function _zeroPad(v) {"," return v < 10 ? '0' + v : v;"," }",""," return d.getUTCFullYear() + '-' +"," _zeroPad(d.getUTCMonth() + 1) + '-' +"," _zeroPad(d.getUTCDate()) + 'T' +"," _zeroPad(d.getUTCHours()) + COLON +"," _zeroPad(d.getUTCMinutes()) + COLON +"," _zeroPad(d.getUTCSeconds()) + 'Z';"," },",""," /**"," * <p>Converts an arbitrary value to a JSON string representation.</p>"," *"," * <p>Objects with cyclical references will trigger an exception.</p>"," *"," * <p>If a whitelist is provided, only matching object keys will be"," * included. Alternately, a replacer function may be passed as the"," * second parameter. This function is executed on every value in the"," * input, and its return value will be used in place of the original value."," * This is useful to serialize specialized objects or class instances.</p>"," *"," * <p>If a positive integer or non-empty string is passed as the third"," * parameter, the output will be formatted with carriage returns and"," * indentation for readability. If a String is passed (such as \"\\t\") it"," * will be used once for each indentation level. If a number is passed,"," * that number of spaces will be used.</p>"," *"," * @method stringify"," * @param o {MIXED} any arbitrary value to convert to JSON string"," * @param w {Array|Function} (optional) whitelist of acceptable object"," * keys to include, or a replacer function to modify the"," * raw value before serialization"," * @param ind {Number|String} (optional) indentation character or depth of"," * spaces to format the output."," * @return {string} JSON string representation of the input"," * @static"," */"," stringify : function (o,w,ind) {"," return Native && Y.JSON.useNativeStringify ?"," Native.stringify(o,w,ind) : _stringify(o,w,ind);"," },",""," /**"," * <p>Number of occurrences of a special character within a single call to"," * stringify that should trigger promotion of that character to a dedicated"," * preprocess step for future calls. This is only used in environments"," * that don't support native JSON, or when useNativeStringify is set to"," * false.</p>"," *"," * <p>So, if set to 50 and an object is passed to stringify that includes"," * strings containing the special character \\x07 more than 50 times,"," * subsequent calls to stringify will process object strings through a"," * faster serialization path for \\x07 before using the generic, slower,"," * replacement process for all special characters.</p>"," *"," * <p>To prime the preprocessor cache, set this value to 1, then call"," * <code>Y.JSON.stringify(\"<em>(all special characters to"," * cache)</em>\");</code>, then return this setting to a more conservative"," * value.</p>"," *"," * <p>Special characters \\ \" \\b \\t \\n \\f \\r are already cached.</p>"," *"," * @property charCacheThreshold"," * @static"," * @default 100"," * @type {Number}"," */"," charCacheThreshold: 100","});","","","}, '@VERSION@', {\"requires\": [\"yui-base\"]});"];
-_yuitest_coverage["build/json-stringify/json-stringify.js"].lines = {"1":0,"11":0,"74":0,"75":0,"76":0,"84":0,"85":0,"86":0,"87":0,"91":0,"92":0,"93":0,"96":0,"100":0,"101":0,"105":0,"106":0,"107":0,"111":0,"115":0,"116":0,"120":0,"121":0,"122":0,"125":0,"131":0,"132":0,"134":0,"135":0,"139":0,"140":0,"141":0,"142":0,"144":0,"149":0,"153":0,"154":0,"164":0,"165":0,"166":0,"167":0,"170":0,"171":0,"174":0,"175":0,"178":0,"182":0,"183":0,"184":0,"185":0,"186":0,"187":0,"191":0,"192":0,"193":0,"197":0,"200":0,"202":0,"203":0,"204":0,"208":0,"209":0,"211":0,"212":0,"213":0,"214":0,"215":0,"222":0,"224":0,"225":0,"229":0,"236":0,"241":0,"242":0,"243":0,"245":0,"249":0,"275":0,"276":0,"279":0,"315":0};
-_yuitest_coverage["build/json-stringify/json-stringify.js"].functions = {"_type:74":0,"_char:84":0,"_string:100":0,"_indent:115":0,"_serialize:153":0,"_stringify:120":0,"_zeroPad:275":0,"dateToString:274":0,"stringify:314":0,"(anonymous 1):1":0};
-_yuitest_coverage["build/json-stringify/json-stringify.js"].coveredLines = 81;
-_yuitest_coverage["build/json-stringify/json-stringify.js"].coveredFunctions = 10;
+_yuitest_coverage["build/json-stringify/json-stringify.js"].code=["YUI.add('json-stringify', function (Y, NAME) {","","/**"," * Provides Y.JSON.stringify method for converting objects to JSON strings."," *"," * @module json"," * @submodule json-stringify"," * @for JSON"," * @static"," */","// All internals kept private for security reasons","function fromGlobal(ref) {"," var g = ((typeof global === 'object') ? global : undefined);"," return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];","}","var _JSON = fromGlobal('JSON'),"," Lang = Y.Lang,"," isFunction= Lang.isFunction,"," isObject = Lang.isObject,"," isArray = Lang.isArray,"," _toStr = Object.prototype.toString,"," Native = (_toStr.call(_JSON) === '[object JSON]' && _JSON),"," useNative = !!Native,"," UNDEFINED = 'undefined',"," OBJECT = 'object',"," NULL = 'null',"," STRING = 'string',"," NUMBER = 'number',"," BOOLEAN = 'boolean',"," DATE = 'date',"," _allowable= {"," 'undefined' : UNDEFINED,"," 'string' : STRING,"," '[object String]' : STRING,"," 'number' : NUMBER,"," '[object Number]' : NUMBER,"," 'boolean' : BOOLEAN,"," '[object Boolean]' : BOOLEAN,"," '[object Date]' : DATE,"," '[object RegExp]' : OBJECT"," },"," EMPTY = '',"," OPEN_O = '{',"," CLOSE_O = '}',"," OPEN_A = '[',"," CLOSE_A = ']',"," COMMA = ',',"," COMMA_CR = \",\\n\","," CR = \"\\n\","," COLON = ':',"," COLON_SP = ': ',"," QUOTE = '\"',",""," // Regex used to capture characters that need escaping before enclosing"," // their containing string in quotes."," _SPECIAL = /[\\x00-\\x07\\x0b\\x0e-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,",""," // Character substitution map for common escapes and special characters."," _COMMON = ["," [/\\\\/g, '\\\\\\\\'],"," [/\\\"/g, '\\\\\"'],"," [/\\x08/g, '\\\\b'],"," [/\\x09/g, '\\\\t'],"," [/\\x0a/g, '\\\\n'],"," [/\\x0c/g, '\\\\f'],"," [/\\x0d/g, '\\\\r']"," ],"," _COMMON_LENGTH = _COMMON.length,",""," // In-process optimization for special character escapes that haven't yet"," // been promoted to _COMMON"," _CHAR = {},",""," // Per-char counter to determine if it's worth fast tracking a special"," // character escape sequence."," _CHAR_COUNT, _CACHE_THRESHOLD;","","// Utility function used to determine how to serialize a variable.","function _type(o) {"," var t = typeof o;"," return _allowable[t] || // number, string, boolean, undefined"," _allowable[_toStr.call(o)] || // Number, String, Boolean, Date"," (t === OBJECT ?"," (o ? OBJECT : NULL) : // object, array, null, misc natives"," UNDEFINED); // function, unknown","}","","// Escapes a special character to a safe Unicode representation","function _char(c) {"," if (!_CHAR[c]) {"," _CHAR[c] = '\\\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);"," _CHAR_COUNT[c] = 0;"," }",""," // === to avoid this conditional for the remainder of the current operation"," if (++_CHAR_COUNT[c] === _CACHE_THRESHOLD) {"," _COMMON.push([new RegExp(c, 'g'), _CHAR[c]]);"," _COMMON_LENGTH = _COMMON.length;"," }",""," return _CHAR[c];","}","","// Enclose escaped strings in quotes","function _string(s) {"," var i, chr;",""," // Preprocess the string against common characters to avoid function"," // overhead associated with replacement via function."," for (i = 0; i < _COMMON_LENGTH; i++) {"," chr = _COMMON[i];"," s = s.replace(chr[0], chr[1]);"," }"," "," // original function replace for the not-as-common set of chars"," return QUOTE + s.replace(_SPECIAL, _char) + QUOTE;","}","","// Adds the provided space to the beginning of every line in the input string","function _indent(s,space) {"," return s.replace(/^/gm, space);","}","","// JavaScript implementation of stringify (see API declaration of stringify)","function _stringify(o,w,space) {"," if (o === undefined) {"," return undefined;"," }",""," var replacer = isFunction(w) ? w : null,"," format = _toStr.call(space).match(/String|Number/) || [],"," _date = Y.JSON.dateToString,"," stack = [],"," tmp,i,len;",""," _CHAR_COUNT = {};"," _CACHE_THRESHOLD = Y.JSON.charCacheThreshold;",""," if (replacer || !isArray(w)) {"," w = undefined;"," }",""," // Ensure whitelist keys are unique (bug 2110391)"," if (w) {"," tmp = {};"," for (i = 0, len = w.length; i < len; ++i) {"," tmp[w[i]] = true;"," }"," w = tmp;"," }",""," // Per the spec, strings are truncated to 10 characters and numbers"," // are converted to that number of spaces (max 10)"," space = format[0] === 'Number' ?"," new Array(Math.min(Math.max(0,space),10)+1).join(\" \") :"," (space || EMPTY).slice(0,10);",""," function _serialize(h,key) {"," var value = h[key],"," t = _type(value),"," a = [],"," colon = space ? COLON_SP : COLON,"," arr, i, keys, k, v;",""," // Per the ECMA 5 spec, toJSON is applied before the replacer is"," // called. Also per the spec, Date.prototype.toJSON has been added, so"," // Date instances should be serialized prior to exposure to the"," // replacer. I disagree with this decision, but the spec is the spec."," if (isObject(value) && isFunction(value.toJSON)) {"," value = value.toJSON(key);"," } else if (t === DATE) {"," value = _date(value);"," }",""," if (isFunction(replacer)) {"," value = replacer.call(h,key,value);"," }",""," if (value !== h[key]) {"," t = _type(value);"," }",""," switch (t) {"," case DATE : // intentional fallthrough. Pre-replacer Dates are"," // serialized in the toJSON stage. Dates here would"," // have been produced by the replacer."," case OBJECT : break;"," case STRING : return _string(value);"," case NUMBER : return isFinite(value) ? value+EMPTY : NULL;"," case BOOLEAN : return value+EMPTY;"," case NULL : return NULL;"," default : return undefined;"," }",""," // Check for cyclical references in nested objects"," for (i = stack.length - 1; i >= 0; --i) {"," if (stack[i] === value) {"," throw new Error(\"JSON.stringify. Cyclical reference\");"," }"," }",""," arr = isArray(value);",""," // Add the object to the processing stack"," stack.push(value);",""," if (arr) { // Array"," for (i = value.length - 1; i >= 0; --i) {"," a[i] = _serialize(value, i) || NULL;"," }"," } else { // Object"," // If whitelist provided, take only those keys"," keys = w || value;"," i = 0;",""," for (k in keys) {"," if (keys.hasOwnProperty(k)) {"," v = _serialize(value, k);"," if (v) {"," a[i++] = _string(k) + colon + v;"," }"," }"," }"," }",""," // remove the array from the stack"," stack.pop();",""," if (space && a.length) {"," return arr ?"," OPEN_A + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_A :"," OPEN_O + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_O;"," } else {"," return arr ?"," OPEN_A + a.join(COMMA) + CLOSE_A :"," OPEN_O + a.join(COMMA) + CLOSE_O;"," }"," }",""," // process the input"," return _serialize({'':o},'');","}","","// Double check basic native functionality. This is primarily to catch broken","// early JSON API implementations in Firefox 3.1 beta1 and beta2.","if ( Native ) {"," try {"," useNative = ( '0' === Native.stringify(0) );"," } catch ( e ) {"," useNative = false;"," }","}","","Y.mix(Y.namespace('JSON'),{"," /**"," * Leverage native JSON stringify if the browser has a native"," * implementation. In general, this is a good idea. See the Known Issues"," * section in the JSON user guide for caveats. The default value is true"," * for browsers with native JSON support."," *"," * @property useNativeStringify"," * @type Boolean"," * @default true"," * @static"," */"," useNativeStringify : useNative,",""," /**"," * Serializes a Date instance as a UTC date string. Used internally by"," * stringify. Override this method if you need Dates serialized in a"," * different format."," *"," * @method dateToString"," * @param d {Date} The Date to serialize"," * @return {String} stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ"," * @deprecated Use a replacer function"," * @static"," */"," dateToString : function (d) {"," function _zeroPad(v) {"," return v < 10 ? '0' + v : v;"," }",""," return d.getUTCFullYear() + '-' +"," _zeroPad(d.getUTCMonth() + 1) + '-' +"," _zeroPad(d.getUTCDate()) + 'T' +"," _zeroPad(d.getUTCHours()) + COLON +"," _zeroPad(d.getUTCMinutes()) + COLON +"," _zeroPad(d.getUTCSeconds()) + 'Z';"," },",""," /**"," * <p>Converts an arbitrary value to a JSON string representation.</p>"," *"," * <p>Objects with cyclical references will trigger an exception.</p>"," *"," * <p>If a whitelist is provided, only matching object keys will be"," * included. Alternately, a replacer function may be passed as the"," * second parameter. This function is executed on every value in the"," * input, and its return value will be used in place of the original value."," * This is useful to serialize specialized objects or class instances.</p>"," *"," * <p>If a positive integer or non-empty string is passed as the third"," * parameter, the output will be formatted with carriage returns and"," * indentation for readability. If a String is passed (such as \"\\t\") it"," * will be used once for each indentation level. If a number is passed,"," * that number of spaces will be used.</p>"," *"," * @method stringify"," * @param o {MIXED} any arbitrary value to convert to JSON string"," * @param w {Array|Function} (optional) whitelist of acceptable object"," * keys to include, or a replacer function to modify the"," * raw value before serialization"," * @param ind {Number|String} (optional) indentation character or depth of"," * spaces to format the output."," * @return {string} JSON string representation of the input"," * @static"," */"," stringify : function (o,w,ind) {"," return Native && Y.JSON.useNativeStringify ?"," Native.stringify(o,w,ind) : _stringify(o,w,ind);"," },",""," /**"," * <p>Number of occurrences of a special character within a single call to"," * stringify that should trigger promotion of that character to a dedicated"," * preprocess step for future calls. This is only used in environments"," * that don't support native JSON, or when useNativeStringify is set to"," * false.</p>"," *"," * <p>So, if set to 50 and an object is passed to stringify that includes"," * strings containing the special character \\x07 more than 50 times,"," * subsequent calls to stringify will process object strings through a"," * faster serialization path for \\x07 before using the generic, slower,"," * replacement process for all special characters.</p>"," *"," * <p>To prime the preprocessor cache, set this value to 1, then call"," * <code>Y.JSON.stringify(\"<em>(all special characters to"," * cache)</em>\");</code>, then return this setting to a more conservative"," * value.</p>"," *"," * <p>Special characters \\ \" \\b \\t \\n \\f \\r are already cached.</p>"," *"," * @property charCacheThreshold"," * @static"," * @default 100"," * @type {Number}"," */"," charCacheThreshold: 100","});","","","}, '@VERSION@', {\"requires\": [\"yui-base\"]});"];
+_yuitest_coverage["build/json-stringify/json-stringify.js"].lines = {"1":0,"12":0,"13":0,"14":0,"16":0,"79":0,"80":0,"81":0,"89":0,"90":0,"91":0,"92":0,"96":0,"97":0,"98":0,"101":0,"105":0,"106":0,"110":0,"111":0,"112":0,"116":0,"120":0,"121":0,"125":0,"126":0,"127":0,"130":0,"136":0,"137":0,"139":0,"140":0,"144":0,"145":0,"146":0,"147":0,"149":0,"154":0,"158":0,"159":0,"169":0,"170":0,"171":0,"172":0,"175":0,"176":0,"179":0,"180":0,"183":0,"187":0,"188":0,"189":0,"190":0,"191":0,"192":0,"196":0,"197":0,"198":0,"202":0,"205":0,"207":0,"208":0,"209":0,"213":0,"214":0,"216":0,"217":0,"218":0,"219":0,"220":0,"227":0,"229":0,"230":0,"234":0,"241":0,"246":0,"247":0,"248":0,"250":0,"254":0,"280":0,"281":0,"284":0,"320":0};
+_yuitest_coverage["build/json-stringify/json-stringify.js"].functions = {"fromGlobal:12":0,"_type:79":0,"_char:89":0,"_string:105":0,"_indent:120":0,"_serialize:158":0,"_stringify:125":0,"_zeroPad:280":0,"dateToString:279":0,"stringify:319":0,"(anonymous 1):1":0};
+_yuitest_coverage["build/json-stringify/json-stringify.js"].coveredLines = 84;
+_yuitest_coverage["build/json-stringify/json-stringify.js"].coveredFunctions = 11;
_yuitest_coverline("build/json-stringify/json-stringify.js", 1);
YUI.add('json-stringify', function (Y, NAME) {
@@ -42,9 +42,18 @@ YUI.add('json-stringify', function (Y, NAME) {
* @for JSON
* @static
*/
+// All internals kept private for security reasons
_yuitest_coverfunc("build/json-stringify/json-stringify.js", "(anonymous 1)", 1);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 11);
-var _JSON = (Y.config.win || {}).JSON,
+_yuitest_coverline("build/json-stringify/json-stringify.js", 12);
+function fromGlobal(ref) {
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "fromGlobal", 12);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 13);
+var g = ((typeof global === 'object') ? global : undefined);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 14);
+return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
+}
+_yuitest_coverline("build/json-stringify/json-stringify.js", 16);
+var _JSON = fromGlobal('JSON'),
Lang = Y.Lang,
isFunction= Lang.isFunction,
isObject = Lang.isObject,
@@ -107,12 +116,12 @@ var _JSON = (Y.config.win || {}).JSON,
_CHAR_COUNT, _CACHE_THRESHOLD;
// Utility function used to determine how to serialize a variable.
-_yuitest_coverline("build/json-stringify/json-stringify.js", 74);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 79);
function _type(o) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_type", 74);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 75);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_type", 79);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 80);
var t = typeof o;
- _yuitest_coverline("build/json-stringify/json-stringify.js", 76);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 81);
return _allowable[t] || // number, string, boolean, undefined
_allowable[_toStr.call(o)] || // Number, String, Boolean, Date
(t === OBJECT ?
@@ -121,113 +130,113 @@ return _allowable[t] || // number, string, boolean, undefined
}
// Escapes a special character to a safe Unicode representation
-_yuitest_coverline("build/json-stringify/json-stringify.js", 84);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 89);
function _char(c) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_char", 84);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 85);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_char", 89);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 90);
if (!_CHAR[c]) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 86);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 91);
_CHAR[c] = '\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);
- _yuitest_coverline("build/json-stringify/json-stringify.js", 87);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 92);
_CHAR_COUNT[c] = 0;
}
// === to avoid this conditional for the remainder of the current operation
- _yuitest_coverline("build/json-stringify/json-stringify.js", 91);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 96);
if (++_CHAR_COUNT[c] === _CACHE_THRESHOLD) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 92);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 97);
_COMMON.push([new RegExp(c, 'g'), _CHAR[c]]);
- _yuitest_coverline("build/json-stringify/json-stringify.js", 93);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 98);
_COMMON_LENGTH = _COMMON.length;
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 96);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 101);
return _CHAR[c];
}
// Enclose escaped strings in quotes
-_yuitest_coverline("build/json-stringify/json-stringify.js", 100);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 105);
function _string(s) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_string", 100);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 101);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_string", 105);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 106);
var i, chr;
// Preprocess the string against common characters to avoid function
// overhead associated with replacement via function.
- _yuitest_coverline("build/json-stringify/json-stringify.js", 105);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 110);
for (i = 0; i < _COMMON_LENGTH; i++) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 106);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 111);
chr = _COMMON[i];
- _yuitest_coverline("build/json-stringify/json-stringify.js", 107);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 112);
s = s.replace(chr[0], chr[1]);
}
// original function replace for the not-as-common set of chars
- _yuitest_coverline("build/json-stringify/json-stringify.js", 111);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 116);
return QUOTE + s.replace(_SPECIAL, _char) + QUOTE;
}
// Adds the provided space to the beginning of every line in the input string
-_yuitest_coverline("build/json-stringify/json-stringify.js", 115);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 120);
function _indent(s,space) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_indent", 115);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 116);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_indent", 120);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 121);
return s.replace(/^/gm, space);
}
// JavaScript implementation of stringify (see API declaration of stringify)
-_yuitest_coverline("build/json-stringify/json-stringify.js", 120);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 125);
function _stringify(o,w,space) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_stringify", 120);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 121);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_stringify", 125);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 126);
if (o === undefined) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 122);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 127);
return undefined;
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 125);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 130);
var replacer = isFunction(w) ? w : null,
format = _toStr.call(space).match(/String|Number/) || [],
_date = Y.JSON.dateToString,
stack = [],
tmp,i,len;
- _yuitest_coverline("build/json-stringify/json-stringify.js", 131);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 136);
_CHAR_COUNT = {};
- _yuitest_coverline("build/json-stringify/json-stringify.js", 132);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 137);
_CACHE_THRESHOLD = Y.JSON.charCacheThreshold;
- _yuitest_coverline("build/json-stringify/json-stringify.js", 134);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 139);
if (replacer || !isArray(w)) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 135);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 140);
w = undefined;
}
// Ensure whitelist keys are unique (bug 2110391)
- _yuitest_coverline("build/json-stringify/json-stringify.js", 139);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 144);
if (w) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 140);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 145);
tmp = {};
- _yuitest_coverline("build/json-stringify/json-stringify.js", 141);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 146);
for (i = 0, len = w.length; i < len; ++i) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 142);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 147);
tmp[w[i]] = true;
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 144);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 149);
w = tmp;
}
// Per the spec, strings are truncated to 10 characters and numbers
// are converted to that number of spaces (max 10)
- _yuitest_coverline("build/json-stringify/json-stringify.js", 149);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 154);
space = format[0] === 'Number' ?
new Array(Math.min(Math.max(0,space),10)+1).join(" ") :
(space || EMPTY).slice(0,10);
- _yuitest_coverline("build/json-stringify/json-stringify.js", 153);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 158);
function _serialize(h,key) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_serialize", 153);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 154);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_serialize", 158);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 159);
var value = h[key],
t = _type(value),
a = [],
@@ -238,87 +247,87 @@ var value = h[key],
// called. Also per the spec, Date.prototype.toJSON has been added, so
// Date instances should be serialized prior to exposure to the
// replacer. I disagree with this decision, but the spec is the spec.
- _yuitest_coverline("build/json-stringify/json-stringify.js", 164);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 169);
if (isObject(value) && isFunction(value.toJSON)) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 165);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 170);
value = value.toJSON(key);
- } else {_yuitest_coverline("build/json-stringify/json-stringify.js", 166);
+ } else {_yuitest_coverline("build/json-stringify/json-stringify.js", 171);
if (t === DATE) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 167);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 172);
value = _date(value);
}}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 170);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 175);
if (isFunction(replacer)) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 171);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 176);
value = replacer.call(h,key,value);
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 174);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 179);
if (value !== h[key]) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 175);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 180);
t = _type(value);
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 178);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 183);
switch (t) {
case DATE : // intentional fallthrough. Pre-replacer Dates are
// serialized in the toJSON stage. Dates here would
// have been produced by the replacer.
- case OBJECT : _yuitest_coverline("build/json-stringify/json-stringify.js", 182);
+ case OBJECT : _yuitest_coverline("build/json-stringify/json-stringify.js", 187);
break;
- case STRING : _yuitest_coverline("build/json-stringify/json-stringify.js", 183);
+ case STRING : _yuitest_coverline("build/json-stringify/json-stringify.js", 188);
return _string(value);
- case NUMBER : _yuitest_coverline("build/json-stringify/json-stringify.js", 184);
+ case NUMBER : _yuitest_coverline("build/json-stringify/json-stringify.js", 189);
return isFinite(value) ? value+EMPTY : NULL;
- case BOOLEAN : _yuitest_coverline("build/json-stringify/json-stringify.js", 185);
+ case BOOLEAN : _yuitest_coverline("build/json-stringify/json-stringify.js", 190);
return value+EMPTY;
- case NULL : _yuitest_coverline("build/json-stringify/json-stringify.js", 186);
+ case NULL : _yuitest_coverline("build/json-stringify/json-stringify.js", 191);
return NULL;
- default : _yuitest_coverline("build/json-stringify/json-stringify.js", 187);
+ default : _yuitest_coverline("build/json-stringify/json-stringify.js", 192);
return undefined;
}
// Check for cyclical references in nested objects
- _yuitest_coverline("build/json-stringify/json-stringify.js", 191);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 196);
for (i = stack.length - 1; i >= 0; --i) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 192);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 197);
if (stack[i] === value) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 193);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 198);
throw new Error("JSON.stringify. Cyclical reference");
}
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 197);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 202);
arr = isArray(value);
// Add the object to the processing stack
- _yuitest_coverline("build/json-stringify/json-stringify.js", 200);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 205);
stack.push(value);
- _yuitest_coverline("build/json-stringify/json-stringify.js", 202);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 207);
if (arr) { // Array
- _yuitest_coverline("build/json-stringify/json-stringify.js", 203);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 208);
for (i = value.length - 1; i >= 0; --i) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 204);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 209);
a[i] = _serialize(value, i) || NULL;
}
} else { // Object
// If whitelist provided, take only those keys
- _yuitest_coverline("build/json-stringify/json-stringify.js", 208);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 213);
keys = w || value;
- _yuitest_coverline("build/json-stringify/json-stringify.js", 209);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 214);
i = 0;
- _yuitest_coverline("build/json-stringify/json-stringify.js", 211);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 216);
for (k in keys) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 212);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 217);
if (keys.hasOwnProperty(k)) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 213);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 218);
v = _serialize(value, k);
- _yuitest_coverline("build/json-stringify/json-stringify.js", 214);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 219);
if (v) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 215);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 220);
a[i++] = _string(k) + colon + v;
}
}
@@ -326,17 +335,17 @@ a[i++] = _string(k) + colon + v;
}
// remove the array from the stack
- _yuitest_coverline("build/json-stringify/json-stringify.js", 222);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 227);
stack.pop();
- _yuitest_coverline("build/json-stringify/json-stringify.js", 224);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 229);
if (space && a.length) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 225);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 230);
return arr ?
OPEN_A + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_A :
OPEN_O + CR + _indent(a.join(COMMA_CR), space) + CR + CLOSE_O;
} else {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 229);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 234);
return arr ?
OPEN_A + a.join(COMMA) + CLOSE_A :
OPEN_O + a.join(COMMA) + CLOSE_O;
@@ -344,25 +353,25 @@ return arr ?
}
// process the input
- _yuitest_coverline("build/json-stringify/json-stringify.js", 236);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 241);
return _serialize({'':o},'');
}
// Double check basic native functionality. This is primarily to catch broken
// early JSON API implementations in Firefox 3.1 beta1 and beta2.
-_yuitest_coverline("build/json-stringify/json-stringify.js", 241);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 246);
if ( Native ) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 242);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 247);
try {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 243);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 248);
useNative = ( '0' === Native.stringify(0) );
} catch ( e ) {
- _yuitest_coverline("build/json-stringify/json-stringify.js", 245);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 250);
useNative = false;
}
}
-_yuitest_coverline("build/json-stringify/json-stringify.js", 249);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 254);
Y.mix(Y.namespace('JSON'),{
/**
* Leverage native JSON stringify if the browser has a native
@@ -389,15 +398,15 @@ Y.mix(Y.namespace('JSON'),{
* @static
*/
dateToString : function (d) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "dateToString", 274);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 275);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "dateToString", 279);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 280);
function _zeroPad(v) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_zeroPad", 275);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 276);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "_zeroPad", 280);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 281);
return v < 10 ? '0' + v : v;
}
- _yuitest_coverline("build/json-stringify/json-stringify.js", 279);
+ _yuitest_coverline("build/json-stringify/json-stringify.js", 284);
return d.getUTCFullYear() + '-' +
_zeroPad(d.getUTCMonth() + 1) + '-' +
_zeroPad(d.getUTCDate()) + 'T' +
@@ -434,8 +443,8 @@ return d.getUTCFullYear() + '-' +
* @static
*/
stringify : function (o,w,ind) {
- _yuitest_coverfunc("build/json-stringify/json-stringify.js", "stringify", 314);
-_yuitest_coverline("build/json-stringify/json-stringify.js", 315);
+ _yuitest_coverfunc("build/json-stringify/json-stringify.js", "stringify", 319);
+_yuitest_coverline("build/json-stringify/json-stringify.js", 320);
return Native && Y.JSON.useNativeStringify ?
Native.stringify(o,w,ind) : _stringify(o,w,ind);
},
View
7 build/json-stringify/json-stringify-debug.js
@@ -8,7 +8,12 @@ YUI.add('json-stringify', function (Y, NAME) {
* @for JSON
* @static
*/
-var _JSON = (Y.config.win || {}).JSON,
+// All internals kept private for security reasons
+function fromGlobal(ref) {
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
+}
+var _JSON = fromGlobal('JSON'),
Lang = Y.Lang,
isFunction= Lang.isFunction,
isObject = Lang.isObject,
View
2  build/json-stringify/json-stringify-min.js
@@ -1 +1 @@
-YUI.add("json-stringify",function(e,t){function H(e){var t=typeof e;return g[t]||g[u.call(e)]||(t===c?e?c:h:l)}function B(e){return _[e]||(_[e]="\\u"+("0000"+(+e.charCodeAt(0)).toString(16)).slice(-4),D[e]=0),++D[e]===P&&(O.push([new RegExp(e,"g"),_[e]]),M=O.length),_[e]}function j(e){var t,n;for(t=0;t<M;t++)n=O[t],e=e.replace(n[0],n[1]);return L+e.replace(A,B)+L}function F(e,t){return e.replace(/^/gm,t)}function I(t,n,r){function M(e,t){var u=e[t],f=H(u),L=[],A=r?k:C,O,_,D,P,B;s(u)&&i(u.toJSON)?u=u.toJSON(t):f===m&&(u=l(u)),i(a)&&(u=a.call(e,t,u)),u!==e[t]&&(f=H(u));switch(f){case m:case c:break;case p:return j(u);case d:return isFinite(u)?u+y:h;case v:return u+y;case h:return h;default:return undefined}for(_=g.length-1;_>=0;--_)if(g[_]===u)throw new Error("JSON.stringify. Cyclical reference");O=o(u),g.push(u);if(O)for(_=u.length-1;_>=0;--_)L[_]=M(u,_)||h;else{D=n||u,_=0;for(P in D)D.hasOwnProperty(P)&&(B=M(u,P),B&&(L[_++]=j(P)+A+B))}return g.pop(),r&&L.length?O?E+N+F(L.join(T),r)+N+S:b+N+F(L.join(T),r)+N+w:O?E+L.join(x)+S:b+L.join(x)+w}if(t===undefined)return undefined;var a=i(n)?n:null,f=u.call(r).match(/String|Number/)||[],l=e.JSON.dateToString,g=[],L,A,O;D={},P=e.JSON.charCacheThreshold;if(a||!o(n))n=undefined;if(n){L={};for(A=0,O=n.length;A<O;++A)L[n[A]]=!0;n=L}return r=f[0]==="Number"?(new Array(Math.min(Math.max(0,r),10)+1)).join(" "):(r||y).slice(0,10),M({"":t},"")}var n=(e.config.win||{}).JSON,r=e.Lang,i=r.isFunction,s=r.isObject,o=r.isArray,u=Object.prototype.toString,a=u.call(n)==="[object JSON]"&&n,f=!!a,l="undefined",c="object",h="null",p="string",d="number",v="boolean",m="date",g={"undefined":l,string:p,"[object String]":p,number:d,"[object Number]":d,"boolean":v,"[object Boolean]":v,"[object Date]":m,"[object RegExp]":c},y="",b="{",w="}",E="[",S="]",x=",",T=",\n",N="\n",C=":",k=": ",L='"',A=/[\x00-\x07\x0b\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,O=[[/\\/g,"\\\\"],[/\"/g,'\\"'],[/\x08/g,"\\b"],[/\x09/g,"\\t"],[/\x0a/g,"\\n"],[/\x0c/g,"\\f"],[/\x0d/g,"\\r"]],M=O.length,_={},D,P;if(a)try{f="0"===a.stringify(0)}catch(q){f=!1}e.mix(e.namespace("JSON"),{useNativeStringify:f,dateToString:function(e){function t(e){return e<10?"0"+e:e}return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+C+t(e.getUTCMinutes())+C+t(e.getUTCSeconds())+"Z"},stringify:function(t,n,r){return a&&e.JSON.useNativeStringify?a.stringify(t,n,r):I(t,n,r)},charCacheThreshold:100})},"@VERSION@",{requires:["yui-base"]});
+YUI.add("json-stringify",function(e,t){function n(t){var n=typeof global=="object"?global:undefined;return(e.UA.nodejs&&n?n:e.config.win||{})[t]}function B(e){var t=typeof e;return y[t]||y[a.call(e)]||(t===h?e?h:p:c)}function j(e){return D[e]||(D[e]="\\u"+("0000"+(+e.charCodeAt(0)).toString(16)).slice(-4),P[e]=0),++P[e]===H&&(M.push([new RegExp(e,"g"),D[e]]),_=M.length),D[e]}function F(e){var t,n;for(t=0;t<_;t++)n=M[t],e=e.replace(n[0],n[1]);return A+e.replace(O,j)+A}function I(e,t){return e.replace(/^/gm,t)}function q(t,n,r){function M(e,t){var a=e[t],f=B(a),y=[],A=r?L:k,O,_,D,P,H;o(a)&&s(a.toJSON)?a=a.toJSON(t):f===g&&(a=l(a)),s(i)&&(a=i.call(e,t,a)),a!==e[t]&&(f=B(a));switch(f){case g:case h:break;case d:return F(a);case v:return isFinite(a)?a+b:p;case m:return a+b;case p:return p;default:return undefined}for(_=c.length-1;_>=0;--_)if(c[_]===a)throw new Error("JSON.stringify. Cyclical reference");O=u(a),c.push(a);if(O)for(_=a.length-1;_>=0;--_)y[_]=M(a,_)||p;else{D=n||a,_=0;for(P in D)D.hasOwnProperty(P)&&(H=M(a,P),H&&(y[_++]=F(P)+A+H))}return c.pop(),r&&y.length?O?S+C+I(y.join(N),r)+C+x:w+C+I(y.join(N),r)+C+E:O?S+y.join(T)+x:w+y.join(T)+E}if(t===undefined)return undefined;var i=s(n)?n:null,f=a.call(r).match(/String|Number/)||[],l=e.JSON.dateToString,c=[],y,A,O;P={},H=e.JSON.charCacheThreshold;if(i||!u(n))n=undefined;if(n){y={};for(A=0,O=n.length;A<O;++A)y[n[A]]=!0;n=y}return r=f[0]==="Number"?(new Array(Math.min(Math.max(0,r),10)+1)).join(" "):(r||b).slice(0,10),M({"":t},"")}var r=n("JSON"),i=e.Lang,s=i.isFunction,o=i.isObject,u=i.isArray,a=Object.prototype.toString,f=a.call(r)==="[object JSON]"&&r,l=!!f,c="undefined",h="object",p="null",d="string",v="number",m="boolean",g="date",y={"undefined":c,string:d,"[object String]":d,number:v,"[object Number]":v,"boolean":m,"[object Boolean]":m,"[object Date]":g,"[object RegExp]":h},b="",w="{",E="}",S="[",x="]",T=",",N=",\n",C="\n",k=":",L=": ",A='"',O=/[\x00-\x07\x0b\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,M=[[/\\/g,"\\\\"],[/\"/g,'\\"'],[/\x08/g,"\\b"],[/\x09/g,"\\t"],[/\x0a/g,"\\n"],[/\x0c/g,"\\f"],[/\x0d/g,"\\r"]],_=M.length,D={},P,H;if(f)try{l="0"===f.stringify(0)}catch(R){l=!1}e.mix(e.namespace("JSON"),{useNativeStringify:l,dateToString:function(e){function t(e){return e<10?"0"+e:e}return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+k+t(e.getUTCMinutes())+k+t(e.getUTCSeconds())+"Z"},stringify:function(t,n,r){return f&&e.JSON.useNativeStringify?f.stringify(t,n,r):q(t,n,r)},charCacheThreshold:100})},"@VERSION@",{requires:["yui-base"]});
View
7 build/json-stringify/json-stringify.js
@@ -8,7 +8,12 @@ YUI.add('json-stringify', function (Y, NAME) {
* @for JSON
* @static
*/
-var _JSON = (Y.config.win || {}).JSON,
+// All internals kept private for security reasons
+function fromGlobal(ref) {
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
+}
+var _JSON = fromGlobal('JSON'),
Lang = Y.Lang,
isFunction= Lang.isFunction,
isObject = Lang.isObject,
View
20 src/json/HISTORY.md
@@ -1,6 +1,26 @@
JSON Utility Change History
===========================
+3.7.3
+-----
+
+* Updated to use native JSON when in Node.js
+
+3.7.2
+-----
+
+* No changes.
+
+3.7.1
+-----
+
+* No changes.
+
+3.7.0
+-----
+
+* No changes.
+
3.6.0
-----
View
11 src/json/js/parse.js
@@ -11,7 +11,7 @@
*
* <p>The <code>json</code> module is a rollup of <code>json-parse</code> and
* <code>json-stringify</code>.</p>
- *
+ *
* <p>As their names suggest, <code>json-parse</code> adds support for parsing
* JSON data (Y.JSON.parse) and <code>json-stringify</code> for serializing
* JavaScript data into JSON strings (Y.JSON.stringify). You may choose to
@@ -37,7 +37,8 @@
// All internals kept private for security reasons
function fromGlobal(ref) {
- return (Y.config.win || this || {})[ref];
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
}
@@ -107,7 +108,7 @@ var _JSON = fromGlobal('JSON'),
* @private
*/
_UNSAFE = /[^\],:{}\s]/,
-
+
/**
* Replaces specific unicode characters with their appropriate \unnnn
* format. Some browsers ignore certain characters during eval.
@@ -173,7 +174,7 @@ var _JSON = fromGlobal('JSON'),
// incorrectly by some browser implementations.
// NOTE: This modifies the input if such characters are found!
s = s.replace(_UNICODE_EXCEPTIONS, _escapeException);
-
+
// Test for any remaining invalid characters
if (!_UNSAFE.test(s.replace(_ESCAPES,'@').
replace(_VALUES,']').
@@ -186,7 +187,7 @@ var _JSON = fromGlobal('JSON'),
throw new SyntaxError('JSON.parse');
};
-
+
Y.namespace('JSON').parse = function (s,reviver) {
if (typeof s !== 'string') {
s += '';
View
7 src/json/js/stringify.js
@@ -6,7 +6,12 @@
* @for JSON
* @static
*/
-var _JSON = (Y.config.win || {}).JSON,
+// All internals kept private for security reasons
+function fromGlobal(ref) {
+ var g = ((typeof global === 'object') ? global : undefined);
+ return ((Y.UA.nodejs && g) ? g : (Y.config.win || {}))[ref];
+}
+var _JSON = fromGlobal('JSON'),
Lang = Y.Lang,
isFunction= Lang.isFunction,
isObject = Lang.isObject,
View
2  src/json/meta/json.json
@@ -5,7 +5,7 @@
"json-stringify"
],
"submodules": {
- "json-parse": { "requires": [ "yui-base" ] },
+ "json-parse": { "requires": [ "yui-base" ] },
"json-stringify": { "requires": [ "yui-base" ] }
}
}
View
18 src/json/tests/cli/lib/node.js
@@ -0,0 +1,18 @@
+YUI.add('node-tests', function (Y) {
+
+ var Assert = Y.Assert,
+ suite = new Y.Test.Suite('json Node.js tests');
+
+ suite.add(new Y.Test.Case({
+ name: 'Check native in Node.js',
+ 'should be using native parse': function() {
+ Assert.isTrue(Y.JSON.useNativeParse, 'should be true here');
+ },
+ 'should be using native stringify': function() {
+ Assert.isTrue(Y.JSON.useNativeStringify, 'should be true here');
+ }
+ }));
+
+ Y.Test.Runner.add(suite);
+
+});
View
33 src/json/tests/cli/run-json.js
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+
+process.chdir(__dirname);
+
+var YUITest = require('yuitest'),
+ path = require('path'),
+ fs = require('fs'),
+ dir = path.join(__dirname, '../../../../build-npm/'),
+ YUI = require(dir).YUI,
+ json;
+
+
+YUI({useSync: true }).use('test', function(Y) {
+ Y.Test.Runner = YUITest.TestRunner;
+ Y.Test.Case = YUITest.TestCase;
+ Y.Test.Suite = YUITest.TestSuite;
+ Y.Assert = YUITest.Assert;
+
+ Y.applyConfig({
+ modules: {
+ 'json-tests': {
+ fullpath: path.join(__dirname, '../unit/assets/json-tests.js'),
+ requires: ['json', 'test']
+ }
+ }
+ });
+
+ Y.use('json-tests');
+
+ Y.Test.Runner.setName('json cli tests');
+
+});
+
View
33 src/json/tests/cli/run-node.js
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+
+process.chdir(__dirname);
+
+var YUITest = require('yuitest'),
+ path = require('path'),
+ fs = require('fs'),
+ dir = path.join(__dirname, '../../../../build-npm/'),
+ YUI = require(dir).YUI,
+ json;
+
+
+YUI({useSync: true }).use('test', function(Y) {
+ Y.Test.Runner = YUITest.TestRunner;
+ Y.Test.Case = YUITest.TestCase;
+ Y.Test.Suite = YUITest.TestSuite;
+ Y.Assert = YUITest.Assert;
+
+ Y.applyConfig({
+ modules: {
+ 'node-tests': {
+ fullpath: path.join(__dirname, './lib/node.js'),
+ requires: ['json', 'test']
+ }
+ }
+ });
+
+ Y.use('node-tests');
+
+ Y.Test.Runner.setName('json cli tests');
+
+});
+
View
257 src/json/tests/unit/assets/json-tests.js
@@ -196,159 +196,159 @@ suite.add(new Y.Test.Case({
test_failOnEmptyString : function () {
// parse should throw an error
Y.Assert.isString(Y.JSON.parse(""));
- Y.log("Parsed empty string, but should have failed.","warn","TestRunner");
+ // Y.log("Parsed empty string, but should have failed.","warn","TestRunner");
},
test_failOnFunction : function () {
// parse should throw an error
Y.JSON.parse('{"fn":function(){}}');
- Y.log("Parsed a function, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed a function, but should have failed.","warn","TestRunner");
},
test_failOnRegex : function () {
// parse should throw an error
Y.JSON.parse('{"re":/abc/}');
- Y.log("Parsed regular expression literal, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed regular expression literal, but should have failed.","warn","TestRunner");
},
test_failOnNew : function () {
// parse should throw an error
Y.JSON.parse('{"dt":new Date()}');
- Y.log("Parsed <code>new Date()</code>, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed <code>new Date()</code>, but should have failed.","warn","TestRunner");
},
test_failOnUnquotedVal : function () {
// parse should throw an error
Y.JSON.parse('{"foo":bar}');
- Y.log("Parsed unquoted non-native value, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed unquoted non-native value, but should have failed.","warn","TestRunner");
},
test_failOnUnquotedKey : function () {
// parse should throw an error
Y.JSON.parse('{foo:1}');
- Y.log("Parsed unquoted object key, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed unquoted object key, but should have failed.","warn","TestRunner");
},
test_failOnUnclosedObject : function () {
// parse should throw an error
Y.JSON.parse('{"unclosed":"object"');
- Y.log("Parsed unclosed object, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed unclosed object, but should have failed.","warn","TestRunner");
},
test_failOnUnclosedArray : function () {
// parse should throw an error
Y.JSON.parse('["unclosed array"');
- Y.log("Parsed unclosed array, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed unclosed array, but should have failed.","warn","TestRunner");
},
test_failOnExtraCommaInObject : function () {
// JS validator will allow, FF 3.1b2 native will allow. IE8 errors.
// eval will fail in IE6-7, but pass in others
// Trailing commas are invalid, but not a security risk, so acceptable
Y.JSON.parse('{"extra":"comma",}');
- Y.log("Parsed object with extra comma, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed object with extra comma, but should have failed.","warn","TestRunner");
throw new Error("Parsed object with extra comma, but should have failed.");
},
test_failOnDoubleExtraCommaInObject : function () {
// parse should throw an error
Y.JSON.parse('{"extra":"commas",,}');
- Y.log("Parsed object with two extra commas, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed object with two extra commas, but should have failed.","warn","TestRunner");
},
test_failOnExtraCommaInArray : function () {
// Correct failure in IE6-8. FF accepts trailing commas without error
// Trailing commas are invalid, but not a security risk, so acceptable
Y.JSON.parse('["extra","comma",]');
- Y.log("Parsed array with extra comma, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed array with extra comma, but should have failed.","warn","TestRunner");
throw new Error("Parsed array with extra comma, but should have failed.");
},
test_failOnDoubleExtraCommaInArray : function () {
// Correct failure in IE6-8. FF accepts trailing commas without error
// Trailing commas are invalid, but not a security risk, so acceptable
Y.JSON.parse('["extra","commas",,]');
- Y.log("Parsed array with two extra commas, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed array with two extra commas, but should have failed.","warn","TestRunner");
throw new Error("Parsed array with two extra commas, but should have failed.");
},
test_failOnMissingValue : function () {
// Correct failure in IE6-8. FF accepts trailing commas without error
// Trailing commas are invalid, but not a security risk, so acceptable
var data = Y.JSON.parse('[,"<-- missing value"]');
- Y.log("Parsed array with missing value ("+data[0]+"), but should have failed.","warn","TestRunner");
+ //Y.log("Parsed array with missing value ("+data[0]+"), but should have failed.","warn","TestRunner");
throw new Error("Parsed array with missing value ("+data[0]+"), but should have failed.");
},
test_failOnCommaAfterClose : function () {
// parse should throw an error
Y.JSON.parse('["comma","after","close"],');
- Y.log("Parsed comma after array close, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed comma after array close, but should have failed.","warn","TestRunner");
},
test_failOnValueAfterClose : function () {
// parse should throw an error
Y.JSON.parse('{"misplaced":"value"}" after close"');
- Y.log("Parsed string value after object close, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed string value after object close, but should have failed.","warn","TestRunner");
},
test_failOnExtraClose : function () {
// parse should throw an error
var data = Y.JSON.parse('{"foo":1}}');
- Y.log("Parsed extra closing curly brace on object, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed extra closing curly brace on object, but should have failed.","warn","TestRunner");
throw new Error("Parsed extra closing curly brace on object, but should have failed.");
},
test_failOnExpression : function () {
// parse should throw an error
Y.JSON.parse('{"foo":1+2}');
- Y.log("Parsed expression, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed expression, but should have failed.","warn","TestRunner");
},
test_failOnZeroPrefixedNumber : function () {
// Correct failure in IE8. FF accepts leading zeros without error
// Leading zeros are invalid, but not a security risk, so acceptable
Y.JSON.parse('{"foo":01}');
- Y.log("Parsed zero prefixed number, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed zero prefixed number, but should have failed.","warn","TestRunner");
throw new Error("Parsed zero prefixed number, but should have failed.");
},
test_failOnHex : function () {
// parse should throw an error
Y.JSON.parse('{"foo":0x14}');
- Y.log("Parsed hex value, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed hex value, but should have failed.","warn","TestRunner");
},
test_failOnIllegalBackslashEscape : function () {
// Correctly fails in all but IE8's native parse.
// The spec does not specify a limitation to the escape characters a
// decoder supports, so either is acceptable.
var data = Y.JSON.parse('["illegal backslash escape: \\x15"]');
- Y.log("Parsed illegal backslash escape \\x15, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed illegal backslash escape \\x15, but should have failed.","warn","TestRunner");
throw new Error("Parsed illegal backslash escape \\x15, but should have failed.");
},
test_failOnMissingColon : function () {
// parse should throw an error
Y.JSON.parse('{"foo" null}');
- Y.log("Parsed object with missing colon, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed object with missing colon, but should have failed.","warn","TestRunner");
},
test_failOnDoubleColon : function () {
// parse should throw an error
Y.JSON.parse('{"foo"::1}');
- Y.log("Parsed double colon in object, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed double colon in object, but should have failed.","warn","TestRunner");
},
test_failOnCommaInsteadOfColon : function () {
// parse should throw an error
Y.JSON.parse('{"foo",1}');
- Y.log("Parsed comma in place of colon, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed comma in place of colon, but should have failed.","warn","TestRunner");
},
test_failOnColonInsteadOfComma : function () {
// parse should throw an error
Y.JSON.parse('["colon instead of":"comma"]');
- Y.log("Parsed colon in place of comma, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed colon in place of comma, but should have failed.","warn","TestRunner");
},
test_failOnSingleQuote : function () {
// parse should throw an error
Y.JSON.parse("{'foo':1}");
- Y.log("Parsed single quote, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed single quote, but should have failed.","warn","TestRunner");
},
test_failOnLineBreakChar : function () {
// FF3.1b2 currently allows linebreak chars in native implementation
// Harmless, so permissable
Y.JSON.parse("[\"line\nbreak\"]");
- Y.log("Parsed unescaped line break character, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed unescaped line break character, but should have failed.","warn","TestRunner");
throw new Error("Parsed unescaped line break character, but should have failed.");
},
test_failOnMismatchedClose : function () {
// parse should throw an error
Y.JSON.parse('["mismatched"}');
- Y.log("Parsed curly brace close for array, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed curly brace close for array, but should have failed.","warn","TestRunner");
},
test_failOnObjectInput: function () {
// parse should throw an error
Y.JSON.parse({"should": "be treated as [object Object]"});
- Y.log("Parsed object input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed object input, but should have failed.","warn","TestRunner");
},
test_arrayContainingValidJSON: function () {
// Should be ToString'ed to '{"foo":"bar"}' which is valid
@@ -360,46 +360,46 @@ suite.add(new Y.Test.Case({
test_failOnArrayInput: function () {
// parse should throw an error
Y.JSON.parse(['x', 'y']); // should be treated as "x,y");
- Y.log("Parsed array input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed array input, but should have failed.","warn","TestRunner");
},
test_failOnDateInput: function () {
// parse should throw an error
Y.JSON.parse(new Date()); // should be treated as date string
- Y.log("Parsed Date input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed Date input, but should have failed.","warn","TestRunner");
},
test_failOnRegExpInput: function () {
// parse should throw an error
Y.JSON.parse(/should fail/); // should ToString to '/should fail/'
Y.JSON.parse(/true/); // should ToString to '/true/'
- Y.log("Parsed RegExp input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed RegExp input, but should have failed.","warn","TestRunner");
},
test_failOnErrorInput: function () {
// parse should throw an error
Y.JSON.parse(new Error("Boom")); // ToString to 'Error: Boom'
Y.JSON.parse(new Error("true")); // ToString to 'Error: true'
Y.JSON.parse(new SyntaxError("true")); // ToString to 'Error: true'
- Y.log("Parsed Error input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed Error input, but should have failed.","warn","TestRunner");
},
test_failOnFunctionInput: function () {
// parse should throw an error
Y.JSON.parse(function () { return "decompiled!"; }); // ToString 'function ...'
- Y.log("Parsed function input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed function input, but should have failed.","warn","TestRunner");
},
test_failOnNaNInput: function () {
// parse should throw an error
Y.JSON.parse(NaN); // ToString to 'NaN', but not a valid JSON number
- Y.log("Parsed NaN input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed NaN input, but should have failed.","warn","TestRunner");
},
test_failOnInfinityInput: function () {
// parse should throw an error
Y.JSON.parse(Infinity); // ToString to 'Infinity', but not valid JSON
- Y.log("Parsed Infinity input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed Infinity input, but should have failed.","warn","TestRunner");
},
test_failOnUndefinedInput: function () {
// Should be ToString'ed to 'undefined'
Y.JSON.parse(undefined);
Y.JSON.parse();
- Y.log("Parsed undefined input, but should have failed.","warn","TestRunner");
+ //Y.log("Parsed undefined input, but should have failed.","warn","TestRunner");
},
test_booleanInput: function () {
// Should be ToString'ed to 'true'
@@ -517,58 +517,6 @@ suite.add(new Y.Test.Case({
}
},
- setUp: function () {
-
- // `action` is not allowed via innerHTML on Win8 apps.
- // See: http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx
-
- var f = Y.Node.one(Y.config.doc.createElement("form"));
-
- f.set("id", "testbed");
- f.setAttribute("action", "");
-
- Y.one("body").append(f);
-
- f.setHTML(
- '<p>' +
- '<input type="text" id="empty_text">' +
- '<input type="text" id="text" value="text">' +
- '<input type="radio" id="unchecked_radio" value="unchecked">' +
- '<input type="radio" id="checked_radio" value="radio" checked="checked">' +
- '<input type="checkbox" id="unchecked_box" value="unchecked">' +
- '<input type="checkbox" id="checked_box" value="box" checked="checked">' +
- '<textarea id="empty_textarea"></textarea>' +
- '<textarea id="textarea">textarea</textarea>' +
- '<select id="select">' +
- '<option value="unselected">Unselected</option>' +
- '<option value="selected" selected="selected">Selected</option>' +
- '</select>' +
- '<select id="multiple_select" multiple="multiple" size="3">' +
- '<option value="unselected">Unselected</option>' +
- '<option value="selected" selected="selected">Selected</option>' +
- '<option value="selected also" selected="selected">Selected also</option>' +
- '</select>' +
- '<button id="button" type="button">content; no value</button>' +
- '<button id="button_with_value" type="button" value="button value">content and value</button>' +
- '<button id="button_submit" type="submit">content; no value</button>' +
- '<button id="button_submit_with_value" type="submit" value="submit button value">content and value</button>' +
- '<input type="button" id="input_button" value="input button">' +
- '<input type="submit" id="input_submit" value="input submit">' +
- '</p>');
-
- // For now, setting `name` outside of innerHTML so we don't fail in Win 8 Apps.
- // TODO: Clean up based on final resolution of this: https://connect.microsoft.com/IE/feedback/details/765964/win8-app-msapphost-cannot-set-secure-valid-html-using-innerhtml-if-it-contains-form-fields-with-name-set
-
- Y.one("#unchecked_radio").setAttribute("name", "radio");
- Y.one("#checked_radio").setAttribute("name", "radio");
- Y.one("#unchecked_box").setAttribute("name", "box");
- Y.one("#checked_box").setAttribute("name", "box");
- },
-
- tearDown: function () {
- Y.one("#testbed").remove(true);
- },
-
test_stringifyNatives: function () {
Y.Assert.areSame('[true,false,null,-0.12345,"string",{"object with one member":["array with one element"]}]',
Y.JSON.stringify([true,false,null,-0.12345,"string",{"object with one member":["array with one element"]}]));
@@ -643,56 +591,95 @@ suite.add(new Y.Test.Case({
ref = d.toJSON ? d.toJSON() : "1946-07-06T00:00:00Z";
Y.Assert.areSame('{"dt":"'+ref+'"}', Y.JSON.stringify({dt : d}));
- },
-
- test_stringifyFormValue : function () {
- function $(id) { return document.getElementById(id); }
-
- var data = {
- empty_text : $('empty_text').value,
- text : $('text').value,
- unchecked_radio : $('unchecked_radio').value,
- checked_radio : $('checked_radio').value,
- unchecked_box : $('unchecked_box').value,
- checked_box : $('checked_box').value,
- empty_textarea : $('empty_textarea').value,
- textarea : $('textarea').value,
- select : $('select').value,
- multiple_select : $('multiple_select').value,
- // Buttons commented out for now because IE reports values
- // differently
- //button : $('button').value,
- //button_with_value : $('button_with_value').value,
- //button_submit : $('button_submit').value,
- //button_submit_with_value: $('button_submit_with_value').value,
- input_button : $('input_button').value,
- input_submit : $('input_submit').value//,
- //input_image : $('input_image').value
- };
-
- Y.Assert.areSame('{'+
- '"empty_text":"",'+
- '"text":"text",'+
- '"unchecked_radio":"unchecked",'+
- '"checked_radio":"radio",'+
- '"unchecked_box":"unchecked",'+
- '"checked_box":"box",'+
- '"empty_textarea":"",'+
- '"textarea":"textarea",'+
- '"select":"selected",'+
- '"multiple_select":"selected",'+
- //'"button":"",'+
- //'"button_with_value":"button value",'+
- //'"button_submit":"",'+
- //'"button_submit_with_value":"submit button value",'+
- '"input_button":"input button",'+
- '"input_submit":"input submit"}',
- //'"input_image":"input image"}',
- Y.JSON.stringify(data));
}
-
}));
+//Don't add the test if win and doc are not available
+if (Y.config.win && Y.config.doc) {
+ suite.add(new Y.Test.Case({
+ name: "DOM based tests",
+ setUp: function () {
+ Y.one("body").append('<form id="testbed" action="">' +
+ '<h3>Form used for field value extraction, stringification</h3>' +
+ '<input type="text" id="empty_text">' +
+ '<input type="text" id="text" value="text">' +
+ '<input type="radio" name="radio" id="unchecked_radio" value="unchecked">' +
+ '<input type="radio" name="radio" id="checked_radio" value="radio" checked="checked">' +
+ '<input type="checkbox" name="box" id="unchecked_box" value="unchecked">' +
+ '<input type="checkbox" name="box" id="checked_box" value="box" checked="checked">' +
+ '<textarea id="empty_textarea"></textarea>' +
+ '<textarea id="textarea">textarea</textarea>' +
+ '<select id="select">' +
+ '<option value="unselected">Unselected</option>' +
+ '<option value="selected" selected="selected">Selected</option>' +
+ '</select>' +
+ '<select id="multiple_select" multiple="multiple" size="3">' +
+ '<option value="unselected">Unselected</option>' +
+ '<option value="selected" selected="selected">Selected</option>' +
+ '<option value="selected also" selected="selected">Selected also</option>' +
+ '</select>' +
+ '<button id="button" type="button">content; no value</button>' +
+ '<button id="button_with_value" type="button" value="button value">content and value</button>' +
+ '<button id="button_submit" type="submit">content; no value</button>' +
+ '<button id="button_submit_with_value" type="submit" value="submit button value">content and value</button>' +
+ '<input type="button" id="input_button" value="input button">' +
+ '<input type="submit" id="input_submit" value="input submit">' +
+ '<!--input type="image" id="input_image" src="404.png" value="input image"-->' +
+ '</form>');
+ },
+
+ tearDown: function () {
+ Y.one("#testbed").remove(true);
+ },
+
+ test_stringifyFormValue : function () {
+ function $(id) { return document.getElementById(id); }
+
+ var data = {
+ empty_text : $('empty_text').value,
+ text : $('text').value,
+ unchecked_radio : $('unchecked_radio').value,
+ checked_radio : $('checked_radio').value,
+ unchecked_box : $('unchecked_box').value,
+ checked_box : $('checked_box').value,
+ empty_textarea : $('empty_textarea').value,
+ textarea : $('textarea').value,
+ select : $('select').value,
+ multiple_select : $('multiple_select').value,
+ // Buttons commented out for now because IE reports values
+ // differently
+ //button : $('button').value,
+ //button_with_value : $('button_with_value').value,
+ //button_submit : $('button_submit').value,
+ //button_submit_with_value: $('button_submit_with_value').value,
+ input_button : $('input_button').value,
+ input_submit : $('input_submit').value//,
+ //input_image : $('input_image').value
+ };
+
+ Y.Assert.areSame('{'+
+ '"empty_text":"",'+
+ '"text":"text",'+
+ '"unchecked_radio":"unchecked",'+
+ '"checked_radio":"radio",'+
+ '"unchecked_box":"unchecked",'+
+ '"checked_box":"box",'+
+ '"empty_textarea":"",'+
+ '"textarea":"textarea",'+
+ '"select":"selected",'+
+ '"multiple_select":"selected",'+
+ //'"button":"",'+
+ //'"button_with_value":"button value",'+
+ //'"button_submit":"",'+
+ //'"button_submit_with_value":"submit button value",'+
+ '"input_button":"input button",'+
+ '"input_submit":"input submit"}',
+ //'"input_image":"input image"}',
+ Y.JSON.stringify(data));
+ }
+ }));
+}
+
suite.add(new Y.Test.Case({
name : "whitelist",
Please sign in to comment.
Something went wrong with that request. Please try again.