summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-02-09 19:28:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-09 19:28:39 +0000
commita0395e526d75fbb642e47c3cd8858647627794e0 (patch)
tree6e61f86f5f72da6856cabc7197c21475cf3c188c
parentb7c7df6a979d16d926814f601246234bf65adbc2 (diff)
downloadpdfium-a0395e526d75fbb642e47c3cd8858647627794e0.tar.xz
Tidy V8TemplateMap.
Change-Id: Idcba60bb36c0d47c0d2acb21ddfa3b3b46cdfe49 Reviewed-on: https://pdfium-review.googlesource.com/26170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--fxjs/cfxjs_engine.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp
index c773a16324..dd1f21d84f 100644
--- a/fxjs/cfxjs_engine.cpp
+++ b/fxjs/cfxjs_engine.cpp
@@ -28,8 +28,11 @@ static wchar_t kPerObjectDataTag[] = L"CFXJS_PerObjectData";
// Global weak map to save dynamic objects.
class V8TemplateMapTraits : public v8::StdMapTraits<void*, v8::Object> {
public:
- typedef v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits> MapType;
- typedef void WeakCallbackDataType;
+ using MapType = v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits>;
+ using WeakCallbackDataType = void;
+
+ static const v8::PersistentContainerCallbackType kCallbackType =
+ v8::kWeakWithInternalFields;
static WeakCallbackDataType*
WeakCallbackParameter(MapType* map, void* key, v8::Local<v8::Object> value) {
@@ -37,17 +40,16 @@ class V8TemplateMapTraits : public v8::StdMapTraits<void*, v8::Object> {
}
static MapType* MapFromWeakCallbackInfo(
const v8::WeakCallbackInfo<WeakCallbackDataType>&);
-
static void* KeyFromWeakCallbackInfo(
const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {
return data.GetParameter();
}
- static const v8::PersistentContainerCallbackType kCallbackType =
- v8::kWeakWithInternalFields;
- static void DisposeWeak(
- const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {}
static void OnWeakCallback(
const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {}
+ static void DisposeWeak(
+ const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {
+ // TODO(tsepez): this is expected be called during GC.
+ }
static void Dispose(v8::Isolate* isolate,
v8::Global<v8::Object> value,
void* key);
@@ -56,12 +58,19 @@ class V8TemplateMapTraits : public v8::StdMapTraits<void*, v8::Object> {
class V8TemplateMap {
public:
- typedef v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits> MapType;
+ using MapType = v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits>;
+
+ explicit V8TemplateMap(v8::Isolate* isolate) : m_map(isolate) {}
+ ~V8TemplateMap() = default;
- explicit V8TemplateMap(v8::Isolate* isolate);
- ~V8TemplateMap();
+ void SetAndMakeWeak(void* key, v8::Local<v8::Object> handle) {
+ ASSERT(!m_map.Contains(key));
- void set(void* key, v8::Local<v8::Object> handle);
+ // Inserting an object into a GlobalValueMap with the appropriate traits
+ // has the side-effect of making the object weak deep in the guts of V8,
+ // and arranges for it to be cleaned up by the methods in the traits.
+ m_map.Set(key, handle);
+ }
friend class V8TemplateMapTraits;
@@ -253,15 +262,6 @@ size_t FXJS_GlobalIsolateRefCount() {
return g_isolate_ref_count;
}
-V8TemplateMap::V8TemplateMap(v8::Isolate* isolate) : m_map(isolate) {}
-
-V8TemplateMap::~V8TemplateMap() {}
-
-void V8TemplateMap::set(void* key, v8::Local<v8::Object> handle) {
- ASSERT(!m_map.Contains(key));
- m_map.Set(key, handle);
-}
-
FXJS_PerIsolateData::~FXJS_PerIsolateData() {}
// static
@@ -536,10 +536,11 @@ v8::Local<v8::Object> CFXJS_Engine::NewFXJSBoundObject(int nObjDefnID,
if (pObjDef->m_pConstructor)
pObjDef->m_pConstructor(this, obj);
- if (!bStatic && FXJS_PerIsolateData::Get(GetIsolate())->m_pDynamicObjsMap)
- FXJS_PerIsolateData::Get(GetIsolate())
- ->m_pDynamicObjsMap->set(pObjData, obj);
-
+ if (!bStatic) {
+ auto* pIsolateData = FXJS_PerIsolateData::Get(GetIsolate());
+ if (pIsolateData->m_pDynamicObjsMap)
+ pIsolateData->m_pDynamicObjsMap->SetAndMakeWeak(pObjData, obj);
+ }
return obj;
}