Repository: thrift
Updated Branches:
  refs/heads/master bb98e97fd -> 738143cf3


THRIFT-3293 JavaScript: null values turn into empty structs in constructor
Patch: HÃ¥kon Hitland


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/738143cf
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/738143cf
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/738143cf

Branch: refs/heads/master
Commit: 738143cf36436d65c7e379351968e6e0a1f4ca3f
Parents: bb98e97
Author: Henrique Mendonça <[email protected]>
Authored: Sun Aug 16 19:17:33 2015 +1000
Committer: Henrique Mendonça <[email protected]>
Committed: Sun Aug 16 19:17:33 2015 +1000

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_js_generator.cc |  2 +-
 lib/nodejs/test/deep-constructor.test.js    | 16 ++++++++++++++++
 test/JsDeepConstructorTest.thrift           |  4 ++++
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/738143cf/compiler/cpp/src/generate/t_js_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_js_generator.cc 
b/compiler/cpp/src/generate/t_js_generator.cc
index 8e136c4..c348774 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -705,7 +705,7 @@ void 
t_js_generator::generate_js_struct_definition(ofstream& out,
 
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       t_type* t = get_true_type((*m_iter)->get_type());
-      out << indent() << indent() << "if (args." << (*m_iter)->get_name() << " 
!== undefined) {"
+      out << indent() << indent() << "if (args." << (*m_iter)->get_name() << " 
!== undefined && args." << (*m_iter)->get_name() << " !== null) {"
           << endl << indent() << indent() << indent() << "this." << 
(*m_iter)->get_name();
 
       if (t->is_struct()) {

http://git-wip-us.apache.org/repos/asf/thrift/blob/738143cf/lib/nodejs/test/deep-constructor.test.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/test/deep-constructor.test.js 
b/lib/nodejs/test/deep-constructor.test.js
index 41e7dd0..8dd29ee 100644
--- a/lib/nodejs/test/deep-constructor.test.js
+++ b/lib/nodejs/test/deep-constructor.test.js
@@ -213,9 +213,25 @@ function createTestCases(serialize, deserialize) {
         struct_nested_containers_field2: null
       });
       var received = deserialize(serialize(tObj), ttypes.Complex);
+      assert.strictEqual(tObj.struct_field, null);
       assert.ok(tObj !== received);
       assert.deepEqual(tObj, received);
       assert.end();
+    },
+
+    "Can make list with objects": function(assert) {
+      var tObj = new ttypes.ComplexList({
+             "struct_list_field": [new ttypes.Complex({})]
+      });
+      var innerObj = tObj.struct_list_field[0];
+      assert.ok(innerObj instanceof ttypes.Complex)
+      assert.strictEqual(innerObj.struct_field, null);
+      assert.strictEqual(innerObj.struct_list_field, null);
+      assert.strictEqual(innerObj.struct_set_field, null);
+      assert.strictEqual(innerObj.struct_map_field, null);
+      assert.strictEqual(innerObj.struct_nested_containers_field, null);
+      assert.strictEqual(innerObj.struct_nested_containers_field2, null);
+      assert.end();
     }
 
   };

http://git-wip-us.apache.org/repos/asf/thrift/blob/738143cf/test/JsDeepConstructorTest.thrift
----------------------------------------------------------------------
diff --git a/test/JsDeepConstructorTest.thrift 
b/test/JsDeepConstructorTest.thrift
index 9150854..c2e23af 100644
--- a/test/JsDeepConstructorTest.thrift
+++ b/test/JsDeepConstructorTest.thrift
@@ -10,3 +10,7 @@ struct Complex {
   5: list<set<map<string,list<Simple>>>> struct_nested_containers_field
   6: map<string, list<map<string,Simple>> > struct_nested_containers_field2
 }
+
+struct ComplexList {
+  1: list<Complex> struct_list_field;
+}

Reply via email to