summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorJochen Eisinger <jochen@chromium.org>2015-05-14 02:00:44 +0200
committerJochen Eisinger <jochen@chromium.org>2015-05-14 02:00:44 +0200
commit1b8a296b5d1fdd7f6d7daa099f7feef869e05e5e (patch)
treeb5abbe51992f6925bc9c3978d5444910e516c2ba /fpdfsdk/src/javascript
parent8aa1eac606d8e5030de6509f5d5d66e90db521f4 (diff)
downloadpdfium-1b8a296b5d1fdd7f6d7daa099f7feef869e05e5e.tar.xz
Use phantom handles instead of weak handles
Phantom handles allow for freeing objects with one pass of GC. However, this means that by the time the callback is invoked, the v8 object already does no longer exist. To avoid accidential access to the dead object, there are now two callbacks, where the first must only reset the handle, and the second does the clean-up work. R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1129253004
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 6c0c868e4c..66fd2b682f 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -88,16 +88,19 @@ void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
}
/* --------------------------------- CJS_Object --------------------------------- */
-void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
+void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
{
CJS_Object* pJSObj = data.GetParameter();
- if(pJSObj)
- {
- pJSObj->ExitInstance();
- delete pJSObj;
- }
- v8::Local<v8::Object> obj = data.GetValue();
- JS_FreePrivate(obj);
+ pJSObj->ExitInstance();
+ delete pJSObj;
+ JS_FreePrivate(data.GetInternalField(0));
+}
+
+void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
+{
+ CJS_Object* pJSObj = data.GetParameter();
+ pJSObj->Dispose();
+ data.SetSecondPassCallback(FreeObject);
}
CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
@@ -117,7 +120,13 @@ CJS_Object::~CJS_Object(void)
void CJS_Object::MakeWeak()
{
- m_pObject.SetWeak(this, FreeObject);
+ m_pObject.SetWeak(
+ this, DisposeObject, v8::WeakCallbackType::kInternalFields);
+}
+
+void CJS_Object::Dispose()
+{
+ m_pObject.Reset();
}
CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)