-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcore.h
More file actions
117 lines (101 loc) · 2.59 KB
/
Copy pathcore.h
File metadata and controls
117 lines (101 loc) · 2.59 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Core.h
*
* The main javascript class, used for assigning variables
* and executing javascript
*
* @copyright 2015 - 2026 Copernica B.V.
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <phpcpp.h>
#include "isolate.h"
/**
* Start namespace
*/
namespace JS {
/**
* Class definition
*/
class Core : public std::enable_shared_from_this<Core>
{
private:
/**
* The Isolate that manages the v8 environment (this is a bit like the "window"
* platform in a browser, a fully separated environment)
* @var Isolate
*/
Isolate _isolate;
/**
* The context in which variables are stored
* @var v8::Global<v8::Context>
*/
v8::Global<v8::Context> _context;
public:
/**
* Constructor with a default root
*/
Core();
/**
* Constructor with an alternative root object
* @param root
*/
Core(const Php::Value &root);
/**
* No copying allowed
* @param that the object we cannot copy
*/
Core(const Core &that) = delete;
/**
* Destructor
*/
virtual ~Core() = default;
/**
* Given an isolate, it is possible to upgrade to the full context
* @return std::shared_ptr
*/
static std::shared_ptr<Core> upgrade(v8::Isolate *isolate);
/**
* The isolate of this context
* @return Isolate
*/
v8::Isolate *isolate() { return _isolate; }
/**
* Wrap a certain PHP object into a javascript object
* @param object MUST be an object!
* @return v8::Local<v8::Value>
*/
v8::Local<v8::Value> wrap(const Php::Value &object);
/**
* Expose the context
* Watch out: a handling-scope must be passed to prove that is exists
* @param scope
* @return v8::Local<v8::Context>
*/
v8::Local<v8::Context> context(const v8::HandleScope &scope) { return _context.Get(_isolate); }
/**
* Assign a variable to the javascript context
* @param name name of property to assign required
* @param value value to be assigned
* @param attribytes property attributes
* @return bool
*/
bool assign(const Php::Value &name, const Php::Value &value, const Php::Value &attributes);
/**
* Parse a piece of javascript code
* @param code the code to execute
* @param timeout possible timeout in seconds
* @return Php::Value
* @throws Php::Exception
*/
Php::Value evaluate(const Php::Value &code, const Php::Value &timeout);
};
/**
* End namespace
*/
}