Mising JS refactoring in XFA.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1463973002 .
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 3b5e6af..8263cd4 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -136,13 +136,13 @@
                          v8::Global<v8::Context>* pV8PersistentContext,
                          std::vector<v8::Global<v8::Object>*>* pStaticObjects);
 
+IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate);
+
 // Called as part of FXJS_InitializeRuntime, exposed so PDF can make its
 // own contexts compatible with XFA or vice versa.
 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
                                  IJS_Runtime* pIRuntime);
 
-IJS_Runtime* FXJS_GetRuntimeFromV8Context(v8::Local<v8::Context> v8Context);
-
 // Called after FXJS_InitializeRuntime call made.
 int FXJS_Execute(v8::Isolate* pIsolate,
                  IJS_Context* pJSContext,
diff --git a/fpdfsdk/src/javascript/JS_Define.h b/fpdfsdk/src/javascript/JS_Define.h
index 740295e..02b36f9 100644
--- a/fpdfsdk/src/javascript/JS_Define.h
+++ b/fpdfsdk/src/javascript/JS_Define.h
@@ -78,8 +78,8 @@
                   v8::Local<v8::String> property,
                   const v8::PropertyCallbackInfo<v8::Value>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -104,8 +104,8 @@
                   v8::Local<v8::Value> value,
                   const v8::PropertyCallbackInfo<void>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -143,8 +143,8 @@
               const char* class_name_string,
               const v8::FunctionCallbackInfo<v8::Value>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -366,8 +366,8 @@
                       v8::Local<v8::String> property,
                       const v8::PropertyCallbackInfo<v8::Value>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -393,8 +393,8 @@
                       v8::Local<v8::Value> value,
                       const v8::PropertyCallbackInfo<v8::Value>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -417,8 +417,7 @@
                       v8::Local<v8::String> property,
                       const v8::PropertyCallbackInfo<v8::Boolean>& info) {
   v8::Isolate* isolate = info.GetIsolate();
-  IJS_Runtime* pRuntime =
-      FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext());
+  IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
@@ -442,8 +441,8 @@
                        CFX_WideString&)>
 void JSGlobalFunc(const char* func_name_string,
                   const v8::FunctionCallbackInfo<v8::Value>& info) {
-  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(
-      FXJS_GetRuntimeFromV8Context(info.GetIsolate()->GetCurrentContext()));
+  CJS_Runtime* pRuntime =
+      static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate()));
   if (!pRuntime)
     return;
   IJS_Context* pContext = pRuntime->GetCurrentContext();
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index a3100be..9c2c538 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -288,7 +288,7 @@
   v8::Context::Scope context_scope(v8Context);
 
   FXJS_PerIsolateData::SetUp(pIsolate);
-  FXJS_SetRuntimeForV8Context(v8Context, pIRuntime);
+  v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
 
   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
   pStaticObjects->resize(maxID + 1);
@@ -366,16 +366,17 @@
   delete pData;
 }
 
+IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
+  v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
+  return static_cast<IJS_Runtime*>(
+      context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
+}
+
 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
                                  IJS_Runtime* pIRuntime) {
   v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
 }
 
-IJS_Runtime* FXJS_GetRuntimeFromV8Context(v8::Local<v8::Context> v8Context) {
-  return static_cast<IJS_Runtime*>(
-      v8Context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
-}
-
 int FXJS_Execute(v8::Isolate* pIsolate,
                  IJS_Context* pJSContext,
                  const wchar_t* script,