From 6ffd840c1f4d7d74a6c4c07c5791c4f3db8d50b9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 6 Jun 2018 20:51:04 +0000 Subject: Remove still more v8::Context slot usage. Removes CJS_Runtime::RuntimeFromIsolateCurrentContext() Change-Id: I51abcf32aaafac522e1595edf663507c26781357 Reviewed-on: https://pdfium-review.googlesource.com/34230 Commit-Queue: Tom Sepez Commit-Queue: dsinclair Reviewed-by: dsinclair --- fxjs/cjs_global.cpp | 11 ++++++----- fxjs/cjs_publicmethods.cpp | 7 +++++-- fxjs/cjs_runtime.cpp | 7 ------- fxjs/cjs_runtime.h | 2 -- 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(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 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 >&)> void JSGlobalFunc(const char* func_name_string, const v8::FunctionCallbackInfo& 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( - 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; - 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 funC = v8::Local::Cast(v); const int argc = 1; v8::Local timeStr = - CJS_Runtime::RuntimeFromIsolateCurrentContext(pIsolate)->NewString( - str.AsStringView()); + v8::String::NewFromUtf8(pIsolate, + FX_UTF8Encode(str.AsStringView()).c_str(), + v8::NewStringType::kNormal) + .ToLocalChecked(); v8::Local argv[argc] = {timeStr}; v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); if (v->IsNumber()) { -- cgit v1.2.3