diff options
-rw-r--r-- | fxjs/cjs_global.cpp | 11 | ||||
-rw-r--r-- | fxjs/cjs_publicmethods.cpp | 7 | ||||
-rw-r--r-- | fxjs/cjs_runtime.cpp | 7 | ||||
-rw-r--r-- | fxjs/cjs_runtime.h | 2 | ||||
-rw-r--r-- | fxjs/js_define.cpp | 6 |
5 files changed, 15 insertions, 18 deletions
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index 5834ab9600..1e01f96aee 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -311,9 +311,9 @@ CJS_Return CJS_Global::setPersistent( } void CJS_Global::UpdateGlobalPersistentVariables() { - CJS_Runtime* pRuntime = - static_cast<CJS_Runtime*>(CFXJS_Engine::EngineFromIsolateCurrentContext( - ToV8Object()->GetIsolate())); + CJS_Runtime* pRuntime = GetRuntime(); + if (!pRuntime) + return; for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); @@ -450,8 +450,9 @@ void CJS_Global::ObjectToArray(CJS_Runtime* pRuntime, void CJS_Global::PutObjectProperty(v8::Local<v8::Object> pObj, CJS_KeyValue* pData) { - CJS_Runtime* pRuntime = - CJS_Runtime::RuntimeFromIsolateCurrentContext(ToV8Object()->GetIsolate()); + CJS_Runtime* pRuntime = GetRuntime(); + if (pRuntime) + return; for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { CJS_KeyValue* pObjData = pData->objData.GetAt(i); diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index d37706c973..678aca5317 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -120,8 +120,11 @@ template <CJS_Return (*F)(CJS_Runtime*, const std::vector<v8::Local<v8::Value>>&)> void JSGlobalFunc(const char* func_name_string, const v8::FunctionCallbackInfo<v8::Value>& info) { - CJS_Runtime* pRuntime = - CJS_Runtime::RuntimeFromIsolateCurrentContext(info.GetIsolate()); + CJS_Object* pObj = CFXJS_Engine::GetObjectPrivate(info.Holder()); + if (!pObj) + return; + + CJS_Runtime* pRuntime = pObj->GetRuntime(); if (!pRuntime) return; diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp index 2896c5f701..d7ee93ff2c 100644 --- a/fxjs/cjs_runtime.cpp +++ b/fxjs/cjs_runtime.cpp @@ -46,13 +46,6 @@ #include "fxjs/cfxjse_value.h" #endif // PDF_ENABLE_XFA -// static -CJS_Runtime* CJS_Runtime::RuntimeFromIsolateCurrentContext( - v8::Isolate* pIsolate) { - return static_cast<CJS_Runtime*>( - CFXJS_Engine::EngineFromIsolateCurrentContext(pIsolate)); -} - CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), m_bBlocking(false), diff --git a/fxjs/cjs_runtime.h b/fxjs/cjs_runtime.h index 0c32562304..73b722db43 100644 --- a/fxjs/cjs_runtime.h +++ b/fxjs/cjs_runtime.h @@ -27,8 +27,6 @@ class CJS_Runtime : public IJS_Runtime, public: using FieldEvent = std::pair<WideString, JS_EVENT_T>; - static CJS_Runtime* RuntimeFromIsolateCurrentContext(v8::Isolate* pIsolate); - explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv); ~CJS_Runtime() override; diff --git a/fxjs/js_define.cpp b/fxjs/js_define.cpp index 3e14a3dd1d..124fd91651 100644 --- a/fxjs/js_define.cpp +++ b/fxjs/js_define.cpp @@ -236,8 +236,10 @@ 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::RuntimeFromIsolateCurrentContext(pIsolate)->NewString( - str.AsStringView()); + v8::String::NewFromUtf8(pIsolate, + FX_UTF8Encode(str.AsStringView()).c_str(), + v8::NewStringType::kNormal) + .ToLocalChecked(); v8::Local<v8::Value> argv[argc] = {timeStr}; v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); if (v->IsNumber()) { |