From efabb89c75169611801330b71b5fd230d46f8128 Mon Sep 17 00:00:00 2001 From: T Jake Luciani Date: Wed, 28 Jul 2010 22:31:12 +0000 Subject: [PATCH] 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 --- lib/js/test/src/test/TestHandler.java | 2 +- lib/js/test/test.html | 227 ++++++++++++++++---------- lib/js/thrift.js | 43 +++-- 3 files changed, 170 insertions(+), 102 deletions(-) diff --git a/lib/js/test/src/test/TestHandler.java b/lib/js/test/src/test/TestHandler.java index 727a32b7..f2c944f4 100644 --- a/lib/js/test/src/test/TestHandler.java +++ b/lib/js/test/src/test/TestHandler.java @@ -48,7 +48,7 @@ public class TestHandler implements ThriftTest.Iface { } public void testException(String arg) throws Xception, TException { - throw new Xception(1,"server test exception"); + throw new Xception(1,arg); } public int testI32(int thing) throws TException { diff --git a/lib/js/test/test.html b/lib/js/test/test.html index 0e2ee420..708db416 100644 --- a/lib/js/test/test.html +++ b/lib/js/test/test.html @@ -1,95 +1,142 @@ - - - + + - Thrift Javascript Bindings - Example - - - - - - - + + Thrift Javascript Bindings: Unit Test + + + + + + + + + + + + + - - - - +*/ + + //]]> + +

Thrift Javascript Bindings: Unit Test (ThriftTest.thrift)

+

+

+
+

+ Valid XHTML 1.0! +

diff --git a/lib/js/thrift.js b/lib/js/thrift.js index 5e9c89e7..04a34d1d 100644 --- a/lib/js/thrift.js +++ b/lib/js/thrift.js @@ -54,7 +54,7 @@ Thrift.TException.prototype = { } -Thrift.TApplicationException = { +Thrift.TApplicationExceptionType = { "UNKNOWN" : 0, "UNKNOWN_METHOD" : 1, "INVALID_MESSAGE_TYPE" : 2, @@ -401,7 +401,9 @@ Thrift.Protocol.prototype = { 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 @@ Thrift.Protocol.prototype = { 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 @@ Thrift.Protocol.prototype = { }, 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 @@ Thrift.Protocol.prototype = { this.rpos.push(this.rstack.length); this.rstack.push(list) - - + return r; }, @@ -616,19 +625,24 @@ Thrift.Protocol.prototype = { }, - 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 @@ Thrift.Protocol.prototype = { r["value"] = f } - return r }, -- 2.17.1