From: Rick Waldron Date: Wed, 28 Sep 2011 17:40:33 +0000 (-0400) Subject: [#719] Rebase, fixes tests X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=2f8fee2dee2d54928cac35a4efbd84068c7d5b9a;p=popcorn-js.git [#719] Rebase, fixes tests --- diff --git a/popcorn.js b/popcorn.js index b012c60..22c3f52 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1176,7 +1176,6 @@ second = second || Popcorn.nop; return function() { - first.apply( this, arguments ); second.apply( this, arguments ); }; @@ -1188,8 +1187,7 @@ // 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 ) { @@ -1209,7 +1207,7 @@ 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 ]; @@ -1229,14 +1227,13 @@ // 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; @@ -1310,6 +1307,30 @@ 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 diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 0c02792..376f932 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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();