summaryrefslogtreecommitdiff
path: root/fxjs/cfxjs_engine.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-02-13 18:23:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-13 18:23:28 +0000
commitdb8ef922e8f45fec00470e6234d9ba65e9be9537 (patch)
treed24990328c61547665bc7dd4cdd6e88016b4eb36 /fxjs/cfxjs_engine.cpp
parent0294f3d06517265a3b63ec3238b32f77d92a71bf (diff)
downloadpdfium-db8ef922e8f45fec00470e6234d9ba65e9be9537.tar.xz
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 <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cfxjs_engine.cpp')
-rw-r--r--fxjs/cfxjs_engine.cpp39
1 files 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<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr;
static wchar_t kPerObjectDataTag[] = L"CFXJS_PerObjectData";
// Global weak map to save dynamic objects.
-class V8TemplateMapTraits : public v8::StdMapTraits<void*, v8::Object> {
+class V8TemplateMapTraits
+ : public v8::StdMapTraits<CFXJS_PerObjectData*, v8::Object> {
public:
- using MapType = v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits>;
- using WeakCallbackDataType = void;
+ using WeakCallbackDataType = CFXJS_PerObjectData;
+ using MapType = v8::
+ GlobalValueMap<WeakCallbackDataType*, v8::Object, V8TemplateMapTraits>;
static const v8::PersistentContainerCallbackType kCallbackType =
v8::kWeakWithInternalFields;
- static WeakCallbackDataType*
- WeakCallbackParameter(MapType* map, void* key, v8::Local<v8::Object> value) {
+ static WeakCallbackDataType* WeakCallbackParameter(
+ MapType* map,
+ WeakCallbackDataType* key,
+ v8::Local<v8::Object> value) {
return key;
}
static MapType* MapFromWeakCallbackInfo(
const v8::WeakCallbackInfo<WeakCallbackDataType>&);
- static void* KeyFromWeakCallbackInfo(
+ static WeakCallbackDataType* KeyFromWeakCallbackInfo(
const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {
return data.GetParameter();
}
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.
- }
+ const v8::WeakCallbackInfo<WeakCallbackDataType>& data);
static void Dispose(v8::Isolate* isolate,
v8::Global<v8::Object> value,
- void* key);
+ WeakCallbackDataType* key);
static void DisposeCallbackData(WeakCallbackDataType* callbackData) {}
};
class V8TemplateMap {
public:
- using MapType = v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits>;
+ using WeakCallbackDataType = CFXJS_PerObjectData;
+ using MapType = v8::
+ GlobalValueMap<WeakCallbackDataType*, v8::Object, V8TemplateMapTraits>;
explicit V8TemplateMap(v8::Isolate* isolate) : m_map(isolate) {}
~V8TemplateMap() = default;
- void SetAndMakeWeak(void* key, v8::Local<v8::Object> handle) {
+ void SetAndMakeWeak(WeakCallbackDataType* key, v8::Local<v8::Object> handle) {
ASSERT(!m_map.Contains(key));
// Inserting an object into a GlobalValueMap with the appropriate traits
@@ -202,7 +208,7 @@ static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
void V8TemplateMapTraits::Dispose(v8::Isolate* isolate,
v8::Global<v8::Object> value,
- void* key) {
+ WeakCallbackDataType* key) {
v8::Local<v8::Object> 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<WeakCallbackDataType>& data) {
+ // TODO(tsepez): this is expected be called during GC.
+}
+
V8TemplateMapTraits::MapType* V8TemplateMapTraits::MapFromWeakCallbackInfo(
const v8::WeakCallbackInfo<WeakCallbackDataType>& 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;
}