]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#719] Rebase, fixes tests
authorRick Waldron <waldron.rick@gmail.com>
Wed, 28 Sep 2011 17:40:33 +0000 (13:40 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 28 Sep 2011 17:40:33 +0000 (13:40 -0400)
popcorn.js
test/popcorn.unit.js

index b012c605fade72247634523be129cdad5cd1b0c8..22c3f52d73fd7c6e490b9c53ebee3e3f9249883c 100644 (file)
       second = second || Popcorn.nop;
 
       return function() {
-
         first.apply( this, arguments );
         second.apply( this, arguments );
       };
 
     // apply safe, and empty default functions
     methods.forEach(function( method ) {
-
-      definition[ method ] = definition[ method ] || Popcorn.nop;
+      definition[ method ] = safeTry( definition[ method ] || Popcorn.nop, name );
     });
 
     var pluginFn = function( setup, options ) {
       options._running = false;
 
       natives.start = natives.start || natives[ "in" ];
-      natives.end = natives.end || natives[ "out" ]; 
+      natives.end = natives.end || natives[ "out" ];
 
       // Check for previously set default options
       defaults = this.options.defaults && this.options.defaults[ options._natives && options._natives.type ];
 
         // extends previous functions with compose function
         methods.forEach(function( method ) {
-
           natives[ method ] = combineFn( natives[ method ], compose[ method ] );
         });
       });
 
       //  Ensure a manifest object, an empty object is a sufficient fallback
       options._natives.manifest = manifest;
-      
+
       //  Checks for expected properties
       if ( !( "start" in options ) ) {
         options.start = options[ "in" ] || 0;
     return plugin;
   };
 
+  // Storage for plugin function errors
+  Popcorn.plugin.errors = [];
+
+  // Returns wrapped plugin function
+  function safeTry( fn, pluginName ) {
+    return function() {
+      try {
+        return fn.apply( this, arguments );
+      } catch ( ex ) {
+        // Push plugin function errors into logging queue
+        Popcorn.plugin.errors.push({
+          plugin: pluginName,
+          thrown: ex,
+          source: fn.toString()
+        });
+
+        // Trigger an error that the instance can listen for
+        // and react to
+        this.trigger( "error", Popcorn.plugin.errors );
+      }
+    };
+  }
+
+  // Debug-mode flag for plugin development
   Popcorn.plugin.debug = false;
 
   //  removePlugin( type ) removes all tracks of that from all instances of popcorn
index 0c027921bd1d839f7bc1c2c9ab9ea204184f818c..376f932027da62a76effa0c16f96a4456540c910 100644 (file)
@@ -1509,6 +1509,56 @@ test("Configurable Defaults", function() {
 
 });
 
+test( "Exceptions", function() {
+
+  var $pop = Popcorn( "#video" ),
+      expects = 5,
+      count = 0;
+
+  Popcorn.plugin.errors = [];
+
+  function plus() {
+    if ( ++count == expects ) {
+      Popcorn.removePlugin( "exceptions" );
+      Popcorn.plugin.errors = [];
+      start();
+      $pop.destroy();
+    }
+  }
+
+  expect( expects );
+  stop( 5000 );
+
+  Popcorn.plugin( "exceptions", {
+    start: function() {
+      foo();
+    },
+    end: function() {
+    }
+  });
+
+  $pop.listen( "canplayall", function() {
+    this.exceptions({
+      start: 1,
+      end: 2
+    }).exec( 3, function() {
+      equal( Popcorn.plugin.errors.length, 1, "Popcorn.plugin.errors has one item");
+      plus();
+    }).currentTime( 0 ).play();
+
+    this.listen( "error", function( errors ) {
+      ok( errors.length, "`errors` array has error objects" );
+      plus();
+      ok( errors[ 0 ].thrown, "`errors[ 0 ].thrown` property exists" );
+      plus();
+      ok( errors[ 0 ].plugin, "`errors[ 0 ].plugin` property exists" );
+      plus();
+      ok( errors[ 0 ].source, "`errors[ 0 ].source` property exists" );
+      plus();
+    });
+  });
+});
+
 test("Start Zero Immediately", function() {
 
   var $pop = Popcorn("#video"),
@@ -2103,6 +2153,8 @@ test( "Popcorn Compose", function() {
       Popcorn.removePlugin("testPlugin");
       Popcorn.removePlugin("pluginOptions1");
       Popcorn.removePlugin("pluginOptions2");
+
+      popped.destroy();
       start();
     }
   }
@@ -2690,7 +2742,7 @@ test( "In/Out aliases", function() {
   var popcorn = Popcorn( "#video" ),
       expects = 5,
       count = 0,
-      counter = 0; 
+      counter = 0;
 
   expect( expects );
   stop();