Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

throw Error, not string

  • Loading branch information...
commit 7533fd0e0846f5db2740ca5628ab3d46c39a701f 1 parent 51a105e
bitmage authored
Showing with 19 additions and 5 deletions.
  1. +19 −5 index.js
24 index.js
View
@@ -60,9 +60,12 @@ var EasyXml = function() {
* Public
* Takes an object and returns an XML string
*/
- self.render = function(object, rootElementOverride) {
+ self.render = function(object, rootElementOverride, done) {
var xml = element(rootElementOverride || self.config.rootElement);
+ if (done && typeof done == 'function') {
+ }
+
parseChildElement(xml, object);
return new ElementTree(xml).write({
@@ -75,7 +78,18 @@ var EasyXml = function() {
* Recursive, Private
* Takes an object and attaches it to the XML doc
*/
- function parseChildElement(parentXmlNode, parentObjectNode) {
+ function parseChildElement(parentXmlNode, parentObjectNode, next) {
+
+ // if we have a callback then allow the event loop to run between recursions
+ if (next) {
+ recurse = function (xml, obj, cb) {
+ process.nextTick(function () {
+ parseChildElement(xml, obj, cb);
+ });
+ }
+ else recurse = parseChildElement;
+ }
+
for (var key in parentObjectNode) {
if (parentObjectNode.hasOwnProperty(key)) {
var child = parentObjectNode[key];
@@ -86,7 +100,7 @@ var EasyXml = function() {
if (typeof child === 'string' || typeof child === 'number') {
parentXmlNode.set(key.substring(1), child);
} else {
- throw("non_string_attribute");
+ throw new Error("non_string_attribute");
}
} else if (child === null) {
// Null data, send an empty tag
@@ -111,7 +125,7 @@ var EasyXml = function() {
// JavaScript date format
el.text = child.toString();
} else {
- throw("unknown_date_format");
+ throw new Error("unknown_date_format");
}
} else if (typeof child === 'object' && child.constructor && child.constructor.name && child.constructor.name === 'Array') {
// Array
@@ -140,7 +154,7 @@ var EasyXml = function() {
el = subElement(parentXmlNode, key);
el.text = child.toString();
} else {
- throw("unknown_data_type");
+ throw new Error("unknown_data_type");
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.