OLD | NEW |
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 "fpdfsdk/javascript/JS_Object.h" | 7 #include "fpdfsdk/javascript/JS_Object.h" |
8 | 8 |
9 #include "fpdfsdk/javascript/JS_Define.h" | 9 #include "fpdfsdk/javascript/JS_Define.h" |
10 #include "fpdfsdk/javascript/cjs_context.h" | 10 #include "fpdfsdk/javascript/cjs_context.h" |
11 | 11 |
12 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} | 12 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} |
13 | 13 |
14 CJS_EmbedObj::~CJS_EmbedObj() { | 14 CJS_EmbedObj::~CJS_EmbedObj() { |
15 } | 15 } |
16 | 16 |
17 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { | 17 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { |
18 CJS_Object* pJSObj = data.GetParameter(); | 18 CJS_Object* pJSObj = data.GetParameter(); |
19 pJSObj->ExitInstance(); | |
20 delete pJSObj; | 19 delete pJSObj; |
21 CFXJS_Engine::FreeObjectPrivate(data.GetInternalField(0)); | 20 CFXJS_Engine::FreeObjectPrivate(data.GetInternalField(0)); |
22 } | 21 } |
23 | 22 |
24 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { | 23 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { |
25 CJS_Object* pJSObj = data.GetParameter(); | 24 CJS_Object* pJSObj = data.GetParameter(); |
26 pJSObj->Dispose(); | 25 pJSObj->Dispose(); |
27 data.SetSecondPassCallback(FreeObject); | 26 data.SetSecondPassCallback(FreeObject); |
28 } | 27 } |
29 | 28 |
30 CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) { | 29 CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) { |
31 m_pIsolate = pObject->GetIsolate(); | 30 m_pIsolate = pObject->GetIsolate(); |
32 m_pV8Object.Reset(m_pIsolate, pObject); | 31 m_pV8Object.Reset(m_pIsolate, pObject); |
33 } | 32 } |
34 | 33 |
35 CJS_Object::~CJS_Object() {} | 34 CJS_Object::~CJS_Object() {} |
36 | 35 |
37 void CJS_Object::MakeWeak() { | 36 void CJS_Object::MakeWeak() { |
38 m_pV8Object.SetWeak(this, DisposeObject, | 37 m_pV8Object.SetWeak(this, DisposeObject, |
39 v8::WeakCallbackType::kInternalFields); | 38 v8::WeakCallbackType::kInternalFields); |
40 } | 39 } |
41 | 40 |
42 void CJS_Object::Dispose() { | 41 void CJS_Object::Dispose() { |
43 m_pV8Object.Reset(); | 42 m_pV8Object.Reset(); |
44 } | 43 } |
45 | 44 |
46 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} | 45 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} |
47 | |
48 void CJS_Object::ExitInstance() {} | |
OLD | NEW |