Add JavaScript test for CXJ_Model object.

Fix NULL segv uncovered by test.

Change-Id: I0015e234852b48f00315771e725b94fda844eaa5
Reviewed-on: https://pdfium-review.googlesource.com/c/50312
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/resources/javascript/xfa_specific/xfa_model.in b/testing/resources/javascript/xfa_specific/xfa_model.in
new file mode 100644
index 0000000..57a2427
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/xfa_model.in
@@ -0,0 +1,50 @@
+{{header}}
+{{include ../../xfa_catalog_1_0.fragment}}
+{{include ../../xfa_object_2_0.fragment}}
+{{include ../../xfa_preamble_3_0.fragment}}
+{{include ../../xfa_config_4_0.fragment}}
+{{object 5 0}} <<
+>>
+stream
+<template>
+  <subform layout="tb" name="my_doc">
+    <pageSet id="page" relation="orderedOccurrence">
+      <occur initial="1" max="1" min="1"/>
+      <pageArea id="Page1" name="Page1">
+        <occur max="1" min="1"/>
+        <contentArea h="100mm" w="200mm" x="0.25in" y="0.25in"/>
+      </pageArea>
+      <pageArea id="Page2" name="Page2">
+        <occur max="1" min="1"/>
+        <contentArea h="100mm" w="200mm" x="0.25in" y="0.25in"/>
+      </pageArea>
+    </pageSet>
+    <event activity="docReady" ref="$host">
+      <script contentType="application/x-javascript">
+        {{include ../expect.js}}
+        {{include ../property_test_helpers.js}}
+        testRIProperty(xfa.form, "aliasNode", undefined);
+        testRIProperty(xfa.form, "context", undefined);
+        expect("typeof xfa.form.clearErrorList", "function");
+        expect("typeof xfa.form.createNode", "function");
+        expect("typeof xfa.form.isCompatibleNS", "function");
+        expect("xfa.form.clearErrorList('args', 'ignored')", undefined);
+        expectError("xfa.form.createNode()");
+        expect("xfa.form.createNode('bogus')", undefined);
+        expect("xfa.form.createNode('template')", "[object XFAObject]");
+        expectError("xfa.form.isCompatibleNS()");
+        expect("xfa.form.isCompatibleNS('bogus')", false);
+        expect("xfa.form.isCompatibleNS('')", true);
+      </script>
+    </event>
+  </subform>
+</template>
+endstream
+endobj
+{{include ../../xfa_locale_6_0.fragment}}
+{{include ../../xfa_postamble_7_0.fragment}}
+{{include ../../xfa_pages_8_0.fragment}}
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/xfa_specific/xfa_model_expected.txt b/testing/resources/javascript/xfa_specific/xfa_model_expected.txt
new file mode 100644
index 0000000..7613cca
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/xfa_model_expected.txt
@@ -0,0 +1,14 @@
+Alert: PASS: aliasNode = undefined
+Alert: PASS: aliasNode = undefined
+Alert: PASS: context = undefined
+Alert: PASS: context = undefined
+Alert: PASS: typeof xfa.form.clearErrorList = function
+Alert: PASS: typeof xfa.form.createNode = function
+Alert: PASS: typeof xfa.form.isCompatibleNS = function
+Alert: PASS: xfa.form.clearErrorList('args', 'ignored') = undefined
+Alert: PASS: xfa.form.createNode() threw XFAObject.createNode: Incorrect number of parameters passed to function.
+Alert: PASS: xfa.form.createNode('bogus') = null
+Alert: PASS: xfa.form.createNode('template') = [object XFAObject]
+Alert: PASS: xfa.form.isCompatibleNS() threw XFAObject.isCompatibleNS: Incorrect number of parameters passed to function.
+Alert: PASS: xfa.form.isCompatibleNS('bogus') = false
+Alert: PASS: xfa.form.isCompatibleNS('') = true
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 3062890..9ebd303 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1056,6 +1056,9 @@
 
 CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType) {
   CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
+  if (!pNode)
+    return nullptr;
+
   pNode->SetFlagAndNotify(XFA_NodeFlag_Initialized);
   return pNode;
 }