From ad6079cbd8dc362a3cc42e1f97c01aa5ccd48bfe Mon Sep 17 00:00:00 2001 From: Douglas Crockford Date: Wed, 23 Feb 2011 13:54:25 -0800 Subject: [PATCH] Style conformance. --- cycle.js | 24 ++++++++++++++---------- json.js | 6 +++--- json2.js | 10 +++++----- json_parse.js | 7 ++++--- json_parse_state.js | 9 +++++---- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/cycle.js b/cycle.js index c5ef2a8..b6fa7dd 100755 --- a/cycle.js +++ b/cycle.js @@ -1,7 +1,7 @@ // cycle.js -// 2011-01-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,7 +75,7 @@ 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) + ']'); } @@ -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 @@ -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 4018ed0..ef5f30e 100755 --- a/json.js +++ b/json.js @@ -1,6 +1,6 @@ /* json.js - 2011-01-18 + 2011-02-23 Public Domain @@ -365,7 +365,7 @@ if (!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); @@ -450,7 +450,7 @@ if (!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; diff --git a/json2.js b/json2.js index 36d3dc3..b4c02d3 100755 --- a/json2.js +++ b/json2.js @@ -1,6 +1,6 @@ /* http://www.JSON.org/json2.js - 2011-01-18 + 2011-02-23 Public Domain. @@ -315,8 +315,8 @@ if (!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); @@ -328,7 +328,7 @@ if (!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); @@ -413,7 +413,7 @@ if (!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; diff --git a/json_parse.js b/json_parse.js index c712d37..5a8a8ef 100755 --- a/json_parse.js +++ b/json_parse.js @@ -1,6 +1,6 @@ /* http://www.JSON.org/json_parse.js - 2011-01-18 + 2011-02-23 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 @@ -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 f474805..75414a2 100755 --- a/json_parse_state.js +++ b/json_parse_state.js @@ -1,6 +1,6 @@ /* http://www.JSON.org/json_parse_state.js - 2011-01-18 + 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;