summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/JS_Define.cpp2
-rw-r--r--fxjs/JS_Define.h6
-rw-r--r--fxjs/cjs_global.cpp12
-rw-r--r--fxjs/cjs_globalarrays.cpp3
-rw-r--r--fxjs/cjs_globalconsts.cpp12
-rw-r--r--fxjs/cjs_publicmethods.cpp2
-rw-r--r--fxjs/cjs_runtime.cpp5
-rw-r--r--fxjs/cjs_runtime.h2
-rw-r--r--fxjs/fxjs_v8.cpp22
-rw-r--r--fxjs/fxjs_v8.h6
10 files changed, 43 insertions, 29 deletions
diff --git a/fxjs/JS_Define.cpp b/fxjs/JS_Define.cpp
index 90f7557422..171e05c66e 100644
--- a/fxjs/JS_Define.cpp
+++ b/fxjs/JS_Define.cpp
@@ -232,7 +232,7 @@ double JS_DateParse(const WideString& str) {
v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
const int argc = 1;
v8::Local<v8::Value> timeStr =
- CJS_Runtime::CurrentRuntimeFromIsolate(pIsolate)->NewString(
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(pIsolate)->NewString(
str.AsStringView());
v8::Local<v8::Value> argv[argc] = {timeStr};
v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked();
diff --git a/fxjs/JS_Define.h b/fxjs/JS_Define.h
index 08654b96e1..f45738e847 100644
--- a/fxjs/JS_Define.h
+++ b/fxjs/JS_Define.h
@@ -66,7 +66,7 @@ void JSPropGetter(const char* prop_name_string,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -94,7 +94,7 @@ void JSPropSetter(const char* prop_name_string,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -118,7 +118,7 @@ void JSMethod(const char* method_name_string,
const char* class_name_string,
const v8::FunctionCallbackInfo<v8::Value>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index eb66488d8e..3fc4bf0f0f 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -33,7 +33,7 @@ void JSSpecialPropQuery(const char*,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Integer>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -53,7 +53,7 @@ void JSSpecialPropGet(const char* class_name,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -81,7 +81,7 @@ void JSSpecialPropPut(const char* class_name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -104,7 +104,7 @@ void JSSpecialPropDel(const char* class_name,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Boolean>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
@@ -360,7 +360,7 @@ CJS_Return JSGlobalAlternate::setPersistent(
void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
CJS_Runtime* pRuntime =
- static_cast<CJS_Runtime*>(CFXJS_Engine::CurrentEngineFromIsolate(
+ static_cast<CJS_Runtime*>(CFXJS_Engine::EngineFromIsolateCurrentContext(
m_pJSObject->ToV8Object()->GetIsolate()));
for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) {
@@ -501,7 +501,7 @@ void JSGlobalAlternate::ObjectToArray(CJS_Runtime* pRuntime,
void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
CJS_KeyValue* pData) {
- CJS_Runtime* pRuntime = CJS_Runtime::CurrentRuntimeFromIsolate(
+ CJS_Runtime* pRuntime = CJS_Runtime::RuntimeFromIsolateCurrentContext(
m_pJSObject->ToV8Object()->GetIsolate());
for (int i = 0, sz = pData->objData.Count(); i < sz; i++) {
diff --git a/fxjs/cjs_globalarrays.cpp b/fxjs/cjs_globalarrays.cpp
index 7857161205..818b13f0e8 100644
--- a/fxjs/cjs_globalarrays.cpp
+++ b/fxjs/cjs_globalarrays.cpp
@@ -16,7 +16,8 @@
(rt)->DefineGlobalConst( \
(name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
CJS_Runtime* pCurrentRuntime = \
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); \
+ CJS_Runtime::RuntimeFromIsolateCurrentContext( \
+ info.GetIsolate()); \
if (pCurrentRuntime) \
info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \
}); \
diff --git a/fxjs/cjs_globalconsts.cpp b/fxjs/cjs_globalconsts.cpp
index 598479780a..a07bf60302 100644
--- a/fxjs/cjs_globalconsts.cpp
+++ b/fxjs/cjs_globalconsts.cpp
@@ -6,12 +6,12 @@
#include "fxjs/cjs_globalconsts.h"
-#define GLOBAL_STRING(rt, name, value) \
- (rt)->DefineGlobalConst( \
- (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
- info.GetReturnValue().Set( \
- CFXJS_Engine::CurrentEngineFromIsolate(info.GetIsolate()) \
- ->NewString(value)); \
+#define GLOBAL_STRING(rt, name, value) \
+ (rt)->DefineGlobalConst( \
+ (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
+ info.GetReturnValue().Set( \
+ CFXJS_Engine::EngineFromIsolateCurrentContext(info.GetIsolate()) \
+ ->NewString(value)); \
})
// static
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 45eae7f8d2..9fcfc5f291 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -120,7 +120,7 @@ template <CJS_Return (*F)(CJS_Runtime*,
void JSGlobalFunc(const char* func_name_string,
const v8::FunctionCallbackInfo<v8::Value>& info) {
CJS_Runtime* pRuntime =
- CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate());
+ CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
if (!pRuntime)
return;
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 919c5a9b66..bffd77cba7 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -63,9 +63,10 @@ std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
}
// static
-CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) {
+CJS_Runtime* CJS_Runtime::RuntimeFromIsolateCurrentContext(
+ v8::Isolate* pIsolate) {
return static_cast<CJS_Runtime*>(
- CFXJS_Engine::CurrentEngineFromIsolate(pIsolate));
+ CFXJS_Engine::EngineFromIsolateCurrentContext(pIsolate));
}
CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv)
diff --git a/fxjs/cjs_runtime.h b/fxjs/cjs_runtime.h
index 7ecc0d5ce4..5d55b9a492 100644
--- a/fxjs/cjs_runtime.h
+++ b/fxjs/cjs_runtime.h
@@ -27,7 +27,7 @@ class CJS_Runtime : public IJS_Runtime,
public:
using FieldEvent = std::pair<WideString, JS_EVENT_T>;
- static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate);
+ static CJS_Runtime* RuntimeFromIsolateCurrentContext(v8::Isolate* pIsolate);
explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv);
~CJS_Runtime() override;
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 50345cfcd1..e73ab0a8f0 100644
--- a/fxjs/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -177,8 +177,8 @@ void V8TemplateMapTraits::Dispose(v8::Isolate* isolate,
if (!pObjDef)
return;
if (pObjDef->m_pDestructor) {
- pObjDef->m_pDestructor(CFXJS_Engine::CurrentEngineFromIsolate(isolate),
- obj);
+ pObjDef->m_pDestructor(
+ CFXJS_Engine::EngineFromIsolateCurrentContext(isolate), obj);
}
CFXJS_Engine::FreeObjectPrivate(obj);
}
@@ -261,10 +261,19 @@ CFXJS_Engine::CFXJS_Engine(v8::Isolate* pIsolate) : CJS_V8(pIsolate) {}
CFXJS_Engine::~CFXJS_Engine() = default;
// static
-CFXJS_Engine* CFXJS_Engine::CurrentEngineFromIsolate(v8::Isolate* pIsolate) {
+CFXJS_Engine* CFXJS_Engine::EngineFromIsolateCurrentContext(
+ v8::Isolate* pIsolate) {
+ return EngineFromContext(pIsolate->GetCurrentContext());
+}
+
+CFXJS_Engine* CFXJS_Engine::EngineFromContext(v8::Local<v8::Context> pContext) {
return static_cast<CFXJS_Engine*>(
- pIsolate->GetCurrentContext()->GetAlignedPointerFromEmbedderData(
- kPerContextDataIndex));
+ pContext->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
+}
+
+void CFXJS_Engine::SetEngineInContext(CFXJS_Engine* pEngine,
+ v8::Local<v8::Context> pContext) {
+ pContext->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pEngine);
}
// static
@@ -385,8 +394,7 @@ void CFXJS_Engine::InitializeEngine() {
v8::Local<v8::Context> v8Context = v8::Context::New(
GetIsolate(), nullptr, GetGlobalObjectTemplate(GetIsolate()));
v8::Context::Scope context_scope(v8Context);
-
- v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, this);
+ SetEngineInContext(this, v8Context);
int maxID = CFXJS_ObjDefinition::MaxID(GetIsolate());
m_StaticObjects.resize(maxID + 1);
diff --git a/fxjs/fxjs_v8.h b/fxjs/fxjs_v8.h
index 4575235755..0372ade9ce 100644
--- a/fxjs/fxjs_v8.h
+++ b/fxjs/fxjs_v8.h
@@ -137,7 +137,11 @@ class CFXJS_Engine : public CJS_V8 {
v8::Local<v8::Object> obj);
using Destructor = void (*)(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj);
- static CFXJS_Engine* CurrentEngineFromIsolate(v8::Isolate* pIsolate);
+ static CFXJS_Engine* EngineFromIsolateCurrentContext(v8::Isolate* pIsolate);
+ static CFXJS_Engine* EngineFromContext(v8::Local<v8::Context> pContext);
+ static void SetEngineInContext(CFXJS_Engine* pEngine,
+ v8::Local<v8::Context> pContext);
+
static int GetObjDefnID(v8::Local<v8::Object> pObj);
// Always returns a valid, newly-created objDefnID.