summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/include/jsapi/fxjs_v8.h2
-rw-r--r--fpdfsdk/src/javascript/Document.cpp4
-rw-r--r--fpdfsdk/src/javascript/Field.cpp18
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp44
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp2
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp22
6 files changed, 26 insertions, 66 deletions
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 3499bfbfea..a1541593a1 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index bccf08b271..105e487e1c 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -1467,7 +1467,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;
@@ -1511,7 +1511,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;
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 52f6321f4a..266f29592a 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -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;
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index bd762b4946..553fc95631 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -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;
}
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index bbe9f6e8c8..643cefb92f 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -205,7 +205,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);
}
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 190641131a..6349ca3a6f 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -497,13 +497,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,
@@ -519,24 +512,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) {