THRIFT-3293 JavaScript: null values turn into empty structs in constructor
Patch: Håkon Hitland
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 @@
 
     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()) {
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 @@
         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();
     }
 
   };
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 @@
   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;
+}