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

Side by Side Diff: fpdfsdk/src/javascript/JS_Object.cpp

Issue 1129253004: Use phantom handles instead of weak handles (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/include/jsapi/fxjs_v8.h ('k') | fpdfsdk/src/jsapi/fxjs_v8.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) 83 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
84 { 84 {
85 ASSERT(pTimer != NULL); 85 ASSERT(pTimer != NULL);
86 pTimer->KillJSTimer(); 86 pTimer->KillJSTimer();
87 delete pTimer; 87 delete pTimer;
88 } 88 }
89 89
90 /* --------------------------------- CJS_Object ------------------------------- -- */ 90 /* --------------------------------- CJS_Object ------------------------------- -- */
91 void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data) 91 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
92 { 92 {
93 CJS_Object* pJSObj = data.GetParameter(); 93 CJS_Object* pJSObj = data.GetParameter();
94 » if(pJSObj) 94 pJSObj->ExitInstance();
95 » { 95 delete pJSObj;
96 » » pJSObj->ExitInstance(); 96 » JS_FreePrivate(data.GetInternalField(0));
97 » » delete pJSObj; 97 }
98 » } 98
99 » v8::Local<v8::Object> obj = data.GetValue(); 99 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data)
100 » JS_FreePrivate(obj); 100 {
101 » CJS_Object* pJSObj = data.GetParameter();
102 pJSObj->Dispose();
103 data.SetSecondPassCallback(FreeObject);
101 } 104 }
102 105
103 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) 106 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
104 { 107 {
105 v8::Local<v8::Context> context = pObject->CreationContext(); 108 v8::Local<v8::Context> context = pObject->CreationContext();
106 m_pIsolate = context->GetIsolate(); 109 m_pIsolate = context->GetIsolate();
107 m_pObject.Reset(m_pIsolate, pObject); 110 m_pObject.Reset(m_pIsolate, pObject);
108 }; 111 };
109 112
110 CJS_Object::~CJS_Object(void) 113 CJS_Object::~CJS_Object(void)
111 { 114 {
112 delete m_pEmbedObj; 115 delete m_pEmbedObj;
113 m_pEmbedObj = NULL; 116 m_pEmbedObj = NULL;
114 117
115 m_pObject.Reset(); 118 m_pObject.Reset();
116 }; 119 };
117 120
118 void CJS_Object::MakeWeak() 121 void CJS_Object::MakeWeak()
119 { 122 {
120 » m_pObject.SetWeak(this, FreeObject); 123 » m_pObject.SetWeak(
124 this, DisposeObject, v8::WeakCallbackType::kInternalFields);
125 }
126
127 void CJS_Object::Dispose()
128 {
129 m_pObject.Reset();
121 } 130 }
122 131
123 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) 132 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
124 { 133 {
125 return FXJS_GetPageView(cc); 134 return FXJS_GetPageView(cc);
126 } 135 }
127 136
128 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, F X_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon) 137 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, F X_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
129 { 138 {
130 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); 139 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
131 } 140 }
132 141
133 void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg) 142 void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
134 { 143 {
135 ASSERT(pContext != NULL); 144 ASSERT(pContext != NULL);
136 145
137 if (pContext->IsMsgBoxEnabled()) 146 if (pContext->IsMsgBoxEnabled())
138 { 147 {
139 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 148 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
140 if(pApp) 149 if(pApp)
141 pApp->JS_appAlert(swMsg, NULL, 0, 3); 150 pApp->JS_appAlert(swMsg, NULL, 0, 3);
142 } 151 }
143 } 152 }
144 153
145 154
OLDNEW
« no previous file with comments | « fpdfsdk/include/jsapi/fxjs_v8.h ('k') | fpdfsdk/src/jsapi/fxjs_v8.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698