-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathphp_context.cpp
More file actions
95 lines (83 loc) · 2.25 KB
/
Copy pathphp_context.cpp
File metadata and controls
95 lines (83 loc) · 2.25 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
/**
* PhpContext.cpp
*
* Implementation file for the PhpContext class
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2025 - 2026 Copernica BV
*/
/**
* Dependencies
*/
#include "php_context.h"
#include "php_script.h"
#include "names.h"
/**
* Begin of namespace
*/
namespace JS {
/**
* Constructor
* @param params
*/
void PhpContext::__construct(Php::Parameters ¶ms)
{
// if no parameters were supplied, we stick with the default context
if (params.size() == 0) _core = std::make_shared<Core>();
// the root object was supplied, create a new core
else _core = std::make_shared<Core>(params[0]);
}
/**
* Assign a variable to the javascript context
* @param params array of parameters:
* - string name of property to assign required
* - mixed property value to assign required
* - integer property attributes optional
*
* The property attributes can be one of the following values
*
* - ReadOnly
* - DontEnum
* - DontDelete
*
* If not specified, the property will be writable, enumerable and
* deletable.
*/
Php::Value PhpContext::assign(Php::Parameters ¶ms)
{
// pass on
_core->assign(params[0], params[1], params.size() > 2 ? params[2] : Php::Value(v8::None));
// allow chaining
return this;
}
/**
* Parse a piece of javascript code
*
* @param params array with one parameter: the code to execute
* @return Php::Value
* @throws Php::Exception
*/
Php::Value PhpContext::evaluate(Php::Parameters ¶ms)
{
// pass on
return _core->evaluate(params[0], params.size() > 1 ? params[1] : Php::Value(0));
}
/**
* Parse a piece of javascript code for multi-use, returns a JS\Script
* @param params array with one parameter: the code to execute
* @return Php::Value
* @throws Php::Exception
*/
Php::Value PhpContext::parse(Php::Parameters ¶ms)
{
// first parameter must the source
Php::Value source = params[0];
// construct a script (can throw)
auto *script = new PhpScript(_core, source.clone(Php::Type::String).rawValue());
// wrap in user space object
return Php::Object(Names::Script, script);
}
/**
* End of namespace
*/
}