Don't pass null isolates to FXJS_ when we have a real isolate.
authorTom Sepez <tsepez@chromium.org>
Thu, 17 Sep 2015 22:30:14 +0000 (15:30 -0700)
committerTom Sepez <tsepez@chromium.org>
Thu, 17 Sep 2015 22:30:14 +0000 (15:30 -0700)
Kill some now unused functions as a result.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1350703003 .

fpdfsdk/include/jsapi/fxjs_v8.h
fpdfsdk/src/javascript/Document.cpp
fpdfsdk/src/javascript/Field.cpp
fpdfsdk/src/javascript/JS_EventHandler.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/jsapi/fxjs_v8.cpp

index 3499bfb..a154159 100644 (file)
@@ -125,9 +125,7 @@ const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj);
 void FXJS_SetPrivate(v8::Isolate* pIsolate,
                      v8::Local<v8::Object> pObj,
                      void* p);
-void FXJS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj);
-void* FXJS_GetPrivate(v8::Local<v8::Object> pObj);
 void FXJS_FreePrivate(void* p);
 void FXJS_FreePrivate(v8::Local<v8::Object> pObj);
 
index 27a3971..796fddb 100644 (file)
@@ -1428,7 +1428,7 @@ FX_BOOL Document::icons(IFXJS_Context* cc,
     if (pObj.IsEmpty())
       return FALSE;
 
-    CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
+    CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
     if (!pJS_Icon)
       return FALSE;
 
@@ -1472,7 +1472,7 @@ FX_BOOL Document::getIcon(IFXJS_Context* cc,
       if (pObj.IsEmpty())
         return FALSE;
 
-      CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
+      CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
       if (!pJS_Icon)
         return FALSE;
 
index 66a9601..140bb42 100644 (file)
@@ -3300,8 +3300,6 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc,
     return FALSE;
 
   CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
-  ASSERT(pFormField != NULL);
-
   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
     return FALSE;
 
@@ -3310,17 +3308,13 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc,
     return FALSE;
 
   CJS_Context* pContext = (CJS_Context*)cc;
-  ASSERT(pContext != NULL);
-
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  ASSERT(pRuntime != NULL);
-
   v8::Local<v8::Object> pObj =
       FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
                            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
   ASSERT(pObj.IsEmpty() == FALSE);
 
-  CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
+  CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
   Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
 
   CPDF_Stream* pIconStream = NULL;
@@ -3339,8 +3333,6 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc,
   return TRUE;
 }
 
-//#pragma warning(default: 4800)
-
 FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc,
                                 const CJS_Parameters& params,
                                 CJS_Value& vRet,
@@ -3526,22 +3518,20 @@ FX_BOOL Field::getArray(IFXJS_Context* cc,
 
   CJS_Array FormFieldArray(m_isolate);
   for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
-    CFX_WideString* pStr = swSort.GetAt(j);
-
+    nonstd::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
     v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
         pRuntime->GetIsolate(), pContext,
         FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
     ASSERT(pObj.IsEmpty() == FALSE);
 
-    CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pObj);
+    CJS_Field* pJSField =
+        (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
     Field* pField = (Field*)pJSField->GetEmbedObject();
     pField->AttachField(m_pJSDoc, *pStr);
 
     CJS_Value FormFieldValue(m_isolate);
     FormFieldValue = pJSField;
     FormFieldArray.SetElement(j, FormFieldValue);
-
-    delete pStr;
   }
 
   vRet = FormFieldArray;
index bd762b4..553fc95 100644 (file)
@@ -611,10 +611,7 @@ FX_BOOL CJS_EventHandler::Shift() {
 }
 
 Field* CJS_EventHandler::Source() {
-  ASSERT(m_pJSContext != NULL);
-
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
-
   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
       pRuntime->GetIsolate(), m_pJSContext,
       FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
@@ -624,32 +621,21 @@ Field* CJS_EventHandler::Source() {
                            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
   ASSERT(pFieldObj.IsEmpty() == FALSE);
 
-  CJS_Document* pJSDocument = (CJS_Document*)FXJS_GetPrivate(pDocObj);
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  if (m_pTargetDoc != NULL)
-    pDocument->AttachDoc(m_pTargetDoc);
-  else
-    pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
-  // if (m_pSourceField == NULL)
-  //  return NULL;
-  // CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
-  // CPDF_FormField* pFormField = pWidget->GetFormField();
-  // ASSERT(pFormField);
-  // CFX_WideString csFieldName = pFormField->GetFullName();
-  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pFieldObj);
-  ASSERT(pJSField != NULL);
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
+
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
   Field* pField = (Field*)pJSField->GetEmbedObject();
-  ASSERT(pField != NULL);
   pField->AttachField(pDocument, m_strSourceName);
   return pField;
 }
 
 Field* CJS_EventHandler::Target_Field() {
-  ASSERT(m_pJSContext != NULL);
-
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
-
   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
       pRuntime->GetIsolate(), m_pJSContext,
       FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
@@ -659,19 +645,15 @@ Field* CJS_EventHandler::Target_Field() {
                            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
   ASSERT(pFieldObj.IsEmpty() == FALSE);
 
-  CJS_Document* pJSDocument = (CJS_Document*)FXJS_GetPrivate(pDocObj);
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  if (m_pTargetDoc != NULL)
-    pDocument->AttachDoc(m_pTargetDoc);
-  else
-    pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
-  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pFieldObj);
-  ASSERT(pJSField != NULL);
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
 
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
   Field* pField = (Field*)pJSField->GetEmbedObject();
-  ASSERT(pField != NULL);
-
   pField->AttachField(pDocument, m_strTargetName);
   return pField;
 }
index 81f9462..edc8c25 100644 (file)
@@ -184,7 +184,7 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
         if (FXJS_GetObjDefnID(pThis) ==
             FXJS_GetObjDefnID(GetIsolate(), L"Document")) {
           if (CJS_Document* pJSDocument =
-                  (CJS_Document*)FXJS_GetPrivate(pThis)) {
+                  (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
             if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
               pDocument->AttachDoc(pReaderDoc);
           }
index 381bfba..69ea2cb 100644 (file)
@@ -489,13 +489,6 @@ const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj) {
     return kFXJSValueNameUndefined;
   return NULL;
 }
-void FXJS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {
-  FXJS_SetPrivate(NULL, pObj, p);
-}
-
-void* FXJS_GetPrivate(v8::Local<v8::Object> pObj) {
-  return FXJS_GetPrivate(NULL, pObj);
-}
 
 void FXJS_SetPrivate(v8::Isolate* pIsolate,
                      v8::Local<v8::Object> pObj,
@@ -511,24 +504,21 @@ void FXJS_SetPrivate(v8::Isolate* pIsolate,
 
 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty())
-    return NULL;
-  CFXJS_PrivateData* pPrivateData = NULL;
-  if (pObj->InternalFieldCount())
+    return nullptr;
+  CFXJS_PrivateData* pPrivateData = nullptr;
+  if (pObj->InternalFieldCount()) {
     pPrivateData =
         (CFXJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
-  else {
+  } else {
     // It could be a global proxy object.
     v8::Local<v8::Value> v = pObj->GetPrototype();
-    v8::Isolate* isolate = (v8::Isolate*)pIsolate;
-    v8::Local<v8::Context> context = isolate->GetCurrentContext();
+    v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
     if (v->IsObject())
       pPrivateData = (CFXJS_PrivateData*)v->ToObject(context)
                          .ToLocalChecked()
                          ->GetAlignedPointerFromInternalField(0);
   }
-  if (!pPrivateData)
-    return NULL;
-  return pPrivateData->pPrivate;
+  return pPrivateData ? pPrivateData->pPrivate : nullptr;
 }
 
 void FXJS_FreePrivate(void* pPrivateData) {