summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp64
-rw-r--r--fpdfsdk/src/javascript/Consts.h4
-rw-r--r--fpdfsdk/src/javascript/Document.cpp67
-rw-r--r--fpdfsdk/src/javascript/Field.cpp104
-rw-r--r--fpdfsdk/src/javascript/JS_Define.h38
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp11
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Value.cpp173
-rw-r--r--fpdfsdk/src/javascript/JS_Value.h51
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp136
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.h2
-rw-r--r--fpdfsdk/src/javascript/app.cpp83
-rw-r--r--fpdfsdk/src/javascript/color.cpp81
-rw-r--r--fpdfsdk/src/javascript/global.cpp20
-rw-r--r--fpdfsdk/src/javascript/global.h7
-rw-r--r--fpdfsdk/src/javascript/util.cpp21
16 files changed, 377 insertions, 487 deletions
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index 3381978caf..d71c71129d 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -129,62 +129,62 @@ IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
/* ------------------------------ CJS_GlobalConsts ------------------------- */
-static void DefineGlobalConstString(v8::Isolate* pIsolate,
+static void DefineGlobalConstString(CJS_Runtime* pRuntime,
const wchar_t* pConstName,
const wchar_t* pValue) {
- FXJS_DefineGlobalConst(pIsolate, pConstName,
- FXJS_NewString(pIsolate, pValue));
+ FXJS_DefineGlobalConst(pRuntime->GetIsolate(), pConstName,
+ FXJS_NewString(pRuntime->GetIsolate(), pValue));
}
-void CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
+void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) {
DefineGlobalConstString(
- pIsolate, L"IDS_GREATER_THAN",
+ pRuntime, L"IDS_GREATER_THAN",
L"Invalid value: must be greater than or equal to % s.");
DefineGlobalConstString(
- pIsolate, L"IDS_GT_AND_LT",
+ pRuntime, L"IDS_GT_AND_LT",
L"Invalid value: must be greater than or equal to % s "
L"and less than or equal to % s.");
- DefineGlobalConstString(pIsolate, L"IDS_LESS_THAN",
+ DefineGlobalConstString(pRuntime, L"IDS_LESS_THAN",
L"Invalid value: must be less than or equal to % s.");
- DefineGlobalConstString(pIsolate, L"IDS_INVALID_MONTH", L"**Invalid**");
+ DefineGlobalConstString(pRuntime, L"IDS_INVALID_MONTH", L"**Invalid**");
DefineGlobalConstString(
- pIsolate, L"IDS_INVALID_DATE",
+ pRuntime, L"IDS_INVALID_DATE",
L"Invalid date / time: please ensure that the date / time exists.Field");
DefineGlobalConstString(
- pIsolate, L"IDS_INVALID_VALUE",
+ pRuntime, L"IDS_INVALID_VALUE",
L"The value entered does not match the format of the field");
- DefineGlobalConstString(pIsolate, L"IDS_AM", L"am");
- DefineGlobalConstString(pIsolate, L"IDS_PM", L"pm");
+ DefineGlobalConstString(pRuntime, L"IDS_AM", L"am");
+ DefineGlobalConstString(pRuntime, L"IDS_PM", L"pm");
DefineGlobalConstString(
- pIsolate, L"IDS_MONTH_INFO",
+ pRuntime, L"IDS_MONTH_INFO",
L"January[1] February[2] March[3] April[4] May[5] "
L"June[6] July[7] August[8] September[9] October[10] "
L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] "
L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] "
L"Dec[12]");
- DefineGlobalConstString(pIsolate, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **");
+ DefineGlobalConstString(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **");
}
/* ------------------------------ CJS_GlobalArrays ------------------------ */
-void DefineGlobalConstStringArray(v8::Isolate* pIsolate,
+void DefineGlobalConstStringArray(CJS_Runtime* pRuntime,
const wchar_t* sConstName,
const wchar_t** pValues,
size_t nValues) {
- CJS_Array array(pIsolate);
+ CJS_Array array(pRuntime);
for (size_t i = 0; i < nValues; ++i) {
- array.SetElement(i, CJS_Value(pIsolate, pValues[i]));
+ array.SetElement(i, CJS_Value(pRuntime, pValues[i]));
}
- CJS_PropValue prop(pIsolate);
+ CJS_PropValue prop(pRuntime);
prop << array;
- FXJS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value());
+ FXJS_DefineGlobalConst(pRuntime->GetIsolate(), sConstName, prop.ToV8Value());
}
-void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
+void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) {
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -195,7 +195,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?\\.\\d+", /* -.1 */
L"[+-]?\\d+\\." /* -1. */
};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -203,7 +203,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -214,35 +214,35 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?[.,]\\d+", /* -,1 */
L"[+-]?\\d+[.,]" /* -1, */
};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -261,7 +261,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
*/
L"011(\\.|[- \\d])*" /* international */
};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -273,7 +273,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
L"011(\\.|[- \\d])*" /* international */
};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -281,7 +281,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY";
const FX_WCHAR* ArrayContent[] = {
L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
@@ -289,7 +289,7 @@ void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT";
const FX_WCHAR* ArrayContent[] = {
L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
- DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ DefineGlobalConstStringArray(pRuntime, ArrayName, ArrayContent,
FX_ArraySize(ArrayContent));
}
}
diff --git a/fpdfsdk/src/javascript/Consts.h b/fpdfsdk/src/javascript/Consts.h
index a1d36f8877..57c843e660 100644
--- a/fpdfsdk/src/javascript/Consts.h
+++ b/fpdfsdk/src/javascript/Consts.h
@@ -103,14 +103,14 @@ class CJS_Zoomtype : public CJS_Object {
class CJS_GlobalConsts : public CJS_Object {
public:
- static void DefineJSObjects(v8::Isolate* pIsolate);
+ static void DefineJSObjects(CJS_Runtime* pRuntime);
};
/* ------------------------------ CJS_GlobalArrays -------------------------- */
class CJS_GlobalArrays : public CJS_Object {
public:
- static void DefineJSObjects(v8::Isolate* pIsolate);
+ static void DefineJSObjects(CJS_Runtime* pRuntmie);
};
#endif // FPDFSDK_SRC_JAVASCRIPT_CONSTS_H_
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 1719c443a9..7c1f5775d2 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -566,8 +566,6 @@ FX_BOOL Document::resetForm(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
-
if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
@@ -575,13 +573,9 @@ FX_BOOL Document::resetForm(IJS_Context* cc,
CPDFSDK_InterForm* pInterForm =
(CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aName(isolate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array aName(pRuntime);
if (params.size() > 0) {
switch (params[0].GetType()) {
@@ -596,10 +590,9 @@ FX_BOOL Document::resetForm(IJS_Context* cc,
CFX_PtrArray aFields;
for (int i = 0, isz = aName.GetLength(); i < isz; i++) {
- CJS_Value valElement(isolate);
+ CJS_Value valElement(pRuntime);
aName.GetElement(i, valElement);
CFX_WideString swVal = valElement.ToCFXWideString();
-
for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) {
aFields.Add((void*)pPDFForm->GetField(j, swVal));
}
@@ -629,7 +622,6 @@ FX_BOOL Document::submitForm(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
CJS_Context* pContext = (CJS_Context*)cc;
int nSize = params.size();
if (nSize < 1) {
@@ -637,11 +629,12 @@ FX_BOOL Document::submitForm(IJS_Context* cc,
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ v8::Isolate* isolate = pRuntime->GetIsolate();
+ CJS_Array aFields(pRuntime);
CFX_WideString strURL;
FX_BOOL bFDF = TRUE;
FX_BOOL bEmpty = FALSE;
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aFields(isolate);
CJS_Value v = params[0];
if (v.GetType() == CJS_Value::VT_string) {
@@ -657,17 +650,19 @@ FX_BOOL Document::submitForm(IJS_Context* cc,
v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL");
if (!pValue.IsEmpty())
strURL =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF");
- bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+
pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty");
- bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+
pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
aFields.Attach(
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
}
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CPDFSDK_InterForm* pInterForm =
(CPDFSDK_InterForm*)m_pDocument->GetInterForm();
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
@@ -683,7 +678,7 @@ FX_BOOL Document::submitForm(IJS_Context* cc,
CFX_PtrArray fieldObjects;
for (int i = 0, sz = aFields.GetLength(); i < sz; i++) {
- CJS_Value valName(isolate);
+ CJS_Value valName(pRuntime);
aFields.GetElement(i, valName);
CFX_WideString sName = valName.ToCFXWideString();
@@ -735,8 +730,6 @@ FX_BOOL Document::mailDoc(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
-
FX_BOOL bUI = TRUE;
CFX_WideString cTo = L"";
CFX_WideString cCc = L"";
@@ -757,36 +750,34 @@ FX_BOOL Document::mailDoc(IJS_Context* cc,
if (params.size() >= 6)
cMsg = params[5].ToCFXWideString();
- v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ v8::Isolate* isolate = pRuntime->GetIsolate();
if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
v8::Local<v8::Object> pObj = params[0].ToV8Object();
v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
- bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt();
+ bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
- cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
- cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
- cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cBcc =
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
cSubject =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
- cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cMsg =
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
}
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
pRuntime->BeginBlock();
CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
@@ -1403,13 +1394,11 @@ FX_BOOL Document::icons(IJS_Context* cc,
return TRUE;
}
- CJS_Array Icons(m_isolate);
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array Icons(pRuntime);
IconElement* pIconElement = NULL;
int iIconTreeLength = m_pIconTree->GetLength();
-
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
for (int i = 0; i < iIconTreeLength; i++) {
pIconElement = (*m_pIconTree)[i];
@@ -1428,7 +1417,7 @@ FX_BOOL Document::icons(IJS_Context* cc,
pIcon->SetStream(pIconElement->IconStream->GetStream());
pIcon->SetIconName(pIconElement->IconName);
- Icons.SetElement(i, CJS_Value(m_isolate, pJS_Icon));
+ Icons.SetElement(i, CJS_Value(pRuntime, pJS_Icon));
}
vp << Icons;
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index fce9aecc29..56fc56b206 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -1031,7 +1031,7 @@ void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
FX_BOOL Field::currentValueIndices(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -1044,8 +1044,8 @@ FX_BOOL Field::currentValueIndices(IJS_Context* cc,
vp >> iSelecting;
array.Add(iSelecting);
} else if (vp.IsArrayObject()) {
- CJS_Array SelArray(m_isolate);
- CJS_Value SelValue(m_isolate);
+ CJS_Array SelArray(pRuntime);
+ CJS_Value SelValue(pRuntime);
int iSelecting;
vp >> SelArray;
for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
@@ -1077,10 +1077,10 @@ FX_BOOL Field::currentValueIndices(IJS_Context* cc,
if (pFormField->CountSelectedItems() == 1)
vp << pFormField->GetSelectedIndex(0);
else if (pFormField->CountSelectedItems() > 1) {
- CJS_Array SelArray(m_isolate);
+ CJS_Array SelArray(pRuntime);
for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
SelArray.SetElement(
- i, CJS_Value(m_isolate, pFormField->GetSelectedIndex(i)));
+ i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
}
vp << SelArray;
} else
@@ -1489,8 +1489,6 @@ FX_BOOL Field::editable(IJS_Context* cc,
FX_BOOL Field::exportValues(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
-
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0)
@@ -1508,12 +1506,13 @@ FX_BOOL Field::exportValues(IJS_Context* cc,
if (!vp.IsArrayObject())
return FALSE;
} else {
- CJS_Array ExportValusArray(m_isolate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array ExportValusArray(pRuntime);
if (m_nFormControlIndex < 0) {
for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
CPDF_FormControl* pFormControl = pFormField->GetControl(i);
ExportValusArray.SetElement(
- i, CJS_Value(m_isolate, pFormControl->GetExportValue().c_str()));
+ i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
}
} else {
if (m_nFormControlIndex >= pFormField->CountControls())
@@ -1525,7 +1524,7 @@ FX_BOOL Field::exportValues(IJS_Context* cc,
return FALSE;
ExportValusArray.SetElement(
- 0, CJS_Value(m_isolate, pFormControl->GetExportValue().c_str()));
+ 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
}
vp << ExportValusArray;
}
@@ -1564,10 +1563,8 @@ FX_BOOL Field::fileSelect(IJS_Context* cc,
FX_BOOL Field::fillColor(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
-
- CJS_Array crArray(m_isolate);
-
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array crArray(pRuntime);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0)
@@ -2021,23 +2018,20 @@ FX_BOOL Field::name(IJS_Context* cc,
FX_BOOL Field::numItems(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
+ if (!vp.IsGetting())
+ return FALSE;
+
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0)
return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return FALSE;
- if (!vp.IsGetting())
- return FALSE;
-
vp << (int32_t)pFormField->CountOptions();
-
return TRUE;
}
@@ -2056,28 +2050,22 @@ FX_BOOL Field::page(IJS_Context* cc,
if (!pFormField)
return FALSE;
- ASSERT(m_pDocument != NULL);
-
+ CFX_PtrArray widgetArray;
CPDFSDK_InterForm* pInterForm =
(CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgetArray;
pInterForm->GetWidgets(pFormField, widgetArray);
if (widgetArray.GetSize() > 0) {
- CJS_Array PageArray(m_isolate);
-
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array PageArray(pRuntime);
for (int i = 0, sz = widgetArray.GetSize(); i < sz; i++) {
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
- ASSERT(pWidget != NULL);
-
CPDFSDK_PageView* pPageView = pWidget->GetPageView();
if (!pPageView)
return FALSE;
PageArray.SetElement(
- i, CJS_Value(m_isolate, (int32_t)pPageView->GetPageIndex()));
+ i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
}
vp << PageArray;
@@ -2284,7 +2272,11 @@ FX_BOOL Field::readonly(IJS_Context* cc,
FX_BOOL Field::rect(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Value Upper_Leftx(pRuntime);
+ CJS_Value Upper_Lefty(pRuntime);
+ CJS_Value Lower_Rightx(pRuntime);
+ CJS_Value Lower_Righty(pRuntime);
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -2292,10 +2284,8 @@ FX_BOOL Field::rect(IJS_Context* cc,
if (!vp.IsArrayObject())
return FALSE;
- CJS_Array rcArray(m_isolate);
+ CJS_Array rcArray(pRuntime);
vp >> rcArray;
- CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate),
- Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
rcArray.GetElement(0, Upper_Leftx);
rcArray.GetElement(1, Upper_Lefty);
rcArray.GetElement(2, Lower_Rightx);
@@ -2308,7 +2298,6 @@ FX_BOOL Field::rect(IJS_Context* cc,
pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
CPDF_Rect crRect(pArray);
-
if (m_bDelay) {
AddDelay_Rect(FP_RECT, crRect);
} else {
@@ -2321,34 +2310,26 @@ FX_BOOL Field::rect(IJS_Context* cc,
return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
CPDFSDK_InterForm* pInterForm =
(CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
CPDFSDK_Widget* pWidget =
pInterForm->GetWidget(GetSmartFieldControl(pFormField));
if (!pWidget)
return FALSE;
CFX_FloatRect crRect = pWidget->GetRect();
- CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate),
- Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
Upper_Leftx = (int32_t)crRect.left;
Upper_Lefty = (int32_t)crRect.top;
Lower_Rightx = (int32_t)crRect.right;
Lower_Righty = (int32_t)crRect.bottom;
- CJS_Array rcArray(m_isolate);
+ CJS_Array rcArray(pRuntime);
rcArray.SetElement(0, Upper_Leftx);
rcArray.SetElement(1, Upper_Lefty);
rcArray.SetElement(2, Lower_Rightx);
rcArray.SetElement(3, Lower_Righty);
-
vp << rcArray;
}
-
return TRUE;
}
@@ -2572,7 +2553,8 @@ void Field::SetRotation(CPDFSDK_Document* pDocument,
FX_BOOL Field::strokeColor(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array crArray(pRuntime);
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -2581,7 +2563,6 @@ FX_BOOL Field::strokeColor(IJS_Context* cc,
if (!vp.IsArrayObject())
return FALSE;
- CJS_Array crArray(m_isolate);
vp >> crArray;
CPWL_Color color;
@@ -2600,8 +2581,6 @@ FX_BOOL Field::strokeColor(IJS_Context* cc,
return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)
return FALSE;
@@ -2610,7 +2589,6 @@ FX_BOOL Field::strokeColor(IJS_Context* cc,
pFormControl->GetBorderColor(iColorType);
CPWL_Color color;
-
if (iColorType == COLORTYPE_TRANSPARENT) {
color = CPWL_Color(COLORTYPE_TRANSPARENT);
} else if (iColorType == COLORTYPE_GRAY) {
@@ -2629,11 +2607,9 @@ FX_BOOL Field::strokeColor(IJS_Context* cc,
} else
return FALSE;
- CJS_Array crArray(m_isolate);
color::ConvertPWLColorToArray(color, crArray);
vp << crArray;
}
-
return TRUE;
}
@@ -2724,15 +2700,16 @@ FX_BOOL Field::submitName(IJS_Context* cc,
FX_BOOL Field::textColor(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array crArray(pRuntime);
if (vp.IsSetting()) {
if (!m_bCanSet)
return FALSE;
- CJS_Array crArray(m_isolate);
if (!vp.IsArrayObject())
return FALSE;
+
vp >> crArray;
CPWL_Color color;
@@ -2750,8 +2727,6 @@ FX_BOOL Field::textColor(IJS_Context* cc,
return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)
return FALSE;
@@ -2770,11 +2745,9 @@ FX_BOOL Field::textColor(IJS_Context* cc,
if (iColorType == COLORTYPE_TRANSPARENT)
crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
- CJS_Array crArray(m_isolate);
color::ConvertPWLColorToArray(crRet, crArray);
vp << crArray;
}
-
return TRUE;
}
@@ -2983,7 +2956,7 @@ void Field::SetUserName(CPDFSDK_Document* pDocument,
FX_BOOL Field::value(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- ASSERT(m_pDocument != NULL);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -2992,17 +2965,16 @@ FX_BOOL Field::value(IJS_Context* cc,
CJS_WideStringArray strArray;
if (vp.IsArrayObject()) {
- CJS_Array ValueArray(m_isolate);
+ CJS_Array ValueArray(pRuntime);
vp.ConvertToArray(ValueArray);
for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
- CJS_Value ElementValue(m_isolate);
+ CJS_Value ElementValue(pRuntime);
ValueArray.GetElement(i, ElementValue);
strArray.Add(ElementValue.ToCFXWideString());
}
} else {
CFX_WideString swValue;
vp >> swValue;
-
strArray.Add(swValue);
}
@@ -3018,8 +2990,6 @@ FX_BOOL Field::value(IJS_Context* cc,
return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
switch (pFormField->GetFieldType()) {
case FIELDTYPE_PUSHBUTTON:
return FALSE;
@@ -3040,8 +3010,8 @@ FX_BOOL Field::value(IJS_Context* cc,
} break;
case FIELDTYPE_LISTBOX: {
if (pFormField->CountSelectedItems() > 1) {
- CJS_Array ValueArray(m_isolate);
- CJS_Value ElementValue(m_isolate);
+ CJS_Array ValueArray(pRuntime);
+ CJS_Value ElementValue(pRuntime);
int iIndex;
for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
iIndex = pFormField->GetSelectedIndex(i);
@@ -3514,7 +3484,7 @@ FX_BOOL Field::getArray(IJS_Context* cc,
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
ASSERT(pRuntime != NULL);
- CJS_Array FormFieldArray(m_isolate);
+ CJS_Array FormFieldArray(pRuntime);
for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
nonstd::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
@@ -3526,7 +3496,7 @@ FX_BOOL Field::getArray(IJS_Context* cc,
Field* pField = (Field*)pJSField->GetEmbedObject();
pField->AttachField(m_pJSDoc, *pStr);
- CJS_Value FormFieldValue(m_isolate);
+ CJS_Value FormFieldValue(pRuntime);
FormFieldValue = pJSField;
FormFieldArray.SetElement(j, FormFieldValue);
}
diff --git a/fpdfsdk/src/javascript/JS_Define.h b/fpdfsdk/src/javascript/JS_Define.h
index 766bf4baba..cb39841c53 100644
--- a/fpdfsdk/src/javascript/JS_Define.h
+++ b/fpdfsdk/src/javascript/JS_Define.h
@@ -79,14 +79,15 @@ void JSPropGetter(const char* prop_name_string,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
- CJS_PropValue value(isolate);
+ CJS_PropValue value(pRuntime);
value.StartGetting();
if (!(pObj->*M)(pContext, value, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
@@ -105,14 +106,15 @@ void JSPropSetter(const char* prop_name_string,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
- CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
+ CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
propValue.StartSetting();
if (!(pObj->*M)(pContext, propValue, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
@@ -143,15 +145,16 @@ void JSMethod(const char* method_name_string,
const char* class_name_string,
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
IJS_Context* cc = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
- parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
+ parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
}
- CJS_Value valueRes(isolate);
+ CJS_Value valueRes(pRuntime);
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
@@ -365,7 +368,8 @@ void JSSpecialPropGet(const char* class_name,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
@@ -376,7 +380,7 @@ void JSSpecialPropGet(const char* class_name,
CFX_WideString propname =
CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
CFX_WideString sError;
- CJS_PropValue value(isolate);
+ CJS_PropValue value(pRuntime);
value.StartGetting();
if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
@@ -391,7 +395,8 @@ void JSSpecialPropPut(const char* class_name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
@@ -402,7 +407,7 @@ void JSSpecialPropPut(const char* class_name,
CFX_WideString propname =
CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
CFX_WideString sError;
- CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
+ CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
PropValue.StartSetting();
if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
@@ -438,19 +443,20 @@ template <FX_BOOL (*F)(IJS_Context* cc,
CFX_WideString& sError)>
void JSGlobalFunc(const char* func_name_string,
const v8::FunctionCallbackInfo<v8::Value>& info) {
- v8::Isolate* isolate = info.GetIsolate();
- IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
+ CJS_Runtime* pRuntime =
+ static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate()));
if (!pRuntime)
return;
IJS_Context* cc = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
- parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
+ parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
}
- CJS_Value valueRes(isolate);
+ CJS_Value valueRes(pRuntime);
CFX_WideString sError;
if (!(*F)(cc, parameters, valueRes, sError)) {
- FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
+ FXJS_Error(pRuntime->GetIsolate(),
+ JSFormatErrorString(func_name_string, nullptr, sError));
return;
}
info.GetReturnValue().Set(valueRes.ToV8Value());
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index fcf6ee8795..83e2c9af2a 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -29,10 +29,17 @@
/* ------------------------------ CJS_Runtime ------------------------------ */
+// static
IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) {
return new CJS_Runtime(pEnv);
}
+// static
+CJS_Runtime* CJS_Runtime::FromContext(const IJS_Context* cc) {
+ const CJS_Context* pContext = static_cast<const CJS_Context*>(cc);
+ return pContext->GetJSRuntime();
+}
+
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
: m_pApp(pApp),
m_pDocument(NULL),
@@ -115,8 +122,8 @@ void CJS_Runtime::DefineJSObjects() {
// ObjDefIDs 18 - 20 (these can't fail, return void).
CJS_PublicMethods::DefineJSObjects(GetIsolate());
- CJS_GlobalConsts::DefineJSObjects(GetIsolate());
- CJS_GlobalArrays::DefineJSObjects(GetIsolate());
+ CJS_GlobalConsts::DefineJSObjects(this);
+ CJS_GlobalArrays::DefineJSObjects(this);
// ObjDefIDs 21 - 22.
CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h
index 2b7cb3767f..8cbec38fc6 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.h
+++ b/fpdfsdk/src/javascript/JS_Runtime.h
@@ -29,6 +29,8 @@ class CJS_Runtime : public IJS_Runtime {
using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>;
+ static CJS_Runtime* FromContext(const IJS_Context* cc);
+
explicit CJS_Runtime(CPDFDoc_Environment* pApp);
~CJS_Runtime() override;
diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp
index 94b5ff6e8c..a5844c1d58 100644
--- a/fpdfsdk/src/javascript/JS_Value.cpp
+++ b/fpdfsdk/src/javascript/JS_Value.cpp
@@ -21,61 +21,63 @@ static double GetNan() {
/* ---------------------------- CJS_Value ---------------------------- */
-CJS_Value::CJS_Value(v8::Isolate* isolate)
- : m_eType(VT_unknown), m_isolate(isolate) {}
-CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t)
- : m_eType(t), m_pValue(pValue), m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime)
+ : m_eType(VT_unknown), m_pJSRuntime(pRuntime) {
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const int& iValue)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t)
+ : m_eType(t), m_pValue(pValue), m_pJSRuntime(pRuntime) {
+}
+
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue)
+ : m_pJSRuntime(pRuntime) {
operator=(iValue);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const bool& bValue)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue)
+ : m_pJSRuntime(pRuntime) {
operator=(bValue);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const float& fValue)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue)
+ : m_pJSRuntime(pRuntime) {
operator=(fValue);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const double& dValue)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue)
+ : m_pJSRuntime(pRuntime) {
operator=(dValue);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object> pJsObj)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object> pJsObj)
+ : m_pJSRuntime(pRuntime) {
operator=(pJsObj);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object* pJsObj)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pJsObj)
+ : m_pJSRuntime(pRuntime) {
operator=(pJsObj);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Document* pJsDoc)
+ : m_pJSRuntime(pRuntime) {
m_eType = VT_object;
if (pJsDoc)
m_pValue = pJsDoc->ToV8Object();
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr)
+ : m_pJSRuntime(pRuntime) {
operator=(pWstr);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr)
+ : m_pJSRuntime(pRuntime) {
operator=(pStr);
}
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array)
- : m_isolate(isolate) {
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array)
+ : m_pJSRuntime(pRuntime) {
operator=(array);
}
@@ -100,15 +102,15 @@ void CJS_Value::Detach() {
*/
int CJS_Value::ToInt() const {
- return FXJS_ToInt32(m_isolate, m_pValue);
+ return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue);
}
bool CJS_Value::ToBool() const {
- return FXJS_ToBoolean(m_isolate, m_pValue);
+ return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue);
}
double CJS_Value::ToDouble() const {
- return FXJS_ToNumber(m_isolate, m_pValue);
+ return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue);
}
float CJS_Value::ToFloat() const {
@@ -116,16 +118,17 @@ float CJS_Value::ToFloat() const {
}
CJS_Object* CJS_Value::ToCJSObject() const {
- v8::Local<v8::Object> pObj = FXJS_ToObject(m_isolate, m_pValue);
- return (CJS_Object*)FXJS_GetPrivate(m_isolate, pObj);
+ v8::Local<v8::Object> pObj =
+ FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue);
+ return (CJS_Object*)FXJS_GetPrivate(m_pJSRuntime->GetIsolate(), pObj);
}
v8::Local<v8::Object> CJS_Value::ToV8Object() const {
- return FXJS_ToObject(m_isolate, m_pValue);
+ return FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue);
}
CFX_WideString CJS_Value::ToCFXWideString() const {
- return FXJS_ToString(m_isolate, m_pValue);
+ return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pValue);
}
CFX_ByteString CJS_Value::ToCFXByteString() const {
@@ -138,7 +141,8 @@ v8::Local<v8::Value> CJS_Value::ToV8Value() const {
v8::Local<v8::Array> CJS_Value::ToV8Array() const {
if (IsArrayObject())
- return v8::Local<v8::Array>::Cast(FXJS_ToObject(m_isolate, m_pValue));
+ return v8::Local<v8::Array>::Cast(
+ FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue));
return v8::Local<v8::Array>();
}
@@ -146,27 +150,27 @@ v8::Local<v8::Array> CJS_Value::ToV8Array() const {
*/
void CJS_Value::operator=(int iValue) {
- m_pValue = FXJS_NewNumber(m_isolate, iValue);
+ m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue);
m_eType = VT_number;
}
void CJS_Value::operator=(bool bValue) {
- m_pValue = FXJS_NewBoolean(m_isolate, bValue);
+ m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue);
m_eType = VT_boolean;
}
void CJS_Value::operator=(double dValue) {
- m_pValue = FXJS_NewNumber(m_isolate, dValue);
+ m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), dValue);
m_eType = VT_number;
}
void CJS_Value::operator=(float fValue) {
- m_pValue = FXJS_NewNumber(m_isolate, fValue);
+ m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), fValue);
m_eType = VT_number;
}
void CJS_Value::operator=(v8::Local<v8::Object> pObj) {
- m_pValue = FXJS_NewObject(m_isolate, pObj);
+ m_pValue = FXJS_NewObject(m_pJSRuntime->GetIsolate(), pObj);
m_eType = VT_fxobject;
}
@@ -183,7 +187,7 @@ void CJS_Value::operator=(CJS_Document* pJsDoc) {
}
void CJS_Value::operator=(const FX_WCHAR* pWstr) {
- m_pValue = FXJS_NewString(m_isolate, (wchar_t*)pWstr);
+ m_pValue = FXJS_NewString(m_pJSRuntime->GetIsolate(), (wchar_t*)pWstr);
m_eType = VT_string;
}
@@ -197,19 +201,20 @@ void CJS_Value::operator=(const FX_CHAR* pStr) {
}
void CJS_Value::operator=(CJS_Array& array) {
- m_pValue = FXJS_NewObject2(m_isolate, (v8::Local<v8::Array>)array);
+ m_pValue =
+ FXJS_NewObject2(m_pJSRuntime->GetIsolate(), (v8::Local<v8::Array>)array);
m_eType = VT_object;
}
void CJS_Value::operator=(CJS_Date& date) {
- m_pValue = FXJS_NewDate(m_isolate, (double)date);
+ m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), (double)date);
m_eType = VT_date;
}
void CJS_Value::operator=(CJS_Value value) {
m_pValue = value.ToV8Value();
m_eType = value.m_eType;
- m_isolate = value.m_isolate;
+ m_pJSRuntime = value.m_pJSRuntime;
}
/* ----------------------------------------------------------------------------------------
@@ -250,7 +255,7 @@ FX_BOOL CJS_Value::IsDateObject() const {
// CJS_Value::operator CJS_Array()
FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const {
if (IsArrayObject()) {
- array.Attach(FXJS_ToArray(m_isolate, m_pValue));
+ array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue));
return TRUE;
}
@@ -277,17 +282,11 @@ FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const {
CJS_PropValue::CJS_PropValue(const CJS_Value& value)
: CJS_Value(value), m_bIsSetting(0) {}
-CJS_PropValue::CJS_PropValue(v8::Isolate* isolate)
- : CJS_Value(isolate), m_bIsSetting(0) {}
-
-CJS_PropValue::~CJS_PropValue() {}
-
-FX_BOOL CJS_PropValue::IsSetting() {
- return m_bIsSetting;
+CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime)
+ : CJS_Value(pRuntime), m_bIsSetting(0) {
}
-FX_BOOL CJS_PropValue::IsGetting() {
- return !m_bIsSetting;
+CJS_PropValue::~CJS_PropValue() {
}
void CJS_PropValue::operator<<(int iValue) {
@@ -406,9 +405,8 @@ CJS_PropValue::operator v8::Local<v8::Value>() const {
return m_pValue;
}
-/* ======================================== CJS_Array
- * ========================================= */
-CJS_Array::CJS_Array(v8::Isolate* isolate) : m_isolate(isolate) {}
+CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {
+}
CJS_Array::~CJS_Array() {}
@@ -423,15 +421,17 @@ FX_BOOL CJS_Array::IsAttached() {
void CJS_Array::GetElement(unsigned index, CJS_Value& value) {
if (m_pArray.IsEmpty())
return;
- v8::Local<v8::Value> p = FXJS_GetArrayElement(m_isolate, m_pArray, index);
+ v8::Local<v8::Value> p =
+ FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index);
value.Attach(p, CJS_Value::VT_object);
}
void CJS_Array::SetElement(unsigned index, CJS_Value value) {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_isolate);
+ m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
- FXJS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value());
+ FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index,
+ value.ToV8Value());
}
int CJS_Array::GetLength() {
@@ -442,30 +442,29 @@ int CJS_Array::GetLength() {
CJS_Array::operator v8::Local<v8::Array>() {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_isolate);
+ m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
return m_pArray;
}
-/* ======================================== CJS_Date
- * ========================================= */
-
-CJS_Date::CJS_Date(v8::Isolate* isolate) : m_isolate(isolate) {}
+CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {
+}
-CJS_Date::CJS_Date(v8::Isolate* isolate, double dMsec_time) {
- m_isolate = isolate;
- m_pDate = FXJS_NewDate(isolate, dMsec_time);
+CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime)
+ : m_pJSRuntime(pRuntime) {
+ m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime);
}
-CJS_Date::CJS_Date(v8::Isolate* isolate,
+CJS_Date::CJS_Date(CJS_Runtime* pRuntime,
int year,
int mon,
int day,
int hour,
int min,
- int sec) {
- m_isolate = isolate;
- m_pDate = FXJS_NewDate(isolate, MakeDate(year, mon, day, hour, min, sec, 0));
+ int sec)
+ : m_pJSRuntime(pRuntime) {
+ m_pDate = FXJS_NewDate(pRuntime->GetIsolate(),
+ MakeDate(year, mon, day, hour, min, sec, 0));
}
double CJS_Date::MakeDate(int year,
@@ -484,7 +483,7 @@ CJS_Date::~CJS_Date() {}
FX_BOOL CJS_Date::IsValidDate() {
if (m_pDate.IsEmpty())
return FALSE;
- return !JS_PortIsNan(FXJS_ToNumber(m_isolate, m_pDate));
+ return !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate));
}
void CJS_Date::Attach(v8::Local<v8::Value> pDate) {
@@ -493,7 +492,8 @@ void CJS_Date::Attach(v8::Local<v8::Value> pDate) {
int CJS_Date::GetYear() {
if (IsValidDate())
- return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetYearFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -501,12 +501,13 @@ int CJS_Date::GetYear() {
void CJS_Date::SetYear(int iYear) {
double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(),
GetSeconds(), 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
int CJS_Date::GetMonth() {
if (IsValidDate())
- return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetMonthFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -514,12 +515,13 @@ int CJS_Date::GetMonth() {
void CJS_Date::SetMonth(int iMonth) {
double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(),
GetSeconds(), 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
int CJS_Date::GetDay() {
if (IsValidDate())
- return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetDayFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -527,12 +529,13 @@ int CJS_Date::GetDay() {
void CJS_Date::SetDay(int iDay) {
double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(),
GetSeconds(), 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
int CJS_Date::GetHours() {
if (IsValidDate())
- return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetHourFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -540,12 +543,13 @@ int CJS_Date::GetHours() {
void CJS_Date::SetHours(int iHours) {
double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(),
GetSeconds(), 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
int CJS_Date::GetMinutes() {
if (IsValidDate())
- return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetMinFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -553,12 +557,13 @@ int CJS_Date::GetMinutes() {
void CJS_Date::SetMinutes(int minutes) {
double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes,
GetSeconds(), 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
int CJS_Date::GetSeconds() {
if (IsValidDate())
- return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
+ return JS_GetSecFromTime(
+ JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)));
return 0;
}
@@ -566,7 +571,7 @@ int CJS_Date::GetSeconds() {
void CJS_Date::SetSeconds(int seconds) {
double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(),
GetMinutes(), seconds, 0);
- FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
+ FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date));
}
CJS_Date::operator v8::Local<v8::Value>() {
@@ -576,13 +581,13 @@ CJS_Date::operator v8::Local<v8::Value>() {
CJS_Date::operator double() const {
if (m_pDate.IsEmpty())
return 0.0;
- return FXJS_ToNumber(m_isolate, m_pDate);
+ return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate);
}
CFX_WideString CJS_Date::ToString() const {
if (m_pDate.IsEmpty())
return L"";
- return FXJS_ToString(m_isolate, m_pDate);
+ return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pDate);
}
double _getLocalTZA() {
diff --git a/fpdfsdk/src/javascript/JS_Value.h b/fpdfsdk/src/javascript/JS_Value.h
index fdcc66279f..d64fdc6a11 100644
--- a/fpdfsdk/src/javascript/JS_Value.h
+++ b/fpdfsdk/src/javascript/JS_Value.h
@@ -14,6 +14,7 @@ class CJS_Array;
class CJS_Date;
class CJS_Document;
class CJS_Object;
+class CJS_Runtime;
class CJS_Value {
public:
@@ -29,18 +30,18 @@ class CJS_Value {
VT_undefined
};
- CJS_Value(v8::Isolate* isolate);
- CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t);
- CJS_Value(v8::Isolate* isolate, const int& iValue);
- CJS_Value(v8::Isolate* isolate, const double& dValue);
- CJS_Value(v8::Isolate* isolate, const float& fValue);
- CJS_Value(v8::Isolate* isolate, const bool& bValue);
- CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object>);
- CJS_Value(v8::Isolate* isolate, CJS_Object*);
- CJS_Value(v8::Isolate* isolate, CJS_Document*);
- CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr);
- CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr);
- CJS_Value(v8::Isolate* isolate, CJS_Array& array);
+ CJS_Value(CJS_Runtime* pRuntime);
+ CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t);
+ CJS_Value(CJS_Runtime* pRuntime, const int& iValue);
+ CJS_Value(CJS_Runtime* pRuntime, const double& dValue);
+ CJS_Value(CJS_Runtime* pRuntime, const float& fValue);
+ CJS_Value(CJS_Runtime* pRuntime, const bool& bValue);
+ CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object>);
+ CJS_Value(CJS_Runtime* pRuntime, CJS_Object*);
+ CJS_Value(CJS_Runtime* pRuntime, CJS_Document*);
+ CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr);
+ CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr);
+ CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array);
~CJS_Value();
@@ -79,12 +80,12 @@ class CJS_Value {
FX_BOOL ConvertToArray(CJS_Array&) const;
FX_BOOL ConvertToDate(CJS_Date&) const;
- v8::Isolate* GetIsolate() { return m_isolate; }
+ CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; }
protected:
Type m_eType;
v8::Local<v8::Value> m_pValue;
- v8::Isolate* m_isolate;
+ CJS_Runtime* m_pJSRuntime;
};
class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> {
@@ -98,12 +99,12 @@ class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> {
class CJS_PropValue : public CJS_Value {
public:
CJS_PropValue(const CJS_Value&);
- CJS_PropValue(v8::Isolate* isolate);
+ CJS_PropValue(CJS_Runtime* pRuntime);
~CJS_PropValue();
- public:
- FX_BOOL IsSetting();
- FX_BOOL IsGetting();
+ FX_BOOL IsSetting() const { return m_bIsSetting; }
+ FX_BOOL IsGetting() const { return !m_bIsSetting; }
+
void operator<<(int);
void operator>>(int&) const;
void operator<<(bool);
@@ -135,7 +136,7 @@ class CJS_PropValue : public CJS_Value {
class CJS_Array {
public:
- CJS_Array(v8::Isolate* isolate);
+ CJS_Array(CJS_Runtime* pRuntime);
virtual ~CJS_Array();
void Attach(v8::Local<v8::Array> pArray);
@@ -145,20 +146,20 @@ class CJS_Array {
FX_BOOL IsAttached();
operator v8::Local<v8::Array>();
- v8::Isolate* GetIsolate() { return m_isolate; }
+ CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; }
private:
v8::Local<v8::Array> m_pArray;
- v8::Isolate* m_isolate;
+ CJS_Runtime* m_pJSRuntime;
};
class CJS_Date {
friend class CJS_Value;
public:
- CJS_Date(v8::Isolate* isolate);
- CJS_Date(v8::Isolate* isolate, double dMsec_time);
- CJS_Date(v8::Isolate* isolate,
+ CJS_Date(CJS_Runtime* pRuntime);
+ CJS_Date(CJS_Runtime* pRuntime, double dMsec_time);
+ CJS_Date(CJS_Runtime* pRuntime,
int year,
int mon,
int day,
@@ -198,7 +199,7 @@ class CJS_Date {
protected:
v8::Local<v8::Value> m_pDate;
- v8::Isolate* m_isolate;
+ CJS_Runtime* m_pJSRuntime;
};
double JS_GetDateTime();
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 528577d9ec..4743d3dff3 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -19,19 +19,6 @@
#include "resource.h"
#include "util.h"
-static v8::Isolate* GetIsolate(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-/* -------------------------------- CJS_PublicMethods
- * -------------------------------- */
-
#define DOUBLE_CORRECT 0.000000000000001
BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
@@ -346,9 +333,9 @@ FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource,
return bAllDigits;
}
-CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate,
+CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
CJS_Value val) {
- CJS_Array StrArray(isolate);
+ CJS_Array StrArray(pRuntime);
if (val.IsArrayObject()) {
val.ConvertToArray(StrArray);
return StrArray;
@@ -363,14 +350,14 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate,
while (*p) {
const char* pTemp = strchr(p, ch);
if (pTemp == NULL) {
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
+ StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(p).c_str()));
break;
} else {
char* pSub = new char[pTemp - p + 1];
strncpy(pSub, p, pTemp - p);
*(pSub + (pTemp - p)) = '\0';
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str()));
+ StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str()));
delete[] pSub;
nIndex++;
@@ -911,21 +898,19 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
CJS_Value& vRet,
CFX_WideString& sError) {
#if _FX_OS_ != _FX_ANDROID_
- v8::Isolate* isolate = ::GetIsolate(cc);
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
if (params.size() != 6) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
+
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
+
CFX_WideString& Value = pEvent->Value();
CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
if (strValue.IsEmpty())
return TRUE;
@@ -1031,8 +1016,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
}
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
+ CJS_Array arColor(pRuntime);
+ CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
arColor.SetElement(0, vColElm);
vColElm = 1;
@@ -1042,7 +1027,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
arColor.SetElement(3, vColElm);
- CJS_PropValue vProp(isolate);
+ CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
vProp << arColor;
vProp.StartSetting();
@@ -1052,8 +1037,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
} else {
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
+ CJS_Array arColor(pRuntime);
+ CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
arColor.SetElement(0, vColElm);
vColElm = 0;
@@ -1061,11 +1046,11 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
arColor.SetElement(2, vColElm);
arColor.SetElement(3, vColElm);
- CJS_PropValue vProp(isolate);
+ CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
fTarget->textColor(cc, vProp, sError);
- CJS_Array aProp(isolate);
+ CJS_Array aProp(pRuntime);
vProp.ConvertToArray(aProp);
CPWL_Color crProp;
@@ -1074,7 +1059,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
color::ConvertArrayToPWLColor(arColor, crColor);
if (crColor != crProp) {
- CJS_PropValue vProp2(isolate);
+ CJS_PropValue vProp2(pRuntime);
vProp2.StartGetting();
vProp2 << arColor;
vProp2.StartSetting();
@@ -1470,12 +1455,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1500,8 +1481,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_FormatEx(cc, newParams, vRet, sError);
}
@@ -1510,12 +1491,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1540,8 +1517,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
}
@@ -1550,11 +1527,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1567,8 +1541,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_FormatEx(cc, newParams, vRet, sError);
}
@@ -1576,10 +1550,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1592,8 +1564,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
}
@@ -1760,24 +1732,18 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
if (params.size() != 1) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
- std::string cFormat;
- int iIndex = params[0].ToInt();
-
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
- // CJS_Value val = pEvent->Value();
+
+ std::string cFormat;
+ int iIndex = params[0].ToInt();
CFX_WideString& val = pEvent->Value();
std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
std::wstring wstrChange = pEvent->Change().c_str();
@@ -1808,9 +1774,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc,
}
CJS_Parameters params2;
- CJS_Value vMask(isolate, cFormat.c_str());
- params2.push_back(vMask);
-
+ params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str()));
return AFSpecial_KeystrokeEx(cc, params2, vRet, sError);
}
@@ -1922,45 +1886,31 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
if (params.size() != 2) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
CJS_Value params1 = params[1];
-
if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
- ASSERT(pReaderDoc != NULL);
-
CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
- double dValue;
CFX_WideString sFunction = params[0].ToCFXWideString();
- if (wcscmp(sFunction.c_str(), L"PRD") == 0)
- dValue = 1.0;
- else
- dValue = 0.0;
-
- CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate, params1);
+ double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0;
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1);
int nFieldsCount = 0;
for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) {
- CJS_Value jsValue(isolate);
+ CJS_Value jsValue(pRuntime);
FieldNameArray.GetElement(i, jsValue);
CFX_WideString wsFieldName = jsValue.ToCFXWideString();
@@ -2022,7 +1972,7 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc,
dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) /
FXSYS_pow((double)10, (double)6);
- CJS_Value jsValue(isolate, dValue);
+ CJS_Value jsValue(pRuntime, dValue);
if (pContext->GetEventHandler()->m_pValue)
pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString();
@@ -2083,16 +2033,14 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
if (params.size() != 1) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
- CJS_Array nums(isolate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array nums(pRuntime);
CFX_WideString str = params[0].ToCFXWideString();
CFX_WideString sPart;
@@ -2107,7 +2055,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
sPart += wc;
} else {
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str()));
+ nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
sPart = L"";
nIndex++;
}
@@ -2115,7 +2063,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
}
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str()));
+ nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
}
if (nums.GetLength() > 0)
diff --git a/fpdfsdk/src/javascript/PublicMethods.h b/fpdfsdk/src/javascript/PublicMethods.h
index 0c9c9b4682..f328c15400 100644
--- a/fpdfsdk/src/javascript/PublicMethods.h
+++ b/fpdfsdk/src/javascript/PublicMethods.h
@@ -179,7 +179,7 @@ class CJS_PublicMethods : public CJS_Object {
static double AF_Simple(const FX_WCHAR* sFuction,
double dValue1,
double dValue2);
- static CJS_Array AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val);
+ static CJS_Array AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val);
};
#endif // FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index bc18ae53a9..93a627c97a 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -18,12 +18,6 @@
#include "JS_Value.h"
#include "resource.h"
-static v8::Isolate* GetIsolate(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- return pRuntime->GetIsolate();
-}
-
BEGIN_JS_STATIC_CONST(CJS_TimerObj)
END_JS_STATIC_CONST()
@@ -119,7 +113,7 @@ FX_BOOL app::activeDocs(IJS_Context* cc,
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
- CJS_Array aDocs(pRuntime->GetIsolate());
+ CJS_Array aDocs(pRuntime);
if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
CJS_Document* pJSDocument = NULL;
if (pDoc == pCurDoc) {
@@ -134,7 +128,7 @@ FX_BOOL app::activeDocs(IJS_Context* cc,
(CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
ASSERT(pJSDocument != NULL);
}
- aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
+ aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
}
if (aDocs.GetLength() > 0)
vp << aDocs;
@@ -155,7 +149,7 @@ FX_BOOL app::calculate(IJS_Context* cc,
CJS_Context* pContext = (CJS_Context*)cc;
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CJS_Array aDocs(pRuntime->GetIsolate());
+ CJS_Array aDocs(pRuntime);
if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
} else {
@@ -266,7 +260,8 @@ FX_BOOL app::alert(IJS_Context* cc,
int iIcon = 0;
int iType = 0;
- v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ v8::Isolate* isolate = pRuntime->GetIsolate();
if (iSize == 1) {
if (params[0].GetType() == CJS_Value::VT_object) {
@@ -274,25 +269,25 @@ FX_BOOL app::alert(IJS_Context* cc,
{
v8::Local<v8::Value> pValue =
FXJS_GetObjectElement(isolate, pObj, L"cMsg");
- swMsg =
- CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
+ swMsg = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown)
+ .ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
- swTitle =
- CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
+ swTitle = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown)
+ .ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon");
- iIcon = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
+ iIcon = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt();
pValue = FXJS_GetObjectElement(isolate, pObj, L"nType");
- iType = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
+ iType = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt();
}
if (swMsg == L"") {
- CJS_Array carray(isolate);
+ CJS_Array carray(pRuntime);
if (params[0].ConvertToArray(carray)) {
int iLength = carray.GetLength();
- CJS_Value* pValue = new CJS_Value(isolate);
+ CJS_Value* pValue = new CJS_Value(pRuntime);
for (int i = 0; i < iLength; ++i) {
carray.GetElement(i, *pValue);
swMsg += (*pValue).ToCFXWideString();
@@ -340,15 +335,10 @@ FX_BOOL app::alert(IJS_Context* cc,
}
}
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
pRuntime->BeginBlock();
vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
iIcon);
pRuntime->EndBlock();
-
return TRUE;
}
@@ -595,8 +585,8 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- v8::Isolate* isolate = GetIsolate(cc);
+ if (params.size() < 1)
+ return FALSE;
FX_BOOL bUI = TRUE;
CFX_WideString cTo = L"";
@@ -605,30 +595,33 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
CFX_WideString cSubject = L"";
CFX_WideString cMsg = L"";
- if (params.size() < 1)
- return FALSE;
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ v8::Isolate* isolate = pRuntime->GetIsolate();
if (params[0].GetType() == CJS_Value::VT_object) {
v8::Local<v8::Object> pObj = params[0].ToV8Object();
v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
- bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
- cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
- cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
- cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cBcc =
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
cSubject =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
- cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ cMsg =
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
} else {
if (params.size() < 2)
return FALSE;
@@ -646,15 +639,10 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
cMsg = params[5].ToCFXWideString();
}
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
pRuntime->BeginBlock();
- pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
- cBcc.c_str(), cMsg.c_str());
+ pContext->GetReaderApp()->JS_docmailForm(NULL, 0, bUI, cTo.c_str(),
+ cSubject.c_str(), cCc.c_str(),
+ cBcc.c_str(), cMsg.c_str());
pRuntime->EndBlock();
return FALSE;
@@ -743,7 +731,8 @@ FX_BOOL app::response(IJS_Context* cc,
CFX_WideString swDefault = L"";
bool bPassWord = false;
- v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ v8::Isolate* isolate = pRuntime->GetIsolate();
int iLength = params.size();
if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) {
@@ -751,22 +740,22 @@ FX_BOOL app::response(IJS_Context* cc,
v8::Local<v8::Value> pValue =
FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
swQuestion =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
swTitle =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault");
swDefault =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel");
swLabel =
- CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
- bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
} else {
switch (iLength) {
case 5:
diff --git a/fpdfsdk/src/javascript/color.cpp b/fpdfsdk/src/javascript/color.cpp
index 791785a626..515548e1ac 100644
--- a/fpdfsdk/src/javascript/color.cpp
+++ b/fpdfsdk/src/javascript/color.cpp
@@ -14,15 +14,6 @@
#include "JS_Context.h"
#include "JS_Runtime.h"
-static v8::Isolate* GetIsolate(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
/* -------------------------- color -------------------------- */
BEGIN_JS_STATIC_CONST(CJS_Color)
@@ -71,24 +62,24 @@ color::~color() {
void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) {
switch (color.nColorType) {
case COLORTYPE_TRANSPARENT:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
+ array.SetElement(0, CJS_Value(array.GetJSRuntime(), "T"));
break;
case COLORTYPE_GRAY:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "G"));
- array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
+ array.SetElement(0, CJS_Value(array.GetJSRuntime(), "G"));
+ array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1));
break;
case COLORTYPE_RGB:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "RGB"));
- array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3));
+ array.SetElement(0, CJS_Value(array.GetJSRuntime(), "RGB"));
+ array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3));
break;
case COLORTYPE_CMYK:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "CMYK"));
- array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3));
- array.SetElement(4, CJS_Value(array.GetIsolate(), color.fColor4));
+ array.SetElement(0, CJS_Value(array.GetJSRuntime(), "CMYK"));
+ array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3));
+ array.SetElement(4, CJS_Value(array.GetJSRuntime(), color.fColor4));
break;
}
}
@@ -98,7 +89,7 @@ void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) {
if (nArrayLen < 1)
return;
- CJS_Value value(array.GetIsolate());
+ CJS_Value value(array.GetJSRuntime());
array.GetElement(0, value);
CFX_ByteString sSpace = value.ToCFXByteString();
@@ -139,22 +130,20 @@ void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) {
}
}
-#define JS_IMPLEMENT_COLORPROP(prop, var) \
- FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \
- CFX_WideString& sError) { \
- CJS_Context* pContext = (CJS_Context*)cc; \
- v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate(); \
- if (vp.IsGetting()) { \
- CJS_Array array(isolate); \
- ConvertPWLColorToArray(var, array); \
- vp << array; \
- } else { \
- CJS_Array array(isolate); \
- if (!vp.ConvertToArray(array)) \
- return FALSE; \
- ConvertArrayToPWLColor(array, var); \
- } \
- return TRUE; \
+#define JS_IMPLEMENT_COLORPROP(prop, var) \
+ FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \
+ CFX_WideString& sError) { \
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \
+ CJS_Array array(pRuntime); \
+ if (vp.IsGetting()) { \
+ ConvertPWLColorToArray(var, array); \
+ vp << array; \
+ } else { \
+ if (!vp.ConvertToArray(array)) \
+ return FALSE; \
+ ConvertArrayToPWLColor(array, var); \
+ } \
+ return TRUE; \
}
JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
@@ -174,11 +163,12 @@ FX_BOOL color::convert(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = GetIsolate(cc);
int iSize = params.size();
if (iSize < 2)
return FALSE;
- CJS_Array aSource(isolate);
+
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array aSource(pRuntime);
if (!params[0].ConvertToArray(aSource))
return FALSE;
@@ -198,7 +188,7 @@ FX_BOOL color::convert(IJS_Context* cc,
nColorType = COLORTYPE_CMYK;
}
- CJS_Array aDest(isolate);
+ CJS_Array aDest(pRuntime);
CPWL_Color crDest = crSource;
crDest.ConvertColorType(nColorType);
ConvertPWLColorToArray(crDest, aDest);
@@ -211,12 +201,12 @@ FX_BOOL color::equal(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = GetIsolate(cc);
if (params.size() < 2)
return FALSE;
- CJS_Array array1(isolate), array2(isolate);
-
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array array1(pRuntime);
+ CJS_Array array2(pRuntime);
if (!params[0].ConvertToArray(array1))
return FALSE;
if (!params[1].ConvertToArray(array2))
@@ -224,12 +214,9 @@ FX_BOOL color::equal(IJS_Context* cc,
CPWL_Color color1;
CPWL_Color color2;
-
ConvertArrayToPWLColor(array1, color1);
ConvertArrayToPWLColor(array2, color2);
-
color1.ConvertColorType(color2.nColorType);
-
vRet = color1 == color2;
return TRUE;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 69e983f139..c8510d27dc 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -193,8 +193,8 @@ FX_BOOL JSGlobalAlternate::DoProperty(IJS_Context* cc,
vp << pData->sData;
return TRUE;
case JS_GLOBALDATA_TYPE_OBJECT: {
- v8::Local<v8::Object> obj =
- v8::Local<v8::Object>::New(vp.GetIsolate(), pData->pData);
+ v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(
+ vp.GetJSRuntime()->GetIsolate(), pData->pData);
vp << obj;
return TRUE;
}
@@ -286,8 +286,7 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
}
}
-void JSGlobalAlternate::CommitGlobalPersisitentVariables() {
- ASSERT(m_pGlobalData);
+void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) {
for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) {
CFX_ByteString name = it->first;
JSGlobalData* pData = it->second;
@@ -308,12 +307,11 @@ void JSGlobalAlternate::CommitGlobalPersisitentVariables() {
m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
break;
case JS_GLOBALDATA_TYPE_OBJECT:
- // if (pData->pData)
{
CJS_GlobalVariableArray array;
v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(
GetJSObject()->GetIsolate(), pData->pData);
- ObjectToArray(obj, array);
+ ObjectToArray(cc, obj, array);
m_pGlobalData->SetGlobalVariableObject(name, array);
m_pGlobalData->SetGlobalVariablePersistent(name,
pData->bPersistent);
@@ -328,13 +326,15 @@ void JSGlobalAlternate::CommitGlobalPersisitentVariables() {
}
}
-void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj,
+void JSGlobalAlternate::ObjectToArray(IJS_Context* cc,
+ v8::Local<v8::Object> pObj,
CJS_GlobalVariableArray& array) {
v8::Local<v8::Context> context = pObj->CreationContext();
v8::Isolate* isolate = context->GetIsolate();
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+
v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj);
int nObjElements = pKeyList->Length();
-
for (int i = 0; i < nObjElements; i++) {
CFX_WideString ws =
FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i));
@@ -358,7 +358,7 @@ void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj,
} break;
case CJS_Value::VT_string: {
CFX_ByteString sValue =
- CJS_Value(isolate, v, CJS_Value::VT_string).ToCFXByteString();
+ CJS_Value(pRuntime, v, CJS_Value::VT_string).ToCFXByteString();
CJS_KeyValue* pObjElement = new CJS_KeyValue;
pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
pObjElement->sKey = sKey;
@@ -369,7 +369,7 @@ void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj,
CJS_KeyValue* pObjElement = new CJS_KeyValue;
pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
pObjElement->sKey = sKey;
- ObjectToArray(FXJS_ToObject(isolate, v), pObjElement->objData);
+ ObjectToArray(cc, FXJS_ToObject(isolate, v), pObjElement->objData);
array.Add(pObjElement);
} break;
case CJS_Value::VT_null: {
diff --git a/fpdfsdk/src/javascript/global.h b/fpdfsdk/src/javascript/global.h
index 5ae9c9f9db..30f5d07b31 100644
--- a/fpdfsdk/src/javascript/global.h
+++ b/fpdfsdk/src/javascript/global.h
@@ -56,7 +56,7 @@ class JSGlobalAlternate : public CJS_EmbedObj {
private:
void UpdateGlobalPersistentVariables();
- void CommitGlobalPersisitentVariables();
+ void CommitGlobalPersisitentVariables(IJS_Context* cc);
void DestroyGlobalPersisitentVariables();
FX_BOOL SetGlobalVariables(const FX_CHAR* propname,
int nType,
@@ -65,12 +65,11 @@ class JSGlobalAlternate : public CJS_EmbedObj {
const CFX_ByteString& sData,
v8::Local<v8::Object> pData,
bool bDefaultPersistent);
-
- void ObjectToArray(v8::Local<v8::Object> pObj,
+ void ObjectToArray(IJS_Context* cc,
+ v8::Local<v8::Object> pObj,
CJS_GlobalVariableArray& array);
void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
- private:
std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal;
CFX_WideString m_sFilePath;
CJS_GlobalData* m_pGlobalData;
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index 6a48c09a08..14e15c1b6f 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -20,16 +20,6 @@
#include <ctype.h>
#endif
-static v8::Isolate* GetIsolate(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
BEGIN_JS_STATIC_CONST(CJS_Util)
END_JS_STATIC_CONST()
@@ -191,17 +181,16 @@ FX_BOOL util::printd(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = GetIsolate(cc);
-
int iSize = params.size();
if (iSize < 2)
return FALSE;
- CJS_Value p1(isolate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Value p1(pRuntime);
p1 = params[0];
CJS_Value p2 = params[1];
- CJS_Date jsDate(isolate);
+ CJS_Date jsDate(pRuntime);
if (!p2.ConvertToDate(jsDate)) {
sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
return FALSE;
@@ -504,7 +493,6 @@ FX_BOOL util::scand(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = GetIsolate(cc);
int iSize = params.size();
if (iSize < 2)
return FALSE;
@@ -518,8 +506,7 @@ FX_BOOL util::scand(IJS_Context* cc,
}
if (!JS_PortIsNan(dDate)) {
- CJS_Date date(isolate, dDate);
- vRet = date;
+ vRet = CJS_Date(CJS_Runtime::FromContext(cc), dDate);
} else {
vRet.SetNull();
}