Skip to content

Commit

Permalink
Merge branch 'json'
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Oct 6, 2012
2 parents d7fa399 + 7b3762d commit f968f0f
Show file tree
Hide file tree
Showing 16 changed files with 414 additions and 276 deletions.
88 changes: 45 additions & 43 deletions build/json-parse/json-parse-coverage.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions build/json-parse/json-parse-debug.js
Expand Up @@ -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
Expand All @@ -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];
}


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,']').
Expand All @@ -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 += '';
Expand Down
2 changes: 1 addition & 1 deletion build/json-parse/json-parse-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions build/json-parse/json-parse.js
Expand Up @@ -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
Expand All @@ -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];
}


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,']').
Expand All @@ -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 += '';
Expand Down
199 changes: 104 additions & 95 deletions build/json-stringify/json-stringify-coverage.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion build/json-stringify/json-stringify-debug.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion build/json-stringify/json-stringify-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion build/json-stringify/json-stringify.js
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions 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
-----

Expand Down
11 changes: 6 additions & 5 deletions src/json/js/parse.js
Expand Up @@ -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
Expand All @@ -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];
}


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,']').
Expand All @@ -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 += '';
Expand Down
7 changes: 6 additions & 1 deletion src/json/js/stringify.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/json/meta/json.json
Expand Up @@ -5,7 +5,7 @@
"json-stringify"
],
"submodules": {
"json-parse": { "requires": [ "yui-base" ] },
"json-parse": { "requires": [ "yui-base" ] },
"json-stringify": { "requires": [ "yui-base" ] }
}
}
Expand Down
18 changes: 18 additions & 0 deletions 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);

});
33 changes: 33 additions & 0 deletions 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');

});

33 changes: 33 additions & 0 deletions 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');

});

0 comments on commit f968f0f

Please sign in to comment.