Split CFXJSE_Engine::QueryVariableValue() into Query/Update.
-- Add VariablesContextForScriptNode() helper
-- Remove out parameter for update method.
-- Keep out parameter for query method.
Change-Id: I8436c0c27ae91499ca4736860b529be0f6901148
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81112
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp
index 8e04bb8..058ed487 100644
--- a/fxjs/xfa/cfxjse_engine.cpp
+++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -310,9 +310,8 @@
CXFA_Object* pScriptObject =
lpScriptContext->GetVariablesScript(pOriginalObject);
- if (pScriptObject &&
- lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName,
- &pValue, true)) {
+ if (pScriptObject && lpScriptContext->QueryVariableValue(
+ pScriptObject->AsNode(), szPropName, &pValue)) {
return pValue;
}
@@ -392,7 +391,7 @@
return pReturnValue;
if (lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName,
- &pReturnValue, true)) {
+ &pReturnValue)) {
return pReturnValue;
}
Optional<XFA_SCRIPTATTRIBUTEINFO> info = XFA_GetScriptAttributeByName(
@@ -470,8 +469,8 @@
CXFA_Object* pScriptObject =
lpScriptContext->GetVariablesScript(pOriginalObject);
if (pScriptObject) {
- lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName,
- &pValue, false);
+ lpScriptContext->UpdateVariableValue(ToNode(pScriptObject), szPropName,
+ pValue);
}
}
@@ -584,31 +583,29 @@
v8::Local<v8::Object>());
}
-bool CFXJSE_Engine::QueryVariableValue(CXFA_Node* pScriptNode,
- ByteStringView szPropName,
- v8::Local<v8::Value>* pValue,
- bool bGetter) {
+CFXJSE_Context* CFXJSE_Engine::VariablesContextForScriptNode(
+ CXFA_Node* pScriptNode) {
if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script)
- return false;
+ return nullptr;
CXFA_Node* variablesNode = pScriptNode->GetParent();
if (!variablesNode ||
variablesNode->GetElementType() != XFA_Element::Variables) {
- return false;
+ return nullptr;
}
auto it = m_mapVariableToContext.find(pScriptNode->JSObject());
- if (it == m_mapVariableToContext.end() || !it->second)
+ return it != m_mapVariableToContext.end() ? it->second.get() : nullptr;
+}
+
+bool CFXJSE_Engine::QueryVariableValue(CXFA_Node* pScriptNode,
+ ByteStringView szPropName,
+ v8::Local<v8::Value>* pValue) {
+ CFXJSE_Context* pVariableContext = VariablesContextForScriptNode(pScriptNode);
+ if (!pVariableContext)
return false;
- CFXJSE_Context* pVariableContext = it->second.get();
v8::Local<v8::Object> pObject = pVariableContext->GetGlobalObject();
- if (!bGetter) {
- fxv8::ReentrantSetObjectOwnPropertyHelper(GetIsolate(), pObject, szPropName,
- *pValue);
- return true;
- }
-
if (!fxv8::ReentrantHasObjectOwnPropertyHelper(GetIsolate(), pObject,
szPropName)) {
return false;
@@ -627,6 +624,19 @@
return true;
}
+bool CFXJSE_Engine::UpdateVariableValue(CXFA_Node* pScriptNode,
+ ByteStringView szPropName,
+ v8::Local<v8::Value> pValue) {
+ CFXJSE_Context* pVariableContext = VariablesContextForScriptNode(pScriptNode);
+ if (!pVariableContext)
+ return false;
+
+ v8::Local<v8::Object> pObject = pVariableContext->GetGlobalObject();
+ fxv8::ReentrantSetObjectOwnPropertyHelper(GetIsolate(), pObject, szPropName,
+ pValue);
+ return true;
+}
+
void CFXJSE_Engine::RemoveBuiltInObjs(CFXJSE_Context* pContext) {
CFXJSE_ScopeUtil_IsolateHandleContext scope(GetJseContext());
v8::Local<v8::Object> pObject = pContext->GetGlobalObject();
diff --git a/fxjs/xfa/cfxjse_engine.h b/fxjs/xfa/cfxjse_engine.h
index 65707b3..b09643c 100644
--- a/fxjs/xfa/cfxjse_engine.h
+++ b/fxjs/xfa/cfxjse_engine.h
@@ -160,10 +160,13 @@
bool IsStrictScopeInJavaScript();
CXFA_Object* GetVariablesThis(CXFA_Object* pObject);
CXFA_Object* GetVariablesScript(CXFA_Object* pObject);
+ CFXJSE_Context* VariablesContextForScriptNode(CXFA_Node* pScriptNode);
bool QueryVariableValue(CXFA_Node* pScriptNode,
ByteStringView szPropName,
- v8::Local<v8::Value>* pValue,
- bool bGetter);
+ v8::Local<v8::Value>* pValue);
+ bool UpdateVariableValue(CXFA_Node* pScriptNode,
+ ByteStringView szPropName,
+ v8::Local<v8::Value> pValue);
bool RunVariablesScript(CXFA_Node* pScriptNode);
UnownedPtr<CJS_Runtime> const m_pSubordinateRuntime;