forked from gonzus/JavaScript-V8-XS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gonzalo Diethelm
committed
Jun 15, 2018
1 parent
9aaab6d
commit 82aa028
Showing
13 changed files
with
8,249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.bak | ||
Makefile | ||
Makefile.old | ||
MYMETA.json | ||
MYMETA.yml | ||
*.sw[op] | ||
blib | ||
pm_to_blib | ||
*.tar.gz | ||
*.c | ||
*.o | ||
*.bs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0.000001 2018-06-13 | ||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%module{JavaScript::V8::XS}; | ||
|
||
%name{JavaScript::V8::XS} class V8Context | ||
{ | ||
V8Context(const char* flags = 0); | ||
~V8Context(); | ||
|
||
void set_flags_from_string(const char *str); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.gitignore | ||
Changes | ||
JavaScript-V8-XS-Context.xsp | ||
MANIFEST | ||
Makefile.PL | ||
V8Context.cc | ||
V8Context.h | ||
v8-perl.xs | ||
lib/JavaScript/V8/XS.pm | ||
perlobject.map | ||
ppport.h | ||
typemap | ||
typemap.xsp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use 5.008009; | ||
use ExtUtils::MakeMaker; | ||
|
||
my $V8_ROOT = '/Users/gdiethelm/src/v8'; | ||
my $V8_INCLUDE = "$V8_ROOT/include"; | ||
my $V8_LIB = "$V8_ROOT/out.gn/x64.release"; | ||
my @V8_LIBS = qw/ v8 v8_libbase v8_libplatform icuuc icui18n /; | ||
|
||
my $CC = 'c++'; | ||
my $CC_OPTS = '--std=c++0x -Wreserved-user-defined-literal'; | ||
my $LD = 'c++'; | ||
my $LD_OPTS = "-L${V8_LIB} " . join(' ', map { "-l$_" } @V8_LIBS); | ||
|
||
WriteMakefile( | ||
NAME => 'JavaScript::V8::XS', | ||
VERSION_FROM => 'lib/JavaScript/V8/XS.pm', | ||
ABSTRACT_FROM => 'lib/JavaScript/V8/XS.pm', | ||
LICENSE => 'mit', | ||
MIN_PERL_VERSION => 5.018000, | ||
PREREQ_PM => { | ||
'ExtUtils::XSpp' => '0.11', | ||
# 'XSLoader' => 0, | ||
}, | ||
TEST_REQUIRES => { | ||
'Data::Dumper' => 0, | ||
'Test::More' => 0, | ||
}, | ||
AUTHOR => [ | ||
'Gonzalo Diethelm ([email protected])', | ||
], | ||
|
||
CC => "$CC $CC_OPTS", | ||
DEFINE => '', | ||
INC => "-I $V8_INCLUDE", | ||
|
||
LD => "$LD $LD_OPTS", | ||
OBJECT => '$(O_FILES)', | ||
|
||
XSOPT => '-C++ -hiertype', | ||
TYPEMAPS => ['perlobject.map'], # TODO | ||
depend => { 'v8-perl.c' => 'JavaScript-V8-XS-Context.xsp' }, | ||
META_MERGE => { | ||
'meta-spec' => { version => 2 }, | ||
resources => { | ||
repository => { | ||
type => 'git', | ||
url => '[email protected]:gonzus/JavaScript-V8-XS', | ||
web => 'https://github.com/gonzus/JavaScript-V8-XS', | ||
}, | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "libplatform/libplatform.h" | ||
#include "V8Context.h" | ||
|
||
using namespace v8; | ||
|
||
int V8Context::v8_initialized = 0; | ||
|
||
V8Context::V8Context(const char* flags) | ||
{ | ||
fprintf(stderr, "V8 construct\n"); | ||
V8Context::initialize_v8(); | ||
fprintf(stderr, "V8 construct done\n"); | ||
} | ||
|
||
V8Context::~V8Context() | ||
{ | ||
fprintf(stderr, "V8 destruct\n"); | ||
fprintf(stderr, "V8 destruct done\n"); | ||
} | ||
|
||
void V8Context::set_flags_from_string(const char *str) | ||
{ | ||
V8::SetFlagsFromString(str, strlen(str)); | ||
} | ||
|
||
void V8Context::initialize_v8() | ||
{ | ||
if (v8_initialized) { | ||
return; | ||
} | ||
v8_initialized = 1; | ||
|
||
fprintf(stderr, "V8 initializing\n"); | ||
const char* prog = "foo"; | ||
v8::V8::InitializeICUDefaultLocation(prog); | ||
v8::V8::InitializeExternalStartupData(prog); | ||
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform(); | ||
v8::V8::InitializePlatform(platform.get()); | ||
v8::V8::Initialize(); | ||
fprintf(stderr, "V8 initializing done\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef V8CONTEXT_H_ | ||
#define V8CONTEXT_H_ | ||
|
||
#include <v8.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#include <EXTERN.h> | ||
#include <perl.h> | ||
#include <XSUB.h> | ||
#include "ppport.h" | ||
} | ||
#endif | ||
|
||
class V8Context { | ||
public: | ||
V8Context(const char* flags = NULL); | ||
~V8Context(); | ||
|
||
void set_flags_from_string(const char *str); | ||
private: | ||
static int v8_initialized; | ||
static void initialize_v8(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package JavaScript::V8::XS; | ||
use strict; | ||
use warnings; | ||
use parent 'Exporter'; | ||
|
||
use XSLoader; | ||
|
||
our $VERSION = '0.000001'; | ||
XSLoader::load( __PACKAGE__, $VERSION ); | ||
|
||
our @EXPORT_OK = qw[]; | ||
|
||
1; | ||
__END__ | ||
=pod | ||
=encoding utf8 | ||
=head1 NAME | ||
JavaScript::V8::XS - Perl XS binding for the V8 JavaScript engine | ||
=head1 VERSION | ||
Version 0.000001 | ||
=head1 SYNOPSIS | ||
use JavaScript::V8::XS; | ||
my $v8 = JavaScript::V8::XS->new(); | ||
=head1 SEE ALSO | ||
L<< https://metacpan.org/pod/JavaScript::V8 >> | ||
L<< https://metacpan.org/pod/JavaScript::Duktape::XS >> | ||
=head1 AUTHOR | ||
=over 4 | ||
=item * Gonzalo Diethelm C<< gonzus AT cpan DOT org >> | ||
=back | ||
=head1 THANKS | ||
=over 4 | ||
=item * Authors of JavaScript::V8 | ||
=back | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# "perlobject.map" Dean Roehrich, version 19960302 | ||
# | ||
# TYPEMAPs | ||
# | ||
# HV * -> unblessed Perl HV object. | ||
# AV * -> unblessed Perl AV object. | ||
# | ||
# INPUT/OUTPUT maps | ||
# | ||
# O_* -> opaque blessed objects | ||
# T_* -> opaque blessed or unblessed objects | ||
# | ||
# O_OBJECT -> link an opaque C or C++ object to a blessed Perl object. | ||
# T_OBJECT -> link an opaque C or C++ object to an unblessed Perl object. | ||
# O_HvRV -> a blessed Perl HV object. | ||
# T_HvRV -> an unblessed Perl HV object. | ||
# O_AvRV -> a blessed Perl AV object. | ||
# T_AvRV -> an unblessed Perl AV object. | ||
|
||
TYPEMAP | ||
|
||
HV * T_HvRV | ||
AV * T_AvRV | ||
|
||
|
||
###################################################################### | ||
OUTPUT | ||
|
||
# The Perl object is blessed into 'CLASS', which should be a | ||
# char* having the name of the package for the blessing. | ||
O_OBJECT | ||
sv_setref_pv( $arg, CLASS, (void*)$var ); | ||
|
||
T_OBJECT | ||
sv_setref_pv( $arg, Nullch, (void*)$var ); | ||
|
||
# Cannot use sv_setref_pv() because that will destroy | ||
# the HV-ness of the object. Remember that newRV() will increment | ||
# the refcount. | ||
O_HvRV | ||
$arg = sv_bless( newRV((SV*)$var), gv_stashpv(CLASS,1) ); | ||
|
||
T_HvRV | ||
$arg = newRV((SV*)$var); | ||
|
||
# Cannot use sv_setref_pv() because that will destroy | ||
# the AV-ness of the object. Remember that newRV() will increment | ||
# the refcount. | ||
O_AvRV | ||
$arg = sv_bless( newRV((SV*)$var), gv_stashpv(CLASS,1) ); | ||
|
||
T_AvRV | ||
$arg = newRV((SV*)$var); | ||
|
||
|
||
###################################################################### | ||
INPUT | ||
|
||
O_OBJECT | ||
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) | ||
$var = ($type)SvIV((SV*)SvRV( $arg )); | ||
else{ | ||
warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
||
T_OBJECT | ||
if( SvROK($arg) ) | ||
$var = ($type)SvIV((SV*)SvRV( $arg )); | ||
else{ | ||
warn( \"${Package}::$func_name() -- $var is not an SV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
||
O_HvRV | ||
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVHV) ) | ||
$var = (HV*)SvRV( $arg ); | ||
else { | ||
warn( \"${Package}::$func_name() -- $var is not a blessed HV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
||
T_HvRV | ||
if( SvROK($arg) && (SvTYPE(SvRV($arg)) == SVt_PVHV) ) | ||
$var = (HV*)SvRV( $arg ); | ||
else { | ||
warn( \"${Package}::$func_name() -- $var is not an HV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
||
O_AvRV | ||
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVAV) ) | ||
$var = (AV*)SvRV( $arg ); | ||
else { | ||
warn( \"${Package}::$func_name() -- $var is not a blessed AV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
||
T_AvRV | ||
if( SvROK($arg) && (SvTYPE(SvRV($arg)) == SVt_PVAV) ) | ||
$var = (AV*)SvRV( $arg ); | ||
else { | ||
warn( \"${Package}::$func_name() -- $var is not an AV reference\" ); | ||
XSRETURN_UNDEF; | ||
} | ||
|
Oops, something went wrong.