Permalink
Browse files

Add a test for passing a JS function to another JS function

  • Loading branch information...
1 parent 4ba07b7 commit 403f418de77a560c5825633be3a15a2203be13c2 Max Maischein committed Apr 4, 2012
Showing with 50 additions and 0 deletions.
  1. +1 −0 MANIFEST
  2. +49 −0 t/05-callback-parameter.t
View
@@ -31,6 +31,7 @@ t/02-repl.t
t/02-synopsis.t
t/03-unicode.t
t/04-looong-input.t
+t/05-callback-parameter.t
t/10-xul-hud.t
t/10-xul-hud.xul
t/11-memleak-callback.t
View
@@ -0,0 +1,49 @@
+#!perl -w
+use strict;
+use Test::More;
+
+use MozRepl::RemoteObject;
+
+my $repl;
+my $ok = eval {
+ $repl = MozRepl::RemoteObject->install_bridge(
+ #log => ['debug'],
+ use_queue => 1,
+ );
+ 1;
+};
+if (! $ok) {
+ my $err = $@;
+ plan skip_all => "Couldn't connect to MozRepl: $@";
+} else {
+ plan tests => 1;
+};
+
+my $fetch_foo = $repl->declare(<<JS);
+function(e) {
+ return e.foo;
+}
+JS
+
+sub genObj {
+ my ($repl) = @_;
+ my $rn = $repl->name;
+ my $obj = $repl->expr(<<JS)
+(function() {
+ var res = {};
+ res.foo = "bar";
+ res.baz = "flirble";
+ return res
+})()
+JS
+}
+
+my $apply = $repl->declare(<<JS);
+function( cont, item ) {
+ return cont(item)
+};
+JS
+
+my $obj = genObj($repl);
+
+is $apply->($fetch_foo, $obj), 'bar', "We can apply a JS function to a JS object";

0 comments on commit 403f418

Please sign in to comment.