summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Meier <roger@apache.org>2011-07-08 12:44:29 +0000
committerRoger Meier <roger@apache.org>2011-07-08 12:44:29 +0000
commit6b0d4567167f689de4a3bd2f7475de0fd82d3bdc (patch)
tree56eedb055b1e47dc5f02a8e377c368332eee7f25
parent30aae0ca877c9f5863ff881b29edc6a38df9d85a (diff)
downloadthrift-6b0d4567167f689de4a3bd2f7475de0fd82d3bdc.tar.gz
THRIFT-1232 JavaScript TException should be a constructor function
Patch: Pascal Bach file: 1232-Improve-Exception-handling-and-make-error-hierarchy.patch git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1144292 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--compiler/cpp/src/generate/t_js_generator.cc1
-rw-r--r--lib/js/thrift.js123
2 files changed, 59 insertions, 65 deletions
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index 7561b12d6..b6ca05a38 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -576,6 +576,7 @@ void t_js_generator::generate_js_struct_definition(ofstream& out,
out << "Thrift.inherits(" <<
js_namespace(tstruct->get_program()) <<
tstruct->get_name() << ", Thrift.TException);" << endl;
+ out << js_namespace(tstruct->get_program())<<tstruct->get_name() <<".prototype.name = '" << tstruct->get_name() << "';" << endl;
} else {
//init prototype
out << js_namespace(tstruct->get_program())<<tstruct->get_name() <<".prototype = {};\n";
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index 8b1733e3b..860cb99c9 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -72,14 +72,12 @@ var Thrift = {
};
-Thrift.TException = {};
-Thrift.TException.prototype = {
- initialize: function(message, code) {
- this.message = message;
- this.code = (code === null) ? 0 : code;
- }
-};
+Thrift.TException = function(message) {
+ this.message = message;
+};
+Thrift.inherits(Thrift.TException, Error);
+Thrift.TException.prototype.name = 'TException';
Thrift.TApplicationExceptionType = {
'UNKNOWN' : 0,
@@ -94,80 +92,75 @@ Thrift.TApplicationException = function(message, code) {
this.message = message;
this.code = (code === null) ? 0 : code;
};
+Thrift.inherits(Thrift.TApplicationException, Thrift.TException);
+Thrift.TApplicationException.prototype.name = 'TApplicationException';
-Thrift.TApplicationException.prototype = {
+Thrift.TApplicationException.prototype.read = function(input) {
+ while (1) {
+ var ret = input.readFieldBegin();
- read: function(input) {
- while (1) {
- var ret = input.readFieldBegin();
+ if (ret.ftype == Thrift.Type.STOP) {
+ break;
+ }
- if (ret.ftype == Thrift.Type.STOP) {
- break;
- }
+ var fid = ret.fid;
- var fid = ret.fid;
-
- switch (fid) {
- case 1:
- if (ret.ftype == Thrift.Type.STRING) {
- ret = input.readString();
- this.message = ret.value;
- } else {
- ret = input.skip(ret.ftype);
- }
-
- break;
- case 2:
- if (ret.ftype == Thrift.Type.I32) {
- ret = input.readI32();
- this.code = ret.value;
- } else {
- ret = input.skip(ret.ftype);
- }
- break;
-
- default:
+ switch (fid) {
+ case 1:
+ if (ret.ftype == Thrift.Type.STRING) {
+ ret = input.readString();
+ this.message = ret.value;
+ } else {
ret = input.skip(ret.ftype);
- break;
- }
-
- input.readFieldEnd();
+ }
+ break;
+ case 2:
+ if (ret.ftype == Thrift.Type.I32) {
+ ret = input.readI32();
+ this.code = ret.value;
+ } else {
+ ret = input.skip(ret.ftype);
+ }
+ break;
+ default:
+ ret = input.skip(ret.ftype);
+ break;
}
- input.readStructEnd();
- },
-
- write: function(output) {
- var xfer = 0;
+ input.readFieldEnd();
+ }
- output.writeStructBegin('TApplicationException');
+ input.readStructEnd();
+};
- if (this.message) {
- output.writeFieldBegin('message', Thrift.Type.STRING, 1);
- output.writeString(this.getMessage());
- output.writeFieldEnd();
- }
+Thrift.TApplicationException.prototype.write = function(output) {
+ var xfer = 0;
- if (this.code) {
- output.writeFieldBegin('type', Thrift.Type.I32, 2);
- output.writeI32(this.code);
- output.writeFieldEnd();
- }
+ output.writeStructBegin('TApplicationException');
- output.writeFieldStop();
- output.writeStructEnd();
- },
-
- getCode: function() {
- return this.code;
- },
+ if (this.message) {
+ output.writeFieldBegin('message', Thrift.Type.STRING, 1);
+ output.writeString(this.getMessage());
+ output.writeFieldEnd();
+ }
- getMessage: function() {
- return this.message;
+ if (this.code) {
+ output.writeFieldBegin('type', Thrift.Type.I32, 2);
+ output.writeI32(this.code);
+ output.writeFieldEnd();
}
+
+ output.writeFieldStop();
+ output.writeStructEnd();
};
+Thrift.TApplicationException.prototype.getCode = function() {
+ return this.code;
+};
+Thrift.TApplicationException.prototype.getMessage = function() {
+ return this.message;
+};
/**
*If you do not specify a url then you must handle ajax on your own.