***SPAM*** [OpenSRF-GIT] OpenSRF branch master updated. 6c3b1001c6183b2f633d0f43ccd3d28071c0c48d

Evergreen Git git at git.evergreen-ils.org
Wed Aug 20 16:57:55 EDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".

The branch, master has been updated
       via  6c3b1001c6183b2f633d0f43ccd3d28071c0c48d (commit)
      from  2677f8e815a61f9b808bb57647f6ec9d448f0268 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6c3b1001c6183b2f633d0f43ccd3d28071c0c48d
Author: Bill Erickson <berick at esilibrary.com>
Date:   Mon May 5 13:40:46 2014 -0400

    LP#1316245: JS now uses browser-native JSON routines
    
    * Replace JSON2jsRaw() with JSON.parse()
    
    * Replace js2JSONRaw() with JSON.stringify()
    
    * Removed unit tests for JSON2jsRaw() and js2JSONRaw()
    
    * Removed jsonPretty() pretty-printing routine.  Use
      JSON.stringify(json, null, <spaces>) instead.
    
    See also:
    
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>

diff --git a/src/javascript/JSON_v1.js b/src/javascript/JSON_v1.js
index 37ff048..3148a50 100644
--- a/src/javascript/JSON_v1.js
+++ b/src/javascript/JSON_v1.js
@@ -6,18 +6,11 @@ var JSON_DATA_KEY    = '__p';
 function JSON_version() { return 'wrapper'; }
 
 function JSON2js(text) {
-    return decodeJS(JSON2jsRaw(text));
+    return decodeJS(JSON.parse(text));
 }
 
 JSON2js.fallbackObjectifier = null;
 
