The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

JavaScript::Runtime::OpcodeCounting - JavaScript::Runtime that counts how many opcodes that are executed

SYNOPSIS

  use JavaScript;
  use JavaScript::Runtime::OpcodeCounting;
  
  my $runtime = JavaScript::Runtime->new(qw(-OpcodeCounting));
  my $context = $runtime->create_context();

  $runtime->set_opcount(0);
  $runtime->set_opcount_limit(1000);
  $context->eval($some_javascript_code);
  print "Execution was aborted becuse we hit the limit" if $@ && $@->isa('JavaScript::Error::OpcodeLimitExceeded');
  print "Ran ", $runtime->get_opcount(), " opcodes";

DESCRIPTION

This module provides an extended JavaScript::Runtime class that keeps track on how many opcodes are executed by the runtime. It can also be set to abort execution when N number of opcodes have been executed by setting an upper limit.

Currently both the counter and the limit are implemented as U32 values. If lots, and I mean *lots*, of opcodes are executed without resetting the counter it will eventually overflow.

INTERFACE

INSTANCE METHODS

get_opcount

Returns the number of opcodes that have been executed.

set_opcount ( $count )

Sets the internal counter to $count.

get_opcount_limit

Returns the current limit before we abort execution.

set_opcount_limit ( $limit )

Sets the limit to $limit. If set to 0 no abortion will occur.

BUGS AND LIMITATIONS

Please report any bugs or feature requests to bug-javascript-runtime-opcodecounting@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Claes Jakobsson <claesjac@cpan.org>

LICENCE AND COPYRIGHT

Copyright (c) 2007, Claes Jakobsson <claesjac@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.