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

Side by Side Diff: fxjs/cfxjse_runtimedata.cpp

Issue 2354923003: Fix leaks related to the usage of JSE runtime data (Closed)
Patch Set: Created 4 years, 3 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 | « fxjs/cfxjse_runtimedata.h ('k') | fxjs/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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "fxjs/cfxjse_runtimedata.h" 7 #include "fxjs/cfxjse_runtimedata.h"
8 8
9 #include "fxjs/cfxjse_isolatetracker.h" 9 #include "fxjs/cfxjse_isolatetracker.h"
10 #include "fxjs/include/fxjs_v8.h" 10 #include "fxjs/include/fxjs_v8.h"
11 11
12 namespace { 12 namespace {
13 13
14 // Duplicates fpdfsdk's cjs_runtime.h, but keeps XFA from depending on it. 14 // Duplicates fpdfsdk's cjs_runtime.h, but keeps XFA from depending on it.
15 // TODO(tsepez): make a single version of this. 15 // TODO(tsepez): make a single version of this.
16 class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 16 class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
17 void* Allocate(size_t length) override { return calloc(1, length); } 17 void* Allocate(size_t length) override { return calloc(1, length); }
18 void* AllocateUninitialized(size_t length) override { return malloc(length); } 18 void* AllocateUninitialized(size_t length) override { return malloc(length); }
19 void Free(void* data, size_t length) override { free(data); } 19 void Free(void* data, size_t length) override { free(data); }
20 }; 20 };
21 21
22 void Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) { 22 void Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) {
23 if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) { 23 if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate))
24 delete pData->m_pFXJSERuntimeData; 24 delete pData;
25 pData->m_pFXJSERuntimeData = nullptr;
26 }
27 if (bOwned) 25 if (bOwned)
28 pIsolate->Dispose(); 26 pIsolate->Dispose();
29 } 27 }
30 28
31 void KillV8() { 29 void KillV8() {
32 v8::V8::Dispose(); 30 v8::V8::Dispose();
33 } 31 }
34 32
35 } // namespace 33 } // namespace
36 34
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (!pIsolate) 68 if (!pIsolate)
71 return; 69 return;
72 CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, Runtime_DisposeCallback); 70 CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, Runtime_DisposeCallback);
73 } 71 }
74 72
75 CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate) 73 CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate)
76 : m_pIsolate(pIsolate) {} 74 : m_pIsolate(pIsolate) {}
77 75
78 CFXJSE_RuntimeData::~CFXJSE_RuntimeData() {} 76 CFXJSE_RuntimeData::~CFXJSE_RuntimeData() {}
79 77
80 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { 78 std::unique_ptr<CFXJSE_RuntimeData> CFXJSE_RuntimeData::Create(
81 CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); 79 v8::Isolate* pIsolate) {
80 std::unique_ptr<CFXJSE_RuntimeData> pRuntimeData(
81 new CFXJSE_RuntimeData(pIsolate));
82 CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); 82 CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
83 v8::Local<v8::FunctionTemplate> hFuncTemplate = 83 v8::Local<v8::FunctionTemplate> hFuncTemplate =
84 v8::FunctionTemplate::New(pIsolate); 84 v8::FunctionTemplate::New(pIsolate);
85 v8::Local<v8::ObjectTemplate> hGlobalTemplate = 85 v8::Local<v8::ObjectTemplate> hGlobalTemplate =
86 hFuncTemplate->InstanceTemplate(); 86 hFuncTemplate->InstanceTemplate();
87 hGlobalTemplate->Set( 87 hGlobalTemplate->Set(
88 v8::Symbol::GetToStringTag(pIsolate), 88 v8::Symbol::GetToStringTag(pIsolate),
89 v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal) 89 v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal)
90 .ToLocalChecked()); 90 .ToLocalChecked());
91 v8::Local<v8::Context> hContext = 91 v8::Local<v8::Context> hContext =
92 v8::Context::New(pIsolate, 0, hGlobalTemplate); 92 v8::Context::New(pIsolate, 0, hGlobalTemplate);
93 hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate)); 93 hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate));
94 pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate); 94 pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate);
95 pRuntimeData->m_hRootContext.Reset(pIsolate, hContext); 95 pRuntimeData->m_hRootContext.Reset(pIsolate, hContext);
96 return pRuntimeData; 96 return pRuntimeData;
97 } 97 }
98 98
99 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { 99 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) {
100 FXJS_PerIsolateData::SetUp(pIsolate); 100 FXJS_PerIsolateData::SetUp(pIsolate);
101 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); 101 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
102 if (!pData->m_pFXJSERuntimeData) 102 if (!pData->m_pFXJSERuntimeData)
103 pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); 103 pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate);
104 return pData->m_pFXJSERuntimeData; 104 return pData->m_pFXJSERuntimeData.get();
105 } 105 }
106 106
107 CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr; 107 CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr;
OLDNEW
« no previous file with comments | « fxjs/cfxjse_runtimedata.h ('k') | fxjs/fxjs_v8.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698