From 6133d56efbf280ce9099cdae1963d9943e610f2a Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 13 Jun 2011 22:22:21 -0400 Subject: [PATCH] [#573] Adds protection handling for popcorn proto methods inside of removePlugin; 28 Unit tests --- popcorn.js | 9 +++++++-- test/popcorn.unit.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/popcorn.js b/popcorn.js index d5adf7652..add60b901 100644 --- a/popcorn.js +++ b/popcorn.js @@ -642,7 +642,7 @@ // Protected API methods Popcorn.protect = { - natives: "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten".toLowerCase().split( /\s+/ ) + natives: "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten exec".toLowerCase().split( /\s+/ ) }; // Internal Only - Adds track events to the instance object @@ -836,7 +836,7 @@ Popcorn.plugin = function( name, definition, manifest ) { if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) { - Popcorn.error("'" + name + "' is a protected function name"); + Popcorn.error( "'" + name + "' is a protected function name" ); return; } @@ -956,6 +956,11 @@ name = obj; obj = Popcorn.p; + if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) { + Popcorn.error( "'" + name + "' is a protected function name" ); + return; + } + var registryLen = Popcorn.registry.length, registryIdx; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 099a19863..45100b65c 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -334,6 +334,25 @@ test("Protected", function () { }); +test("Protected from removal", function () { + + expect( Popcorn.protect.natives.length * 2 ); + + Popcorn.protect.natives.forEach(function( name ) { + + try { + Popcorn.plugin( name ); + } catch( e ) { + ok( true, e.message + " and cannot be used as a plugin name" ); + } + + try { + Popcorn.removePlugin( name ); + } catch( e ) { + ok( true, e.message + " and cannot be removed with this API" ); + } + }); +});