FX_BOOL app::activeDocs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return FALSE; CJS_Context* pContext = (CJS_Context*)cc; CPDFDoc_Environment* pApp = pContext->GetReaderApp(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); CJS_Array aDocs(pRuntime); if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { CJS_Document* pJSDocument = NULL; if (pDoc == pCurDoc) { v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) pJSDocument = (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); } else { v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); pJSDocument = (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); ASSERT(pJSDocument); } aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument)); } if (aDocs.GetLength() > 0) vp << aDocs; else vp.SetNull(); return TRUE; }
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<v8::Context> context = v8::Local<v8::Context>::New(m_isolate, m_context); v8::Context::Scope context_scope(context); m_pDocument = pReaderDoc; if (pReaderDoc) { v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); if (!pThis.IsEmpty()) { if (FXJS_GetObjDefnID(pThis) == FXJS_GetObjDefnID(GetIsolate(), L"Document")) { if (CJS_Document* pJSDocument = (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) pDocument->AttachDoc(pReaderDoc); } } } } } }