mirror of
https://github.com/phpv8/v8js.git
synced 2024-09-19 16:35:19 +00:00
defer bailout until std::function dtor
std::function allocates some heap memory, at least with some implementations and expects the dtor to run. Hence defer the bailout until the dtor ran.
This commit is contained in:
parent
beedb680db
commit
a83c49266e
@ -529,6 +529,9 @@ static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, lo
|
||||
memory_limit = c->memory_limit;
|
||||
}
|
||||
|
||||
/* std::function relies on its dtor to be executed, otherwise it leaks
|
||||
* some memory on bailout. */
|
||||
{
|
||||
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [res](v8::Isolate *isolate) {
|
||||
v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
|
||||
return script->Run();
|
||||
@ -537,6 +540,13 @@ static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, lo
|
||||
v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call TSRMLS_CC);
|
||||
}
|
||||
|
||||
if(V8JSG(fatal_error_abort)) {
|
||||
/* Check for fatal error marker possibly set by v8js_error_handler; just
|
||||
* rethrow the error since we're now out of V8. */
|
||||
zend_bailout();
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
|
||||
*/
|
||||
static PHP_METHOD(V8Js, executeString)
|
||||
|
15
v8js_v8.cc
15
v8js_v8.cc
@ -76,13 +76,19 @@ void v8js_v8_init(TSRMLS_D) /* {{{ */
|
||||
/* }}} */
|
||||
|
||||
|
||||
/**
|
||||
* Prepare V8 call trampoline with time & memory limit, exception handling, etc.
|
||||
*
|
||||
* The caller MUST check V8JSG(fatal_error_abort) and trigger further bailout
|
||||
* either immediately after this function returns (or possibly after freeing
|
||||
* heap allocated memory).
|
||||
*/
|
||||
void v8js_v8_call(v8js_ctx *c, zval **return_value,
|
||||
long flags, long time_limit, long memory_limit,
|
||||
std::function< v8::Local<v8::Value>(v8::Isolate *) >& v8_call TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
char *tz = NULL;
|
||||
|
||||
{
|
||||
V8JS_CTX_PROLOGUE(c);
|
||||
|
||||
V8JSG(timer_mutex).lock();
|
||||
@ -197,13 +203,6 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
|
||||
v8js_to_zval(result, *return_value, flags, c->isolate TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
} /* /V8JS_CTX_PROLOGUE */
|
||||
|
||||
if(V8JSG(fatal_error_abort)) {
|
||||
/* Check for fatal error marker possibly set by v8js_error_handler; just
|
||||
* rethrow the error since we're now out of V8. */
|
||||
zend_bailout();
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -281,6 +281,9 @@ static int v8js_v8object_call_method(zend_string *method, zend_object *object, I
|
||||
zend_get_parameters_array_ex(argc, argv);
|
||||
}
|
||||
|
||||
/* std::function relies on its dtor to be executed, otherwise it leaks
|
||||
* some memory on bailout. */
|
||||
{
|
||||
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [obj, method, argc, argv TSRMLS_CC](v8::Isolate *isolate) {
|
||||
int i = 0;
|
||||
|
||||
@ -316,11 +319,18 @@ static int v8js_v8object_call_method(zend_string *method, zend_object *object, I
|
||||
};
|
||||
|
||||
v8js_v8_call(obj->ctx, &return_value, obj->flags, obj->ctx->time_limit, obj->ctx->memory_limit, v8_call TSRMLS_CC);
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
efree(argv);
|
||||
}
|
||||
|
||||
if(V8JSG(fatal_error_abort)) {
|
||||
/* Check for fatal error marker possibly set by v8js_error_handler; just
|
||||
* rethrow the error since we're now out of V8. */
|
||||
zend_bailout();
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
Loading…
Reference in New Issue
Block a user