svn commit: samba r9174 - in branches/SAMBA_4_0/source/scripting/libjs: .

tridge at samba.org tridge at samba.org
Sun Aug 7 06:19:18 GMT 2005


Author: tridge
Date: 2005-08-07 06:19:17 +0000 (Sun, 07 Aug 2005)
New Revision: 9174

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9174

Log:
ejs does not include the special variable 'length' in for loops over objects,
so we need to check for it separately in the object lineariser


Modified:
   branches/SAMBA_4_0/source/scripting/libjs/encoder.js


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/libjs/encoder.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/encoder.js	2005-08-07 06:16:32 UTC (rev 9173)
+++ branches/SAMBA_4_0/source/scripting/libjs/encoder.js	2005-08-07 06:19:17 UTC (rev 9174)
@@ -21,6 +21,9 @@
 	for (i in o) { 
 		count++;  
 	}
+	if (o.length != undefined) {
+		count++;
+	}
 	return count;
 }
 
@@ -31,29 +34,40 @@
 	return s.join(rep, a);
 }
 
+function encodeElement(e, name) {
+	var t = typeof(e);
+	var r;
+	var s = string_init();
+	if (t == 'object' && e == null) {
+		t = 'null';
+	}
+	if (t == 'object') {
+		r = s.sprintf("%s:%s:%s", name, t, encodeObject(e));
+	} else if (t == "string") {
+		var enc = s.encodeURIComponent(e);
+		var rep = __replace(enc, '%', '#');
+		r = s.sprintf("%s:%s:%s:", 
+			      name, t, __replace(s.encodeURIComponent(e),'%','#'));
+	} else if (t == "boolean" || t == "number") {
+		r = s.sprintf("%s:%s:%s:", name, t, "" + e);
+	} else if (t == "undefined" || t == "null") {
+		r = s.sprintf("%s:%s:", name, t);
+	} else {
+		println("Unable to linearise type " + t);
+		r = "";
+	}
+	return r;
+}
+
 function encodeObject(o) {
 	var s = string_init();
 	var i, r = s.sprintf("%u:", __count_members(o));
 	for (i in o) {
-		var t = typeof(o[i]);
-		if (t == 'object' && o[i] == null) {
-			t = 'null';
-		}
-		if (t == 'object') {
-			r = s.sprintf("%s%s:%s:%s", r, i, t, encodeObject(o[i]));
-		} else if (t == "string") {
-			var enc = s.encodeURIComponent(o[i]);
-			var rep = __replace(enc, '%', '#');
-			r = s.sprintf("%s%s:%s:%s:", 
-				      r, i, t, __replace(s.encodeURIComponent(o[i]),'%','#'));
-		} else if (t == "boolean" || t == "number") {
-			r = s.sprintf("%s%s:%s:%s:", r, i, t, "" + o[i]);
-		} else if (t == "undefined" || t == "null") {
-			r = s.sprintf("%s%s:%s:", r, i, t);
-		} else {
-			println("Unable to linearise type " + t);
-		}
+		r = r + encodeElement(o[i], i);
 	}
+	if (o.length != undefined) {
+		r = r + encodeElement(o.length, 'length');
+	}
 	return r;
 }
 



More information about the samba-cvs mailing list