diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-03-13 19:24:08 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-03-13 19:24:08 +0000 |
commit | a1581d7fde2b8663ad07a2d3d675776164369f26 (patch) | |
tree | 3e1e70b51aa3b64babf62363e1763cb2be08a2a3 /sca-cpp/trunk/modules/js/htdocs/util.js | |
parent | d1d9ba0e29baed02a052dae81b049d00a1454bf8 (diff) |
Add Javascript functions and test cases to help work with JSON.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1081204 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/js/htdocs/util.js')
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/util.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js index 20af741c6d..512e3c26d5 100644 --- a/sca-cpp/trunk/modules/js/htdocs/util.js +++ b/sca-cpp/trunk/modules/js/htdocs/util.js @@ -72,6 +72,13 @@ function reverse(l) { return l.slice(0).reverse(); } +function range(a, b) { + var l = new Array(); + for (var x = a; x < b; x++) + l.push(x); + return l; +} + function isNil(v) { if (v == null || typeof v == 'undefined' || (v.constructor == Array && v.length == 0)) return true; @@ -85,7 +92,7 @@ function isSymbol(v) { } function isString(v) { - if (typeof v == 'string') + if (typeof v == 'string' && v.slice(0, 1) != "'") return true; return false; } @@ -199,6 +206,21 @@ function debug(o) { } /** + * Simple assert function. + */ +function AssertException() { +} + +AssertException.prototype.toString = function () { + return 'AssertException'; +}; + +function assert(exp) { + if (!exp) + throw new AssertException(); +} + +/** * Write a list of strings. */ function writeStrings(l) { @@ -252,6 +274,16 @@ function unmemo(obj) { } /** + * Returns a list of the properties of an object. + */ +function properties(o) { + var a = new Array(); + for (p in o) + a.push(p); + return a; +} + +/** * Functions with side effects. Use with moderation. */ |