-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv8_v8context.h
More file actions
146 lines (99 loc) · 4.28 KB
/
Copy pathv8_v8context.h
File metadata and controls
146 lines (99 loc) · 4.28 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: metagoto <runpac314 gmail com> |
+----------------------------------------------------------------------+
*/
#ifndef V8_V8CONTEXT_H
#define V8_V8CONTEXT_H
#include <list>
#include <functional>
#include <algorithm>
#include <v8.h>
#include "php_v8.h"
#include "v8_xref.h"
struct v8context;
struct reg_class_pack
{
reg_class_pack(zend_class_entry* ce, v8context* context)
: ce(ce)
, context(context)
{}
zend_class_entry* ce;
v8context* context;
};
struct v8context
{
v8context();
~v8context();
v8::Handle<v8::Value> run(const char* src, const int len);
void set(const char* name, const int name_len, v8::Handle<v8::Value> value);
v8::Handle<v8::Value> get(const char* name, const int name_len) const;
bool has(const char* name, const int name_len) const;
bool unset(const char* name, const int name_len);
void register_func(const char* name, const int name_len, const zend_fcall_info& fci, const zend_fcall_info_cache& fcc);
void register_class(const char* name, const int name_len, zend_class_entry* ce);
v8::Handle<v8::Value> getter(v8::Local<v8::String> name, const v8::AccessorInfo& args, ze_obj* zeo);
v8::Handle<v8::Value> setter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& args, ze_obj* zeo);
static v8::Handle<v8::Value> func_callback(const v8::Arguments& args);
static v8::Handle<v8::Value> ctor_callback(const v8::Arguments& args);
static v8::Handle<v8::Value> interceptor_get(v8::Local<v8::String> name, const v8::AccessorInfo& args)
{
ze_obj* zeo = static_cast<ze_obj*>(v8::Handle<v8::External>::Cast(args.This()->GetInternalField(0))->Value());
return zeo->context->getter(name, args, zeo);
}
static v8::Handle<v8::Value> interceptor_set(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& args){
ze_obj* zeo = static_cast<ze_obj*>(v8::Handle<v8::External>::Cast(args.This()->GetInternalField(0))->Value());
return zeo->context->setter(name, value, args, zeo);
}
//static void release(v8::Persistent<v8::Value> val, void* parameter);
const v8::Persistent<v8::Context>& get_context() const;
void register_ze_obj(v8::Handle<v8::Object> obj, zval* val TSRMLS_DC);
struct del_fcall_info : public std::unary_function<void, fcall_info*>
{
void operator()(fcall_info* fc) {
if (fc->fci.function_name) {
zval_ptr_dtor(&fc->fci.function_name);
}
delete fc;
}
};
struct del_ze_obj : public std::unary_function<void, ze_obj*>
{
void operator()(ze_obj* zeo) {
if (zeo->obj) {
zval_ptr_dtor(&zeo->obj);
}
delete zeo;
}
};
struct ze_obj_zval_pred : public std::unary_function<bool, ze_obj*>
{
ze_obj_zval_pred(zval* val)
: val(val)
{}
bool operator()(ze_obj* zeo) const
{
return zeo->obj == val;
}
zval* val;
};
private:
v8::Persistent<v8::Context> context;
typedef std::list<fcall_info*> fcall_list_t;
fcall_list_t fcall_list;
typedef std::list<ze_obj*> ze_obj_list_t;
ze_obj_list_t ze_obj_list;
};
#endif // V8_V8CONTEXT_H