added test case and fix for records contained in arrays
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@980253 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index 5e9c89e..04a34d1 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -54,7 +54,7 @@
}
-Thrift.TApplicationException = {
+Thrift.TApplicationExceptionType = {
"UNKNOWN" : 0,
"UNKNOWN_METHOD" : 1,
"INVALID_MESSAGE_TYPE" : 2,
@@ -401,7 +401,9 @@
var p = this.tpos.pop()
while( this.tstack.length > p+1 ){
- this.tstack[p].push(this.tstack.pop())
+ var tmpVal = this.tstack[p+1]
+ this.tstack.splice(p+1, 1)
+ this.tstack[p].push(tmpVal)
}
this.tstack[p] = '['+this.tstack[p].join(",")+']';
@@ -416,7 +418,9 @@
var p = this.tpos.pop()
while( this.tstack.length > p+1 ){
- this.tstack[p].push(this.tstack.pop())
+ var tmpVal = this.tstack[p+1]
+ this.tstack.splice(p+1, 1)
+ this.tstack[p].push(tmpVal)
}
this.tstack[p] = '['+this.tstack[p].join(",")+']';
@@ -486,13 +490,19 @@
},
readStructBegin : function(name){
- var r = {};
- r["fname"] = '';
-
- return r;
+ var r = {}
+ r["fname"] = ''
+
+ //incase this is an array of structs
+ if(this.rstack[this.rstack.length-1] instanceof Array)
+ this.rstack.push(this.rstack[this.rstack.length-1].shift())
+
+ return r
},
readStructEnd : function(){
+ if(this.rstack[this.rstack.length-2] instanceof Array)
+ this.rstack.pop()
},
readFieldBegin : function(){
@@ -578,8 +588,7 @@
this.rpos.push(this.rstack.length);
this.rstack.push(list)
-
-
+
return r;
},
@@ -616,19 +625,24 @@
},
- readI32 : function(){
- var f = this.rstack[this.rstack.length-1]
+ readI32 : function(f){
+ if(f == undefined)
+ f = this.rstack[this.rstack.length-1]
+
var r = {}
if(f instanceof Array){
- r["value"] = f.pop()
-
+ if(f.length == 0)
+ r["value"] = undefined
+ else
+ r["value"] = f.shift()
+
}else if(f instanceof Object){
for(var i in f){
if(i == null) continue
this.rstack.push(f[i])
delete f[i]
-
+
r["value"] = i
break
}
@@ -636,7 +650,6 @@
r["value"] = f
}
-
return r
},