This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathphp_v8_exceptions.h
124 lines (92 loc) · 5.63 KB
/
php_v8_exceptions.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
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* This file is part of the pinepain/php-v8 PHP extension.
*
* Copyright (c) 2015-2018 Bogdan Padalko <pinepain@gmail.com>
*
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the
* LICENSE file that was distributed with this source or visit
* http://opensource.org/licenses/MIT
*/
#ifndef PHP_V8_EXCEPTIONS_H
#define PHP_V8_EXCEPTIONS_H
#include "php_v8_context.h"
#include "php_v8_isolate.h"
#include <v8.h>
extern "C" {
#include "php.h"
#ifdef ZTS
#include "TSRM.h"
#endif
#include "zend_exceptions.h"
}
extern zend_class_entry* php_v8_generic_exception_class_entry;
extern zend_class_entry* php_v8_try_catch_exception_class_entry;
extern zend_class_entry* php_v8_termination_exception_class_entry;
extern zend_class_entry* php_v8_resource_limit_exception_class_entry;
extern zend_class_entry* php_v8_time_limit_exception_class_entry;
extern zend_class_entry* php_v8_memory_limit_exception_class_entry;
extern zend_class_entry* php_v8_value_exception_class_entry;
extern void php_v8_throw_try_catch_exception(php_v8_isolate_t *php_v8_isolate, php_v8_context_t *php_v8_context, v8::TryCatch *try_catch);
extern void php_v8_throw_try_catch_exception(php_v8_context_t *php_v8_context, v8::TryCatch *try_catch);
#define PHP_V8_THROW_EXCEPTION_CE(message, ce) zend_throw_exception((ce), (message), 0);
#define PHP_V8_THROW_EXCEPTION(message) PHP_V8_THROW_EXCEPTION_CE((message), php_v8_generic_exception_class_entry);
#define PHP_V8_THROW_VALUE_EXCEPTION(message) PHP_V8_THROW_EXCEPTION_CE((message), php_v8_value_exception_class_entry);
#define PHP_V8_TRY_CATCH(isolate) v8::TryCatch try_catch(isolate);
#define PHP_V8_CATCH_START(value) if ((value).IsEmpty()) { assert(try_catch.HasCaught());
#define PHP_V8_CATCH_END() } assert(!try_catch.HasCaught());
#define PHP_V8_MAYBE_CATCH(php_v8_context, try_catch) \
php_v8_isolate_limits_maybe_stop_timer((php_v8_context)->php_v8_isolate);\
if ((try_catch).HasCaught()) { \
php_v8_throw_try_catch_exception((php_v8_context), &(try_catch)); \
php_v8_isolate_external_exceptions_maybe_clear((php_v8_context)->php_v8_isolate); \
return; \
} \
php_v8_isolate_external_exceptions_maybe_clear((php_v8_context)->php_v8_isolate); \
#define PHP_V8_TRY_CATCH_EXCEPTION_STORE_ISOLATE(to_zval, from_isolate_zv) zend_update_property(php_v8_try_catch_exception_class_entry, (to_zval), ZEND_STRL("isolate"), (from_isolate_zv));
#define PHP_V8_TRY_CATCH_EXCEPTION_READ_ISOLATE(from_zval) zend_read_property(php_v8_try_catch_exception_class_entry, (from_zval), ZEND_STRL("isolate"), 0, &rv)
#define PHP_V8_TRY_CATCH_EXCEPTION_STORE_CONTEXT(to_zval, from_context_zv) zend_update_property(php_v8_try_catch_exception_class_entry, (to_zval), ZEND_STRL("context"), (from_context_zv));
#define PHP_V8_TRY_CATCH_EXCEPTION_READ_CONTEXT(from_zval) zend_read_property(php_v8_try_catch_exception_class_entry, (from_zval), ZEND_STRL("context"), 0, &rv)
#define PHP_V8_TRY_CATCH_EXCEPTION_STORE_TRY_CATCH(to_zval, from_isolate_zv) zend_update_property(php_v8_try_catch_exception_class_entry, (to_zval), ZEND_STRL("try_catch"), (from_isolate_zv));
#define PHP_V8_TRY_CATCH_EXCEPTION_READ_TRY_CATCH(from_zval) zend_read_property(php_v8_try_catch_exception_class_entry, (from_zval), ZEND_STRL("try_catch"), 0, &rv)
#define PHP_V8_THROW_EXCEPTION_WHEN_NOTHING_CE(value, message, ce) \
if ((value).IsNothing()) { \
PHP_V8_THROW_EXCEPTION_CE(message, ce); \
return; \
}
#define PHP_V8_THROW_EXCEPTION_WHEN_EMPTY_CE(value, message, ce) \
if ((value).IsEmpty()) { \
PHP_V8_THROW_EXCEPTION_CE(message, ce); \
return; \
}
#define PHP_V8_THROW_EXCEPTION_WHEN_UNDEFINED_CE(value, message, ce) \
if ((value)->IsUndefined()) { \
PHP_V8_THROW_EXCEPTION_CE(message, ce); \
return; \
}
#define PHP_V8_THROW_VALUE_EXCEPTION_WHEN_NOTHING(value, message) PHP_V8_THROW_EXCEPTION_WHEN_NOTHING_CE((value), (message), php_v8_value_exception_class_entry)
#define PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(value, message) PHP_V8_THROW_EXCEPTION_WHEN_EMPTY_CE((value), (message), php_v8_value_exception_class_entry)
#define PHP_V8_THROW_VALUE_EXCEPTION_WHEN_UNDEFINED(value, message) PHP_V8_THROW_EXCEPTION_WHEN_UNDEFINED_CE((value), (message), php_v8_value_exception_class_entry)
#define PHP_V8_THROW_EXCEPTION_WHEN_NOTHING(value, message) \
if ((value).IsNothing()) { \
PHP_V8_THROW_EXCEPTION(message); \
return; \
}
#define PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(value, message) \
if ((value).IsEmpty()) { \
PHP_V8_THROW_EXCEPTION(message); \
return; \
}
#define PHP_V8_THROW_EXCEPTION_WHEN_LIMITS_HIT(php_v8_context) \
if ((php_v8_context)->php_v8_isolate->limits.time_limit_hit || (php_v8_context)->php_v8_isolate->limits.memory_limit_hit) { \
php_v8_throw_try_catch_exception((php_v8_context), NULL); \
return; \
}
#define PHP_V8_EMPTY_HANDLER_MSG_PART " is empty. Forgot to call parent::__construct()?"
//#define PHP_V8_CHECK_EMPTY_HANDLER(val, message) if (NULL == (val)->php_v8_isolate || (val)->persistent->IsEmpty()) { PHP_V8_THROW_EXCEPTION(message); return; }
// we check handler to be !IsEmpty() in constructors and before value creations, so unless we didn't check that by mistacke, IsEmpty() check may be skipped
#define PHP_V8_CHECK_EMPTY_HANDLER(val, message) if (NULL == (val)->php_v8_isolate) { PHP_V8_THROW_EXCEPTION(message); return; }
#define PHP_V8_CHECK_EMPTY_HANDLER_RET(val, message, ret) if (NULL == (val)->php_v8_isolate) { PHP_V8_THROW_EXCEPTION(message); return (ret); }
PHP_MINIT_FUNCTION(php_v8_exceptions);
#endif //PHP_V8_EXCEPTIONS_H