Remove backpointer to runtime from CJS_Array.
This is always available elsewhere, so save the bytes and ease
removal of CJS_Array since it now only contains a single v8 local.
Review-Url: https://codereview.chromium.org/2217253002
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index a4c639f..9c680de 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -519,7 +519,7 @@
CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array aName(pRuntime);
+ CJS_Array aName;
if (params.empty()) {
pPDFForm->ResetForm(TRUE);
@@ -532,14 +532,14 @@
aName.Attach(params[0].ToV8Array());
break;
case CJS_Value::VT_string:
- aName.SetElement(0, params[0]);
+ aName.SetElement(pRuntime->GetIsolate(), 0, params[0]);
break;
}
std::vector<CPDF_FormField*> aFields;
for (int i = 0, isz = aName.GetLength(); i < isz; ++i) {
CJS_Value valElement(pRuntime);
- aName.GetElement(i, valElement);
+ aName.GetElement(pRuntime->GetIsolate(), i, valElement);
CFX_WideString swVal = valElement.ToCFXWideString();
for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j)
aFields.push_back(pPDFForm->GetField(j, swVal));
@@ -574,7 +574,7 @@
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
v8::Isolate* isolate = pRuntime->GetIsolate();
- CJS_Array aFields(pRuntime);
+ CJS_Array aFields;
CFX_WideString strURL;
FX_BOOL bFDF = TRUE;
FX_BOOL bEmpty = FALSE;
@@ -618,7 +618,7 @@
std::vector<CPDF_FormField*> fieldObjects;
for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) {
CJS_Value valName(pRuntime);
- aFields.GetElement(i, valName);
+ aFields.GetElement(pRuntime->GetIsolate(), i, valName);
CFX_WideString sName = valName.ToCFXWideString();
CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
@@ -1099,7 +1099,7 @@
}
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array Icons(pRuntime);
+ CJS_Array Icons;
int i = 0;
for (const auto& pIconElement : m_IconList) {
@@ -1118,7 +1118,8 @@
pIcon->SetStream(pIconElement->IconStream->GetStream());
pIcon->SetIconName(pIconElement->IconName);
- Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon));
+ Icons.SetElement(pRuntime->GetIsolate(), i++,
+ CJS_Value(pRuntime, pJS_Icon));
}
vp << Icons;
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 937b3c6..34a2466 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -960,12 +960,12 @@
vp >> iSelecting;
array.push_back(iSelecting);
} else if (vp.IsArrayObject()) {
- CJS_Array SelArray(pRuntime);
+ CJS_Array SelArray;
CJS_Value SelValue(pRuntime);
int iSelecting;
vp >> SelArray;
for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
- SelArray.GetElement(i, SelValue);
+ SelArray.GetElement(pRuntime->GetIsolate(), i, SelValue);
iSelecting = SelValue.ToInt();
array.push_back(iSelecting);
}
@@ -991,10 +991,11 @@
if (pFormField->CountSelectedItems() == 1) {
vp << pFormField->GetSelectedIndex(0);
} else if (pFormField->CountSelectedItems() > 1) {
- CJS_Array SelArray(pRuntime);
+ CJS_Array SelArray;
for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
SelArray.SetElement(
- i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
+ pRuntime->GetIsolate(), i,
+ CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
}
vp << SelArray;
} else {
@@ -1378,12 +1379,13 @@
return FALSE;
} else {
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array ExportValusArray(pRuntime);
+ CJS_Array ExportValusArray;
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(pRuntime, pFormControl->GetExportValue().c_str()));
+ pRuntime->GetIsolate(), i,
+ CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
}
} else {
if (m_nFormControlIndex >= pFormField->CountControls())
@@ -1395,7 +1397,8 @@
return FALSE;
ExportValusArray.SetElement(
- 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
+ pRuntime->GetIsolate(), 0,
+ CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
}
vp << ExportValusArray;
}
@@ -1432,7 +1435,7 @@
CJS_PropValue& vp,
CFX_WideString& sError) {
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array crArray(pRuntime);
+ CJS_Array crArray;
std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
if (FieldArray.empty())
return FALSE;
@@ -1447,7 +1450,7 @@
vp >> crArray;
CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
+ color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
if (m_bDelay) {
AddDelay_Color(FP_FILLCOLOR, color);
} else {
@@ -1484,7 +1487,7 @@
return FALSE;
}
- color::ConvertPWLColorToArray(color, crArray);
+ color::ConvertPWLColorToArray(pRuntime, color, &crArray);
vp << crArray;
}
@@ -1885,14 +1888,15 @@
}
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array PageArray(pRuntime);
+ CJS_Array PageArray;
for (size_t i = 0; i < widgets.size(); ++i) {
CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
if (!pPageView)
return FALSE;
PageArray.SetElement(
- i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
+ pRuntime->GetIsolate(), i,
+ CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
}
vp << PageArray;
@@ -2083,12 +2087,12 @@
if (!vp.IsArrayObject())
return FALSE;
- CJS_Array rcArray(pRuntime);
+ CJS_Array rcArray;
vp >> rcArray;
- rcArray.GetElement(0, Upper_Leftx);
- rcArray.GetElement(1, Upper_Lefty);
- rcArray.GetElement(2, Lower_Rightx);
- rcArray.GetElement(3, Lower_Righty);
+ rcArray.GetElement(pRuntime->GetIsolate(), 0, Upper_Leftx);
+ rcArray.GetElement(pRuntime->GetIsolate(), 1, Upper_Lefty);
+ rcArray.GetElement(pRuntime->GetIsolate(), 2, Lower_Rightx);
+ rcArray.GetElement(pRuntime->GetIsolate(), 3, Lower_Righty);
FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
@@ -2120,11 +2124,11 @@
Lower_Rightx = (int32_t)crRect.right;
Lower_Righty = (int32_t)crRect.bottom;
- CJS_Array rcArray(pRuntime);
- rcArray.SetElement(0, Upper_Leftx);
- rcArray.SetElement(1, Upper_Lefty);
- rcArray.SetElement(2, Lower_Rightx);
- rcArray.SetElement(3, Lower_Righty);
+ CJS_Array rcArray;
+ rcArray.SetElement(pRuntime->GetIsolate(), 0, Upper_Leftx);
+ rcArray.SetElement(pRuntime->GetIsolate(), 1, Upper_Lefty);
+ rcArray.SetElement(pRuntime->GetIsolate(), 2, Lower_Rightx);
+ rcArray.SetElement(pRuntime->GetIsolate(), 3, Lower_Righty);
vp << rcArray;
}
return TRUE;
@@ -2299,7 +2303,7 @@
CJS_PropValue& vp,
CFX_WideString& sError) {
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array crArray(pRuntime);
+ CJS_Array crArray;
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -2311,7 +2315,7 @@
vp >> crArray;
CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
+ color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
if (m_bDelay) {
AddDelay_Color(FP_STROKECOLOR, color);
@@ -2352,7 +2356,7 @@
return FALSE;
}
- color::ConvertPWLColorToArray(color, crArray);
+ color::ConvertPWLColorToArray(pRuntime, color, &crArray);
vp << crArray;
}
return TRUE;
@@ -2444,7 +2448,7 @@
CJS_PropValue& vp,
CFX_WideString& sError) {
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array crArray(pRuntime);
+ CJS_Array crArray;
if (vp.IsSetting()) {
if (!m_bCanSet)
@@ -2456,7 +2460,7 @@
vp >> crArray;
CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
+ color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
if (m_bDelay) {
AddDelay_Color(FP_TEXTCOLOR, color);
@@ -2487,7 +2491,7 @@
if (iColorType == COLORTYPE_TRANSPARENT)
crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
- color::ConvertPWLColorToArray(crRet, crArray);
+ color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
vp << crArray;
}
return TRUE;
@@ -2695,11 +2699,11 @@
std::vector<CFX_WideString> strArray;
if (vp.IsArrayObject()) {
- CJS_Array ValueArray(pRuntime);
+ CJS_Array ValueArray;
vp.ConvertToArray(ValueArray);
for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
CJS_Value ElementValue(pRuntime);
- ValueArray.GetElement(i, ElementValue);
+ ValueArray.GetElement(pRuntime->GetIsolate(), i, ElementValue);
strArray.push_back(ElementValue.ToCFXWideString());
}
} else {
@@ -2728,7 +2732,7 @@
} break;
case FIELDTYPE_LISTBOX: {
if (pFormField->CountSelectedItems() > 1) {
- CJS_Array ValueArray(pRuntime);
+ CJS_Array ValueArray;
CJS_Value ElementValue(pRuntime);
int iIndex;
for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
@@ -2736,7 +2740,7 @@
ElementValue = pFormField->GetOptionValue(iIndex).c_str();
if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
- ValueArray.SetElement(i, ElementValue);
+ ValueArray.SetElement(pRuntime->GetIsolate(), i, ElementValue);
}
vp << ValueArray;
} else {
@@ -3086,7 +3090,7 @@
CJS_Context* pContext = (CJS_Context*)cc;
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CJS_Array FormFieldArray(pRuntime);
+ CJS_Array FormFieldArray;
int j = 0;
for (const auto& pStr : swSort) {
@@ -3101,10 +3105,10 @@
CJS_Value FormFieldValue(pRuntime);
FormFieldValue = pJSField;
- FormFieldArray.SetElement(j++, FormFieldValue);
+ FormFieldArray.SetElement(pRuntime->GetIsolate(), j++, FormFieldValue);
}
- vRet = FormFieldArray;
+ vRet = CJS_Value(pRuntime, FormFieldArray);
return TRUE;
}
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index 9d65c79..ab81aa0 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -73,10 +73,9 @@
operator=(pStr);
}
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array)
- : m_pJSRuntime(pRuntime) {
- operator=(array);
-}
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array)
+ : m_pValue(array.ToV8Array(pRuntime->GetIsolate())),
+ m_pJSRuntime(pRuntime) {}
CJS_Value::~CJS_Value() {}
@@ -192,11 +191,6 @@
operator=(CFX_WideString::FromLocal(pStr).c_str());
}
-void CJS_Value::operator=(const CJS_Array& array) {
- ASSERT(m_pJSRuntime == array.GetJSRuntime());
- m_pValue = array.ToV8Array();
-}
-
void CJS_Value::operator=(const CJS_Date& date) {
ASSERT(m_pJSRuntime == date.GetJSRuntime());
m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date.ToDouble());
@@ -360,7 +354,7 @@
void CJS_PropValue::operator<<(CJS_Array& array) {
ASSERT(!m_bIsSetting);
- CJS_Value::operator=(array);
+ m_pValue = array.ToV8Array(m_pJSRuntime->GetIsolate());
}
void CJS_PropValue::operator>>(CJS_Date& date) const {
@@ -373,30 +367,30 @@
CJS_Value::operator=(date);
}
-CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {}
-
-CJS_Array::~CJS_Array() {}
+CJS_Array::CJS_Array() {}
CJS_Array::CJS_Array(const CJS_Array& other) = default;
+CJS_Array::~CJS_Array() {}
+
void CJS_Array::Attach(v8::Local<v8::Array> pArray) {
m_pArray = pArray;
}
-void CJS_Array::GetElement(unsigned index, CJS_Value& value) const {
- if (m_pArray.IsEmpty())
- return;
- v8::Local<v8::Value> p =
- FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index);
- value.Attach(p);
+void CJS_Array::GetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ CJS_Value& value) const {
+ if (!m_pArray.IsEmpty())
+ value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index));
}
-void CJS_Array::SetElement(unsigned index, CJS_Value value) {
+void CJS_Array::SetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ const CJS_Value& value) {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
+ m_pArray = FXJS_NewArray(pIsolate);
- FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index,
- value.ToV8Value());
+ FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value());
}
int CJS_Array::GetLength() const {
@@ -405,9 +399,9 @@
return FXJS_GetArrayLength(m_pArray);
}
-v8::Local<v8::Array> CJS_Array::ToV8Array() const {
+v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
+ m_pArray = FXJS_NewArray(pIsolate);
return m_pArray;
}
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 01b4e5b..75c40a6 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -40,7 +40,7 @@
CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj);
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(CJS_Runtime* pRuntime, const CJS_Array& array);
CJS_Value(const CJS_Value& other);
~CJS_Value();
@@ -129,21 +129,23 @@
class CJS_Array {
public:
- explicit CJS_Array(CJS_Runtime* pRuntime);
+ CJS_Array();
CJS_Array(const CJS_Array& other);
virtual ~CJS_Array();
void Attach(v8::Local<v8::Array> pArray);
- void GetElement(unsigned index, CJS_Value& value) const;
- void SetElement(unsigned index, CJS_Value value);
+ void GetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ CJS_Value& value) const;
+ void SetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ const CJS_Value& value);
int GetLength() const;
- v8::Local<v8::Array> ToV8Array() const;
- CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; }
+ v8::Local<v8::Array> ToV8Array(v8::Isolate* pIsolate) const;
private:
mutable v8::Local<v8::Array> m_pArray;
- CJS_Runtime* const m_pJSRuntime;
};
class CJS_Date {
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 34819c7..6af59bd 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -155,7 +155,7 @@
CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
CJS_Value val) {
- CJS_Array StrArray(pRuntime);
+ CJS_Array StrArray;
if (val.IsArrayObject()) {
val.ConvertToArray(StrArray);
return StrArray;
@@ -171,7 +171,8 @@
const char* pTemp = strchr(p, ch);
if (!pTemp) {
StrArray.SetElement(
- nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str()));
+ pRuntime->GetIsolate(), nIndex,
+ CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str()));
break;
}
@@ -180,7 +181,8 @@
*(pSub + (pTemp - p)) = '\0';
StrArray.SetElement(
- nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str()));
+ pRuntime->GetIsolate(), nIndex,
+ CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str()));
delete[] pSub;
nIndex++;
@@ -827,16 +829,15 @@
}
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(pRuntime);
+ CJS_Array arColor;
CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
- arColor.SetElement(0, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm);
vColElm = 1;
- arColor.SetElement(1, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm);
vColElm = 0;
- arColor.SetElement(2, vColElm);
-
- arColor.SetElement(3, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm);
CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
@@ -848,26 +849,26 @@
} else {
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(pRuntime);
+ CJS_Array arColor;
CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
- arColor.SetElement(0, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm);
vColElm = 0;
- arColor.SetElement(1, vColElm);
- arColor.SetElement(2, vColElm);
- arColor.SetElement(3, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm);
+ arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm);
CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
fTarget->textColor(cc, vProp, sError);
- CJS_Array aProp(pRuntime);
+ CJS_Array aProp;
vProp.ConvertToArray(aProp);
CPWL_Color crProp;
CPWL_Color crColor;
- color::ConvertArrayToPWLColor(aProp, crProp);
- color::ConvertArrayToPWLColor(arColor, crColor);
+ color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp);
+ color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor);
if (crColor != crProp) {
CJS_PropValue vProp2(pRuntime);
@@ -1656,7 +1657,7 @@
for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) {
CJS_Value jsValue(pRuntime);
- FieldNameArray.GetElement(i, jsValue);
+ FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue);
CFX_WideString wsFieldName = jsValue.ToCFXWideString();
for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) {
@@ -1784,7 +1785,7 @@
}
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array nums(pRuntime);
+ CJS_Array nums;
CFX_WideString str = params[0].ToCFXWideString();
CFX_WideString sPart;
@@ -1799,7 +1800,8 @@
sPart += wc;
} else {
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
+ nums.SetElement(pRuntime->GetIsolate(), nIndex,
+ CJS_Value(pRuntime, sPart.c_str()));
sPart = L"";
nIndex++;
}
@@ -1807,11 +1809,12 @@
}
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
+ nums.SetElement(pRuntime->GetIsolate(), nIndex,
+ CJS_Value(pRuntime, sPart.c_str()));
}
if (nums.GetLength() > 0)
- vRet = nums;
+ vRet = CJS_Value(pRuntime, nums);
else
vRet.SetNull();
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index 329b625..6738520 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -109,7 +109,7 @@
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
- CJS_Array aDocs(pRuntime);
+ CJS_Array aDocs;
if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
CJS_Document* pJSDocument = nullptr;
if (pDoc == pCurDoc) {
@@ -124,7 +124,8 @@
(CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
ASSERT(pJSDocument);
}
- aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
+ aDocs.SetElement(pRuntime->GetIsolate(), 0,
+ CJS_Value(pRuntime, pJSDocument));
}
if (aDocs.GetLength() > 0)
vp << aDocs;
@@ -144,8 +145,6 @@
CJS_Context* pContext = (CJS_Context*)cc;
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CJS_Array aDocs(pRuntime);
if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
} else {
@@ -284,14 +283,14 @@
CFX_WideString swMsg;
if (newParams[0].GetType() == CJS_Value::VT_object) {
- CJS_Array carray(pRuntime);
+ CJS_Array carray;
if (newParams[0].ConvertToArray(carray)) {
swMsg = L"[";
CJS_Value element(pRuntime);
for (int i = 0; i < carray.GetLength(); ++i) {
if (i)
swMsg += L", ";
- carray.GetElement(i, element);
+ carray.GetElement(pRuntime->GetIsolate(), i, element);
swMsg += element.ToCFXWideString();
}
swMsg += L"]";
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index 74c885b..c0b6333 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -57,38 +57,50 @@
color::~color() {}
-void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) {
+void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
+ const CPWL_Color& color,
+ CJS_Array* array) {
switch (color.nColorType) {
case COLORTYPE_TRANSPARENT:
- array.SetElement(0, CJS_Value(array.GetJSRuntime(), "T"));
+ array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "T"));
break;
case COLORTYPE_GRAY:
- array.SetElement(0, CJS_Value(array.GetJSRuntime(), "G"));
- array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1));
+ array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "G"));
+ array->SetElement(pRuntime->GetIsolate(), 1,
+ CJS_Value(pRuntime, color.fColor1));
break;
case COLORTYPE_RGB:
- 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));
+ array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "RGB"));
+ array->SetElement(pRuntime->GetIsolate(), 1,
+ CJS_Value(pRuntime, color.fColor1));
+ array->SetElement(pRuntime->GetIsolate(), 2,
+ CJS_Value(pRuntime, color.fColor2));
+ array->SetElement(pRuntime->GetIsolate(), 3,
+ CJS_Value(pRuntime, color.fColor3));
break;
case COLORTYPE_CMYK:
- 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));
+ array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "CMYK"));
+ array->SetElement(pRuntime->GetIsolate(), 1,
+ CJS_Value(pRuntime, color.fColor1));
+ array->SetElement(pRuntime->GetIsolate(), 2,
+ CJS_Value(pRuntime, color.fColor2));
+ array->SetElement(pRuntime->GetIsolate(), 3,
+ CJS_Value(pRuntime, color.fColor3));
+ array->SetElement(pRuntime->GetIsolate(), 4,
+ CJS_Value(pRuntime, color.fColor4));
break;
}
}
-void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) {
+void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
+ const CJS_Array& array,
+ CPWL_Color* color) {
int nArrayLen = array.GetLength();
if (nArrayLen < 1)
return;
- CJS_Value value(array.GetJSRuntime());
- array.GetElement(0, value);
+ CJS_Value value(pRuntime);
+ array.GetElement(pRuntime->GetIsolate(), 0, value);
CFX_ByteString sSpace = value.ToCFXByteString();
double d1 = 0;
@@ -97,34 +109,35 @@
double d4 = 0;
if (nArrayLen > 1) {
- array.GetElement(1, value);
+ array.GetElement(pRuntime->GetIsolate(), 1, value);
d1 = value.ToDouble();
}
if (nArrayLen > 2) {
- array.GetElement(2, value);
+ array.GetElement(pRuntime->GetIsolate(), 2, value);
d2 = value.ToDouble();
}
if (nArrayLen > 3) {
- array.GetElement(3, value);
+ array.GetElement(pRuntime->GetIsolate(), 3, value);
d3 = value.ToDouble();
}
if (nArrayLen > 4) {
- array.GetElement(4, value);
+ array.GetElement(pRuntime->GetIsolate(), 4, value);
d4 = value.ToDouble();
}
if (sSpace == "T") {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ *color = CPWL_Color(COLORTYPE_TRANSPARENT);
} else if (sSpace == "G") {
- color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
+ *color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
} else if (sSpace == "RGB") {
- color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
+ *color =
+ CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
} else if (sSpace == "CMYK") {
- color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3,
- (FX_FLOAT)d4);
+ *color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2,
+ (FX_FLOAT)d3, (FX_FLOAT)d4);
}
}
@@ -132,14 +145,14 @@
FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \
CFX_WideString& sError) { \
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \
- CJS_Array array(pRuntime); \
+ CJS_Array array; \
if (vp.IsGetting()) { \
- ConvertPWLColorToArray(var, array); \
+ ConvertPWLColorToArray(pRuntime, var, &array); \
vp << array; \
} else { \
if (!vp.ConvertToArray(array)) \
return FALSE; \
- ConvertArrayToPWLColor(array, var); \
+ ConvertArrayToPWLColor(pRuntime, array, &var); \
} \
return TRUE; \
}
@@ -166,12 +179,12 @@
return FALSE;
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array aSource(pRuntime);
+ CJS_Array aSource;
if (!params[0].ConvertToArray(aSource))
return FALSE;
CPWL_Color crSource;
- ConvertArrayToPWLColor(aSource, crSource);
+ ConvertArrayToPWLColor(pRuntime, aSource, &crSource);
CFX_ByteString sDestSpace = params[1].ToCFXByteString();
int nColorType = COLORTYPE_TRANSPARENT;
@@ -186,11 +199,11 @@
nColorType = COLORTYPE_CMYK;
}
- CJS_Array aDest(pRuntime);
+ CJS_Array aDest;
CPWL_Color crDest = crSource;
crDest.ConvertColorType(nColorType);
- ConvertPWLColorToArray(crDest, aDest);
- vRet = aDest;
+ ConvertPWLColorToArray(pRuntime, crDest, &aDest);
+ vRet = CJS_Value(pRuntime, aDest);
return TRUE;
}
@@ -203,8 +216,8 @@
return FALSE;
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_Array array1(pRuntime);
- CJS_Array array2(pRuntime);
+ CJS_Array array1;
+ CJS_Array array2;
if (!params[0].ConvertToArray(array1))
return FALSE;
if (!params[1].ConvertToArray(array2))
@@ -212,8 +225,8 @@
CPWL_Color color1;
CPWL_Color color2;
- ConvertArrayToPWLColor(array1, color1);
- ConvertArrayToPWLColor(array2, color2);
+ ConvertArrayToPWLColor(pRuntime, array1, &color1);
+ ConvertArrayToPWLColor(pRuntime, array2, &color2);
color1.ConvertColorType(color2.nColorType);
vRet = color1 == color2;
return TRUE;
diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h
index 2beddb5..5c8c99f 100644
--- a/fpdfsdk/javascript/color.h
+++ b/fpdfsdk/javascript/color.h
@@ -41,9 +41,12 @@
CJS_Value& vRet,
CFX_WideString& sError);
- public:
- static void ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array);
- static void ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color);
+ static void ConvertPWLColorToArray(CJS_Runtime* pRuntime,
+ const CPWL_Color& color,
+ CJS_Array* array);
+ static void ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
+ const CJS_Array& array,
+ CPWL_Color* color);
private:
CPWL_Color m_crTransparent;