dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 1 | // 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> |
| 10 | |
| 11 | CFXJSE_IsolateTracker::CFXJSE_IsolateTracker() {} |
| 12 | |
| 13 | CFXJSE_IsolateTracker::~CFXJSE_IsolateTracker() {} |
| 14 | |
weili | ad589d7 | 2016-08-19 14:09:33 -0700 | [diff] [blame] | 15 | void CFXJSE_IsolateTracker::Append( |
| 16 | v8::Isolate* pIsolate, |
| 17 | std::unique_ptr<v8::ArrayBuffer::Allocator> alloc) { |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 18 | m_OwnedIsolates.push_back(pIsolate); |
weili | ad589d7 | 2016-08-19 14:09:33 -0700 | [diff] [blame] | 19 | m_AllocatorMap[pIsolate] = std::move(alloc); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void CFXJSE_IsolateTracker::Remove( |
| 23 | v8::Isolate* pIsolate, |
| 24 | CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { |
| 25 | auto it = std::find(m_OwnedIsolates.begin(), m_OwnedIsolates.end(), pIsolate); |
| 26 | bool bFound = it != m_OwnedIsolates.end(); |
| 27 | if (bFound) |
| 28 | m_OwnedIsolates.erase(it); |
| 29 | lpfnDisposeCallback(pIsolate, bFound); |
weili | ad589d7 | 2016-08-19 14:09:33 -0700 | [diff] [blame] | 30 | |
| 31 | m_AllocatorMap.erase(pIsolate); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void CFXJSE_IsolateTracker::RemoveAll( |
| 35 | CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { |
| 36 | for (v8::Isolate* pIsolate : m_OwnedIsolates) |
| 37 | lpfnDisposeCallback(pIsolate, true); |
| 38 | |
| 39 | m_OwnedIsolates.clear(); |
weili | ad589d7 | 2016-08-19 14:09:33 -0700 | [diff] [blame] | 40 | m_AllocatorMap.clear(); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 41 | } |