Skip to content

Commit cec4847

Browse files
committed
add timeout option on initiation
1 parent 9aa729c commit cec4847

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/JavaScript/Duktape.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,20 @@ sub new {
134134
my %options = @_;
135135

136136
my $max_memory = $options{max_memory} || 0;
137+
my $timeout = $options{timeout} || 0;
138+
139+
if ($timeout){
140+
croak "timeout option must be a number" if !JavaScript::Duktape::Vm::duk_sv_is_number( $timeout );
141+
}
137142

138143
if ( $max_memory ){
139-
croak "max_memory option should be a number" if !JavaScript::Duktape::Vm::duk_sv_is_number( $max_memory );
144+
croak "max_memory option must be a number" if !JavaScript::Duktape::Vm::duk_sv_is_number( $max_memory );
140145
croak "max_memory must be at least 256k (256 * 1024)" if $max_memory < 256 * 1024;
141146
}
142147

143148
my $self = bless {}, $class;
144149

145-
my $duk = $self->{duk} = JavaScript::Duktape::Vm->perl_duk_new( $max_memory );
150+
my $duk = $self->{duk} = JavaScript::Duktape::Vm->perl_duk_new( $max_memory, $timeout );
146151

147152
$self->{pid} = $$;
148153
$self->{max_memory} = $max_memory;

lib/JavaScript/Duktape/C/duk_perl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ void fatal_handler (void *udata, const char *msg) {
183183
/**
184184
* new
185185
******************************************************************************/
186-
SV *perl_duk_new(const char *classname, size_t max_memory) {
186+
SV *perl_duk_new(const char *classname, size_t max_memory, int timeout) {
187187
duk_context *ctx;
188188
SV *obj;
189189
SV *obj_ref;
190190

191191
perlDuk *duk = malloc(sizeof(*duk));
192192
duk->ctx = NULL;
193-
duk->timeout = 0;
193+
duk->timeout = timeout;
194194
duk->max_memory = max_memory;
195195
duk->total_allocated = 0;
196196

0 commit comments

Comments
 (0)