mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-08 15:48:40 +00:00
Free php_v8js_accessor_ctx when we are done with it.
This commit is contained in:
parent
3f77a5a356
commit
24257b54af
@ -142,8 +142,18 @@ v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);
|
||||
/* Convert V8 value into zval */
|
||||
int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
|
||||
|
||||
struct php_v8js_accessor_ctx
|
||||
{
|
||||
char *variable_name_string;
|
||||
uint variable_name_string_len;
|
||||
v8::Isolate *isolate;
|
||||
};
|
||||
|
||||
void php_v8js_accessor_ctx_dtor(php_v8js_accessor_ctx * TSRMLS_DC);
|
||||
|
||||
/* Register accessors into passed object */
|
||||
void php_v8js_register_accessors(v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
||||
void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
||||
|
||||
|
||||
/* {{{ Context container */
|
||||
struct php_v8js_ctx {
|
||||
@ -161,6 +171,7 @@ struct php_v8js_ctx {
|
||||
std::vector<char *> modules_stack;
|
||||
std::vector<char *> modules_base;
|
||||
std::map<const char *,v8js_tmpl_t> template_cache;
|
||||
std::vector<php_v8js_accessor_ctx *> accessor_list;
|
||||
#ifdef ZTS
|
||||
void ***zts_ctx;
|
||||
#endif
|
||||
|
10
v8js.cc
10
v8js.cc
@ -554,6 +554,13 @@ static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
|
||||
}
|
||||
c->template_cache.~map();
|
||||
|
||||
/* Clear contexts */
|
||||
for (std::vector<php_v8js_accessor_ctx*>::iterator it = c->accessor_list.begin();
|
||||
it != c->accessor_list.end(); ++it) {
|
||||
php_v8js_accessor_ctx_dtor(*it TSRMLS_CC);
|
||||
}
|
||||
c->accessor_list.~vector();
|
||||
|
||||
/* Clear global object, dispose context */
|
||||
if (!c->context.IsEmpty()) {
|
||||
c->context.Reset();
|
||||
@ -600,6 +607,7 @@ static zend_object_value php_v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
|
||||
new(&c->modules_stack) std::vector<char*>();
|
||||
new(&c->modules_base) std::vector<char*>();
|
||||
new(&c->template_cache) std::map<const char *,v8js_tmpl_t>();
|
||||
new(&c->accessor_list) std::vector<php_v8js_accessor_ctx *>();
|
||||
|
||||
retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) php_v8js_free_storage, NULL TSRMLS_CC);
|
||||
retval.handlers = &v8js_object_handlers;
|
||||
@ -818,7 +826,7 @@ static PHP_METHOD(V8Js, __construct)
|
||||
|
||||
/* Register Get accessor for passed variables */
|
||||
if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
|
||||
php_v8js_register_accessors(php_obj_t, vars_arr, isolate TSRMLS_CC);
|
||||
php_v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
|
||||
}
|
||||
|
||||
/* Set name for the PHP JS object */
|
||||
|
@ -25,13 +25,6 @@ extern "C" {
|
||||
#include <v8.h>
|
||||
#include <string>
|
||||
|
||||
struct php_v8js_accessor_ctx
|
||||
{
|
||||
char *variable_name_string;
|
||||
uint variable_name_string_len;
|
||||
v8::Isolate *isolate;
|
||||
};
|
||||
|
||||
static void php_v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
{
|
||||
v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());
|
||||
@ -50,7 +43,14 @@ static void php_v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::Pr
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void php_v8js_register_accessors(v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
||||
void php_v8js_accessor_ctx_dtor(php_v8js_accessor_ctx *ctx TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
efree(ctx->variable_name_string);
|
||||
efree(ctx);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate> php_obj_t, zval *array, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
char *property_name;
|
||||
uint property_name_len;
|
||||
@ -87,6 +87,9 @@ void php_v8js_register_accessors(v8::Local<v8::FunctionTemplate> php_obj_t, zval
|
||||
|
||||
/* Set the variable fetch callback for given symbol on named property */
|
||||
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(php_obj_t));
|
||||
|
||||
/* record the context so we can free it later */
|
||||
accessor_list->push_back(ctx);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
Loading…
Reference in New Issue
Block a user