Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1407063012: Merge to XFA: Keep "static" objects per-context rather than per isolate. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/jsapi/fxjs_v8.cpp
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 3413d72bb3d0218a98976465ccbe3596f6749d23..f0992896663ae7a4275acf459ddb76d65ed5239b 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -95,7 +95,6 @@ class CFXJS_ObjDefinition {
v8::Isolate* m_pIsolate;
v8::Global<v8::FunctionTemplate> m_FunctionTemplate;
v8::Global<v8::Signature> m_Signature;
- v8::Global<v8::Object> m_StaticObj;
};
static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
@@ -273,9 +272,11 @@ void FXJS_DefineGlobalConst(v8::Isolate* pIsolate,
pDefault, v8::ReadOnly);
}
-void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
- IJS_Runtime* pIRuntime,
- v8::Global<v8::Context>& v8PersistentContext) {
+void FXJS_InitializeRuntime(
+ v8::Isolate* pIsolate,
+ IJS_Runtime* pIRuntime,
+ v8::Global<v8::Context>* pV8PersistentContext,
+ std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
if (pIsolate == g_isolate)
++g_isolate_ref_count;
@@ -290,14 +291,9 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
FXJS_SetRuntimeForV8Context(v8Context, pIRuntime);
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
+ pStaticObjects->resize(maxID + 1);
for (int i = 0; i < maxID; ++i) {
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
- CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
- v8::Local<v8::String> m_ObjName =
- v8::String::NewFromUtf8(pIsolate, bs.c_str(),
- v8::NewStringType::kNormal,
- bs.GetLength()).ToLocalChecked();
-
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
v8Context->Global()
->GetPrototype()
@@ -311,24 +307,28 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
->ToObject(v8Context)
.ToLocalChecked());
} else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) {
+ CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
+ v8::Local<v8::String> m_ObjName =
+ v8::String::NewFromUtf8(pIsolate, bs.c_str(),
+ v8::NewStringType::kNormal,
+ bs.GetLength()).ToLocalChecked();
+
v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, pIRuntime, i);
v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust();
- pObjDef->m_StaticObj.Reset(pIsolate, obj);
+ pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj);
}
}
- v8PersistentContext.Reset(pIsolate, v8Context);
+ pV8PersistentContext->Reset(pIsolate, v8Context);
}
void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
- v8::Global<v8::Context>& v8PersistentContext) {
- if (pIsolate == g_isolate && --g_isolate_ref_count > 0)
- return;
-
+ v8::Global<v8::Context>* pV8PersistentContext,
+ std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::Locker locker(pIsolate);
v8::HandleScope handle_scope(pIsolate);
v8::Local<v8::Context> context =
- v8::Local<v8::Context>::New(pIsolate, v8PersistentContext);
+ v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext);
v8::Context::Scope context_scope(context);
FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
@@ -345,8 +345,10 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
pObj =
context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
- } else if (!pObjDef->m_StaticObj.IsEmpty()) {
- pObj = v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
+ } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) {
+ pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i));
+ delete pStaticObjects->at(i);
+ pStaticObjects->at(i) = nullptr;
}
if (!pObj.IsEmpty()) {
@@ -357,6 +359,9 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
delete pObjDef;
}
+ if (pIsolate == g_isolate && --g_isolate_ref_count > 0)
+ return;
+
pIsolate->SetData(g_embedderDataSlot, nullptr);
delete pData;
}
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698