-function JSON2jsRaw(text) {
-    var obj;
-    eval('obj = ' + text);
-    return obj;
-}
-
-
 /* iterates over object, arrays, or fieldmapper objects */
 function jsIterate( arg, callback ) {
     if( arg && typeof arg == 'object' ) {
@@ -132,90 +125,5 @@ function encodeJS(arg) {
 
 /* turns a javascript object into a JSON string */
 function js2JSON(arg) {
-    return js2JSONRaw(encodeJS(arg));
+    return JSON.stringify(encodeJS(arg));
 }
-
-function js2JSONRaw(arg) {
-
-    if( arg == null ) 
-        return 'null';
-
-    var o;
-
-    switch (typeof arg) {
-
-        case 'object':
-
-            if (arg.constructor == Array) {
-                o = '';
-                jsIterate( arg,
-                    function(obj, i) {
-                        if (o) o += ',';
-                        o += js2JSONRaw(obj[i]);
-                    }
-                );
-                return '[' + o + ']';
-
-            } else if (typeof arg.toString != 'undefined') {
-                o = '';
-                jsIterate( arg,
-                    function(obj, i) {
-                        if (o) o += ',';
-                        o = o + js2JSONRaw(i) + ':' + js2JSONRaw(obj[i]);
-                    }
-                );
-                return '{' + o + '}';
-
-            }
-
-            return 'null';
-
-        case 'number': return arg;
-
-        case 'string':
-            var s = String(arg);
-            s = s.replace(/\\/g, '\\\\');
-            s = s.replace(/"/g, '\\"');
-            s = s.replace(/\t/g, "\\t");
-            s = s.replace(/\n/g, "\\n");
-            s = s.replace(/\r/g, "\\r");
-            s = s.replace(/\f/g, "\\f");
-            return '"' + s + '"';
-
-        case 'boolean':
-            return (arg) ? 'true' : 'false';
-
-        default: return 'null';
-    }
-}
-
-
-function __tabs(c) { 
-    var s = ''; 
-    for( i = 0; i < c; i++ ) s += '\t';
-    return s;
-}
-
-function jsonPretty(str) {
-    if(!str) return "";
-    var s = '';
-    var d = 0;
-    for( var i = 0; i < str.length; i++ ) {
-        var c = str.charAt(i);
-        if( c == '{' || c == '[' ) {
-            s += c + '\n' + __tabs(++d);
-        } else if( c == '}' || c == ']' ) {
-            s += '\n' + __tabs(--d) + '\n';
-            if( str.charAt(i+1) == ',' ) {
-                s += '\n' + __tabs(d);
-            }
-        } else if( c == ',' ) {
-            s += ',\n' + __tabs(d);
-        } else {
-            s += c;
-        }
-    }
-    return s;
-}
-
-
diff --git a/src/javascript/tests/testJSON_v1.js b/src/javascript/tests/testJSON_v1.js
index 9530fa0..9039444 100644
--- a/src/javascript/tests/testJSON_v1.js
+++ b/src/javascript/tests/testJSON_v1.js
@@ -45,66 +45,6 @@ doh.register("JSONTests", [
         // Order of object attributes is not guaranteed
         doh.assertTrue(js2JSON({"foo":{"one":[null,"two",2]}}) == '{"foo":{"one":[null,"two",2]}}');
     },
-    function test_js2JSONRaw_strict() {
-        // Solo nulls and booleans are stringified XXX
-        doh.assertTrue(js2JSONRaw(null) === "null");
-        doh.assertTrue(js2JSONRaw(true) === "true");
-        doh.assertTrue(js2JSONRaw(false) === "false");
-    },
-    function test_js2JSONRaw_numbers() {
-        doh.assertTrue(js2JSONRaw(0) === 0);
-        doh.assertTrue(js2JSONRaw(1.5) === 1.5);
-        doh.assertTrue(js2JSONRaw(.7) === .7);
-    },
-    function test_js2JSONRaw_strings() {
-        doh.assertTrue(js2JSONRaw("") == '""');
-        doh.assertTrue(js2JSONRaw("foo") == '"foo"');
-        // Escape sequences
-        doh.assertTrue(js2JSONRaw("foo\n\t\n") == '"foo\\n\\t\\n"');
-    },
-    function test_js2JSONRaw_arrays() {
-        doh.assertTrue(js2JSONRaw([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
-    },
-    function test_js2JSONRaw_objects() {
-        doh.assertTrue(js2JSONRaw({"foo":"bar"}) == '{"foo":"bar"}');
-        doh.assertTrue(js2JSONRaw({"foo":true}) == '{"foo":true}');
-        doh.assertTrue(js2JSONRaw({"foo":0}) == '{"foo":0}');
-    },
-    function test_js2JSONRaw_objects_ordered() {
-        // Order of object attributes is not guaranteed
-        doh.assertTrue(js2JSONRaw({"foo":{"one":[null,"two",2]}}) == '{"foo":{"one":[null,"two",2]}}');
-    },
-    function test_JSON2jsRaw_strict() {
-        // Standalone quoted nulls and booleans are converted to primitives
-        doh.assertTrue(JSON2jsRaw(null) === null);
-        doh.assertTrue(JSON2jsRaw("null") === null);
-        doh.assertTrue(JSON2jsRaw(true) === true);
-        doh.assertTrue(JSON2jsRaw("true") === true);
-        doh.assertTrue(JSON2jsRaw(false) === false);
-        doh.assertTrue(JSON2jsRaw("false") === false);
-    },
-    function test_JSON2jsRaw_numbers() {
-        // Zero is zero and only zero
-        doh.assertTrue(JSON2jsRaw(0) === 0);
-        doh.assertTrue(JSON2jsRaw(1.5) === 1.5);
-        doh.assertTrue(JSON2jsRaw(.5) === .5);
-    },
-    function test_JSON2jsRaw_strings() {
-        // Empty string
-        doh.assertTrue(JSON2jsRaw('""') === "");
-        // String
-        doh.assertTrue(JSON2jsRaw('"foo"') == "foo");
-    },
-    function test_JSON2jsRaw_arrays() {
-        // Array; access an index
-        doh.assertTrue(JSON2jsRaw('[0,1,2,3,4,5]')[1] == 1);
-    },
-    function test_JSON2jsRaw_objects() {
-        // Object; access a key
-        doh.assertTrue(JSON2jsRaw('{"foo":"bar"}').foo == "bar");
-        doh.assertTrue(JSON2jsRaw('{"foo":{"two":2,"one":null}}').foo.one === null);
-        doh.assertTrue(JSON2jsRaw('{"foo":{"two":2,"one":"null"}}').foo.one === "null");
-    },
     function test_JSON2js_strict() {
         // Standalone quoted nulls and booleans are converted to primitives
         doh.assertTrue(JSON2js(null) === null);

-----------------------------------------------------------------------

Summary of changes:
 src/javascript/JSON_v1.js           |   96 +----------------------------------
 src/javascript/tests/testJSON_v1.js |   60 ----------------------
 2 files changed, 2 insertions(+), 154 deletions(-)


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list