]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#573] Adds protection handling for popcorn proto methods inside of removePlugin...
authorRick Waldron <waldron.rick@gmail.com>
Tue, 14 Jun 2011 02:22:21 +0000 (22:22 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Tue, 14 Jun 2011 02:26:21 +0000 (22:26 -0400)
popcorn.js
test/popcorn.unit.js

index d5adf76528ff9b1ab18f0472db07bf9f8410db5e..add60b901f68a95f16c67f9fe109d33e6c7810e3 100644 (file)
 
   //  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
   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;
     }
 
       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;
 
index 099a1986368738518df6ac926ee4dec18cfdefe1..45100b65c80509293a918f03f8291b5dea81a385 100644 (file)
@@ -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" );
+    }
+  });
+});