Pass ByteStringView to CFXJSE_Context::ExecuteScript()
Most callers already have one, and avoids implicit construction of
one as an argument to NewStringHelper().
Change-Id: I59f933bfa6c66e8e90fc1b7b63195dfdbf3da4cc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86854
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_context.cpp b/fxjs/xfa/cfxjse_context.cpp
index 563bfe7..25e93bf 100644
--- a/fxjs/xfa/cfxjse_context.cpp
+++ b/fxjs/xfa/cfxjse_context.cpp
@@ -239,14 +239,14 @@
ExecuteScript(szConsoleScript, nullptr, v8::Local<v8::Object>());
}
-bool CFXJSE_Context::ExecuteScript(const char* szScript,
+bool CFXJSE_Context::ExecuteScript(ByteStringView bsScript,
CFXJSE_Value* pRetValue,
v8::Local<v8::Object> hNewThis) {
CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
v8::Local<v8::Context> hContext = GetIsolate()->GetCurrentContext();
v8::TryCatch trycatch(GetIsolate());
v8::Local<v8::String> hScriptString =
- fxv8::NewStringHelper(GetIsolate(), szScript);
+ fxv8::NewStringHelper(GetIsolate(), bsScript);
if (hNewThis.IsEmpty()) {
v8::Local<v8::Script> hScript;
if (v8::Script::Compile(hContext, hScriptString).ToLocal(&hScript)) {
diff --git a/fxjs/xfa/cfxjse_context.h b/fxjs/xfa/cfxjse_context.h
index 381f8b0..bf3a686 100644
--- a/fxjs/xfa/cfxjse_context.h
+++ b/fxjs/xfa/cfxjse_context.h
@@ -41,7 +41,7 @@
void EnableCompatibleMode();
// Note: `pNewThisObject` may be empty.
- bool ExecuteScript(const char* szScript,
+ bool ExecuteScript(ByteStringView bsScript,
CFXJSE_Value* pRetValue,
v8::Local<v8::Object> pNewThisObject);
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp
index 82594ca..8f53cdb 100644
--- a/fxjs/xfa/cfxjse_engine.cpp
+++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -179,7 +179,8 @@
pThisBinding = GetOrCreateJSBindingFromMap(pThisObject);
IJS_Runtime::ScopedEventContext ctx(m_pSubordinateRuntime.Get());
- return m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pThisBinding);
+ return m_JsContext->ExecuteScript(btScript.AsStringView(), hRetValue,
+ pThisBinding);
}
bool CFXJSE_Engine::QueryNodeByFlag(CXFA_Node* refNode,
@@ -592,8 +593,8 @@
CreateVariablesContext(pScriptNode, pThisObject);
AutoRestorer<cppgc::Persistent<CXFA_Object>> nodeRestorer(&m_pThisObject);
m_pThisObject = pThisObject;
- return pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get(),
- v8::Local<v8::Object>());
+ return pVariablesContext->ExecuteScript(
+ btScript.AsStringView(), hRetValue.get(), v8::Local<v8::Object>());
}
CFXJSE_Context* CFXJSE_Engine::VariablesContextForScriptNode(
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 6b30378..8c72a49 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -3311,14 +3311,13 @@
pContext->ThrowCompilerErrorException();
return;
}
-
std::unique_ptr<CFXJSE_Context> pNewContext =
CFXJSE_Context::Create(pIsolate, nullptr, nullptr, nullptr);
auto returnValue = std::make_unique<CFXJSE_Value>();
- pNewContext->ExecuteScript(
- FX_UTF8Encode(wsJavaScriptBuf.value().AsStringView()).c_str(),
- returnValue.get(), v8::Local<v8::Object>());
+ ByteString bsScript = FX_UTF8Encode(wsJavaScriptBuf.value().AsStringView());
+ pNewContext->ExecuteScript(bsScript.AsStringView(), returnValue.get(),
+ v8::Local<v8::Object>());
info.GetReturnValue().Set(returnValue->DirectGetValue());
}