Home  |  Linux  | Mysql  | PHP  | XML
From:Jesse Thompson Date:Fri Apr  6 02:35:46 2007
Subject:Perl exceptions from bound JS constructors do not propogate
Am I approaching this the wrong way, or is this perhaps something to report
in rt?

It looks like when I bind a class and throw an error (such as a die()
statement or a failed DB connect) from within a static or object method, it
bubbles beautifully through JS as an exception.

However when I bind a class and register some perl sub as a *constructor*,
any dies or errors from there seem to make the constructor abort silently
instead.

Example: in the code attached below, the perl diagnostic displays a blessed
object. when you uncomment "test point 2" you get a well documented error
message. When you uncomment "Test point #1" however, the message goes
unreported and you get a blank (uncontructed) object instead of a blessed
hash.

Thank you for your consideration. :)

- - Jesse Thompson
Webformix, Bend OR



use JavaScript;
use Data::Dumper;

my $rt = JavaScript::Runtime->new();
my $cx = $rt->create_context();

$cx->bind_function(write => sub { print @_; });

$cx->bind_class(
  name => 'JSDB',
  package => 'JSDB',
  constructor => "JSDB::new",
  fs => { test => \&JSDB::test, },
);
$cx->set_error_handler( sub { die(Dumper(\@_)); } );

$ret = $cx->eval(q[

var dbh = new JSDB;
dbh.test();

]);

print "js_ret = ($ret), \$@ = ($@)\n";
die(Dumper($ret));

exit;

package JSDB;

sub new
{
   my $class = shift;
   my $self = {};

#  die("Test point #1");

   bless $self, $class;
   return($self);
}

sub test
{
  my $self = shift;

#  die("Test point #2");
}

Navigate in group perl.javascript at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants