Replace calls to v8::Isolate::GetCurrent(), part 2
Bug: pdfium:1737
Change-Id: Ief32867361e14c211eac0fe8f1d4792ee48bd035
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86295
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index f85c983..6b30378 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -5559,5 +5559,5 @@
void CFXJSE_FormCalcContext::ThrowException(const WideString& str) const {
DCHECK(!str.IsEmpty());
- FXJSE_ThrowMessage(str.ToUTF8().AsStringView());
+ FXJSE_ThrowMessage(GetIsolate(), str.ToUTF8().AsStringView());
}
diff --git a/fxjs/xfa/cfxjse_value.cpp b/fxjs/xfa/cfxjse_value.cpp
index f676c13..a22bd61 100644
--- a/fxjs/xfa/cfxjse_value.cpp
+++ b/fxjs/xfa/cfxjse_value.cpp
@@ -63,10 +63,8 @@
} // namespace
-void FXJSE_ThrowMessage(ByteStringView utf8Message) {
- v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
+void FXJSE_ThrowMessage(v8::Isolate* pIsolate, ByteStringView utf8Message) {
DCHECK(pIsolate);
-
CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate);
v8::Local<v8::String> hMessage = fxv8::NewStringHelper(pIsolate, utf8Message);
v8::Local<v8::Value> hError = v8::Exception::Error(hMessage);
diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp
index 751ff67..fc8a18d 100644
--- a/fxjs/xfa/cjx_exclgroup.cpp
+++ b/fxjs/xfa/cjx_exclgroup.cpp
@@ -155,5 +155,5 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting)
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
}
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index 20634e1..b0a2ee7 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -351,7 +351,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -365,7 +365,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewNullHelper(pIsolate);
diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp
index 3a24157..8fc66aa 100644
--- a/fxjs/xfa/cjx_hostpseudomodel.cpp
+++ b/fxjs/xfa/cjx_hostpseudomodel.cpp
@@ -85,7 +85,7 @@
return;
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewStringHelper(pIsolate, "Exchange");
@@ -133,7 +133,8 @@
return;
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set language value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set language value."));
return;
}
ByteString lang = pNotify->GetAppProvider()->GetLanguage().ToUTF8();
@@ -150,7 +151,8 @@
CXFA_FFDoc* hDoc = pNotify->GetFFDoc();
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set numPages value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set numPages value."));
return;
}
*pValue = fxv8::NewNumberHelper(pIsolate, hDoc->CountPages());
@@ -165,7 +167,8 @@
return;
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set platform value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set platform value."));
return;
}
ByteString plat = pNotify->GetAppProvider()->GetPlatform().ToUTF8();
@@ -219,7 +222,8 @@
return;
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set variation value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set variation value."));
return;
}
*pValue = fxv8::NewStringHelper(pIsolate, "Full");
@@ -230,7 +234,8 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set version value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set version value."));
return;
}
*pValue = fxv8::NewStringHelper(pIsolate, "11");
@@ -245,7 +250,7 @@
return;
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
ByteString bsName = pNotify->GetAppProvider()->GetAppName().ToUTF8();
diff --git a/fxjs/xfa/cjx_instancemanager.cpp b/fxjs/xfa/cjx_instancemanager.cpp
index d034dd3..a29a23c 100644
--- a/fxjs/xfa/cjx_instancemanager.cpp
+++ b/fxjs/xfa/cjx_instancemanager.cpp
@@ -39,17 +39,18 @@
return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
}
-int32_t CJX_InstanceManager::SetInstances(int32_t iDesired) {
+int32_t CJX_InstanceManager::SetInstances(v8::Isolate* pIsolate,
+ int32_t iDesired) {
CXFA_Occur* occur = GetXFANode()->GetOccurIfExists();
int32_t iMin = occur ? occur->GetMin() : CXFA_Occur::kDefaultMin;
if (iDesired < iMin) {
- ThrowTooManyOccurrencesException(L"min");
+ ThrowTooManyOccurrencesException(pIsolate, L"min");
return 1;
}
int32_t iMax = occur ? occur->GetMax() : CXFA_Occur::kDefaultMax;
if (iMax >= 0 && iDesired > iMax) {
- ThrowTooManyOccurrencesException(L"max");
+ ThrowTooManyOccurrencesException(pIsolate, L"max");
return 2;
}
@@ -70,7 +71,7 @@
: GetXFANode()->GetItemIfExists(iDesired - 1);
if (!pPrevSibling) {
// TODO(dsinclair): Better error?
- ThrowIndexOutOfBoundsException();
+ ThrowIndexOutOfBoundsException(pIsolate);
return 0;
}
@@ -110,10 +111,12 @@
return 0;
}
-int32_t CJX_InstanceManager::MoveInstance(int32_t iTo, int32_t iFrom) {
+int32_t CJX_InstanceManager::MoveInstance(v8::Isolate* pIsolate,
+ int32_t iTo,
+ int32_t iFrom) {
int32_t iCount = GetXFANode()->GetCount();
if (iFrom > iCount || iTo > iCount - 1) {
- ThrowIndexOutOfBoundsException();
+ ThrowIndexOutOfBoundsException(pIsolate);
return 1;
}
if (iFrom < 0 || iTo < 0 || iFrom == iTo)
@@ -121,7 +124,7 @@
CXFA_Node* pMoveInstance = GetXFANode()->GetItemIfExists(iFrom);
if (!pMoveInstance) {
- ThrowIndexOutOfBoundsException();
+ ThrowIndexOutOfBoundsException(pIsolate);
return 1;
}
@@ -144,7 +147,7 @@
int32_t iFrom = runtime->ToInt32(params[0]);
int32_t iTo = runtime->ToInt32(params[1]);
- MoveInstance(iTo, iFrom);
+ MoveInstance(runtime->GetIsolate(), iTo, iFrom);
CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
if (!pNotify)
@@ -214,7 +217,7 @@
if (params.size() != 1)
return CJS_Result::Failure(JSMessage::kParamError);
- SetInstances(runtime->ToInt32(params[0]));
+ SetInstances(runtime->GetIsolate(), runtime->ToInt32(params[0]));
return CJS_Result::Success();
}
@@ -303,7 +306,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
CXFA_Occur* occur = GetXFANode()->GetOccurIfExists();
@@ -316,7 +319,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
CXFA_Occur* occur = GetXFANode()->GetOccurIfExists();
@@ -329,7 +332,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- SetInstances(fxv8::ReentrantToInt32Helper(pIsolate, *pValue));
+ SetInstances(pIsolate, fxv8::ReentrantToInt32Helper(pIsolate, *pValue));
return;
}
*pValue = fxv8::NewNumberHelper(pIsolate, GetXFANode()->GetCount());
diff --git a/fxjs/xfa/cjx_instancemanager.h b/fxjs/xfa/cjx_instancemanager.h
index 0d574f6..20227c1 100644
--- a/fxjs/xfa/cjx_instancemanager.h
+++ b/fxjs/xfa/cjx_instancemanager.h
@@ -9,6 +9,7 @@
#include "fxjs/xfa/cjx_node.h"
#include "fxjs/xfa/jse_define.h"
+#include "v8/include/v8-forward.h"
class CXFA_InstanceManager;
@@ -30,7 +31,7 @@
JSE_PROP(max);
JSE_PROP(min);
- int32_t MoveInstance(int32_t iTo, int32_t iFrom);
+ int32_t MoveInstance(v8::Isolate* pIsolate, int32_t iTo, int32_t iFrom);
private:
explicit CJX_InstanceManager(CXFA_InstanceManager* mgr);
@@ -41,7 +42,7 @@
static const TypeTag static_type__ = TypeTag::InstanceManager;
static const CJX_MethodSpec MethodSpecs[];
- int32_t SetInstances(int32_t iDesired);
+ int32_t SetInstances(v8::Isolate* pIsolate, int32_t iDesired);
};
#endif // FXJS_XFA_CJX_INSTANCEMANAGER_H_
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp
index 9222413..ffb12dd 100644
--- a/fxjs/xfa/cjx_layoutpseudomodel.cpp
+++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp
@@ -71,7 +71,8 @@
if (!pNotify)
return;
if (bSetting) {
- ThrowException(WideString::FromASCII("Unable to set ready value."));
+ ThrowException(pIsolate,
+ WideString::FromASCII("Unable to set ready value."));
return;
}
diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp
index 254548b..de197b6 100644
--- a/fxjs/xfa/cjx_list.cpp
+++ b/fxjs/xfa/cjx_list.cpp
@@ -106,7 +106,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewNumberHelper(
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index e7a263d..447f5da 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -406,7 +406,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewStringHelper(
@@ -418,7 +418,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = GetDocument()->GetScriptContext()->GetOrCreateJSBindingFromMap(
@@ -430,7 +430,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewBooleanHelper(pIsolate, GetXFANode()->IsContainerNode());
@@ -441,7 +441,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
if (GetXFANode()->GetElementType() == XFA_Element::Subform) {
@@ -456,7 +456,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index ef3051f..cf487c5 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -26,6 +26,7 @@
#include "third_party/base/check_op.h"
#include "third_party/base/compiler_specific.h"
#include "third_party/base/containers/contains.h"
+#include "v8/include/v8-forward.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
#include "xfa/fgas/crt/cfgas_decimal.h"
@@ -134,7 +135,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewStringHelper(pIsolate, GetXFAObject()->GetClassName());
@@ -168,35 +169,43 @@
params);
}
-void CJX_Object::ThrowTooManyOccurrencesException(const WideString& obj) const {
- ThrowException(WideString::FromASCII("The element [") + obj +
- WideString::FromASCII(
- "] has violated its allowable number of occurrences."));
+void CJX_Object::ThrowTooManyOccurrencesException(v8::Isolate* pIsolate,
+ const WideString& obj) const {
+ ThrowException(
+ pIsolate, WideString::FromASCII("The element [") + obj +
+ WideString::FromASCII(
+ "] has violated its allowable number of occurrences."));
}
-void CJX_Object::ThrowInvalidPropertyException() const {
- ThrowException(WideString::FromASCII("Invalid property set operation."));
+void CJX_Object::ThrowInvalidPropertyException(v8::Isolate* pIsolate) const {
+ ThrowException(pIsolate,
+ WideString::FromASCII("Invalid property set operation."));
}
-void CJX_Object::ThrowIndexOutOfBoundsException() const {
- ThrowException(WideString::FromASCII("Index value is out of bounds."));
+void CJX_Object::ThrowIndexOutOfBoundsException(v8::Isolate* pIsolate) const {
+ ThrowException(pIsolate,
+ WideString::FromASCII("Index value is out of bounds."));
}
void CJX_Object::ThrowParamCountMismatchException(
+ v8::Isolate* pIsolate,
const WideString& method) const {
ThrowException(
+ pIsolate,
WideString::FromASCII("Incorrect number of parameters calling method '") +
- method + WideString::FromASCII("'."));
+ method + WideString::FromASCII("'."));
}
-void CJX_Object::ThrowArgumentMismatchException() const {
- ThrowException(WideString::FromASCII(
- "Argument mismatch in property or function argument."));
+void CJX_Object::ThrowArgumentMismatchException(v8::Isolate* pIsolate) const {
+ ThrowException(pIsolate,
+ WideString::FromASCII(
+ "Argument mismatch in property or function argument."));
}
-void CJX_Object::ThrowException(const WideString& str) const {
+void CJX_Object::ThrowException(v8::Isolate* pIsolate,
+ const WideString& str) const {
DCHECK(!str.IsEmpty());
- FXJSE_ThrowMessage(str.ToUTF8().AsStringView());
+ FXJSE_ThrowMessage(pIsolate, str.ToUTF8().AsStringView());
}
bool CJX_Object::HasAttribute(XFA_Attribute eAttr) const {
@@ -1223,7 +1232,7 @@
if (!validate) {
// TODO(dsinclair): Better error message?
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -1338,7 +1347,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -1355,7 +1364,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -1411,7 +1420,7 @@
return;
auto* mgr = static_cast<CJX_InstanceManager*>(pManagerNode->JSObject());
- mgr->MoveInstance(iTo, iFrom);
+ mgr->MoveInstance(pIsolate, iTo, iFrom);
CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
if (!pNotify)
return;
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index 151601a..7bc5e83 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -20,6 +20,7 @@
#include "third_party/base/span.h"
#include "v8/include/cppgc/garbage-collected.h"
#include "v8/include/cppgc/member.h"
+#include "v8/include/v8-forward.h"
#include "xfa/fxfa/fxfa_basic.h"
class CFXJSE_MapModule;
@@ -210,11 +211,13 @@
CalcData* GetOrCreateCalcData(cppgc::Heap* heap);
void TakeCalcDataFrom(CJX_Object* that);
- void ThrowInvalidPropertyException() const;
- void ThrowArgumentMismatchException() const;
- void ThrowIndexOutOfBoundsException() const;
- void ThrowParamCountMismatchException(const WideString& method) const;
- void ThrowTooManyOccurrencesException(const WideString& obj) const;
+ void ThrowInvalidPropertyException(v8::Isolate* pIsolate) const;
+ void ThrowArgumentMismatchException(v8::Isolate* pIsolate) const;
+ void ThrowIndexOutOfBoundsException(v8::Isolate* pIsolate) const;
+ void ThrowParamCountMismatchException(v8::Isolate* pIsolate,
+ const WideString& method) const;
+ void ThrowTooManyOccurrencesException(v8::Isolate* pIsolate,
+ const WideString& obj) const;
protected:
enum class SOMMessageType {
@@ -239,7 +242,7 @@
bool bScriptModify);
void DefineMethods(pdfium::span<const CJX_MethodSpec> methods);
void MoveBufferMapData(CXFA_Object* pSrcObj, CXFA_Object* pDstObj);
- void ThrowException(const WideString& str) const;
+ void ThrowException(v8::Isolate* pIsolate, const WideString& str) const;
private:
using Type__ = CJX_Object;
diff --git a/fxjs/xfa/cjx_script.cpp b/fxjs/xfa/cjx_script.cpp
index b508d28..d917c73 100644
--- a/fxjs/xfa/cjx_script.cpp
+++ b/fxjs/xfa/cjx_script.cpp
@@ -23,7 +23,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
*pValue = fxv8::NewStringHelper(pIsolate, "0");
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp
index 084ddf7..31ee3be 100644
--- a/fxjs/xfa/cjx_subform.cpp
+++ b/fxjs/xfa/cjx_subform.cpp
@@ -109,7 +109,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp
index 8e402b2..eebe818 100644
--- a/fxjs/xfa/cjx_tree.cpp
+++ b/fxjs/xfa/cjx_tree.cpp
@@ -103,7 +103,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
const Mask<XFA_ResolveFlag> kFlags = {XFA_ResolveFlag::kSiblings,
@@ -117,7 +117,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
const Mask<XFA_ResolveFlag> kFlags = {XFA_ResolveFlag::kSiblings,
@@ -133,7 +133,7 @@
XFA_Attribute eAttribute) {
if (bSetting) {
WideString wsMessage = L"Unable to set ";
- FXJSE_ThrowMessage(wsMessage.ToUTF8().AsStringView());
+ FXJSE_ThrowMessage(pIsolate, wsMessage.ToUTF8().AsStringView());
return;
}
@@ -152,7 +152,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -169,7 +169,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -184,7 +184,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
@@ -199,7 +199,7 @@
bool bSetting,
XFA_Attribute eAttribute) {
if (bSetting) {
- ThrowInvalidPropertyException();
+ ThrowInvalidPropertyException(pIsolate);
return;
}
diff --git a/fxjs/xfa/fxjse.h b/fxjs/xfa/fxjse.h
index e5f6262..5e34632 100644
--- a/fxjs/xfa/fxjse.h
+++ b/fxjs/xfa/fxjse.h
@@ -91,6 +91,6 @@
extern const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor;
extern const FXJSE_CLASS_DESCRIPTOR kFormCalcFM2JSDescriptor;
-void FXJSE_ThrowMessage(ByteStringView utf8Message);
+void FXJSE_ThrowMessage(v8::Isolate* pIsolate, ByteStringView utf8Message);
#endif // FXJS_XFA_FXJSE_H_