From b4694249b336d1c0bea9222880b49dcf9284791d Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 15 Aug 2016 16:44:55 -0700 Subject: Push v8::Isolate into CFXJS_Engine class Nearly all the "loose" functions in FXJS become methods on the CFJXS_Engine. This is the "missing link" wrt some layering violatons that have been around forever. We can stop passing &m_ variables from CJS_ down into FXJS Initialization as a result. Review-Url: https://codereview.chromium.org/2245863002 --- fpdfsdk/javascript/Consts.cpp | 40 +++--- fpdfsdk/javascript/Document.cpp | 235 ++++++++++++++----------------- fpdfsdk/javascript/Document.h | 6 +- fpdfsdk/javascript/Field.cpp | 101 ++++++-------- fpdfsdk/javascript/Field.h | 3 - fpdfsdk/javascript/JS_Define.h | 246 ++++++++++++++++----------------- fpdfsdk/javascript/JS_EventHandler.cpp | 24 ++-- fpdfsdk/javascript/JS_Object.cpp | 2 +- fpdfsdk/javascript/JS_Runtime_Stub.cpp | 3 +- fpdfsdk/javascript/JS_Value.cpp | 234 +++++++++++++++---------------- fpdfsdk/javascript/JS_Value.h | 70 +++++----- fpdfsdk/javascript/PublicMethods.cpp | 116 ++++++++-------- fpdfsdk/javascript/app.cpp | 100 +++++++------- fpdfsdk/javascript/app.h | 2 +- fpdfsdk/javascript/cjs_context.cpp | 4 +- fpdfsdk/javascript/cjs_runtime.cpp | 154 +++++++++++---------- fpdfsdk/javascript/cjs_runtime.h | 10 +- fpdfsdk/javascript/color.cpp | 90 ++++++------ fpdfsdk/javascript/global.cpp | 76 +++++----- fpdfsdk/javascript/ijs_runtime.h | 3 +- fpdfsdk/javascript/util.cpp | 82 +++++------ 21 files changed, 756 insertions(+), 845 deletions(-) (limited to 'fpdfsdk/javascript') diff --git a/fpdfsdk/javascript/Consts.cpp b/fpdfsdk/javascript/Consts.cpp index 19988a61ea..c224ad0de8 100644 --- a/fpdfsdk/javascript/Consts.cpp +++ b/fpdfsdk/javascript/Consts.cpp @@ -99,11 +99,12 @@ JS_STATIC_CONST_ENTRY_STRING(L"refW", L"ReflowWidth") END_JS_STATIC_CONST() IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype) -#define GLOBAL_STRING(rt, name, value) \ - FXJS_DefineGlobalConst( \ - (rt)->GetIsolate(), (name), \ - [](const v8::FunctionCallbackInfo& info) { \ - info.GetReturnValue().Set(FXJS_NewString(info.GetIsolate(), (value))); \ +#define GLOBAL_STRING(rt, name, value) \ + (rt)->DefineGlobalConst( \ + (name), [](const v8::FunctionCallbackInfo& info) { \ + info.GetReturnValue().Set( \ + CFXJS_Engine::CurrentEngineFromIsolate(info.GetIsolate()) \ + ->NewString(value)); \ }) void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) { @@ -137,21 +138,20 @@ void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) { GLOBAL_STRING(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **"); } -#define GLOBAL_ARRAY(rt, name, ...) \ - { \ - const FX_WCHAR* values[] = {__VA_ARGS__}; \ - v8::Local array = FXJS_NewArray((rt)->GetIsolate()); \ - for (size_t i = 0; i < FX_ArraySize(values); ++i) \ - array->Set(i, FXJS_NewString((rt)->GetIsolate(), values[i])); \ - rt->SetConstArray(name, array); \ - FXJS_DefineGlobalConst( \ - (rt)->GetIsolate(), (name), \ - [](const v8::FunctionCallbackInfo& info) { \ - CJS_Runtime* pLocalRuntime = static_cast( \ - FXJS_GetCurrentEngineFromIsolate(info.GetIsolate())); \ - if (pLocalRuntime) \ - info.GetReturnValue().Set(pLocalRuntime->GetConstArray(name)); \ - }); \ +#define GLOBAL_ARRAY(rt, name, ...) \ + { \ + const FX_WCHAR* values[] = {__VA_ARGS__}; \ + v8::Local array = (rt)->NewArray(); \ + for (size_t i = 0; i < FX_ArraySize(values); ++i) \ + array->Set(i, (rt)->NewString(values[i])); \ + (rt)->SetConstArray((name), array); \ + (rt)->DefineGlobalConst( \ + (name), [](const v8::FunctionCallbackInfo& info) { \ + CJS_Runtime* pCurrentRuntime = \ + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); \ + if (pCurrentRuntime) \ + info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \ + }); \ } void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) { diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index a55bf81139..7ddd571f90 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -28,12 +28,6 @@ #include "fpdfsdk/javascript/resource.h" #include "third_party/base/numerics/safe_math.h" -static v8::Isolate* GetIsolate(IJS_Context* cc) { - CJS_Context* pContext = (CJS_Context*)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - return pRuntime->GetIsolate(); -} - BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) END_JS_STATIC_CONST() @@ -148,12 +142,10 @@ void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { CJS_Runtime* pRuntime = static_cast(pIRuntime); Document* pDoc = static_cast(GetEmbedObject()); pDoc->AttachDoc(pRuntime->GetReaderDocument()); - pDoc->SetIsolate(pRuntime->GetIsolate()); } Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), - m_isolate(nullptr), m_pDocument(nullptr), m_cwBaseURL(L""), m_bDelay(FALSE) {} @@ -289,9 +281,7 @@ FX_BOOL Document::getField(IJS_Context* cc, } CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - - CFX_WideString wideName = params[0].ToCFXWideString(pIsolate); + CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { @@ -300,10 +290,9 @@ FX_BOOL Document::getField(IJS_Context* cc, } v8::Local pFieldObj = - FXJS_NewFxDynamicObj(pIsolate, pRuntime, CJS_Field::g_nObjDefnID); - + pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); CJS_Field* pJSField = - static_cast(FXJS_GetPrivate(pIsolate, pFieldObj)); + static_cast(pRuntime->GetObjectPrivate(pFieldObj)); Field* pField = static_cast(pJSField->GetEmbedObject()); pField->AttachField(this, wideName); @@ -317,16 +306,13 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, CJS_Value& vRet, CFX_WideString& sError) { CJS_Context* pContext = static_cast(cc); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); if (params.size() != 1) { sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); return FALSE; } - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - - int nIndex = params[0].ToInt(pIsolate); + int nIndex = params[0].ToInt(pRuntime); if (nIndex < 0) { sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); return FALSE; @@ -378,21 +364,19 @@ FX_BOOL Document::mailForm(IJS_Context* cc, CJS_Value& vRet, CFX_WideString& sError) { CJS_Context* pContext = static_cast(cc); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; int iLength = params.size(); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - - FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pIsolate) : TRUE; - CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pIsolate) : L""; - CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pIsolate) : L""; - CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pIsolate) : L""; + FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; + CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; + CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; + CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; CFX_WideString cSubject = - iLength > 4 ? params[4].ToCFXWideString(pIsolate) : L""; - CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pIsolate) : L""; + iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; + CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); CFX_ByteTextBuf textBuf; @@ -414,7 +398,6 @@ FX_BOOL Document::print(IJS_Context* cc, CFX_WideString& sError) { CJS_Context* pContext = static_cast(cc); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); FX_BOOL bUI = TRUE; int nStart = 0; @@ -428,9 +411,10 @@ FX_BOOL Document::print(IJS_Context* cc, int nlength = params.size(); if (nlength == 9) { if (params[8].GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[8].ToV8Object(pIsolate); - if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { - if (CJS_Object* pJSObj = params[8].ToCJSObject(pIsolate)) { + v8::Local pObj = params[8].ToV8Object(pRuntime); + if (CFXJS_Engine::GetObjDefnID(pObj) == + CJS_PrintParamsObj::g_nObjDefnID) { + if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { if (PrintParamsObj* pprintparamsObj = static_cast(pJSObj->GetEmbedObject())) { bUI = pprintparamsObj->bUI; @@ -447,21 +431,21 @@ FX_BOOL Document::print(IJS_Context* cc, } } else { if (nlength >= 1) - bUI = params[0].ToBool(pIsolate); + bUI = params[0].ToBool(pRuntime); if (nlength >= 2) - nStart = params[1].ToInt(pIsolate); + nStart = params[1].ToInt(pRuntime); if (nlength >= 3) - nEnd = params[2].ToInt(pIsolate); + nEnd = params[2].ToInt(pRuntime); if (nlength >= 4) - bSilent = params[3].ToBool(pIsolate); + bSilent = params[3].ToBool(pRuntime); if (nlength >= 5) - bShrinkToFit = params[4].ToBool(pIsolate); + bShrinkToFit = params[4].ToBool(pRuntime); if (nlength >= 6) - bPrintAsImage = params[5].ToBool(pIsolate); + bPrintAsImage = params[5].ToBool(pRuntime); if (nlength >= 7) - bReverse = params[6].ToBool(pIsolate); + bReverse = params[6].ToBool(pRuntime); if (nlength >= 8) - bAnnotations = params[7].ToBool(pIsolate); + bAnnotations = params[7].ToBool(pRuntime); } if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { @@ -492,9 +476,8 @@ FX_BOOL Document::removeField(IJS_Context* cc, } CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - CFX_WideString sFieldName = params[0].ToCFXWideString(pIsolate); + CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); std::vector widgets; pInterForm->GetWidgets(sFieldName, &widgets); @@ -547,22 +530,21 @@ FX_BOOL Document::resetForm(IJS_Context* cc, } CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); switch (params[0].GetType()) { default: - aName.Attach(params[0].ToV8Array(pIsolate)); + aName.Attach(params[0].ToV8Array(pRuntime)); break; case CJS_Value::VT_string: - aName.SetElement(pRuntime->GetIsolate(), 0, params[0]); + aName.SetElement(pRuntime, 0, params[0]); break; } std::vector aFields; - for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { + for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { CJS_Value valElement(pRuntime); - aName.GetElement(pRuntime->GetIsolate(), i, valElement); - CFX_WideString swVal = valElement.ToCFXWideString(pIsolate); + aName.GetElement(pRuntime, i, valElement); + CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) aFields.push_back(pPDFForm->GetField(j, swVal)); } @@ -601,37 +583,35 @@ FX_BOOL Document::submitForm(IJS_Context* cc, FX_BOOL bEmpty = FALSE; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); CJS_Value v = params[0]; if (v.GetType() == CJS_Value::VT_string) { - strURL = params[0].ToCFXWideString(pIsolate); + strURL = params[0].ToCFXWideString(pRuntime); if (nSize > 1) - bFDF = params[1].ToBool(pIsolate); + bFDF = params[1].ToBool(pRuntime); if (nSize > 2) - bEmpty = params[2].ToBool(pIsolate); + bEmpty = params[2].ToBool(pRuntime); if (nSize > 3) - aFields.Attach(params[3].ToV8Array(pIsolate)); + aFields.Attach(params[3].ToV8Array(pRuntime)); } else if (v.GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[0].ToV8Object(pIsolate); - v8::Local pValue = - FXJS_GetObjectProperty(pIsolate, pObj, L"cURL"); + v8::Local pObj = params[0].ToV8Object(pRuntime); + v8::Local pValue = pRuntime->GetObjectProperty(pObj, L"cURL"); if (!pValue.IsEmpty()) - strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bFDF"); - bFDF = CJS_Value(pRuntime, pValue).ToBool(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); + bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"bEmpty"); - bEmpty = CJS_Value(pRuntime, pValue).ToBool(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); + bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"aFields"); - aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pIsolate)); + pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); + aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); } CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - if (aFields.GetLength() == 0 && bEmpty) { + if (aFields.GetLength(pRuntime) == 0 && bEmpty) { if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { pRuntime->BeginBlock(); pInterForm->SubmitForm(strURL, FALSE); @@ -641,11 +621,11 @@ FX_BOOL Document::submitForm(IJS_Context* cc, } std::vector fieldObjects; - for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { + for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { CJS_Value valName(pRuntime); - aFields.GetElement(pRuntime->GetIsolate(), i, valName); + aFields.GetElement(pRuntime, i, valName); - CFX_WideString sName = valName.ToCFXWideString(pIsolate); + CFX_WideString sName = valName.ToCFXWideString(pRuntime); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { CPDF_FormField* pField = pPDFForm->GetField(j, sName); @@ -694,42 +674,40 @@ FX_BOOL Document::mailDoc(IJS_Context* cc, CFX_WideString cMsg = L""; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); if (params.size() >= 1) - bUI = params[0].ToBool(pIsolate); + bUI = params[0].ToBool(pRuntime); if (params.size() >= 2) - cTo = params[1].ToCFXWideString(pIsolate); + cTo = params[1].ToCFXWideString(pRuntime); if (params.size() >= 3) - cCc = params[2].ToCFXWideString(pIsolate); + cCc = params[2].ToCFXWideString(pRuntime); if (params.size() >= 4) - cBcc = params[3].ToCFXWideString(pIsolate); + cBcc = params[3].ToCFXWideString(pRuntime); if (params.size() >= 5) - cSubject = params[4].ToCFXWideString(pIsolate); + cSubject = params[4].ToCFXWideString(pRuntime); if (params.size() >= 6) - cMsg = params[5].ToCFXWideString(pIsolate); + cMsg = params[5].ToCFXWideString(pRuntime); if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[0].ToV8Object(pIsolate); + v8::Local pObj = params[0].ToV8Object(pRuntime); - v8::Local pValue = - FXJS_GetObjectProperty(pIsolate, pObj, L"bUI"); - bUI = CJS_Value(pRuntime, pValue).ToInt(pIsolate); + v8::Local pValue = pRuntime->GetObjectProperty(pObj, L"bUI"); + bUI = CJS_Value(pRuntime, pValue).ToInt(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cTo"); - cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"cTo"); + cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cCc"); - cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"cCc"); + cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cBcc"); - cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"cBcc"); + cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cSubject"); - cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); + cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); - pValue = FXJS_GetObjectProperty(pIsolate, pObj, L"cMsg"); - cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pIsolate); + pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); + cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); } pRuntime->BeginBlock(); @@ -772,19 +750,17 @@ FX_BOOL Document::info(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Local pObj = - FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); - - v8::Isolate* isolate = GetIsolate(cc); - FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor); - FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle); - FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject); - FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords); - FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator); - FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer); - FXJS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate); - FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate); - FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped); + + v8::Local pObj = pRuntime->NewFxDynamicObj(-1); + pRuntime->PutObjectString(pObj, L"Author", cwAuthor); + pRuntime->PutObjectString(pObj, L"Title", cwTitle); + pRuntime->PutObjectString(pObj, L"Subject", cwSubject); + pRuntime->PutObjectString(pObj, L"Keywords", cwKeywords); + pRuntime->PutObjectString(pObj, L"Creator", cwCreator); + pRuntime->PutObjectString(pObj, L"Producer", cwProducer); + pRuntime->PutObjectString(pObj, L"CreationDate", cwCreationDate); + pRuntime->PutObjectString(pObj, L"ModDate", cwModDate); + pRuntime->PutObjectString(pObj, L"Trapped", cwTrapped); // It's to be compatible to non-standard info dictionary. for (const auto& it : *pDictionary) { @@ -792,11 +768,11 @@ FX_BOOL Document::info(IJS_Context* cc, CPDF_Object* pValueObj = it.second; CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); if (pValueObj->IsString() || pValueObj->IsName()) { - FXJS_PutObjectString(isolate, pObj, wsKey, pValueObj->GetUnicodeText()); + pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText()); } else if (pValueObj->IsNumber()) { - FXJS_PutObjectNumber(isolate, pObj, wsKey, (float)pValueObj->GetNumber()); + pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber()); } else if (pValueObj->IsBoolean()) { - FXJS_PutObjectBoolean(isolate, pObj, wsKey, !!pValueObj->GetInteger()); + pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger()); } } vp << pObj; @@ -1108,22 +1084,21 @@ FX_BOOL Document::addIcon(IJS_Context* cc, } CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate); + CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); if (params[1].GetType() != CJS_Value::VT_object) { sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); return FALSE; } - v8::Local pJSIcon = params[1].ToV8Object(pIsolate); - if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { + v8::Local pJSIcon = params[1].ToV8Object(pRuntime); + if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); return FALSE; } - CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pIsolate)->GetEmbedObject(); + CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); if (!pEmbedObj) { sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); return FALSE; @@ -1153,12 +1128,13 @@ FX_BOOL Document::icons(IJS_Context* cc, int i = 0; for (const auto& pIconElement : m_IconList) { - v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); if (pObj.IsEmpty()) return FALSE; - CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); + CJS_Icon* pJS_Icon = + static_cast(pRuntime->GetObjectPrivate(pObj)); if (!pJS_Icon) return FALSE; @@ -1168,8 +1144,7 @@ FX_BOOL Document::icons(IJS_Context* cc, pIcon->SetStream(pIconElement->IconStream->GetStream()); pIcon->SetIconName(pIconElement->IconName); - Icons.SetElement(pRuntime->GetIsolate(), i++, - CJS_Value(pRuntime, pJS_Icon)); + Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); } vp << Icons; @@ -1190,20 +1165,20 @@ FX_BOOL Document::getIcon(IJS_Context* cc, return FALSE; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - CFX_WideString swIconName = params[0].ToCFXWideString(pIsolate); + CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); for (const auto& pIconElement : m_IconList) { if (pIconElement->IconName == swIconName) { Icon* pRetIcon = pIconElement->IconStream; - v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); if (pObj.IsEmpty()) return FALSE; - CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); + CJS_Icon* pJS_Icon = + static_cast(pRuntime->GetObjectPrivate(pObj)); if (!pJS_Icon) return FALSE; @@ -1275,11 +1250,10 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, return FALSE; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0; - int nWordNo = params.size() > 1 ? params[1].ToInt(pIsolate) : 0; - bool bStrip = params.size() > 2 ? params[2].ToBool(pIsolate) : true; + int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; + int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; + bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); if (!pDocument) @@ -1340,9 +1314,8 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, return FALSE; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Isolate* pIsolate = pRuntime->GetIsolate(); - int nPageNo = params.size() > 0 ? params[0].ToInt(pIsolate) : 0; + int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); @@ -1372,8 +1345,8 @@ FX_BOOL Document::getPrintParams(IJS_Context* cc, CFX_WideString& sError) { CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - v8::Local pRetObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); + v8::Local pRetObj = + pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); // Not implemented yet. @@ -1526,8 +1499,8 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, return FALSE; } - CJS_Runtime* runtime = context->GetJSRuntime(); - CFX_WideString wideName = params[0].ToCFXWideString(runtime->GetIsolate()); + CJS_Runtime* pRuntime = context->GetJSRuntime(); + CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CFX_ByteString utf8Name = wideName.UTF8Encode(); CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); @@ -1553,11 +1526,11 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc, scrollPositionArraySize = j; } - runtime->BeginBlock(); + pRuntime->BeginBlock(); CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), scrollPositionArray.get(), scrollPositionArraySize); - runtime->EndBlock(); + pRuntime->EndBlock(); return TRUE; } diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 873f70e327..1c20ac4221 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -269,7 +269,6 @@ class Document : public CJS_EmbedObj { CPDFSDK_Document* GetReaderDoc(); void AddDelayData(CJS_DelayData* pData); void DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex); - void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } CJS_Document* GetCJSDoc() const; private: @@ -282,12 +281,11 @@ class Document : public CJS_EmbedObj { const CFX_ByteString& propName, CFX_WideString& sError); - v8::Isolate* m_isolate; - std::list> m_IconList; CPDFSDK_Document* m_pDocument; CFX_WideString m_cwBaseURL; - bool m_bDelay; std::list> m_DelayData; + std::list> m_IconList; + bool m_bDelay; }; class CJS_Document : public CJS_Object { diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 20c41c6a19..1f4a18375a 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -123,9 +123,6 @@ CJS_DelayData::CJS_DelayData(FIELD_PROP prop, CJS_DelayData::~CJS_DelayData() {} void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { - CJS_Runtime* pRuntime = static_cast(pIRuntime); - Field* pField = static_cast(GetEmbedObject()); - pField->SetIsolate(pRuntime->GetIsolate()); } Field::Field(CJS_Object* pJSObject) @@ -134,8 +131,7 @@ Field::Field(CJS_Object* pJSObject) m_pDocument(nullptr), m_nFormControlIndex(-1), m_bCanSet(FALSE), - m_bDelay(FALSE), - m_isolate(nullptr) {} + m_bDelay(FALSE) {} Field::~Field() {} @@ -967,9 +963,9 @@ FX_BOOL Field::currentValueIndices(IJS_Context* cc, CJS_Value SelValue(pRuntime); int iSelecting; vp >> SelArray; - for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { - SelArray.GetElement(pRuntime->GetIsolate(), i, SelValue); - iSelecting = SelValue.ToInt(pRuntime->GetIsolate()); + for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) { + SelArray.GetElement(pRuntime, i, SelValue); + iSelecting = SelValue.ToInt(pRuntime); array.push_back(iSelecting); } } @@ -997,8 +993,7 @@ FX_BOOL Field::currentValueIndices(IJS_Context* cc, CJS_Array SelArray; for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { SelArray.SetElement( - pRuntime->GetIsolate(), i, - CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); + pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); } vp << SelArray; } else { @@ -1389,7 +1384,7 @@ FX_BOOL Field::exportValues(IJS_Context* cc, for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { CPDF_FormControl* pFormControl = pFormField->GetControl(i); ExportValusArray.SetElement( - pRuntime->GetIsolate(), i, + pRuntime, i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); } } else { @@ -1402,7 +1397,7 @@ FX_BOOL Field::exportValues(IJS_Context* cc, return FALSE; ExportValusArray.SetElement( - pRuntime->GetIsolate(), 0, + pRuntime, 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); } vp << ExportValusArray; @@ -1904,8 +1899,7 @@ FX_BOOL Field::page(IJS_Context* cc, return FALSE; PageArray.SetElement( - pRuntime->GetIsolate(), i, - CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); + pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); } vp << PageArray; @@ -2099,20 +2093,16 @@ FX_BOOL Field::rect(IJS_Context* cc, CJS_Array rcArray; vp >> rcArray; - rcArray.GetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); - rcArray.GetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); - rcArray.GetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); - rcArray.GetElement(pRuntime->GetIsolate(), 3, Lower_Righty); + rcArray.GetElement(pRuntime, 0, Upper_Leftx); + rcArray.GetElement(pRuntime, 1, Upper_Lefty); + rcArray.GetElement(pRuntime, 2, Lower_Rightx); + rcArray.GetElement(pRuntime, 3, Lower_Righty); FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - pArray[0] = - static_cast(Upper_Leftx.ToInt(pRuntime->GetIsolate())); - pArray[1] = - static_cast(Lower_Righty.ToInt(pRuntime->GetIsolate())); - pArray[2] = - static_cast(Lower_Rightx.ToInt(pRuntime->GetIsolate())); - pArray[3] = - static_cast(Upper_Lefty.ToInt(pRuntime->GetIsolate())); + pArray[0] = static_cast(Upper_Leftx.ToInt(pRuntime)); + pArray[1] = static_cast(Lower_Righty.ToInt(pRuntime)); + pArray[2] = static_cast(Lower_Rightx.ToInt(pRuntime)); + pArray[3] = static_cast(Upper_Lefty.ToInt(pRuntime)); CFX_FloatRect crRect(pArray); if (m_bDelay) { @@ -2139,10 +2129,10 @@ FX_BOOL Field::rect(IJS_Context* cc, Lower_Righty = CJS_Value(pRuntime, static_cast(crRect.bottom)); CJS_Array rcArray; - rcArray.SetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); - rcArray.SetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); - rcArray.SetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); - rcArray.SetElement(pRuntime->GetIsolate(), 3, Lower_Righty); + rcArray.SetElement(pRuntime, 0, Upper_Leftx); + rcArray.SetElement(pRuntime, 1, Upper_Lefty); + rcArray.SetElement(pRuntime, 2, Lower_Rightx); + rcArray.SetElement(pRuntime, 3, Lower_Righty); vp << rcArray; } return TRUE; @@ -2716,12 +2706,11 @@ FX_BOOL Field::value(IJS_Context* cc, std::vector strArray; if (vp.GetJSValue()->IsArrayObject()) { CJS_Array ValueArray; - vp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), ValueArray); - for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { + vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray); + for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { CJS_Value ElementValue(pRuntime); - ValueArray.GetElement(pRuntime->GetIsolate(), i, ElementValue); - strArray.push_back( - ElementValue.ToCFXWideString(pRuntime->GetIsolate())); + ValueArray.GetElement(pRuntime, i, ElementValue); + strArray.push_back(ElementValue.ToCFXWideString(pRuntime)); } } else { CFX_WideString swValue; @@ -2756,13 +2745,12 @@ FX_BOOL Field::value(IJS_Context* cc, iIndex = pFormField->GetSelectedIndex(i); ElementValue = CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); - if (FXSYS_wcslen( - ElementValue.ToCFXWideString(pRuntime->GetIsolate()) - .c_str()) == 0) { + if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) == + 0) { ElementValue = CJS_Value( pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); } - ValueArray.SetElement(pRuntime->GetIsolate(), i, ElementValue); + ValueArray.SetElement(pRuntime, i, ElementValue); } vp << ValueArray; } else { @@ -2787,7 +2775,7 @@ FX_BOOL Field::value(IJS_Context* cc, break; } } - vp.GetJSValue()->MaybeCoerceToNumber(m_isolate); + vp.GetJSValue()->MaybeCoerceToNumber(pRuntime); return TRUE; } @@ -2918,7 +2906,7 @@ FX_BOOL Field::buttonGetCaption(IJS_Context* cc, int nface = 0; int iSize = params.size(); if (iSize >= 1) - nface = params[0].ToInt(pRuntime->GetIsolate()); + nface = params[0].ToInt(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2954,7 +2942,7 @@ FX_BOOL Field::buttonGetIcon(IJS_Context* cc, int nface = 0; int iSize = params.size(); if (iSize >= 1) - nface = params[0].ToInt(pRuntime->GetIsolate()); + nface = params[0].ToInt(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2968,11 +2956,11 @@ FX_BOOL Field::buttonGetIcon(IJS_Context* cc, if (!pFormControl) return FALSE; - v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); ASSERT(pObj.IsEmpty() == FALSE); - CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); + CJS_Icon* pJS_Icon = static_cast(pRuntime->GetObjectPrivate(pObj)); Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); CPDF_Stream* pIconStream = nullptr; @@ -3023,11 +3011,11 @@ FX_BOOL Field::checkThisBox(IJS_Context* cc, return FALSE; CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int nWidget = params[0].ToInt(pRuntime->GetIsolate()); + int nWidget = params[0].ToInt(pRuntime); bool bCheckit = true; if (iSize >= 2) - bCheckit = params[1].ToBool(pRuntime->GetIsolate()); + bCheckit = params[1].ToBool(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -3069,7 +3057,7 @@ FX_BOOL Field::defaultIsChecked(IJS_Context* cc, return FALSE; CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int nWidget = params[0].ToInt(pRuntime->GetIsolate()); + int nWidget = params[0].ToInt(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -3118,16 +3106,15 @@ FX_BOOL Field::getArray(IJS_Context* cc, int j = 0; for (const auto& pStr : swSort) { - v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); ASSERT(!pObj.IsEmpty()); CJS_Field* pJSField = - static_cast(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); + static_cast(pRuntime->GetObjectPrivate(pObj)); Field* pField = static_cast(pJSField->GetEmbedObject()); pField->AttachField(m_pJSDoc, *pStr); - FormFieldArray.SetElement(pRuntime->GetIsolate(), j++, - CJS_Value(pRuntime, pJSField)); + FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField)); } vRet = CJS_Value(pRuntime, FormFieldArray); @@ -3143,11 +3130,11 @@ FX_BOOL Field::getItemAt(IJS_Context* cc, int iSize = params.size(); int nIdx = -1; if (iSize >= 1) - nIdx = params[0].ToInt(pRuntime->GetIsolate()); + nIdx = params[0].ToInt(pRuntime); FX_BOOL bExport = TRUE; if (iSize >= 2) - bExport = params[1].ToBool(pRuntime->GetIsolate()); + bExport = params[1].ToBool(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -3196,7 +3183,7 @@ FX_BOOL Field::isBoxChecked(IJS_Context* cc, int nIndex = -1; if (params.size() >= 1) - nIndex = params[0].ToInt(pRuntime->GetIsolate()); + nIndex = params[0].ToInt(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -3222,7 +3209,7 @@ FX_BOOL Field::isDefaultChecked(IJS_Context* cc, int nIndex = -1; if (params.size() >= 1) - nIndex = params[0].ToInt(pRuntime->GetIsolate()); + nIndex = params[0].ToInt(pRuntime); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 3d1b0ff876..0ffdbd4ba4 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -435,7 +435,6 @@ class Field : public CJS_EmbedObj { FX_BOOL AttachField(Document* pDocument, const CFX_WideString& csFieldName); void SetDelay(FX_BOOL bDelay); - void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } protected: void ParseFieldName(const std::wstring& strFieldNameParsed, @@ -464,9 +463,7 @@ class Field : public CJS_EmbedObj { CFX_WideString m_FieldName; int m_nFormControlIndex; FX_BOOL m_bCanSet; - FX_BOOL m_bDelay; - v8::Isolate* m_isolate; }; class CJS_Field : public CJS_Object { diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index b9ae1408f6..770f9f5459 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -76,23 +76,22 @@ void JSPropGetter(const char* prop_name_string, const char* class_name_string, v8::Local property, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); - CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); + CJS_Object* pJSObj = + static_cast(pRuntime->GetObjectPrivate(info.Holder())); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; CJS_PropValue value(pRuntime); value.StartGetting(); - if (!(pObj->*M)(pContext, value, sError)) { - FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, - sError)); + if (!(pObj->*M)(pRuntime->GetCurrentContext(), value, sError)) { + pRuntime->Error( + JSFormatErrorString(class_name_string, prop_name_string, sError)); return; } - info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(isolate)); + info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(pRuntime)); } template property, v8::Local value, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); - CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); + CJS_Object* pJSObj = + static_cast(pRuntime->GetObjectPrivate(info.Holder())); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; CJS_PropValue propValue(pRuntime, CJS_Value(pRuntime, value)); propValue.StartSetting(); - if (!(pObj->*M)(pContext, propValue, sError)) { - FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, - sError)); + if (!(pObj->*M)(pRuntime->GetCurrentContext(), propValue, sError)) { + pRuntime->Error( + JSFormatErrorString(class_name_string, prop_name_string, sError)); } } @@ -141,26 +139,26 @@ template & info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); std::vector parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { parameters.push_back(CJS_Value(pRuntime, info[i])); } - CJS_Value valueRes(pRuntime); - CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); + CJS_Object* pJSObj = + static_cast(pRuntime->GetObjectPrivate(info.Holder())); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; - if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { - FXJS_Error(isolate, JSFormatErrorString(class_name_string, - method_name_string, sError)); + CJS_Value valueRes(pRuntime); + if (!(pObj->*M)(pRuntime->GetCurrentContext(), parameters, valueRes, + sError)) { + pRuntime->Error( + JSFormatErrorString(class_name_string, method_name_string, sError)); return; } - info.GetReturnValue().Set(valueRes.ToV8Value(isolate)); + info.GetReturnValue().Set(valueRes.ToV8Value(pRuntime)); } #define JS_STATIC_METHOD(method_name, class_name) \ @@ -183,7 +181,7 @@ void JSMethod(const char* method_name_string, #define DECLARE_JS_CLASS_BASE_PART() \ static const wchar_t* g_pClassName; \ static int g_nObjDefnID; \ - static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); + static void DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType); #define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \ @@ -194,28 +192,28 @@ void JSMethod(const char* method_name_string, DECLARE_JS_CLASS_BASE_PART() \ DECLARE_JS_CLASS_CONST_PART() -#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ - IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ - IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ - void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ - FXJSOBJTYPE eObjType) { \ - g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ - eObjType, nullptr, nullptr); \ - DefineConsts(pIsolate); \ +#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ + IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ + IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ + void js_class_name::DefineJSObjects(CFXJS_Engine* pEngine, \ + FXJSOBJTYPE eObjType) { \ + g_nObjDefnID = pEngine->DefineObj(js_class_name::g_pClassName, eObjType, \ + nullptr, nullptr); \ + DefineConsts(pEngine); \ } #define DECLARE_JS_CLASS_CONST_PART() \ static JSConstSpec JS_Class_Consts[]; \ - static void DefineConsts(v8::Isolate* pIsolate); + static void DefineConsts(CFXJS_Engine* pEngine); #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ - void js_class_name::DefineConsts(v8::Isolate* pIsolate) { \ + void js_class_name::DefineConsts(CFXJS_Engine* pEngine) { \ for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ - FXJS_DefineObjConst( \ - pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName, \ + pEngine->DefineObjConst( \ + g_nObjDefnID, JS_Class_Consts[i].pName, \ JS_Class_Consts[i].t == 0 \ - ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ - : FXJS_NewString(pIsolate, JS_Class_Consts[i].str)); \ + ? pEngine->NewNumber(JS_Class_Consts[i].number) \ + : pEngine->NewString(JS_Class_Consts[i].str)); \ } \ } @@ -231,53 +229,55 @@ void JSMethod(const char* method_name_string, DECLARE_JS_CLASS_CONST_PART() \ DECLARE_JS_CLASS_RICH_PART() -#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ - IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ - IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ - IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ - void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ - FXJSOBJTYPE eObjType) { \ - g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ - eObjType, JSConstructor, JSDestructor); \ - DefineConsts(pIsolate); \ - DefineProps(pIsolate); \ - DefineMethods(pIsolate); \ +#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ + IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ + IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ + IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ + void js_class_name::DefineJSObjects(CFXJS_Engine* pEngine, \ + FXJSOBJTYPE eObjType) { \ + g_nObjDefnID = pEngine->DefineObj(js_class_name::g_pClassName, eObjType, \ + JSConstructor, JSDestructor); \ + DefineConsts(pEngine); \ + DefineProps(pEngine); \ + DefineMethods(pEngine); \ } #define DECLARE_JS_CLASS_RICH_PART() \ static void JSConstructor(CFXJS_Engine* pEngine, v8::Local obj); \ - static void JSDestructor(v8::Local obj); \ - static void DefineProps(v8::Isolate* pIsoalte); \ - static void DefineMethods(v8::Isolate* pIsoalte); \ + static void JSDestructor(CFXJS_Engine* pEngine, v8::Local obj); \ + static void DefineProps(CFXJS_Engine* pEngine); \ + static void DefineMethods(CFXJS_Engine* pEngine); \ static JSPropertySpec JS_Class_Properties[]; \ static JSMethodSpec JS_Class_Methods[]; -#define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ - class_name) \ - void js_class_name::JSConstructor(CFXJS_Engine* pEngine, \ - v8::Local obj) { \ - CJS_Object* pObj = new js_class_name(obj); \ - pObj->SetEmbedObject(new class_alternate(pObj)); \ - FXJS_SetPrivate(nullptr, obj, (void*)pObj); \ - pObj->InitInstance(static_cast(pEngine)); \ - } \ - void js_class_name::JSDestructor(v8::Local obj) { \ - js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \ - pObj->ExitInstance(); \ - delete pObj; \ - } \ - void js_class_name::DefineProps(v8::Isolate* pIsolate) { \ - for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ - FXJS_DefineObjProperty( \ - pIsolate, g_nObjDefnID, JS_Class_Properties[i].pName, \ - JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ - } \ - } \ - void js_class_name::DefineMethods(v8::Isolate* pIsolate) { \ - for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ - FXJS_DefineObjMethod(pIsolate, g_nObjDefnID, JS_Class_Methods[i].pName, \ - JS_Class_Methods[i].pMethodCall); \ - } \ +#define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ + class_name) \ + void js_class_name::JSConstructor(CFXJS_Engine* pEngine, \ + v8::Local obj) { \ + CJS_Object* pObj = new js_class_name(obj); \ + pObj->SetEmbedObject(new class_alternate(pObj)); \ + pEngine->SetObjectPrivate(obj, (void*)pObj); \ + pObj->InitInstance(static_cast(pEngine)); \ + } \ + void js_class_name::JSDestructor(CFXJS_Engine* pEngine, \ + v8::Local obj) { \ + js_class_name* pObj = \ + static_cast(pEngine->GetObjectPrivate(obj)); \ + pObj->ExitInstance(); \ + delete pObj; \ + } \ + void js_class_name::DefineProps(CFXJS_Engine* pEngine) { \ + for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ + pEngine->DefineObjProperty(g_nObjDefnID, JS_Class_Properties[i].pName, \ + JS_Class_Properties[i].pPropGet, \ + JS_Class_Properties[i].pPropPut); \ + } \ + } \ + void js_class_name::DefineMethods(CFXJS_Engine* pEngine) { \ + for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ + pEngine->DefineObjMethod(g_nObjDefnID, JS_Class_Methods[i].pName, \ + JS_Class_Methods[i].pMethodCall); \ + } \ } // Special JS classes implement methods, props, and queries, but not consts. @@ -292,14 +292,14 @@ void JSMethod(const char* method_name_string, IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, class_name) \ - void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ + void js_class_name::DefineJSObjects(CFXJS_Engine* pEngine, \ FXJSOBJTYPE eObjType) { \ - g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ - eObjType, JSConstructor, JSDestructor); \ - DefineConsts(pIsolate); \ - DefineProps(pIsolate); \ - DefineMethods(pIsolate); \ - DefineAllProperties(pIsolate); \ + g_nObjDefnID = pEngine->DefineObj(js_class_name::g_pClassName, eObjType, \ + JSConstructor, JSDestructor); \ + DefineConsts(pEngine); \ + DefineProps(pEngine); \ + DefineMethods(pEngine); \ + DefineAllProperties(pEngine); \ } #define DECLARE_SPECIAL_JS_CLASS_PART() \ @@ -314,7 +314,7 @@ void JSMethod(const char* method_name_string, static void delprop_static( \ v8::Local property, \ const v8::PropertyCallbackInfo& info); \ - static void DefineAllProperties(v8::Isolate* pIsolate); + static void DefineAllProperties(CFXJS_Engine* pEngine); #define IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, \ class_name) \ @@ -338,9 +338,9 @@ void JSMethod(const char* method_name_string, const v8::PropertyCallbackInfo& info) { \ JSSpecialPropDel(#class_name, property, info); \ } \ - void js_class_name::DefineAllProperties(v8::Isolate* pIsolate) { \ - FXJS_DefineObjAllProperties( \ - pIsolate, g_nObjDefnID, js_class_name::queryprop_static, \ + void js_class_name::DefineAllProperties(CFXJS_Engine* pEngine) { \ + pEngine->DefineObjAllProperties( \ + g_nObjDefnID, js_class_name::queryprop_static, \ js_class_name::getprop_static, js_class_name::putprop_static, \ js_class_name::delprop_static); \ } @@ -349,12 +349,13 @@ template void JSSpecialPropQuery(const char*, v8::Local property, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); + CJS_Runtime* pRuntime = + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); v8::String::Utf8Value utf8_value(property); CFX_WideString propname = CFX_WideString::FromUTF8( CFX_ByteStringC(*utf8_value, utf8_value.length())); CJS_Object* pJSObj = - reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); + static_cast(pRuntime->GetObjectPrivate(info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); info.GetReturnValue().Set(bRet ? 4 : 0); @@ -364,14 +365,12 @@ template void JSSpecialPropGet(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = - reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); + static_cast(pRuntime->GetObjectPrivate(info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); v8::String::Utf8Value utf8_value(property); CFX_WideString propname = CFX_WideString::FromUTF8( @@ -379,11 +378,12 @@ void JSSpecialPropGet(const char* class_name, CFX_WideString sError; CJS_PropValue value(pRuntime); value.StartGetting(); - if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { - FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); + if (!pObj->DoProperty(pRuntime->GetCurrentContext(), propname.c_str(), value, + sError)) { + pRuntime->Error(JSFormatErrorString(class_name, "GetProperty", sError)); return; } - info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(isolate)); + info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(pRuntime)); } template @@ -391,14 +391,12 @@ void JSSpecialPropPut(const char* class_name, v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = - reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); + static_cast(pRuntime->GetObjectPrivate(info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); v8::String::Utf8Value utf8_value(property); CFX_WideString propname = CFX_WideString::FromUTF8( @@ -406,8 +404,9 @@ void JSSpecialPropPut(const char* class_name, CFX_WideString sError; CJS_PropValue PropValue(pRuntime, CJS_Value(pRuntime, value)); PropValue.StartSetting(); - if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { - FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); + if (!pObj->DoProperty(pRuntime->GetCurrentContext(), propname.c_str(), + PropValue, sError)) { + pRuntime->Error(JSFormatErrorString(class_name, "PutProperty", sError)); } } @@ -415,20 +414,19 @@ template void JSSpecialPropDel(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); CJS_Runtime* pRuntime = - static_cast(FXJS_GetCurrentEngineFromIsolate(isolate)); + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = - reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); + static_cast(pRuntime->GetObjectPrivate(info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); v8::String::Utf8Value utf8_value(property); CFX_WideString propname = CFX_WideString::FromUTF8( CFX_ByteStringC(*utf8_value, utf8_value.length())); CFX_WideString sError; - if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { + if (!pObj->DelProperty(pRuntime->GetCurrentContext(), propname.c_str(), + sError)) { CFX_ByteString cbName; cbName.Format("%s.%s", class_name, "DelProperty"); // Probably a missing call to JSFX_Error(). @@ -441,23 +439,21 @@ template void JSGlobalFunc(const char* func_name_string, const v8::FunctionCallbackInfo& info) { - CJS_Runtime* pRuntime = static_cast( - FXJS_GetCurrentEngineFromIsolate(info.GetIsolate())); + CJS_Runtime* pRuntime = + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); if (!pRuntime) return; - IJS_Context* pContext = pRuntime->GetCurrentContext(); std::vector parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { parameters.push_back(CJS_Value(pRuntime, info[i])); } CJS_Value valueRes(pRuntime); CFX_WideString sError; - if (!(*F)(pContext, parameters, valueRes, sError)) { - FXJS_Error(pRuntime->GetIsolate(), - JSFormatErrorString(func_name_string, nullptr, sError)); + if (!(*F)(pRuntime->GetCurrentContext(), parameters, valueRes, sError)) { + pRuntime->Error(JSFormatErrorString(func_name_string, nullptr, sError)); return; } - info.GetReturnValue().Set(valueRes.ToV8Value(pRuntime->GetIsolate())); + info.GetReturnValue().Set(valueRes.ToV8Value(pRuntime)); } #define JS_STATIC_GLOBAL_FUN(fun_name) \ @@ -468,7 +464,7 @@ void JSGlobalFunc(const char* func_name_string, #define JS_STATIC_DECLARE_GLOBAL_FUN() \ static JSMethodSpec global_methods[]; \ - static void DefineJSObjects(v8::Isolate* pIsolate) + static void DefineJSObjects(CFXJS_Engine* pEngine) #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ JSMethodSpec js_class_name::global_methods[] = { @@ -477,13 +473,13 @@ void JSGlobalFunc(const char* func_name_string, #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() -#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ - void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ - for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ - FXJS_DefineGlobalMethod(pIsolate, \ - js_class_name::global_methods[i].pName, \ - js_class_name::global_methods[i].pMethodCall); \ - } \ +#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ + void js_class_name::DefineJSObjects(CFXJS_Engine* pEngine) { \ + for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ + pEngine->DefineGlobalMethod( \ + js_class_name::global_methods[i].pName, \ + js_class_name::global_methods[i].pMethodCall); \ + } \ } #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ diff --git a/fpdfsdk/javascript/JS_EventHandler.cpp b/fpdfsdk/javascript/JS_EventHandler.cpp index 8dc1b8270c..fe9a909dc9 100644 --- a/fpdfsdk/javascript/JS_EventHandler.cpp +++ b/fpdfsdk/javascript/JS_EventHandler.cpp @@ -595,22 +595,22 @@ FX_BOOL CJS_EventHandler::Shift() { Field* CJS_EventHandler::Source() { CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); - v8::Local pDocObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); + v8::Local pDocObj = + pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID); ASSERT(!pDocObj.IsEmpty()); - v8::Local pFieldObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); + v8::Local pFieldObj = + pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); ASSERT(!pFieldObj.IsEmpty()); CJS_Document* pJSDocument = - (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj); + static_cast(pRuntime->GetObjectPrivate(pDocObj)); Document* pDocument = (Document*)pJSDocument->GetEmbedObject(); pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc : m_pJSContext->GetReaderDocument()); CJS_Field* pJSField = - (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj); + static_cast(pRuntime->GetObjectPrivate(pFieldObj)); Field* pField = (Field*)pJSField->GetEmbedObject(); pField->AttachField(pDocument, m_strSourceName); return pField; @@ -618,22 +618,22 @@ Field* CJS_EventHandler::Source() { Field* CJS_EventHandler::Target_Field() { CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); - v8::Local pDocObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); + v8::Local pDocObj = + pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID); ASSERT(!pDocObj.IsEmpty()); - v8::Local pFieldObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); + v8::Local pFieldObj = + pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); ASSERT(!pFieldObj.IsEmpty()); CJS_Document* pJSDocument = - (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj); + static_cast(pRuntime->GetObjectPrivate(pDocObj)); Document* pDocument = (Document*)pJSDocument->GetEmbedObject(); pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc : m_pJSContext->GetReaderDocument()); CJS_Field* pJSField = - (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj); + static_cast(pRuntime->GetObjectPrivate(pFieldObj)); Field* pField = (Field*)pJSField->GetEmbedObject(); pField->AttachField(pDocument, m_strTargetName); return pField; diff --git a/fpdfsdk/javascript/JS_Object.cpp b/fpdfsdk/javascript/JS_Object.cpp index d67ceeb0c6..3de0eceba3 100644 --- a/fpdfsdk/javascript/JS_Object.cpp +++ b/fpdfsdk/javascript/JS_Object.cpp @@ -19,7 +19,7 @@ void FreeObject(const v8::WeakCallbackInfo& data) { CJS_Object* pJSObj = data.GetParameter(); pJSObj->ExitInstance(); delete pJSObj; - FXJS_FreePrivate(data.GetInternalField(0)); + CFXJS_Engine::FreeObjectPrivate(data.GetInternalField(0)); } void DisposeObject(const v8::WeakCallbackInfo& data) { diff --git a/fpdfsdk/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/javascript/JS_Runtime_Stub.cpp index 109be0acd6..98c641f750 100644 --- a/fpdfsdk/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/javascript/JS_Runtime_Stub.cpp @@ -147,7 +147,8 @@ class CJS_RuntimeStub final : public IJS_Runtime { } #endif // PDF_ENABLE_XFA - int Execute(const CFX_WideString& script, CFX_WideString* info) override { + int ExecuteScript(const CFX_WideString& script, + CFX_WideString* info) override { return 0; } diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index b7198353da..c99affbede 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -39,16 +39,16 @@ CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local pValue) : m_pValue(pValue) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) - : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), iValue)) {} + : m_pValue(pRuntime->NewNumber(iValue)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) - : m_pValue(FXJS_NewBoolean(pRuntime->GetIsolate(), bValue)) {} + : m_pValue(pRuntime->NewBoolean(bValue)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) - : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), fValue)) {} + : m_pValue(pRuntime->NewNumber(fValue)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) - : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), dValue)) {} + : m_pValue(pRuntime->NewNumber(dValue)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) { if (pObj) @@ -56,17 +56,16 @@ CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) { } CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) - : m_pValue(FXJS_NewString(pRuntime->GetIsolate(), (wchar_t*)pWstr)) {} + : m_pValue(pRuntime->NewString(pWstr)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) - : m_pValue(FXJS_NewString(pRuntime->GetIsolate(), - CFX_WideString::FromLocal(pStr).c_str())) {} + : m_pValue(pRuntime->NewString(CFX_WideString::FromLocal(pStr).c_str())) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array) - : m_pValue(array.ToV8Array(pRuntime->GetIsolate())) {} + : m_pValue(array.ToV8Array(pRuntime)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Date& date) - : m_pValue(date.ToV8Date(pRuntime->GetIsolate())) {} + : m_pValue(date.ToV8Date(pRuntime)) {} CJS_Value::~CJS_Value() {} @@ -80,62 +79,63 @@ void CJS_Value::Detach() { m_pValue = v8::Local(); } -int CJS_Value::ToInt(v8::Isolate* pIsolate) const { - return FXJS_ToInt32(pIsolate, m_pValue); +int CJS_Value::ToInt(CJS_Runtime* pRuntime) const { + return pRuntime->ToInt32(m_pValue); } -bool CJS_Value::ToBool(v8::Isolate* pIsolate) const { - return FXJS_ToBoolean(pIsolate, m_pValue); +bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const { + return pRuntime->ToBoolean(m_pValue); } -double CJS_Value::ToDouble(v8::Isolate* pIsolate) const { - return FXJS_ToNumber(pIsolate, m_pValue); +double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const { + return pRuntime->ToNumber(m_pValue); } -float CJS_Value::ToFloat(v8::Isolate* pIsolate) const { - return (float)ToDouble(pIsolate); +float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const { + return (float)ToDouble(pRuntime); } -CJS_Object* CJS_Value::ToCJSObject(v8::Isolate* pIsolate) const { - v8::Local pObj = FXJS_ToObject(pIsolate, m_pValue); - return (CJS_Object*)FXJS_GetPrivate(pIsolate, pObj); +CJS_Object* CJS_Value::ToCJSObject(CJS_Runtime* pRuntime) const { + v8::Local pObj = pRuntime->ToObject(m_pValue); + return static_cast(pRuntime->GetObjectPrivate(pObj)); } -v8::Local CJS_Value::ToV8Object(v8::Isolate* pIsolate) const { - return FXJS_ToObject(pIsolate, m_pValue); +v8::Local CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const { + return pRuntime->ToObject(m_pValue); } -CFX_WideString CJS_Value::ToCFXWideString(v8::Isolate* pIsolate) const { - return FXJS_ToString(pIsolate, m_pValue); +CFX_WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const { + return pRuntime->ToString(m_pValue); } -CFX_ByteString CJS_Value::ToCFXByteString(v8::Isolate* pIsolate) const { - return CFX_ByteString::FromUnicode(ToCFXWideString(pIsolate)); +CFX_ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const { + return CFX_ByteString::FromUnicode(ToCFXWideString(pRuntime)); } -v8::Local CJS_Value::ToV8Value(v8::Isolate* pIsolate) const { +v8::Local CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const { return m_pValue; } -v8::Local CJS_Value::ToV8Array(v8::Isolate* pIsolate) const { +v8::Local CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const { if (IsArrayObject()) - return v8::Local::Cast(FXJS_ToObject(pIsolate, m_pValue)); + return v8::Local::Cast(pRuntime->ToObject(m_pValue)); return v8::Local(); } void CJS_Value::SetNull(CJS_Runtime* pRuntime) { - m_pValue = FXJS_NewNull(pRuntime->GetIsolate()); + m_pValue = pRuntime->NewNull(); } -void CJS_Value::MaybeCoerceToNumber(v8::Isolate* pIsolate) { +void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) { bool bAllowNaN = false; if (GetType() == VT_string) { - CFX_ByteString bstr = ToCFXByteString(pIsolate); + CFX_ByteString bstr = ToCFXByteString(pRuntime); if (bstr.GetLength() == 0) return; if (bstr == "NaN") bAllowNaN = true; } + v8::Isolate* pIsolate = pRuntime->GetIsolate(); v8::TryCatch try_catch(pIsolate); v8::MaybeLocal maybeNum = m_pValue->ToNumber(pIsolate->GetCurrentContext()); @@ -176,14 +176,14 @@ bool CJS_Value::IsDateObject() const { return !m_pValue.IsEmpty() && m_pValue->IsDate(); } -bool CJS_Value::ConvertToArray(v8::Isolate* pIsolate, CJS_Array& array) const { +bool CJS_Value::ConvertToArray(CJS_Runtime* pRuntime, CJS_Array& array) const { if (!IsArrayObject()) return false; - array.Attach(FXJS_ToArray(pIsolate, m_pValue)); + array.Attach(pRuntime->ToArray(m_pValue)); return true; } -bool CJS_Value::ConvertToDate(v8::Isolate* pIsolate, CJS_Date& date) const { +bool CJS_Value::ConvertToDate(CJS_Runtime* pRuntime, CJS_Date& date) const { if (!IsDateObject()) return false; v8::Local mutable_value = m_pValue; @@ -206,7 +206,7 @@ void CJS_PropValue::operator<<(int iValue) { void CJS_PropValue::operator>>(int& iValue) const { ASSERT(m_bIsSetting); - iValue = m_Value.ToInt(m_pJSRuntime->GetIsolate()); + iValue = m_Value.ToInt(m_pJSRuntime); } void CJS_PropValue::operator<<(bool bValue) { @@ -216,7 +216,7 @@ void CJS_PropValue::operator<<(bool bValue) { void CJS_PropValue::operator>>(bool& bValue) const { ASSERT(m_bIsSetting); - bValue = m_Value.ToBool(m_pJSRuntime->GetIsolate()); + bValue = m_Value.ToBool(m_pJSRuntime); } void CJS_PropValue::operator<<(double dValue) { @@ -226,7 +226,7 @@ void CJS_PropValue::operator<<(double dValue) { void CJS_PropValue::operator>>(double& dValue) const { ASSERT(m_bIsSetting); - dValue = m_Value.ToDouble(m_pJSRuntime->GetIsolate()); + dValue = m_Value.ToDouble(m_pJSRuntime); } void CJS_PropValue::operator<<(CJS_Object* pObj) { @@ -236,7 +236,7 @@ void CJS_PropValue::operator<<(CJS_Object* pObj) { void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToCJSObject(m_pJSRuntime->GetIsolate()); + ppObj = m_Value.ToCJSObject(m_pJSRuntime); } void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { @@ -246,8 +246,7 @@ void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { ASSERT(m_bIsSetting); - ppJsDoc = static_cast( - m_Value.ToCJSObject(m_pJSRuntime->GetIsolate())); + ppJsDoc = static_cast(m_Value.ToCJSObject(m_pJSRuntime)); } void CJS_PropValue::operator<<(v8::Local pObj) { @@ -257,7 +256,7 @@ void CJS_PropValue::operator<<(v8::Local pObj) { void CJS_PropValue::operator>>(v8::Local& ppObj) const { ASSERT(m_bIsSetting); - ppObj = m_Value.ToV8Object(m_pJSRuntime->GetIsolate()); + ppObj = m_Value.ToV8Object(m_pJSRuntime); } void CJS_PropValue::operator<<(CFX_ByteString str) { @@ -267,7 +266,7 @@ void CJS_PropValue::operator<<(CFX_ByteString str) { void CJS_PropValue::operator>>(CFX_ByteString& str) const { ASSERT(m_bIsSetting); - str = m_Value.ToCFXByteString(m_pJSRuntime->GetIsolate()); + str = m_Value.ToCFXByteString(m_pJSRuntime); } void CJS_PropValue::operator<<(const FX_WCHAR* str) { @@ -277,7 +276,7 @@ void CJS_PropValue::operator<<(const FX_WCHAR* str) { void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { ASSERT(m_bIsSetting); - wide_string = m_Value.ToCFXWideString(m_pJSRuntime->GetIsolate()); + wide_string = m_Value.ToCFXWideString(m_pJSRuntime); } void CJS_PropValue::operator<<(CFX_WideString wide_string) { @@ -287,18 +286,17 @@ void CJS_PropValue::operator<<(CFX_WideString wide_string) { void CJS_PropValue::operator>>(CJS_Array& array) const { ASSERT(m_bIsSetting); - m_Value.ConvertToArray(m_pJSRuntime->GetIsolate(), array); + m_Value.ConvertToArray(m_pJSRuntime, array); } void CJS_PropValue::operator<<(CJS_Array& array) { ASSERT(!m_bIsSetting); - m_Value = - CJS_Value(m_pJSRuntime, array.ToV8Array(m_pJSRuntime->GetIsolate())); + m_Value = CJS_Value(m_pJSRuntime, array.ToV8Array(m_pJSRuntime)); } void CJS_PropValue::operator>>(CJS_Date& date) const { ASSERT(m_bIsSetting); - m_Value.ConvertToDate(m_pJSRuntime->GetIsolate(), date); + m_Value.ConvertToDate(m_pJSRuntime, date); } void CJS_PropValue::operator<<(CJS_Date& date) { @@ -316,154 +314,146 @@ void CJS_Array::Attach(v8::Local pArray) { m_pArray = pArray; } -void CJS_Array::GetElement(v8::Isolate* pIsolate, +void CJS_Array::GetElement(CJS_Runtime* pRuntime, unsigned index, CJS_Value& value) const { if (!m_pArray.IsEmpty()) - value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index)); + value.Attach(pRuntime->GetArrayElement(m_pArray, index)); } -void CJS_Array::SetElement(v8::Isolate* pIsolate, +void CJS_Array::SetElement(CJS_Runtime* pRuntime, unsigned index, const CJS_Value& value) { if (m_pArray.IsEmpty()) - m_pArray = FXJS_NewArray(pIsolate); + m_pArray = pRuntime->NewArray(); - FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value(pIsolate)); + pRuntime->PutArrayElement(m_pArray, index, value.ToV8Value(pRuntime)); } -int CJS_Array::GetLength() const { +int CJS_Array::GetLength(CJS_Runtime* pRuntime) const { if (m_pArray.IsEmpty()) return 0; - return FXJS_GetArrayLength(m_pArray); + return pRuntime->GetArrayLength(m_pArray); } -v8::Local CJS_Array::ToV8Array(v8::Isolate* pIsolate) const { +v8::Local CJS_Array::ToV8Array(CJS_Runtime* pRuntime) const { if (m_pArray.IsEmpty()) - m_pArray = FXJS_NewArray(pIsolate); + m_pArray = pRuntime->NewArray(); return m_pArray; } CJS_Date::CJS_Date() {} -CJS_Date::CJS_Date(v8::Isolate* pIsolate, double dMsecTime) - : m_pDate(FXJS_NewDate(pIsolate, dMsecTime)) {} +CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) + : m_pDate(pRuntime->NewDate(dMsecTime)) {} -CJS_Date::CJS_Date(v8::Isolate* pIsolate, +CJS_Date::CJS_Date(CJS_Runtime* pRuntime, int year, int mon, int day, int hour, int min, int sec) - : m_pDate(FXJS_NewDate(pIsolate, - MakeDate(year, mon, day, hour, min, sec, 0))) {} + : m_pDate(pRuntime->NewDate(MakeDate(year, mon, day, hour, min, sec, 0))) {} CJS_Date::~CJS_Date() {} -bool CJS_Date::IsValidDate(v8::Isolate* pIsolate) const { - return !m_pDate.IsEmpty() && !JS_PortIsNan(FXJS_ToNumber(pIsolate, m_pDate)); +bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { + return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToNumber(m_pDate)); } void CJS_Date::Attach(v8::Local pDate) { m_pDate = pDate; } -int CJS_Date::GetYear(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetYear(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetYear(v8::Isolate* pIsolate, int iYear) { - m_pDate = FXJS_NewDate( - pIsolate, - MakeDate(iYear, GetMonth(pIsolate), GetDay(pIsolate), GetHours(pIsolate), - GetMinutes(pIsolate), GetSeconds(pIsolate), 0)); +void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) { + m_pDate = pRuntime->NewDate( + MakeDate(iYear, GetMonth(pRuntime), GetDay(pRuntime), GetHours(pRuntime), + GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); } -int CJS_Date::GetMonth(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetMonth(v8::Isolate* pIsolate, int iMonth) { - m_pDate = FXJS_NewDate( - pIsolate, - MakeDate(GetYear(pIsolate), iMonth, GetDay(pIsolate), GetHours(pIsolate), - GetMinutes(pIsolate), GetSeconds(pIsolate), 0)); +void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) { + m_pDate = pRuntime->NewDate( + MakeDate(GetYear(pRuntime), iMonth, GetDay(pRuntime), GetHours(pRuntime), + GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); } -int CJS_Date::GetDay(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetDay(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetDay(v8::Isolate* pIsolate, int iDay) { - m_pDate = FXJS_NewDate( - pIsolate, - MakeDate(GetYear(pIsolate), GetMonth(pIsolate), iDay, GetHours(pIsolate), - GetMinutes(pIsolate), GetSeconds(pIsolate), 0)); +void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) { + m_pDate = pRuntime->NewDate( + MakeDate(GetYear(pRuntime), GetMonth(pRuntime), iDay, GetHours(pRuntime), + GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); } -int CJS_Date::GetHours(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetHours(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetHours(v8::Isolate* pIsolate, int iHours) { - m_pDate = FXJS_NewDate( - pIsolate, - MakeDate(GetYear(pIsolate), GetMonth(pIsolate), GetDay(pIsolate), iHours, - GetMinutes(pIsolate), GetSeconds(pIsolate), 0)); +void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) { + m_pDate = pRuntime->NewDate( + MakeDate(GetYear(pRuntime), GetMonth(pRuntime), GetDay(pRuntime), iHours, + GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); } -int CJS_Date::GetMinutes(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetMinutes(v8::Isolate* pIsolate, int minutes) { - m_pDate = - FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate), - GetDay(pIsolate), GetHours(pIsolate), - minutes, GetSeconds(pIsolate), 0)); +void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) { + m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), + GetDay(pRuntime), GetHours(pRuntime), + minutes, GetSeconds(pRuntime), 0)); } -int CJS_Date::GetSeconds(v8::Isolate* pIsolate) const { - if (!IsValidDate(pIsolate)) +int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const { + if (!IsValidDate(pRuntime)) return 0; - return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(pIsolate, m_pDate))); + return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate))); } -void CJS_Date::SetSeconds(v8::Isolate* pIsolate, int seconds) { - m_pDate = - FXJS_NewDate(pIsolate, MakeDate(GetYear(pIsolate), GetMonth(pIsolate), - GetDay(pIsolate), GetHours(pIsolate), - GetMinutes(pIsolate), seconds, 0)); +void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) { + m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), + GetDay(pRuntime), GetHours(pRuntime), + GetMinutes(pRuntime), seconds, 0)); } -double CJS_Date::ToDouble(v8::Isolate* pIsolate) const { - return !m_pDate.IsEmpty() ? FXJS_ToNumber(pIsolate, m_pDate) : 0.0; +double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const { + return !m_pDate.IsEmpty() ? pRuntime->ToNumber(m_pDate) : 0.0; } -CFX_WideString CJS_Date::ToString(v8::Isolate* pIsolate) const { - return !m_pDate.IsEmpty() ? FXJS_ToString(pIsolate, m_pDate) - : CFX_WideString(); +CFX_WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const { + return !m_pDate.IsEmpty() ? pRuntime->ToString(m_pDate) : CFX_WideString(); } -v8::Local CJS_Date::ToV8Date(v8::Isolate* pIsolate) const { +v8::Local CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const { return m_pDate; } @@ -688,7 +678,8 @@ double JS_DateParse(const CFX_WideString& str) { if (v->IsFunction()) { v8::Local funC = v8::Local::Cast(v); const int argc = 1; - v8::Local timeStr = FXJS_WSToJSString(pIsolate, str); + v8::Local timeStr = + CJS_Runtime::CurrentRuntimeFromIsolate(pIsolate)->WSToJSString(str); v8::Local argv[argc] = {timeStr}; v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); if (v->IsNumber()) { @@ -763,15 +754,14 @@ std::vector JS_ExpandKeywordParams( originals[0].IsArrayObject()) { return result; } - v8::Local pObj = originals[0].ToV8Object(pRuntime->GetIsolate()); + v8::Local pObj = originals[0].ToV8Object(pRuntime); result[0] = CJS_Value(pRuntime); // Make unknown. va_list ap; va_start(ap, nKeywords); for (size_t i = 0; i < nKeywords; ++i) { const wchar_t* property = va_arg(ap, const wchar_t*); - v8::Local v8Value = - FXJS_GetObjectProperty(pRuntime->GetIsolate(), pObj, property); + v8::Local v8Value = pRuntime->GetObjectProperty(pObj, property); if (!v8Value->IsUndefined()) result[i] = CJS_Value(pRuntime, v8Value); } diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h index 5587ed04de..c567a7cbf2 100644 --- a/fpdfsdk/javascript/JS_Value.h +++ b/fpdfsdk/javascript/JS_Value.h @@ -55,25 +55,25 @@ class CJS_Value { static Type GetValueType(v8::Local value); Type GetType() const { return GetValueType(m_pValue); } - int ToInt(v8::Isolate* pIsolate) const; - bool ToBool(v8::Isolate* pIsolate) const; - double ToDouble(v8::Isolate* pIsolate) const; - float ToFloat(v8::Isolate* pIsolate) const; - CJS_Object* ToCJSObject(v8::Isolate* pIsolate) const; - CFX_WideString ToCFXWideString(v8::Isolate* pIsolate) const; - CFX_ByteString ToCFXByteString(v8::Isolate* pIsolate) const; - v8::Local ToV8Object(v8::Isolate* pIsolate) const; - v8::Local ToV8Array(v8::Isolate* pIsolate) const; - v8::Local ToV8Value(v8::Isolate* pIsolate) const; + int ToInt(CJS_Runtime* pRuntime) const; + bool ToBool(CJS_Runtime* pRuntime) const; + double ToDouble(CJS_Runtime* pRuntime) const; + float ToFloat(CJS_Runtime* pRuntime) const; + CJS_Object* ToCJSObject(CJS_Runtime* pRuntime) const; + CFX_WideString ToCFXWideString(CJS_Runtime* pRuntime) const; + CFX_ByteString ToCFXByteString(CJS_Runtime* pRuntime) const; + v8::Local ToV8Object(CJS_Runtime* pRuntime) const; + v8::Local ToV8Array(CJS_Runtime* pRuntime) const; + v8::Local ToV8Value(CJS_Runtime* pRuntime) const; // Replace the current |m_pValue| with a v8::Number if possible // to make one from the current |m_pValue|. - void MaybeCoerceToNumber(v8::Isolate* pIsolate); + void MaybeCoerceToNumber(CJS_Runtime* pRuntime); bool IsArrayObject() const; bool IsDateObject() const; - bool ConvertToArray(v8::Isolate* pIsolate, CJS_Array&) const; - bool ConvertToDate(v8::Isolate* pIsolate, CJS_Date&) const; + bool ConvertToArray(CJS_Runtime* pRuntime, CJS_Array&) const; + bool ConvertToDate(CJS_Runtime* pRuntime, CJS_Date&) const; protected: v8::Local m_pValue; @@ -127,15 +127,15 @@ class CJS_Array { virtual ~CJS_Array(); void Attach(v8::Local pArray); - void GetElement(v8::Isolate* pIsolate, + void GetElement(CJS_Runtime* pRuntime, unsigned index, CJS_Value& value) const; - void SetElement(v8::Isolate* pIsolate, + void SetElement(CJS_Runtime* pRuntime, unsigned index, const CJS_Value& value); - int GetLength() const; + int GetLength(CJS_Runtime* pRuntime) const; - v8::Local ToV8Array(v8::Isolate* pIsolate) const; + v8::Local ToV8Array(CJS_Runtime* pRuntime) const; private: mutable v8::Local m_pArray; @@ -144,8 +144,8 @@ class CJS_Array { class CJS_Date { public: CJS_Date(); - CJS_Date(v8::Isolate* pIsolate, double dMsec_time); - CJS_Date(v8::Isolate* pIsolate, + CJS_Date(CJS_Runtime* pRuntime, double dMsec_time); + CJS_Date(CJS_Runtime* pRuntime, int year, int mon, int day, @@ -155,29 +155,29 @@ class CJS_Date { virtual ~CJS_Date(); void Attach(v8::Local pDate); - bool IsValidDate(v8::Isolate* pIsolate) const; + bool IsValidDate(CJS_Runtime* pRuntime) const; - int GetYear(v8::Isolate* pIsolate) const; - void SetYear(v8::Isolate* pIsolate, int iYear); + int GetYear(CJS_Runtime* pRuntime) const; + void SetYear(CJS_Runtime* pRuntime, int iYear); - int GetMonth(v8::Isolate* pIsolate) const; - void SetMonth(v8::Isolate* pIsolate, int iMonth); + int GetMonth(CJS_Runtime* pRuntime) const; + void SetMonth(CJS_Runtime* pRuntime, int iMonth); - int GetDay(v8::Isolate* pIsolate) const; - void SetDay(v8::Isolate* pIsolate, int iDay); + int GetDay(CJS_Runtime* pRuntime) const; + void SetDay(CJS_Runtime* pRuntime, int iDay); - int GetHours(v8::Isolate* pIsolate) const; - void SetHours(v8::Isolate* pIsolate, int iHours); + int GetHours(CJS_Runtime* pRuntime) const; + void SetHours(CJS_Runtime* pRuntime, int iHours); - int GetMinutes(v8::Isolate* pIsolate) const; - void SetMinutes(v8::Isolate* pIsolate, int minutes); + int GetMinutes(CJS_Runtime* pRuntime) const; + void SetMinutes(CJS_Runtime* pRuntime, int minutes); - int GetSeconds(v8::Isolate* pIsolate) const; - void SetSeconds(v8::Isolate* pIsolate, int seconds); + int GetSeconds(CJS_Runtime* pRuntime) const; + void SetSeconds(CJS_Runtime* pRuntime, int seconds); - v8::Local ToV8Date(v8::Isolate* pIsolate) const; - double ToDouble(v8::Isolate* pIsolate) const; - CFX_WideString ToString(v8::Isolate* pIsolate) const; + v8::Local ToV8Date(CJS_Runtime* pRuntime) const; + double ToDouble(CJS_Runtime* pRuntime) const; + CFX_WideString ToString(CJS_Runtime* pRuntime) const; protected: v8::Local m_pDate; diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index f1e23dbef5..01bcfac44a 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -163,10 +163,10 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val) { CJS_Array StrArray; if (val.IsArrayObject()) { - val.ConvertToArray(pRuntime->GetIsolate(), StrArray); + val.ConvertToArray(pRuntime, StrArray); return StrArray; } - CFX_WideString wsStr = val.ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString wsStr = val.ToCFXWideString(pRuntime); CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); const char* p = t.c_str(); @@ -177,7 +177,7 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, const char* pTemp = strchr(p, ch); if (!pTemp) { StrArray.SetElement( - pRuntime->GetIsolate(), nIndex, + pRuntime, nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); break; } @@ -187,7 +187,7 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, *(pSub + (pTemp - p)) = '\0'; StrArray.SetElement( - pRuntime->GetIsolate(), nIndex, + pRuntime, nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); delete[] pSub; @@ -743,13 +743,12 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, if (strValue.IsEmpty()) return TRUE; - int iDec = params[0].ToInt(pRuntime->GetIsolate()); - int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); - int iNegStyle = params[2].ToInt(pRuntime->GetIsolate()); + int iDec = params[0].ToInt(pRuntime); + int iSepStyle = params[1].ToInt(pRuntime); + int iNegStyle = params[2].ToInt(pRuntime); // params[3] is iCurrStyle, it's not used. - CFX_WideString wstrCurrency = - params[4].ToCFXWideString(pRuntime->GetIsolate()); - FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime->GetIsolate()); + CFX_WideString wstrCurrency = params[4].ToCFXWideString(pRuntime); + FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime); if (iDec < 0) iDec = -iDec; @@ -839,12 +838,12 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, CJS_Array arColor; CJS_Value vColElm(pRuntime); vColElm = CJS_Value(pRuntime, L"RGB"); - arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); + arColor.SetElement(pRuntime, 0, vColElm); vColElm = CJS_Value(pRuntime, 1); - arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); + arColor.SetElement(pRuntime, 1, vColElm); vColElm = CJS_Value(pRuntime, 0); - arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); - arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); + arColor.SetElement(pRuntime, 2, vColElm); + arColor.SetElement(pRuntime, 3, vColElm); CJS_PropValue vProp(pRuntime); vProp.StartGetting(); @@ -859,18 +858,18 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, CJS_Array arColor; CJS_Value vColElm(pRuntime); vColElm = CJS_Value(pRuntime, L"RGB"); - arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); + arColor.SetElement(pRuntime, 0, vColElm); vColElm = CJS_Value(pRuntime, 0); - arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); - arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); - arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); + arColor.SetElement(pRuntime, 1, vColElm); + arColor.SetElement(pRuntime, 2, vColElm); + arColor.SetElement(pRuntime, 3, vColElm); CJS_PropValue vProp(pRuntime); vProp.StartGetting(); fTarget->textColor(cc, vProp, sError); CJS_Array aProp; - vProp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), aProp); + vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); CPWL_Color crProp; CPWL_Color crColor; @@ -942,7 +941,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); + int iSepStyle = params[1].ToInt(pRuntime); if (iSepStyle < 0 || iSepStyle > 3) iSepStyle = 0; const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; @@ -1017,11 +1016,11 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format( if (strValue.IsEmpty()) return TRUE; - int iDec = params[0].ToInt(pRuntime->GetIsolate()); + int iDec = params[0].ToInt(pRuntime); if (iDec < 0) iDec = -iDec; - int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); + int iSepStyle = params[1].ToInt(pRuntime); if (iSepStyle < 0 || iSepStyle > 3) iSepStyle = 0; @@ -1117,7 +1116,7 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, if (strValue.IsEmpty()) return TRUE; - CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); double dDate = 0.0f; if (strValue.Find(L"GMT") != -1) { @@ -1218,7 +1217,7 @@ FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( if (strValue.IsEmpty()) return TRUE; - CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); bool bWrongFormat = FALSE; double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); if (bWrongFormat || JS_PortIsNan(dRet)) { @@ -1244,7 +1243,7 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int iIndex = params[0].ToInt(pRuntime->GetIsolate()); + int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", @@ -1282,7 +1281,7 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke( } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int iIndex = params[0].ToInt(pRuntime->GetIsolate()); + int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", @@ -1319,7 +1318,7 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int iIndex = params[0].ToInt(pRuntime->GetIsolate()); + int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1344,7 +1343,7 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke( } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - int iIndex = params[0].ToInt(pRuntime->GetIsolate()); + int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1391,7 +1390,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Format( CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CFX_WideString wsSource = pEvent->Value(); CFX_WideString wsFormat; - switch (params[0].ToInt(pRuntime->GetIsolate())) { + switch (params[0].ToInt(pRuntime)) { case 0: wsFormat = L"99999"; break; @@ -1432,7 +1431,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( return FALSE; CFX_WideString& valEvent = pEvent->Value(); - CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); if (wstrMask.IsEmpty()) return TRUE; @@ -1520,7 +1519,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( const char* cFormat = ""; CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - switch (params[0].ToInt(pRuntime->GetIsolate())) { + switch (params[0].ToInt(pRuntime)) { case 0: cFormat = "99999"; break; @@ -1596,8 +1595,8 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, return FALSE; } - CFX_WideString sValue = params[0].ToCFXWideString(pRuntime->GetIsolate()); - CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); + CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); double dDate = MakeRegularDate(sValue, sFormat, nullptr); @@ -1625,11 +1624,10 @@ FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, return FALSE; } - vRet = CJS_Value( - pRuntime, static_cast(AF_Simple( - params[0].ToCFXWideString(pRuntime->GetIsolate()).c_str(), - params[1].ToDouble(pRuntime->GetIsolate()), - params[2].ToDouble(pRuntime->GetIsolate())))); + vRet = CJS_Value(pRuntime, static_cast(AF_Simple( + params[0].ToCFXWideString(pRuntime).c_str(), + params[1].ToDouble(pRuntime), + params[2].ToDouble(pRuntime)))); return TRUE; } @@ -1646,10 +1644,10 @@ FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, return FALSE; } - CFX_WideString ws = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString ws = params[0].ToCFXWideString(pRuntime); ws.Replace(L",", L"."); vRet = CJS_Value(pRuntime, ws.c_str()); - vRet.MaybeCoerceToNumber(pRuntime->GetIsolate()); + vRet.MaybeCoerceToNumber(pRuntime); if (vRet.GetType() != CJS_Value::VT_number) vRet = CJS_Value(pRuntime, 0); return TRUE; @@ -1678,17 +1676,16 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); int nFieldsCount = 0; - for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { + for (int i = 0, isz = FieldNameArray.GetLength(pRuntime); i < isz; i++) { CJS_Value jsValue(pRuntime); - FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); - CFX_WideString wsFieldName = - jsValue.ToCFXWideString(pRuntime->GetIsolate()); + FieldNameArray.GetElement(pRuntime, i, jsValue); + CFX_WideString wsFieldName = jsValue.ToCFXWideString(pRuntime); for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { @@ -1749,8 +1746,7 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( FXSYS_pow((double)10, (double)6); CJS_Value jsValue(pRuntime, dValue); if (pContext->GetEventHandler()->m_pValue) - pContext->GetEventHandler()->Value() = - jsValue.ToCFXWideString(pRuntime->GetIsolate()); + pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); return TRUE; } @@ -1778,25 +1774,25 @@ FX_BOOL CJS_PublicMethods::AFRange_Validate( return TRUE; double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); - FX_BOOL bGreaterThan = params[0].ToBool(pRuntime->GetIsolate()); - double dGreaterThan = params[1].ToDouble(pRuntime->GetIsolate()); - FX_BOOL bLessThan = params[2].ToBool(pRuntime->GetIsolate()); - double dLessThan = params[3].ToDouble(pRuntime->GetIsolate()); + FX_BOOL bGreaterThan = params[0].ToBool(pRuntime); + double dGreaterThan = params[1].ToDouble(pRuntime); + FX_BOOL bLessThan = params[2].ToBool(pRuntime); + double dLessThan = params[3].ToDouble(pRuntime); CFX_WideString swMsg; if (bGreaterThan && bLessThan) { if (dEentValue < dGreaterThan || dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), - params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str(), - params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); + params[1].ToCFXWideString(pRuntime).c_str(), + params[3].ToCFXWideString(pRuntime).c_str()); } else if (bGreaterThan) { if (dEentValue < dGreaterThan) swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), - params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str()); + params[1].ToCFXWideString(pRuntime).c_str()); } else if (bLessThan) { if (dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), - params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); + params[3].ToCFXWideString(pRuntime).c_str()); } if (!swMsg.IsEmpty()) { @@ -1819,7 +1815,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, } CJS_Array nums; - CFX_WideString str = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString str = params[0].ToCFXWideString(pRuntime); CFX_WideString sPart; if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') @@ -1832,8 +1828,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, sPart += wc; } else { if (sPart.GetLength() > 0) { - nums.SetElement(pRuntime->GetIsolate(), nIndex, - CJS_Value(pRuntime, sPart.c_str())); + nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); sPart = L""; nIndex++; } @@ -1841,11 +1836,10 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, } if (sPart.GetLength() > 0) { - nums.SetElement(pRuntime->GetIsolate(), nIndex, - CJS_Value(pRuntime, sPart.c_str())); + nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); } - if (nums.GetLength() > 0) + if (nums.GetLength(pRuntime) > 0) vRet = CJS_Value(pRuntime, nums); else vRet.SetNull(pRuntime); diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 8d7420b7bd..18415dcea2 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -235,21 +235,21 @@ FX_BOOL app::activeDocs(IJS_Context* cc, if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { CJS_Document* pJSDocument = nullptr; if (pDoc == pCurDoc) { - v8::Local pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); - if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) + v8::Local pObj = pRuntime->GetThisObj(); + if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { pJSDocument = - (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); + static_cast(pRuntime->GetObjectPrivate(pObj)); + } } else { - v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Document::g_nObjDefnID); pJSDocument = - (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); + static_cast(pRuntime->GetObjectPrivate(pObj)); ASSERT(pJSDocument); } - aDocs.SetElement(pRuntime->GetIsolate(), 0, - CJS_Value(pRuntime, pJSDocument)); + aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); } - if (aDocs.GetLength() > 0) + if (aDocs.GetLength(pRuntime) > 0) vp << aDocs; else vp.GetJSValue()->SetNull(pRuntime); @@ -412,34 +412,34 @@ FX_BOOL app::alert(IJS_Context* cc, CFX_WideString swMsg; if (newParams[0].GetType() == CJS_Value::VT_object) { CJS_Array carray; - if (newParams[0].ConvertToArray(pRuntime->GetIsolate(), carray)) { + if (newParams[0].ConvertToArray(pRuntime, carray)) { swMsg = L"["; CJS_Value element(pRuntime); - for (int i = 0; i < carray.GetLength(); ++i) { + for (int i = 0; i < carray.GetLength(pRuntime); ++i) { if (i) swMsg += L", "; - carray.GetElement(pRuntime->GetIsolate(), i, element); - swMsg += element.ToCFXWideString(pRuntime->GetIsolate()); + carray.GetElement(pRuntime, i, element); + swMsg += element.ToCFXWideString(pRuntime); } swMsg += L"]"; } else { - swMsg = newParams[0].ToCFXWideString(pRuntime->GetIsolate()); + swMsg = newParams[0].ToCFXWideString(pRuntime); } } else { - swMsg = newParams[0].ToCFXWideString(pRuntime->GetIsolate()); + swMsg = newParams[0].ToCFXWideString(pRuntime); } int iIcon = 0; if (newParams[1].GetType() != CJS_Value::VT_unknown) - iIcon = newParams[1].ToInt(pRuntime->GetIsolate()); + iIcon = newParams[1].ToInt(pRuntime); int iType = 0; if (newParams[2].GetType() != CJS_Value::VT_unknown) - iType = newParams[2].ToInt(pRuntime->GetIsolate()); + iType = newParams[2].ToInt(pRuntime); CFX_WideString swTitle; if (newParams[3].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[3].ToCFXWideString(pRuntime->GetIsolate()); + swTitle = newParams[3].ToCFXWideString(pRuntime); else swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); @@ -461,7 +461,7 @@ FX_BOOL app::beep(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); - pEnv->JS_appBeep(params[0].ToInt(pRuntime->GetIsolate())); + pEnv->JS_appBeep(params[0].ToInt(pRuntime)); return TRUE; } @@ -500,23 +500,21 @@ FX_BOOL app::setInterval(IJS_Context* cc, } CFX_WideString script = - params.size() > 0 ? params[0].ToCFXWideString(pRuntime->GetIsolate()) - : L""; + params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; if (script.IsEmpty()) { sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); return TRUE; } - uint32_t dwInterval = - params.size() > 1 ? params[1].ToInt(pRuntime->GetIsolate()) : 1000; + uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); m_Timers.push_back(std::unique_ptr( new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0))); - v8::Local pRetObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); - CJS_TimerObj* pJS_TimerObj = static_cast( - FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); + v8::Local pRetObj = + pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); + CJS_TimerObj* pJS_TimerObj = + static_cast(pRuntime->GetObjectPrivate(pRetObj)); TimerObj* pTimerObj = static_cast(pJS_TimerObj->GetEmbedObject()); pTimerObj->SetTimer(m_Timers.back().get()); @@ -536,23 +534,22 @@ FX_BOOL app::setTimeOut(IJS_Context* cc, return FALSE; } - CFX_WideString script = params[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString script = params[0].ToCFXWideString(pRuntime); if (script.IsEmpty()) { sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); return TRUE; } - uint32_t dwTimeOut = - params.size() > 1 ? params[1].ToInt(pRuntime->GetIsolate()) : 1000; + uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); m_Timers.push_back(std::unique_ptr( new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut))); - v8::Local pRetObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); + v8::Local pRetObj = + pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); - CJS_TimerObj* pJS_TimerObj = static_cast( - FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); + CJS_TimerObj* pJS_TimerObj = + static_cast(pRuntime->GetObjectPrivate(pRetObj)); TimerObj* pTimerObj = static_cast(pJS_TimerObj->GetEmbedObject()); pTimerObj->SetTimer(m_Timers.back().get()); @@ -571,7 +568,7 @@ FX_BOOL app::clearTimeOut(IJS_Context* cc, return FALSE; } - app::ClearTimerCommon(params[0]); + app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]); return TRUE; } @@ -585,19 +582,19 @@ FX_BOOL app::clearInterval(IJS_Context* cc, return FALSE; } - app::ClearTimerCommon(params[0]); + app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]); return TRUE; } -void app::ClearTimerCommon(const CJS_Value& param) { +void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { if (param.GetType() != CJS_Value::VT_object) return; - v8::Local pObj = param.ToV8Object(GetJSObject()->GetIsolate()); - if (FXJS_GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) + v8::Local pObj = param.ToV8Object(pRuntime); + if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) return; - CJS_Object* pJSObj = param.ToCJSObject(GetJSObject()->GetIsolate()); + CJS_Object* pJSObj = param.ToCJSObject(pRuntime); if (!pJSObj) return; @@ -671,11 +668,11 @@ FX_BOOL app::mailMsg(IJS_Context* cc, sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); return FALSE; } - bool bUI = newParams[0].ToBool(pRuntime->GetIsolate()); + bool bUI = newParams[0].ToBool(pRuntime); CFX_WideString cTo; if (newParams[1].GetType() != CJS_Value::VT_unknown) { - cTo = newParams[1].ToCFXWideString(pRuntime->GetIsolate()); + cTo = newParams[1].ToCFXWideString(pRuntime); } else { if (!bUI) { // cTo parameter required when UI not invoked. @@ -686,19 +683,19 @@ FX_BOOL app::mailMsg(IJS_Context* cc, CFX_WideString cCc; if (newParams[2].GetType() != CJS_Value::VT_unknown) - cCc = newParams[2].ToCFXWideString(pRuntime->GetIsolate()); + cCc = newParams[2].ToCFXWideString(pRuntime); CFX_WideString cBcc; if (newParams[3].GetType() != CJS_Value::VT_unknown) - cBcc = newParams[3].ToCFXWideString(pRuntime->GetIsolate()); + cBcc = newParams[3].ToCFXWideString(pRuntime); CFX_WideString cSubject; if (newParams[4].GetType() != CJS_Value::VT_unknown) - cSubject = newParams[4].ToCFXWideString(pRuntime->GetIsolate()); + cSubject = newParams[4].ToCFXWideString(pRuntime); CFX_WideString cMsg; if (newParams[5].GetType() != CJS_Value::VT_unknown) - cMsg = newParams[5].ToCFXWideString(pRuntime->GetIsolate()); + cMsg = newParams[5].ToCFXWideString(pRuntime); pRuntime->BeginBlock(); pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), @@ -794,24 +791,23 @@ FX_BOOL app::response(IJS_Context* cc, sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); return FALSE; } - CFX_WideString swQuestion = - newParams[0].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); CFX_WideString swTitle = L"PDF"; if (newParams[1].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[1].ToCFXWideString(pRuntime->GetIsolate()); + swTitle = newParams[1].ToCFXWideString(pRuntime); CFX_WideString swDefault; if (newParams[2].GetType() != CJS_Value::VT_unknown) - swDefault = newParams[2].ToCFXWideString(pRuntime->GetIsolate()); + swDefault = newParams[2].ToCFXWideString(pRuntime); bool bPassword = false; if (newParams[3].GetType() != CJS_Value::VT_unknown) - bPassword = newParams[3].ToBool(pRuntime->GetIsolate()); + bPassword = newParams[3].ToBool(pRuntime); CFX_WideString swLabel; if (newParams[4].GetType() != CJS_Value::VT_unknown) - swLabel = newParams[4].ToCFXWideString(pRuntime->GetIsolate()); + swLabel = newParams[4].ToCFXWideString(pRuntime); const int MAX_INPUT_BYTES = 2048; std::unique_ptr pBuff(new char[MAX_INPUT_BYTES + 2]); diff --git a/fpdfsdk/javascript/app.h b/fpdfsdk/javascript/app.h index 52dfd2f9ca..97db59e437 100644 --- a/fpdfsdk/javascript/app.h +++ b/fpdfsdk/javascript/app.h @@ -161,7 +161,7 @@ class app : public CJS_EmbedObj { // CJS_EmbedObj void RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript); - void ClearTimerCommon(const CJS_Value& param); + void ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param); bool m_bCalculate; bool m_bRuntimeHighLight; diff --git a/fpdfsdk/javascript/cjs_context.cpp b/fpdfsdk/javascript/cjs_context.cpp index 06abf7f48d..c37fdab738 100644 --- a/fpdfsdk/javascript/cjs_context.cpp +++ b/fpdfsdk/javascript/cjs_context.cpp @@ -29,7 +29,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString* info) { v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); - v8::Local context = m_pRuntime->NewJSContext(); + v8::Local context = m_pRuntime->NewLocalContext(); v8::Context::Scope context_scope(context); if (m_bBusy) { @@ -49,7 +49,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString sErrorMessage; int nRet = 0; if (script.GetLength() > 0) { - nRet = m_pRuntime->Execute(script.c_str(), &sErrorMessage); + nRet = m_pRuntime->ExecuteScript(script.c_str(), &sErrorMessage); } if (nRet < 0) { diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index 36d888a2ea..7ea9b158a5 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -55,11 +55,18 @@ CJS_Runtime* CJS_Runtime::FromContext(const IJS_Context* cc) { return pContext->GetJSRuntime(); } +// static +CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) { + return static_cast( + CFXJS_Engine::CurrentEngineFromIsolate(pIsolate)); +} + CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(nullptr), m_bBlocking(false), m_isolateManaged(false) { + v8::Isolate* pIsolate = nullptr; #ifndef PDF_ENABLE_XFA IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { @@ -71,11 +78,13 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } - m_isolateManaged = FXJS_GetIsolate(&m_isolate); + m_isolateManaged = FXJS_GetIsolate(&pIsolate); + SetIsolate(pIsolate); #else if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. - m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); + pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime(); + SetIsolate(pIsolate); } else { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { @@ -87,15 +96,15 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } - m_isolateManaged = FXJS_GetIsolate(&m_isolate); + m_isolateManaged = FXJS_GetIsolate(&pIsolate); + SetIsolate(pIsolate); } - v8::Isolate* isolate = m_isolate; - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); + v8::Isolate::Scope isolate_scope(pIsolate); + v8::HandleScope handle_scope(pIsolate); if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { CJS_Context* pContext = (CJS_Context*)NewContext(); - FXJS_InitializeEngine(GetIsolate(), this, &m_context, &m_StaticObjects); + InitializeEngine(); ReleaseContext(pContext); return; } @@ -109,7 +118,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) #endif CJS_Context* pContext = (CJS_Context*)NewContext(); - FXJS_InitializeEngine(GetIsolate(), this, &m_context, &m_StaticObjects); + InitializeEngine(); ReleaseContext(pContext); } @@ -117,12 +126,11 @@ CJS_Runtime::~CJS_Runtime() { for (auto* obs : m_observers) obs->OnDestroyed(); - m_ContextArray.clear(); - m_ConstArrays.clear(); - FXJS_ReleaseEngine(GetIsolate(), &m_context, &m_StaticObjects); - m_context.Reset(); - if (m_isolateManaged) - m_isolate->Dispose(); + ReleaseEngine(); + if (m_isolateManaged) { + GetIsolate()->Dispose(); + SetIsolate(nullptr); + } } void CJS_Runtime::DefineJSObjects() { @@ -133,43 +141,43 @@ void CJS_Runtime::DefineJSObjects() { // The call order determines the "ObjDefID" assigned to each class. // ObjDefIDs 0 - 2 - CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); + CJS_Border::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Display::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Font::DefineJSObjects(this, FXJSOBJTYPE_STATIC); // ObjDefIDs 3 - 5 - CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); + CJS_Highlight::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Position::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_ScaleHow::DefineJSObjects(this, FXJSOBJTYPE_STATIC); // ObjDefIDs 6 - 8 - CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); + CJS_ScaleWhen::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Style::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Zoomtype::DefineJSObjects(this, FXJSOBJTYPE_STATIC); // ObjDefIDs 9 - 11 - CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); + CJS_App::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Color::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Console::DefineJSObjects(this, FXJSOBJTYPE_STATIC); // ObjDefIDs 12 - 14 - CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL); - CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); + CJS_Document::DefineJSObjects(this, FXJSOBJTYPE_GLOBAL); + CJS_Event::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Field::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); // ObjDefIDs 15 - 17 - CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); - CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); - CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); + CJS_Global::DefineJSObjects(this, FXJSOBJTYPE_STATIC); + CJS_Icon::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); + CJS_Util::DefineJSObjects(this, FXJSOBJTYPE_STATIC); // ObjDefIDs 18 - 20 (these can't fail, return void). - CJS_PublicMethods::DefineJSObjects(GetIsolate()); + CJS_PublicMethods::DefineJSObjects(this); CJS_GlobalConsts::DefineJSObjects(this); CJS_GlobalArrays::DefineJSObjects(this); // ObjDefIDs 21 - 22. - CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); - CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); + CJS_TimerObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); + CJS_PrintParamsObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); } IJS_Context* CJS_Runtime::NewContext() { @@ -191,36 +199,45 @@ IJS_Context* CJS_Runtime::GetCurrentContext() { } void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { - if (m_pDocument != pReaderDoc) { - v8::Isolate::Scope isolate_scope(m_isolate); - v8::HandleScope handle_scope(m_isolate); - v8::Local context = - v8::Local::New(m_isolate, m_context); - v8::Context::Scope context_scope(context); - - m_pDocument = pReaderDoc; - if (pReaderDoc) { - v8::Local pThis = FXJS_GetThisObj(GetIsolate()); - if (!pThis.IsEmpty()) { - if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) { - if (CJS_Document* pJSDocument = - (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { - if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) - pDocument->AttachDoc(pReaderDoc); - } - } - } - } - } + if (m_pDocument == pReaderDoc) + return; + + v8::Isolate::Scope isolate_scope(GetIsolate()); + v8::HandleScope handle_scope(GetIsolate()); + v8::Local context = NewLocalContext(); + v8::Context::Scope context_scope(context); + + m_pDocument = pReaderDoc; + if (!pReaderDoc) + return; + + v8::Local pThis = GetThisObj(); + if (pThis.IsEmpty()) + return; + + if (CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::g_nObjDefnID) + return; + + CJS_Document* pJSDocument = + static_cast(GetObjectPrivate(pThis)); + if (!pJSDocument) + return; + + Document* pDocument = static_cast(pJSDocument->GetEmbedObject()); + if (!pDocument) + return; + + pDocument->AttachDoc(pReaderDoc); } CPDFSDK_Document* CJS_Runtime::GetReaderDocument() { return m_pDocument; } -int CJS_Runtime::Execute(const CFX_WideString& script, CFX_WideString* info) { +int CJS_Runtime::ExecuteScript(const CFX_WideString& script, + CFX_WideString* info) { FXJSErr error = {}; - int nRet = FXJS_Execute(m_isolate, script, &error); + int nRet = Execute(script, &error); if (nRet < 0) { info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, error.message); @@ -236,19 +253,6 @@ void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { m_FieldEventSet.erase(event); } -v8::Local CJS_Runtime::NewJSContext() { - return v8::Local::New(m_isolate, m_context); -} - -void CJS_Runtime::SetConstArray(const CFX_WideString& name, - v8::Local array) { - m_ConstArrays[name] = v8::Global(m_isolate, array); -} - -v8::Local CJS_Runtime::GetConstArray(const CFX_WideString& name) { - return v8::Local::New(m_isolate, m_ConstArrays[name]); -} - void CJS_Runtime::AddObserver(Observer* observer) { ASSERT(!pdfium::ContainsKey(m_observers, observer)); m_observers.insert(observer); @@ -272,8 +276,7 @@ FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, v8::Isolate::Scope isolate_scope(GetIsolate()); v8::HandleScope handle_scope(GetIsolate()); v8::Local old_context = GetIsolate()->GetCurrentContext(); - v8::Local context = - v8::Local::New(GetIsolate(), m_context); + v8::Local context = NewLocalContext(); v8::Context::Scope context_scope(context); // Caution: We're about to hand to XFA an object that in order to invoke @@ -283,7 +286,7 @@ FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, // Do so now. // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's // embedder data slots, and/or to always use the right context. - FXJS_SetEngineForV8Context(old_context, this); + CFXJS_Engine::SetForV8Context(old_context, this); v8::Local propvalue = context->Global()->Get(v8::String::NewFromUtf8( @@ -304,8 +307,7 @@ FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, v8::Isolate* pIsolate = GetIsolate(); v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); - v8::Local context = - v8::Local::New(pIsolate, m_context); + v8::Local context = NewLocalContext(); v8::Context::Scope context_scope(context); // v8::Local tmpCotext = diff --git a/fpdfsdk/javascript/cjs_runtime.h b/fpdfsdk/javascript/cjs_runtime.h index 16432d5394..33d2956ce3 100644 --- a/fpdfsdk/javascript/cjs_runtime.h +++ b/fpdfsdk/javascript/cjs_runtime.h @@ -33,6 +33,7 @@ class CJS_Runtime : public IJS_Runtime, public CFXJS_Engine { using FieldEvent = std::pair; static CJS_Runtime* FromContext(const IJS_Context* cc); + static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); explicit CJS_Runtime(CPDFDoc_Environment* pApp); ~CJS_Runtime() override; @@ -43,7 +44,8 @@ class CJS_Runtime : public IJS_Runtime, public CFXJS_Engine { IJS_Context* GetCurrentContext() override; void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override; CPDFSDK_Document* GetReaderDocument() override; - int Execute(const CFX_WideString& script, CFX_WideString* info) override; + int ExecuteScript(const CFX_WideString& script, + CFX_WideString* info) override; CPDFDoc_Environment* GetReaderApp() const { return m_pApp; } @@ -55,12 +57,6 @@ class CJS_Runtime : public IJS_Runtime, public CFXJS_Engine { void EndBlock() { m_bBlocking = FALSE; } FX_BOOL IsBlocking() const { return m_bBlocking; } - v8::Isolate* GetIsolate() const { return m_isolate; } - v8::Local NewJSContext(); - - void SetConstArray(const CFX_WideString& name, v8::Local array); - v8::Local GetConstArray(const CFX_WideString& name); - #ifdef PDF_ENABLE_XFA FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) override; diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index 949c429970..f77d5481dd 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -62,32 +62,24 @@ void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, CJS_Array* array) { switch (color.nColorType) { case COLORTYPE_TRANSPARENT: - array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "T")); + array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "T")); break; case COLORTYPE_GRAY: - array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "G")); - array->SetElement(pRuntime->GetIsolate(), 1, - CJS_Value(pRuntime, color.fColor1)); + array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "G")); + array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); break; case COLORTYPE_RGB: - array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "RGB")); - array->SetElement(pRuntime->GetIsolate(), 1, - CJS_Value(pRuntime, color.fColor1)); - array->SetElement(pRuntime->GetIsolate(), 2, - CJS_Value(pRuntime, color.fColor2)); - array->SetElement(pRuntime->GetIsolate(), 3, - CJS_Value(pRuntime, color.fColor3)); + array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "RGB")); + array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); + array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2)); + array->SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3)); break; case COLORTYPE_CMYK: - array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "CMYK")); - array->SetElement(pRuntime->GetIsolate(), 1, - CJS_Value(pRuntime, color.fColor1)); - array->SetElement(pRuntime->GetIsolate(), 2, - CJS_Value(pRuntime, color.fColor2)); - array->SetElement(pRuntime->GetIsolate(), 3, - CJS_Value(pRuntime, color.fColor3)); - array->SetElement(pRuntime->GetIsolate(), 4, - CJS_Value(pRuntime, color.fColor4)); + array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "CMYK")); + array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); + array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2)); + array->SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3)); + array->SetElement(pRuntime, 4, CJS_Value(pRuntime, color.fColor4)); break; } } @@ -95,13 +87,13 @@ void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, const CJS_Array& array, CPWL_Color* color) { - int nArrayLen = array.GetLength(); + int nArrayLen = array.GetLength(pRuntime); if (nArrayLen < 1) return; CJS_Value value(pRuntime); - array.GetElement(pRuntime->GetIsolate(), 0, value); - CFX_ByteString sSpace = value.ToCFXByteString(pRuntime->GetIsolate()); + array.GetElement(pRuntime, 0, value); + CFX_ByteString sSpace = value.ToCFXByteString(pRuntime); double d1 = 0; double d2 = 0; @@ -109,23 +101,23 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, double d4 = 0; if (nArrayLen > 1) { - array.GetElement(pRuntime->GetIsolate(), 1, value); - d1 = value.ToDouble(pRuntime->GetIsolate()); + array.GetElement(pRuntime, 1, value); + d1 = value.ToDouble(pRuntime); } if (nArrayLen > 2) { - array.GetElement(pRuntime->GetIsolate(), 2, value); - d2 = value.ToDouble(pRuntime->GetIsolate()); + array.GetElement(pRuntime, 2, value); + d2 = value.ToDouble(pRuntime); } if (nArrayLen > 3) { - array.GetElement(pRuntime->GetIsolate(), 3, value); - d3 = value.ToDouble(pRuntime->GetIsolate()); + array.GetElement(pRuntime, 3, value); + d3 = value.ToDouble(pRuntime); } if (nArrayLen > 4) { - array.GetElement(pRuntime->GetIsolate(), 4, value); - d4 = value.ToDouble(pRuntime->GetIsolate()); + array.GetElement(pRuntime, 4, value); + d4 = value.ToDouble(pRuntime); } if (sSpace == "T") { @@ -141,20 +133,20 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, } } -#define JS_IMPLEMENT_COLORPROP(prop, var) \ - FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ - CFX_WideString& sError) { \ - CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \ - CJS_Array array; \ - if (vp.IsGetting()) { \ - ConvertPWLColorToArray(pRuntime, var, &array); \ - vp << array; \ - } else { \ - if (!vp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), array)) \ - return FALSE; \ - ConvertArrayToPWLColor(pRuntime, array, &var); \ - } \ - return TRUE; \ +#define JS_IMPLEMENT_COLORPROP(prop, var) \ + FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ + CFX_WideString& sError) { \ + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \ + CJS_Array array; \ + if (vp.IsGetting()) { \ + ConvertPWLColorToArray(pRuntime, var, &array); \ + vp << array; \ + } else { \ + if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) \ + return FALSE; \ + ConvertArrayToPWLColor(pRuntime, array, &var); \ + } \ + return TRUE; \ } JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) @@ -180,13 +172,13 @@ FX_BOOL color::convert(IJS_Context* cc, CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CJS_Array aSource; - if (!params[0].ConvertToArray(pRuntime->GetIsolate(), aSource)) + if (!params[0].ConvertToArray(pRuntime, aSource)) return FALSE; CPWL_Color crSource; ConvertArrayToPWLColor(pRuntime, aSource, &crSource); - CFX_ByteString sDestSpace = params[1].ToCFXByteString(pRuntime->GetIsolate()); + CFX_ByteString sDestSpace = params[1].ToCFXByteString(pRuntime); int nColorType = COLORTYPE_TRANSPARENT; if (sDestSpace == "T") { @@ -218,9 +210,9 @@ FX_BOOL color::equal(IJS_Context* cc, CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CJS_Array array1; CJS_Array array2; - if (!params[0].ConvertToArray(pRuntime->GetIsolate(), array1)) + if (!params[0].ConvertToArray(pRuntime, array1)) return FALSE; - if (!params[1].ConvertToArray(pRuntime->GetIsolate(), array2)) + if (!params[1].ConvertToArray(pRuntime, array2)) return FALSE; CPWL_Color color1; diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 5ffc5594a6..27c156e527 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -168,11 +168,11 @@ FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, return FALSE; } - auto it = m_mapGlobal.find(params[0].ToCFXByteString(pRuntime->GetIsolate())); + auto it = m_mapGlobal.find(params[0].ToCFXByteString(pRuntime)); if (it != m_mapGlobal.end()) { JSGlobalData* pData = it->second; if (!pData->bDeleted) { - pData->bPersistent = params[1].ToBool(pRuntime->GetIsolate()); + pData->bPersistent = params[1].ToBool(pRuntime); return TRUE; } } @@ -182,6 +182,10 @@ FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, } void JSGlobalAlternate::UpdateGlobalPersistentVariables() { + CJS_Runtime* pRuntime = + static_cast(CFXJS_Engine::CurrentEngineFromIsolate( + m_pJSObject->ToV8Object()->GetIsolate())); + for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); switch (pData->data.nType) { @@ -189,43 +193,41 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::NUMBER, pData->data.dData, false, "", v8::Local(), pData->bPersistent == 1); - FXJS_PutObjectNumber(nullptr, m_pJSObject->ToV8Object(), - pData->data.sKey.UTF8Decode(), pData->data.dData); + pRuntime->PutObjectNumber(m_pJSObject->ToV8Object(), + pData->data.sKey.UTF8Decode(), + pData->data.dData); break; case JS_GlobalDataType::BOOLEAN: SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Local(), pData->bPersistent == 1); - FXJS_PutObjectBoolean(nullptr, m_pJSObject->ToV8Object(), - pData->data.sKey.UTF8Decode(), - (bool)(pData->data.bData == 1)); + pRuntime->PutObjectBoolean(m_pJSObject->ToV8Object(), + pData->data.sKey.UTF8Decode(), + (bool)(pData->data.bData == 1)); break; case JS_GlobalDataType::STRING: SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::STRING, 0, false, pData->data.sData, v8::Local(), pData->bPersistent == 1); - FXJS_PutObjectString(nullptr, m_pJSObject->ToV8Object(), - pData->data.sKey.UTF8Decode(), - pData->data.sData.UTF8Decode()); + pRuntime->PutObjectString(m_pJSObject->ToV8Object(), + pData->data.sKey.UTF8Decode(), + pData->data.sData.UTF8Decode()); break; case JS_GlobalDataType::OBJECT: { - v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); - v8::Local pObj = - FXJS_NewFxDynamicObj(pRuntime, nullptr, -1); + v8::Local pObj = pRuntime->NewFxDynamicObj(-1); PutObjectProperty(pObj, &pData->data); - SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::OBJECT, 0, false, "", pObj, pData->bPersistent == 1); - FXJS_PutObjectObject(nullptr, m_pJSObject->ToV8Object(), - pData->data.sKey.UTF8Decode(), pObj); + pRuntime->PutObjectObject(m_pJSObject->ToV8Object(), + pData->data.sKey.UTF8Decode(), pObj); } break; case JS_GlobalDataType::NULLOBJ: SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::NULLOBJ, 0, false, "", v8::Local(), pData->bPersistent == 1); - FXJS_PutObjectNull(nullptr, m_pJSObject->ToV8Object(), - pData->data.sKey.UTF8Decode()); + pRuntime->PutObjectNull(m_pJSObject->ToV8Object(), + pData->data.sKey.UTF8Decode()); break; } } @@ -271,31 +273,29 @@ void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) { void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, v8::Local pObj, CJS_GlobalVariableArray& array) { - v8::Isolate* isolate = pObj->GetIsolate(); CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - std::vector pKeyList = - FXJS_GetObjectPropertyNames(isolate, pObj); + std::vector pKeyList = pRuntime->GetObjectPropertyNames(pObj); for (const auto& ws : pKeyList) { CFX_ByteString sKey = ws.UTF8Encode(); - v8::Local v = FXJS_GetObjectProperty(isolate, pObj, ws); + v8::Local v = pRuntime->GetObjectProperty(pObj, ws); switch (CJS_Value::GetValueType(v)) { case CJS_Value::VT_number: { CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::NUMBER; pObjElement->sKey = sKey; - pObjElement->dData = FXJS_ToNumber(isolate, v); + pObjElement->dData = pRuntime->ToNumber(v); array.Add(pObjElement); } break; case CJS_Value::VT_boolean: { CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::BOOLEAN; pObjElement->sKey = sKey; - pObjElement->dData = FXJS_ToBoolean(isolate, v); + pObjElement->dData = pRuntime->ToBoolean(v); array.Add(pObjElement); } break; case CJS_Value::VT_string: { CFX_ByteString sValue = - CJS_Value(pRuntime, v).ToCFXByteString(pRuntime->GetIsolate()); + CJS_Value(pRuntime, v).ToCFXByteString(pRuntime); CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::STRING; pObjElement->sKey = sKey; @@ -306,7 +306,7 @@ void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::OBJECT; pObjElement->sKey = sKey; - ObjectToArray(cc, FXJS_ToObject(isolate, v), pObjElement->objData); + ObjectToArray(cc, pRuntime->ToObject(v), pObjElement->objData); array.Add(pObjElement); } break; case CJS_Value::VT_null: { @@ -323,31 +323,31 @@ void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, void JSGlobalAlternate::PutObjectProperty(v8::Local pObj, CJS_KeyValue* pData) { + CJS_Runtime* pRuntime = CJS_Runtime::CurrentRuntimeFromIsolate( + m_pJSObject->ToV8Object()->GetIsolate()); + for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { CJS_KeyValue* pObjData = pData->objData.GetAt(i); switch (pObjData->nType) { case JS_GlobalDataType::NUMBER: - FXJS_PutObjectNumber(nullptr, pObj, pObjData->sKey.UTF8Decode(), - pObjData->dData); + pRuntime->PutObjectNumber(pObj, pObjData->sKey.UTF8Decode(), + pObjData->dData); break; case JS_GlobalDataType::BOOLEAN: - FXJS_PutObjectBoolean(nullptr, pObj, pObjData->sKey.UTF8Decode(), - pObjData->bData == 1); + pRuntime->PutObjectBoolean(pObj, pObjData->sKey.UTF8Decode(), + pObjData->bData == 1); break; case JS_GlobalDataType::STRING: - FXJS_PutObjectString(nullptr, pObj, pObjData->sKey.UTF8Decode(), - pObjData->sData.UTF8Decode()); + pRuntime->PutObjectString(pObj, pObjData->sKey.UTF8Decode(), + pObjData->sData.UTF8Decode()); break; case JS_GlobalDataType::OBJECT: { - v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); - v8::Local pNewObj = - FXJS_NewFxDynamicObj(pRuntime, nullptr, -1); + v8::Local pNewObj = pRuntime->NewFxDynamicObj(-1); PutObjectProperty(pNewObj, pObjData); - FXJS_PutObjectObject(nullptr, pObj, pObjData->sKey.UTF8Decode(), - pNewObj); + pRuntime->PutObjectObject(pObj, pObjData->sKey.UTF8Decode(), pNewObj); } break; case JS_GlobalDataType::NULLOBJ: - FXJS_PutObjectNull(nullptr, pObj, pObjData->sKey.UTF8Decode()); + pRuntime->PutObjectNull(pObj, pObjData->sKey.UTF8Decode()); break; } } diff --git a/fpdfsdk/javascript/ijs_runtime.h b/fpdfsdk/javascript/ijs_runtime.h index cae465a849..3dcfa372de 100644 --- a/fpdfsdk/javascript/ijs_runtime.h +++ b/fpdfsdk/javascript/ijs_runtime.h @@ -31,7 +31,8 @@ class IJS_Runtime { virtual IJS_Context* GetCurrentContext() = 0; virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0; virtual CPDFSDK_Document* GetReaderDocument() = 0; - virtual int Execute(const CFX_WideString& script, CFX_WideString* info) = 0; + virtual int ExecuteScript(const CFX_WideString& script, + CFX_WideString* info) = 0; #ifdef PDF_ENABLE_XFA virtual FX_BOOL GetValueByName(const CFX_ByteStringC& utf8Name, diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index a68d96c9e9..fa53a9e223 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -122,8 +122,7 @@ FX_BOOL util::printf(IJS_Context* cc, int iSize = params.size(); if (iSize < 1) return FALSE; - std::wstring c_ConvChar( - params[0].ToCFXWideString(pRuntime->GetIsolate()).c_str()); + std::wstring c_ConvChar(params[0].ToCFXWideString(pRuntime).c_str()); std::vector c_strConvers; int iOffset = 0; int iOffend = 0; @@ -156,17 +155,15 @@ FX_BOOL util::printf(IJS_Context* cc, switch (ParseDataType(&c_strFormat)) { case UTIL_INT: - strSegment.Format(c_strFormat.c_str(), - params[iIndex].ToInt(pRuntime->GetIsolate())); + strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt(pRuntime)); break; case UTIL_DOUBLE: strSegment.Format(c_strFormat.c_str(), - params[iIndex].ToDouble(pRuntime->GetIsolate())); + params[iIndex].ToDouble(pRuntime)); break; case UTIL_STRING: - strSegment.Format( - c_strFormat.c_str(), - params[iIndex].ToCFXWideString(pRuntime->GetIsolate()).c_str()); + strSegment.Format(c_strFormat.c_str(), + params[iIndex].ToCFXWideString(pRuntime).c_str()); break; default: strSegment.Format(L"%S", c_strFormat.c_str()); @@ -192,45 +189,38 @@ FX_BOOL util::printd(IJS_Context* cc, CJS_Value p1 = params[0]; CJS_Value p2 = params[1]; CJS_Date jsDate; - if (!p2.ConvertToDate(pRuntime->GetIsolate(), jsDate)) { + if (!p2.ConvertToDate(pRuntime, jsDate)) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); return FALSE; } - if (!jsDate.IsValidDate(pRuntime->GetIsolate())) { + if (!jsDate.IsValidDate(pRuntime)) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); return FALSE; } if (p1.GetType() == CJS_Value::VT_number) { CFX_WideString swResult; - switch (p1.ToInt(pRuntime->GetIsolate())) { + switch (p1.ToInt(pRuntime)) { case 0: - swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", - jsDate.GetYear(pRuntime->GetIsolate()), - jsDate.GetMonth(pRuntime->GetIsolate()) + 1, - jsDate.GetDay(pRuntime->GetIsolate()), - jsDate.GetHours(pRuntime->GetIsolate()), - jsDate.GetMinutes(pRuntime->GetIsolate()), - jsDate.GetSeconds(pRuntime->GetIsolate())); + swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", jsDate.GetYear(pRuntime), + jsDate.GetMonth(pRuntime) + 1, jsDate.GetDay(pRuntime), + jsDate.GetHours(pRuntime), jsDate.GetMinutes(pRuntime), + jsDate.GetSeconds(pRuntime)); break; case 1: swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", - jsDate.GetYear(pRuntime->GetIsolate()), - jsDate.GetMonth(pRuntime->GetIsolate()) + 1, - jsDate.GetDay(pRuntime->GetIsolate()), - jsDate.GetHours(pRuntime->GetIsolate()), - jsDate.GetMinutes(pRuntime->GetIsolate()), - jsDate.GetSeconds(pRuntime->GetIsolate())); + jsDate.GetYear(pRuntime), jsDate.GetMonth(pRuntime) + 1, + jsDate.GetDay(pRuntime), jsDate.GetHours(pRuntime), + jsDate.GetMinutes(pRuntime), + jsDate.GetSeconds(pRuntime)); break; case 2: swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", - jsDate.GetYear(pRuntime->GetIsolate()), - jsDate.GetMonth(pRuntime->GetIsolate()) + 1, - jsDate.GetDay(pRuntime->GetIsolate()), - jsDate.GetHours(pRuntime->GetIsolate()), - jsDate.GetMinutes(pRuntime->GetIsolate()), - jsDate.GetSeconds(pRuntime->GetIsolate())); + jsDate.GetYear(pRuntime), jsDate.GetMonth(pRuntime) + 1, + jsDate.GetDay(pRuntime), jsDate.GetHours(pRuntime), + jsDate.GetMinutes(pRuntime), + jsDate.GetSeconds(pRuntime)); break; default: sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSVALUEERROR); @@ -242,15 +232,14 @@ FX_BOOL util::printd(IJS_Context* cc, } if (p1.GetType() == CJS_Value::VT_string) { - if (iSize > 2 && params[2].ToBool(pRuntime->GetIsolate())) { + if (iSize > 2 && params[2].ToBool(pRuntime)) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_NOTSUPPORT); return FALSE; // currently, it doesn't support XFAPicture. } // Convert PDF-style format specifiers to wcsftime specifiers. Remove any // pre-existing %-directives before inserting our own. - std::basic_string cFormat = - p1.ToCFXWideString(pRuntime->GetIsolate()).c_str(); + std::basic_string cFormat = p1.ToCFXWideString(pRuntime).c_str(); cFormat.erase(std::remove(cFormat.begin(), cFormat.end(), '%'), cFormat.end()); @@ -265,12 +254,12 @@ FX_BOOL util::printd(IJS_Context* cc, } } - int iYear = jsDate.GetYear(pRuntime->GetIsolate()); - int iMonth = jsDate.GetMonth(pRuntime->GetIsolate()); - int iDay = jsDate.GetDay(pRuntime->GetIsolate()); - int iHour = jsDate.GetHours(pRuntime->GetIsolate()); - int iMin = jsDate.GetMinutes(pRuntime->GetIsolate()); - int iSec = jsDate.GetSeconds(pRuntime->GetIsolate()); + int iYear = jsDate.GetYear(pRuntime); + int iMonth = jsDate.GetMonth(pRuntime); + int iDay = jsDate.GetDay(pRuntime); + int iHour = jsDate.GetHours(pRuntime); + int iMin = jsDate.GetMinutes(pRuntime); + int iSec = jsDate.GetSeconds(pRuntime); TbConvertAdditional cTableAd[] = { {L"m", iMonth + 1}, {L"d", iDay}, @@ -330,10 +319,9 @@ FX_BOOL util::printx(IJS_Context* cc, return FALSE; } - vRet = CJS_Value(pRuntime, - printx(params[0].ToCFXWideString(pRuntime->GetIsolate()), - params[1].ToCFXWideString(pRuntime->GetIsolate())) - .c_str()); + vRet = CJS_Value(pRuntime, printx(params[0].ToCFXWideString(pRuntime), + params[1].ToCFXWideString(pRuntime)) + .c_str()); return TRUE; } @@ -448,15 +436,15 @@ FX_BOOL util::scand(IJS_Context* cc, if (iSize < 2) return FALSE; - CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); - CFX_WideString sDate = params[1].ToCFXWideString(pRuntime->GetIsolate()); + CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); + CFX_WideString sDate = params[1].ToCFXWideString(pRuntime); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) { dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, nullptr); } if (!JS_PortIsNan(dDate)) { - vRet = CJS_Value(pRuntime, CJS_Date(pRuntime->GetIsolate(), dDate)); + vRet = CJS_Value(pRuntime, CJS_Date(pRuntime, dDate)); } else { vRet.SetNull(pRuntime); } @@ -476,7 +464,7 @@ FX_BOOL util::byteToChar(IJS_Context* cc, return FALSE; } - int arg = params[0].ToInt(pRuntime->GetIsolate()); + int arg = params[0].ToInt(pRuntime); if (arg < 0 || arg > 255) { sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); return FALSE; -- cgit v1.2.3