Permalink
Browse files

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
  • Loading branch information...
1 parent 2badac7 commit b661e83fab3bfa7a5240f254e8a948830ffeabdf @bufferoverflow bufferoverflow committed Apr 15, 2012
Showing with 43 additions and 43 deletions.
  1. +1 −1 compiler/cpp/src/generate/t_js_generator.cc
  2. +42 −42 lib/js/test/test.js
@@ -699,7 +699,7 @@ void t_js_generator::generate_js_struct_writer(ofstream& out,
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) <<
View
@@ -32,7 +32,7 @@ var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, A
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();
});
});

0 comments on commit b661e83

Please sign in to comment.