Rename IJS_Context to IJS_EventContext.

Prevents confusion with v8::Context, which is wrapped by a
different IJS_ class.

Change-Id: Iff75809e65015c0f810294de1f0d8ecf963150a3
Reviewed-on: https://pdfium-review.googlesource.com/2751
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 1a0a53c..38600ed 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -30,7 +30,7 @@
 #include "fpdfsdk/javascript/JS_Object.h"
 #include "fpdfsdk/javascript/JS_Value.h"
 #include "fpdfsdk/javascript/app.h"
-#include "fpdfsdk/javascript/cjs_context.h"
+#include "fpdfsdk/javascript/cjs_event_context.h"
 #include "fpdfsdk/javascript/cjs_runtime.h"
 #include "fpdfsdk/javascript/resource.h"
 #include "third_party/base/numerics/safe_math.h"
@@ -163,7 +163,7 @@
 }
 
 // the total number of fileds in document.
-bool Document::numFields(IJS_Context* cc,
+bool Document::numFields(IJS_EventContext* cc,
                          CJS_PropValue& vp,
                          CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -180,7 +180,7 @@
   return true;
 }
 
-bool Document::dirty(IJS_Context* cc,
+bool Document::dirty(IJS_EventContext* cc,
                      CJS_PropValue& vp,
                      CFX_WideString& sError) {
   if (!m_pFormFillEnv) {
@@ -189,28 +189,28 @@
   }
   if (vp.IsGetting()) {
     vp << !!m_pFormFillEnv->GetChangeMark();
-  } else {
-    bool bChanged = false;
-    vp >> bChanged;
-
-    if (bChanged)
-      m_pFormFillEnv->SetChangeMark();
-    else
-      m_pFormFillEnv->ClearChangeMark();
+    return true;
   }
+  bool bChanged = false;
+  vp >> bChanged;
+  if (bChanged)
+    m_pFormFillEnv->SetChangeMark();
+  else
+    m_pFormFillEnv->ClearChangeMark();
+
   return true;
 }
 
-bool Document::ADBE(IJS_Context* cc,
+bool Document::ADBE(IJS_EventContext* cc,
                     CJS_PropValue& vp,
                     CFX_WideString& sError) {
   if (vp.IsGetting())
-    vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc));
+    vp.GetJSValue()->SetNull(CJS_Runtime::FromEventContext(cc));
 
   return true;
 }
 
-bool Document::pageNum(IJS_Context* cc,
+bool Document::pageNum(IJS_EventContext* cc,
                        CJS_PropValue& vp,
                        CFX_WideString& sError) {
   if (!m_pFormFillEnv) {
@@ -218,27 +218,24 @@
     return false;
   }
   if (vp.IsGetting()) {
-    if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) {
+    if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView())
       vp << pPageView->GetPageIndex();
-    }
-  } else {
-    int iPageCount = m_pFormFillEnv->GetPageCount();
-    int iPageNum = 0;
-    vp >> iPageNum;
-
-    if (iPageNum >= 0 && iPageNum < iPageCount) {
-      m_pFormFillEnv->JS_docgotoPage(iPageNum);
-    } else if (iPageNum >= iPageCount) {
-      m_pFormFillEnv->JS_docgotoPage(iPageCount - 1);
-    } else if (iPageNum < 0) {
-      m_pFormFillEnv->JS_docgotoPage(0);
-    }
+    return true;
   }
+  int iPageCount = m_pFormFillEnv->GetPageCount();
+  int iPageNum = 0;
+  vp >> iPageNum;
+  if (iPageNum >= 0 && iPageNum < iPageCount)
+    m_pFormFillEnv->JS_docgotoPage(iPageNum);
+  else if (iPageNum >= iPageCount)
+    m_pFormFillEnv->JS_docgotoPage(iPageCount - 1);
+  else if (iPageNum < 0)
+    m_pFormFillEnv->JS_docgotoPage(0);
 
   return true;
 }
 
