CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), m_bBlocking(false), m_isolateManaged(false) { v8::Isolate* pIsolate = nullptr; IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&pIsolate); SetIsolate(pIsolate); #ifdef PDF_ENABLE_XFA v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); IJS_EventContext* pContext = NewEventContext(); InitializeEngine(); ReleaseEventContext(pContext); SetFormFillEnvToDocument(); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(nullptr), m_bBlocking(FALSE), m_isolate(nullptr), m_isolateManaged(false) { #ifndef PDF_ENABLE_XFA IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); #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(); } else { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); } v8::Isolate* isolate = m_isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); return; } #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); #ifdef PDF_ENABLE_XFA CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); #endif CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }