-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathplatform.cpp
More file actions
80 lines (68 loc) · 1.39 KB
/
platform.cpp
File metadata and controls
80 lines (68 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* NewPlatform.cpp
*
* Implementation file for the NewPlatform class
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2025 Copernica BV
*/
/**
* Dependencies
*/
#include "platform.h"
/**
* Begin of namespace
*/
namespace JS {
/**
* The single one instance
* @var Platform
*/
Platform *Platform::_instance = nullptr;
/**
* Private constructor (as this is a singleton)
*/
Platform::Platform() : _platform(v8::platform::NewSingleThreadedDefaultPlatform())
{
// initialize all platform-stuff
v8::V8::InitializeICUDefaultLocation(nullptr);
v8::V8::InitializeExternalStartupData("/usr/share/v8/");
v8::V8::InitializePlatform(_platform.get());
v8::V8::Initialize();
}
/**
* Destructor
*/
Platform::~Platform()
{
// cleanup stuff
v8::V8::Dispose();
v8::V8::DisposePlatform();
}
/**
* Get the one and only instance
* @return Platform
*/
Platform *Platform::instance()
{
// already set?
if (_instance != nullptr) return _instance;
// cerate the one and only instance right now
return _instance = new Platform();
}
/**
* Cleanup the platform instance
*/
void Platform::shutdown()
{
// if not even initialized
if (_instance == nullptr) return;
// destruct the one and only instance
delete _instance;
// set back to nullptr
_instance = nullptr;
}
/**
* End of namespace
*/
}