From a282c7380f3964de41ea93c9980b12c4513d3473 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 13 Oct 2016 12:14:34 -0700 Subject: Revert of Reland: Make the CPDFXFA_App non-global (patchset #2 id:20001 of https://codereview.chromium.org/2418653003/ ) Reason for revert: https://build.chromium.org/p/client.pdfium/builders/linux_xfa_asan_lsan/builds/117/steps/corpus%20tests/logs/stdio Original issue's description: > Reland: Make the CPDFXFA_App non-global > > This reverts commit b685e6471075bebd26711bc183de3128f54932e3. > > This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. > > BUG=pdfium:623 > > Committed: https://pdfium.googlesource.com/pdfium/+/f3736bca5f874b0889c5906ffbd74a405089f671 TBR=tsepez@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2414883006 --- fpdfsdk/javascript/cjs_runtime.cpp | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'fpdfsdk/javascript') diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index 637fa0a411..d41726b315 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -68,7 +68,7 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) m_bBlocking(false), m_isolateManaged(false) { v8::Isolate* pIsolate = nullptr; - +#ifndef PDF_ENABLE_XFA IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; @@ -81,15 +81,44 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) } m_isolateManaged = FXJS_GetIsolate(&pIsolate); SetIsolate(pIsolate); +#else + if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { + // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. + pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime(); + SetIsolate(pIsolate); + } else { + 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(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); + if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { + CJS_Context* pContext = (CJS_Context*)NewContext(); + InitializeEngine(); + 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(); InitializeEngine(); ReleaseContext(pContext); @@ -232,9 +261,19 @@ 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 = NewLocalContext(); v8::Context::Scope context_scope(context); + // Caution: We're about to hand to XFA an object that in order to invoke + // methods will require that the current v8::Context always has a pointer + // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates + // its own v8::Context which has not initialized the embedder data slot. + // 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. + CFXJS_Engine::SetForV8Context(old_context, this); + v8::Local propvalue = context->Global()->Get(v8::String::NewFromUtf8( GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); -- cgit v1.2.3