From 848a13b6777cbff8cc4aea3ab3d69eaa0b82ae6c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 9 Oct 2015 13:14:47 -0700 Subject: Pass IJS_Runtime, not IJS_Context, to native object constructors. This better separates the two IJS_ classes, with the IJS_Context taking on its proper role of describing an event. There's no need for the event details for object creation, so this gets much cleaner. Move some JS error reporting code from CJS_Context to CJS_Runtime. Make InitInstance() and ExitInstance() voids, they always return TRUE and we never check the result anyways. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1389163007 . --- fpdfsdk/src/javascript/Document.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'fpdfsdk/src/javascript/Document.cpp') diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 7c1f5775d2..24f55b03f9 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -140,17 +140,12 @@ END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_Document, Document) -FX_BOOL CJS_Document::InitInstance(IJS_Context* cc) { - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - - Document* pDoc = (Document*)GetEmbedObject(); - ASSERT(pDoc != NULL); - - pDoc->AttachDoc(pContext->GetReaderDocument()); - pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); - return TRUE; -}; +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 --------------------------------- */ @@ -326,7 +321,7 @@ FX_BOOL Document::getField(IJS_Context* cc, CJS_Runtime* pRuntime = pContext->GetJSRuntime(); v8::Local pFieldObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID); + pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); v8::Isolate* isolate = GetIsolate(cc); CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); @@ -835,7 +830,7 @@ 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(), pContext, -1); + FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); @@ -1394,7 +1389,6 @@ FX_BOOL Document::icons(IJS_Context* cc, return TRUE; } - CJS_Context* pContext = static_cast(cc); CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CJS_Array Icons(pRuntime); IconElement* pIconElement = NULL; @@ -1403,7 +1397,7 @@ FX_BOOL Document::icons(IJS_Context* cc, pIconElement = (*m_pIconTree)[i]; v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); + pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); if (pObj.IsEmpty()) return FALSE; @@ -1446,7 +1440,7 @@ FX_BOOL Document::getIcon(IJS_Context* cc, Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; v8::Local pObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID); + pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); if (pObj.IsEmpty()) return FALSE; @@ -1642,7 +1636,7 @@ FX_BOOL Document::getPrintParams(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); v8::Local pRetObj = FXJS_NewFxDynamicObj( - pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID); + pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); // Not implemented yet. -- cgit v1.2.3