From db8ef922e8f45fec00470e6234d9ba65e9be9537 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 13 Feb 2018 18:23:28 +0000 Subject: Use actual type in place of void* in V8 map Add an override so we can comment about the need for it someday. Change-Id: I344c6fd7a635aeab030f0e769bd03a86406ffdd8 Reviewed-on: https://pdfium-review.googlesource.com/26310 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fxjs/cfxjs_engine.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp index dd1f21d84f..927d4a7b0a 100644 --- a/fxjs/cfxjs_engine.cpp +++ b/fxjs/cfxjs_engine.cpp @@ -13,6 +13,8 @@ #include "fxjs/cfxjse_runtimedata.h" #include "fxjs/cjs_object.h" +class CFXJS_PerObjectData; + // Keep this consistent with the values defined in gin/public/context_holder.h // (without actually requiring a dependency on gin itself for the standalone // embedders of PDFIum). The value we want to use is: @@ -26,44 +28,48 @@ static v8::Global* g_DefaultGlobalObjectTemplate = nullptr; static wchar_t kPerObjectDataTag[] = L"CFXJS_PerObjectData"; // Global weak map to save dynamic objects. -class V8TemplateMapTraits : public v8::StdMapTraits { +class V8TemplateMapTraits + : public v8::StdMapTraits { public: - using MapType = v8::GlobalValueMap; - using WeakCallbackDataType = void; + using WeakCallbackDataType = CFXJS_PerObjectData; + using MapType = v8:: + GlobalValueMap; static const v8::PersistentContainerCallbackType kCallbackType = v8::kWeakWithInternalFields; - static WeakCallbackDataType* - WeakCallbackParameter(MapType* map, void* key, v8::Local value) { + static WeakCallbackDataType* WeakCallbackParameter( + MapType* map, + WeakCallbackDataType* key, + v8::Local value) { return key; } static MapType* MapFromWeakCallbackInfo( const v8::WeakCallbackInfo&); - static void* KeyFromWeakCallbackInfo( + static WeakCallbackDataType* KeyFromWeakCallbackInfo( const v8::WeakCallbackInfo& data) { return data.GetParameter(); } static void OnWeakCallback( const v8::WeakCallbackInfo& data) {} static void DisposeWeak( - const v8::WeakCallbackInfo& data) { - // TODO(tsepez): this is expected be called during GC. - } + const v8::WeakCallbackInfo& data); static void Dispose(v8::Isolate* isolate, v8::Global value, - void* key); + WeakCallbackDataType* key); static void DisposeCallbackData(WeakCallbackDataType* callbackData) {} }; class V8TemplateMap { public: - using MapType = v8::GlobalValueMap; + using WeakCallbackDataType = CFXJS_PerObjectData; + using MapType = v8:: + GlobalValueMap; explicit V8TemplateMap(v8::Isolate* isolate) : m_map(isolate) {} ~V8TemplateMap() = default; - void SetAndMakeWeak(void* key, v8::Local handle) { + void SetAndMakeWeak(WeakCallbackDataType* key, v8::Local handle) { ASSERT(!m_map.Contains(key)); // Inserting an object into a GlobalValueMap with the appropriate traits @@ -202,7 +208,7 @@ static v8::Local GetGlobalObjectTemplate( void V8TemplateMapTraits::Dispose(v8::Isolate* isolate, v8::Global value, - void* key) { + WeakCallbackDataType* key) { v8::Local obj = value.Get(isolate); if (obj.IsEmpty()) return; @@ -217,10 +223,15 @@ void V8TemplateMapTraits::Dispose(v8::Isolate* isolate, CFXJS_Engine::FreeObjectPrivate(obj); } +void V8TemplateMapTraits::DisposeWeak( + const v8::WeakCallbackInfo& data) { + // TODO(tsepez): this is expected be called during GC. +} + V8TemplateMapTraits::MapType* V8TemplateMapTraits::MapFromWeakCallbackInfo( const v8::WeakCallbackInfo& data) { V8TemplateMap* pMap = - (FXJS_PerIsolateData::Get(data.GetIsolate()))->m_pDynamicObjsMap.get(); + FXJS_PerIsolateData::Get(data.GetIsolate())->m_pDynamicObjsMap.get(); return pMap ? &pMap->m_map : nullptr; } -- cgit v1.2.3