blob: 5340d9b5c0a62d336e9778692ae82e05bd104444 [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#ifndef FXJS_CFXJSE_ISOLATETRACKER_H_
8#define FXJS_CFXJSE_ISOLATETRACKER_H_
9
weiliad589d72016-08-19 14:09:33 -070010#include <map>
11#include <memory>
dsinclair08fea802016-07-12 10:37:52 -070012#include <vector>
13
14#include "v8/include/v8.h"
15
16#include "fxjs/cfxjse_runtimedata.h"
17
18class CFXJSE_ScopeUtil_IsolateHandle {
19 public:
20 explicit CFXJSE_ScopeUtil_IsolateHandle(v8::Isolate* pIsolate)
21 : m_isolate(pIsolate), m_iscope(pIsolate), m_hscope(pIsolate) {}
22 v8::Isolate* GetIsolate() { return m_isolate; }
23
24 private:
25 CFXJSE_ScopeUtil_IsolateHandle(const CFXJSE_ScopeUtil_IsolateHandle&) =
26 delete;
27 void operator=(const CFXJSE_ScopeUtil_IsolateHandle&) = delete;
28 void* operator new(size_t size) = delete;
29 void operator delete(void*, size_t) = delete;
30
31 v8::Isolate* m_isolate;
32 v8::Isolate::Scope m_iscope;
33 v8::HandleScope m_hscope;
34};
35
36class CFXJSE_ScopeUtil_IsolateHandleRootContext {
37 public:
38 explicit CFXJSE_ScopeUtil_IsolateHandleRootContext(v8::Isolate* pIsolate)
39 : m_parent(pIsolate),
40 m_cscope(v8::Local<v8::Context>::New(
41 pIsolate,
42 CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext)) {}
43
44 private:
45 CFXJSE_ScopeUtil_IsolateHandleRootContext(
46 const CFXJSE_ScopeUtil_IsolateHandleRootContext&) = delete;
47 void operator=(const CFXJSE_ScopeUtil_IsolateHandleRootContext&) = delete;
48 void* operator new(size_t size) = delete;
49 void operator delete(void*, size_t) = delete;
50
51 CFXJSE_ScopeUtil_IsolateHandle m_parent;
52 v8::Context::Scope m_cscope;
53};
54
55class CFXJSE_IsolateTracker {
56 public:
57 typedef void (*DisposeCallback)(v8::Isolate*, bool bOwnedIsolate);
58
59 CFXJSE_IsolateTracker();
60 ~CFXJSE_IsolateTracker();
61
weiliad589d72016-08-19 14:09:33 -070062 void Append(v8::Isolate* pIsolate,
63 std::unique_ptr<v8::ArrayBuffer::Allocator> alloc);
dsinclair08fea802016-07-12 10:37:52 -070064 void Remove(v8::Isolate* pIsolate, DisposeCallback lpfnDisposeCallback);
65 void RemoveAll(DisposeCallback lpfnDisposeCallback);
66
67 static CFXJSE_IsolateTracker* g_pInstance;
68
69 protected:
70 std::vector<v8::Isolate*> m_OwnedIsolates;
weiliad589d72016-08-19 14:09:33 -070071 std::map<v8::Isolate*, std::unique_ptr<v8::ArrayBuffer::Allocator>>
72 m_AllocatorMap;
dsinclair08fea802016-07-12 10:37:52 -070073};
74
75#endif // FXJS_CFXJSE_ISOLATETRACKER_H_