Skip to content

Instantly share code, notes, and snippets.

@stash
Created June 5, 2010 21:48
Show Gist options
  • Save stash/427031 to your computer and use it in GitHub Desktop.
Save stash/427031 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use warnings;
use strict;
use Test::More;
use JavaScript;
my $rt = JavaScript::Runtime->new;
my $cx = $rt->create_context;
my $js_callback;
$cx->bind_function(register_callback => sub {
pass 'in register_callback';
$js_callback = shift;
pass 'done register callback';
});
$cx->bind_function('write' => sub { print @_,$/ });
$cx->bind_function('is' => \&is);
$cx->bind_function('pass' => \&pass);
$cx->eval(<<'EOJS');
function outer() {
pass("outer called");
register_callback(function inner() {
pass("inner called");
});
pass("registered callback");
}
EOJS
ok !$@, "eval was fine";
{
local $@;
$cx->call('outer');
ok !$@, "call was fine";
ok $js_callback, "callback was set";
}
{
diag "going to call callback";
$js_callback->(); # SEGFAULT
ok !$@, "call of callback was fine";
undef $js_callback;
}
done_testing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment