-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathscope.h
More file actions
101 lines (86 loc) · 1.82 KB
/
Copy pathscope.h
File metadata and controls
101 lines (86 loc) · 1.82 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Scope.h
*
* Utility class to set up the handle scope based on a Context. This
* class make sure we do not have to repeat the same code over and over
* again.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2025 - 2026 Copernica BV
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include "core.h"
/**
* Begin of namespace
*/
namespace JS {
/**
* Class definition
*/
class Scope
{
private:
/**
* Scope for the isolate
* @var v8::Isolate::Scope
*/
v8::Isolate::Scope _iscope;
/**
* Stack-allocated handle scope
* @var v8::HandleScope
*/
v8::HandleScope _hscope;
/**
* We need the context in a local handle
* @var v8::Local<v8::Context>
*/
v8::Local<v8::Context> _context;
/**
* Enter the context for this call
* @var v8::Context::Scope
*/
v8::Context::Scope _cscope;
public:
/**
* Constructor
* @param context
*/
Scope(const std::shared_ptr<Core> &context) :
_iscope(context->isolate()),
_hscope(context->isolate()),
_context(context->context(_hscope)),
_cscope(_context) {}
/**
* Constructor
* @param isolate
*/
Scope(v8::Isolate *isolate) :
_iscope(isolate),
_hscope(isolate),
_context(isolate->GetCurrentContext()),
_cscope(_context) {}
/**
* Destructor
*/
virtual ~Scope() = default;
/**
* Cast to the context
* @return v8::Local<v8::Context>
*/
operator v8::Local<v8::Context>& () { return _context; }
/**
* Get the global object
* @return v8::Local<v8::Object>
*/
v8::Local<v8::Object> global() const { return _context->Global(); }
};
/**
* End of namespace
*/
}