Adding support for lstring.

This commit is contained in:
sergiotarxz 2021-01-06 20:47:33 +01:00
parent 4bfca82bcd
commit ff2f583c24
Signed by untrusted user who does not match committer: sergiotarxz
GPG Key ID: E5903508B6510AC2
5 changed files with 31 additions and 11 deletions

View File

@ -6,15 +6,11 @@ bin/peertube-dl-hypnotoad
bin/peertube-dl-web
bin/peertube-dl-web.conf
cpanfile
include/javascript_builtins.h
javascript_builtins.c
javascript_interpreter_xs/javascript.xs
javascript_interpreter_xs/Makefile.PL
lib/auto/Peertube/DL/.exists
lib/Peertube/DL.pm
lib/Peertube/DL/Downloaders.pm
lib/Peertube/DL/Javascript.pm
lib/Peertube/DL/Javascript.xs
lib/Peertube/DL/public/css/index.css
lib/Peertube/DL/public/img/spinner.svg
lib/Peertube/DL/public/index.html
@ -24,7 +20,7 @@ lib/Peertube/DL/UserAgent.pm
lib/Peertube/DL/Utils.pm
LICENSE
Makefile.PL
MANIFEST This list of files
MANIFEST
README.md
src/include/javascript_builtins.h
src/javascript_builtins.c

View File

@ -7,13 +7,15 @@ WriteMakefile(
INST_BIN => './bin',
test => { TESTS => 't/*.t' },
test => { TESTS => 't/*/*.t' },
DIR => [ 'src', 'javascript_interpreter_xs/' ],
);
sub MY::postamble {
'
src: src/Makefile
cd src && $(MAKE) $(PASSTHRU)
src && $(MAKE) $(PASSTHRU)
javascript_interpreter_xs: javascript_interpreter_xs/Makefile
cd javascript_interpreter_xs/ && $(MAKE) $(PASSTHRU)
';
}

7
bin/js-pruebas Normal file → Executable file
View File

@ -1,4 +1,5 @@
#!/usr/bin/env perl
#
use strict;
use warnings;
@ -7,13 +8,13 @@ use feature 'say';
use Peertube::DL::Javascript;
my $a = Peertube::DL::Javascript::_duk_create_heap_default();
eval { Peertube::DL::Javascript::_duk_push_lstring( $a, "print(\"hola mundo\\n\");" ); };
eval { Peertube::DL::Javascript::_duk_push_lstring( $a, "\"hola mundo\"" ); };
if ($@) {
warn $@;
$@ = "";
}
if ( defined $a ) {
printf( "0x%0x\n", $a );
}
Peertube::DL::Javascript::_duk_peval($a);
say Peertube::DL::Javascript::_duk_get_lstring($a, -1);
Peertube::DL::Javascript::_duk_destroy_heap($a);
}

View File

@ -3,9 +3,9 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Peertube::DL::Javascript',
VERSION => '0.1',
LIBS => ['-lduktape'],
LIBS => ['-lduktape -l../src'],
INC => '-Iduktape -I../src/include',
XS => { 'javascript.xs' => 'javascript.o' },
OBJECT => 'javascript.o ../src/javascript_builtins.o',
OBJECT => '../src/javascript_builtins.o javascript.o',
LDFLAGS => '-Wl-t',
);

View File

@ -75,3 +75,24 @@ _duk_destroy_heap(SV *)
croak("Cannot destroy something that is not a context.");
}
duk_destroy_heap(context);
SV *
_duk_get_lstring(SV *, SV *)
CODE:
duk_context *context = (duk_context *) SvUV(ST(0));
if (!context) {
croak("Unable to get lstring from no existing context.");
}
duk_idx_t idx = SvIV(ST(1));
if (!duk_is_string(context, idx)) {
croak("Idx is not a string.");
}
if (duk_is_symbol(context, idx)) {
croak("This is a symbol, not a string.");
}
duk_size_t *lstring_len;
const char * lstring = duk_get_lstring(context, idx, lstring_len);
RETVAL = newSVpv(lstring, (size_t) lstring_len);
OUTPUT:
RETVAL