blob: 0dd4158714067b08dc627d18f663ce53d2996660 [file] [log] [blame]
dsinclair08fea802016-07-12 10:37:52 -07001// Copyright 2016 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/cfxjse_isolatetracker.h"
8
9#include <algorithm>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050010#include <utility>
dsinclair08fea802016-07-12 10:37:52 -070011
12CFXJSE_IsolateTracker::CFXJSE_IsolateTracker() {}
13
14CFXJSE_IsolateTracker::~CFXJSE_IsolateTracker() {}
15
weiliad589d72016-08-19 14:09:33 -070016void CFXJSE_IsolateTracker::Append(
17 v8::Isolate* pIsolate,
18 std::unique_ptr<v8::ArrayBuffer::Allocator> alloc) {
dsinclair08fea802016-07-12 10:37:52 -070019 m_OwnedIsolates.push_back(pIsolate);
weiliad589d72016-08-19 14:09:33 -070020 m_AllocatorMap[pIsolate] = std::move(alloc);
dsinclair08fea802016-07-12 10:37:52 -070021}
22
23void CFXJSE_IsolateTracker::Remove(
24 v8::Isolate* pIsolate,
25 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) {
26 auto it = std::find(m_OwnedIsolates.begin(), m_OwnedIsolates.end(), pIsolate);
27 bool bFound = it != m_OwnedIsolates.end();
28 if (bFound)
29 m_OwnedIsolates.erase(it);
30 lpfnDisposeCallback(pIsolate, bFound);
weiliad589d72016-08-19 14:09:33 -070031
32 m_AllocatorMap.erase(pIsolate);
dsinclair08fea802016-07-12 10:37:52 -070033}
34
35void CFXJSE_IsolateTracker::RemoveAll(
36 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) {
37 for (v8::Isolate* pIsolate : m_OwnedIsolates)
38 lpfnDisposeCallback(pIsolate, true);
39
40 m_OwnedIsolates.clear();
weiliad589d72016-08-19 14:09:33 -070041 m_AllocatorMap.clear();
dsinclair08fea802016-07-12 10:37:52 -070042}