forked from crodas/PHPJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_phpjs.h
111 lines (86 loc) · 3.81 KB
/
php_phpjs.h
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
/* This code was generated by phptoc.php */
#ifndef PHP_PHPJS_H
#define PHP_PHPJS_H
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend.h"
#include "zend_API.h"
#include "zend_exceptions.h"
#include "zend_operators.h"
#include "zend_constants.h"
#include "zend_ini.h"
#include "zend_interfaces.h"
#define _S(str) str, sizeof(str) - 1
extern zend_module_entry phpjs_module_entry;
#define phpext_phpjs_ptr &phpjs_module_entry
typedef struct {
zend_object zo;
duk_context * ctx;
zval * vm;
duk_idx_t idx;
} phpjs_wrap_duk_t;
typedef struct {
zval* zval;
duk_context * ctx;
duk_idx_t idx;
} phpjs_object_hanler;
typedef struct {
zend_object zo;
duk_context * ctx;
} php_js_t;
BEGIN_EXTERN_C()
extern PHPAPI zend_class_entry *phpjs_JS_ptr;
extern PHPAPI zend_class_entry *phpjs_JSException_ptr;
extern PHPAPI zend_class_entry *phpjs_JSObjectWrapper_ptr;
extern PHPAPI zend_class_entry *phpjs_JSFunctionWrapper_ptr;
extern PHPAPI zend_class_entry *phpjs_JS_ptr;
extern void duk_to_zval(zval ** var, duk_context * ctx, duk_idx_t idx);
extern void zval_to_duk(duk_context * ctx, char * name, zval * value);
extern duk_idx_t duk_push_php_array_or_object(duk_context * ctx, HashTable * myht);
extern duk_ret_t php_get_function_wrapper(duk_context * ctx);
extern duk_ret_t duk_set_into_php(duk_context * ctx);
extern duk_ret_t duk_get_from_php(duk_context * ctx);
extern void php_register_function_handler(TSRMLS_D);
extern void php_register_object_handler(TSRMLS_D);
extern duk_ret_t php_mod_search_handler(duk_context *ctx);
extern duk_ret_t php_object_handler(duk_context *ctx);
extern duk_ret_t phpjs_obj_has_function(duk_context *ctx);
extern duk_ret_t phpjs_obj_get_function(duk_context *ctx);
extern duk_ret_t phpjs_obj_set_function(duk_context *ctx);
extern duk_ret_t phpjs_obj_delete_function(duk_context *ctx);
extern duk_ret_t phpjs_obj_keys_function(duk_context *ctx);
extern duk_ret_t phpjs_empty_function(duk_context *ctx);
extern void phpjs_wrapped_free(phpjs_wrap_duk_t * obj TSRMLS_DC);
extern void phpjs_add_duk_context(zval * this, duk_context * ctx, duk_idx_t idx TSRMLS_DC);
extern int zval_array_to_stack(duk_context * ctx, zval * a_args);
extern int phpjs_php__call(duk_context * ctx, char * fnc, zval * a_args, zval * return_value TSRMLS_DC);
#define php_duk_free_return(ctx) duk_pop(ctx);
END_EXTERN_C()
#define Z_EXCEPTION_PROP(x) Z_STRVAL_P(zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), x, sizeof(x)-1, 0 TSRMLS_CC))
#define FETCH_THIS_WRAPPER \
phpjs_wrap_duk_t * obj = (phpjs_wrap_duk_t *) zend_object_store_get_object(getThis() TSRMLS_CC ); \
if (!this_ptr || obj->ctx == NULL) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected error. This method cannot be called statically"); \
return; \
} \
duk_context * ctx = obj->ctx;
#define FETCH_THIS_EX(validate) \
zval* object = getThis(); \
php_js_t* obj = NULL; \
obj = (php_js_t *) zend_object_store_get_object( object TSRMLS_CC ); \
if (!this_ptr || (validate && (!instanceof_function(Z_OBJCE_P(this_ptr), phpjs_JS_ptr TSRMLS_CC) || obj->ctx == NULL))) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected error. This method cannot be called statically"); \
return; \
} \
duk_context * ctx = obj->ctx;
#define FETCH_THIS FETCH_THIS_EX(1)
#define SET_PROP(var, t, n, v) zend_update_property_string(t, var, n, sizeof(n)-1, v TSRMLS_CC);
#define THROW_EXCEPTION(message) do { \
zval * tc_ex; \
MAKE_STD_ZVAL(tc_ex); \
object_init_ex(tc_ex, phpjs_JSException_ptr); \
SET_PROP(tc_ex, phpjs_JSException_ptr, "message", message); \
zend_throw_exception_object(tc_ex TSRMLS_CC); \
} while (0); \
#endif