Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions v8js_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
c->object_name.~Persistent();
c->global_template.Reset();
c->global_template.~Persistent();
c->array_tmpl.Reset();
c->array_tmpl.~Persistent();

/* Clear persistent call_impl & method_tmpls templates */
for (std::map<v8js_tmpl_t *, v8js_tmpl_t>::iterator it = c->call_impls.begin();
Expand Down Expand Up @@ -221,6 +223,7 @@ static zend_object_value v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
new(&c->object_name) v8::Persistent<v8::String>();
new(&c->context) v8::Persistent<v8::Context>();
new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
new(&c->array_tmpl) v8::Persistent<v8::FunctionTemplate>();

new(&c->modules_stack) std::vector<char*>();
new(&c->modules_base) std::vector<char*>();
Expand Down
3 changes: 2 additions & 1 deletion v8js_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct v8js_ctx {
long memory_limit;
bool memory_limit_hit;

v8::Persistent<v8::FunctionTemplate> global_template;
v8js_tmpl_t global_template;
v8js_tmpl_t array_tmpl;

zval *module_loader;
std::vector<char *> modules_stack;
Expand Down
20 changes: 15 additions & 5 deletions v8js_object_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,22 @@ static v8::Handle<v8::Object> v8js_wrap_array_to_object(v8::Isolate *isolate, zv
uint key_len;
ulong index;

// @todo re-use template likewise
v8::Local<v8::FunctionTemplate> new_tpl = v8::FunctionTemplate::New(isolate, 0);
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
v8::Local<v8::FunctionTemplate> new_tpl;

if(ctx->array_tmpl.IsEmpty()) {
new_tpl = v8::FunctionTemplate::New(isolate, 0);

/* Call it Array, but it is not a native array, especially it doesn't have
* have the typical Array.prototype functions. */
new_tpl->SetClassName(V8JS_SYM("Array"));
/* Call it Array, but it is not a native array, especially it doesn't have
* have the typical Array.prototype functions. */
new_tpl->SetClassName(V8JS_SYM("Array"));

/* Store for later re-use */
ctx->array_tmpl.Reset(isolate, new_tpl);
}
else {
new_tpl = v8::Local<v8::FunctionTemplate>::New(isolate, ctx->array_tmpl);
}

v8::Handle<v8::Object> newobj = new_tpl->InstanceTemplate()->NewInstance();

Expand Down