THRIFT-1277 Node.js serializes false booleans as null
Patch: Henrique Mendonca
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1326371 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index eb553ad..a603647 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -699,7 +699,7 @@
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) <<
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index 2d8fe23..fb36f68 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -32,7 +32,7 @@
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 @@
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 @@
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 @@
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 @@
var mapTestOutput = client.testMap(mapTestInput);
for (var key in mapTestOutput) {
- equals(mapTestOutput[key], mapTestInput[key]);
+ equal(mapTestOutput[key], mapTestInput[key]);
}
});
@@ -132,7 +132,7 @@
var mapTestOutput = client.testStringMap(mapTestInput);
for (var key in mapTestOutput) {
- equals(mapTestOutput[key], mapTestInput[key]);
+ equal(mapTestOutput[key], mapTestInput[key]);
}
});
@@ -147,11 +147,11 @@
});
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 @@
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 @@
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 @@
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 @@
},
"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 @@
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 @@
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 @@
QUnit.stop();
client.testDouble(3.14159265, function(result) {
- equals(result, 3.14159265);
+ equal(result, 3.14159265);
QUnit.start();
});
});
@@ -333,7 +333,7 @@
QUnit.stop();
client.testByte(0x01, function(result) {
- equals(result, 0x01);
+ equal(result, 0x01);
QUnit.start();
});
});
@@ -343,17 +343,17 @@
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 @@
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 @@
QUnit.start();
})
.error(function(e){
- equals(e.errorCode, 1001);
- equals(e.message, "Xception");
+ equal(e.errorCode, 1001);
+ equal(e.message, "Xception");
QUnit.start();
});
});