[Pkg-javascript-commits] [json-js] 12/85: Imported Upstream version 0~20110315
Jonas Smedegaard
dr at jones.dk
Mon Mar 14 10:39:14 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository json-js.
commit 9a3d8a8cb8a46d15fae3a383c6aeed6178adf9b4
Author: dr at jones.dk <dr at jones.dk>
Date: Fri Apr 22 12:22:11 2011 +0200
Imported Upstream version 0~20110315
---
cycle.js | 28 +++++++++--------
json.js | 86 +++++++++++++++++++++++++----------------------------
json2.js | 71 +++++++++++++++++++++----------------------
json_parse.js | 9 +++---
json_parse_state.js | 9 +++---
5 files changed, 101 insertions(+), 102 deletions(-)
diff --git a/cycle.js b/cycle.js
index a6e0fa5..b6fa7dd 100755
--- a/cycle.js
+++ b/cycle.js
@@ -1,7 +1,7 @@
// cycle.js
-// 2010-11-18
+// 2011-02-23
-/*jslint forin: true, evil: true */
+/*jslint evil: true, regexp: false */
/*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
retrocycle, stringify, test, toString
@@ -9,6 +9,7 @@
if (typeof JSON.decycle !== 'function') {
JSON.decycle = function decycle(object) {
+ "use strict";
// Make a deep copy of an object or array, assuring that there is at most
// one instance of each object or array in the resulting structure. The
@@ -74,9 +75,9 @@ if (typeof JSON.decycle !== 'function') {
nu = {};
for (name in value) {
- if (Object.hasOwnProperty.call(value, name)) {
+ if (Object.prototype.hasOwnProperty.call(value, name)) {
nu[name] = derez(value[name],
- path + '[' + JSON.stringify(name) + ']');
+ path + '[' + JSON.stringify(name) + ']');
}
}
}
@@ -93,6 +94,7 @@ if (typeof JSON.decycle !== 'function') {
if (typeof JSON.retrocycle !== 'function') {
JSON.retrocycle = function retrocycle($) {
+ "use strict";
// Restore an object that was reduced by decycle. Members whose values are
// objects of the form
@@ -114,7 +116,7 @@ if (typeof JSON.retrocycle !== 'function') {
// produces an array containing a single element which is the array itself.
var px =
-/^\$(?:\[(?:\d?|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
+ /^\$(?:\[(?:\d?|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
(function rez(value) {
@@ -140,13 +142,15 @@ if (typeof JSON.retrocycle !== 'function') {
}
} else {
for (name in value) {
- item = value[name];
- if (item && typeof item === 'object') {
- path = item.$ref;
- if (typeof path === 'string' && px.test(path)) {
- value[name] = eval(path);
- } else {
- rez(item);
+ if (typeof value[name] === 'object') {
+ item = value[name];
+ if (item) {
+ path = item.$ref;
+ if (typeof path === 'string' && px.test(path)) {
+ value[name] = eval(path);
+ } else {
+ rez(item);
+ }
}
}
}
diff --git a/json.js b/json.js
index ea2377f..ef5f30e 100755
--- a/json.js
+++ b/json.js
@@ -1,6 +1,6 @@
/*
json.js
- 2010-12-08
+ 2011-02-23
Public Domain
@@ -196,8 +196,9 @@
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
-if (!this.JSON) {
- this.JSON = {};
+var JSON;
+if (!JSON) {
+ JSON = {};
}
(function () {
@@ -213,19 +214,19 @@ if (!this.JSON) {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf()) ?
- this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z' : null;
+ this.getUTCFullYear() + '-' +
+ f(this.getUTCMonth() + 1) + '-' +
+ f(this.getUTCDate()) + 'T' +
+ f(this.getUTCHours()) + ':' +
+ f(this.getUTCMinutes()) + ':' +
+ f(this.getUTCSeconds()) + 'Z' : null;
};
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function (key) {
- return this.valueOf();
- };
+ String.prototype.toJSON =
+ Number.prototype.toJSON =
+ Boolean.prototype.toJSON = function (key) {
+ return this.valueOf();
+ };
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
@@ -252,13 +253,11 @@ if (!this.JSON) {
// sequences.
escapable.lastIndex = 0;
- return escapable.test(string) ?
- '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' :
- '"' + string + '"';
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
+ var c = meta[a];
+ return typeof c === 'string' ? c :
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
+ }) + '"' : '"' + string + '"';
}
@@ -341,11 +340,9 @@ if (!this.JSON) {
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
- v = partial.length === 0 ? '[]' :
- gap ? '[\n' + gap +
- partial.join(',\n' + gap) + '\n' +
- mind + ']' :
- '[' + partial.join(',') + ']';
+ v = partial.length === 0 ? '[]' : gap ?
+ '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
+ '[' + partial.join(',') + ']';
gap = mind;
return v;
}
@@ -368,7 +365,7 @@ if (!this.JSON) {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -380,9 +377,9 @@ if (!this.JSON) {
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
- v = partial.length === 0 ? '{}' :
- gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
- mind + '}' : '{' + partial.join(',') + '}';
+ v = partial.length === 0 ? '{}' : gap ?
+ '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
+ '{' + partial.join(',') + '}';
gap = mind;
return v;
}
@@ -423,7 +420,7 @@ if (!this.JSON) {
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
- typeof replacer.length !== 'number')) {
+ typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
@@ -453,7 +450,7 @@ if (!this.JSON) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
@@ -494,9 +491,9 @@ if (!this.JSON) {
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/
-.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
-.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
-.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
@@ -517,18 +514,17 @@ if (!this.JSON) {
throw new SyntaxError('JSON.parse');
};
}
-}());
-
// Augment the basic prototypes if they have not already been augmented.
// These forms are obsolete. It is recommended that JSON.stringify and
// JSON.parse be used instead.
-if (!Object.prototype.toJSONString) {
- Object.prototype.toJSONString = function (filter) {
- return JSON.stringify(this, filter);
- };
- Object.prototype.parseJSON = function (filter) {
- return JSON.parse(this, filter);
- };
-}
+ if (!Object.prototype.toJSONString) {
+ Object.prototype.toJSONString = function (filter) {
+ return JSON.stringify(this, filter);
+ };
+ Object.prototype.parseJSON = function (filter) {
+ return JSON.parse(this, filter);
+ };
+ }
+}());
diff --git a/json2.js b/json2.js
index 22b44d9..b4c02d3 100755
--- a/json2.js
+++ b/json2.js
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
- 2010-11-17
+ 2011-02-23
Public Domain.
@@ -159,8 +159,9 @@
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
-if (!this.JSON) {
- this.JSON = {};
+var JSON;
+if (!JSON) {
+ JSON = {};
}
(function () {
@@ -176,19 +177,19 @@ if (!this.JSON) {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf()) ?
- this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z' : null;
+ this.getUTCFullYear() + '-' +
+ f(this.getUTCMonth() + 1) + '-' +
+ f(this.getUTCDate()) + 'T' +
+ f(this.getUTCHours()) + ':' +
+ f(this.getUTCMinutes()) + ':' +
+ f(this.getUTCSeconds()) + 'Z' : null;
};
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function (key) {
- return this.valueOf();
- };
+ String.prototype.toJSON =
+ Number.prototype.toJSON =
+ Boolean.prototype.toJSON = function (key) {
+ return this.valueOf();
+ };
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
@@ -215,13 +216,11 @@ if (!this.JSON) {
// sequences.
escapable.lastIndex = 0;
- return escapable.test(string) ?
- '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' :
- '"' + string + '"';
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
+ var c = meta[a];
+ return typeof c === 'string' ? c :
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
+ }) + '"' : '"' + string + '"';
}
@@ -304,11 +303,9 @@ if (!this.JSON) {
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
- v = partial.length === 0 ? '[]' :
- gap ? '[\n' + gap +
- partial.join(',\n' + gap) + '\n' +
- mind + ']' :
- '[' + partial.join(',') + ']';
+ v = partial.length === 0 ? '[]' : gap ?
+ '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
+ '[' + partial.join(',') + ']';
gap = mind;
return v;
}
@@ -318,8 +315,8 @@ if (!this.JSON) {
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
- k = rep[i];
- if (typeof k === 'string') {
+ if (typeof rep[i] === 'string') {
+ k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -331,7 +328,7 @@ if (!this.JSON) {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -343,9 +340,9 @@ if (!this.JSON) {
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
- v = partial.length === 0 ? '{}' :
- gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
- mind + '}' : '{' + partial.join(',') + '}';
+ v = partial.length === 0 ? '{}' : gap ?
+ '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
+ '{' + partial.join(',') + '}';
gap = mind;
return v;
}
@@ -386,7 +383,7 @@ if (!this.JSON) {
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
- typeof replacer.length !== 'number')) {
+ typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
@@ -416,7 +413,7 @@ if (!this.JSON) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
@@ -457,9 +454,9 @@ if (!this.JSON) {
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/
-.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
-.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
-.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
diff --git a/json_parse.js b/json_parse.js
index ca120c5..6c3ccbf 100755
--- a/json_parse.js
+++ b/json_parse.js
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse.js
- 2009-05-31
+ 2011-03-06
Public Domain.
@@ -47,10 +47,11 @@
*/
/*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode,
- hasOwnProperty, message, n, name, push, r, t, text
+ hasOwnProperty, message, n, name, prototype, push, r, t, text
*/
var json_parse = (function () {
+ "use strict";
// This is a function that can parse a JSON text, producing a JavaScript
// data structure. It is a simple, recursive descent parser. It does not use
@@ -136,7 +137,7 @@ var json_parse = (function () {
}
}
number = +string;
- if (isNaN(number)) {
+ if (!isFinite(number)) {
error("Bad number");
} else {
return number;
@@ -329,7 +330,7 @@ var json_parse = (function () {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
diff --git a/json_parse_state.js b/json_parse_state.js
index a2a9ea7..75414a2 100755
--- a/json_parse_state.js
+++ b/json_parse_state.js
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse_state.js
- 2009-05-31
+ 2011-02-23
Public Domain.
@@ -51,11 +51,12 @@
/*members "", "\"", ",", "\/", ":", "[", "\\", "]", acomma, avalue, b,
call, colon, container, exec, f, false, firstavalue, firstokey,
fromCharCode, go, hasOwnProperty, key, length, n, null, ocomma, okey,
- ovalue, pop, push, r, replace, slice, state, t, test, true, value, "{",
- "}"
+ ovalue, pop, prototype, push, r, replace, slice, state, t, test, true,
+ value, "{", "}"
*/
var json_parse = (function () {
+ "use strict";
// This function creates a JSON parse function that uses a state machine rather
// than the dangerous eval function to parse a JSON text.
@@ -380,7 +381,7 @@ var json_parse = (function () {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
- if (Object.hasOwnProperty.call(value, k)) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/json-js.git
More information about the Pkg-javascript-commits
mailing list