summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cfxjs_engine.cpp5
-rw-r--r--fxjs/cfxjs_engine.h5
-rw-r--r--fxjs/cjs_app.cpp22
-rw-r--r--fxjs/cjs_document.cpp33
-rw-r--r--fxjs/cjs_eventhandler.cpp18
-rw-r--r--fxjs/cjs_field.cpp10
-rw-r--r--fxjs/cjs_global.cpp54
-rw-r--r--fxjs/cjs_runtime.cpp12
-rw-r--r--fxjs/js_define.h27
9 files changed, 87 insertions, 99 deletions
diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp
index 107ed3abae..5d0f3b0ec5 100644
--- a/fxjs/cfxjs_engine.cpp
+++ b/fxjs/cfxjs_engine.cpp
@@ -591,15 +591,16 @@ void CFXJS_Engine::Error(const WideString& message) {
GetIsolate()->ThrowException(NewString(message.AsStringView()));
}
+// static
CJS_Object* CFXJS_Engine::GetObjectPrivate(v8::Local<v8::Object> pObj) {
CFXJS_PerObjectData* pData = CFXJS_PerObjectData::GetFromObject(pObj);
if (!pData && !pObj.IsEmpty()) {
// It could be a global proxy object.
v8::Local<v8::Value> v = pObj->GetPrototype();
- v8::Local<v8::Context> context = GetIsolate()->GetCurrentContext();
if (v->IsObject()) {
pData = CFXJS_PerObjectData::GetFromObject(
- v->ToObject(context).ToLocalChecked());
+ v->ToObject(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .ToLocalChecked());
}
}
return pData ? pData->m_pPrivate.get() : nullptr;
diff --git a/fxjs/cfxjs_engine.h b/fxjs/cfxjs_engine.h
index d1fb70cc28..0c9d70d83d 100644
--- a/fxjs/cfxjs_engine.h
+++ b/fxjs/cfxjs_engine.h
@@ -85,7 +85,7 @@ class CFXJS_Engine : public CFX_V8 {
static CFXJS_Engine* EngineFromContext(v8::Local<v8::Context> pContext);
static int GetObjDefnID(v8::Local<v8::Object> pObj);
-
+ static CJS_Object* GetObjectPrivate(v8::Local<v8::Object> pObj);
static void SetObjectPrivate(v8::Local<v8::Object> pObj,
std::unique_ptr<CJS_Object> p);
static void FreeObjectPrivate(v8::Local<v8::Object> pObj);
@@ -128,9 +128,6 @@ class CFXJS_Engine : public CFX_V8 {
v8::Local<v8::Object> GetThisObj();
v8::Local<v8::Object> NewFXJSBoundObject(int nObjDefnID,
bool bStatic = false);
- // Retrieve native object binding.
- CJS_Object* GetObjectPrivate(v8::Local<v8::Object> pObj);
-
void Error(const WideString& message);
v8::Local<v8::Context> GetV8Context() {
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index 3f9244cf66..1997e9afe9 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -99,9 +99,10 @@ CJS_App::~CJS_App() = default;
CJS_Return CJS_App::get_active_docs(CJS_Runtime* pRuntime) {
CJS_Document* pJSDocument = nullptr;
v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
- if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::GetObjDefnID())
- pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
-
+ if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::GetObjDefnID()) {
+ pJSDocument =
+ static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pObj));
+ }
v8::Local<v8::Array> aDocs = pRuntime->NewArray();
pRuntime->PutArrayElement(
aDocs, 0,
@@ -326,8 +327,9 @@ CJS_Return CJS_App::setInterval(
if (pRetObj.IsEmpty())
return CJS_Return(false);
- CJS_TimerObj* pJS_TimerObj =
- static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
+ auto* pJS_TimerObj =
+ static_cast<CJS_TimerObj*>(CFXJS_Engine::GetObjectPrivate(pRetObj));
+
pJS_TimerObj->SetTimer(pTimerRef);
return CJS_Return(pRetObj);
}
@@ -354,8 +356,9 @@ CJS_Return CJS_App::setTimeOut(
if (pRetObj.IsEmpty())
return CJS_Return(false);
- CJS_TimerObj* pJS_TimerObj =
- static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
+ auto* pJS_TimerObj =
+ static_cast<CJS_TimerObj*>(CFXJS_Engine::GetObjectPrivate(pRetObj));
+
pJS_TimerObj->SetTimer(pTimerRef);
return CJS_Return(pRetObj);
}
@@ -389,12 +392,11 @@ void CJS_App::ClearTimerCommon(CJS_Runtime* pRuntime,
if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::GetObjDefnID())
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(pObj);
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(pObj);
if (!pJSObj)
return;
- CJS_TimerObj* pJS_TimerObj = static_cast<CJS_TimerObj*>(pJSObj);
- GlobalTimer::Cancel(pJS_TimerObj->GetTimerID());
+ GlobalTimer::Cancel(static_cast<CJS_TimerObj*>(pJSObj)->GetTimerID());
}
CJS_Return CJS_App::execMenuItem(
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 3022519293..d6dc4d6020 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -254,12 +254,12 @@ CJS_Return CJS_Document::getField(
if (pFieldObj.IsEmpty())
return CJS_Return(false);
- CJS_Field* pJSField =
- static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
- pJSField->AttachField(this, wideName);
+ auto* pJSField =
+ static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
if (!pJSField)
return CJS_Return(false);
+ pJSField->AttachField(this, wideName);
return CJS_Return(pJSField->ToV8Object());
}
@@ -362,7 +362,7 @@ CJS_Return CJS_Document::print(
if (CFXJS_Engine::GetObjDefnID(pObj) ==
CJS_PrintParamsObj::GetObjDefnID()) {
v8::Local<v8::Object> pObj = pRuntime->ToObject(params[8]);
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(pObj);
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(pObj);
if (pJSObj) {
CJS_PrintParamsObj* printObj =
static_cast<CJS_PrintParamsObj*>(pJSObj);
@@ -1013,8 +1013,7 @@ CJS_Return CJS_Document::getAnnot(
CPDFSDK_AnnotIteration annotIteration(pPageView, false);
CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
for (const auto& pSDKAnnotCur : annotIteration) {
- CPDFSDK_BAAnnot* pBAAnnot =
- static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get());
+ auto* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get());
if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
pSDKBAAnnot = pBAAnnot;
break;
@@ -1028,8 +1027,8 @@ CJS_Return CJS_Document::getAnnot(
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Annot* pJS_Annot =
- static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
+ auto* pJS_Annot =
+ static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj));
if (!pJS_Annot)
return CJS_Return(false);
@@ -1063,8 +1062,8 @@ CJS_Return CJS_Document::getAnnots(
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Annot* pJS_Annot =
- static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
+ auto* pJS_Annot =
+ static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj));
pJS_Annot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()));
pRuntime->PutArrayElement(
annots, i,
@@ -1119,7 +1118,7 @@ CJS_Return CJS_Document::addIcon(
return CJS_Return(JSGetStringFromID(JSMessage::kTypeError));
v8::Local<v8::Object> pObj = pRuntime->ToObject(params[1]);
- CJS_Object* obj = pRuntime->GetObjectPrivate(pObj);
+ CJS_Object* obj = CFXJS_Engine::GetObjectPrivate(pObj);
if (!obj)
return CJS_Return(JSGetStringFromID(JSMessage::kTypeError));
@@ -1140,8 +1139,8 @@ CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) {
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Icon* pJS_Icon =
- static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
+ auto* pJS_Icon =
+ static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
pJS_Icon->SetIconName(name);
pRuntime->PutArrayElement(Icons, i++,
pJS_Icon
@@ -1172,12 +1171,12 @@ CJS_Return CJS_Document::getIcon(
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
- if (!pJS_Icon)
+ auto* pJSIcon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
+ if (!pJSIcon)
return CJS_Return(false);
- pJS_Icon->SetIconName(*it);
- return CJS_Return(pJS_Icon->ToV8Object());
+ pJSIcon->SetIconName(*it);
+ return CJS_Return(pJSIcon->ToV8Object());
}
CJS_Return CJS_Document::removeIcon(
diff --git a/fxjs/cjs_eventhandler.cpp b/fxjs/cjs_eventhandler.cpp
index 2f42d4157f..0fd330fd13 100644
--- a/fxjs/cjs_eventhandler.cpp
+++ b/fxjs/cjs_eventhandler.cpp
@@ -580,10 +580,11 @@ CJS_Field* CJS_EventHandler::Source() {
if (pFieldObj.IsEmpty())
return nullptr;
- CJS_Document* pJSDocument =
- static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
- CJS_Field* pJSField =
- static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
+ auto* pJSDocument =
+ static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pDocObj));
+
+ auto* pJSField =
+ static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
pJSDocument->SetFormFillEnv(m_pTargetFormFillEnv
? m_pTargetFormFillEnv.Get()
@@ -605,10 +606,11 @@ CJS_Field* CJS_EventHandler::Target_Field() {
if (pFieldObj.IsEmpty())
return nullptr;
- CJS_Document* pJSDocument =
- static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pDocObj));
- CJS_Field* pJSField =
- static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
+ auto* pJSDocument =
+ static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pDocObj));
+
+ auto* pJSField =
+ static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
pJSDocument->SetFormFillEnv(m_pTargetFormFillEnv
? m_pTargetFormFillEnv.Get()
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 0a322477ec..cdbe0dfc4d 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -2279,10 +2279,8 @@ CJS_Return CJS_Field::buttonGetIcon(
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
- if (!pJS_Icon)
- return CJS_Return(false);
- return CJS_Return(pJS_Icon->ToV8Object());
+ auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
+ return pJS_Icon ? CJS_Return(pJS_Icon->ToV8Object()) : CJS_Return(false);
}
CJS_Return CJS_Field::buttonImportIcon(
@@ -2399,8 +2397,8 @@ CJS_Return CJS_Field::getArray(
if (pObj.IsEmpty())
return CJS_Return(false);
- CJS_Field* pJSField =
- static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
+ auto* pJSField =
+ static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj));
pJSField->AttachField(m_pJSDoc, *pStr);
pRuntime->PutArrayElement(FormFieldArray, j++,
pJSField
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 9a1f541212..5834ab9600 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -32,18 +32,17 @@ template <class Alt>
void JSSpecialPropQuery(const char*,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Integer>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
- Alt* pObj = static_cast<Alt*>(pJSObj);
- CJS_Return result =
- pObj->QueryProperty(PropFromV8Prop(info.GetIsolate(), property).c_str());
+ CJS_Return result = static_cast<Alt*>(pJSObj)->QueryProperty(
+ PropFromV8Prop(info.GetIsolate(), property).c_str());
+
info.GetReturnValue().Set(!result.HasError() ? 4 : 0);
}
@@ -51,24 +50,22 @@ template <class Alt>
void JSSpecialPropGet(const char* class_name,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
- Alt* pObj = static_cast<Alt*>(pJSObj);
- CJS_Return result = pObj->GetProperty(
+ CJS_Return result = static_cast<Alt*>(pJSObj)->GetProperty(
pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str());
+
if (result.HasError()) {
pRuntime->Error(
JSFormatErrorString(class_name, "GetProperty", result.Error()));
return;
}
-
if (result.HasReturn())
info.GetReturnValue().Set(result.Return());
}
@@ -78,18 +75,17 @@ void JSSpecialPropPut(const char* class_name,
v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
- Alt* pObj = static_cast<Alt*>(pJSObj);
- CJS_Return result = pObj->SetProperty(
+ CJS_Return result = static_cast<Alt*>(pJSObj)->SetProperty(
pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str(), value);
+
if (result.HasError()) {
pRuntime->Error(
JSFormatErrorString(class_name, "PutProperty", result.Error()));
@@ -100,17 +96,15 @@ template <class Alt>
void JSSpecialPropDel(const char* class_name,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Boolean>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
- Alt* pObj = static_cast<Alt*>(pJSObj);
- CJS_Return result = pObj->DelProperty(
+ CJS_Return result = static_cast<Alt*>(pJSObj)->DelProperty(
pRuntime, PropFromV8Prop(info.GetIsolate(), property).c_str());
if (result.HasError()) {
// TODO(dsinclair): Should this set the pRuntime->Error result?
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index a8640eaa34..2896c5f701 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -168,14 +168,12 @@ void CJS_Runtime::SetFormFillEnvToDocument() {
v8::Context::Scope context_scope(context);
v8::Local<v8::Object> pThis = GetThisObj();
- if (pThis.IsEmpty())
+ if (pThis.IsEmpty() ||
+ CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::GetObjDefnID()) {
return;
-
- if (CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::GetObjDefnID())
- return;
-
- CJS_Document* pJSDocument =
- static_cast<CJS_Document*>(GetObjectPrivate(pThis));
+ }
+ auto* pJSDocument =
+ static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pThis));
if (!pJSDocument)
return;
diff --git a/fxjs/js_define.h b/fxjs/js_define.h
index 325642d8ce..93dfd49099 100644
--- a/fxjs/js_define.h
+++ b/fxjs/js_define.h
@@ -63,13 +63,12 @@ void JSPropGetter(const char* prop_name_string,
const char* class_name_string,
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
C* pObj = static_cast<C*>(pJSObj);
@@ -90,13 +89,12 @@ void JSPropSetter(const char* prop_name_string,
v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
C* pObj = static_cast<C*>(pJSObj);
@@ -113,13 +111,12 @@ template <class C,
void JSMethod(const char* method_name_string,
const char* class_name_string,
const v8::FunctionCallbackInfo<v8::Value>& info) {
- CJS_Runtime* pRuntime =
- CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate());
- if (!pRuntime)
+ CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+ if (!pJSObj)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ CJS_Runtime* pRuntime = pJSObj->GetRuntime();
+ if (!pRuntime)
return;
std::vector<v8::Local<v8::Value>> parameters;