Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

THRIFT-1044 Fix JavaScript inheritance

Patch Wade Simmons


git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1062279 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 90443f4e11d883fba6abb23562a159e8a8b0b78e 1 parent 4b3f1c3
@bufferoverflow bufferoverflow authored
View
35 compiler/cpp/src/generate/t_js_generator.cc
@@ -541,19 +541,12 @@ void t_js_generator::generate_js_struct_definition(ofstream& out,
out << "}\n";
if (is_exception) {
- if (gen_node_) {
- out << "require('util').inherits(" <<
- js_namespace(tstruct->get_program()) <<
- tstruct->get_name() << ", Thrift.TException)" << endl;
- } else {
- out << "for (var property in Thrift.TException)"<<endl<<
- js_namespace(tstruct->get_program())<<tstruct->get_name()<<"[property] = Thrift.TException[property]"<<endl;
- }
- }
-
- if (!gen_node_) {
- //init prototype
- out << js_namespace(tstruct->get_program())<<tstruct->get_name() <<".prototype = {}\n";
+ out << "Thrift.inherits(" <<
+ js_namespace(tstruct->get_program()) <<
+ tstruct->get_name() << ", Thrift.TException)" << endl;
+ } else {
+ //init prototype
+ out << js_namespace(tstruct->get_program())<<tstruct->get_name() <<".prototype = {}\n";
}
@@ -935,17 +928,15 @@ void t_js_generator::generate_service_client(t_service* tservice) {
if (tservice->get_extends() != NULL) {
- extends = tservice->get_extends()->get_name();
-
- f_service_ << "for (var property in "<<extends<<"Client)"<<endl<<
- js_namespace(tservice->get_program()) << service_name_<<"Client[property] = "<<extends<<"Client[property]"<<endl;
-
+ indent(f_service_) << "Thrift.inherits(" <<
+ js_namespace(tservice->get_program()) <<
+ service_name_ << "Client, " <<
+ tservice->get_extends()->get_name() << ".Client)" << endl;
+ } else {
+ //init prototype
+ indent(f_service_) << js_namespace(tservice->get_program())<<service_name_ << "Client.prototype = {}"<<endl;
}
- //init prototype
- f_service_ << js_namespace(tservice->get_program())<<service_name_ << "Client.prototype = {}"<<endl;
-
-
// Generate client method implementations
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::const_iterator f_iter;
View
8 lib/js/thrift.js
@@ -723,4 +723,10 @@ Thrift.objectLength = function(obj) {
return length;
}
-
+Thirft.inherits = function(constructor, superConstructor) {
+ // Prototypal Inheritance
+ // http://javascript.crockford.com/prototypal.html
+ function F() {}
+ F.prototype = superConstructor.prototype;
+ constructor.prototype = new F();
+}
View
4 lib/nodejs/lib/thrift/thrift.js
@@ -132,3 +132,7 @@ TApplicationException.prototype.write = function(output){
exports.objectLength = function(obj) {
return Object.keys(obj).length;
}
+
+exports.inherits = function(constructor, superConstructor) {
+ sys.inherits(constructor, superConstructor);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.