Skip to content

Commit e73660a

Browse files
committed
Merge pull request #12 from mamod/fix_nested
localize $@ error var on destruction fixes #9
2 parents 47d3213 + ca4327c commit e73660a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/JavaScript/Duktape.pm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ sub new {
175175
return 1;
176176
};
177177

178-
$duk->push_perl_function($self->{call}, -1, 1);
178+
$duk->push_perl_function($self->{call}, -1);
179179
$duk->put_global_string('perlCall');
180-
181180
return $self;
182181
}
183182

@@ -265,11 +264,20 @@ sub eval {
265264
sub vm { shift->{duk}; }
266265
sub duk { shift->{duk}; }
267266

267+
sub destroy {
268+
my $self = shift;
269+
return if !$self->{duk};
270+
local $@; #duk_desatroy_heap mess with $@!!
271+
$self->{duk}->gc(0);
272+
$self->{duk}->destroy_heap();
273+
delete $self->{duk};
274+
}
275+
268276
sub DESTROY {
269277
my $self = shift;
270278
my $duk = $self->duk;
271279
if ($self->{pid} == $$){
272-
$duk->destroy_heap();
280+
$self->destroy();
273281
}
274282
}
275283

@@ -512,7 +520,6 @@ sub push_c_function {
512520
my $self = shift;
513521
my $sub = shift;
514522
my $nargs = shift || -1;
515-
my $nofinalizer = shift;
516523

517524
$GlobalRef->{"$sub"} = sub {
518525
my @args = @_;
@@ -547,8 +554,6 @@ sub push_c_function {
547554
};
548555

549556
$self->perl_push_function($GlobalRef->{"$sub"}, $nargs);
550-
551-
return if $nofinalizer;
552557
$self->eval_string("(function(){perlFinalizer('$sub')})");
553558
$self->set_finalizer(-2);
554559
}

0 commit comments

Comments
 (0)