-bool Document::addAnnot(IJS_Context* cc,
+bool Document::addAnnot(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -246,7 +243,7 @@
   return true;
 }
 
-bool Document::addField(IJS_Context* cc,
+bool Document::addField(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -254,7 +251,7 @@
   return true;
 }
 
-bool Document::exportAsText(IJS_Context* cc,
+bool Document::exportAsText(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -262,7 +259,7 @@
   return true;
 }
 
-bool Document::exportAsFDF(IJS_Context* cc,
+bool Document::exportAsFDF(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
@@ -270,7 +267,7 @@
   return true;
 }
 
-bool Document::exportAsXFDF(IJS_Context* cc,
+bool Document::exportAsXFDF(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -283,7 +280,7 @@
 // note: the paremter cName, this is clue how to treat if the cName is not a
 // valiable filed name in this document
 
-bool Document::getField(IJS_Context* cc,
+bool Document::getField(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -295,8 +292,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
@@ -317,7 +313,7 @@
 }
 
 // Gets the name of the nth field in the document
-bool Document::getNthFieldName(IJS_Context* cc,
+bool Document::getNthFieldName(IJS_EventContext* cc,
                                const std::vector<CJS_Value>& params,
                                CJS_Value& vRet,
                                CFX_WideString& sError) {
@@ -329,8 +325,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   int nIndex = params[0].ToInt(pRuntime);
   if (nIndex < 0) {
     sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
@@ -346,7 +341,7 @@
   return true;
 }
 
-bool Document::importAnFDF(IJS_Context* cc,
+bool Document::importAnFDF(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
@@ -354,7 +349,7 @@
   return true;
 }
 
-bool Document::importAnXFDF(IJS_Context* cc,
+bool Document::importAnXFDF(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -362,7 +357,7 @@
   return true;
 }
 
-bool Document::importTextData(IJS_Context* cc,
+bool Document::importTextData(IJS_EventContext* cc,
                               const std::vector<CJS_Value>& params,
                               CJS_Value& vRet,
                               CFX_WideString& sError) {
@@ -373,7 +368,7 @@
 // exports the form data and mails the resulting fdf file as an attachment to
 // all recipients.
 // comment: need reader supports
-bool Document::mailForm(IJS_Context* cc,
+bool Document::mailForm(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -385,10 +380,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
     return false;
   }
-
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   int iLength = params.size();
   bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true;
   CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L"";
@@ -397,14 +389,13 @@
   CFX_WideString cSubject =
       iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L"";
   CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L"";
-
   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   CFX_ByteTextBuf textBuf;
   if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
     return false;
 
   pRuntime->BeginBlock();
-  CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv();
+  CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
   pFormFillEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
                                cTo.c_str(), cSubject.c_str(), cCc.c_str(),
                                cBcc.c_str(), cMsg.c_str());
@@ -412,7 +403,7 @@
   return true;
 }
 
-bool Document::print(IJS_Context* cc,
+bool Document::print(IJS_EventContext* cc,
                      const std::vector<CJS_Value>& params,
                      CJS_Value& vRet,
                      CFX_WideString& sError) {
@@ -420,10 +411,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   bool bUI = true;
   int nStart = 0;
   int nEnd = 0;
@@ -432,7 +420,6 @@
   bool bPrintAsImage = false;
   bool bReverse = false;
   bool bAnnotations = false;
-
   int nlength = params.size();
   if (nlength == 9) {
     if (params[8].GetType() == CJS_Value::VT_object) {
@@ -485,7 +472,7 @@
 // comment:
 // note: if the filed name is not rational, adobe is dumb for it.
 
-bool Document::removeField(IJS_Context* cc,
+bool Document::removeField(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
@@ -502,8 +489,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime);
   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
@@ -546,7 +532,7 @@
 // comment:
 // note: if the fields names r not rational, aodbe is dumb for it.
 
-bool Document::resetForm(IJS_Context* cc,
+bool Document::resetForm(IJS_EventContext* cc,
                          const std::vector<CJS_Value>& params,
                          CJS_Value& vRet,
                          CFX_WideString& sError) {
@@ -571,7 +557,7 @@
     return true;
   }
 
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+  CJS_EventContext* pContext = static_cast<CJS_EventContext*>(cc);
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
 
   switch (params[0].GetType()) {
@@ -600,7 +586,7 @@
   return true;
 }
 
-bool Document::saveAs(IJS_Context* cc,
+bool Document::saveAs(IJS_EventContext* cc,
                       const std::vector<CJS_Value>& params,
                       CJS_Value& vRet,
                       CFX_WideString& sError) {
@@ -608,14 +594,14 @@
   return true;
 }
 
-bool Document::syncAnnotScan(IJS_Context* cc,
+bool Document::syncAnnotScan(IJS_EventContext* cc,
                              const std::vector<CJS_Value>& params,
                              CJS_Value& vRet,
                              CFX_WideString& sError) {
   return true;
 }
 
-bool Document::submitForm(IJS_Context* cc,
+bool Document::submitForm(IJS_EventContext* cc,
                           const std::vector<CJS_Value>& params,
                           CJS_Value& vRet,
                           CFX_WideString& sError) {
@@ -628,8 +614,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CJS_Array aFields;
   CFX_WideString strURL;
   bool bFDF = true;
@@ -698,20 +683,19 @@
   m_pFormFillEnv.Reset(pFormFillEnv);
 }
 
-bool Document::bookmarkRoot(IJS_Context* cc,
+bool Document::bookmarkRoot(IJS_EventContext* cc,
                             CJS_PropValue& vp,
                             CFX_WideString& sError) {
   return true;
 }
 
-bool Document::mailDoc(IJS_Context* cc,
+bool Document::mailDoc(IJS_EventContext* cc,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        CFX_WideString& sError) {
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
 
   // TODO(tsepez): Check maximum number of allowed params.
-
   bool bUI = true;
   CFX_WideString cTo = L"";
   CFX_WideString cCc = L"";
@@ -719,8 +703,6 @@
   CFX_WideString cSubject = L"";
   CFX_WideString cMsg = L"";
 
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
   if (params.size() >= 1)
     bUI = params[0].ToBool(pRuntime);
   if (params.size() >= 2)
@@ -761,17 +743,16 @@
   pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(),
                                cCc.c_str(), cBcc.c_str(), cMsg.c_str());
   pRuntime->EndBlock();
-
   return true;
 }
 
-bool Document::author(IJS_Context* cc,
+bool Document::author(IJS_EventContext* cc,
                       CJS_PropValue& vp,
                       CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "Author", sError);
 }
 
-bool Document::info(IJS_Context* cc,
+bool Document::info(IJS_EventContext* cc,
                     CJS_PropValue& vp,
                     CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -797,9 +778,7 @@
   CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate");
   CFX_WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped");
 
-  CJS_Context* pContext = (CJS_Context*)cc;
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1);
   pRuntime->PutObjectProperty(pObj, L"Author", pRuntime->NewString(cwAuthor));
   pRuntime->PutObjectProperty(pObj, L"Title", pRuntime->NewString(cwTitle));
@@ -834,7 +813,7 @@
   return true;
 }
 
-bool Document::getPropertyInternal(IJS_Context* cc,
+bool Document::getPropertyInternal(IJS_EventContext* cc,
                                    CJS_PropValue& vp,
                                    const CFX_ByteString& propName,
                                    CFX_WideString& sError) {
@@ -862,19 +841,19 @@
   return true;
 }
 
-bool Document::creationDate(IJS_Context* cc,
+bool Document::creationDate(IJS_EventContext* cc,
                             CJS_PropValue& vp,
                             CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "CreationDate", sError);
 }
 
-bool Document::creator(IJS_Context* cc,
+bool Document::creator(IJS_EventContext* cc,
                        CJS_PropValue& vp,
                        CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "Creator", sError);
 }
 
-bool Document::delay(IJS_Context* cc,
+bool Document::delay(IJS_EventContext* cc,
                      CJS_PropValue& vp,
                      CFX_WideString& sError) {
   if (!m_pFormFillEnv) {
@@ -883,49 +862,50 @@
   }
   if (vp.IsGetting()) {
     vp << m_bDelay;
-  } else {
-    if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) {
-      sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
-      return false;
-    }
-    vp >> m_bDelay;
-    if (m_bDelay) {
-      m_DelayData.clear();
-    } else {
-      std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess;
-      DelayDataToProcess.swap(m_DelayData);
-      for (const auto& pData : DelayDataToProcess)
-        Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
-    }
+    return true;
   }
+  if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) {
+    sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
+    return false;
+  }
+  vp >> m_bDelay;
+  if (m_bDelay) {
+    m_DelayData.clear();
+    return true;
+  }
+  std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess;
+  DelayDataToProcess.swap(m_DelayData);
+  for (const auto& pData : DelayDataToProcess)
+    Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
+
   return true;
 }
 
-bool Document::keywords(IJS_Context* cc,
+bool Document::keywords(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "Keywords", sError);
 }
 
-bool Document::modDate(IJS_Context* cc,
+bool Document::modDate(IJS_EventContext* cc,
                        CJS_PropValue& vp,
                        CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "ModDate", sError);
 }
 
-bool Document::producer(IJS_Context* cc,
+bool Document::producer(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "Producer", sError);
 }
 
-bool Document::subject(IJS_Context* cc,
+bool Document::subject(IJS_EventContext* cc,
                        CJS_PropValue& vp,
                        CFX_WideString& sError) {
   return getPropertyInternal(cc, vp, "Subject", sError);
 }
 
-bool Document::title(IJS_Context* cc,
+bool Document::title(IJS_EventContext* cc,
                      CJS_PropValue& vp,
                      CFX_WideString& sError) {
   if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) {
@@ -935,7 +915,7 @@
   return getPropertyInternal(cc, vp, "Title", sError);
 }
 
-bool Document::numPages(IJS_Context* cc,
+bool Document::numPages(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -950,7 +930,7 @@
   return true;
 }
 
-bool Document::external(IJS_Context* cc,
+bool Document::external(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   // In Chrome case, should always return true.
@@ -960,7 +940,7 @@
   return true;
 }
 
-bool Document::filesize(IJS_Context* cc,
+bool Document::filesize(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -971,19 +951,21 @@
   return true;
 }
 
-bool Document::mouseX(IJS_Context* cc,
+bool Document::mouseX(IJS_EventContext* cc,
                       CJS_PropValue& vp,
                       CFX_WideString& sError) {
   return true;
 }
 
-bool Document::mouseY(IJS_Context* cc,
+bool Document::mouseY(IJS_EventContext* cc,
                       CJS_PropValue& vp,
                       CFX_WideString& sError) {
   return true;
 }
 
-bool Document::URL(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
+bool Document::URL(IJS_EventContext* cc,
+                   CJS_PropValue& vp,
+                   CFX_WideString& sError) {
   if (vp.IsSetting()) {
     sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
     return false;
@@ -996,7 +978,7 @@
   return true;
 }
 
-bool Document::baseURL(IJS_Context* cc,
+bool Document::baseURL(IJS_EventContext* cc,
                        CJS_PropValue& vp,
                        CFX_WideString& sError) {
   if (vp.IsGetting()) {
@@ -1007,7 +989,7 @@
   return true;
 }
 
-bool Document::calculate(IJS_Context* cc,
+bool Document::calculate(IJS_EventContext* cc,
                          CJS_PropValue& vp,
                          CFX_WideString& sError) {
   if (!m_pFormFillEnv) {
@@ -1017,15 +999,15 @@
   CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
   if (vp.IsGetting()) {
     vp << !!pInterForm->IsCalculateEnabled();
-  } else {
-    bool bCalculate;
-    vp >> bCalculate;
-    pInterForm->EnableCalculate(bCalculate);
+    return true;
   }
+  bool bCalculate;
+  vp >> bCalculate;
+  pInterForm->EnableCalculate(bCalculate);
   return true;
 }
 
-bool Document::documentFileName(IJS_Context* cc,
+bool Document::documentFileName(IJS_EventContext* cc,
                                 CJS_PropValue& vp,
                                 CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -1050,7 +1032,7 @@
   return true;
 }
 
-bool Document::path(IJS_Context* cc,
+bool Document::path(IJS_EventContext* cc,
                     CJS_PropValue& vp,
                     CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -1065,40 +1047,40 @@
   return true;
 }
 
-bool Document::pageWindowRect(IJS_Context* cc,
+bool Document::pageWindowRect(IJS_EventContext* cc,
                               CJS_PropValue& vp,
                               CFX_WideString& sError) {
   return true;
 }
 
-bool Document::layout(IJS_Context* cc,
+bool Document::layout(IJS_EventContext* cc,
                       CJS_PropValue& vp,
                       CFX_WideString& sError) {
   return true;
 }
 
-bool Document::addLink(IJS_Context* cc,
+bool Document::addLink(IJS_EventContext* cc,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        CFX_WideString& sError) {
   return true;
 }
 
-bool Document::closeDoc(IJS_Context* cc,
+bool Document::closeDoc(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
   return true;
 }
 
-bool Document::getPageBox(IJS_Context* cc,
+bool Document::getPageBox(IJS_EventContext* cc,
                           const std::vector<CJS_Value>& params,
                           CJS_Value& vRet,
                           CFX_WideString& sError) {
   return true;
 }
 
-bool Document::getAnnot(IJS_Context* cc,
+bool Document::getAnnot(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -1110,8 +1092,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   int nPageNo = params[0].ToInt(pRuntime);
   CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
   CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo);
@@ -1150,7 +1131,7 @@
   return true;
 }
 
-bool Document::getAnnots(IJS_Context* cc,
+bool Document::getAnnots(IJS_EventContext* cc,
                          const std::vector<CJS_Value>& params,
                          CJS_Value& vRet,
                          CFX_WideString& sError) {
@@ -1158,8 +1139,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
 
   // TODO(tonikitoo): Add support supported parameters as per
   // the PDF spec.
@@ -1200,29 +1180,29 @@
   return true;
 }
 
-bool Document::getAnnot3D(IJS_Context* cc,
+bool Document::getAnnot3D(IJS_EventContext* cc,
                           const std::vector<CJS_Value>& params,
                           CJS_Value& vRet,
                           CFX_WideString& sError) {
-  vRet.SetNull(CJS_Runtime::FromContext(cc));
+  vRet.SetNull(CJS_Runtime::FromEventContext(cc));
   return true;
 }
 
-bool Document::getAnnots3D(IJS_Context* cc,
+bool Document::getAnnots3D(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
   return true;
 }
 
-bool Document::getOCGs(IJS_Context* cc,
+bool Document::getOCGs(IJS_EventContext* cc,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        CFX_WideString& sError) {
   return true;
 }
 
-bool Document::getLinks(IJS_Context* cc,
+bool Document::getLinks(IJS_EventContext* cc,
                         const std::vector<CJS_Value>& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
@@ -1234,7 +1214,7 @@
           rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
 }
 
-bool Document::addIcon(IJS_Context* cc,
+bool Document::addIcon(IJS_EventContext* cc,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        CFX_WideString& sError) {
@@ -1243,10 +1223,8 @@
     return false;
   }
 
-  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
-
   if (params[1].GetType() != CJS_Value::VT_object) {
     sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
     return false;
@@ -1269,7 +1247,7 @@
   return true;
 }
 
-bool Document::icons(IJS_Context* cc,
+bool Document::icons(IJS_EventContext* cc,
                      CJS_PropValue& vp,
                      CFX_WideString& sError) {
   if (vp.IsSetting()) {
@@ -1277,7 +1255,7 @@
     return false;
   }
 
-  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   if (m_Icons.empty()) {
     vp.GetJSValue()->SetNull(pRuntime);
     return true;
@@ -1310,7 +1288,7 @@
   return true;
 }
 
-bool Document::getIcon(IJS_Context* cc,
+bool Document::getIcon(IJS_EventContext* cc,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        CFX_WideString& sError) {
@@ -1322,7 +1300,7 @@
   if (m_Icons.empty())
     return false;
 
-  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
 
   for (const auto& pIconElement : m_Icons) {
@@ -1353,7 +1331,7 @@
   return false;
 }
 
-bool Document::removeIcon(IJS_Context* cc,
+bool Document::removeIcon(IJS_EventContext* cc,
                           const std::vector<CJS_Value>& params,
                           CJS_Value& vRet,
                           CFX_WideString& sError) {
@@ -1361,7 +1339,7 @@
   return true;
 }
 
-bool Document::createDataObject(IJS_Context* cc,
+bool Document::createDataObject(IJS_EventContext* cc,
                                 const std::vector<CJS_Value>& params,
                                 CJS_Value& vRet,
                                 CFX_WideString& sError) {
@@ -1369,13 +1347,13 @@
   return true;
 }
 
-bool Document::media(IJS_Context* cc,
+bool Document::media(IJS_EventContext* cc,
                      CJS_PropValue& vp,
                      CFX_WideString& sError) {
   return true;
 }
 
-bool Document::calculateNow(IJS_Context* cc,
+bool Document::calculateNow(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -1393,13 +1371,13 @@
   return true;
 }
 
-bool Document::Collab(IJS_Context* cc,
+bool Document::Collab(IJS_EventContext* cc,
                       CJS_PropValue& vp,
                       CFX_WideString& sError) {
   return true;
 }
 
-bool Document::getPageNthWord(IJS_Context* cc,
+bool Document::getPageNthWord(IJS_EventContext* cc,
                               const std::vector<CJS_Value>& params,
                               CJS_Value& vRet,
                               CFX_WideString& sError) {
@@ -1411,7 +1389,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
     return false;
   }
-  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
 
   // TODO(tsepez): check maximum allowable params.
 
@@ -1458,7 +1436,7 @@
   return true;
 }
 
-bool Document::getPageNthWordQuads(IJS_Context* cc,
+bool Document::getPageNthWordQuads(IJS_EventContext* cc,
                                    const std::vector<CJS_Value>& params,
                                    CJS_Value& vRet,
                                    CFX_WideString& sError) {
@@ -1473,7 +1451,7 @@
   return false;
 }
 
-bool Document::getPageNumWords(IJS_Context* cc,
+bool Document::getPageNumWords(IJS_EventContext* cc,
                                const std::vector<CJS_Value>& params,
                                CJS_Value& vRet,
                                CFX_WideString& sError) {
@@ -1485,7 +1463,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
     return false;
   }
-  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
   CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
   if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
@@ -1510,12 +1488,11 @@
   return true;
 }
 
-bool Document::getPrintParams(IJS_Context* cc,
+bool Document::getPrintParams(IJS_EventContext* cc,
                               const std::vector<CJS_Value>& params,
                               CJS_Value& vRet,
                               CFX_WideString& sError) {
-  CJS_Context* pContext = (CJS_Context*)cc;
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   v8::Local<v8::Object> pRetObj =
       pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID);
 
@@ -1597,7 +1574,7 @@
   return swRet;
 }
 
-bool Document::zoom(IJS_Context* cc,
+bool Document::zoom(IJS_EventContext* cc,
                     CJS_PropValue& vp,
                     CFX_WideString& sError) {
   return true;
@@ -1613,13 +1590,13 @@
 (refW,  ReflowWidth)
 */
 
-bool Document::zoomType(IJS_Context* cc,
+bool Document::zoomType(IJS_EventContext* cc,
                         CJS_PropValue& vp,
                         CFX_WideString& sError) {
   return true;
 }
 
-bool Document::deletePages(IJS_Context* cc,
+bool Document::deletePages(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
@@ -1627,7 +1604,7 @@
   return true;
 }
 
-bool Document::extractPages(IJS_Context* cc,
+bool Document::extractPages(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -1635,7 +1612,7 @@
   return true;
 }
 
-bool Document::insertPages(IJS_Context* cc,
+bool Document::insertPages(IJS_EventContext* cc,
                            const std::vector<CJS_Value>& params,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
@@ -1643,7 +1620,7 @@
   return true;
 }
 
-bool Document::replacePages(IJS_Context* cc,
+bool Document::replacePages(IJS_EventContext* cc,
                             const std::vector<CJS_Value>& params,
                             CJS_Value& vRet,
                             CFX_WideString& sError) {
@@ -1651,7 +1628,7 @@
   return true;
 }
 
-bool Document::getURL(IJS_Context* cc,
+bool Document::getURL(IJS_EventContext* cc,
                       const std::vector<CJS_Value>& params,
                       CJS_Value& vRet,
                       CFX_WideString& sError) {
@@ -1659,7 +1636,7 @@
   return true;
 }
 
-bool Document::gotoNamedDest(IJS_Context* cc,
+bool Document::gotoNamedDest(IJS_EventContext* cc,
                              const std::vector<CJS_Value>& params,
                              CJS_Value& vRet,
                              CFX_WideString& sError) {
@@ -1671,7 +1648,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
   CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
   CFX_ByteString utf8Name = wideName.UTF8Encode();
   CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();