Peertube-dl/lib/Peertube/DL/Javascript.pm
2021-01-09 03:55:59 +01:00

53 lines
1.1 KiB
Perl
Executable File

#!/usr/bin/env perl
package Peertube::DL::Javascript;
use strict;
use warnings;
use feature 'say';
use XSLoader;
use Data::Dumper;
XSLoader::load();
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->{___ContextPrivateDONOTTOUCH} =
Peertube::DL::Javascript::_duk_create_heap_default();
return $self;
}
sub evalJS {
my $self = shift;
my $context = $self->___ContextDONOTUSE;
my $code = shift;
return Peertube::DL::Javascript::_duk_eval_wrapper( $context, $code );
}
sub callJSFunction {
my $self = shift;
my $function = shift;
my @function_arguments = @_;
my $context = $self->___ContextDONOTUSE;
return Peertube::DL::Javascript::_duk_call_function(
$context,
$function,
@function_arguments
);
}
sub ___ContextDONOTUSE {
my $self = shift;
return $self->{___ContextPrivateDONOTTOUCH};
}
sub DESTROY {
my $self = shift;
my $context = $self->___ContextDONOTUSE;
Peertube::DL::Javascript::_duk_destroy_heap($context);
undef $self;
}
1;