You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2012/04/15 17:58:43 UTC

svn commit: r1326371 - in /thrift/trunk: compiler/cpp/src/generate/t_js_generator.cc lib/js/test/test.js

Author: roger
Date: Sun Apr 15 15:58:43 2012
New Revision: 1326371

URL: http://svn.apache.org/viewvc?rev=1326371&view=rev
Log:
THRIFT-1277 Node.js serializes false booleans as null
Patch: Henrique Mendonca

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc
    thrift/trunk/lib/js/test/test.js

Modified: thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc?rev=1326371&r1=1326370&r2=1326371&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_js_generator.cc Sun Apr 15 15:58:43 2012
@@ -699,7 +699,7 @@ void t_js_generator::generate_js_struct_
   indent(out) << "output.writeStructBegin('" << name << "');" << endl;
 
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
-    out << indent() << "if (this." << (*f_iter)->get_name() << ") {" << endl;
+    out << indent() << "if (this." << (*f_iter)->get_name() <<  " !== null && this." << (*f_iter)->get_name() << " !== undefined) {" << endl;
     indent_up();
 
     indent(out) <<

Modified: thrift/trunk/lib/js/test/test.js
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/js/test/test.js?rev=1326371&r1=1326370&r2=1326371&view=diff
==============================================================================
--- thrift/trunk/lib/js/test/test.js (original)
+++ thrift/trunk/lib/js/test/test.js Sun Apr 15 15:58:43 2012
@@ -32,7 +32,7 @@ var stringTest = "Afrikaans, Alemannisch
 function checkRecursively(map1, map2) {
   if (typeof map1 !== 'function' && typeof map2 !== 'function') {
     if (!map1 || typeof map1 !== 'object') {
-        equals(map1, map2);
+        equal(map1, map2);
     } else {
       for (var key in map1) {
         checkRecursively(map1[key], map2[key]);
@@ -44,29 +44,29 @@ function checkRecursively(map1, map2) {
 module("Base Types");
 
   test("Void", function() {
-    equals(client.testVoid(), undefined);
+    equal(client.testVoid(), undefined);
   });
   test("String", function() {
-    equals(client.testString(stringTest), stringTest);
+    equal(client.testString(stringTest), stringTest);
 
     var specialCharacters = 'quote: \" backslash:' +
           ' forwardslash-escaped: \/ ' +
           ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
           ' now-all-of-them-together: "\\\/\b\n\r\t' +
           ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
-    equals(client.testString(specialCharacters),specialCharacters);
+    equal(client.testString(specialCharacters),specialCharacters);
   });
   test("Double", function() {
-    equals(client.testDouble(3.14), 3.14);
+    equal(client.testDouble(3.14), 3.14);
   });
   test("Byte", function() {
-    equals(client.testByte(0x01), 0x01);
+    equal(client.testByte(0x01), 0x01);
   });
   test("I32", function() {
-    equals(client.testI32(Math.pow(2,30)), Math.pow(2,30));
+    equal(client.testI32(Math.pow(2,30)), Math.pow(2,30));
   });
   test("I64", function() {
-    equals(client.testI64(Math.pow(2,60)), Math.pow(2,60));
+    equal(client.testI64(Math.pow(2,60)), Math.pow(2,60));
   });
 
 
@@ -81,12 +81,12 @@ module("Structured Types");
 
     var structTestOutput = client.testStruct(structTestInput);
 
-    equals(structTestOutput.string_thing, structTestInput.string_thing);
-    equals(structTestOutput.byte_thing, structTestInput.byte_thing);
-    equals(structTestOutput.i32_thing, structTestInput.i32_thing);
-    equals(structTestOutput.i64_thing, structTestInput.i64_thing);
+    equal(structTestOutput.string_thing, structTestInput.string_thing);
+    equal(structTestOutput.byte_thing, structTestInput.byte_thing);
+    equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+    equal(structTestOutput.i64_thing, structTestInput.i64_thing);
     
-    equals(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
+    equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
   });
 
   test("Nest", function() {
@@ -103,14 +103,14 @@ module("Structured Types");
     
     var nestTestOutput = client.testNest(nestTestInput);
     
-    equals(nestTestOutput.byte_thing, nestTestInput.byte_thing);
-    equals(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
-    equals(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
-    equals(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
-    equals(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
-    equals(nestTestOutput.i32_thing, nestTestInput.i32_thing);
+    equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
+    equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+    equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+    equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+    equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+    equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
     
-    equals(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
+    equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
   });
 
   test("Map", function() {
@@ -119,7 +119,7 @@ module("Structured Types");
     var mapTestOutput = client.testMap(mapTestInput);
 
     for (var key in mapTestOutput) {
-      equals(mapTestOutput[key], mapTestInput[key]);
+      equal(mapTestOutput[key], mapTestInput[key]);
     }
   });
 
@@ -132,7 +132,7 @@ module("Structured Types");
     var mapTestOutput = client.testStringMap(mapTestInput);
 
     for (var key in mapTestOutput) {
-      equals(mapTestOutput[key], mapTestInput[key]);
+      equal(mapTestOutput[key], mapTestInput[key]);
     }
   });
 
@@ -147,11 +147,11 @@ module("Structured Types");
   });
 
   test("Enum", function() {
-    equals(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
+    equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
   });
 
   test("TypeDef", function() {
-    equals(client.testTypedef(69), 69);
+    equal(client.testTypedef(69), 69);
   });
 
 
@@ -168,7 +168,7 @@ module("deeper!");
 
     for (var key in mapMapTestOutput) {
       for (var key2 in mapMapTestOutput[key]) {
-        equals(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
+        equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
       }
     }
     
@@ -183,12 +183,12 @@ module("Exception");
     try{
       client.testException("Xception");
     }catch(e){
-      equals(e.errorCode, 1001);
-      equals(e.message, "Xception");
+      equal(e.errorCode, 1001);
+      equal(e.message, "Xception");
     }
   });
 
-  test("no Exception", function() {
+  test("no Exception", 0, function() {
     try{
       client.testException("no Exception");
     }catch(e){
@@ -202,7 +202,7 @@ module("Exception");
       client.testException("ApplicationException");
     } catch(e) {
       ok(true); //@HACK: ignore faulty java server response for exceptions
-      //equals(e.message, "ApplicationException");
+      //equal(e.message, "ApplicationException");
     }
   });
 
@@ -247,7 +247,7 @@ module("Insanity");
       },
       "2":{ "6":{ "userMap":null, "xtructs":null } }
     };
-    var res = client.testInsanity("");
+    var res = client.testInsanity(new ThriftTest.Insanity());
     ok(res, JSON.stringify(res));
     ok(insanity, JSON.stringify(insanity));
 
@@ -278,7 +278,7 @@ module("Async Manual");
       dataType: "text",
       success: function(res){
         transport.setRecvBuffer( res );
-        equals(client.recv_testI32(), Math.pow(-2,31));
+        equal(client.recv_testI32(), Math.pow(-2,31));
       },
       error: function() { ok(false); },
       complete: function() {
@@ -305,7 +305,7 @@ module("Async Manual");
       dataType: "text",
       success: function(res){
         transport.setRecvBuffer( res );
-        equals(client.recv_testI64(), Math.pow(-2,61));
+        equal(client.recv_testI64(), Math.pow(-2,61));
       },
       error: function() { ok(false); },
       complete: function() {
@@ -323,7 +323,7 @@ module("Async");
 
     QUnit.stop();
     client.testDouble(3.14159265, function(result) {
-      equals(result, 3.14159265);
+      equal(result, 3.14159265);
       QUnit.start();
     });
   });
@@ -333,7 +333,7 @@ module("Async");
 
     QUnit.stop();
     client.testByte(0x01, function(result) {
-      equals(result, 0x01);
+      equal(result, 0x01);
       QUnit.start();
     });
   });
@@ -343,17 +343,17 @@ module("Async");
 
     QUnit.stop();
     client.testI32(Math.pow(2,30), function(result) {
-      equals(result, Math.pow(2,30));
+      equal(result, Math.pow(2,30));
       QUnit.start();
     });
 
     QUnit.stop();
     var jqxhr = client.testI32(Math.pow(-2,31), function(result) {
-      equals(result, Math.pow(-2,31));
+      equal(result, Math.pow(-2,31));
     });
 
     jqxhr.success(function(result) {
-      equals(result, Math.pow(-2,31));
+      equal(result, Math.pow(-2,31));
       QUnit.start();
     });
   });
@@ -363,17 +363,17 @@ module("Async");
 
     QUnit.stop();
     client.testI64(Math.pow(2,60), function(result) {
-      equals(result, Math.pow(2,60));
+      equal(result, Math.pow(2,60));
       QUnit.start();
     });
 
     QUnit.stop();
     client.testI64(Math.pow(-2,61), function(result) {
-      equals(result, Math.pow(-2,61));
+      equal(result, Math.pow(-2,61));
     })
     .error( function(e) {  ok(false); } )
     .success(function(result) {
-      equals(result, Math.pow(-2,61));
+      equal(result, Math.pow(-2,61));
     })
     .complete(function() {
       ok(true);
@@ -391,8 +391,8 @@ module("Async");
       QUnit.start();
     })
     .error(function(e){
-      equals(e.errorCode, 1001);
-      equals(e.message, "Xception");
+      equal(e.errorCode, 1001);
+      equal(e.message, "Xception");
       QUnit.start();
     });
   });