Fix JS event.value behavior.

Add more tests and make sure the behavior matches Acrobat Reader's.

Change-Id: I46ce84c77c5687acae1910f66ccecf2ef07793f8
Reviewed-on: https://pdfium-review.googlesource.com/c/45372
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp
index 1862b19..f1eeae0 100644
--- a/fxjs/cjs_event.cpp
+++ b/fxjs/cjs_event.cpp
@@ -304,6 +304,12 @@
   if (!pEvent->m_pValue)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
+  if (vp.IsEmpty())
+    return CJS_Result::Failure(JSMessage::kBadObjectError);
+
+  if (vp->IsNullOrUndefined() || vp->IsBoolean())
+    return CJS_Result::Failure(JSMessage::kInvalidSetError);
+
   pEvent->Value() = pRuntime->ToWideString(vp);
   return CJS_Result::Success();
 }
diff --git a/fxjs/js_resources.cpp b/fxjs/js_resources.cpp
index 0b53c26..05b5b37 100644
--- a/fxjs/js_resources.cpp
+++ b/fxjs/js_resources.cpp
@@ -51,6 +51,8 @@
       return L"Object is of the wrong type.";
     case JSMessage::kUnknownProperty:
       return L"Unknown property.";
+    case JSMessage::kInvalidSetError:
+      return L"Set not possible, invalid or unknown.";
 #ifdef PDF_ENABLE_XFA
     case JSMessage::kTooManyOccurances:
       return L"Too many occurances.";
diff --git a/fxjs/js_resources.h b/fxjs/js_resources.h
index 576fba5..79d5502 100644
--- a/fxjs/js_resources.h
+++ b/fxjs/js_resources.h
@@ -31,6 +31,7 @@
   kBadObjectError,
   kObjectTypeError,
   kUnknownProperty,
+  kInvalidSetError,
 #ifdef PDF_ENABLE_XFA
   kTooManyOccurances,
   kUnknownMethod,
diff --git a/testing/resources/javascript/event_properties.in b/testing/resources/javascript/event_properties.in
index 6f563d1..df727de 100644
--- a/testing/resources/javascript/event_properties.in
+++ b/testing/resources/javascript/event_properties.in
@@ -155,6 +155,16 @@
       expect("event.value", "");
       expect("event.value = 'boo'", "boo");
       expect("event.value", "boo");
+      expect("event.value = ''", "");
+      expect("event.value", "");
+      expect("event.value = 0", 0);
+      expect("event.value", 0);
+      expect("event.value = 2", 2);
+      expect("event.value", 2);
+      expectError("event.value = true");
+      expectError("event.value = false");
+      expectError("event.value = undefined");
+      expectError("event.value = null");
 
       expect("event.willCommit", true);
       expectError("event.willCommit = 'boo'");
diff --git a/testing/resources/javascript/event_properties_expected.txt b/testing/resources/javascript/event_properties_expected.txt
index bdcecc2..227841c 100644
--- a/testing/resources/javascript/event_properties_expected.txt
+++ b/testing/resources/javascript/event_properties_expected.txt
@@ -46,6 +46,16 @@
 Alert: PASS: event.value = 
 Alert: PASS: event.value = 'boo' = boo
 Alert: PASS: event.value = boo
+Alert: PASS: event.value = '' = 
+Alert: PASS: event.value = 
+Alert: PASS: event.value = 0 = 0
+Alert: PASS: event.value = 0
+Alert: PASS: event.value = 2 = 2
+Alert: PASS: event.value = 2
+Alert: PASS: event.value = true threw event.value: Set not possible, invalid or unknown.
+Alert: PASS: event.value = false threw event.value: Set not possible, invalid or unknown.
+Alert: PASS: event.value = undefined threw event.value: Set not possible, invalid or unknown.
+Alert: PASS: event.value = null threw event.value: Set not possible, invalid or unknown.
 Alert: PASS: event.willCommit = true
 Alert: PASS: event.willCommit = 'boo' threw event.willCommit: Operation not supported.
 Alert: PASS: event.willCommit = true