mw.hook: Use hasOwnProperty
authorFomafix <fomafix@googlemail.com>
Wed, 9 Apr 2014 06:52:05 +0000 (06:52 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Wed, 9 Apr 2014 06:52:05 +0000 (06:52 +0000)
This allows hooks with name of predefined methods.

Change-Id: I71823a61a43787c14b410bc732f934fe7545fcee

resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 57f85d8..f6154ee 100644 (file)
@@ -2371,7 +2371,9 @@ var mw = ( function ( $, undefined ) {
                         * @return {mw.hook}
                         */
                        return function ( name ) {
-                               var list = lists[name] || ( lists[name] = $.Callbacks( 'memory' ) );
+                               var list = hasOwn.call( lists, name ) ?
+                                       lists[name] :
+                                       lists[name] = $.Callbacks( 'memory' );
 
                                return {
                                        /**
index e1fcb6a..6f81155 100644 (file)
 
        } );
 
-       QUnit.test( 'mw.hook', 12, function ( assert ) {
+       QUnit.test( 'mw.hook', 13, function ( assert ) {
                var hook, add, fire, chars, callback;
 
                mw.hook( 'test.hook.unfired' ).add( function () {
                } );
                mw.hook( 'test.hook.basic' ).fire();
 
+               mw.hook( 'hasOwnProperty' ).add( function () {
+                       assert.ok( true, 'hook with name of predefined method' );
+               } );
+               mw.hook( 'hasOwnProperty' ).fire();
+
                mw.hook( 'test.hook.data' ).add( function ( data1, data2 ) {
                        assert.equal( data1, 'example', 'Fire with data (string param)' );
                        assert.deepEqual( data2, ['two'], 'Fire with data (array param)' );