Ensure JavaScript sources are strings or streams.

More closely follow the spec.

Bug: chromium:959274
Change-Id: I25db01e846773f920fc466f17671b9f31056eb03
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53971
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 2d2ff03..1621741 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -113,12 +113,12 @@
 }
 
 WideString CPDF_Action::GetJavaScript() const {
-  WideString csJS;
   if (!m_pDict)
-    return csJS;
+    return WideString();
 
   const CPDF_Object* pJS = m_pDict->GetDirectObjectFor("JS");
-  return pJS ? pJS->GetUnicodeText() : csJS;
+  return (pJS && (pJS->IsString() || pJS->IsStream())) ? pJS->GetUnicodeText()
+                                                       : WideString();
 }
 
 size_t CPDF_Action::GetSubActionsCount() const {
diff --git a/testing/resources/javascript/bug_959274_1.in b/testing/resources/javascript/bug_959274_1.in
new file mode 100644
index 0000000..74909c0
--- /dev/null
+++ b/testing/resources/javascript/bug_959274_1.in
@@ -0,0 +1,36 @@
+{{header}}
+{{object 1 0}} <<
+  /Type /Catalog
+  /Pages 2 0 R
+  /OpenAction 10 0 R
+>>
+endobj
+{{object 2 0}} <<
+  /Type /Pages
+  /Count 1
+  /Kids [
+    3 0 R
+  ]
+>>
+endobj
+% Page number 0.
+{{object 3 0}} <<
+  /Type /Page
+  /Parent 2 0 R
+  /Resources <<
+    /Font <</F1 15 0 R>>
+  >>
+  /Contents [21 0 R]
+  /MediaBox [0 0 612 792]
+>>
+% OpenAction action
+{{object 10 0}} <<
+  /Type /Action
+  /S /JavaScript
+  /JS /app.alert#28#22FAILURE#22#29
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/bug_959274_1_expected.txt b/testing/resources/javascript/bug_959274_1_expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testing/resources/javascript/bug_959274_1_expected.txt